Changeset 29

Show
Ignore:
Timestamp:
04/11/06 13:58:09 (3 years ago)
Author:
jordi
Message:

The page navigation toolbar works as expected, setting the sensitiveness of its controls correctly.

Location:
trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IMainView.h

    r27 r29  
    4545                                           const gchar *body) = 0; 
    4646            virtual void showPage (DocumentPage *page) = 0; 
     47            virtual void setTotalPages (gint pages) = 0; 
     48            virtual void setGoToPageText (const gchar *text) = 0; 
     49            virtual const gchar *getGoToPageText (void) = 0; 
    4750            virtual void setTitle (const gchar *title) = 0; 
    4851 
  • trunk/src/MainPter.cxx

    r27 r29  
    6363    if ( m_Document->isLoaded () ) 
    6464    { 
     65        m_Document->goToFirstPage (); 
    6566        if ( 0 == g_ascii_strcasecmp ("", m_Document->getTitle ()) ) 
    6667        { 
     
    7172            view.setTitle (m_Document->getTitle ()); 
    7273        } 
    73         view.sensitiveGoToFirstPage (FALSE); 
    74         view.sensitiveGoToLastPage (TRUE); 
    75         view.sensitiveGoToNextPage (TRUE); 
    7674        view.sensitiveGoToPage (TRUE); 
    77         view.sensitiveGoToPreviousPage (FALSE); 
    7875        view.sensitiveZoomIn (TRUE); 
    7976        view.sensitiveZoomOut (TRUE); 
    8077        view.sensitiveZoomFit (TRUE); 
    8178        view.sensitiveZoomWidth (TRUE); 
     79        view.setTotalPages (m_Document->getNumPages ()); 
    8280        showPage (); 
    8381    } 
     
    126124    // state. 
    127125    setInitialState (); 
     126} 
     127 
     128/// 
     129/// @brief The "Go To First Page" action was activated. 
     130/// 
     131void 
     132MainPter::goToFirstPageActivated (void) 
     133{ 
     134    g_assert (NULL != m_Document &&  
     135              "Tried to go to the first page of a NULL document."); 
     136     
     137    m_Document->goToFirstPage (); 
     138    showPage (); 
     139} 
     140 
     141void 
     142MainPter::goToLastPageActivated (void) 
     143{ 
     144    g_assert (NULL != m_Document &&  
     145              "Tried to go to the last page of a NULL document."); 
     146     
     147    m_Document->goToLastPage (); 
     148    showPage (); 
     149} 
     150 
     151void 
     152MainPter::goToNextPageActivated (void) 
     153{ 
     154    g_assert (NULL != m_Document &&  
     155              "Tried to go to the next page of a NULL document."); 
     156     
     157    m_Document->goToNextPage (); 
     158    showPage (); 
     159} 
     160 
     161void 
     162MainPter::goToPageActivated (void) 
     163{ 
     164    g_assert (NULL != m_Document &&  
     165              "Tried to go to the a page of a NULL document."); 
     166     
     167    // First try to get the page number from the view. 
     168    const gchar *goToPageText = getView ().getGoToPageText (); 
     169    if ( NULL != goToPageText ) 
     170    { 
     171        // Try to read as much as possible. 
     172        int pageNum = atoi (goToPageText); 
     173        // If the page number is too high, the Document class will 
     174        // go to the last page. The same if it's too low. 
     175        m_Document->goToPage (pageNum); 
     176        showPage (); 
     177    } 
     178} 
     179 
     180void 
     181MainPter::goToPreviousPageActivated (void) 
     182{ 
     183    g_assert (NULL != m_Document &&  
     184              "Tried to go to the previous page of a NULL document."); 
     185     
     186    m_Document->goToPreviousPage (); 
     187    showPage (); 
    128188} 
    129189 
     
    218278    g_assert (m_Document->isLoaded () &&  
    219279              "Tried to show a page from a not loaded document."); 
    220              
     280 
     281    IMainView &view = getView (); 
     282    // Set the text for the current page. 
     283    gint currentPage = m_Document->getCurrentPageNum (); 
     284    gchar *goToPageText = g_strdup_printf ("%d", currentPage); 
     285    view.setGoToPageText (goToPageText); 
     286    g_free (goToPageText); 
     287     
     288    // Set the page navigation sensitivity. 
     289    view.sensitiveGoToFirstPage (1 < currentPage ); 
     290    view.sensitiveGoToPreviousPage (1 < currentPage ); 
     291    view.sensitiveGoToLastPage (m_Document->getNumPages() > currentPage); 
     292    view.sensitiveGoToNextPage (m_Document->getNumPages() > currentPage); 
     293     
    221294    DocumentPage *page = m_Document->renderPage (); 
    222295    if ( NULL != page ) 
  • trunk/src/MainPter.h

    r24 r29  
    3131            IMainView &getView (void); 
    3232            void setView (IMainView *view); 
    33  
     33             
     34            void goToFirstPageActivated (void); 
     35            void goToLastPageActivated (void); 
     36            void goToNextPageActivated (void); 
     37            void goToPageActivated (void); 
     38            void goToPreviousPageActivated (void); 
    3439            void openFileActivated (void); 
    3540 
  • trunk/tests/DumbDocument.cxx

    r27 r29  
    3131    m_OpenError = DocumentErrorNone; 
    3232    m_Password = NULL; 
     33    setNumPages (2); 
    3334} 
    3435 
  • trunk/tests/DumbMainView.cxx

    r27 r29  
    2727    IMainView (pter) 
    2828{ 
     29    m_CurrentPage = 0; 
    2930    // This won't be deleted because it's presenter responsability. 
    3031    m_DocumentPage = NULL; 
     32    m_GoToPageText = g_strdup (""); 
    3133    m_OpenFileName = g_strdup (""); 
    3234    m_Password = NULL; 
     
    4446    m_Title = g_strdup (""); 
    4547    m_TimesShownPassword = 0; 
     48    m_TotalPages = 0; 
    4649} 
    4750 
    4851DumbMainView::~DumbMainView () 
    4952{ 
     53    g_free (m_GoToPageText); 
    5054    g_free (m_OpenFileName); 
    5155    g_free (m_Password); 
     
    120124} 
    121125 
    122 void 
    123 DumbMainView::show (void) 
    124 { 
    125     m_Shown = TRUE; 
    126 } 
    127  
    128 void 
    129 DumbMainView::showErrorMessage (const gchar *title, const gchar *body) 
    130 { 
    131     m_ShownError = TRUE; 
    132 } 
    133  
    134 void 
    135 DumbMainView::showPage (DocumentPage *page) 
    136 { 
    137     m_DocumentPage = page; 
     126const gchar * 
     127DumbMainView::getGoToPageText () 
     128{ 
     129    return (const gchar *)m_GoToPageText; 
     130} 
     131 
     132void 
     133DumbMainView::setTotalPages (gint pages) 
     134{ 
     135    m_TotalPages = pages; 
     136} 
     137 
     138void 
     139DumbMainView::setGoToPageText (const char *text) 
     140{ 
     141    g_free (m_GoToPageText); 
     142    m_GoToPageText = g_strdup (text); 
     143    m_CurrentPage = atoi(text); 
    138144} 
    139145 
     
    145151} 
    146152 
     153void 
     154DumbMainView::show (void) 
     155{ 
     156    m_Shown = TRUE; 
     157} 
     158 
     159void 
     160DumbMainView::showErrorMessage (const gchar *title, const gchar *body) 
     161{ 
     162    m_ShownError = TRUE; 
     163} 
     164 
     165void 
     166DumbMainView::showPage (DocumentPage *page) 
     167{ 
     168    m_DocumentPage = page; 
     169} 
    147170 
    148171//////////////////////////////////////////////////////////////// 
     
    154177{ 
    155178    return m_TimesShownPassword; 
     179} 
     180 
     181gint 
     182DumbMainView::getCurrentPage () 
     183{ 
     184    return m_CurrentPage; 
     185} 
     186 
     187gint 
     188DumbMainView::getTotalPages () 
     189{ 
     190    return m_TotalPages; 
    156191} 
    157192 
  • trunk/tests/DumbMainView.h

    r27 r29  
    3939            void sensitiveZoomFit (gboolean sensitive); 
    4040            void sensitiveZoomWidth (gboolean sensitive); 
     41            const gchar *getGoToPageText (void); 
     42            void setTotalPages (gint pages); 
     43            void setGoToPageText (const char *text); 
     44            void setTitle (const gchar *title); 
    4145            void show (void); 
    4246            void showErrorMessage (const gchar *title, const gchar *body); 
    4347            void showPage (DocumentPage *page); 
    44             void setTitle (const gchar *title); 
    4548 
    4649            // Methods for test purposes. 
    47             gint countTimesShownPasswordPrompt (); 
     50            gint countTimesShownPasswordPrompt (void); 
     51            gint getCurrentPage (void);             
    4852            const gchar *getTitle (void); 
     53            gint getTotalPages (void); 
    4954            gboolean hasImagePageView (void); 
    5055            gboolean isShown (void); 
     
    6368 
    6469        protected: 
     70            gint m_CurrentPage; 
    6571            DocumentPage *m_DocumentPage; 
     72            gchar *m_GoToPageText; 
    6673            gchar *m_OpenFileName; 
    6774            gchar *m_Password; 
     
    7986            gint m_TimesShownPassword; 
    8087            gchar *m_Title; 
     88            gint m_TotalPages; 
    8189    }; 
    8290} 
  • trunk/tests/MainPterTest.cxx

    r28 r29  
    262262    CPPUNIT_ASSERT_EQUAL (1, m_View->countTimesShownPasswordPrompt ()); 
    263263} 
     264 
     265/// 
     266/// @brief Test page navigation. 
     267/// 
     268/// I'll load a 4-pages document and will try to go to the first, last, next,  
     269/// previous and also on a page using the entry on the toolbar. 
     270/// 
     271void 
     272MainPterTest::pageNavigation () 
     273{ 
     274    m_View->setOpenFileName ("/tmp/test.pdf"); 
     275    m_Document->setNumPages (4); 
     276    m_MainPter->openFileActivated (); 
     277    // Check that sets the correct number of pages and the current page. 
     278    CPPUNIT_ASSERT_EQUAL (4, m_View->getTotalPages ()); 
     279    CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ()); 
     280    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     281    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     282    // Going to the next page should make all actions sensitive. 
     283    m_MainPter->goToNextPageActivated (); 
     284    CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ());  
     285    CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); 
     286    CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 
     287    CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 
     288    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
     289    CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); 
     290    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     291    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     292    // Going to the last will make some unsensitive. 
     293    m_MainPter->goToLastPageActivated (); 
     294    CPPUNIT_ASSERT_EQUAL (4, m_View->getCurrentPage ());  
     295    CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); 
     296    CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); 
     297    CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); 
     298    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
     299    CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); 
     300    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     301    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     302    // Again to the last won't harm (just in case...) nor going next. 
     303    m_MainPter->goToLastPageActivated (); 
     304    m_MainPter->goToNextPageActivated (); 
     305    CPPUNIT_ASSERT_EQUAL (4, m_View->getCurrentPage ());  
     306    CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); 
     307    CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); 
     308    CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); 
     309    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
     310    CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); 
     311    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     312    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     313    // But going to the previous will change something. 
     314    m_MainPter->goToPreviousPageActivated (); 
     315    CPPUNIT_ASSERT_EQUAL (3, m_View->getCurrentPage ());  
     316    CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); 
     317    CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 
     318    CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 
     319    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
     320    CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); 
     321    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     322    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     323    // Now, to the first again. 
     324    m_MainPter->goToFirstPageActivated (); 
     325    CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ());  
     326    CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); 
     327    CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 
     328    CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 
     329    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
     330    CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 
     331    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     332    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     333    // Check sane behaviour. 
     334    m_MainPter->goToFirstPageActivated (); 
     335    m_MainPter->goToPreviousPageActivated (); 
     336    CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ());  
     337    CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); 
     338    CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 
     339    CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 
     340    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
     341    CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 
     342    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     343    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     344 
     345    // Now try again using the page entry on toolbar. 
     346    m_View->setGoToPageText ("2"); 
     347    m_MainPter->goToPageActivated (); 
     348    CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ());  
     349    CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); 
     350    CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 
     351    CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 
     352    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
     353    CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); 
     354    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     355    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     356 
     357    m_View->setGoToPageText ("4"); 
     358    m_MainPter->goToPageActivated (); 
     359    CPPUNIT_ASSERT_EQUAL (4, m_View->getCurrentPage ());  
     360    CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); 
     361    CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); 
     362    CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); 
     363    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
     364    CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); 
     365    CPPUNIT_ASSERT (m_View->hasImagePageView ());     
     366    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     367 
     368    m_View->setGoToPageText ("1"); 
     369    m_MainPter->goToPageActivated (); 
     370    CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ());  
     371    CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); 
     372    CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 
     373    CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 
     374    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
     375    CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 
     376    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     377    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     378 
     379    // Invalid values. 
     380    m_View->setGoToPageText ("123123"); 
     381    m_MainPter->goToPageActivated (); 
     382    CPPUNIT_ASSERT_EQUAL (4, m_View->getCurrentPage ());  
     383    CPPUNIT_ASSERT (m_View->isSensitiveGoToFirstPage ()); 
     384    CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); 
     385    CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); 
     386    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
     387    CPPUNIT_ASSERT (m_View->isSensitiveGoToPreviousPage ()); 
     388    CPPUNIT_ASSERT (m_View->hasImagePageView ());     
     389    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     390 
     391    m_View->setGoToPageText ("0"); 
     392    m_MainPter->goToPageActivated (); 
     393    CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ());  
     394    CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); 
     395    CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 
     396    CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 
     397    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
     398    CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 
     399    CPPUNIT_ASSERT (m_View->hasImagePageView ());     
     400    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     401 
     402    m_MainPter->goToNextPageActivated (); 
     403    m_View->setGoToPageText ("Jejej"); 
     404    m_MainPter->goToPageActivated (); 
     405    CPPUNIT_ASSERT_EQUAL (1, m_View->getCurrentPage ());  
     406    CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); 
     407    CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 
     408    CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 
     409    CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 
     410    CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 
     411    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     412    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     413} 
  • trunk/tests/MainPterTest.h

    r28 r29  
    3333        CPPUNIT_TEST (badPassword); 
    3434        CPPUNIT_TEST (goodPassword); 
     35        CPPUNIT_TEST (pageNavigation); 
    3536        CPPUNIT_TEST_SUITE_END(); 
    3637 
     
    4647            void badPassword (void); 
    4748            void goodPassword (void); 
     49            void pageNavigation (void); 
    4850 
    4951        private: