Changeset 117

Show
Ignore:
Timestamp:
04/25/06 09:27:46 (2 years ago)
Author:
jordi
Message:

The main view now shows on the status bar the file loading as well as changing the current cursor to a watch.

Added the missing comments to the JobLoad? class.

Location:
trunk
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IMainView.h

    r107 r117  
    2727    class DocumentOutline; 
    2828 
     29    /// 
     30    /// @brief How to show the new page. 
     31    /// 
    2932    enum PageScroll 
    3033    { 
     
    3841 
    3942    /// 
     43    /// @brief Main view's cursor. 
     44    /// 
     45    enum ViewCursor 
     46    { 
     47        /// Normal cursor. 
     48        MAIN_VIEW_CURSOR_NORMAL, 
     49        /// Hour glass wait cursor. 
     50        MAIN_VIEW_CURSOR_WAIT, 
     51        /// Drag cursor. 
     52        MAIN_VIEW_CURSOR_DRAG 
     53    }; 
     54 
     55    /// 
    4056    /// @class IMainView 
    4157    /// @brief Interface class for the main view. 
     
    168184            /// 
    169185            virtual void sensitiveGoToPreviousPage (gboolean sensitive) = 0; 
     186             
     187            /// 
     188            /// @brief Changes the sensitivity of the "Open" action. 
     189            /// 
     190            /// The view must change the sensitivity (it's called enabled or 
     191            /// disabled on some toolkits) of the "Open" action 
     192            /// (both on the menu and the toolbar or any other place). 
     193            /// 
     194            /// @param sensitive Set to TRUE if need to make sensitive (enable) 
     195            ///                  the action (enable) or FALSE to  
     196            ///                  insensitive (disable) it. 
     197            /// 
     198            virtual void sensitiveOpen (gboolean sensitive) = 0; 
    170199 
    171200            /// 
     
    259288            /// 
    260289            virtual void sensitiveZoomWidth (gboolean sensitive) = 0; 
     290 
     291            /// 
     292            /// @brief Sets the page view's cursor. 
     293            /// 
     294            /// The main view must show the cursor as given by @a cursorType 
     295            /// for the page's view. 
     296            /// 
     297            /// @param cursorType The type of cursor to show. 
     298            /// 
     299            virtual void setCursor (ViewCursor cursorType) = 0; 
     300 
     301            /// 
     302            /// @brief Sets the text of the status bar. 
     303            /// 
     304            /// The view must show the text at @a text unless it's NULL, 
     305            /// which means show nothing. 
     306            /// 
     307            /// @param text The text to shown on the status bar or NULL if 
     308            ///             no text should be shown on the status bar. 
     309            /// 
     310            virtual void setStatusBarText (const gchar *text) = 0; 
    261311 
    262312            /// 
  • trunk/src/JobLoad.cxx

    r115 r117  
    2222 
    2323// Forward declarations. 
    24 gboolean job_load_done (gpointer data); 
    25 gboolean job_load_error (gpointer data); 
    26 gboolean job_load_password (gpointer data); 
    27 gpointer job_load_run (gpointer data); 
    28  
     24static gboolean job_load_done (gpointer data); 
     25static gboolean job_load_error (gpointer data); 
     26static gboolean job_load_password (gpointer data); 
     27static gpointer job_load_run (gpointer data); 
     28 
     29/// 
     30/// @brief Constructs a new JobLoad object. 
     31/// 
    2932JobLoad::JobLoad () 
    3033{ 
     
    4043} 
    4144 
     45/// 
     46/// @brief Deletes all dynamically allocated memory by JobLoad. 
     47/// 
    4248JobLoad::~JobLoad () 
    4349{ 
     
    5056} 
    5157 
     58/// 
     59/// @brief Checks if a new password can be tried. 
     60/// 
     61/// This function checks if we passed the number of time we can try a 
     62/// password. 
     63/// 
     64/// Be warned that this function alters the number of tries left. 
     65/// 
     66/// @return TRUE if we can try another password, FALSE otherwise. 
     67/// 
    5268gboolean 
    5369JobLoad::canTryPassword () 
     
    6278} 
    6379 
     80/// 
     81/// @brief Gets the file name to load or reload. 
     82/// 
     83/// @return The file name to load or reload. 
     84/// 
    6485const gchar * 
    6586JobLoad::getFileName () 
     
    6889} 
    6990 
     91/// 
     92/// @brief Gets the last error. 
     93/// 
     94/// @return The last load error. 
     95/// 
    7096GError * 
    7197JobLoad::getError () 
     
    74100} 
    75101 
     102/// 
     103/// @brief Gets the previously used page num. 
     104/// 
     105/// This is for reloading, gives the page where we were before reloading 
     106/// the document. 
     107/// 
     108/// @return The numbe of the page where we were. 
     109/// 
    76110gint 
    77111JobLoad::getPageNum () 
     
    80114} 
    81115 
     116/// 
     117/// @brief Gets the password. 
     118/// 
     119/// @return The password to use to open the document. 
     120/// 
    82121const gchar * 
    83122JobLoad::getPassword () 
     
    86125} 
    87126 
     127/// 
     128/// @brief The presenter that's opening the file. 
     129/// 
     130/// @return The presenter that is loading or reloading the document. 
     131/// 
    88132MainPter & 
    89133JobLoad::getPresenter () 
     
    94138} 
    95139 
     140/// 
     141/// @brief Gets the previously used rotation. 
     142/// 
     143/// This is for reloading. Gets the rotation of the document before reloading. 
     144/// 
     145/// @return The degrees the document was rotated before. 
     146/// 
    96147gint 
    97148JobLoad::getRotation () 
     
    100151} 
    101152 
     153/// 
     154/// @brief Gets the previously used zoom. 
     155/// 
     156/// This is for reloading. Gets the zoom of the document before reloading. 
     157/// 
     158/// @return The degrees the document was zoomed before. 
     159/// 
    102160gdouble 
    103161JobLoad::getZoom () 
     
    106164} 
    107165 
     166/// 
     167/// @brief Checks if we are reloading. 
     168/// 
     169/// @return TRUE if we are reloading, FALSE otherwise. 
     170/// 
    108171gboolean 
    109172JobLoad::isReload () 
     
    112175} 
    113176 
     177/// 
     178/// @brief Open the document. 
     179/// 
     180/// This function will insensitive the Open and Reload actions, set 
     181/// the view's status bar text, sets the wait cursor, and creates a new thread 
     182/// that opens the document. 
     183/// 
    114184void 
    115185JobLoad::run () 
     
    119189        g_thread_init (NULL); 
    120190    } 
     191     
     192    // Unsensitive the open and reload actions. 
     193    IMainView &view = getPresenter ().getView (); 
     194    view.sensitiveOpen (FALSE); 
     195    view.sensitiveReload (FALSE); 
     196    // Show the statusbar text. 
     197    gchar *statusText = NULL; 
     198    if ( isReload () ) 
     199    { 
     200        statusText = g_strdup_printf (_("Reloading file %s..."),  
     201                                        getFileName ()); 
     202    } 
     203    else 
     204    { 
     205        statusText = g_strdup_printf (_("Loading file %s..."), getFileName ()); 
     206    } 
     207    view.setStatusBarText (statusText); 
     208    g_free (statusText); 
     209    // Set the cursor. 
     210    view.setCursor (MAIN_VIEW_CURSOR_WAIT); 
    121211 
    122212    GError *error = NULL; 
     
    128218} 
    129219 
     220/// 
     221/// @brief Sets the file name to open. 
     222/// 
     223/// @param fileName The file name to load or reload. 
     224/// 
    130225void 
    131226JobLoad::setFileName (const gchar *fileName) 
     
    135230} 
    136231 
     232/// 
     233/// @brief Sets the last error. 
     234/// 
     235/// @param error The last error opening a file. 
     236/// 
    137237void 
    138238JobLoad::setError (GError *error) 
     
    145245} 
    146246 
     247/// 
     248/// @brief Sets the page number. 
     249/// 
     250/// This is used for reloading, see getPageNum(). 
     251/// 
     252/// @param pageNum The page to go when the document is reloaded. 
     253/// 
    147254void 
    148255JobLoad::setPage (gint pageNum) 
     
    151258} 
    152259 
     260/// 
     261/// @brief Sets the password to open the document. 
     262/// 
     263/// @param password The password to use. 
     264/// 
    153265void 
    154266JobLoad::setPassword (const gchar *password) 
     
    158270} 
    159271 
     272/// 
     273/// @brief Sets the presenter that loads the document. 
     274/// 
     275/// @param pter The MainPter that will load the document. 
     276/// 
    160277void 
    161278JobLoad::setPresenter (MainPter *pter) 
     
    164281} 
    165282 
     283/// 
     284/// @brief Sets if we are reloading. 
     285/// 
     286/// @param reload TRUE if we are reloading, false otherwise. 
     287/// 
    166288void 
    167289JobLoad::setReload (gboolean reload) 
     
    170292} 
    171293 
     294/// 
     295/// @brief Sets the rotation to use after reloading. 
     296/// 
     297/// @param rotation The degrees of rotation. 
     298/// 
    172299void 
    173300JobLoad::setRotation (gint rotation) 
     
    176303} 
    177304 
     305/// 
     306/// @brief Sets the zoom to use after reloading. 
     307/// 
     308/// @param zoom The level of zoom. 
     309/// 
    178310void 
    179311JobLoad::setZoom (gdouble zoom) 
     
    182314} 
    183315 
    184 /// 
    185  
     316//////////////////////////////////////////////////////////////// 
     317// Static threaded functions. 
     318//////////////////////////////////////////////////////////////// 
     319 
     320/// 
     321/// @brief The load is finished. 
     322/// 
     323/// This can be called either when the document was loaded correctly or  
     324/// after an error. What it does is set the presenter in a known state 
     325/// ready to be used again. 
     326/// 
     327/// @param data This parameter hold the JobLoad to open. 
     328///  
    186329gboolean 
    187330job_load_done (gpointer data) 
     
    201344} 
    202345 
     346/// 
     347/// @brief The load had errors. 
     348/// 
     349/// This is called when the load of the document had any error except 
     350/// when it's encrypted. 
     351/// 
     352/// @param data This parameter hold the JobLoad to open. 
     353///  
    203354gboolean 
    204355job_load_error (gpointer data) 
     
    209360    job->getPresenter ().getView ().showErrorMessage (_("Error Loading File"), 
    210361                                                    job->getError ()->message); 
    211     delete job; 
    212  
    213     return FALSE; 
    214 } 
    215  
     362    job->setReload (FALSE); 
     363    return job_load_done (data); 
     364} 
     365 
     366/// 
     367/// @brief The document is encrypted. 
     368/// 
     369/// This function is called when the document is encrypted. It asks to the 
     370/// user the password and tries until the user doesn't supply a password 
     371/// anymore (returned NULL) or canTryPassword() returns FALSE. 
     372/// 
     373/// When trying a new password, it creates a new thread. 
     374/// 
     375/// @param data This parameter hold the JobLoad to open. 
     376///  
    216377gboolean 
    217378job_load_password (gpointer data) 
     
    234395                g_error_free (error); 
    235396            } 
    236         } 
    237         else 
    238         { 
    239             delete job; 
     397            return FALSE; 
    240398        } 
    241399    } 
     
    246404                _("The password you have supplier is not a valid password " 
    247405                  "for this file.")); 
    248         delete job; 
    249     } 
    250  
    251     return FALSE; 
    252 } 
    253  
     406    } 
     407 
     408    return job_load_done (data); 
     409} 
     410 
     411/// 
     412/// @brief Opens the files. 
     413/// 
     414/// This is the threaded function that will try to call the presenter's 
     415/// loading function with the given file name and password. This function 
     416/// just tests if the load was successful or not and then tells glib to  
     417/// call the actual end function, that will show the result to the user. 
     418/// 
     419/// When this function is compiled with DEBUG defined, the calls to the 
     420/// "end" functions aren't scheduled by glib, since the test framework doesn't 
     421/// use it. 
     422/// 
     423/// @param data This parameter hold the JobLoad to open. 
     424/// 
    254425gpointer 
    255426job_load_run (gpointer data) 
  • trunk/src/JobLoad.h

    r115 r117  
    2323    // Forward declarations. 
    2424    class MainPter; 
    25      
     25    
     26    /// 
     27    /// @class JobLoad 
     28    /// @brief A background job that loads a file. 
     29    /// 
     30    /// This class is used to load and reload the PDF files. It creates 
     31    /// a thread that loads a file name. 
     32    /// 
    2633    class JobLoad 
    2734    { 
  • trunk/src/MainPter.cxx

    r115 r117  
    136136    } 
    137137 
     138    // Sensitive the open file action. 
     139    view.sensitiveOpen (TRUE); 
    138140    // Show the toolbar and statusbar depending on the configuration. 
    139141    view.showToolbar (config.showToolbar ()); 
     
    141143    view.setOutline (m_Document->getOutline ()); 
    142144    view.showSidebar (showSidebar); 
     145    // Remove the status bar text. 
     146    view.setStatusBarText (NULL); 
    143147    // Show the first page *AFTER* showing the sidebar because  
    144148    // the view change the row to the first outline that doesn't need 
     
    146150    // by the first outline is selected and we don't want this. 
    147151    m_Document->goToFirstPage (); 
     152    // Show the normal cursor. 
     153    view.setCursor (MAIN_VIEW_CURSOR_NORMAL); 
    148154    view.show ();  
    149155} 
     
    278284    Config &config = Config::getConfig (); 
    279285    gchar *lastFolder = config.getOpenFileFolder (); 
    280     gchar *fileName = getView ().openFileDialog (lastFolder); 
     286    IMainView &view = getView (); 
     287    gchar *fileName = view.openFileDialog (lastFolder); 
    281288    g_free (lastFolder);     
    282289    if ( NULL != fileName ) 
     
    287294    } 
    288295 
     296    // Open the file. 
    289297    JobLoad *job = new JobLoad (); 
    290298    job->setPresenter (this); 
     
    356364void 
    357365MainPter::reloadActivated () 
    358 {     
     366{    
     367    // Reopen the document. 
    359368    JobLoad *job = new JobLoad (); 
    360369    job->setPresenter (this); 
     
    366375    job->setRotation (m_Document->getRotation ()); 
    367376    job->setZoom ( m_Document->getZoom ()); 
    368     // Reopen the document. 
    369377    job->run (); 
    370378} 
     
    617625    return TRUE; 
    618626} 
    619 /* 
    620         { 
    621             // Now that the document has been loaded, just reset the initial 
    622             // state. 
    623             setInitialState (canShowPage); 
    624         } 
    625         else 
    626         { 
    627             // We got an error, but also can be that the file is encrypted. 
    628             if ( DocumentErrorEncrypted == error->code ) 
    629             { 
    630                 // Now we got an encrypted file. 
    631                 // Prompt for the password up to three time, until the password 
    632                 // is correct or the user cancels the password dialog. 
    633                 int passwordTries = 0; 
    634                 gchar *password = NULL; 
    635                 gboolean loaded = FALSE; 
    636                 do  
    637                 { 
    638                     g_free (password); 
    639                     password = getView ().promptPasswordDialog (); 
    640                     loaded = m_Document->loadFile (fileName, password, NULL); 
    641                 } while ( 3 > ++passwordTries &&  
    642                           NULL != password &&  
    643                           !loaded); 
    644  
    645                 // We are go, just check if we could load it or show the 
    646                 // error. 
    647                 if ( loaded ) 
    648                 { 
    649                     // Phew, finally loaded. Set the initial state. 
    650                     setInitialState (canShowPage); 
    651                 } 
    652                 else if ( NULL != password ) 
    653                 { 
    654                     // We didn't get the correct password, but the user 
    655                     // tried, because the password is not NULL. 
    656                     getView ().showErrorMessage (_("Error Loading File"), 
    657                             _("The password you have supplier is not a" 
    658                               " valid password for this file.")); 
    659                     g_free (password); 
    660                 } 
    661             } 
    662             else 
    663             { 
    664                 // It was an error. Show the error message. 
    665                 getView ().showErrorMessage (_("Error Loading File"),  
    666                                              error->message);                 
    667  
    668             } 
    669             g_free (error); 
    670         } 
    671     } 
    672      
    673 } 
    674 */ 
    675627 
    676628/// 
  • trunk/src/gtk/MainView.cxx

    r114 r117  
    357357 
    358358void  
     359MainView::sensitiveOpen (gboolean sensitive) 
     360{ 
     361    GtkAction *open =  
     362        gtk_ui_manager_get_action (m_UIManager, "/MenuBar/FileMenu/OpenFile"); 
     363    gtk_action_set_sensitive (open, sensitive); 
     364} 
     365 
     366void  
    359367MainView::sensitiveReload (gboolean sensitive) 
    360368{ 
     
    479487} 
    480488 
     489void 
     490MainView::setCursor (ViewCursor cursorType) 
     491{ 
     492    GdkCursor *cursor = NULL; 
     493    switch (cursorType) 
     494    { 
     495        case MAIN_VIEW_CURSOR_WAIT: 
     496            cursor = gdk_cursor_new (GDK_WATCH); 
     497            break; 
     498        case MAIN_VIEW_CURSOR_DRAG: 
     499            cursor = gdk_cursor_new (GDK_FLEUR); 
     500            break; 
     501        default: 
     502            cursor = NULL; 
     503    } 
     504 
     505    if ( NULL != m_MainWindow && GDK_IS_WINDOW (m_MainWindow->window) ) 
     506    { 
     507        gdk_window_set_cursor (m_MainWindow->window, cursor); 
     508    } 
     509    if ( NULL != cursor ) 
     510    { 
     511        gdk_cursor_unref (cursor); 
     512    } 
     513    gdk_flush (); 
     514} 
     515 
    481516void  
    482517MainView::setTotalPages (gint pages) 
     
    497532{ 
    498533    return gtk_entry_get_text (GTK_ENTRY (m_CurrentPage)); 
     534} 
     535 
     536void 
     537MainView::setStatusBarText (const gchar *text) 
     538{ 
     539    gint contextId = gtk_statusbar_get_context_id (GTK_STATUSBAR (m_StatusBar), 
     540            "general_message"); 
     541    gtk_statusbar_pop (GTK_STATUSBAR (m_StatusBar), contextId); 
     542    if ( NULL != text ) 
     543    { 
     544        gtk_statusbar_push (GTK_STATUSBAR (m_StatusBar), contextId, text); 
     545    } 
    499546} 
    500547 
     
    10741121        DragInfo *info = (DragInfo *)data; 
    10751122        delete info; 
    1076          
    10771123        return TRUE; 
    10781124    } 
  • trunk/src/gtk/MainView.h

    r110 r117  
    4242            void sensitiveGoToPreviousPage (gboolean sensitive); 
    4343            void sensitiveReload (gboolean sensitive); 
     44            void sensitiveOpen (gboolean sensitive); 
    4445            void sensitiveRotateLeft (gboolean sensitive); 
    4546            void sensitiveRotateRight (gboolean sensitive); 
     
    5253            void showPage (DocumentPage *page, PageScroll scroll); 
    5354            void showSidebar (gboolean show); 
     55            void setCursor (ViewCursor cursorType); 
    5456            void setTotalPages (gint pages); 
    5557            void setGoToPageText (const gchar *text); 
     58            void setStatusBarText (const gchar *text); 
    5659            const gchar *getGoToPageText (void); 
    5760            void getPageViewSize (gint *width, gint *height); 
  • trunk/src/main.cxx

    r115 r117  
    5454    // Create the main presenter. 
    5555    MainPter *mainPter = new MainPter (); 
     56    // Create the main view. 
     57    MainView *mainView = new MainView (mainPter); 
     58    // Let know to the presenter which is its view. 
     59    mainPter->setView (mainView); 
     60    // Enter the main loop and wait for user interaction. */ 
    5661    // Now check if we have additional parameters. Any additional parameter 
    5762    // will be a file name to open. 
     
    6368        job->run (); 
    6469    } 
    65     // Create the main view. 
    66     MainView *mainView = new MainView (mainPter); 
    67     // Let know to the presenter which is its view. 
    68     mainPter->setView (mainView); 
    69     // Enter the main loop and wait for user interaction. */ 
    7070    gtk_main(); 
    7171     
  • trunk/tests/DumbMainView.cxx

    r107 r117  
    126126 
    127127void 
     128DumbMainView::sensitiveOpen (gboolean sensitive) 
     129{ 
     130} 
     131 
     132void 
    128133DumbMainView::sensitiveReload (gboolean sensitive) 
    129134{