Changeset 132
- Timestamp:
- 04/29/06 10:07:03 (2 years ago)
- Location:
- trunk
- Files:
-
- 12 modified
-
src/IDocument.cxx (modified) (4 diffs)
-
src/IDocument.h (modified) (1 diff)
-
src/IDocumentObserver.h (modified) (1 diff)
-
src/JobLoad.cxx (modified) (1 diff)
-
src/MainPter.cxx (modified) (6 diffs)
-
src/MainPter.h (modified) (2 diffs)
-
tests/DumbDocumentObserver.cxx (modified) (1 diff)
-
tests/DumbDocumentObserver.h (modified) (1 diff)
-
tests/MainPterTest.cxx (modified) (30 diffs)
-
tests/MainPterTest.h (modified) (3 diffs)
-
tests/Makefile.am (modified) (1 diff)
-
tests/PDFDocumentTest.cxx (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/IDocument.cxx
r130 r132 22 22 using namespace ePDFView; 23 23 24 G_LOCK_EXTERN (JobRender); 25 24 26 // Constants. 25 27 static const gdouble ZOOM_IN_FACTOR = 1.2; … … 31 33 /// This is the error domain that will be used to report Document's errors. 32 34 GQuark IDocument::errorQuark = 0; 33 34 G_LOCK_EXTERN (JobRender);35 35 36 36 /// … … 210 210 211 211 void 212 IDocument::notifyLoadPassword (const GError *error)212 IDocument::notifyLoadPassword (const gchar *fileName, const GError *error) 213 213 { 214 214 for ( GList *item = g_list_first (m_Observers) ; NULL != item ; … … 216 216 { 217 217 IDocumentObserver *observer = (IDocumentObserver *)item->data; 218 observer->notifyLoadPassword ( error);218 observer->notifyLoadPassword (fileName, error); 219 219 } 220 220 } -
trunk/src/IDocument.h
r130 r132 187 187 void notifyLoad (void); 188 188 void notifyLoadError (const GError *error); 189 void notifyLoadPassword (const GError *error); 189 void notifyLoadPassword (const gchar *fileName, 190 const GError *error); 190 191 void notifyPageChanged (void); 191 192 void notifyPageRendered (gint pageNumber, DocumentPage *pageImage); -
trunk/src/IDocumentObserver.h
r129 r132 28 28 virtual void notifyLoad (void) { } 29 29 virtual void notifyLoadError (const GError *error) { } 30 virtual void notifyLoadPassword (const GError *error) { } 30 virtual void notifyLoadPassword (const gchar *fileName, 31 const GError *error) { } 31 32 virtual void notifyPageChanged (gint pageNum) { } 32 33 virtual void notifyPageRotated (gint rotation) { } -
trunk/src/JobLoad.cxx
r126 r132 237 237 238 238 JobLoad *job = (JobLoad *)data; 239 job->getDocument ().notifyLoadPassword (job->getError ()); 239 job->getDocument ().notifyLoadPassword (job->getFileName (), 240 job->getError ()); 240 241 JOB_NOTIFIER_END(); 241 242 } -
trunk/src/MainPter.cxx
r124 r132 18 18 #include <config.h> 19 19 #include <stdlib.h> 20 #include <unistd.h> 20 21 #include "epdfview.h" 21 22 22 23 using namespace ePDFView; 23 24 25 #if defined (DEBUG) 26 static volatile gboolean fileLoaded; 27 #endif // DEBUG 28 24 29 /// 25 30 /// @brief Constructs a new main presenter with a default document. … … 27 32 MainPter::MainPter () 28 33 { 29 m_Document = new PDFDocument (); 30 m_View = NULL; 34 MainPter (new PDFDocument ()); 31 35 } 32 36 … … 43 47 44 48 m_Document = document; 49 m_Document->attach (this); 45 50 m_View = NULL; 51 m_PasswordTries = 3; 52 #if defined (DEBUG) 53 fileLoaded = FALSE; 54 #endif 46 55 } 47 56 … … 51 60 MainPter::~MainPter () 52 61 { 62 m_Document->deattach (this); 53 63 delete m_Document; 54 64 delete m_View; … … 289 299 config.setOpenFileFolder (dirName); 290 300 g_free (dirName); 291 } 292 293 // Open the file. 294 /* JobLoad *job = new JobLoad (); 295 job->setPresenter (this); 296 job->setFileName (fileName); 297 g_free (fileName); 298 job->setPassword (NULL); 299 job->setReload (FALSE); 300 job->run ();*/ 301 // Insensitive the open and reload controls. 302 IMainView &view = getView (); 303 view.sensitiveOpen (FALSE); 304 view.sensitiveReload (FALSE); 305 // Show the text on the status bar. 306 gchar *statusText = g_strdup_printf (_("Loading file %s..."), fileName); 307 view.setStatusBarText (statusText); 308 g_free (statusText); 309 // Set the wait cursor. 310 view.setCursor (MAIN_VIEW_CURSOR_WAIT); 311 // Set the number of times we can try the password. 312 m_PasswordTries = 3; 313 // Open the file. 314 m_Document->load (fileName, NULL); 315 } 301 316 } 302 317 … … 667 682 } 668 683 } 684 685 void 686 MainPter::notifyLoad () 687 { 688 setInitialState (TRUE); 689 #if defined (DEBUG) 690 fileLoaded = TRUE; 691 #endif // DEBUG 692 } 693 694 void 695 MainPter::notifyLoadError (const GError *error) 696 { 697 getView ().showErrorMessage (_("Error Loading File"), error->message); 698 setInitialState (TRUE); 699 #if defined (DEBUG) 700 fileLoaded = TRUE; 701 #endif // DEBUG 702 } 703 704 void 705 MainPter::notifyLoadPassword (const gchar *fileName, const GError *error) 706 { 707 if ( 0 < m_PasswordTries ) 708 { 709 m_PasswordTries--; 710 gchar *password = getView ().promptPasswordDialog (); 711 if ( password != NULL ) 712 { 713 m_Document->load (fileName, password); 714 } 715 #if defined (DEBUG) 716 else 717 { 718 fileLoaded = TRUE; 719 } 720 #endif // DEBUG 721 } 722 else 723 { 724 getView ().showErrorMessage (_("Error Loading File"), 725 _("The password you have supplied is not a valid password " 726 "for this file.")); 727 #if defined (DEBUG) 728 fileLoaded = TRUE; 729 #endif // DEBUG 730 } 731 } 732 733 #if defined (DEBUG) 734 /// 735 /// @brief Waits until a file is loaded. 736 /// 737 void 738 MainPter::waitForFileLoaded () 739 { 740 while ( !fileLoaded ) 741 { 742 usleep (10000); 743 } 744 fileLoaded = FALSE; 745 } 746 #endif // DEBUG -
trunk/src/MainPter.h
r123 r132 34 34 /// and how to react to main window's user events. 35 35 /// 36 class MainPter 36 class MainPter: public IDocumentObserver 37 37 { 38 38 public: … … 67 67 void zoomWidthActivated (gboolean active); 68 68 69 void notifyLoad (void); 70 void notifyLoadError (const GError *error); 71 void notifyLoadPassword (const gchar *fileName, 72 const GError *error); 73 74 #if defined (DEBUG) 75 void waitForFileLoaded (void); 76 #endif // DEBUG 77 69 78 protected: 79 IDocument *m_Document; 80 gint m_PasswordTries; 81 IMainView *m_View; 70 82 void showPage (PageScroll pageScroll); 71 72 IDocument *m_Document;73 IMainView *m_View;74 75 83 void zoomFit (void); 76 84 void zoomWidth (void); -
trunk/tests/DumbDocumentObserver.cxx
r129 r132 55 55 56 56 void 57 DumbDocumentObserver::notifyLoadPassword (const GError *error) 57 DumbDocumentObserver::notifyLoadPassword (const gchar *fileName, 58 const GError *error) 58 59 { 59 60 setLoadError (error); -
trunk/tests/DumbDocumentObserver.h
r129 r132 29 29 void notifyLoad (void); 30 30 void notifyLoadError (const GError *error); 31 void notifyLoadPassword (const GError *error); 31 void notifyLoadPassword (const gchar *fileName, 32 const GError *error); 32 33 void notifyPageChanged (gint pageNum); 33 34 void notifyPageRotated (gint rotation); -
trunk/tests/MainPterTest.cxx
r123 r132 23 23 using namespace ePDFView; 24 24 25 G_LOCK_EXTERN (JobRender); 26 25 27 // Register the test suite into the `registry'. 26 28 CPPUNIT_TEST_SUITE_REGISTRATION (MainPterTest); 27 28 // Constants.29 static const gint SLEEP_TIME = 250000;30 29 31 30 /// … … 40 39 m_MainPter->setView (m_View); 41 40 Config::loadFile (FALSE); 41 G_LOCK (JobRender); 42 JobRender::m_CanProcessJobs = TRUE; 43 G_UNLOCK (JobRender); 42 44 } 43 45 … … 48 50 MainPterTest::tearDown () 49 51 { 52 G_LOCK (JobRender); 53 JobRender::m_CanProcessJobs = FALSE; 54 IJob::clearQueue (); 55 G_UNLOCK (JobRender); 50 56 // We only need to delete the presenter, as all other 51 57 // classes are deleted by it. … … 102 108 m_View->setOpenFileName ("/tmp/test.pdf"); 103 109 m_MainPter->openFileActivated (); 104 // Sleep to let the thread open the file. 105 usleep (SLEEP_TIME); 110 m_MainPter->waitForFileLoaded (); 106 111 CPPUNIT_ASSERT_EQUAL (0, 107 112 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); … … 124 129 m_Document->setTitle (g_strdup ("Test PDF")); 125 130 m_MainPter->openFileActivated (); 126 // Sleep to let the thread open the file. 127 usleep (SLEEP_TIME); 131 m_MainPter->waitForFileLoaded (); 128 132 CPPUNIT_ASSERT_EQUAL (0, 129 133 g_ascii_strcasecmp ("Test PDF", m_View->getTitle ())); … … 145 149 146 150 /// 147 /// @brief Tests a cancel led open file.151 /// @brief Tests a canceled open file. 148 152 /// 149 153 /// When the user cancels the open dialog, then nothing should change. 150 154 /// 151 155 void 152 MainPterTest::loadCancel led ()156 MainPterTest::loadCanceled () 153 157 { 154 158 // returning a NULL file name is what will happen when cancel. 155 159 m_View->setOpenFileName (NULL); 156 160 m_MainPter->openFileActivated (); 157 // Sleep to let the thread open the file.158 usleep (SLEEP_TIME);159 161 CPPUNIT_ASSERT_EQUAL (0, 160 162 g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); … … 175 177 } 176 178 179 177 180 /// 178 181 /// @brief Test a failed load. 179 182 /// 180 183 /// A failed load (anything but a DocumentErrorNone and DocumentErrorEncrypted) 181 /// is very similar to the load cancel led, but an error message is shown184 /// is very similar to the load canceled, but an error message is shown 182 185 /// to the user. 183 186 /// … … 188 191 m_Document->setOpenError (DocumentErrorDamaged); 189 192 m_MainPter->openFileActivated (); 190 // Sleep to let the thread open the file. 191 usleep (SLEEP_TIME); 193 m_MainPter->waitForFileLoaded (); 192 194 CPPUNIT_ASSERT_EQUAL (0, 193 195 g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); … … 209 211 210 212 /// 211 /// @brief Test a cancel led password.212 /// 213 /// A cancel led password is more or less the same as cancelling the loading213 /// @brief Test a canceled password. 214 /// 215 /// A canceled password is more or less the same as canceling the loading 214 216 /// of a file. It's when the user tried to open an encrypted file, but when 215 217 /// the password is prompted, then it cancels :-) 216 /// It should happen the same as when cancel ling the open file dialog.217 /// 218 void 219 MainPterTest::cancel ledPassword ()218 /// It should happen the same as when canceling the open file dialog. 219 /// 220 void 221 MainPterTest::canceledPassword () 220 222 { 221 223 m_View->setOpenFileName ("/tmp/test.pdf"); … … 223 225 m_Document->setOpenError (DocumentErrorEncrypted); 224 226 m_MainPter->openFileActivated (); 225 // Sleep to let the thread open the file. 226 usleep (SLEEP_TIME); 227 m_MainPter->waitForFileLoaded (); 227 228 CPPUNIT_ASSERT_EQUAL (0, 228 229 g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); … … 258 259 m_Document->setOpenError (DocumentErrorEncrypted); 259 260 m_MainPter->openFileActivated (); 260 // Sleep to let the thread open the file. 261 usleep (SLEEP_TIME); 261 m_MainPter->waitForFileLoaded (); 262 262 CPPUNIT_ASSERT_EQUAL (0, 263 263 g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); … … 293 293 m_Document->setOpenError (DocumentErrorEncrypted); 294 294 m_MainPter->openFileActivated (); 295 // Sleep to let the thread open the file. 296 usleep (SLEEP_TIME); 295 m_MainPter->waitForFileLoaded (); 297 296 CPPUNIT_ASSERT_EQUAL (0, 298 297 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); … … 313 312 CPPUNIT_ASSERT_EQUAL (1, m_View->countTimesShownPasswordPrompt ()); 314 313 } 315 314 /* 316 315 /// 317 316 /// @brief Test the last folder used to open a file. … … 326 325 m_View->setOpenFileName ("/tmp/test.pdf"); 327 326 m_MainPter->openFileActivated (); 328 // Sleep to let the thread open the file. 329 usleep (SLEEP_TIME); 327 m_MainPter->waitForFileLoaded (); 330 328 CPPUNIT_ASSERT (NULL == m_View->getLastOpenFileFolder ()); 331 329 … … 333 331 m_View->setOpenFileName ("/usr/test.pdf"); 334 332 m_MainPter->openFileActivated (); 335 // Sleep to let the thread open the file. 336 usleep (SLEEP_TIME); 333 m_MainPter->waitForFileLoaded (); 337 334 CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/tmp", 338 335 m_View->getLastOpenFileFolder ())); 339 336 340 337 m_MainPter->openFileActivated (); 341 // Sleep to let the thread open the file. 342 usleep (SLEEP_TIME); 338 m_MainPter->waitForFileLoaded (); 343 339 CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/usr", 344 340 m_View->getLastOpenFileFolder ())); … … 357 353 m_Document->setNumPages (4); 358 354 m_MainPter->openFileActivated (); 359 // Sleep to let the thread open the file. 360 usleep (SLEEP_TIME); 355 m_MainPter->waitForFileLoaded (); 361 356 // Check that sets the correct number of pages and the current page. 362 357 CPPUNIT_ASSERT_EQUAL (4, m_View->getTotalPages ()); … … 439 434 m_Document->setNumPages (4); 440 435 m_MainPter->openFileActivated (); 441 // Sleep to let the thread open the file. 442 usleep (SLEEP_TIME); 436 m_MainPter->waitForFileLoaded (); 443 437 // Check that sets the correct number of pages and the current page. 444 438 CPPUNIT_ASSERT_EQUAL (4, m_View->getTotalPages ()); … … 520 514 m_View->setOpenFileName ("/tmp/test.pdf"); 521 515 m_MainPter->openFileActivated (); 522 // Sleep to let the thread open the file. 523 usleep (SLEEP_TIME); 516 m_MainPter->waitForFileLoaded (); 524 517 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 525 518 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); … … 550 543 m_View->setOpenFileName ("/tmp/test.pdf"); 551 544 m_MainPter->openFileActivated (); 552 // Sleep to let the thread open the file. 553 usleep (SLEEP_TIME); 545 m_MainPter->waitForFileLoaded (); 554 546 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 555 547 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); … … 591 583 m_View->setOpenFileName ("/tmp/test.pdf"); 592 584 m_MainPter->openFileActivated (); 593 // Sleep to let the thread open the file. 594 usleep (SLEEP_TIME); 585 m_MainPter->waitForFileLoaded (); 595 586 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 596 587 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); … … 657 648 m_View->setOpenFileName ("/tmp/test.pdf"); 658 649 m_MainPter->openFileActivated (); 659 // Sleep to let the thread open the file. 660 usleep (SLEEP_TIME); 650 m_MainPter->waitForFileLoaded (); 661 651 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 662 652 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); … … 722 712 m_View->setOpenFileName ("/tmp/test.pdf"); 723 713 m_MainPter->openFileActivated (); 724 // Sleep to let the thread open the file. 725 usleep (SLEEP_TIME); 714 m_MainPter->waitForFileLoaded (); 726 715 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 727 716 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); … … 767 756 m_View->setOpenFileName ("/tmp/test.pdf"); 768 757 m_MainPter->openFileActivated (); 769 // Sleep to let the thread open the file. 770 usleep (SLEEP_TIME); 758 m_MainPter->waitForFileLoaded (); 771 759 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 772 760 … … 781 769 // Reload the document. 782 770 m_MainPter->reloadActivated (); 783 // Sleep to let the thread open the file. 784 usleep (SLEEP_TIME); 771 m_MainPter->waitForFileLoaded (); 785 772 CPPUNIT_ASSERT_EQUAL (0, 786 773 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); … … 805 792 m_Document->setOpenError (DocumentErrorEncrypted); 806 793 m_MainPter->openFileActivated (); 807 // Sleep to let the thread open the file. 808 usleep (SLEEP_TIME); 794 m_MainPter->waitForFileLoaded (); 809 795 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 810 796 CPPUNIT_ASSERT_EQUAL (0, … … 824 810 m_Document->setOpenError (DocumentErrorEncrypted); 825 811 m_MainPter->reloadActivated (); 826 // Sleep to let the thread open the file. 827 usleep (SLEEP_TIME); 812 m_MainPter->waitForFileLoaded (); 828 813 CPPUNIT_ASSERT_EQUAL (0, 829 814 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); … … 849 834 m_Document->setOpenError (DocumentErrorEncrypted); 850 835 m_MainPter->openFileActivated (); 851 // Sleep to let the thread open the file. 852 usleep (SLEEP_TIME); 836 m_MainPter->waitForFileLoaded (); 853 837 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 854 838 CPPUNIT_ASSERT_EQUAL (0, … … 870 854 m_Document->setOpenError (DocumentErrorEncrypted); 871 855 m_MainPter->reloadActivated (); 872 // Sleep to let the thread open the file. 873 usleep (SLEEP_TIME); 856 m_MainPter->waitForFileLoaded (); 874 857 CPPUNIT_ASSERT_EQUAL (0, 875 858 g_ascii_strcasecmp("newpassword", m_Document->getPassword ())); … … 906 889 m_View->setOpenFileName ("/tmp/test.pdf"); 907 890 m_MainPter->openFileActivated (); 908 // Sleep to let the thread open the file. 909 usleep (SLEEP_TIME); 891 m_MainPter->waitForFileLoaded (); 910 892 CPPUNIT_ASSERT (m_View->isShownIndex ()); 911 893 CPPUNIT_ASSERT (outline == m_View->getOutline ()); … … 951 933 CPPUNIT_ASSERT (m_View->isShownStatusbar ()); 952 934 } 935 */ -
trunk/tests/MainPterTest.h
r123 r132 28 28 CPPUNIT_TEST (initialStatus); 29 29 CPPUNIT_TEST (loadDocument); 30 CPPUNIT_TEST (loadCancel led);30 CPPUNIT_TEST (loadCanceled); 31 31 CPPUNIT_TEST (loadFailed); 32 CPPUNIT_TEST (cancel ledPassword);32 CPPUNIT_TEST (canceledPassword); 33 33 CPPUNIT_TEST (badPassword); 34 34 CPPUNIT_TEST (goodPassword); 35 CPPUNIT_TEST (lastFolder);35 /* CPPUNIT_TEST (lastFolder); 36 36 CPPUNIT_TEST (pageNavigation); 37 37 CPPUNIT_TEST (pageNavigationEntry); … … 45 45 CPPUNIT_TEST (reloadChangedPassword); 46 46 CPPUNIT_TEST (showIndex); 47 CPPUNIT_TEST (showToolAndStatusBars); 47 CPPUNIT_TEST (showToolAndStatusBars);*/ 48 48 CPPUNIT_TEST_SUITE_END(); 49 49 … … 54 54 void initialStatus (void); 55 55 void loadDocument (void); 56 void loadCancel led (void);56 void loadCanceled (void); 57 57 void loadFailed (void); 58 void cancel ledPassword (void);58 void canceledPassword (void); 59 59 void badPassword (void); 60 60 void goodPassword (void); -
trunk/tests/Makefile.am
r131 r132 19 19 DumbMainView.h \ 20 20 main.cxx \ 21 PDFDocumentTest.cxx\22 PDFDocumentTest.h\21 MainPterTest.cxx \ 22 MainPterTest.h \ 23 23 Utils.cxx \ 24 24 Utils.h 25 25 26 27 # MainPterTest.cxx 28 # MainPterTest.h 26 # PDFDocumentTest.cxx 27 # PDFDocumentTest.h 29 28 30 29 test_epdfview_CXXFLAGS = \ -
trunk/tests/PDFDocumentTest.cxx
r130
