Changeset 136

Show
Ignore:
Timestamp:
04/29/06 14:09:50 (2 years ago)
Author:
jordi
Message:

Now all tests passes and the ePDFView executable can be build.

Location:
trunk
Files:
13 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IDocument.cxx

    r135 r136  
    211211 
    212212void 
    213 IDocument::notifyLoadPassword (const gchar *fileName, const GError *error) 
     213IDocument::notifyLoadPassword (const gchar *fileName, gboolean reload, 
     214                               const GError *error) 
    214215{ 
    215216    for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 
     
    217218    { 
    218219        IDocumentObserver *observer = (IDocumentObserver *)item->data; 
    219         observer->notifyLoadPassword (fileName, error); 
     220        observer->notifyLoadPassword (fileName, reload, error); 
    220221    } 
    221222} 
     
    272273        IDocumentObserver *observer = (IDocumentObserver *)item->data; 
    273274        observer->notifyPageZoomed (zoom); 
     275    } 
     276} 
     277 
     278void 
     279IDocument::notifyReload () 
     280{ 
     281    // Refresh the cache. 
     282    G_LOCK (JobRender); 
     283    refreshCache (); 
     284    G_UNLOCK (JobRender); 
     285 
     286    for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 
     287          item = g_list_next (item) ) 
     288    { 
     289        IDocumentObserver *observer = (IDocumentObserver *)item->data; 
     290        observer->notifyReload (); 
    274291    } 
    275292} 
     
    286303    job->setFileName (fileName); 
    287304    job->setPassword (password); 
     305    IJob::queue (job); 
     306} 
     307 
     308void 
     309IDocument::reload (void) 
     310{ 
     311    JobLoad *job = new JobLoad (); 
     312    job->setDocument (this); 
     313    job->setFileName (getFileName ()); 
     314    job->setPassword (getPassword ()); 
     315    job->setReload (TRUE); 
    288316    IJob::queue (job); 
    289317} 
     
    11231151    { 
    11241152        PageCache *tmpCached = (PageCache *)page->data; 
    1125         if ( pageNum == tmpCached->pageNumber ) 
     1153        if ( NULL != tmpCached && pageNum == tmpCached->pageNumber ) 
    11261154        { 
    11271155            cached = tmpCached; 
  • trunk/src/IDocument.h

    r135 r136  
    187187            void notifyLoad (void); 
    188188            void notifyLoadError (const GError *error); 
    189             void notifyLoadPassword (const gchar *fileName,  
     189            void notifyLoadPassword (const gchar *fileName, gboolean reload, 
    190190                                     const GError *error); 
    191191            void notifyPageChanged (void); 
     
    194194            void notifyPageRotated (void); 
    195195            void notifyPageZoomed (void); 
     196            void notifyReload (void); 
    196197             
    197198            const gchar *getTitle (void); 
     
    233234 
    234235            void load (const gchar *fileName, const gchar *password); 
     236            void reload (void); 
    235237 
    236238            void goToFirstPage (void); 
  • trunk/src/IDocumentObserver.h

    r132 r136  
    2929            virtual void notifyLoadError (const GError *error) { } 
    3030            virtual void notifyLoadPassword (const gchar *fileName, 
     31                                             gboolean reload, 
    3132                                             const GError *error) { } 
    3233            virtual void notifyPageChanged (gint pageNum) { } 
    3334            virtual void notifyPageRotated (gint rotation) { } 
    3435            virtual void notifyPageZoomed (gdouble zoom) { } 
     36            virtual void notifyReload (void) { } 
    3537 
    3638        protected: 
  • trunk/src/JobLoad.cxx

    r134 r136  
    2525static gboolean job_load_error (gpointer data); 
    2626static gboolean job_load_password (gpointer data); 
     27static gboolean job_reload_done (gpointer data); 
    2728 
    2829/// 
     
    3233    IJob () 
    3334{ 
     35    m_Document = NULL; 
     36    m_Error = NULL; 
    3437    m_FileName = NULL; 
    35     m_Error = NULL; 
    3638    m_Password = NULL; 
    37     m_Document = NULL; 
     39    m_Reload = FALSE; 
    3840} 
    3941 
     
    5254 
    5355/// 
     56/// @brief The document that's loading. 
     57/// 
     58/// @return The document that is loading. 
     59/// 
     60IDocument & 
     61JobLoad::getDocument () 
     62{ 
     63    g_assert (NULL != m_Document && "The document is NULL."); 
     64 
     65    return *m_Document; 
     66} 
     67 
     68/// 
     69/// @brief Gets the last error. 
     70/// 
     71/// @return The last load error. 
     72/// 
     73GError * 
     74JobLoad::getError () 
     75{ 
     76    return m_Error; 
     77} 
     78 
     79/// 
    5480/// @brief Gets the file name to load or reload. 
    5581/// 
     
    6389 
    6490/// 
    65 /// @brief Gets the last error. 
    66 /// 
    67 /// @return The last load error. 
    68 /// 
    69 GError * 
    70 JobLoad::getError () 
    71 { 
    72     return m_Error; 
    73 } 
    74  
    75 /// 
    7691/// @brief Gets the password. 
    7792/// 
     
    85100 
    86101/// 
    87 /// @brief The document that's loading. 
    88 /// 
    89 /// @return The document that is loading. 
    90 /// 
    91 IDocument & 
    92 JobLoad::getDocument () 
    93 { 
    94     g_assert (NULL != m_Document && "The document is NULL."); 
    95  
    96     return *m_Document; 
    97 } 
    98  
     102/// @brief Check if we are reloading. 
     103/// 
     104/// @return TREU if are reloading, FALSE otherwise. 
     105/// 
     106gboolean 
     107JobLoad::isReloading () 
     108{ 
     109    return m_Reload; 
     110} 
    99111 
    100112/// 
     
    108120    if ( getDocument ().loadFile (getFileName (), getPassword (), &error) ) 
    109121    { 
    110         JOB_NOTIFIER (job_load_done, this); 
     122        if ( isReloading () ) 
     123        { 
     124            JOB_NOTIFIER (job_reload_done, this); 
     125        } 
     126        else 
     127        { 
     128            JOB_NOTIFIER (job_load_done, this); 
     129        } 
    111130    } 
    112131    else 
     
    127146 
    128147/// 
     148/// @brief Sets the document to load. 
     149/// 
     150/// @param document The document that will load. 
     151/// 
     152void 
     153JobLoad::setDocument (IDocument *document) 
     154{ 
     155    g_assert ( NULL != document && "Tried to set a NULL document."); 
     156     
     157    m_Document = document; 
     158} 
     159 
     160/// 
     161/// @brief Sets the last error. 
     162/// 
     163/// @param error The last error opening a file. 
     164/// 
     165void 
     166JobLoad::setError (GError *error) 
     167{ 
     168    if ( NULL != m_Error ) 
     169    { 
     170        g_error_free (m_Error); 
     171    } 
     172    m_Error = error; 
     173} 
     174 
     175/// 
    129176/// @brief Sets the file name to open. 
    130177/// 
     
    139186 
    140187/// 
    141 /// @brief Sets the last error. 
    142 /// 
    143 /// @param error The last error opening a file. 
    144 /// 
    145 void 
    146 JobLoad::setError (GError *error) 
    147 { 
    148     if ( NULL != m_Error ) 
    149     { 
    150         g_error_free (m_Error); 
    151     } 
    152     m_Error = error; 
    153 } 
    154  
    155 /// 
    156188/// @brief Sets the password to open the document. 
    157189/// 
     
    166198 
    167199/// 
    168 /// @brief Sets the document to load. 
    169 /// 
    170 /// @param document The document that will load. 
    171 /// 
    172 void 
    173 JobLoad::setDocument (IDocument *document) 
    174 { 
    175     g_assert ( NULL != document && "Tried to set a NULL document."); 
    176      
    177     m_Document = document; 
    178 } 
    179  
     200/// @brief Sets if reload. 
     201/// 
     202/// @param reload TRUE if must reload, FALSE otherwise. 
     203/// 
     204void 
     205JobLoad::setReload (gboolean reload) 
     206{ 
     207    m_Reload = reload; 
     208} 
    180209 
    181210//////////////////////////////////////////////////////////////// 
     
    238267    JobLoad *job = (JobLoad *)data; 
    239268    job->getDocument ().notifyLoadPassword (job->getFileName (), 
     269                                            job->isReloading (), 
    240270                                            job->getError ()); 
    241271    JOB_NOTIFIER_END(); 
     
    243273    return FALSE; 
    244274} 
     275 
     276/// 
     277/// @brief The reload is finished correctly. 
     278/// 
     279/// @param data This parameter holds the JobLoad that finished. 
     280/// 
     281gboolean 
     282job_reload_done (gpointer data) 
     283{ 
     284    g_assert (NULL != data && "The data parameter is NULL."); 
     285 
     286    JobLoad *job = (JobLoad *)data; 
     287    job->getDocument ().notifyReload (); 
     288    JOB_NOTIFIER_END(); 
     289     
     290    return FALSE; 
     291} 
  • trunk/src/JobLoad.h

    r124 r136  
    4040            const gchar *getFileName (void); 
    4141            const gchar *getPassword (void); 
     42            gboolean isReloading (void); 
    4243            gboolean run (void); 
     44            void setDocument (IDocument *document); 
     45            void setError (GError *error); 
    4346            void setFileName (const gchar *fileName); 
    44             void setError (GError *error); 
    4547            void setPassword (const gchar *password); 
    46             void setDocument (IDocument *document); 
     48            void setReload (gboolean reload); 
    4749 
    4850        protected: 
     51            IDocument *m_Document; 
     52            GError *m_Error; 
    4953            gchar *m_FileName; 
    50             GError *m_Error; 
    5154            gchar *m_Password; 
    52             IDocument *m_Document; 
     55            gboolean m_Reload; 
    5356    }; 
    5457} 
  • trunk/src/MainPter.cxx

    r135 r136  
    158158    // Remove the status bar text. 
    159159    view.setStatusBarText (NULL); 
     160    // Show the normal cursor. 
     161    view.setCursor (MAIN_VIEW_CURSOR_NORMAL); 
    160162    // Show the first page *AFTER* showing the sidebar because  
    161163    // the view change the row to the first outline that doesn't need 
    162164    // to be the first page. If we don't do this, the first page pointed 
    163165    // by the first outline is selected and we don't want this. 
    164     m_Document->goToFirstPage (); 
    165     // Show the normal cursor. 
    166     view.setCursor (MAIN_VIEW_CURSOR_NORMAL); 
    167     // Show the window. 
    168166    if ( m_Document->isLoaded () && canShowPage ) 
    169167    { 
     168        m_Document->goToFirstPage (); 
    170169        refreshPage (PAGE_SCROLL_START); 
    171170    } 
     
    398397MainPter::reloadActivated () 
    399398{    
    400     // Reopen the document. 
    401 /*    JobLoad *job = new JobLoad (); 
    402     job->setPresenter (this); 
    403     job->setFileName (m_Document->getFileName ()); 
    404     job->setPassword (m_Document->getPassword ()); 
    405     job->setReload (TRUE); 
    406     // Save the current document's state. 
    407     job->setPage (m_Document->getCurrentPageNum ()); 
    408     job->setRotation (m_Document->getRotation ()); 
    409     job->setZoom ( m_Document->getZoom ()); 
    410     job->run ();*/ 
     399    g_assert ( m_Document->isLoaded () &&  
     400            "Tried to reload a yet to load document."); 
     401 
     402    // Insensitive the open and reload controls. 
     403    IMainView &view = getView (); 
     404    view.sensitiveOpen (FALSE); 
     405    view.sensitiveReload (FALSE); 
     406    // Show the text on the status bar. 
     407    gchar *statusText = g_strdup_printf (_("Reloading file %s..."), 
     408                                         m_Document->getFileName ()); 
     409    view.setStatusBarText (statusText); 
     410    g_free (statusText); 
     411    // Set the wait cursor. 
     412    view.setCursor (MAIN_VIEW_CURSOR_WAIT); 
     413    // Set the number of times we can try the password. 
     414    m_PasswordTries = 3; 
     415    // Reload 
     416    m_Document->reload (); 
    411417} 
    412418 
     
    702708 
    703709void 
    704 MainPter::notifyLoadPassword (const gchar *fileName, const GError *error) 
     710MainPter::notifyLoadPassword (const gchar *fileName, gboolean reload, const GError *error) 
    705711{ 
    706712    if ( 0 < m_PasswordTries ) 
     
    710716        if ( password != NULL ) 
    711717        { 
    712             m_Document->load (fileName, password); 
     718            if ( reload ) 
     719            { 
     720                m_Document->setPassword (password); 
     721                m_Document->reload (); 
     722            } 
     723            else 
     724            { 
     725                m_Document->load (fileName, password); 
     726            } 
    713727        } 
    714728#if defined (DEBUG) 
     
    778792} 
    779793 
     794void 
     795MainPter::notifyReload () 
     796{ 
     797    setInitialState (FALSE); 
     798    refreshPage (PAGE_SCROLL_NONE); 
     799#if defined (DEBUG) 
     800    G_LOCK (fileLoaded); 
     801    fileLoaded = TRUE; 
     802    G_UNLOCK (fileLoaded); 
     803#endif // DEBUG 
     804} 
     805 
    780806#if defined (DEBUG) 
    781807/// 
  • trunk/src/MainPter.h

    r134 r136  
    6868            void notifyLoad (void); 
    6969            void notifyLoadError (const GError *error); 
    70             void notifyLoadPassword (const gchar *fileName,  
     70            void notifyLoadPassword (const gchar *fileName, gboolean reload, 
    7171                                     const GError *error); 
    7272            void notifyPageChanged (gint pageNum); 
    7373            void notifyPageRotated (gint rotation); 
    7474            void notifyPageZoomed (gdouble zoom); 
     75            void notifyReload (void); 
    7576 
    7677            static gboolean pageNotAvailable (gpointer user); 
  • trunk/tests/DumbDocumentObserver.cxx

    r132 r136  
    3131    m_NotifiedPageRotated = FALSE; 
    3232    m_NotifiedPageZoomed = FALSE; 
     33    m_NotifiedReload = FALSE; 
    3334    m_Zoom = 0.0; 
    3435} 
     
    5556 
    5657void 
    57 DumbDocumentObserver::notifyLoadPassword (const gchar *fileName, 
     58DumbDocumentObserver::notifyLoadPassword (const gchar *fileName,  
     59                                          gboolean reload, 
    5860                                          const GError *error) 
    5961{ 
     
    7981    m_NotifiedPageZoomed = TRUE; 
    8082    m_Zoom = zoom; 
     83} 
     84 
     85void 
     86DumbDocumentObserver::notifyReload (void) 
     87{ 
     88    m_NotifiedReload; 
    8189} 
    8290 
     
    106114DumbDocumentObserver::loadFinished (void) 
    107115{ 
    108     return m_NotifiedError || m_NotifiedPassword || m_NotifiedLoad; 
     116    return m_NotifiedError || m_NotifiedPassword || m_NotifiedLoad || 
     117           m_NotifiedReload; 
    109118} 
    110119 
  • trunk/tests/DumbDocumentObserver.h

    r132 r136  
    2929            void notifyLoad (void); 
    3030            void notifyLoadError (const GError *error); 
    31             void notifyLoadPassword (const gchar *fileName,  
     31            void notifyLoadPassword (const gchar *fileName, gboolean reload, 
    3232                                     const GError *error); 
    3333            void notifyPageChanged (gint pageNum); 
    3434            void notifyPageRotated (gint rotation); 
    3535            void notifyPageZoomed (gdouble zoom); 
     36            void notifyReload (void); 
    3637 
    3738            gint getCurrentPage (void); 
     
    5455            gboolean m_NotifiedPageRotated; 
    5556            gboolean m_NotifiedPageZoomed; 
     57            gboolean m_NotifiedReload; 
    5658            gdouble m_Zoom; 
    5759    }; 
  • trunk/tests/MainPterTest.cxx

    r134 r136  
    748748    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 
    749749} 
    750 /* 
     750 
    751751/// 
    752752/// @brief Test to reload a normal document. 
     
    828828/// @brief Tries to reload an encrypted file whose password changed. 
    829829/// 
    830 /// Reloading an encrypted file won't ask for the password unless it changed.  
     830/// Reloading an encrypted file won't ask for the password unless it changed. 
     831/// If the password changed, then the document starts on the first page. 
    831832/// 
    832833void 
     
    870871    CPPUNIT_ASSERT_EQUAL (1, m_View->countTimesShownPasswordPrompt ()); 
    871872} 
    872 */ 
     873 
    873874/// 
    874875/// @brief Checks that the index is shown when a document has outline. 
  • trunk/tests/MainPterTest.h

    r134 r136  
    4141        CPPUNIT_TEST (pageZoomFit); 
    4242        CPPUNIT_TEST (pageZoomAndRotate); 
    43 /*        CPPUNIT_TEST (reloadNormal); 
     43        CPPUNIT_TEST (reloadNormal); 
    4444        CPPUNIT_TEST (reloadEncrypted); 
    45         CPPUNIT_TEST (reloadChangedPassword);*/ 
     45        CPPUNIT_TEST (reloadChangedPassword); 
    4646        CPPUNIT_TEST (showIndex); 
    4747        CPPUNIT_TEST (showToolAndStatusBars); 
  • trunk/tests/Makefile.am

    r132 r136  
    2121    MainPterTest.cxx    \ 
    2222    MainPterTest.h  \ 
     23    PDFDocumentTest.cxx \ 
     24    PDFDocumentTest.h   \ 
    2325    Utils.cxx               \ 
    2426    Utils.h 
    2527 
    26 #   PDFDocumentTest.cxx 
    27 #   PDFDocumentTest.h 
    2828 
    2929test_epdfview_CXXFLAGS =                        \ 
  • trunk/tests/PDFDocumentTest.cxx

    r132 r136  
    583583    m_Document->zoomToWidth (300);  
    584584    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3562f, m_Document->getZoom (), DELTA); 
    585     DocumentPage *page = m_Document->getCurrentPage (); 
     585    DocumentPage *page = NULL; 
     586    while ( NULL == page || (DocumentPage *)0xdeadbeef == page ) 
     587    { 
     588        page = m_Document->getCurrentPage (); 
     589    } 
    586590    CPPUNIT_ASSERT (NULL != page); 
     591    CPPUNIT_ASSERT ((DocumentPage *)0xdeadbeef != page); 
    587592    CPPUNIT_ASSERT_EQUAL (300, page->getWidth ()); 
    588593    CPPUNIT_ASSERT_EQUAL (212, page->getHeight ());