Changeset 154

Show
Ignore:
Timestamp:
05/08/06 15:49:20 (2 years ago)
Author:
jordi
Message:

When the text to find changes, the FindPter? starts a new background job called JobFind?. This JobFind? searches in each page for the text and tells the presenter when it find something or when the find is over. For now it only searches for a non existent text and tells the user that the text is not found.

Location:
trunk
Files:
2 added
16 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/FindPter.cxx

    r153 r154  
    2727FindPter::FindPter (IDocument *document) 
    2828{ 
     29    g_assert (NULL != document && "Tried to set a NULL document."); 
     30     
    2931    m_Document = document; 
     32    m_Job = NULL; 
    3033    m_View = NULL; 
    3134} 
     
    3740{ 
    3841    m_Document = NULL; 
     42    if ( NULL != m_Job ) 
     43    { 
     44        m_Job->cancel (); 
     45    } 
    3946    delete m_View; 
    40     m_View = NULL; 
    4147} 
    4248 
     
    5258 
    5359    return *m_View; 
     60} 
     61 
     62void 
     63FindPter::notifyFindFinished (void) 
     64{ 
     65    m_Job->cancel (); 
     66    m_Job = NULL; 
     67    m_View->setInformationText (_("Not Found!")); 
     68    m_Document->notifyFindFinished (); 
    5469} 
    5570 
     
    90105        m_View->sensitiveFindNext (TRUE); 
    91106        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 (); 
    92124    } 
    93125} 
  • trunk/src/FindPter.h

    r153 r154  
    2121namespace ePDFView 
    2222{ 
     23    // Forward declarations. 
     24    class JobFind; 
     25 
    2326    /// 
    2427    /// @class FindPter 
     
    3538 
    3639            IFindView &getView (void); 
     40            void notifyFindFinished (void); 
    3741            void setView (IFindView *view); 
    3842            void textToFindChanged (void); 
     
    4145            /// The document to search to. 
    4246            IDocument *m_Document; 
     47            /// The current find job. 
     48            JobFind *m_Job; 
    4349            /// The view that the presenter is controlling. 
    4450            IFindView *m_View; 
    45  
    4651    }; 
    4752} 
  • trunk/src/IDocument.cxx

    r150 r154  
    202202} 
    203203 
     204void 
     205IDocument::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 
     215void 
     216IDocument::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 
    204226/// 
    205227/// @brief The document has been loaded. 
  • trunk/src/IDocument.h

    r150 r154  
    134134 
    135135            /// 
     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            /// 
    136149            /// @brief Checks if the document has been loaded. 
    137150            /// 
     
    161174                                       const gchar *password,  
    162175                                       GError **error) = 0; 
     176             
    163177            /// 
    164178            /// @brief Gets a document's page's unscaled size. 
     
    190204            void detach (const IDocumentObserver *observer); 
    191205 
     206            void notifyFindFinished (void); 
     207            void notifyFindStarted (void); 
    192208            void notifyLoad (void); 
    193209            void notifyLoadError (const GError *error); 
  • trunk/src/IDocumentObserver.h

    r148 r154  
    3232            /// @brief Destroys all dynamically allocated memory. 
    3333            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             
    3551            /// 
    3652            /// @brief The document has been loaded. 
  • trunk/src/IFindView.h

    r153 r154  
    8888            virtual void sensitiveFindPrevious (gboolean sensitive) = 0; 
    8989 
     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 
    90101        protected: 
    91102            /// The presenter that controls the view. 
  • trunk/src/Makefile.am

    r153 r154  
    2525    IMainView.h \ 
    2626    IPageView.h \ 
     27    JobFind.cxx \ 
     28    JobFind.h   \ 
    2729    JobLoad.cxx         \ 
    2830    JobLoad.h           \ 
  • trunk/src/PDFDocument.cxx

    r151 r154  
    5252        m_Document = NULL; 
    5353    } 
     54} 
     55 
     56GList * 
     57PDFDocument::findTextInPage (gint pageNum, const gchar *textToFind) 
     58{ 
     59    return NULL; 
    5460} 
    5561 
  • trunk/src/PDFDocument.h

    r148 r154  
    3939            ~PDFDocument (void); 
    4040 
     41            GList *findTextInPage (gint pageNum, const gchar *textToFind); 
    4142            gboolean isLoaded (void); 
    4243            gboolean loadFile (const gchar *filename, const gchar *password,  
  • trunk/src/epdfview.h

    r153 r154  
    3939 
    4040#include <IJob.h> 
     41#include <JobFind.h> 
    4142#include <JobLoad.h> 
    4243#include <JobRender.h> 
  • trunk/tests/DumbDocumentObserver.cxx

    r151 r154  
    3232    m_NotifiedPageZoomed = FALSE; 
    3333    m_NotifiedReload = FALSE; 
     34    m_Searching = FALSE; 
    3435    m_Zoom = 0.0; 
    3536} 
     
    3839{ 
    3940    setLoadError (NULL); 
     41} 
     42 
     43void 
     44DumbDocumentObserver::notifyFindFinished () 
     45{ 
     46    m_Searching = FALSE; 
     47} 
     48 
     49void 
     50DumbDocumentObserver::notifyFindStarted () 
     51{ 
     52    m_Searching = TRUE; 
    4053} 
    4154 
     
    112125 
    113126gboolean 
     127DumbDocumentObserver::isStillSearching (void) 
     128{ 
     129    return m_Searching; 
     130} 
     131 
     132gboolean 
    114133DumbDocumentObserver::loadFinished (void) 
    115134{ 
  • trunk/tests/DumbDocumentObserver.h

    r136 r154  
    2727            ~DumbDocumentObserver (void); 
    2828 
     29            void notifyFindFinished (void); 
     30            void notifyFindStarted (void); 
    2931            void notifyLoad (void); 
    3032            void notifyLoadError (const GError *error); 
     
    3638            void notifyReload (void); 
    3739 
     40            // Functions for test only purposes. 
    3841            gint getCurrentPage (void); 
    3942            const GError *getLoadError (void); 
    4043            gdouble getZoom (void); 
     44            gboolean isStillSearching (void); 
    4145            gboolean loadFinished (void); 
    4246            gboolean notifiedError (void); 
     
    5660            gboolean m_NotifiedPageZoomed; 
    5761            gboolean m_NotifiedReload; 
     62            gboolean m_Searching; 
    5863            gdouble m_Zoom; 
    5964    }; 
  • trunk/tests/DumbFindView.cxx

    r153 r154  
    2626    m_FindNextSensitive = TRUE; 
    2727    m_FindNextSensitive = TRUE; 
     28    m_InformationText = g_strdup (""); 
    2829    m_TextToFind = g_strdup (""); 
    2930} 
     
    3132DumbFindView::~DumbFindView () 
    3233{ 
     34    g_free (m_InformationText); 
    3335    g_free (m_TextToFind); 
    3436} 
     
    5254} 
    5355 
     56void 
     57DumbFindView::setInformationText (const gchar *text) 
     58{ 
     59    g_free (m_InformationText); 
     60    m_InformationText = g_strdup (text); 
     61} 
     62 
    5463//////////////////////////////////////////////////////////////// 
    5564// Test Only Functions. 
    5665//////////////////////////////////////////////////////////////// 
     66 
     67const gchar * 
     68DumbFindView::getInformationText () 
     69{ 
     70    return m_InformationText; 
     71} 
    5772 
    5873gboolean 
  • trunk/tests/DumbFindView.h

    r153 r154  
    2626            DumbFindView (void); 
    2727            ~DumbFindView (void); 
    28  
     28             
    2929            const gchar *getTextToFind (void); 
    3030            void sensitiveFindNext (gboolean sensitive); 
    3131            void sensitiveFindPrevious (gboolean sensitive); 
     32            void setInformationText (const gchar *text); 
    3233             
    3334            // Methods for test only purposes. 
     35            const gchar *getInformationText (void); 
    3436            gboolean isFindNextSensitive (void); 
    35             gboolean isFindPreviousSensitive (void); 
     37            gboolean isFindPreviousSensitive (void);             
    3638            void setTextToFind (const gchar *text); 
    3739 
    38         protected: 
     40        protected:             
    3941            gboolean m_FindNextSensitive; 
    4042            gboolean m_FindPreviousSensitive; 
     43            gchar *m_InformationText; 
    4144            gchar *m_TextToFind; 
    4245    }; 
  • trunk/tests/FindPterTest.cxx

    r153 r154  
    2424using namespace ePDFView; 
    2525 
     26G_LOCK_EXTERN (JobRender); 
     27 
    2628// Register the test suite into the `registry'. 
    2729CPPUNIT_TEST_SUITE_REGISTRATION (FindPterTest); 
     
    4244    m_View = new DumbFindView (); 
    4345    m_FindPter->setView (m_View); 
     46     
     47    G_LOCK (JobRender); 
     48    JobRender::m_CanProcessJobs = TRUE; 
     49    G_UNLOCK (JobRender); 
    4450} 
    4551 
     
    5056FindPterTest::tearDown () 
    5157{ 
     58    G_LOCK (JobRender); 
     59    JobRender::m_CanProcessJobs = FALSE; 
     60    IJob::clearQueue (); 
     61    G_UNLOCK (JobRender); 
     62 
    5263    // Deleting the FindPter will also delete the DumbFindView. 
    5364    delete m_FindPter; 
     
    5970/// 
    6071/// @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. 
    6176/// 
    6277void 
     
    7792    CPPUNIT_ASSERT (!m_View->isFindPreviousSensitive ()); 
    7893} 
     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/// 
     102void 
     103FindPterTest::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  
    2727        CPPUNIT_TEST_SUITE (FindPterTest); 
    2828        CPPUNIT_TEST (viewSensitivity); 
     29        CPPUNIT_TEST (textDoesNotExist); 
    2930        CPPUNIT_TEST_SUITE_END (); 
    3031 
     
    3435 
    3536            void viewSensitivity (void); 
     37            void textDoesNotExist (void); 
    3638 
    3739        private: