Changeset 71

Show
Ignore:
Timestamp:
04/16/06 06:52:48 (2 years ago)
Author:
jordi
Message:

The application can now open directly a file from the command line. I haven't added a test case because the function used to load the file is the same used the the openFileActivate() and reloadActivated() member functions of MainPter?, so it's tested with them. I only set this function public instead of protected.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/data/epdfview.desktop

    r48 r71  
    55Comment[es]=Visor de documentos PDF ligero 
    66Encoding=UTF-8 
    7 Exec=epdfview 
     7Exec=epdfview %f 
    88GenericName=PDF Viewer 
    99GenericName[ca]=Visor PDF 
  • trunk/src/MainPter.h

    r66 r71  
    5050            void goToPageActivated (void); 
    5151            void goToPreviousPageActivated (void); 
     52            void openDocument (const gchar *fileName, const gchar *oldPassword, 
     53                               gboolean canShowPage); 
    5254            void openFileActivated (void); 
    5355            void outlineActivated (DocumentOutline *outline); 
     
    6163 
    6264        protected: 
    63             void openDocument (const gchar *fileName, const gchar *oldPassword, 
    64                                gboolean canShowPage); 
    6565            void showPage (void); 
    6666 
  • trunk/src/main.cxx

    r49 r71  
    2525#include "MainPter.h" 
    2626 
     27 
    2728using namespace ePDFView; 
     29 
     30/// 
     31/// @brief The data passed to open_command_line_file() function. 
     32/// 
     33typedef struct 
     34{ 
     35    /// The presenter to make open the file. 
     36    MainPter *presenter; 
     37    /// The filename to open. 
     38    gchar *fileName; 
     39} OpenFileData; 
     40 
     41// Forward declarations. 
     42static gboolean open_command_line_file (gpointer data); 
    2843 
    2944int 
    3045main (int argc, char **argv) 
    3146{ 
    32     // Enable NLS support. 
     47    // Enable NLS. 
    3348    setlocale (LC_ALL, ""); 
    3449    bindtextdomain (PACKAGE, LOCALEDIR); 
    3550    bind_textdomain_codeset (PACKAGE, "UTF-8"); 
    3651    textdomain (PACKAGE); 
     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    } 
    3763    // Initialise the GTK library. 
    3864    gtk_init (&argc, &argv); 
     
    4066    // Create the main presenter. 
    4167    MainPter *mainPter = new MainPter (); 
     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    } 
    4284    // Create the main view. 
    4385    MainView *mainView = new MainView (mainPter); 
     
    5395    return EXIT_SUCCESS; 
    5496} 
     97 
     98gboolean 
     99open_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}