-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcmanfm-statusbar-pdf-pages.c
56 lines (49 loc) · 1.27 KB
/
pcmanfm-statusbar-pdf-pages.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
#include <stdlib.h>
#include <string.h>
#include <pcmanfm-modules.h>
#include <poppler/glib/poppler-document.h>
FM_DEFINE_MODULE( tab_page_status, pdf-num-pages )
static char *_sel_message( FmFileInfoList *files, gint n_files )
{
FmFileInfo *fi;
char* mimetype;
char* filename;
PopplerDocument* document;
GError *error = NULL;
int num_pages;
const char *page_label = "page";
const char *pages_label = "pages";
char *label;
if( n_files > 1 ){
return NULL;
}
fi = fm_file_info_list_peek_head( files );
mimetype = fm_mime_type_get_type( fm_file_info_get_mime_type( fi ) );
if( strcmp( mimetype, "application/pdf" ) != 0 ){
return NULL;
}
filename = fm_path_to_uri( fm_file_info_get_path( fi ) );
document = poppler_document_new_from_file( filename, NULL, &error );
if( error != NULL )
{
fprintf (stderr, "tabbar-pdf-pages error on file %s: %s\n", filename, error->message);
g_error_free( error );
}
free( filename );
if( document == NULL ){
return NULL;
}
num_pages = poppler_document_get_n_pages( document );
g_object_unref(document);
if( num_pages == 1 ){
label = page_label;
} else {
label = pages_label;
}
return g_strdup_printf( " (%i %s)", num_pages, label );
}
FmTabPageStatusInit fm_module_init_tab_page_status = {
NULL,
NULL,
_sel_message
};