Changeset 126

Show
Ignore:
Timestamp:
04/29/06 03:01:55 (2 years ago)
Author:
jordi
Message:

Now loading a password protected file works as well using the new observable method.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/IDocument.cxx

    r124 r126  
    252252 
    253253void 
    254 IDocument::notifyLoadError (GError *error
     254IDocument::notifyLoad (
    255255{ 
    256256    for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 
     
    258258    { 
    259259        IDocumentObserver *observer = (IDocumentObserver *)item->data; 
     260        observer->notifyLoad (); 
     261    } 
     262} 
     263 
     264void 
     265IDocument::notifyLoadError (const GError *error) 
     266{ 
     267    for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 
     268          item = g_list_next (item) ) 
     269    { 
     270        IDocumentObserver *observer = (IDocumentObserver *)item->data; 
    260271        observer->notifyLoadError (error); 
    261272    } 
    262     g_error_free (error); 
     273
     274 
     275void 
     276IDocument::notifyLoadPassword (const GError *error) 
     277
     278    for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 
     279          item = g_list_next (item) ) 
     280    { 
     281        IDocumentObserver *observer = (IDocumentObserver *)item->data; 
     282        observer->notifyLoadPassword (error); 
     283    } 
    263284} 
    264285 
     
    269290    job->setDocument (this); 
    270291    job->setFileName (fileName); 
    271     job->setPassword (NULL); 
     292    job->setPassword (password); 
    272293 
    273294    IJob::queue (job); 
  • trunk/src/IDocument.h

    r124 r126  
    177177            void deattach (const IDocumentObserver *observer); 
    178178 
    179             void notifyLoadError (GError *error); 
     179            void notifyLoad (void); 
     180            void notifyLoadError (const GError *error); 
     181            void notifyLoadPassword (const GError *error); 
    180182             
    181183            const gchar *getTitle (void); 
  • trunk/src/IDocumentObserver.h

    r124 r126  
    2525        public: 
    2626            virtual ~IDocumentObserver (void) { } 
    27              
     27            
     28            virtual void notifyLoad (void) { } 
    2829            virtual void notifyLoadError (const GError *error) { } 
     30            virtual void notifyLoadPassword (const GError *error) { } 
    2931 
    3032        protected: 
  • trunk/src/IJob.h

    r124 r126  
    2121#if defined DEBUG 
    2222#define JOB_NOTIFIER(callback, data) callback (data) 
     23#define JOB_DELETE TRUE 
     24#define JOB_NOTIFIER_END() 
    2325#else // !DEBUG 
    2426#define JOB_NOTIFIER(callback, data) g_idle_add (callback, data) 
     27#define JOB_DELETE FALSE 
     28#define JOB_NOTIFIER_END() delete job 
    2529#endif // !DEBUG 
    2630 
  • trunk/src/JobLoad.cxx

    r124 r126  
    110110        JOB_NOTIFIER (job_load_done, this); 
    111111    } 
    112     else if ( DocumentErrorEncrypted == error->code ) 
    113     { 
    114         g_error_free (error); 
    115         JOB_NOTIFIER (job_load_password, this); 
    116     } 
    117112    else 
    118113    { 
    119114        setError (error); 
    120         JOB_NOTIFIER (job_load_error, this); 
    121     } 
    122     return FALSE; 
     115        if ( DocumentErrorEncrypted == error->code ) 
     116        { 
     117            JOB_NOTIFIER (job_load_password, this); 
     118        } 
     119        else 
     120        { 
     121            JOB_NOTIFIER (job_load_error, this); 
     122        } 
     123    } 
     124 
     125    return JOB_DELETE; 
    123126} 
    124127 
     
    191194 
    192195    JobLoad *job = (JobLoad *)data; 
    193  
     196    job->getDocument ().notifyLoad (); 
     197    JOB_NOTIFIER_END(); 
     198     
    194199    return FALSE; 
    195200} 
     
    210215    JobLoad *job = (JobLoad *)data; 
    211216    job->getDocument ().notifyLoadError (job->getError ()); 
     217    JOB_NOTIFIER_END(); 
    212218     
    213219    return FALSE; 
     
    231237 
    232238    JobLoad *job = (JobLoad *)data; 
    233  
    234     return job_load_done (data); 
    235 } 
     239    job->getDocument ().notifyLoadPassword (job->getError ()); 
     240    JOB_NOTIFIER_END(); 
     241} 
  • trunk/tests/DumbDocumentObserver.cxx

    r125 r126  
    2626    m_Error = NULL; 
    2727    m_NotifiedError = FALSE; 
     28    m_NotifiedPassword = FALSE; 
     29    m_NotifiedLoad = FALSE; 
    2830} 
    2931 
    3032DumbDocumentObserver::~DumbDocumentObserver () 
    3133{ 
    32     if ( NULL != m_Error ) 
    33     { 
    34         g_error_free (m_Error); 
    35     } 
     34    setLoadError (NULL); 
     35
     36 
     37void 
     38DumbDocumentObserver::notifyLoad () 
     39
     40    m_NotifiedLoad = TRUE; 
    3641} 
    3742 
     
    3944DumbDocumentObserver::notifyLoadError (const GError *error) 
    4045{ 
    41     if ( NULL != m_Error ) 
    42     { 
    43         g_error_free (m_Error); 
    44     } 
    45     m_Error = g_error_copy (error); 
     46    setLoadError (error); 
    4647    m_NotifiedError = TRUE; 
     48} 
     49 
     50void 
     51DumbDocumentObserver::notifyLoadPassword (const GError *error) 
     52{ 
     53    setLoadError (error); 
     54    m_NotifiedPassword = TRUE; 
    4755} 
    4856 
     
    7280DumbDocumentObserver::loadFinished (void) 
    7381{ 
    74     return m_NotifiedError
     82    return m_NotifiedError || m_NotifiedPassword || m_NotifiedLoad
    7583} 
    7684 
     
    8694DumbDocumentObserver::notifiedLoaded (void) 
    8795{ 
    88     return FALSE; 
     96    gboolean notified = m_NotifiedLoad; 
     97    m_NotifiedLoad = FALSE; 
     98    return notified; 
    8999} 
    90100 
     
    92102DumbDocumentObserver::notifiedPassword (void) 
    93103{ 
    94     return FALSE; 
     104    gboolean notified = m_NotifiedPassword; 
     105    m_NotifiedPassword = FALSE; 
     106    return notified; 
    95107} 
    96108 
     
    106118    return FALSE; 
    107119} 
     120 
     121void 
     122DumbDocumentObserver::setLoadError (const GError *error) 
     123{ 
     124    if ( NULL != m_Error ) 
     125    { 
     126        g_error_free (m_Error); 
     127    } 
     128    if ( NULL != error ) 
     129    {         
     130        m_Error = g_error_copy (error); 
     131    }     
     132} 
  • trunk/tests/DumbDocumentObserver.h

    r124 r126  
    2727            ~DumbDocumentObserver (void); 
    2828 
     29            void notifyLoad (void); 
    2930            void notifyLoadError (const GError *error); 
     31            void notifyLoadPassword (const GError *error); 
    3032 
    3133            gint getCurrentPage (void); 
     
    3840            gboolean notifiedRotation (void); 
    3941            gboolean notifiedZoom (void); 
     42            void setLoadError (const GError *error); 
    4043 
    4144        protected: 
    4245            GError *m_Error; 
    4346            gboolean m_NotifiedError; 
     47            gboolean m_NotifiedLoad; 
     48            gboolean m_NotifiedPassword; 
    4449    }; 
    4550} 
  • trunk/tests/PDFDocumentTest.cxx

    r125 r126  
    102102    m_Document->load (testFile, NULL); 
    103103    while ( !m_Observer->loadFinished () ) { } 
     104    CPPUNIT_ASSERT (m_Observer->notifiedError ()); 
    104105    CPPUNIT_ASSERT (!m_Document->isLoaded ()); 
    105     CPPUNIT_ASSERT (m_Observer->notifiedError ()); 
    106106 
    107107    gchar *documentError = IDocument::getErrorMessage(DocumentErrorOpenFile); 
     
    145145    g_free (errorMessage); 
    146146} 
    147 /* 
     147 
    148148/// 
    149149/// @brief Test to load an encrypted file using invalid passwords. 
     
    157157PDFDocumentTest::encryptedFile (void) 
    158158{ 
    159     GError *error = NULL; 
    160159    gchar *testFile = getTestFile ("test_encrypted.pdf"); 
    161     CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, &error)); 
    162     while ( !m_Observer->loadFinished () ) { } 
     160    m_Document->load (testFile, NULL); 
     161    while ( !m_Observer->loadFinished () ) { } 
     162    CPPUNIT_ASSERT (m_Observer->notifiedPassword ()); 
    163163    CPPUNIT_ASSERT (!m_Document->isLoaded ()); 
    164     CPPUNIT_ASSERT (m_Observer->notifiedPassword ()); 
    165164 
    166165    gchar *documentError = IDocument::getErrorMessage(DocumentErrorEncrypted); 
     
    168167            "Failed to load document '%s'.\n%s\n", testFile, documentError); 
    169168    g_free(documentError); 
    170     error = m_Observer->getLoadError (); 
     169    const GError *error = m_Observer->getLoadError (); 
    171170    DocumentError errorCode = (DocumentError)error->code; 
    172171    CPPUNIT_ASSERT_EQUAL (DocumentErrorEncrypted, errorCode); 
     
    176175     
    177176    // Now try with an invalid password... 
    178     error = NULL
    179     CPPUNIT_ASSERT (m_Document->loadFile (testFile, "invalidpasswd", &error)); 
    180     while ( !m_Observer->loadFinished () ) { } 
     177    m_Document->load (testFile, "invalidpasswd")
     178    while ( !m_Observer->loadFinished () ) { } 
     179    CPPUNIT_ASSERT (m_Observer->notifiedPassword ()); 
    181180    CPPUNIT_ASSERT (!m_Document->isLoaded ()); 
    182     CPPUNIT_ASSERT (m_Observer->notifiedPassword ()); 
    183181 
    184182    documentError = IDocument::getErrorMessage(DocumentErrorEncrypted); 
     
    195193    // And now, just to test that it can load the pdf using the  
    196194    // correct password. 
    197     error = NULL; 
    198     CPPUNIT_ASSERT (m_Document->loadFile (testFile, "testpasswd", &error)); 
    199     while ( !m_Observer->loadFinished () ) { } 
    200     CPPUNIT_ASSERT (m_Document->isLoaded ()); 
     195    m_Document->load (testFile, "testpasswd"); 
     196    while ( !m_Observer->loadFinished () ) { } 
    201197    CPPUNIT_ASSERT (m_Observer->notifiedLoaded ()); 
     198    CPPUNIT_ASSERT (m_Document->isLoaded ()); 
    202199    CPPUNIT_ASSERT_EQUAL (0, 
    203200            g_ascii_strcasecmp (testFile, m_Document->getFileName ())); 
     
    207204    g_free (testFile); 
    208205} 
    209  
     206/* 
    210207/// 
    211208/// @brief Test to open a valid file. 
  • trunk/tests/PDFDocumentTest.h

    r125 r126  
    2929        CPPUNIT_TEST (fileNotFound); 
    3030        CPPUNIT_TEST (invalidFile); 
    31 /*        CPPUNIT_TEST (encryptedFile); 
    32         CPPUNIT_TEST (validFile); 
     31        CPPUNIT_TEST (encryptedFile); 
     32/*        CPPUNIT_TEST (validFile); 
    3333        CPPUNIT_TEST (relativePath); 
    3434        CPPUNIT_TEST (pageChange);