Changeset 65
- Timestamp:
- 04/14/06 16:24:42 (2 years ago)
- Location:
- trunk
- Files:
-
- 10 modified
-
src/IDocument.cxx (modified) (3 diffs)
-
src/IDocument.h (modified) (2 diffs)
-
src/MainPter.cxx (modified) (6 diffs)
-
src/MainPter.h (modified) (1 diff)
-
src/PDFDocument.cxx (modified) (1 diff)
-
tests/DumbDocument.cxx (modified) (5 diffs)
-
tests/DumbDocument.h (modified) (1 diff)
-
tests/MainPterTest.cxx (modified) (4 diffs)
-
tests/MainPterTest.h (modified) (2 diffs)
-
tests/PDFDocumentTest.cxx (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/IDocument.cxx
r64 r65 136 136 m_PageMode = PageModeUnset; 137 137 m_PageNumber = 0; 138 m_Password = NULL; 138 139 m_Producer = NULL; 139 140 m_Rotation = 0; … … 156 157 g_free (m_Keywords); 157 158 g_free (m_ModifiedDate); 159 g_free (m_Password); 158 160 g_free (m_Producer); 159 161 g_free (m_Subject); … … 504 506 505 507 /// 506 /// @brief Set the document's number of pages. 508 /// @brief Gets the password used to open the document. 509 /// 510 /// @return The password used to open the document, or NULL 511 /// if no password was used. 512 /// 513 const gchar * 514 IDocument::getPassword () 515 { 516 return m_Password; 517 } 518 519 /// 520 /// @brief Sets the password user to open the document. 521 /// 522 /// @param password The password used. 523 /// 524 void 525 IDocument::setPassword (const gchar *password) 526 { 527 gchar *oldPassword = m_Password; 528 m_Password = g_strdup (password); 529 g_free (oldPassword); 530 } 531 532 /// 533 /// @brief Sets the document's number of pages. 507 534 /// 508 535 /// @param numPages The number of pages the document has. -
trunk/src/IDocument.h
r63 r65 180 180 const gchar *getCreator (void); 181 181 void setCreator (const gchar *creator); 182 const gchar *getPassword (void); 183 void setPassword (const gchar *password); 182 184 const gchar *getProducer (void); 183 185 void setProducer (const gchar *producer); … … 242 244 PageMode m_PageMode; 243 245 gint m_PageNumber; 246 gchar *m_Password; 244 247 gchar *m_Producer; 245 248 gint m_Rotation; -
trunk/src/MainPter.cxx
r64 r65 245 245 IMainView &view = getView (); 246 246 gchar *fileName = view.openFileDialog (); 247 openDocument (fileName, TRUE);247 openDocument (fileName, NULL, TRUE); 248 248 g_free (fileName); 249 249 } … … 263 263 gdouble currentZoom = m_Document->getZoom (); 264 264 // Reopen the document. 265 openDocument (m_Document->getFileName (), FALSE); 265 openDocument (m_Document->getFileName (), m_Document->getPassword (), 266 FALSE); 266 267 // And restore the state 267 268 m_Document->setZoom (currentZoom); … … 359 360 /// NULL then that means the user didn't wanted to 360 361 /// open a file, so this function won't do anything. 362 /// @param oldPassword This is only used when reloading. It is the last 363 /// password that was used to open a file, and will be 364 /// used to open the file the first try before asking 365 /// to the user. For opening a new file, just set to NULL. 361 366 /// @param canShowPage Set to TRUE if the application should show the page 362 367 /// after the loading or not. This is useful when reloading … … 365 370 /// 366 371 void 367 MainPter::openDocument (const gchar *fileName, gboolean canShowPage) 372 MainPter::openDocument (const gchar *fileName, const gchar *oldPassword, 373 gboolean canShowPage) 368 374 { 369 375 // if fileName is NULL, then the user cancelled the operation. … … 372 378 if ( NULL != fileName ) 373 379 { 374 GError *error = NULL; 375 if ( m_Document->loadFile (fileName, NULL, &error) )380 GError *error = NULL; 381 if ( m_Document->loadFile (fileName, oldPassword, &error) ) 376 382 { 377 383 // Now that the document has been loaded, just reset the initial … … 380 386 } 381 387 else 382 { 388 { 383 389 // We got an error, but also can be that the file is encrypted. 384 390 if ( DocumentErrorEncrypted == error->code ) -
trunk/src/MainPter.h
r63 r65 60 60 61 61 protected: 62 void openDocument (const gchar *fileName, gboolean canShowPage); 62 void openDocument (const gchar *fileName, const gchar *oldPassword, 63 gboolean canShowPage); 63 64 void showPage (void); 64 65 -
trunk/src/PDFDocument.cxx
r63 r65 125 125 126 126 setFileName (filename); 127 setPassword (password); 127 128 delete m_Document; 128 129 m_Document = newDocument; -
trunk/tests/DumbDocument.cxx
r63 r65 30 30 m_Loaded = FALSE; 31 31 m_OpenError = DocumentErrorNone; 32 m_ Password = NULL;32 m_TestPassword = NULL; 33 33 setNumPages (2); 34 34 } … … 36 36 DumbDocument::~DumbDocument () 37 37 { 38 g_free (m_ Password);38 g_free (m_TestPassword); 39 39 } 40 40 … … 51 51 if ( DocumentErrorNone == m_OpenError ) 52 52 { 53 m_Loaded = TRUE; 53 54 setFileName (filename); 54 m_Loaded = TRUE;55 setPassword (password); 55 56 } 56 57 else if ( DocumentErrorEncrypted == m_OpenError && 57 password != NULL &&58 0 == g_ascii_strcasecmp (password, m_ Password))58 NULL != password && NULL != m_TestPassword && 59 0 == g_ascii_strcasecmp (password, m_TestPassword)) 59 60 { 61 m_Loaded = TRUE; 60 62 setFileName (filename); 61 m_Loaded = TRUE;63 setPassword (password); 62 64 } 63 65 else … … 65 67 g_set_error (error, EPDFVIEW_DOCUMENT_ERROR, m_OpenError, 66 68 "%s", IDocument::getErrorMessage (m_OpenError)); 69 m_Loaded = FALSE; 67 70 } 68 71 setRotation (0); … … 102 105 103 106 void 104 DumbDocument::set Password (const gchar *password)107 DumbDocument::setTestPassword (const gchar *password) 105 108 { 106 g_free (m_Password); 107 m_Password = g_strdup (password); 109 gchar *oldPassword = m_TestPassword; 110 m_TestPassword = g_strdup (password); 111 g_free (oldPassword); 108 112 } -
trunk/tests/DumbDocument.h
r27 r65 36 36 // Test functions. 37 37 void setOpenError (DocumentError error); 38 void set Password (const gchar *password);38 void setTestPassword (const gchar *password); 39 39 40 40 private: 41 41 gboolean m_Loaded; 42 42 DocumentError m_OpenError; 43 gchar *m_ Password;43 gchar *m_TestPassword; 44 44 }; 45 45 } -
trunk/tests/MainPterTest.cxx
r64 r65 233 233 m_View->setOpenFileName ("/tmp/test.pdf"); 234 234 m_View->setPassword ("badpassword"); 235 m_Document->set Password ("goodpassword");235 m_Document->setTestPassword ("goodpassword"); 236 236 m_Document->setOpenError (DocumentErrorEncrypted); 237 237 m_MainPter->openFileActivated (); … … 266 266 m_View->setOpenFileName ("/tmp/test.pdf"); 267 267 m_View->setPassword ("goodpassword"); 268 m_Document->set Password ("goodpassword");268 m_Document->setTestPassword ("goodpassword"); 269 269 m_Document->setOpenError (DocumentErrorEncrypted); 270 270 m_MainPter->openFileActivated (); … … 566 566 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 567 567 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 568 CPPUNIT_ASSERT (!m_View->hasImagePageView ());569 568 570 569 // Reload the document. … … 576 575 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 577 576 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 578 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 579 } 577 } 578 579 /// 580 /// @brief Tries to reload an encrypted file. 581 /// 582 /// Reloading an encrypted file won't ask for the password unless it changed, 583 /// but here we assume that don't 584 /// 585 void 586 MainPterTest::reloadEncrypted () 587 { 588 m_View->setOpenFileName ("/tmp/test.pdf"); 589 m_View->setPassword ("goodpassword"); 590 m_Document->setTestPassword ("goodpassword"); 591 m_Document->setOpenError (DocumentErrorEncrypted); 592 m_MainPter->openFileActivated (); 593 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 594 CPPUNIT_ASSERT_EQUAL (0, 595 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 596 597 m_MainPter->goToNextPageActivated (); 598 m_MainPter->rotateRightActivated (); 599 m_MainPter->zoomWidthActivated (); 600 CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); 601 CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 602 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 603 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 604 605 // Reload the document. 606 m_View->setPassword ("badpassword"); 607 m_Document->setTestPassword ("goodpassword"); 608 m_Document->setOpenError (DocumentErrorEncrypted); 609 m_MainPter->reloadActivated (); 610 CPPUNIT_ASSERT_EQUAL (0, 611 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 612 CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); 613 CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 614 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 615 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 616 CPPUNIT_ASSERT (!m_View->shownError ()); 617 CPPUNIT_ASSERT_EQUAL (0, m_View->countTimesShownPasswordPrompt ()); 618 } 619 620 /// 621 /// @brief Tries to reload an encrypted file whose password changed. 622 /// 623 /// Reloading an encrypted file won't ask for the password unless it changed. 624 /// 625 void 626 MainPterTest::reloadChangedPassword () 627 { 628 m_View->setOpenFileName ("/tmp/test.pdf"); 629 m_View->setPassword ("goodpassword"); 630 m_Document->setTestPassword ("goodpassword"); 631 m_Document->setOpenError (DocumentErrorEncrypted); 632 m_MainPter->openFileActivated (); 633 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 634 CPPUNIT_ASSERT_EQUAL (0, 635 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 636 637 m_MainPter->goToNextPageActivated (); 638 m_MainPter->rotateRightActivated (); 639 m_MainPter->zoomWidthActivated (); 640 CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); 641 CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 642 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 643 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 644 645 // Reload the document. 646 m_View->setPassword ("newpassword"); 647 m_Document->setTestPassword ("newpassword"); 648 CPPUNIT_ASSERT_EQUAL (0, 649 g_ascii_strcasecmp("goodpassword", m_Document->getPassword ())); 650 m_Document->setOpenError (DocumentErrorEncrypted); 651 m_MainPter->reloadActivated (); 652 CPPUNIT_ASSERT_EQUAL (0, 653 g_ascii_strcasecmp("newpassword", m_Document->getPassword ())); 654 CPPUNIT_ASSERT_EQUAL (0, 655 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 656 CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); 657 CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); 658 CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); 659 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 660 CPPUNIT_ASSERT (!m_View->shownError ()); 661 CPPUNIT_ASSERT_EQUAL (1, m_View->countTimesShownPasswordPrompt ()); 662 } -
trunk/tests/MainPterTest.h
r63 r65 38 38 CPPUNIT_TEST (pageZoom); 39 39 CPPUNIT_TEST (reloadNormal); 40 CPPUNIT_TEST (reloadEncrypted); 41 CPPUNIT_TEST (reloadChangedPassword); 40 42 CPPUNIT_TEST_SUITE_END(); 41 43 … … 56 58 void pageZoom (void); 57 59 void reloadNormal (void); 60 void reloadEncrypted (void); 61 void reloadChangedPassword (void); 58 62 59 63 private: -
trunk/tests/PDFDocumentTest.cxx
r58 r65 194 194 g_ascii_strcasecmp (TEST_DATA_DIR "test_encrypted.pdf", 195 195 m_Document->getFileName ())); 196 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("testpasswd", 197 m_Document->getPassword ())); 196 198 } 197 199
