Changeset 200

Show
Ignore:
Timestamp:
06/05/06 08:41:08 (2 years ago)
Author:
jordi
Message:

Added the option to save a copy of the currently loaded document.

Location:
trunk
Files:
2 added
16 modified

Legend:

Unmodified
Added
Removed
  • trunk/data/epdfview-ui.xml

    r185 r200  
    44      <menuitem name="OpenFile" action="OpenFile"/> 
    55      <menuitem name="ReloadFile" action="ReloadFile"/> 
     6      <menuitem name="SaveFile" action="SaveFile"/> 
    67      <separator/> 
    78      <menuitem name="Quit" action="Quit"/> 
  • trunk/src/Config.cxx

    r192 r200  
    2323 
    2424// Constants 
    25 static gchar *DEFAULT_EXTERNAL_BROWSER_COMMAND_LINE = "firefox %s"; 
    26 static gchar *DEFAULT_OPEN_FILE_FOLDER = NULL; 
    27 static gboolean DEFAULT_SHOW_STATUSBAR = TRUE; 
    28 static gboolean DEFAULT_SHOW_TOOLBAR = TRUE; 
    29 static gint DEFAULT_WINDOW_HEIGHT = 650; 
    30 static gint DEFAULT_WINDOW_WIDTH = 600; 
    31 static gint DEFAULT_WINDOW_X = 0; 
    32 static gint DEFAULT_WINDOW_Y = 0; 
    33 static gboolean DEFAULT_ZOOM_TO_FIT = FALSE; 
    34 static gboolean DEFAULT_ZOOM_TO_WIDTH = FALSE; 
     25static const gchar *DEFAULT_EXTERNAL_BROWSER_COMMAND_LINE = "firefox %s"; 
     26static const gchar *DEFAULT_OPEN_FILE_FOLDER = NULL; 
     27static const gchar *DEFAULT_SAVE_FILE_FOLDER = NULL; 
     28static const gboolean DEFAULT_SHOW_STATUSBAR = TRUE; 
     29static const gboolean DEFAULT_SHOW_TOOLBAR = TRUE; 
     30static const gint DEFAULT_WINDOW_HEIGHT = 650; 
     31static const gint DEFAULT_WINDOW_WIDTH = 600; 
     32static const gint DEFAULT_WINDOW_X = 0; 
     33static const gint DEFAULT_WINDOW_Y = 0; 
     34static const gboolean DEFAULT_ZOOM_TO_FIT = FALSE; 
     35static const gboolean DEFAULT_ZOOM_TO_WIDTH = FALSE; 
    3536 
    3637// Static member attributes. 
     
    138139                       key, group, error->message); 
    139140            g_error_free (error); 
    140         }         
     141        } 
    141142    } 
    142143 
     
    207208{ 
    208209    return getString ("open dialog", "folder", DEFAULT_OPEN_FILE_FOLDER); 
     210} 
     211 
     212/// 
     213/// @brief Gets the last folder used to save a file. 
     214/// 
     215/// @return The path to the last folder that was used to save a file. 
     216///         This string must be freed using g_free(). NULL if no folder 
     217///         has been used yet, which means to use the current working directory. 
     218/// 
     219gchar * 
     220Config::getSaveFileFolder () 
     221{ 
     222    return getString ("save dialog", "folder", DEFAULT_SAVE_FILE_FOLDER); 
    209223} 
    210224 
     
    346360 
    347361/// 
     362/// @brief Saves the last folder used to osave a file. 
     363/// 
     364/// @param folder The path to the last folder used. 
     365/// 
     366void 
     367Config::setSaveFileFolder (const gchar *folder) 
     368{ 
     369    g_key_file_set_string (m_Values, "save dialog", "folder", folder); 
     370} 
     371 
     372/// 
    348373/// @brief Save if show the status bar. 
    349374/// 
  • trunk/src/Config.h

    r192 r200  
    3232    class Config 
    3333    { 
    34         public:           
     34        public: 
    3535            static void destroy (void); 
    3636            static Config &getConfig (void); 
    3737            static void loadFile (gboolean load); 
    38              
     38 
    3939            ~Config (void); 
    4040 
    4141            gchar *getExternalBrowserCommandLine (void); 
    4242            gchar *getOpenFileFolder (void); 
     43            gchar *getSaveFileFolder (void); 
    4344            gint getWindowHeight (void); 
    4445            gint getWindowWidth (void); 
     
    4647            gint getWindowY (void); 
    4748            gboolean showStatusbar (void); 
    48             gboolean showToolbar (void);             
     49            gboolean showToolbar (void); 
    4950            gboolean zoomToFit (void); 
    5051            gboolean zoomToWidth (void); 
     
    5253            void setExternalBrowserCommandLine (const gchar *commandLine); 
    5354            void setOpenFileFolder (const gchar *folder); 
     55            void setSaveFileFolder (const gchar *folder); 
    5456            void setShowStatusbar (gboolean show); 
    5557            void setShowToolbar (gboolean show); 
     
    5860            void setZoomToFit (gboolean active); 
    5961            void setZoomToWidth (gboolean active); 
    60              
     62 
    6163        protected: 
    6264            /// The configuration values. 
  • trunk/src/IDocument.cxx

    r196 r200  
    113113            break; 
    114114        default: 
    115             errorMessage = g_strdup_printf (_("Unknown error (%d)."), errorCode);             
     115            errorMessage = g_strdup_printf (_("Unknown error (%d)."), errorCode); 
    116116    } 
    117117 
     
    186186{ 
    187187    g_assert (NULL != observer && "Tried to attach a NULL observer."); 
    188      
     188 
    189189    m_Observers = g_list_prepend (m_Observers, (gpointer)observer); 
    190190} 
     
    225225    } 
    226226    m_FindPage = pageNum; 
    227                  
     227 
    228228    for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 
    229229          item = g_list_next (item) ) 
     
    437437 
    438438/// 
     439/// @brief The document has been saved. 
     440/// 
     441/// This is called when the JobSave class is done. It in turn notifies 
     442/// all attached observers about this situation. 
     443/// 
     444void 
     445IDocument::notifySave () 
     446{ 
     447    for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 
     448          item = g_list_next (item) ) 
     449    { 
     450        IDocumentObserver *observer = (IDocumentObserver *)item->data; 
     451        observer->notifySave (); 
     452    } 
     453} 
     454 
     455/// 
     456/// @brief The document couldn't be saved. 
     457/// 
     458/// This is called by the JobSave class when the document couldn't 
     459/// be saved. It in turns notifies all attached observers. 
     460/// 
     461/// @param error The error message of why couldn't save the document. 
     462/// 
     463void 
     464IDocument::notifySaveError (const GError *error) 
     465{ 
     466    for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 
     467          item = g_list_next (item) ) 
     468    { 
     469        IDocumentObserver *observer = (IDocumentObserver *)item->data; 
     470        observer->notifySaveError (error); 
     471    } 
     472} 
     473 
     474/// 
    439475/// @brief Loads a file. 
    440476/// 
     
    451487    m_Rotation = 0; 
    452488    m_Scale = 1.0f; 
    453      
     489 
    454490    JobLoad *job = new JobLoad (); 
    455491    job->setDocument (this); 
     
    472508    job->setPassword (getPassword ()); 
    473509    job->setReload (TRUE); 
     510    IJob::enqueue (job); 
     511} 
     512 
     513/// 
     514/// @brief Saves a copy of the document. 
     515/// 
     516/// Saves the current document in a new file. 
     517/// 
     518/// @param fileName The file name to save the document's copy to. 
     519/// 
     520void 
     521IDocument::save (const gchar *fileName) 
     522{ 
     523    JobSave *job = new JobSave (); 
     524    job->setDocument (this); 
     525    job->setFileName (fileName); 
    474526    IJob::enqueue (job); 
    475527} 
  • trunk/src/IDocument.h

    r172 r200  
    6060        DocumentErrorFileIO = 10 
    6161    } DocumentError; 
    62          
     62 
    6363    /// 
    6464    /// @brief Defines the document's page mode when opened. 
     
    148148            virtual GList *findTextInPage (gint pageNum,  
    149149                                           const gchar *textToFind) = 0; 
    150              
     150 
    151151            /// 
    152152            /// @brief Checks if the document has been loaded. 
     
    164164            /// The rotation degree is reset to 0 and the scale level to 1.0f 
    165165            /// 
    166             /// @param filename The path, absolute or relative, to the flame  
     166            /// @param filename The path, absolute or relative, to the file name 
    167167            ///                 to open. 
    168168            /// @param password The password to use to decrypt @a filename. If 
     
    173173            /// 
    174174            /// @return TRUE if the file could be opened. FALSE otherwise. 
    175             ///  
    176             virtual gboolean loadFile (const gchar *filename,  
    177                                        const gchar *password,  
     175            /// 
     176            virtual gboolean loadFile (const gchar *filename, 
     177                                       const gchar *password, 
    178178                                       GError **error) = 0; 
    179              
     179 
    180180            /// 
    181181            /// @brief Gets a document's page's unscaled size. 
     
    188188            /// @param height The location to save the page's height. 
    189189            /// 
    190             virtual void getPageSizeForPage (gint pageNum, gdouble *width,  
     190            virtual void getPageSizeForPage (gint pageNum, gdouble *width, 
    191191                                             gdouble *height) = 0; 
    192192 
     
    203203            /// 
    204204            virtual DocumentPage *renderPage (gint pageNum) = 0; 
     205 
     206            /// 
     207            /// @brief Saves a document's copy to a file. 
     208            /// 
     209            /// Tries to save the document to file @a filename. 
     210            /// 
     211            /// @param filename The path, absolute or relative, to the file name 
     212            ///                 to save the copy to. 
     213            /// @param error Location to store any error that could happen or 
     214            ///              set to NULL to ignore errors. 
     215            /// 
     216            /// @return TRUE if the file could be saved. FALSE otherwise. 
     217            /// 
     218            virtual gboolean saveFile (const gchar *filename, 
     219                                       GError **error) = 0; 
    205220 
    206221            void attach (const IDocumentObserver *observer); 
     
    220235            void notifyPageZoomed (void); 
    221236            void notifyReload (void); 
    222              
     237            void notifySave (void); 
     238            void notifySaveError (const GError *error); 
     239 
    223240            const gchar *getTitle (void); 
    224241            void setTitle (gchar *title); 
     
    261278            void load (const gchar *fileName, const gchar *password); 
    262279            void reload (void); 
     280            void save (const gchar *fileName); 
    263281 
    264282            void goToFirstPage (void); 
  • trunk/src/IDocumentObserver.h

    r156 r200  
    5050            /// 
    5151            virtual void notifyFindFinished (void) { } 
    52        
     52 
    5353            /// 
    5454            /// @brief A find has been started. 
     
    5858            /// 
    5959            virtual void notifyFindStarted (void) { } 
    60              
     60 
    6161            /// 
    6262            /// @brief The document has been loaded. 
     
    6666            /// 
    6767            virtual void notifyLoad (void) { } 
    68              
     68 
    6969            /// 
    7070            /// @brief The document couldn't be loaded due an error. 
     
    132132            virtual void notifyReload (void) { } 
    133133 
     134            /// 
     135            /// @brief The document has been saved. 
     136            /// 
     137            /// This function is called when a document's copy has been 
     138            /// saved successfully. 
     139            /// 
     140            virtual void notifySave (void) { } 
     141 
     142            /// 
     143            /// @brief The document couldn't be saved due an error. 
     144            /// 
     145            /// This function is called when a document's copy couldn't be 
     146            /// saved because of an error. The error message is 
     147            /// passed as a parameter. 
     148            /// 
     149            /// @param error The error code and message. 
     150            /// 
     151            virtual void notifySaveError (const GError *error) { } 
     152 
    134153        protected: 
    135154            /// 
  • trunk/src/IMainView.h

    r199 r200  
    108108 
    109109            /// 
     110            /// @brief Shows the save file dialog. 
     111            /// 
     112            /// The view must ask the user which file name to use to 
     113            /// save using the toolkit's specific save dialog. 
     114            /// 
     115            /// @param lastFolder The last folder used to save a file. This is 
     116            ///                   used to show this folder when the save dialog 
     117            ///                   appears. 
     118            /// 
     119            /// @return A copy of the file name that the user will try to use 
     120            ///         to save or NULL if the user cancelled the operation. 
     121            ///         This string will be freed by the presenter. 
     122            /// 
     123            virtual gchar *saveFileDialog (const gchar *lastFolder) = 0; 
     124 
     125            /// 
    110126            /// @brief Changes the sensitivity of the "Find" action. 
    111127            /// 
     
    236252            /// 
    237253            virtual void sensitiveRotateRight (gboolean sensitive) = 0; 
     254 
     255            /// 
     256            /// @brief Changes the sensitivity of the "Save a Copy" action. 
     257            /// 
     258            /// The view must change the sensitivity (it's called enabled or 
     259            /// disabled on some toolkits) of the "Save a Copy" action 
     260            /// (both on the menu and the toolbar or any other place). 
     261            /// 
     262            /// @param sensitive Set to TRUE if need to make sensitive (enable) 
     263            ///                  the action or FALSE to insensitive (disable) 
     264            ///                  it. 
     265            /// 
     266            virtual void sensitiveSave (gboolean sensitive) = 0; 
    238267 
    239268            /// 
  • trunk/src/JobLoad.cxx

    r148 r200  
    224224    job->getDocument ().notifyLoad (); 
    225225    JOB_NOTIFIER_END(); 
    226      
     226 
    227227    return FALSE; 
    228228} 
     
    244244    job->getDocument ().notifyLoadError (job->getError ()); 
    245245    JOB_NOTIFIER_END(); 
    246      
     246 
    247247    return FALSE; 
    248248} 
  • trunk/src/MainPter.cxx

    r199 r200  
    123123        view.sensitiveRotateRight (TRUE); 
    124124        view.sensitiveRotateLeft (TRUE); 
     125        view.sensitiveSave (TRUE); 
    125126        view.sensitiveZoomIn (TRUE); 
    126127        view.sensitiveZoomOut (TRUE); 
     
    150151        view.sensitiveRotateRight (FALSE); 
    151152        view.sensitiveRotateLeft (FALSE); 
     153        view.sensitiveSave (FALSE); 
    152154        view.sensitiveZoomIn (FALSE); 
    153155        view.sensitiveZoomOut (FALSE); 
     
    199201    view.sensitiveRotateRight (FALSE); 
    200202    view.sensitiveRotateLeft (FALSE); 
     203    view.sensitiveSave (FALSE); 
    201204    view.sensitiveZoomIn (FALSE); 
    202205    view.sensitiveZoomOut (FALSE); 
     
    292295    g_assert (NULL != m_Document &&  
    293296              "Tried to go to the last page of a NULL document."); 
    294      
     297 
    295298    m_PagePter->setNextPageScroll (PAGE_SCROLL_START); 
    296299    m_Document->goToLastPage (); 
     
    380383    IMainView &view = getView (); 
    381384    gchar *fileName = view.openFileDialog (lastFolder); 
    382     g_free (lastFolder);     
     385    g_free (lastFolder); 
    383386    if ( NULL != fileName ) 
    384387    { 
     
    389392        setOpenState (fileName, FALSE); 
    390393        m_Document->load (fileName, NULL); 
     394        g_free (fileName); 
    391395    } 
    392396} 
     
    465469    checkZoomSettings (); 
    466470} 
     471 
     472/// 
     473/// @brief The Save File action was activated. 
     474/// 
     475/// This means that the user wants to save a copy of the document. 
     476/// The presenter asks the view to show the Save File dialog and return a  
     477/// file name. 
     478/// Then it will try to save the document and if there's any error it will  
     479/// request the view to show an error dialog. 
     480/// 
     481void 
     482MainPter::saveFileActivated () 
     483{ 
     484    Config &config = Config::getConfig (); 
     485    gchar *lastFolder = config.getSaveFileFolder (); 
     486    IMainView &view = getView (); 
     487    gchar *fileName = view.saveFileDialog (lastFolder); 
     488    g_free (lastFolder); 
     489    if ( NULL != fileName ) 
     490    { 
     491 
     492        // Show on the status bar that we are saving the copy. 
     493        gchar *statusText = g_strdup_printf (_("Saving document to %s..."), 
     494                                             fileName); 
     495        view.setStatusBarText (statusText); 
     496        g_free (statusText); 
     497        gchar *dirName = g_path_get_dirname (fileName); 
     498        config.setSaveFileFolder (dirName); 
     499        g_free (dirName); 
     500        // Save the document. 
     501        m_Document->save (fileName); 
     502        g_free (fileName); 
     503    } 
     504} 
     505 
    467506 
    468507/// 
     
    720759    view.setGoToPageText (goToPageText); 
    721760    g_free (goToPageText); 
    722      
     761 
    723762    // Set the page navigation sensitivity. 
    724763    gboolean documentLoaded = m_Document->isLoaded (); 
     
    761800} 
    762801 
     802void 
     803MainPter::notifySave () 
     804{ 
     805    // Remove the status text. 
     806    getView ().setStatusBarText (NULL); 
     807} 
     808 
     809void 
     810MainPter::notifySaveError (const GError *error) 
     811{ 
     812    getView ().showErrorMessage (_("Error Saving File"), error->message); 
     813} 
     814 
    763815#if defined (DEBUG) 
    764816/// 
  • trunk/src/MainPter.h

    r199 r200  
    4545            IMainView &getView (void); 
    4646            void setView (IMainView *view); 
    47             
     47 
    4848            void findActivated (void); 
    4949            void goToFirstPageActivated (void); 
     
    6060            void rotateLeftActivated (void); 
    6161            void rotateRightActivated (void); 
     62            void saveFileActivated (void); 
    6263            void showIndexActivated (gboolean show); 
    6364            void showStatusbarActivated (gboolean show); 
     
    7677            void notifyPageZoomed (gdouble zoom); 
    7778            void notifyReload (void); 
    78              
     79            void notifySave (void); 
     80            void notifySaveError (const GError *error); 
     81 
    7982#if defined (DEBUG) 
    8083            void waitForFileLoaded (void); 
  • trunk/src/Makefile.am

    r198 r200  
    1313    DocumentOutline.cxx \ 
    1414    DocumentOutline.h   \ 
    15     DocumentPage.h      \ 
     15    DocumentPage.h  \ 
    1616    DocumentPage.cxx    \ 
    1717    DocumentRectangle.cxx   \ 
     
    2222    gettext.h   \ 
    2323    IDocument.cxx   \ 
    24     IDocument.h     \ 
     24    IDocument.h \ 
    2525    IDocumentLink.cxx   \ 
    2626    IDocumentLink.h \ 
     
    3434    JobFind.cxx \ 
    3535    JobFind.h   \ 
    36     JobLoad.cxx     \ 
    37     JobLoad.h       \ 
     36    JobLoad.cxx \ 
     37    JobLoad.h   \ 
    3838    JobRender.cxx   \ 
    3939    JobRender.h \ 
     40    JobSave.cxx \ 
     41    JobSave.h   \ 
    4042    MainPter.cxx    \ 
    41     MainPter.h      \ 
     43    MainPter.h  \ 
    4244    PagePter.cxx    \ 
    4345    PagePter.h  \ 
  • trunk/src/PDFDocument.cxx

    r196 r200  
    181181    // Try to open the PDF document. 
    182182    GError *loadError = NULL; 
    183     PopplerDocument *newDocument =  
     183    PopplerDocument *newDocument = 
    184184        poppler_document_new_from_file (filename_uri, password, &loadError); 
    185185    g_free (filename_uri); 
     
    262262    gchar *subject = NULL; 
    263263    gchar *title = NULL; 
    264     
     264 
    265265    g_object_get (m_Document, 
    266266            "author", &author, 
     
    461461        return NULL; 
    462462    } 
    463      
     463 
    464464    // First create the document's page. 
    465465    gdouble pageWidth; 
     
    488488    } 
    489489    g_object_unref (pixbuf); 
    490      
     490