Changeset 126
- Timestamp:
- 04/29/06 03:01:55 (2 years ago)
- Files:
-
- trunk/src/IDocument.cxx (modified) (3 diffs)
- trunk/src/IDocument.h (modified) (1 diff)
- trunk/src/IDocumentObserver.h (modified) (1 diff)
- trunk/src/IJob.h (modified) (1 diff)
- trunk/src/JobLoad.cxx (modified) (4 diffs)
- trunk/tests/DumbDocumentObserver.cxx (modified) (6 diffs)
- trunk/tests/DumbDocumentObserver.h (modified) (2 diffs)
- trunk/tests/PDFDocumentTest.cxx (modified) (7 diffs)
- trunk/tests/PDFDocumentTest.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/IDocument.cxx
r124 r126 252 252 253 253 void 254 IDocument::notifyLoad Error (GError *error)254 IDocument::notifyLoad () 255 255 { 256 256 for ( GList *item = g_list_first (m_Observers) ; NULL != item ; … … 258 258 { 259 259 IDocumentObserver *observer = (IDocumentObserver *)item->data; 260 observer->notifyLoad (); 261 } 262 } 263 264 void 265 IDocument::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; 260 271 observer->notifyLoadError (error); 261 272 } 262 g_error_free (error); 273 } 274 275 void 276 IDocument::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 } 263 284 } 264 285 … … 269 290 job->setDocument (this); 270 291 job->setFileName (fileName); 271 job->setPassword ( NULL);292 job->setPassword (password); 272 293 273 294 IJob::queue (job); trunk/src/IDocument.h
r124 r126 177 177 void deattach (const IDocumentObserver *observer); 178 178 179 void notifyLoadError (GError *error); 179 void notifyLoad (void); 180 void notifyLoadError (const GError *error); 181 void notifyLoadPassword (const GError *error); 180 182 181 183 const gchar *getTitle (void); trunk/src/IDocumentObserver.h
r124 r126 25 25 public: 26 26 virtual ~IDocumentObserver (void) { } 27 27 28 virtual void notifyLoad (void) { } 28 29 virtual void notifyLoadError (const GError *error) { } 30 virtual void notifyLoadPassword (const GError *error) { } 29 31 30 32 protected: trunk/src/IJob.h
r124 r126 21 21 #if defined DEBUG 22 22 #define JOB_NOTIFIER(callback, data) callback (data) 23 #define JOB_DELETE TRUE 24 #define JOB_NOTIFIER_END() 23 25 #else // !DEBUG 24 26 #define JOB_NOTIFIER(callback, data) g_idle_add (callback, data) 27 #define JOB_DELETE FALSE 28 #define JOB_NOTIFIER_END() delete job 25 29 #endif // !DEBUG 26 30 trunk/src/JobLoad.cxx
r124 r126 110 110 JOB_NOTIFIER (job_load_done, this); 111 111 } 112 else if ( DocumentErrorEncrypted == error->code )113 {114 g_error_free (error);115 JOB_NOTIFIER (job_load_password, this);116 }117 112 else 118 113 { 119 114 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; 123 126 } 124 127 … … 191 194 192 195 JobLoad *job = (JobLoad *)data; 193 196 job->getDocument ().notifyLoad (); 197 JOB_NOTIFIER_END(); 198 194 199 return FALSE; 195 200 } … … 210 215 JobLoad *job = (JobLoad *)data; 211 216 job->getDocument ().notifyLoadError (job->getError ()); 217 JOB_NOTIFIER_END(); 212 218 213 219 return FALSE; … … 231 237 232 238 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 26 26 m_Error = NULL; 27 27 m_NotifiedError = FALSE; 28 m_NotifiedPassword = FALSE; 29 m_NotifiedLoad = FALSE; 28 30 } 29 31 30 32 DumbDocumentObserver::~DumbDocumentObserver () 31 33 { 32 if ( NULL != m_Error ) 33 { 34 g_error_free (m_Error); 35 } 34 setLoadError (NULL); 35 } 36 37 void 38 DumbDocumentObserver::notifyLoad () 39 { 40 m_NotifiedLoad = TRUE; 36 41 } 37 42 … … 39 44 DumbDocumentObserver::notifyLoadError (const GError *error) 40 45 { 41 if ( NULL != m_Error ) 42 { 43 g_error_free (m_Error); 44 } 45 m_Error = g_error_copy (error); 46 setLoadError (error); 46 47 m_NotifiedError = TRUE; 48 } 49 50 void 51 DumbDocumentObserver::notifyLoadPassword (const GError *error) 52 { 53 setLoadError (error); 54 m_NotifiedPassword = TRUE; 47 55 } 48 56 … … 72 80 DumbDocumentObserver::loadFinished (void) 73 81 { 74 return m_NotifiedError ;82 return m_NotifiedError || m_NotifiedPassword || m_NotifiedLoad; 75 83 } 76 84 … … 86 94 DumbDocumentObserver::notifiedLoaded (void) 87 95 { 88 return FALSE; 96 gboolean notified = m_NotifiedLoad; 97 m_NotifiedLoad = FALSE; 98 return notified; 89 99 } 90 100 … … 92 102 DumbDocumentObserver::notifiedPassword (void) 93 103 { 94 return FALSE; 104 gboolean notified = m_NotifiedPassword; 105 m_NotifiedPassword = FALSE; 106 return notified; 95 107 } 96 108 … … 106 118 return FALSE; 107 119 } 120 121 void 122 DumbDocumentObserver::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 27 27 ~DumbDocumentObserver (void); 28 28 29 void notifyLoad (void); 29 30 void notifyLoadError (const GError *error); 31 void notifyLoadPassword (const GError *error); 30 32 31 33 gint getCurrentPage (void); … … 38 40 gboolean notifiedRotation (void); 39 41 gboolean notifiedZoom (void); 42 void setLoadError (const GError *error); 40 43 41 44 protected: 42 45 GError *m_Error; 43 46 gboolean m_NotifiedError; 47 gboolean m_NotifiedLoad; 48 gboolean m_NotifiedPassword; 44 49 }; 45 50 } trunk/tests/PDFDocumentTest.cxx
r125 r126 102 102 m_Document->load (testFile, NULL); 103 103 while ( !m_Observer->loadFinished () ) { } 104 CPPUNIT_ASSERT (m_Observer->notifiedError ()); 104 105 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 105 CPPUNIT_ASSERT (m_Observer->notifiedError ());106 106 107 107 gchar *documentError = IDocument::getErrorMessage(DocumentErrorOpenFile); … … 145 145 g_free (errorMessage); 146 146 } 147 /* 147 148 148 /// 149 149 /// @brief Test to load an encrypted file using invalid passwords. … … 157 157 PDFDocumentTest::encryptedFile (void) 158 158 { 159 GError *error = NULL;160 159 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 ()); 163 163 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 164 CPPUNIT_ASSERT (m_Observer->notifiedPassword ());165 164 166 165 gchar *documentError = IDocument::getErrorMessage(DocumentErrorEncrypted); … … 168 167 "Failed to load document '%s'.\n%s\n", testFile, documentError); 169 168 g_free(documentError); 170 error = m_Observer->getLoadError ();169 const GError *error = m_Observer->getLoadError (); 171 170 DocumentError errorCode = (DocumentError)error->code; 172 171 CPPUNIT_ASSERT_EQUAL (DocumentErrorEncrypted, errorCode); … … 176 175 177 176 // 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 ()); 181 180 CPPUNIT_ASSERT (!m_Document->isLoaded ()); 182 CPPUNIT_ASSERT (m_Observer->notifiedPassword ());183 181 184 182 documentError = IDocument::getErrorMessage(DocumentErrorEncrypted); … … 195 193 // And now, just to test that it can load the pdf using the 196 194 // 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 () ) { } 201 197 CPPUNIT_ASSERT (m_Observer->notifiedLoaded ()); 198 CPPUNIT_ASSERT (m_Document->isLoaded ()); 202 199 CPPUNIT_ASSERT_EQUAL (0, 203 200 g_ascii_strcasecmp (testFile, m_Document->getFileName ())); … … 207 204 g_free (testFile); 208 205 } 209 206 /* 210 207 /// 211 208 /// @brief Test to open a valid file. trunk/tests/PDFDocumentTest.h
r125 r126 29 29 CPPUNIT_TEST (fileNotFound); 30 30 CPPUNIT_TEST (invalidFile); 31 /*CPPUNIT_TEST (encryptedFile);32 CPPUNIT_TEST (validFile);31 CPPUNIT_TEST (encryptedFile); 32 /* CPPUNIT_TEST (validFile); 33 33 CPPUNIT_TEST (relativePath); 34 34 CPPUNIT_TEST (pageChange);
