| | 52 | // Create the comman line options context. |
| | 53 | GOptionContext *optionContext = |
| | 54 | g_option_context_new (_("[FILE] - view PDF documents")); |
| | 55 | g_option_context_add_group (optionContext, gtk_get_option_group (TRUE)); |
| | 56 | GError *error = NULL; |
| | 57 | if ( !g_option_context_parse (optionContext, &argc, &argv, &error) ) |
| | 58 | { |
| | 59 | g_critical ("Error parsing command line options: %s\n", error->message); |
| | 60 | g_error_free (error); |
| | 61 | exit (EXIT_FAILURE); |
| | 62 | } |
| | 68 | // Now check if we have additional parameters. Any additional parameter |
| | 69 | // will be a filename to open. |
| | 70 | if ( argc > 1 ) |
| | 71 | { |
| | 72 | OpenFileData *openFile = new OpenFileData; |
| | 73 | if ( NULL != openFile ) |
| | 74 | { |
| | 75 | openFile->presenter = mainPter; |
| | 76 | openFile->fileName = g_strdup (argv[1]); |
| | 77 | |
| | 78 | // This will call the function when no other GTK event is on |
| | 79 | // the queue, and will let the presenter open the file when |
| | 80 | // then main view is shown. |
| | 81 | g_idle_add (open_command_line_file, openFile); |
| | 82 | } |
| | 83 | } |
| | 97 | |
| | 98 | gboolean |
| | 99 | open_command_line_file (gpointer data) |
| | 100 | { |
| | 101 | g_assert (NULL != data && "The data parameter is NULL."); |
| | 102 | |
| | 103 | OpenFileData *openFile = (OpenFileData *)data; |
| | 104 | g_assert (NULL != openFile->presenter && "The presenter is NULL."); |
| | 105 | g_assert (NULL != openFile->fileName && "The file name is NULL."); |
| | 106 | openFile->presenter->openDocument (openFile->fileName, NULL, TRUE); |
| | 107 | delete openFile; |
| | 108 | |
| | 109 | // Returning FALSE means that the function won't be called again. |
| | 110 | return FALSE; |
| | 111 | } |