Lines 25-30
Link Here
|
25 |
|
25 |
|
26 |
using namespace ePDFView; |
26 |
using namespace ePDFView; |
27 |
|
27 |
|
|
|
28 |
static gboolean displayVersion = FALSE; |
29 |
|
28 |
struct LoadFileInfo |
30 |
struct LoadFileInfo |
29 |
{ |
31 |
{ |
30 |
gchar *fileName; |
32 |
gchar *fileName; |
Lines 32-37
Link Here
|
32 |
PDFDocument *document; |
34 |
PDFDocument *document; |
33 |
}; |
35 |
}; |
34 |
|
36 |
|
|
|
37 |
static GOptionEntry optEntries[] = |
38 |
{ |
39 |
{ "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &displayVersion, |
40 |
N_("Print version information and exit"), 0 }, |
41 |
{ 0 } |
42 |
}; |
43 |
|
35 |
static int |
44 |
static int |
36 |
loadFileFromCommandLine (gpointer data) |
45 |
loadFileFromCommandLine (gpointer data) |
37 |
{ |
46 |
{ |
Lines 57-75
Link Here
|
57 |
// Create the command line options context. |
66 |
// Create the command line options context. |
58 |
GOptionContext *optionContext = |
67 |
GOptionContext *optionContext = |
59 |
g_option_context_new (_("[FILE] - view PDF documents")); |
68 |
g_option_context_new (_("[FILE] - view PDF documents")); |
|
|
69 |
g_option_context_add_main_entries (optionContext, optEntries, PACKAGE); |
70 |
g_option_context_set_help_enabled (optionContext, TRUE); |
60 |
g_option_context_add_group (optionContext, gtk_get_option_group (TRUE)); |
71 |
g_option_context_add_group (optionContext, gtk_get_option_group (TRUE)); |
61 |
GError *error = NULL; |
72 |
GError *error = NULL; |
62 |
if ( !g_option_context_parse (optionContext, &argc, &argv, &error) ) |
73 |
if ( !g_option_context_parse (optionContext, &argc, &argv, &error) ) |
63 |
{ |
74 |
{ |
64 |
g_critical ("Error parsing command line options: %s\n", error->message); |
75 |
g_critical ("Error parsing command line options: %s\n", error->message); |
|
|
76 |
// g_option_group_set_error_hook () seems to be a more elegant solution |
77 |
g_print ("Usage: [-h, --help]/[-V, --version] <file name>\n"); |
65 |
g_error_free (error); |
78 |
g_error_free (error); |
66 |
exit (EXIT_FAILURE); |
79 |
exit (EXIT_FAILURE); |
67 |
} |
80 |
} |
|
|
81 |
if ( displayVersion ) |
82 |
{ |
83 |
g_print ("ePDFView %s\n", VERSION); |
84 |
return EXIT_SUCCESS; |
85 |
} |
86 |
|
68 |
// Initialise the working thread. |
87 |
// Initialise the working thread. |
69 |
IJob::init (); |
88 |
IJob::init (); |
70 |
// Initialise the GTK library. |
89 |
// Initialise the GTK library. |
71 |
gtk_init (&argc, &argv); |
90 |
gtk_init (&argc, &argv); |
72 |
g_set_application_name (_("PDF Viewer")); |
|
|
73 |
// Create the main presenter. |
91 |
// Create the main presenter. |
74 |
PDFDocument *document = new PDFDocument; |
92 |
PDFDocument *document = new PDFDocument; |
75 |
MainPter *mainPter = new MainPter (document); |
93 |
MainPter *mainPter = new MainPter (document); |
Lines 78-91
Link Here
|
78 |
// Let know to the presenter which is its view. |
96 |
// Let know to the presenter which is its view. |
79 |
mainPter->setView (mainView); |
97 |
mainPter->setView (mainView); |
80 |
// Now check if we have additional parameters. Any additional parameter |
98 |
// Now check if we have additional parameters. Any additional parameter |
81 |
// will be a file name to open. |
99 |
// can be only a file name to open, because all other options that could be |
|
|
100 |
// parsed were removed from argv[] by g_option_context_parse (). |
82 |
if ( argc > 1 ) |
101 |
if ( argc > 1 ) |
83 |
{ |
102 |
{ |
|
|
103 |
gchar * errmsg = g_strdup ("testpattern"); |
84 |
LoadFileInfo *info = new LoadFileInfo; |
104 |
LoadFileInfo *info = new LoadFileInfo; |
85 |
info->mainPter = mainPter; |
105 |
info->mainPter = mainPter; |
86 |
info->document = document; |
106 |
info->document = document; |
87 |
info->fileName = g_strdup (argv[1]); |
107 |
info->fileName = g_strdup (argv[1]); |
88 |
g_idle_add (loadFileFromCommandLine, info); |
108 |
// Open file only if it exist and is a regular file but not a directory. |
|
|
109 |
if ( !g_file_test (info->fileName, G_FILE_TEST_EXISTS ) |
110 |
&& g_ascii_strcasecmp (info->fileName, "-") ) |
111 |
g_strlcpy (errmsg, "it does not exist", 60); |
112 |
else if ( g_file_test (info->fileName, G_FILE_TEST_IS_DIR )) |
113 |
g_strlcpy (errmsg, "it is a directory", 60); |
114 |
if ( g_ascii_strcasecmp (errmsg, "testpattern") ) |
115 |
{ |
116 |
g_critical ("Error opening file \"%s\": %s. Exiting...\n", |
117 |
info->fileName, errmsg); |
118 |
return EXIT_FAILURE; |
119 |
} |
120 |
g_idle_add (loadFileFromCommandLine, info); |
89 |
} |
121 |
} |
90 |
|
122 |
|
91 |
gtk_main(); |
123 |
gtk_main(); |
Lines 99-104
Link Here
|
99 |
|
131 |
|
100 |
g_option_context_free (optionContext); |
132 |
g_option_context_free (optionContext); |
101 |
|
133 |
|
102 |
// All done!. |
134 |
// All done! |
103 |
return EXIT_SUCCESS; |
135 |
return EXIT_SUCCESS; |
104 |
} |
136 |
} |