Changeset 115

Show
Ignore:
Timestamp:
04/25/06 07:04:09 (2 years ago)
Author:
jordi
Message:

Loading or reloading a document is now a background process, so the GUI remains "alive" while the presenter loading the file. There are known "bugs", though, that will be fixed on the next commits: The window doesn't unsensitives the open action, the reload action and doesn't show the "opening file" and a progress bar to the status bar.

Also I had to change the check on the configure.ac from glib-2.0 to gthread-2.0, because it's needed in order to use threads on glib. While I was there I changed the current release version to the next 0.1.4 also.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/configure.ac

    r90 r115  
    11dnl Process this file with autoconf to produce a configure script. 
    2 AC_INIT([ePDFView], [0.1.3], [jordi@emma-soft.com]) 
     2AC_INIT([ePDFView], [0.1.4], [jordi@emma-soft.com]) 
    33AC_PREREQ([2.13]) 
    44AC_CONFIG_HEADER([config.h]) 
     
    3131GTK2_REQUIRED=2.6.0 
    3232 
    33 PKG_CHECK_MODULES([GLIB], [glib-2.0 >= $GLIB_REQUIRED]) 
     33PKG_CHECK_MODULES([GLIB], [gthread-2.0 >= $GLIB_REQUIRED]) 
    3434AC_SUBST([GLIB_CFLAGS]) 
    3535AC_SUBST([GLIB_LIBS]) 
  • trunk/src/MainPter.cxx

    r110 r115  
    276276MainPter::openFileActivated () 
    277277{ 
    278     IMainView &view = getView (); 
    279     Config &config = Config::getConfig (); 
    280      
     278    Config &config = Config::getConfig (); 
    281279    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);     
    286282    if ( NULL != fileName ) 
    287283    { 
    288         gchar *dirName = g_path_get_dirname (fileName); 
    289         g_free (fileName); 
    290          
     284        gchar *dirName = g_path_get_dirname (fileName);         
    291285        config.setOpenFileFolder (dirName); 
    292286        g_free (dirName); 
    293287    } 
    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 (); 
    295296} 
    296297 
     
    356357MainPter::reloadActivated () 
    357358{     
     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); 
    358364    // 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 ()); 
    362368    // 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/// 
     375void 
     376MainPter::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/// 
     397void 
     398MainPter::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/// 
     428void 
     429MainPter::setContext (gint pageNum, gint rotation, gdouble zoom) 
     430
     431    m_Document->setZoom (zoom); 
     432    m_Document->setRotation (rotation); 
     433    m_Document->goToPage (pageNum); 
    369434    // Draw the document. 
    370435    showPage (PAGE_SCROLL_NONE); 
    371436} 
    372437 
    373 /// 
    374 /// @brief The "Rotate Left" was activated. 
    375 /// 
    376 void 
    377 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 void 
    399 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 } 
    416438 
    417439/// 
     
    582604///                    page, rotation and zoom again and then show the page. 
    583605/// 
    584 void 
     606bool 
    585607MainPter::openDocument (const gchar *fileName, const gchar *oldPassword, 
    586                         gboolean canShowPage
     608                        GError **error
    587609{ 
    588610    // if fileName is NULL, then the user cancelled the operation. 
     
    591613    if ( NULL != fileName ) 
    592614    { 
    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/* 
    595620        { 
    596621            // Now that the document has been loaded, just reset the initial 
     
    645670        } 
    646671    } 
    647 
    648  
     672     
     673
     674*/ 
    649675 
    650676/// 
  • trunk/src/MainPter.h

    r107 r115  
    5050            void goToPageActivated (void); 
    5151            void goToPreviousPageActivated (void); 
    52             void openDocument (const gchar *fileName, const gchar *oldPassword, 
    53                                gboolean canShowPage); 
     52            bool openDocument (const gchar *fileName, const gchar *oldPassword, 
     53                                GError **error); 
    5454            void openFileActivated (void); 
    5555            void outlineActivated (DocumentOutline *outline); 
     
    6161            void showStatusbarActivated (gboolean show); 
    6262            void showToolbarActivated (gboolean show); 
     63            void setContext (gint pageNum, gint rotation, gdouble zoom); 
    6364            void zoomFitActivated (gboolean active); 
    6465            void zoomInActivated (void); 
  • trunk/src/Makefile.am

    r92 r115  
    1515    IDocument.cxx       \ 
    1616    IDocument.h         \ 
     17    JobLoad.cxx         \ 
     18    JobLoad.h           \ 
    1719    MainPter.cxx        \ 
    1820    MainPter.h          \ 
  • trunk/src/epdfview.h

    r92 r115  
    3232#include <MainPter.h> 
    3333 
     34#include <JobLoad.h> 
     35 
    3436#endif //!__E_PDF_VIEW_H__ 
  • trunk/src/main.cxx

    r94 r115  
    2525#include "MainPter.h" 
    2626#include "Config.h" 
     27#include "JobLoad.h" 
    2728 
    2829 
    2930using namespace ePDFView; 
    30  
    31 /// 
    32 /// @brief The data passed to open_command_line_file() function. 
    33 /// 
    34 typedef struct 
    35 { 
    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); 
    4431 
    4532int 
     
    7158    if ( argc > 1 ) 
    7259    { 
    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 (); 
    8464    } 
    8565    // Create the main view. 
     
    10080    return EXIT_SUCCESS; 
    10181} 
    102  
    103 gboolean 
    104 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  
    9999    m_View->setOpenFileName ("/tmp/test.pdf"); 
    100100    m_MainPter->openFileActivated (); 
     101    // Sleep to let the thread open the file. 
     102    sleep (1); 
    101103    CPPUNIT_ASSERT_EQUAL (0,  
    102104            g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 
     
    119121    m_Document->setTitle (g_strdup ("Test PDF")); 
    120122    m_MainPter->openFileActivated (); 
     123    // Sleep to let the thread open the file. 
     124    sleep (1); 
    121125    CPPUNIT_ASSERT_EQUAL (0,  
    122126            g_ascii_strcasecmp ("Test PDF", m_View->getTitle ())); 
     
    148152    m_View->setOpenFileName (NULL); 
    149153    m_MainPter->openFileActivated (); 
     154    // Sleep to let the thread open the file. 
     155    sleep (1); 
    150156    CPPUNIT_ASSERT_EQUAL (0,  
    151157            g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); 
     
    179185    m_Document->setOpenError (DocumentErrorDamaged); 
    180186    m_MainPter->openFileActivated (); 
     187    // Sleep to let the thread open the file. 
     188    sleep (1); 
    181189    CPPUNIT_ASSERT_EQUAL (0,  
    182190            g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); 
     
    212220    m_Document->setOpenError (DocumentErrorEncrypted); 
    213221    m_MainPter->openFileActivated (); 
     222    // Sleep to let the thread open the file. 
     223    sleep (1); 
    214224    CPPUNIT_ASSERT_EQUAL (0,  
    215225            g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); 
     
    245255    m_Document->setOpenError (DocumentErrorEncrypted); 
    246256    m_MainPter->openFileActivated (); 
     257    // Sleep to let the thread open the file. 
     258    sleep (1); 
    247259    CPPUNIT_ASSERT_EQUAL (0,  
    248260            g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); 
     
    278290    m_Document->setOpenError (DocumentErrorEncrypted); 
    279291    m_MainPter->openFileActivated (); 
     292    // Sleep to let the thread open the file. 
     293    sleep (1); 
    280294    CPPUNIT_ASSERT_EQUAL (0,  
    281295            g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 
     
    309323    m_View->setOpenFileName ("/tmp/test.pdf"); 
    310324    m_MainPter->openFileActivated (); 
     325    // Sleep to let the thread open the file. 
     326    sleep (1); 
    311327    CPPUNIT_ASSERT (NULL == m_View->getLastOpenFileFolder ()); 
    312328 
     
    314330    m_View->setOpenFileName ("/usr/test.pdf"); 
    315331    m_MainPter->openFileActivated (); 
     332    // Sleep to let the thread open the file. 
     333    sleep (1); 
    316334    CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/tmp",  
    317335                                             m_View->getLastOpenFileFolder ())); 
    318336     
    319337    m_MainPter->openFileActivated (); 
     338    // Sleep to let the thread open the file. 
     339    sleep (1); 
    320340    CPPUNIT_ASSERT (0 == g_ascii_strcasecmp ("/usr",  
    321341                                             m_View->getLastOpenFileFolder ())); 
     
    334354    m_Document->setNumPages (4); 
    335355    m_MainPter->openFileActivated (); 
     356    // Sleep to let the thread open the file. 
     357    sleep (1); 
    336358    // Check that sets the correct number of pages and the current page. 
    337359    CPPUNIT_ASSERT_EQUAL (4, m_View->getTotalPages ()); 
     
    414436    m_Document->setNumPages (4); 
    415437    m_MainPter->openFileActivated (); 
     438    // Sleep to let the thread open the file. 
     439    sleep (1); 
    416440    // Check that sets the correct number of pages and the current page. 
    417441    CPPUNIT_ASSERT_EQUAL (4, m_View->getTotalPages ()); 
     
    493517    m_View->setOpenFileName ("/tmp/test.pdf"); 
    494518    m_MainPter->openFileActivated (); 
     519    // Sleep to let the thread open the file. 
     520    sleep (1); 
    495521    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    496522    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     
    521547    m_View->setOpenFileName ("/tmp/test.pdf"); 
    522548    m_MainPter->openFileActivated (); 
     549    // Sleep to let the thread open the file. 
     550    sleep (1); 
    523551    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    524552    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     
    560588    m_View->setOpenFileName ("/tmp/test.pdf"); 
    561589    m_MainPter->openFileActivated (); 
     590    // Sleep to let the thread open the file. 
     591    sleep (1); 
    562592    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    563593    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
     
    624654    m_View->setOpenFileName ("/tmp/test.pdf"); 
    625655    m_MainPter->openFileActivated (); 
     656    // Sleep to let the thread open the file. 
     657    sleep (1); 
    626658    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    627659    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
     
    687719    m_View->setOpenFileName ("/tmp/test.pdf"); 
    688720    m_MainPter->openFileActivated (); 
     721    // Sleep to let the thread open the file. 
     722    sleep (1); 
    689723    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    690724    CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); 
     
    730764    m_View->setOpenFileName ("/tmp/test.pdf"); 
    731765    m_MainPter->openFileActivated (); 
     766    // Sleep to let the thread open the file. 
     767    sleep (1); 
    732768    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    733769 
     
    742778    // Reload the document. 
    743779    m_MainPter->reloadActivated (); 
     780    // Sleep to let the thread open the file. 
     781    sleep (1); 
    744782    CPPUNIT_ASSERT_EQUAL (0,  
    745783            g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 
     
    764802    m_Document->setOpenError (DocumentErrorEncrypted); 
    765803    m_MainPter->openFileActivated (); 
     804    // Sleep to let the thread open the file. 
     805    sleep (1); 
    766806    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    767807    CPPUNIT_ASSERT_EQUAL (0,  
     
    781821    m_Document->setOpenError (DocumentErrorEncrypted); 
    782822    m_MainPter->reloadActivated (); 
     823    // Sleep to let the thread open the file. 
     824    sleep (1); 
    783825    CPPUNIT_ASSERT_EQUAL (0,  
    784826            g_ascii_strcasecmp ("/tmp/test.pdf", m_View->getTitle ())); 
     
    804846    m_Document->setOpenError (DocumentErrorEncrypted); 
    805847    m_MainPter->openFileActivated (); 
     848    // Sleep to let the thread open the file. 
     849    sleep (1); 
    806850    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    807851    CPPUNIT_ASSERT_EQUAL (0,  
     
    823867    m_Document->setOpenError (DocumentErrorEncrypted); 
    824868    m_MainPter->reloadActivated (); 
     869    // Sleep to let the thread open the file. 
     870    sleep (1); 
    825871    CPPUNIT_ASSERT_EQUAL (0, 
    826872            g_ascii_strcasecmp("newpassword", m_Document->getPassword ())); 
     
    860906    m_View->setOpenFileName ("/tmp/test.pdf"); 
    861907    m_MainPter->openFileActivated (); 
     908    // Sleep to let the thread open the file. 
     909    sleep (1); 
    862910    CPPUNIT_ASSERT (m_View->isShownSidebar ()); 
    863911    CPPUNIT_ASSERT (outline == m_View->getOutline ());