Changeset 115
- Timestamp:
- 04/25/06 07:04:09 (2 years ago)
- Files:
-
- trunk/configure.ac (modified) (2 diffs)
- trunk/src/JobLoad.cxx (added)
- trunk/src/JobLoad.h (added)
- trunk/src/MainPter.cxx (modified) (5 diffs)
- trunk/src/MainPter.h (modified) (2 diffs)
- trunk/src/Makefile.am (modified) (1 diff)
- trunk/src/epdfview.h (modified) (1 diff)
- trunk/src/main.cxx (modified) (3 diffs)
- trunk/tests/MainPterTest.cxx (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/configure.ac
r90 r115 1 1 dnl Process this file with autoconf to produce a configure script. 2 AC_INIT([ePDFView], [0.1. 3], [jordi@emma-soft.com])2 AC_INIT([ePDFView], [0.1.4], [jordi@emma-soft.com]) 3 3 AC_PREREQ([2.13]) 4 4 AC_CONFIG_HEADER([config.h]) … … 31 31 GTK2_REQUIRED=2.6.0 32 32 33 PKG_CHECK_MODULES([GLIB], [g lib-2.0 >= $GLIB_REQUIRED])33 PKG_CHECK_MODULES([GLIB], [gthread-2.0 >= $GLIB_REQUIRED]) 34 34 AC_SUBST([GLIB_CFLAGS]) 35 35 AC_SUBST([GLIB_LIBS]) trunk/src/MainPter.cxx
r110 r115 276 276 MainPter::openFileActivated () 277 277 { 278 IMainView &view = getView (); 279 Config &config = Config::getConfig (); 280 278 Config &config = Config::getConfig (); 281 279 gchar *lastFolder = config.getOpenFileFolder (); 282 gchar *fileName = view.openFileDialog (lastFolder); 283 g_free (lastFolder); 284 285 openDocument (fileName, NULL, TRUE); 280 gchar *fileName = getView ().openFileDialog (lastFolder); 281 g_free (lastFolder); 286 282 if ( NULL != fileName ) 287 283 { 288 gchar *dirName = g_path_get_dirname (fileName); 289 g_free (fileName); 290 284 gchar *dirName = g_path_get_dirname (fileName); 291 285 config.setOpenFileFolder (dirName); 292 286 g_free (dirName); 293 287 } 294 288 289 JobLoad *job = new JobLoad (); 290 job->setPresenter (this); 291 job->setFileName (fileName); 292 g_free (fileName); 293 job->setPassword (NULL); 294 job->setReload (FALSE); 295 job->run (); 295 296 } 296 297 … … 356 357 MainPter::reloadActivated () 357 358 { 359 JobLoad *job = new JobLoad (); 360 job->setPresenter (this); 361 job->setFileName (m_Document->getFileName ()); 362 job->setPassword (m_Document->getPassword ()); 363 job->setReload (TRUE); 358 364 // Save the current document's state. 359 gint currentPage = m_Document->getCurrentPageNum ();360 gint currentRotation = m_Document->getRotation ();361 gdouble currentZoom = m_Document->getZoom ();365 job->setPage (m_Document->getCurrentPageNum ()); 366 job->setRotation (m_Document->getRotation ()); 367 job->setZoom ( m_Document->getZoom ()); 362 368 // Reopen the document. 363 openDocument (m_Document->getFileName (), m_Document->getPassword (), 364 FALSE); 365 // And restore the state 366 m_Document->setZoom (currentZoom); 367 m_Document->setRotation (currentRotation); 368 m_Document->goToPage (currentPage); 369 job->run (); 370 } 371 372 /// 373 /// @brief The "Rotate Left" was activated. 374 /// 375 void 376 MainPter::rotateLeftActivated () 377 { 378 g_assert ( NULL != m_Document && "Tried to rotate a NULL document."); 379 380 m_Document->rotateLeft (); 381 382 Config &config = Config::getConfig (); 383 if ( config.zoomToWidth () ) 384 { 385 zoomWidth (); 386 } 387 else if ( config.zoomToFit () ) 388 { 389 zoomFit (); 390 } 391 showPage (PAGE_SCROLL_START); 392 } 393 394 /// 395 /// @brief The "Rotate Right" was activated. 396 /// 397 void 398 MainPter::rotateRightActivated () 399 { 400 g_assert ( NULL != m_Document && "Tried to rotate a NULL document."); 401 402 m_Document->rotateRight (); 403 404 Config &config = Config::getConfig (); 405 if ( config.zoomToWidth () ) 406 { 407 zoomWidth (); 408 } 409 else if ( config.zoomToFit () ) 410 { 411 zoomFit (); 412 } 413 showPage (PAGE_SCROLL_START); 414 } 415 416 /// 417 /// @brief Sets the document context. 418 /// 419 /// By context I mean the rotation, zoom and current page number 420 /// of the document. 421 /// This function is used when reloading to restore the previous 422 /// context (a la function call). 423 /// 424 /// @param pageNum The current document's page number. 425 /// @param rotation The current document's rotation. 426 /// @param zoom The current document's zoom. 427 /// 428 void 429 MainPter::setContext (gint pageNum, gint rotation, gdouble zoom) 430 { 431 m_Document->setZoom (zoom); 432 m_Document->setRotation (rotation); 433 m_Document->goToPage (pageNum); 369 434 // Draw the document. 370 435 showPage (PAGE_SCROLL_NONE); 371 436 } 372 437 373 ///374 /// @brief The "Rotate Left" was activated.375 ///376 void377 MainPter::rotateLeftActivated ()378 {379 g_assert ( NULL != m_Document && "Tried to rotate a NULL document.");380 381 m_Document->rotateLeft ();382 383 Config &config = Config::getConfig ();384 if ( config.zoomToWidth () )385 {386 zoomWidth ();387 }388 else if ( config.zoomToFit () )389 {390 zoomFit ();391 }392 showPage (PAGE_SCROLL_START);393 }394 395 ///396 /// @brief The "Rotate Right" was activated.397 ///398 void399 MainPter::rotateRightActivated ()400 {401 g_assert ( NULL != m_Document && "Tried to rotate a NULL document.");402 403 m_Document->rotateRight ();404 405 Config &config = Config::getConfig ();406 if ( config.zoomToWidth () )407 {408 zoomWidth ();409 }410 else if ( config.zoomToFit () )411 {412 zoomFit ();413 }414 showPage (PAGE_SCROLL_START);415 }416 438 417 439 /// … … 582 604 /// page, rotation and zoom again and then show the page. 583 605 /// 584 void 606 bool 585 607 MainPter::openDocument (const gchar *fileName, const gchar *oldPassword, 586 gboolean canShowPage)608 GError **error) 587 609 { 588 610 // if fileName is NULL, then the user cancelled the operation. … … 591 613 if ( NULL != fileName ) 592 614 { 593 GError *error = NULL; 594 if ( m_Document->loadFile (fileName, oldPassword, &error) ) 615 return m_Document->loadFile (fileName, oldPassword, error); 616 } 617 return TRUE; 618 } 619 /* 595 620 { 596 621 // Now that the document has been loaded, just reset the initial … … 645 670 } 646 671 } 647 } 648 672 673 } 674 */ 649 675 650 676 /// trunk/src/MainPter.h
r107 r115 50 50 void goToPageActivated (void); 51 51 void goToPreviousPageActivated (void); 52 voidopenDocument (const gchar *fileName, const gchar *oldPassword,53 gboolean canShowPage);52 bool openDocument (const gchar *fileName, const gchar *oldPassword, 53 GError **error); 54 54 void openFileActivated (void); 55 55 void outlineActivated (DocumentOutline *outline); … … 61 61 void showStatusbarActivated (gboolean show); 62 62 void showToolbarActivated (gboolean show); 63 void setContext (gint pageNum, gint rotation, gdouble zoom); 63 64 void zoomFitActivated (gboolean active); 64 65 void zoomInActivated (void); trunk/src/Makefile.am
r92 r115 15 15 IDocument.cxx \ 16 16 IDocument.h \ 17 JobLoad.cxx \ 18 JobLoad.h \ 17 19 MainPter.cxx \ 18 20 MainPter.h \ trunk/src/epdfview.h
r92 r115 32 32 #include <MainPter.h> 33 33 34 #include <JobLoad.h> 35 34 36 #endif //!__E_PDF_VIEW_H__ trunk/src/main.cxx
r94 r115 25 25 #include "MainPter.h" 26 26 #include "Config.h" 27 #include "JobLoad.h" 27 28 28 29 29 30 using namespace ePDFView; 30 31 ///32 /// @brief The data passed to open_command_line_file() function.33 ///34 typedef struct35 {36 /// The presenter to make open the file.37 MainPter *presenter;38 /// The file name to open.39 gchar *fileName;40 } OpenFileData;41 42 // Forward declarations.43 static gboolean open_command_line_file (gpointer data);44 31 45 32 int … … 71 58 if ( argc > 1 ) 72 59 { 73 OpenFileData *openFile = new OpenFileData; 74 if ( NULL != openFile ) 75 { 76 openFile->presenter = mainPter; 77 openFile->fileName = g_strdup (argv[1]); 78 79 // This will call the function when no other GTK event is on 80 // the queue, and will let the presenter open the file when 81 // then main view is shown. 82 g_idle_add (open_command_line_file, openFile); 83 } 60 JobLoad *job = new JobLoad (); 61 job->setPresenter (mainPter); 62 job->setFileName (argv[1]); 63 job->run (); 84 64 } 85 65 // Create the main view. … … 100 80 return EXIT_SUCCESS; 101 81 } 102 103 gboolean104 open_command_line_file (gpointer data)105 {106 g_assert (NULL != data && "The data parameter is NULL.");107 108 OpenFileData *openFile = (OpenFileData *)data;109 g_assert (NULL != openFile->presenter && "The presenter is NULL.");110 g_assert (NULL != openFile->fileName && "The file name is NULL.");111 openFile->presenter->openDocument (openFile->fileName, NULL, TRUE);112 delete openFile;113 114 // Returning FALSE means that the function won't be called again.115 return FALSE;116 }trunk/tests/MainPterTest.cxx
r104 r115 99 99 m_View->setOpenFileName ("/tmp/test.pdf"); 100 100 m_MainPter->openFileActivated (); 101 // Sleep to let the thread open the file. 102 sleep (1); 101 103 CPPUNIT_ASSERT_EQUAL (0, 102 104 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); … … 119 121 m_Document->setTitle (g_strdup ("Test PDF")); 120 122 m_MainPter->openFileActivated (); 123 // Sleep to let the thread open the file. 124 sleep (1); 121 125 CPPUNIT_ASSERT_EQUAL (0, 122 126 g_ascii_strcasecmp ("Test PDF", m_View->getTitle ())); … … 148 152 m_View->setOpenFileName (NULL); 149 153 m_MainPter->openFileActivated (); 154 // Sleep to let the thread open the file. 155 sleep (1); 150 156 CPPUNIT_ASSERT_EQUAL (0, 151 157 g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); … … 179 185 m_Document->setOpenError (DocumentErrorDamaged); 180 186 m_MainPter->openFileActivated (); 187 // Sleep to let the thread open the file. 188 sleep (1); 181 189 CPPUNIT_ASSERT_EQUAL (0, 182 190 g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); … … 212 220 m_Document->setOpenError (DocumentErrorEncrypted); 213 221 m_MainPter->openFileActivated (); 222 // Sleep to let the thread open the file. 223 sleep (1); 214 224 CPPUNIT_ASSERT_EQUAL (0, 215 225 g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); … … 245 255 m_Document->setOpenError (DocumentErrorEncrypted); 246 256 m_MainPter->openFileActivated (); 257 // Sleep to let the thread open the file. 258 sleep (1); 247 259 CPPUNIT_ASSERT_EQUAL (0, 248 260 g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); … … 278 290 m_Document->setOpenError (DocumentErrorEncrypted); 279 291 m_MainPter->openFileActivated (); 292 // Sleep to let the thread open the file. 293 sleep (1); 280 294 CPPUNIT_ASSERT_EQUAL (0, 281 295 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); … … 309 323 m_View->setOpenFileName ("/tmp/test.pdf"); 310 324 m_MainPter->openFileActivated (); 325 // Sleep to let the thread open the file. 326 sleep (1); 311 327 CPPUNIT_ASSERT (NULL == m_View->getLastOpenFileFolder ()); 312 328 … … 314 330 m_View->setOpenFileName ("/usr/test.pdf"); 315 331 m_MainPter->openFileActivated (); 332 // Sleep to let the thread open the file. 333 sleep (1); 316 334 CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/tmp", 317 335 m_View->getLastOpenFileFolder ())); 318 336 319 337 m_MainPter->openFileActivated (); 338 // Sleep to let the thread open the file. 339 sleep (1); 320 340 CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/usr", 321 341 m_View->getLastOpenFileFolder ())); … … 334 354 m_Document->setNumPages (4); 335 355 m_MainPter->openFileActivated (); 356 // Sleep to let the thread open the file. 357 sleep (1); 336 358 // Check that sets the correct number of pages and the current page. 337 359 CPPUNIT_ASSERT_EQUAL (4, m_View->getTotalPages ()); … … 414 436 m_Document->setNumPages (4); 415 437 m_MainPter->openFileActivated (); 438 // Sleep to let the thread open the file. 439 sleep (1); 416 440 // Check that sets the correct number of pages and the current page. 417 441 CPPUNIT_ASSERT_EQUAL (4, m_View->getTotalPages ()); … … 493 517 m_View->setOpenFileName ("/tmp/test.pdf"); 494 518 m_MainPter->openFileActivated (); 519 // Sleep to let the thread open the file. 520 sleep (1); 495 521 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 496 522 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); … … 521 547 m_View->setOpenFileName ("/tmp/test.pdf"); 522 548 m_MainPter->openFileActivated (); 549 // Sleep to let the thread open the file. 550 sleep (1); 523 551 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 524 552 CPPUNIT_ASSERT (!m_View->hasImagePageView ()); … … 560 588 m_View->setOpenFileName ("/tmp/test.pdf"); 561 589 m_MainPter->openFileActivated (); 590 // Sleep to let the thread open the file. 591 sleep (1); 562 592 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 563 593 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); … … 624 654 m_View->setOpenFileName ("/tmp/test.pdf"); 625 655 m_MainPter->openFileActivated (); 656 // Sleep to let the thread open the file. 657 sleep (1); 626 658 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 627 659 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); … … 687 719 m_View->setOpenFileName ("/tmp/test.pdf"); 688 720 m_MainPter->openFileActivated (); 721 // Sleep to let the thread open the file. 722 sleep (1); 689 723 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 690 724 CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); … … 730 764 m_View->setOpenFileName ("/tmp/test.pdf"); 731 765 m_MainPter->openFileActivated (); 766 // Sleep to let the thread open the file. 767 sleep (1); 732 768 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 733 769 … … 742 778 // Reload the document. 743 779 m_MainPter->reloadActivated (); 780 // Sleep to let the thread open the file. 781 sleep (1); 744 782 CPPUNIT_ASSERT_EQUAL (0, 745 783 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); … … 764 802 m_Document->setOpenError (DocumentErrorEncrypted); 765 803 m_MainPter->openFileActivated (); 804 // Sleep to let the thread open the file. 805 sleep (1); 766 806 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 767 807 CPPUNIT_ASSERT_EQUAL (0, … … 781 821 m_Document->setOpenError (DocumentErrorEncrypted); 782 822 m_MainPter->reloadActivated (); 823 // Sleep to let the thread open the file. 824 sleep (1); 783 825 CPPUNIT_ASSERT_EQUAL (0, 784 826 g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); … … 804 846 m_Document->setOpenError (DocumentErrorEncrypted); 805 847 m_MainPter->openFileActivated (); 848 // Sleep to let the thread open the file. 849 sleep (1); 806 850 CPPUNIT_ASSERT (m_View->hasImagePageView ()); 807 851 CPPUNIT_ASSERT_EQUAL (0, … … 823 867 m_Document->setOpenError (DocumentErrorEncrypted); 824 868 m_MainPter->reloadActivated (); 869 // Sleep to let the thread open the file. 870 sleep (1); 825 871 CPPUNIT_ASSERT_EQUAL (0, 826 872 g_ascii_strcasecmp("newpassword", m_Document->getPassword ())); … … 860 906 m_View->setOpenFileName ("/tmp/test.pdf"); 861 907 m_MainPter->openFileActivated (); 908 // Sleep to let the thread open the file. 909 sleep (1); 862 910 CPPUNIT_ASSERT (m_View->isShownSidebar ()); 863 911 CPPUNIT_ASSERT (outline == m_View->getOutline ());
