Changeset 136
- Timestamp:
- 04/29/06 14:09:50 (2 years ago)
- Location:
- trunk
- Files:
-
- 13 modified
-
src/IDocument.cxx (modified) (5 diffs)
-
src/IDocument.h (modified) (3 diffs)
-
src/IDocumentObserver.h (modified) (1 diff)
-
src/JobLoad.cxx (modified) (11 diffs)
-
src/JobLoad.h (modified) (1 diff)
-
src/MainPter.cxx (modified) (5 diffs)
-
src/MainPter.h (modified) (1 diff)
-
tests/DumbDocumentObserver.cxx (modified) (4 diffs)
-
tests/DumbDocumentObserver.h (modified) (2 diffs)
-
tests/MainPterTest.cxx (modified) (3 diffs)
-
tests/MainPterTest.h (modified) (1 diff)
-
tests/Makefile.am (modified) (1 diff)
-
tests/PDFDocumentTest.cxx (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/IDocument.cxx
r135 r136 211 211 212 212 void 213 IDocument::notifyLoadPassword (const gchar *fileName, const GError *error) 213 IDocument::notifyLoadPassword (const gchar *fileName, gboolean reload, 214 const GError *error) 214 215 { 215 216 for ( GList *item = g_list_first (m_Observers) ; NULL != item ; … … 217 218 { 218 219 IDocumentObserver *observer = (IDocumentObserver *)item->data; 219 observer->notifyLoadPassword (fileName, error);220 observer->notifyLoadPassword (fileName, reload, error); 220 221 } 221 222 } … … 272 273 IDocumentObserver *observer = (IDocumentObserver *)item->data; 273 274 observer->notifyPageZoomed (zoom); 275 } 276 } 277 278 void 279 IDocument::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 (); 274 291 } 275 292 } … … 286 303 job->setFileName (fileName); 287 304 job->setPassword (password); 305 IJob::queue (job); 306 } 307 308 void 309 IDocument::reload (void) 310 { 311 JobLoad *job = new JobLoad (); 312 job->setDocument (this); 313 job->setFileName (getFileName ()); 314 job->setPassword (getPassword ()); 315 job->setReload (TRUE); 288 316 IJob::queue (job); 289 317 } … … 1123 1151 { 1124 1152 PageCache *tmpCached = (PageCache *)page->data; 1125 if ( pageNum == tmpCached->pageNumber )1153 if ( NULL != tmpCached && pageNum == tmpCached->pageNumber ) 1126 1154 { 1127 1155 cached = tmpCached; -
trunk/src/IDocument.h
r135 r136 187 187 void notifyLoad (void); 188 188 void notifyLoadError (const GError *error); 189 void notifyLoadPassword (const gchar *fileName, 189 void notifyLoadPassword (const gchar *fileName, gboolean reload, 190 190 const GError *error); 191 191 void notifyPageChanged (void); … … 194 194 void notifyPageRotated (void); 195 195 void notifyPageZoomed (void); 196 void notifyReload (void); 196 197 197 198 const gchar *getTitle (void); … … 233 234 234 235 void load (const gchar *fileName, const gchar *password); 236 void reload (void); 235 237 236 238 void goToFirstPage (void); -
trunk/src/IDocumentObserver.h
r132 r136 29 29 virtual void notifyLoadError (const GError *error) { } 30 30 virtual void notifyLoadPassword (const gchar *fileName, 31 gboolean reload, 31 32 const GError *error) { } 32 33 virtual void notifyPageChanged (gint pageNum) { } 33 34 virtual void notifyPageRotated (gint rotation) { } 34 35 virtual void notifyPageZoomed (gdouble zoom) { } 36 virtual void notifyReload (void) { } 35 37 36 38 protected: -
trunk/src/JobLoad.cxx
r134 r136 25 25 static gboolean job_load_error (gpointer data); 26 26 static gboolean job_load_password (gpointer data); 27 static gboolean job_reload_done (gpointer data); 27 28 28 29 /// … … 32 33 IJob () 33 34 { 35 m_Document = NULL; 36 m_Error = NULL; 34 37 m_FileName = NULL; 35 m_Error = NULL;36 38 m_Password = NULL; 37 m_ Document = NULL;39 m_Reload = FALSE; 38 40 } 39 41 … … 52 54 53 55 /// 56 /// @brief The document that's loading. 57 /// 58 /// @return The document that is loading. 59 /// 60 IDocument & 61 JobLoad::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 /// 73 GError * 74 JobLoad::getError () 75 { 76 return m_Error; 77 } 78 79 /// 54 80 /// @brief Gets the file name to load or reload. 55 81 /// … … 63 89 64 90 /// 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 ///76 91 /// @brief Gets the password. 77 92 /// … … 85 100 86 101 /// 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 /// 106 gboolean 107 JobLoad::isReloading () 108 { 109 return m_Reload; 110 } 99 111 100 112 /// … … 108 120 if ( getDocument ().loadFile (getFileName (), getPassword (), &error) ) 109 121 { 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 } 111 130 } 112 131 else … … 127 146 128 147 /// 148 /// @brief Sets the document to load. 149 /// 150 /// @param document The document that will load. 151 /// 152 void 153 JobLoad::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 /// 165 void 166 JobLoad::setError (GError *error) 167 { 168 if ( NULL != m_Error ) 169 { 170 g_error_free (m_Error); 171 } 172 m_Error = error; 173 } 174 175 /// 129 176 /// @brief Sets the file name to open. 130 177 /// … … 139 186 140 187 /// 141 /// @brief Sets the last error.142 ///143 /// @param error The last error opening a file.144 ///145 void146 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 ///156 188 /// @brief Sets the password to open the document. 157 189 /// … … 166 198 167 199 /// 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 /// 204 void 205 JobLoad::setReload (gboolean reload) 206 { 207 m_Reload = reload; 208 } 180 209 181 210 //////////////////////////////////////////////////////////////// … … 238 267 JobLoad *job = (JobLoad *)data; 239 268 job->getDocument ().notifyLoadPassword (job->getFileName (), 269 job->isReloading (), 240 270 job->getError ()); 241 271 JOB_NOTIFIER_END(); … … 243 273 return FALSE; 244 274 } 275 276 /// 277 /// @brief The reload is finished correctly. 278 /// 279 /// @param data This parameter holds the JobLoad that finished. 280 /// 281 gboolean 282 job_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 40 40 const gchar *getFileName (void); 41 41 const gchar *getPassword (void); 42 gboolean isReloading (void); 42 43 gboolean run (void); 44 void setDocument (IDocument *document); 45 void setError (GError *error); 43 46 void setFileName (const gchar *fileName); 44 void setError (GError *error);45 47 void setPassword (const gchar *password); 46 void set Document (IDocument *document);48 void setReload (gboolean reload); 47 49 48 50 protected: 51 IDocument *m_Document; 52 GError *m_Error; 49 53 gchar *m_FileName; 50 GError *m_Error;51 54 gchar *m_Password; 52 IDocument *m_Document;55 gboolean m_Reload; 53 56 }; 54 57 } -
trunk/src/MainPter.cxx
r135 r136 158 158 // Remove the status bar text. 159 159 view.setStatusBarText (NULL); 160 // Show the normal cursor. 161 view.setCursor (MAIN_VIEW_CURSOR_NORMAL); 160 162 // Show the first page *AFTER* showing the sidebar because 161 163 // the view change the row to the first outline that doesn't need 162 164 // to be the first page. If we don't do this, the first page pointed 163 165 // 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.168 166 if ( m_Document->isLoaded () && canShowPage ) 169 167 { 168 m_Document->goToFirstPage (); 170 169 refreshPage (PAGE_SCROLL_START); 171 170 } … … 398 397 MainPter::reloadActivated () 399 398 { 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 (); 411 417 } 412 418 … … 702 708 703 709 void 704 MainPter::notifyLoadPassword (const gchar *fileName, const GError *error)710 MainPter::notifyLoadPassword (const gchar *fileName, gboolean reload, const GError *error) 705 711 { 706 712 if ( 0 < m_PasswordTries ) … … 710 716 if ( password != NULL ) 711 717 { 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 } 713 727 } 714 728 #if defined (DEBUG) … … 778 792 } 779 793 794 void 795 MainPter::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 780 806 #if defined (DEBUG) 781 807 /// -
trunk/src/MainPter.h
r134 r136 68 68 void notifyLoad (void); 69 69 void notifyLoadError (const GError *error); 70 void notifyLoadPassword (const gchar *fileName, 70 void notifyLoadPassword (const gchar *fileName, gboolean reload, 71 71 const GError *error); 72 72 void notifyPageChanged (gint pageNum); 73 73 void notifyPageRotated (gint rotation); 74 74 void notifyPageZoomed (gdouble zoom); 75 void notifyReload (void); 75 76 76 77 static gboolean pageNotAvailable (gpointer user); -
trunk/tests/DumbDocumentObserver.cxx
r132 r136 31 31 m_NotifiedPageRotated = FALSE; 32 32 m_NotifiedPageZoomed = FALSE; 33 m_NotifiedReload = FALSE; 33 34 m_Zoom = 0.0; 34 35 } … … 55 56 56 57 void 57 DumbDocumentObserver::notifyLoadPassword (const gchar *fileName, 58 DumbDocumentObserver::notifyLoadPassword (const gchar *fileName, 59 gboolean reload, 58 60 const GError *error) 59 61 { … … 79 81 m_NotifiedPageZoomed = TRUE; 80 82 m_Zoom = zoom; 83 } 84 85 void 86 DumbDocumentObserver::notifyReload (void) 87 { 88 m_NotifiedReload; 81 89 } 82 90 … … 106 114 DumbDocumentObserver::loadFinished (void) 107 115 { 108 return m_NotifiedError || m_NotifiedPassword || m_NotifiedLoad; 116 return m_NotifiedError || m_NotifiedPassword || m_NotifiedLoad || 117 m_NotifiedReload; 109 118 } 110 119 -
trunk/tests/DumbDocumentObserver.h
r132 r136 29 29 void notifyLoad (void); 30 30 void notifyLoadError (const GError *error); 31 void notifyLoadPassword (const gchar *fileName, 31 void notifyLoadPassword (const gchar *fileName, gboolean reload, 32 32 const GError *error); 33 33 void notifyPageChanged (gint pageNum); 34 34 void notifyPageRotated (gint rotation); 35 35 void notifyPageZoomed (gdouble zoom); 36 void notifyReload (void); 36 37 37 38 gint getCurrentPage (void); … … 54 55 gboolean m_NotifiedPageRotated; 55 56 gboolean m_NotifiedPageZoomed; 57 gboolean m_NotifiedReload; 56 58 gdouble m_Zoom; 57 59 }; -
trunk/tests/MainPterTest.cxx
r134 r136 748 748 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 749 749 } 750 /* 750 751 751 /// 752 752 /// @brief Test to reload a normal document. … … 828 828 /// @brief Tries to reload an encrypted file whose password changed. 829 829 /// 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. 831 832 /// 832 833 void … … 870 871 CPPUNIT_ASSERT_EQUAL (1, m_View->countTimesShownPasswordPrompt ()); 871 872 } 872 */ 873 873 874 /// 874 875 /// @brief Checks that the index is shown when a document has outline. -
trunk/tests/MainPterTest.h
r134 r136 41 41 CPPUNIT_TEST (pageZoomFit); 42 42 CPPUNIT_TEST (pageZoomAndRotate); 43 /*CPPUNIT_TEST (reloadNormal);43 CPPUNIT_TEST (reloadNormal); 44 44 CPPUNIT_TEST (reloadEncrypted); 45 CPPUNIT_TEST (reloadChangedPassword); */45 CPPUNIT_TEST (reloadChangedPassword); 46 46 CPPUNIT_TEST (showIndex); 47 47 CPPUNIT_TEST (showToolAndStatusBars); -
trunk/tests/Makefile.am
r132 r136 21 21 MainPterTest.cxx \ 22 22 MainPterTest.h \ 23 PDFDocumentTest.cxx \ 24 PDFDocumentTest.h \ 23 25 Utils.cxx \ 24 26 Utils.h 25 27 26 # PDFDocumentTest.cxx27 # PDFDocumentTest.h28 28 29 29 test_epdfview_CXXFLAGS = \ -
trunk/tests/PDFDocumentTest.cxx
r132 r136 583 583 m_Document->zoomToWidth (300); 584 584 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 } 586 590 CPPUNIT_ASSERT (NULL != page); 591 CPPUNIT_ASSERT ((DocumentPage *)0xdeadbeef != page); 587 592 CPPUNIT_ASSERT_EQUAL (300, page->getWidth ()); 588 593 CPPUNIT_ASSERT_EQUAL (212, page->getHeight ());
