Changeset 154
- Timestamp:
- 05/08/06 15:49:20 (2 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 16 modified
-
src/FindPter.cxx (modified) (4 diffs)
-
src/FindPter.h (modified) (3 diffs)
-
src/IDocument.cxx (modified) (1 diff)
-
src/IDocument.h (modified) (3 diffs)
-
src/IDocumentObserver.h (modified) (1 diff)
-
src/IFindView.h (modified) (1 diff)
-
src/JobFind.cxx (added)
-
src/JobFind.h (added)
-
src/Makefile.am (modified) (1 diff)
-
src/PDFDocument.cxx (modified) (1 diff)
-
src/PDFDocument.h (modified) (1 diff)
-
src/epdfview.h (modified) (1 diff)
-
tests/DumbDocumentObserver.cxx (modified) (3 diffs)
-
tests/DumbDocumentObserver.h (modified) (3 diffs)
-
tests/DumbFindView.cxx (modified) (3 diffs)
-
tests/DumbFindView.h (modified) (1 diff)
-
tests/FindPterTest.cxx (modified) (5 diffs)
-
tests/FindPterTest.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/FindPter.cxx
r153 r154 27 27 FindPter::FindPter (IDocument *document) 28 28 { 29 g_assert (NULL != document && "Tried to set a NULL document."); 30 29 31 m_Document = document; 32 m_Job = NULL; 30 33 m_View = NULL; 31 34 } … … 37 40 { 38 41 m_Document = NULL; 42 if ( NULL != m_Job ) 43 { 44 m_Job->cancel (); 45 } 39 46 delete m_View; 40 m_View = NULL;41 47 } 42 48 … … 52 58 53 59 return *m_View; 60 } 61 62 void 63 FindPter::notifyFindFinished (void) 64 { 65 m_Job->cancel (); 66 m_Job = NULL; 67 m_View->setInformationText (_("Not Found!")); 68 m_Document->notifyFindFinished (); 54 69 } 55 70 … … 90 105 m_View->sensitiveFindNext (TRUE); 91 106 m_View->sensitiveFindPrevious (TRUE); 107 if ( NULL != m_Job ) 108 { 109 m_Job->cancel (); 110 // When the job is cancelled, it will just delete itself. 111 m_Job = NULL; 112 } 113 114 // Queue a find job. 115 m_Job = new JobFind (); 116 m_Job->setDocument (m_Document); 117 m_Job->setStartingPage (m_Document->getCurrentPageNum ()); 118 m_Job->setTextToFind (textToFind); 119 m_Job->setFindPter (this); 120 IJob::queue (m_Job); 121 122 // Inform all observers. 123 m_Document->notifyFindStarted (); 92 124 } 93 125 } -
trunk/src/FindPter.h
r153 r154 21 21 namespace ePDFView 22 22 { 23 // Forward declarations. 24 class JobFind; 25 23 26 /// 24 27 /// @class FindPter … … 35 38 36 39 IFindView &getView (void); 40 void notifyFindFinished (void); 37 41 void setView (IFindView *view); 38 42 void textToFindChanged (void); … … 41 45 /// The document to search to. 42 46 IDocument *m_Document; 47 /// The current find job. 48 JobFind *m_Job; 43 49 /// The view that the presenter is controlling. 44 50 IFindView *m_View; 45 46 51 }; 47 52 } -
trunk/src/IDocument.cxx
r150 r154 202 202 } 203 203 204 void 205 IDocument::notifyFindFinished () 206 { 207 for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 208 item = g_list_next (item) ) 209 { 210 IDocumentObserver *observer = (IDocumentObserver *)item->data; 211 observer->notifyFindFinished (); 212 } 213 } 214 215 void 216 IDocument::notifyFindStarted () 217 { 218 for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 219 item = g_list_next (item) ) 220 { 221 IDocumentObserver *observer = (IDocumentObserver *)item->data; 222 observer->notifyFindStarted (); 223 } 224 } 225 204 226 /// 205 227 /// @brief The document has been loaded. -
trunk/src/IDocument.h
r150 r154 134 134 135 135 /// 136 /// @brief Finds text on a single page. 137 /// 138 /// The document must find the given text in the indicated page 139 /// number. 140 /// 141 /// @return The list of positions on the page that the text 142 /// was found. If the text is not found on the page, 143 /// then it must result NULL. 144 /// 145 virtual GList *findTextInPage (gint pageNum, 146 const gchar *textToFind) = 0; 147 148 /// 136 149 /// @brief Checks if the document has been loaded. 137 150 /// … … 161 174 const gchar *password, 162 175 GError **error) = 0; 176 163 177 /// 164 178 /// @brief Gets a document's page's unscaled size. … … 190 204 void detach (const IDocumentObserver *observer); 191 205 206 void notifyFindFinished (void); 207 void notifyFindStarted (void); 192 208 void notifyLoad (void); 193 209 void notifyLoadError (const GError *error); -
trunk/src/IDocumentObserver.h
r148 r154 32 32 /// @brief Destroys all dynamically allocated memory. 33 33 virtual ~IDocumentObserver (void) { } 34 34 35 /// 36 /// @brief A find has been finished. 37 /// 38 /// This is called when the find is finished (i.e., no 39 /// results.) 40 /// 41 virtual void notifyFindFinished (void) { } 42 43 /// 44 /// @brief A find has been started. 45 /// 46 /// This function is called when a new find has been started. 47 /// This is mainly for test purposes. 48 /// 49 virtual void notifyFindStarted (void) { } 50 35 51 /// 36 52 /// @brief The document has been loaded. -
trunk/src/IFindView.h
r153 r154 88 88 virtual void sensitiveFindPrevious (gboolean sensitive) = 0; 89 89 90 /// 91 /// @brief Sets the information text. 92 /// 93 /// The view must set a label to the specified text to 94 /// show it to the user. The text to show is something like 95 /// "Searching on page %d of %d" or "Not Found!", etc... 96 /// 97 /// @param text The text to show. 98 /// 99 virtual void setInformationText (const gchar *text) = 0; 100 90 101 protected: 91 102 /// The presenter that controls the view. -
trunk/src/Makefile.am
r153 r154 25 25 IMainView.h \ 26 26 IPageView.h \ 27 JobFind.cxx \ 28 JobFind.h \ 27 29 JobLoad.cxx \ 28 30 JobLoad.h \ -
trunk/src/PDFDocument.cxx
r151 r154 52 52 m_Document = NULL; 53 53 } 54 } 55 56 GList * 57 PDFDocument::findTextInPage (gint pageNum, const gchar *textToFind) 58 { 59 return NULL; 54 60 } 55 61 -
trunk/src/PDFDocument.h
r148 r154 39 39 ~PDFDocument (void); 40 40 41 GList *findTextInPage (gint pageNum, const gchar *textToFind); 41 42 gboolean isLoaded (void); 42 43 gboolean loadFile (const gchar *filename, const gchar *password, -
trunk/src/epdfview.h
r153 r154 39 39 40 40 #include <IJob.h> 41 #include <JobFind.h> 41 42 #include <JobLoad.h> 42 43 #include <JobRender.h> -
trunk/tests/DumbDocumentObserver.cxx
r151 r154 32 32 m_NotifiedPageZoomed = FALSE; 33 33 m_NotifiedReload = FALSE; 34 m_Searching = FALSE; 34 35 m_Zoom = 0.0; 35 36 } … … 38 39 { 39 40 setLoadError (NULL); 41 } 42 43 void 44 DumbDocumentObserver::notifyFindFinished () 45 { 46 m_Searching = FALSE; 47 } 48 49 void 50 DumbDocumentObserver::notifyFindStarted () 51 { 52 m_Searching = TRUE; 40 53 } 41 54 … … 112 125 113 126 gboolean 127 DumbDocumentObserver::isStillSearching (void) 128 { 129 return m_Searching; 130 } 131 132 gboolean 114 133 DumbDocumentObserver::loadFinished (void) 115 134 { -
trunk/tests/DumbDocumentObserver.h
r136 r154 27 27 ~DumbDocumentObserver (void); 28 28 29 void notifyFindFinished (void); 30 void notifyFindStarted (void); 29 31 void notifyLoad (void); 30 32 void notifyLoadError (const GError *error); … … 36 38 void notifyReload (void); 37 39 40 // Functions for test only purposes. 38 41 gint getCurrentPage (void); 39 42 const GError *getLoadError (void); 40 43 gdouble getZoom (void); 44 gboolean isStillSearching (void); 41 45 gboolean loadFinished (void); 42 46 gboolean notifiedError (void); … … 56 60 gboolean m_NotifiedPageZoomed; 57 61 gboolean m_NotifiedReload; 62 gboolean m_Searching; 58 63 gdouble m_Zoom; 59 64 }; -
trunk/tests/DumbFindView.cxx
r153 r154 26 26 m_FindNextSensitive = TRUE; 27 27 m_FindNextSensitive = TRUE; 28 m_InformationText = g_strdup (""); 28 29 m_TextToFind = g_strdup (""); 29 30 } … … 31 32 DumbFindView::~DumbFindView () 32 33 { 34 g_free (m_InformationText); 33 35 g_free (m_TextToFind); 34 36 } … … 52 54 } 53 55 56 void 57 DumbFindView::setInformationText (const gchar *text) 58 { 59 g_free (m_InformationText); 60 m_InformationText = g_strdup (text); 61 } 62 54 63 //////////////////////////////////////////////////////////////// 55 64 // Test Only Functions. 56 65 //////////////////////////////////////////////////////////////// 66 67 const gchar * 68 DumbFindView::getInformationText () 69 { 70 return m_InformationText; 71 } 57 72 58 73 gboolean -
trunk/tests/DumbFindView.h
r153 r154 26 26 DumbFindView (void); 27 27 ~DumbFindView (void); 28 28 29 29 const gchar *getTextToFind (void); 30 30 void sensitiveFindNext (gboolean sensitive); 31 31 void sensitiveFindPrevious (gboolean sensitive); 32 void setInformationText (const gchar *text); 32 33 33 34 // Methods for test only purposes. 35 const gchar *getInformationText (void); 34 36 gboolean isFindNextSensitive (void); 35 gboolean isFindPreviousSensitive (void); 37 gboolean isFindPreviousSensitive (void); 36 38 void setTextToFind (const gchar *text); 37 39 38 protected: 40 protected: 39 41 gboolean m_FindNextSensitive; 40 42 gboolean m_FindPreviousSensitive; 43 gchar *m_InformationText; 41 44 gchar *m_TextToFind; 42 45 }; -
trunk/tests/FindPterTest.cxx
r153 r154 24 24 using namespace ePDFView; 25 25 26 G_LOCK_EXTERN (JobRender); 27 26 28 // Register the test suite into the `registry'. 27 29 CPPUNIT_TEST_SUITE_REGISTRATION (FindPterTest); … … 42 44 m_View = new DumbFindView (); 43 45 m_FindPter->setView (m_View); 46 47 G_LOCK (JobRender); 48 JobRender::m_CanProcessJobs = TRUE; 49 G_UNLOCK (JobRender); 44 50 } 45 51 … … 50 56 FindPterTest::tearDown () 51 57 { 58 G_LOCK (JobRender); 59 JobRender::m_CanProcessJobs = FALSE; 60 IJob::clearQueue (); 61 G_UNLOCK (JobRender); 62 52 63 // Deleting the FindPter will also delete the DumbFindView. 53 64 delete m_FindPter; … … 59 70 /// 60 71 /// @brief Checks the find view's controls sensitivity. 72 /// 73 /// The Find Next and Find Previous buttons will be insensitive while the text 74 /// is empty (i.e., nothing to search), but will become sensitive when 75 /// there's text to search. 61 76 /// 62 77 void … … 77 92 CPPUNIT_ASSERT (!m_View->isFindPreviousSensitive ()); 78 93 } 94 95 /// 96 /// @brief Checks looking for an inexistent text. 97 /// 98 /// If the text to search doesn't exist on the document, then the 99 /// find dialog will receive the text "Not found!" and all observers will 100 /// receive a notifyFindFinished() event. 101 /// 102 void 103 FindPterTest::textDoesNotExist () 104 { 105 m_View->setTextToFind ("AnStupidLongTextThatShouldntAppearInTheDocument"); 106 while ( m_Observer->isStillSearching () ) { } 107 const gchar *infoText = m_View->getInformationText (); 108 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("Not found!", infoText)); 109 } -
trunk/tests/FindPterTest.h
r153 r154 27 27 CPPUNIT_TEST_SUITE (FindPterTest); 28 28 CPPUNIT_TEST (viewSensitivity); 29 CPPUNIT_TEST (textDoesNotExist); 29 30 CPPUNIT_TEST_SUITE_END (); 30 31 … … 34 35 35 36 void viewSensitivity (void); 37 void textDoesNotExist (void); 36 38 37 39 private:
