Changeset 29
- Timestamp:
- 04/11/06 13:58:09 (3 years ago)
- Location:
- trunk
- Files:
-
- 8 modified
-
src/IMainView.h (modified) (1 diff)
-
src/MainPter.cxx (modified) (4 diffs)
-
src/MainPter.h (modified) (1 diff)
-
tests/DumbDocument.cxx (modified) (1 diff)
-
tests/DumbMainView.cxx (modified) (5 diffs)
-
tests/DumbMainView.h (modified) (3 diffs)
-
tests/MainPterTest.cxx (modified) (1 diff)
-
tests/MainPterTest.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/IMainView.h
r27 r29 45 45 const gchar *body) = 0; 46 46 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; 47 50 virtual void setTitle (const gchar *title) = 0; 48 51 -
trunk/src/MainPter.cxx
r27 r29 63 63 if ( m_Document->isLoaded () ) 64 64 { 65 m_Document->goToFirstPage (); 65 66 if ( 0 == g_ascii_strcasecmp ("", m_Document->getTitle ()) ) 66 67 { … … 71 72 view.setTitle (m_Document->getTitle ()); 72 73 } 73 view.sensitiveGoToFirstPage (FALSE);74 view.sensitiveGoToLastPage (TRUE);75 view.sensitiveGoToNextPage (TRUE);76 74 view.sensitiveGoToPage (TRUE); 77 view.sensitiveGoToPreviousPage (FALSE);78 75 view.sensitiveZoomIn (TRUE); 79 76 view.sensitiveZoomOut (TRUE); 80 77 view.sensitiveZoomFit (TRUE); 81 78 view.sensitiveZoomWidth (TRUE); 79 view.setTotalPages (m_Document->getNumPages ()); 82 80 showPage (); 83 81 } … … 126 124 // state. 127 125 setInitialState (); 126 } 127 128 /// 129 /// @brief The "Go To First Page" action was activated. 130 /// 131 void 132 MainPter::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 141 void 142 MainPter::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 151 void 152 MainPter::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 161 void 162 MainPter::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 180 void 181 MainPter::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 (); 128 188 } 129 189 … … 218 278 g_assert (m_Document->isLoaded () && 219 279 "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 221 294 DocumentPage *page = m_Document->renderPage (); 222 295 if ( NULL != page ) -
trunk/src/MainPter.h
r24 r29 31 31 IMainView &getView (void); 32 32 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); 34 39 void openFileActivated (void); 35 40 -
trunk/tests/DumbDocument.cxx
r27 r29 31 31 m_OpenError = DocumentErrorNone; 32 32 m_Password = NULL; 33 setNumPages (2); 33 34 } 34 35 -
trunk/tests/DumbMainView.cxx
r27 r29 27 27 IMainView (pter) 28 28 { 29 m_CurrentPage = 0; 29 30 // This won't be deleted because it's presenter responsability. 30 31 m_DocumentPage = NULL; 32 m_GoToPageText = g_strdup (""); 31 33 m_OpenFileName = g_strdup (""); 32 34 m_Password = NULL; … … 44 46 m_Title = g_strdup (""); 45 47 m_TimesShownPassword = 0; 48 m_TotalPages = 0; 46 49 } 47 50 48 51 DumbMainView::~DumbMainView () 49 52 { 53 g_free (m_GoToPageText); 50 54 g_free (m_OpenFileName); 51 55 g_free (m_Password); … … 120 124 } 121 125 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; 126 const gchar * 127 DumbMainView::getGoToPageText () 128 { 129 return (const gchar *)m_GoToPageText; 130 } 131 132 void 133 DumbMainView::setTotalPages (gint pages) 134 { 135 m_TotalPages = pages; 136 } 137 138 void 139 DumbMainView::setGoToPageText (const char *text) 140 { 141 g_free (m_GoToPageText); 142 m_GoToPageText = g_strdup (text); 143 m_CurrentPage = atoi(text); 138 144 } 139 145 … … 145 151 } 146 152 153 void 154 DumbMainView::show (void) 155 { 156 m_Shown = TRUE; 157 } 158 159 void 160 DumbMainView::showErrorMessage (const gchar *title, const gchar *body) 161 { 162 m_ShownError = TRUE; 163 } 164 165 void 166 DumbMainView::showPage (DocumentPage *page) 167 { 168 m_DocumentPage = page; 169 } 147 170 148 171 //////////////////////////////////////////////////////////////// … … 154 177 { 155 178 return m_TimesShownPassword; 179 } 180 181 gint 182 DumbMainView::getCurrentPage () 183 { 184 return m_CurrentPage; 185 } 186 187 gint 188 DumbMainView::getTotalPages () 189 { 190 return m_TotalPages; 156 191 } 157 192 -
trunk/tests/DumbMainView.h
r27 r29 39 39 void sensitiveZoomFit (gboolean sensitive); 40 40 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); 41 45 void show (void); 42 46 void showErrorMessage (const gchar *title, const gchar *body); 43 47 void showPage (DocumentPage *page); 44 void setTitle (const gchar *title);45 48 46 49 // Methods for test purposes. 47 gint countTimesShownPasswordPrompt (); 50 gint countTimesShownPasswordPrompt (void); 51 gint getCurrentPage (void); 48 52 const gchar *getTitle (void); 53 gint getTotalPages (void); 49 54 gboolean hasImagePageView (void); 50 55 gboolean isShown (void); … … 63 68 64 69 protected: 70 gint m_CurrentPage; 65 71 DocumentPage *m_DocumentPage; 72 gchar *m_GoToPageText; 66 73 gchar *m_OpenFileName; 67 74 gchar *m_Password; … … 79 86 gint m_TimesShownPassword; 80 87 gchar *m_Title; 88 gint m_TotalPages; 81 89 }; 82 90 } -
trunk/tests/MainPterTest.cxx
r28 r29 262 262 CPPUNIT_ASSERT_EQUAL (1, m_View->countTimesShownPasswordPrompt ()); 263 263 } 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 /// 271 void 272 MainPterTest::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 33 33 CPPUNIT_TEST (badPassword); 34 34 CPPUNIT_TEST (goodPassword); 35 CPPUNIT_TEST (pageNavigation); 35 36 CPPUNIT_TEST_SUITE_END(); 36 37 … … 46 47 void badPassword (void); 47 48 void goodPassword (void); 49 void pageNavigation (void); 48 50 49 51 private:
