-
Notifications
You must be signed in to change notification settings - Fork 2
/
pcmanfm-image-size-plugin.c
76 lines (68 loc) · 2.33 KB
/
pcmanfm-image-size-plugin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* pcmanfm-image-size-plugin.c
*
* This file is module for PCManFM.
* It can be used with LibFM and PCManFM version 1.2.0 or newer.
*
* Copyright 2014 Alexander Varnin (fenixk19) <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <string.h>
#include <libfm/fm.h>
#include <magick/api.h>
#include <pcmanfm-modules.h>
FM_DEFINE_MODULE(tab_page_status, image_size)
ExceptionInfo exception;
Image *image = 0;
ImageInfo *image_info = 0;
static char * image_size_sel_message(FmFileInfoList *files, gint n_files) {
const int str_size = 64;
char * buffer;
if(n_files>1)
return 0;
FmFileInfo* fi = fm_file_info_list_peek_head(files);
buffer = g_malloc(str_size);
buffer[0]=0;
if(fm_file_info_is_image(fi)) {
char * path_str = fm_path_to_str(fm_file_info_get_path(fi));
strncpy(image_info->filename, path_str, MaxTextExtent);
g_free(path_str);
image = PingImage(image_info, &exception);
if(image!=0)
snprintf(buffer, str_size, "(%dx%d)",
(int) image->columns, (int) image->rows);
// else
// snprintf(buffer, str_size, "%s:%s",exception.reason,exception.description);
}
return buffer;
}
static gboolean image_size_init(void) {
MagickCoreGenesis(0,MagickFalse);
GetExceptionInfo(&exception);
image_info=CloneImageInfo((ImageInfo *) NULL);
return TRUE;
}
static void image_size_finalize(void) {
DestroyImageInfo(image_info);
DestroyExceptionInfo(&exception);
MagickCoreTerminus();
}
FmTabPageStatusInit fm_module_init_tab_page_status = {
.sel_message = image_size_sel_message,
.init = image_size_init,
.finalize = image_size_finalize,
};