Changeset 24
- Timestamp:
- 04/11/06 11:10:26 (3 years ago)
- Location:
- trunk
- Files:
-
- 9 modified
-
src/IMainView.h (modified) (2 diffs)
-
src/MainPter.cxx (modified) (4 diffs)
-
src/MainPter.h (modified) (1 diff)
-
tests/DumbDocument.cxx (modified) (3 diffs)
-
tests/DumbDocument.h (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
r23 r24 30 30 virtual ~IMainView () {} 31 31 32 virtual gchar *openFileDialog () = 0; 32 33 virtual void sensitiveGoToFirstPage (gboolean sensitive) = 0; 33 34 virtual void sensitiveGoToLastPage (gboolean sensitive) = 0; … … 39 40 virtual void sensitiveZoomFit (gboolean sensitive) = 0; 40 41 virtual void sensitiveZoomWidth (gboolean sensitive) = 0; 41 virtual void show (void) = 0; 42 virtual void show (void) = 0; 43 virtual void showPage (DocumentPage *page) = 0; 42 44 virtual void setTitle (const gchar *title) = 0; 43 45 -
trunk/src/MainPter.cxx
r23 r24 25 25 MainPter::MainPter () 26 26 { 27 m_Document = new PDFDocument (); 27 28 } 28 29 … … 36 37 MainPter::MainPter (IDocument *document) 37 38 { 39 g_assert (NULL != document && "Tried to set a NULL document"); 40 41 m_Document = document; 38 42 } 39 43 … … 54 58 MainPter::setInitialState () 55 59 { 60 g_assert ( NULL != m_Document && "The document is NULL."); 61 56 62 IMainView &view = getView (); 57 view.setTitle (_("PDF Viewer")); 58 view.sensitiveGoToFirstPage (FALSE); 59 view.sensitiveGoToLastPage (FALSE); 60 view.sensitiveGoToNextPage (FALSE); 61 view.sensitiveGoToPage (FALSE); 62 view.sensitiveGoToPreviousPage (FALSE); 63 view.sensitiveZoomIn (FALSE); 64 view.sensitiveZoomOut (FALSE); 65 view.sensitiveZoomFit (FALSE); 66 view.sensitiveZoomWidth (FALSE); 63 if ( m_Document->isLoaded () ) 64 { 65 if ( 0 == g_ascii_strcasecmp ("", m_Document->getTitle ()) ) 66 { 67 view.setTitle (m_Document->getFileName ()); 68 } 69 else 70 { 71 view.setTitle (m_Document->getTitle ()); 72 } 73 view.sensitiveGoToFirstPage (FALSE); 74 view.sensitiveGoToLastPage (TRUE); 75 view.sensitiveGoToNextPage (TRUE); 76 view.sensitiveGoToPage (TRUE); 77 view.sensitiveGoToPreviousPage (FALSE); 78 view.sensitiveZoomIn (TRUE); 79 view.sensitiveZoomOut (TRUE); 80 view.sensitiveZoomFit (TRUE); 81 view.sensitiveZoomWidth (TRUE); 82 showPage (); 83 } 84 else 85 { 86 view.setTitle (_("PDF Viewer")); 87 view.sensitiveGoToFirstPage (FALSE); 88 view.sensitiveGoToLastPage (FALSE); 89 view.sensitiveGoToNextPage (FALSE); 90 view.sensitiveGoToPage (FALSE); 91 view.sensitiveGoToPreviousPage (FALSE); 92 view.sensitiveZoomIn (FALSE); 93 view.sensitiveZoomOut (FALSE); 94 view.sensitiveZoomFit (FALSE); 95 view.sensitiveZoomWidth (FALSE); 96 } 97 67 98 view.show (); 68 99 } … … 97 128 } 98 129 130 /// 131 /// @brief The Open File action was activated. 132 /// 133 /// This means that the user wants to open a new file. The presenter 134 /// asks the view to show the Open File dialog and return a filename. 135 /// Then we'll try to open the file and if it's correct we'll show it, 136 /// otherwise it will request the view to show an error dialog or a 137 /// password dialog, if the document is encrypted. 138 /// 139 void 140 MainPter::openFileActivated () 141 { 142 IMainView &view = getView (); 143 gchar *fileName = view.openFileDialog (); 144 GError *error; 145 if ( m_Document->loadFile (fileName, NULL, &error) ) 146 { 147 // Now that the document has been loaded, just reset the initial 148 // state. 149 setInitialState (); 150 g_free (fileName); 151 } 152 } 99 153 154 /// 155 /// @brief Shows the current page. 156 /// 157 /// This function is called when the presenter needs to show a document's 158 /// page. It only gets the rendered page from the document and then 159 /// pass the resultant DocumentPage to the view. 160 /// 161 void 162 MainPter::showPage () 163 { 164 g_assert (NULL != m_Document && 165 "Tried to show a page from a NULL document."); 166 g_assert (m_Document->isLoaded () && 167 "Tried to show a page from a not loaded document."); 168 169 DocumentPage *page = m_Document->renderPage (); 170 if ( NULL != page ) 171 { 172 getView ().showPage (page); 173 delete page; 174 } 175 } -
trunk/src/MainPter.h
r23 r24 28 28 ~MainPter (); 29 29 30 void setInitialState (void); 30 void setInitialState (void); 31 31 IMainView &getView (void); 32 32 void setView (IMainView *view); 33 33 34 void openFileActivated (void); 35 34 36 protected: 37 void showPage (void); 38 39 IDocument *m_Document; 35 40 IMainView *m_View; 36 41 }; -
trunk/tests/DumbDocument.cxx
r23 r24 28 28 IDocument () 29 29 { 30 m_Loaded = FALSE; 30 31 } 31 32 … … 37 38 DumbDocument::isLoaded () 38 39 { 39 return false;40 return m_Loaded; 40 41 } 41 42 … … 44 45 GError **error) 45 46 { 46 return false; 47 setFileName (filename); 48 m_Loaded = TRUE; 49 return m_Loaded; 47 50 } 48 51 -
trunk/tests/DumbDocument.h
r23 r24 33 33 void getPageSize (gdouble *width, gdouble *height); 34 34 DocumentPage *renderPage (void); 35 36 private: 37 gboolean m_Loaded; 35 38 }; 36 39 } -
trunk/tests/DumbMainView.cxx
r23 r24 29 29 // This won't be deleted because it's presenter responsability. 30 30 m_DocumentPage = NULL; 31 m_OpenFileName = g_strdup (""); 31 32 m_SensitiveGoToFirstPage = TRUE; 32 33 m_SensitiveGoToLastPage = TRUE; … … 44 45 DumbMainView::~DumbMainView () 45 46 { 47 g_free (m_OpenFileName); 46 48 g_free (m_Title); 47 49 } 50 51 gchar * 52 DumbMainView::openFileDialog (void) 53 { 54 return g_strdup (m_OpenFileName); 55 } 48 56 49 57 void … … 105 113 { 106 114 m_Shown = TRUE; 115 } 116 117 void 118 DumbMainView::showPage (DocumentPage *page) 119 { 120 m_DocumentPage = page; 107 121 } 108 122 … … 120 134 121 135 gboolean 136 DumbMainView::hasImagePageView () 137 { 138 return NULL != m_DocumentPage; 139 } 140 141 gboolean 122 142 DumbMainView::isShown () 123 143 { … … 185 205 } 186 206 187 gboolean 188 DumbMainView::hasImagePageView () 189 { 190 return NULL != m_DocumentPage; 191 } 207 void 208 DumbMainView::setOpenFileName (const gchar *fileName) 209 { 210 g_free (m_OpenFileName); 211 m_OpenFileName = g_strdup (fileName); 212 } -
trunk/tests/DumbMainView.h
r23 r24 28 28 ~DumbMainView (); 29 29 30 gchar *openFileDialog (void); 30 31 void sensitiveGoToFirstPage (gboolean sensitive); 31 32 void sensitiveGoToLastPage (gboolean sensitive); … … 37 38 void sensitiveZoomFit (gboolean sensitive); 38 39 void sensitiveZoomWidth (gboolean sensitive); 39 void show (void); 40 void show (void); 41 void showPage (DocumentPage *page); 40 42 void setTitle (const gchar *title); 41 43 42 44 // Methods for test purposes. 43 45 const gchar *getTitle (void); 46 gboolean hasImagePageView (void); 44 47 gboolean isShown (void); 45 48 gboolean isSensitiveGoToFirstPage (void); … … 52 55 gboolean isSensitiveZoomFit (void); 53 56 gboolean isSensitiveZoomWidth (void); 54 gboolean hasImagePageView (void);57 void setOpenFileName (const gchar *fileName); 55 58 56 59 protected: 57 60 DocumentPage *m_DocumentPage; 61 gchar *m_OpenFileName; 58 62 gboolean m_SensitiveGoToFirstPage; 59 63 gboolean m_SensitiveGoToLastPage; -
trunk/tests/MainPterTest.cxx
r23 r24 74 74 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 75 75 } 76 77 /// 78 /// @brief Test loading a document. 79 /// 80 /// Loading a document will set the title to the document's title or the 81 /// document's file name, if it has no title. Also will sensitive the 82 /// go to next page, go to last page and all zoom actions. Also will 83 /// show the document's first page. 84 /// 85 void 86 MainPterTest::loadDocument () 87 { 88 m_View->setOpenFileName ("/tmp/test.pdf"); 89 m_MainPter->openFileActivated (); 90 CPPUNIT_ASSERT_EQUAL (0, 91 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 92 CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); 93 CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 94 CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 95 CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 96 CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 97 CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); 98 CPPUNIT_ASSERT (m_View->isSensitiveZoomOut ()); 99 CPPUNIT_ASSERT (m_View->isSensitiveZoomFit ()); 100 CPPUNIT_ASSERT (m_View->isSensitiveZoomWidth ()); 101 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 102 103 // Now try a document with a title. 104 m_Document->setTitle ("Test PDF"); 105 m_MainPter->openFileActivated (); 106 CPPUNIT_ASSERT_EQUAL (0, 107 g_ascii_strcasecmp ("Test PDF", m_View->getTitle ())); 108 CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); 109 CPPUNIT_ASSERT (m_View->isSensitiveGoToLastPage ()); 110 CPPUNIT_ASSERT (m_View->isSensitiveGoToNextPage ()); 111 CPPUNIT_ASSERT (m_View->isSensitiveGoToPage ()); 112 CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 113 CPPUNIT_ASSERT (m_View->isSensitiveZoomIn ()); 114 CPPUNIT_ASSERT (m_View->isSensitiveZoomOut ()); 115 CPPUNIT_ASSERT (m_View->isSensitiveZoomFit ()); 116 CPPUNIT_ASSERT (m_View->isSensitiveZoomWidth ()); 117 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 118 } -
trunk/tests/MainPterTest.h
r23 r24 27 27 CPPUNIT_TEST_SUITE (MainPterTest); 28 28 CPPUNIT_TEST (initialStatus); 29 CPPUNIT_TEST (loadDocument); 29 30 CPPUNIT_TEST_SUITE_END(); 30 31 … … 34 35 35 36 void initialStatus (void); 37 void loadDocument (void); 36 38 37 39 private:
