Changeset 134
- Timestamp:
- 04/29/06 12:38:36 (2 years ago)
- Location:
- trunk
- Files:
-
- 8 modified
-
src/IDocument.cxx (modified) (6 diffs)
-
src/JobLoad.cxx (modified) (1 diff)
-
src/JobRender.cxx (modified) (2 diffs)
-
src/MainPter.cxx (modified) (26 diffs)
-
src/MainPter.h (modified) (3 diffs)
-
src/main.cxx (modified) (3 diffs)
-
tests/MainPterTest.cxx (modified) (6 diffs)
-
tests/MainPterTest.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/IDocument.cxx
r132 r134 23 23 24 24 G_LOCK_EXTERN (JobRender); 25 G_LOCK_DEFINE_STATIC (pageImage); 25 26 26 27 // Constants. … … 231 232 } 232 233 } 233 #include <stdio.h> 234 234 235 void 235 236 IDocument::notifyPageRendered (gint pageNumber, DocumentPage *pageImage) … … 238 239 if ( NULL != cachedPage ) 239 240 { 241 G_LOCK (pageImage); 240 242 delete cachedPage->pageImage; 241 243 cachedPage->pageImage = pageImage; 244 G_UNLOCK (pageImage); 242 245 } 243 246 } … … 733 736 } 734 737 735 while ( NULL == cachedPage->pageImage ) 736 { 737 ; 738 } 739 740 return cachedPage->pageImage; 738 G_LOCK (pageImage); 739 DocumentPage *pageImage = cachedPage->pageImage; 740 G_UNLOCK (pageImage); 741 742 return pageImage; 741 743 } 742 744 … … 886 888 m_Rotation = (rotation % 360); 887 889 refreshCache (); 890 G_UNLOCK (JobRender); 888 891 notifyPageRotated (); 889 G_UNLOCK (JobRender);890 892 } 891 893 } … … 964 966 m_Scale = zoom; 965 967 refreshCache (); 968 G_UNLOCK (JobRender); 966 969 notifyPageZoomed (); 967 G_UNLOCK (JobRender);968 970 } 969 971 } -
trunk/src/JobLoad.cxx
r132 r134 240 240 job->getError ()); 241 241 JOB_NOTIFIER_END(); 242 } 242 243 return FALSE; 244 } -
trunk/src/JobRender.cxx
r130 r134 47 47 { 48 48 m_PageImage = doc->renderPage (getPageNumber ()); 49 G_UNLOCK (JobRender); 49 50 JOB_NOTIFIER (job_render_done, this); 50 51 return JOB_DELETE; … … 102 103 g_assert (NULL != data && "The data parameter is NULL."); 103 104 105 G_LOCK (JobRender); 106 104 107 JobRender *job = (JobRender *)data; 105 108 IDocument *doc = job->getDocument (); -
trunk/src/MainPter.cxx
r132 r134 24 24 25 25 #if defined (DEBUG) 26 G_LOCK_DEFINE_STATIC (fileLoaded); 26 27 static volatile gboolean fileLoaded; 27 28 #endif // DEBUG 29 30 // Forward declarations. 31 static gboolean page_not_available (gpointer); 32 33 typedef struct 34 { 35 MainPter *pter; 36 PageScroll scroll; 37 } PageNotAvailableData; 28 38 29 39 /// … … 50 60 m_View = NULL; 51 61 m_PasswordTries = 3; 62 m_NextPageScroll = PAGE_SCROLL_START; 52 63 #if defined (DEBUG) 64 G_LOCK (fileLoaded); 53 65 fileLoaded = FALSE; 66 G_UNLOCK (fileLoaded); 54 67 #endif 55 68 } … … 119 132 0 < m_Document->getOutline ()->getNumChildren () && 120 133 PageModeOutlines == m_Document->getPageMode ()); 121 122 if ( canShowPage ) 123 { 124 showPage (PAGE_SCROLL_START); 125 } 134 126 135 } 127 136 else … … 159 168 // Show the normal cursor. 160 169 view.setCursor (MAIN_VIEW_CURSOR_NORMAL); 161 view.show (); 170 view.show (); 171 172 if ( m_Document->isLoaded () && canShowPage ) 173 { 174 refreshPage (PAGE_SCROLL_START); 175 } 162 176 } 163 177 … … 200 214 g_assert (NULL != m_Document && 201 215 "Tried to go to the first page of a NULL document."); 202 216 217 m_NextPageScroll = PAGE_SCROLL_START; 203 218 m_Document->goToFirstPage (); 204 showPage (PAGE_SCROLL_START);205 219 } 206 220 … … 214 228 "Tried to go to the last page of a NULL document."); 215 229 230 m_NextPageScroll = PAGE_SCROLL_START; 216 231 m_Document->goToLastPage (); 217 showPage (PAGE_SCROLL_START);218 232 } 219 233 … … 229 243 if ( m_Document->getCurrentPageNum () < m_Document->getNumPages () ) 230 244 { 245 m_NextPageScroll = PAGE_SCROLL_START; 231 246 m_Document->goToNextPage (); 232 showPage (PAGE_SCROLL_START);233 247 } 234 248 } … … 254 268 int pageNum = atoi (goToPageText); 255 269 // If the page number is too high, the Document class will 256 // go to the last page. The same if it's too low. 270 // remain to the same page page. The same if it's too low. 271 m_NextPageScroll = PAGE_SCROLL_START; 257 272 m_Document->goToPage (pageNum); 258 showPage (PAGE_SCROLL_START); 273 274 // Set the text for the current page. 275 gint newPageNum = m_Document->getCurrentPageNum (); 276 gint totalPages = m_Document->getNumPages (); 277 gchar *goToPageText = g_strdup_printf (_("%d of %d"), 278 newPageNum, totalPages); 279 getView ().setGoToPageText (goToPageText); 280 g_free (goToPageText); 281 259 282 } 260 283 } … … 272 295 if ( 1 < m_Document->getCurrentPageNum () ) 273 296 { 297 m_NextPageScroll = PAGE_SCROLL_END; 274 298 m_Document->goToPreviousPage (); 275 showPage (PAGE_SCROLL_END);276 299 } 277 300 } … … 329 352 g_assert (NULL != outline && "The outline activated is NULL."); 330 353 354 m_NextPageScroll = PAGE_SCROLL_START; 331 355 m_Document->goToPage (outline->getDestinationPage ()); 332 showPage (PAGE_SCROLL_START);333 356 } 334 357 … … 358 381 if ( config.zoomToFit () ) 359 382 { 383 m_NextPageScroll = PAGE_SCROLL_NONE; 360 384 m_Document->zoomToFit (width, height); 361 showPage (PAGE_SCROLL_NONE);362 385 } 363 386 else if ( config.zoomToWidth () ) 364 387 { 388 m_NextPageScroll = PAGE_SCROLL_NONE; 365 389 m_Document->zoomToWidth (width); 366 showPage (PAGE_SCROLL_NONE);367 390 } 368 391 } … … 398 421 g_assert ( NULL != m_Document && "Tried to rotate a NULL document."); 399 422 423 m_NextPageScroll = PAGE_SCROLL_START; 400 424 m_Document->rotateLeft (); 401 425 … … 409 433 zoomFit (); 410 434 } 411 showPage (PAGE_SCROLL_START);412 435 } 413 436 … … 420 443 g_assert ( NULL != m_Document && "Tried to rotate a NULL document."); 421 444 445 m_NextPageScroll = PAGE_SCROLL_START; 422 446 m_Document->rotateRight (); 423 424 447 Config &config = Config::getConfig (); 425 448 if ( config.zoomToWidth () ) … … 431 454 zoomFit (); 432 455 } 433 showPage (PAGE_SCROLL_START); 434 } 435 436 /// 437 /// @brief Sets the document context. 438 /// 439 /// By context I mean the rotation, zoom and current page number 440 /// of the document. 441 /// This function is used when reloading to restore the previous 442 /// context (a la function call). 443 /// 444 /// @param pageNum The current document's page number. 445 /// @param rotation The current document's rotation. 446 /// @param zoom The current document's zoom. 447 /// 448 void 449 MainPter::setContext (gint pageNum, gint rotation, gdouble zoom) 450 { 451 m_Document->setZoom (zoom); 452 m_Document->setRotation (rotation); 453 m_Document->goToPage (pageNum); 454 // Draw the document. 455 showPage (PAGE_SCROLL_NONE); 456 } 457 456 } 458 457 459 458 /// … … 524 523 if ( active ) 525 524 { 525 m_NextPageScroll = PAGE_SCROLL_NONE; 526 526 zoomFit (); 527 showPage (PAGE_SCROLL_NONE);528 527 } 529 528 } … … 545 544 view.activeZoomWidth (FALSE); 546 545 546 m_NextPageScroll = PAGE_SCROLL_NONE; 547 547 m_Document->zoomIn (); 548 showPage (PAGE_SCROLL_NONE);549 548 } 550 549 … … 564 563 view.activeZoomFit (FALSE); 565 564 view.activeZoomWidth (FALSE); 566 565 566 m_NextPageScroll = PAGE_SCROLL_NONE; 567 567 m_Document->zoomOut (); 568 showPage (PAGE_SCROLL_NONE);569 568 } 570 569 … … 601 600 if ( active ) 602 601 { 602 m_NextPageScroll = PAGE_SCROLL_NONE; 603 603 zoomWidth (); 604 showPage (PAGE_SCROLL_NONE);605 604 } 606 605 } … … 641 640 642 641 /// 643 /// @brief Shows the current page.642 /// @brief Refreshes the current page. 644 643 /// 645 644 /// This function is called when the presenter needs to show a document's … … 651 650 /// 652 651 void 653 MainPter:: showPage (PageScroll pageScroll)652 MainPter::refreshPage (PageScroll pageScroll) 654 653 { 655 654 g_assert (NULL != m_Document && 656 655 "Tried to show a page from a NULL document."); 657 g_assert (m_Document->isLoaded () && 658 "Tried to show a page from a not loaded document."); 659 660 IMainView &view = getView (); 661 // Set the text for the current page. 662 gint currentPage = m_Document->getCurrentPageNum (); 663 gint totalPages = m_Document->getNumPages (); 664 gchar *goToPageText = g_strdup_printf (_("%d of %d"), 665 currentPage, totalPages); 666 view.setGoToPageText (goToPageText); 667 g_free (goToPageText); 668 669 // Set the page navigation sensitivity. 670 view.sensitiveGoToFirstPage (1 < currentPage ); 671 view.sensitiveGoToPreviousPage (1 < currentPage ); 672 view.sensitiveGoToLastPage (m_Document->getNumPages() > currentPage); 673 view.sensitiveGoToNextPage (m_Document->getNumPages() > currentPage); 674 // And the zoom sensitivity. 675 view.sensitiveZoomIn (m_Document->canZoomIn ()); 676 view.sensitiveZoomOut (m_Document->canZoomOut ()); 677 678 DocumentPage *documentPage = m_Document->getCurrentPage (); 679 if ( NULL != documentPage ) 680 { 681 getView ().showPage (documentPage, pageScroll); 656 657 if ( m_Document->isLoaded () ) 658 { 659 DocumentPage *documentPage = m_Document->getCurrentPage (); 660 if ( NULL != documentPage ) 661 { 662 getView ().showPage (documentPage, pageScroll); 663 } 664 else 665 { 666 PageNotAvailableData *data = new PageNotAvailableData; 667 data->pter = this; 668 data->scroll = pageScroll; 669 g_timeout_add (50, MainPter::pageNotAvailable, data); 670 } 682 671 } 683 672 } … … 687 676 { 688 677 setInitialState (TRUE); 678 notifyPageChanged (1); 689 679 #if defined (DEBUG) 680 G_LOCK (fileLoaded); 690 681 fileLoaded = TRUE; 682 G_UNLOCK (fileLoaded); 691 683 #endif // DEBUG 692 684 } … … 696 688 { 697 689 getView ().showErrorMessage (_("Error Loading File"), error->message); 698 setInitialState ( TRUE);690 setInitialState (FALSE); 699 691 #if defined (DEBUG) 692 G_LOCK (fileLoaded); 700 693 fileLoaded = TRUE; 694 G_UNLOCK (fileLoaded); 701 695 #endif // DEBUG 702 696 } … … 716 710 else 717 711 { 712 G_LOCK (fileLoaded); 718 713 fileLoaded = TRUE; 714 G_UNLOCK (fileLoaded); 719 715 } 720 716 #endif // DEBUG … … 725 721 _("The password you have supplied is not a valid password " 726 722 "for this file.")); 727 #if defined (DEBUG) 723 setInitialState (FALSE); 724 #if defined (DEBUG) 725 G_LOCK (fileLoaded); 728 726 fileLoaded = TRUE; 727 G_UNLOCK (fileLoaded); 729 728 #endif // DEBUG 730 729 } 731 730 } 732 731 732 void 733 MainPter::notifyPageChanged (gint pageNum) 734 { 735 IMainView &view = getView (); 736 // Set the text for the current page. 737 gint totalPages = m_Document->getNumPages (); 738 gchar *goToPageText = g_strdup_printf (_("%d of %d"), pageNum, totalPages); 739 view.setGoToPageText (goToPageText); 740 g_free (goToPageText); 741 742 // Set the page navigation sensitivity. 743 gboolean documentLoaded = m_Document->isLoaded (); 744 gint numPages = m_Document->getNumPages (); 745 view.sensitiveGoToFirstPage (documentLoaded && 1 < pageNum ); 746 view.sensitiveGoToPreviousPage (documentLoaded && 1 < pageNum ); 747 view.sensitiveGoToLastPage (documentLoaded && numPages > pageNum); 748 view.sensitiveGoToNextPage (documentLoaded && numPages > pageNum); 749 750 refreshPage (m_NextPageScroll); 751 } 752 753 void 754 MainPter::notifyPageRotated (gint rotation) 755 { 756 IMainView &view = getView (); 757 // Set the zoom sensitivity. 758 view.sensitiveZoomIn (m_Document->canZoomIn ()); 759 view.sensitiveZoomOut (m_Document->canZoomOut ()); 760 761 refreshPage (m_NextPageScroll); 762 } 763 764 void 765 MainPter::notifyPageZoomed (gdouble zoom) 766 { 767 IMainView &view = getView (); 768 // Set the zoom sensitivity. 769 view.sensitiveZoomIn (m_Document->canZoomIn ()); 770 view.sensitiveZoomOut (m_Document->canZoomOut ()); 771 772 refreshPage (m_NextPageScroll); 773 } 774 733 775 #if defined (DEBUG) 734 776 /// … … 738 780 MainPter::waitForFileLoaded () 739 781 { 740 while ( !fileLoaded ) 741 { 742 usleep (10000); 743 } 782 volatile gboolean end = FALSE; 783 do 784 { 785 G_LOCK (fileLoaded); 786 end = fileLoaded; 787 G_UNLOCK (fileLoaded); 788 } 789 while ( !end ); 790 G_LOCK (fileLoaded); 744 791 fileLoaded = FALSE; 792 G_UNLOCK (fileLoaded); 745 793 } 746 794 #endif // DEBUG 795 796 gboolean 797 MainPter::pageNotAvailable (gpointer user) 798 { 799 g_assert (NULL != data && "The data parameter in NULL."); 800 801 PageNotAvailableData *data = (PageNotAvailableData *)user; 802 data->pter->refreshPage (data->scroll); 803 delete data; 804 return FALSE; 805 } -
trunk/src/MainPter.h
r132 r134 61 61 void showStatusbarActivated (gboolean show); 62 62 void showToolbarActivated (gboolean show); 63 void setContext (gint pageNum, gint rotation, gdouble zoom);64 63 void zoomFitActivated (gboolean active); 65 64 void zoomInActivated (void); … … 71 70 void notifyLoadPassword (const gchar *fileName, 72 71 const GError *error); 72 void notifyPageChanged (gint pageNum); 73 void notifyPageRotated (gint rotation); 74 void notifyPageZoomed (gdouble zoom); 75 76 static gboolean pageNotAvailable (gpointer user); 73 77 74 78 #if defined (DEBUG) … … 77 81 78 82 protected: 83 PageScroll m_NextPageScroll; 79 84 IDocument *m_Document; 80 85 gint m_PasswordTries; 81 86 IMainView *m_View; 82 void showPage (PageScroll pageScroll);87 void refreshPage (PageScroll pageScroll); 83 88 void zoomFit (void); 84 89 void zoomWidth (void); -
trunk/src/main.cxx
r117 r134 21 21 #include <locale.h> 22 22 #include <gtk/gtk.h> 23 #include <IMainView.h>23 #include "epdfview.h" 24 24 #include <MainView.h> 25 #include "MainPter.h"26 #include "Config.h"27 #include "JobLoad.h"28 29 25 30 26 using namespace ePDFView; … … 52 48 gtk_init (&argc, &argv); 53 49 g_set_application_name (_("PDF Viewer")); 50 // Initialize the working thread. 51 IJob::init (); 54 52 // Create the main presenter. 55 MainPter *mainPter = new MainPter (); 53 PDFDocument *document = new PDFDocument; 54 MainPter *mainPter = new MainPter (document); 56 55 // Create the main view. 57 56 MainView *mainView = new MainView (mainPter); … … 63 62 if ( argc > 1 ) 64 63 { 65 JobLoad *job = new JobLoad (); 66 job->setPresenter (mainPter); 67 job->setFileName (argv[1]); 68 job->run (); 64 document->load (argv[1], NULL); 69 65 } 70 66 gtk_main(); -
trunk/tests/MainPterTest.cxx
r133 r134 312 312 CPPUNIT_ASSERT_EQUAL (1, m_View->countTimesShownPasswordPrompt ()); 313 313 } 314 /* 314 315 315 /// 316 316 /// @brief Test the last folder used to open a file. … … 389 389 CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 390 390 CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); 391 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 391 // Since the page hasn't changed, no image preview is shown. 392 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 392 393 // But going to the previous will change something. 393 394 m_MainPter->goToPreviousPageActivated (); … … 418 419 CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 419 420 CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 420 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 421 // The page hasn't changed. 422 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 421 423 } 422 424 … … 471 473 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 472 474 473 // Invalid values. 475 // Invalid values. Remains to the same page. 474 476 m_View->setGoToPageText ("123123 of 1"); 475 477 m_MainPter->goToPageActivated (); 476 CPPUNIT_ASSERT_EQUAL (4, m_View->getCurrentPage ()); 477 CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); 478 CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); 479 CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); 480 CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 481 CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); 482 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 478 CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ()); 479 CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); 480 CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 481 CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 482 CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 483 CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 484 // Since the page hasn't changed, no image preview is shown. 485 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 483 486 484 487 m_View->setGoToPageText ("0 of 12"); … … 490 493 CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 491 494 CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 492 CPPUNIT_ASSERT ( m_View->hasImagePageView ());495 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 493 496 494 497 m_MainPter->goToNextPageActivated (); 498 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 495 499 m_View->setGoToPageText ("Jejej :-)"); 496 500 m_MainPter->goToPageActivated (); 497 CPPUNIT_ASSERT_EQUAL ( 1, m_View->getCurrentPage ());498 CPPUNIT_ASSERT ( !m_View->isSensitiveGoToFirstPage ());499 CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 500 CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 501 CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 502 CPPUNIT_ASSERT ( !m_View->isSensitiveGoToPreviousPage ());503 CPPUNIT_ASSERT ( m_View->hasImagePageView ());501 CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); 502 CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); 503 CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 504 CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 505 CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 506 CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); 507 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 504 508 } 505 509 … … 744 748 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 745 749 } 746 750 /* 747 751 /// 748 752 /// @brief Test to reload a normal document. -
trunk/tests/MainPterTest.h
r133
