Changeset 134

Show
Ignore:
Timestamp:
04/29/06 12:38:36 (2 years ago)
Author:
jordi
Message:

ePDFView now compiles (thanks Broeisi for pointing that) although it's now faster, it has an odd behaviour (like showing the first page unscaled) and doens't work the reload for now.

Location:
trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IDocument.cxx

    r132 r134  
    2323 
    2424G_LOCK_EXTERN (JobRender); 
     25G_LOCK_DEFINE_STATIC (pageImage); 
    2526 
    2627// Constants. 
     
    231232    } 
    232233} 
    233 #include <stdio.h> 
     234 
    234235void 
    235236IDocument::notifyPageRendered (gint pageNumber, DocumentPage *pageImage) 
     
    238239    if ( NULL != cachedPage ) 
    239240    { 
     241        G_LOCK (pageImage); 
    240242        delete cachedPage->pageImage; 
    241243        cachedPage->pageImage = pageImage; 
     244        G_UNLOCK (pageImage); 
    242245    } 
    243246} 
     
    733736    } 
    734737 
    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; 
    741743} 
    742744 
     
    886888        m_Rotation = (rotation % 360); 
    887889        refreshCache (); 
     890        G_UNLOCK (JobRender); 
    888891        notifyPageRotated (); 
    889         G_UNLOCK (JobRender); 
    890892    } 
    891893} 
     
    964966        m_Scale = zoom; 
    965967        refreshCache (); 
     968        G_UNLOCK (JobRender); 
    966969        notifyPageZoomed (); 
    967         G_UNLOCK (JobRender); 
    968970    } 
    969971} 
  • trunk/src/JobLoad.cxx

    r132 r134  
    240240                                            job->getError ()); 
    241241    JOB_NOTIFIER_END(); 
    242 } 
     242 
     243    return FALSE; 
     244} 
  • trunk/src/JobRender.cxx

    r130 r134  
    4747    { 
    4848        m_PageImage = doc->renderPage (getPageNumber ());  
     49        G_UNLOCK (JobRender); 
    4950        JOB_NOTIFIER (job_render_done, this); 
    5051        return JOB_DELETE; 
     
    102103    g_assert (NULL != data && "The data parameter is NULL."); 
    103104 
     105    G_LOCK (JobRender); 
     106 
    104107    JobRender *job = (JobRender *)data; 
    105108    IDocument *doc = job->getDocument (); 
  • trunk/src/MainPter.cxx

    r132 r134  
    2424 
    2525#if defined (DEBUG) 
     26G_LOCK_DEFINE_STATIC (fileLoaded); 
    2627static volatile gboolean fileLoaded; 
    2728#endif // DEBUG 
     29 
     30// Forward declarations. 
     31static gboolean page_not_available (gpointer); 
     32 
     33typedef struct 
     34{ 
     35    MainPter *pter; 
     36    PageScroll scroll; 
     37} PageNotAvailableData; 
    2838 
    2939/// 
     
    5060    m_View = NULL; 
    5161    m_PasswordTries = 3; 
     62    m_NextPageScroll = PAGE_SCROLL_START; 
    5263#if defined (DEBUG) 
     64    G_LOCK (fileLoaded); 
    5365    fileLoaded = FALSE; 
     66    G_UNLOCK (fileLoaded); 
    5467#endif 
    5568} 
     
    119132                       0 < m_Document->getOutline ()->getNumChildren () && 
    120133                       PageModeOutlines == m_Document->getPageMode ()); 
    121  
    122         if ( canShowPage ) 
    123         { 
    124             showPage (PAGE_SCROLL_START); 
    125         } 
     134     
    126135    } 
    127136    else 
     
    159168    // Show the normal cursor. 
    160169    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    } 
    162176} 
    163177 
     
    200214    g_assert (NULL != m_Document &&  
    201215              "Tried to go to the first page of a NULL document."); 
    202      
     216 
     217    m_NextPageScroll = PAGE_SCROLL_START; 
    203218    m_Document->goToFirstPage (); 
    204     showPage (PAGE_SCROLL_START); 
    205219} 
    206220 
     
    214228              "Tried to go to the last page of a NULL document."); 
    215229     
     230    m_NextPageScroll = PAGE_SCROLL_START; 
    216231    m_Document->goToLastPage (); 
    217     showPage (PAGE_SCROLL_START); 
    218232} 
    219233 
     
    229243    if ( m_Document->getCurrentPageNum () < m_Document->getNumPages () ) 
    230244    { 
     245        m_NextPageScroll = PAGE_SCROLL_START; 
    231246        m_Document->goToNextPage (); 
    232         showPage (PAGE_SCROLL_START); 
    233247    } 
    234248} 
     
    254268        int pageNum = atoi (goToPageText); 
    255269        // 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; 
    257272        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     
    259282    } 
    260283} 
     
    272295    if ( 1 < m_Document->getCurrentPageNum () ) 
    273296    { 
     297        m_NextPageScroll = PAGE_SCROLL_END; 
    274298        m_Document->goToPreviousPage (); 
    275         showPage (PAGE_SCROLL_END); 
    276299    } 
    277300} 
     
    329352    g_assert (NULL != outline && "The outline activated is NULL."); 
    330353     
     354    m_NextPageScroll = PAGE_SCROLL_START; 
    331355    m_Document->goToPage (outline->getDestinationPage ()); 
    332     showPage (PAGE_SCROLL_START); 
    333356} 
    334357 
     
    358381    if ( config.zoomToFit () ) 
    359382    { 
     383        m_NextPageScroll = PAGE_SCROLL_NONE; 
    360384        m_Document->zoomToFit (width, height); 
    361         showPage (PAGE_SCROLL_NONE); 
    362385    } 
    363386    else if ( config.zoomToWidth () ) 
    364387    { 
     388        m_NextPageScroll = PAGE_SCROLL_NONE; 
    365389        m_Document->zoomToWidth (width); 
    366         showPage (PAGE_SCROLL_NONE); 
    367390    } 
    368391} 
     
    398421    g_assert ( NULL != m_Document && "Tried to rotate a NULL document."); 
    399422 
     423    m_NextPageScroll = PAGE_SCROLL_START; 
    400424    m_Document->rotateLeft (); 
    401425 
     
    409433        zoomFit (); 
    410434    } 
    411     showPage (PAGE_SCROLL_START); 
    412435} 
    413436 
     
    420443    g_assert ( NULL != m_Document && "Tried to rotate a NULL document."); 
    421444 
     445    m_NextPageScroll = PAGE_SCROLL_START; 
    422446    m_Document->rotateRight (); 
    423  
    424447    Config &config = Config::getConfig (); 
    425448    if ( config.zoomToWidth () ) 
     
    431454        zoomFit (); 
    432455    } 
    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} 
    458457 
    459458/// 
     
    524523    if ( active ) 
    525524    { 
     525        m_NextPageScroll = PAGE_SCROLL_NONE; 
    526526        zoomFit (); 
    527         showPage (PAGE_SCROLL_NONE); 
    528527    } 
    529528} 
     
    545544    view.activeZoomWidth (FALSE); 
    546545     
     546    m_NextPageScroll = PAGE_SCROLL_NONE; 
    547547    m_Document->zoomIn (); 
    548     showPage (PAGE_SCROLL_NONE); 
    549548} 
    550549 
     
    564563    view.activeZoomFit (FALSE); 
    565564    view.activeZoomWidth (FALSE); 
    566      
     565    
     566    m_NextPageScroll = PAGE_SCROLL_NONE; 
    567567    m_Document->zoomOut (); 
    568     showPage (PAGE_SCROLL_NONE); 
    569568} 
    570569 
     
    601600    if ( active ) 
    602601    { 
     602        m_NextPageScroll = PAGE_SCROLL_NONE; 
    603603        zoomWidth (); 
    604         showPage (PAGE_SCROLL_NONE); 
    605604    } 
    606605} 
     
    641640 
    642641/// 
    643 /// @brief Shows the current page. 
     642/// @brief Refreshes the current page. 
    644643/// 
    645644/// This function is called when the presenter needs to show a document's 
     
    651650/// 
    652651void 
    653 MainPter::showPage (PageScroll pageScroll) 
     652MainPter::refreshPage (PageScroll pageScroll) 
    654653{ 
    655654    g_assert (NULL != m_Document &&  
    656655              "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        } 
    682671    } 
    683672} 
     
    687676{ 
    688677    setInitialState (TRUE); 
     678    notifyPageChanged (1); 
    689679#if defined (DEBUG) 
     680    G_LOCK (fileLoaded); 
    690681    fileLoaded = TRUE; 
     682    G_UNLOCK (fileLoaded); 
    691683#endif // DEBUG 
    692684} 
     
    696688{ 
    697689    getView ().showErrorMessage (_("Error Loading File"), error->message); 
    698     setInitialState (TRUE); 
     690    setInitialState (FALSE); 
    699691#if defined (DEBUG) 
     692    G_LOCK (fileLoaded); 
    700693    fileLoaded = TRUE; 
     694    G_UNLOCK (fileLoaded); 
    701695#endif // DEBUG 
    702696} 
     
    716710        else 
    717711        { 
     712            G_LOCK (fileLoaded); 
    718713            fileLoaded = TRUE; 
     714            G_UNLOCK (fileLoaded); 
    719715        } 
    720716#endif // DEBUG 
     
    725721                _("The password you have supplied is not a valid password " 
    726722                  "for this file.")); 
    727 #if defined (DEBUG)         
     723        setInitialState (FALSE); 
     724#if defined (DEBUG) 
     725        G_LOCK (fileLoaded); 
    728726        fileLoaded = TRUE; 
     727        G_UNLOCK (fileLoaded); 
    729728#endif // DEBUG 
    730729    } 
    731730} 
    732731 
     732void 
     733MainPter::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 
     753void 
     754MainPter::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 
     764void 
     765MainPter::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 
    733775#if defined (DEBUG) 
    734776/// 
     
    738780MainPter::waitForFileLoaded () 
    739781{ 
    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); 
    744791    fileLoaded = FALSE; 
     792    G_UNLOCK (fileLoaded); 
    745793} 
    746794#endif // DEBUG 
     795 
     796gboolean 
     797MainPter::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  
    6161            void showStatusbarActivated (gboolean show); 
    6262            void showToolbarActivated (gboolean show); 
    63             void setContext (gint pageNum, gint rotation, gdouble zoom); 
    6463            void zoomFitActivated (gboolean active); 
    6564            void zoomInActivated (void); 
     
    7170            void notifyLoadPassword (const gchar *fileName,  
    7271                                     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); 
    7377             
    7478#if defined (DEBUG) 
     
    7781 
    7882        protected: 
     83            PageScroll m_NextPageScroll; 
    7984            IDocument *m_Document; 
    8085            gint m_PasswordTries; 
    8186            IMainView *m_View; 
    82             void showPage (PageScroll pageScroll); 
     87            void refreshPage (PageScroll pageScroll); 
    8388            void zoomFit (void); 
    8489            void zoomWidth (void); 
  • trunk/src/main.cxx

    r117 r134  
    2121#include <locale.h> 
    2222#include <gtk/gtk.h> 
    23 #include <IMainView.h> 
     23#include "epdfview.h" 
    2424#include <MainView.h> 
    25 #include "MainPter.h" 
    26 #include "Config.h" 
    27 #include "JobLoad.h" 
    28  
    2925 
    3026using namespace ePDFView; 
     
    5248    gtk_init (&argc, &argv); 
    5349    g_set_application_name (_("PDF Viewer")); 
     50    // Initialize the working thread. 
     51    IJob::init (); 
    5452    // Create the main presenter. 
    55     MainPter *mainPter = new MainPter (); 
     53    PDFDocument *document = new PDFDocument; 
     54    MainPter *mainPter = new MainPter (document); 
    5655    // Create the main view. 
    5756    MainView *mainView = new MainView (mainPter); 
     
    6362    if ( argc > 1 ) 
    6463    { 
    65         JobLoad *job = new JobLoad (); 
    66         job->setPresenter (mainPter); 
    67         job->setFileName (argv[1]); 
    68         job->run (); 
     64        document->load (argv[1], NULL); 
    6965    } 
    7066    gtk_main(); 
  • trunk/tests/MainPterTest.cxx

    r133 r134  
    312312    CPPUNIT_ASSERT_EQUAL (1, m_View->countTimesShownPasswordPrompt ()); 
    313313} 
    314 /* 
     314 
    315315/// 
    316316/// @brief Test the last folder used to open a file. 
     
    389389    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
    390390    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 ()); 
    392393    // But going to the previous will change something. 
    393394    m_MainPter->goToPreviousPageActivated (); 
     
    418419    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
    419420    CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 
    420     CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     421    // The page hasn't changed. 
     422    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    421423} 
    422424 
     
    471473    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    472474 
    473     // Invalid values. 
     475    // Invalid values. Remains to the same page. 
    474476    m_View->setGoToPageText ("123123 of 1"); 
    475477    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 ());     
    483486 
    484487    m_View->setGoToPageText ("0 of 12"); 
     
    490493    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
    491494    CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 
    492     CPPUNIT_ASSERT (m_View->hasImagePageView ());     
     495    CPPUNIT_ASSERT (!m_View->hasImagePageView ());     
    493496 
    494497    m_MainPter->goToNextPageActivated (); 
     498    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    495499    m_View->setGoToPageText ("Jejej :-)"); 
    496500    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 ()); 
    504508} 
    505509 
     
    744748    CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); 
    745749} 
    746  
     750/* 
    747751/// 
    748752/// @brief Test to reload a normal document. 
  • trunk/tests/MainPterTest.h

    r133