Changeset 200
- Timestamp:
- 06/05/06 08:41:08 (2 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 16 modified
-
data/epdfview-ui.xml (modified) (1 diff)
-
src/Config.cxx (modified) (4 diffs)
-
src/Config.h (modified) (4 diffs)
-
src/IDocument.cxx (modified) (6 diffs)
-
src/IDocument.h (modified) (8 diffs)
-
src/IDocumentObserver.h (modified) (4 diffs)
-
src/IMainView.h (modified) (2 diffs)
-
src/JobLoad.cxx (modified) (2 diffs)
-
src/JobSave.cxx (added)
-
src/JobSave.h (added)
-
src/MainPter.cxx (modified) (9 diffs)
-
src/MainPter.h (modified) (3 diffs)
-
src/Makefile.am (modified) (3 diffs)
-
src/PDFDocument.cxx (modified) (4 diffs)
-
src/PDFDocument.h (modified) (1 diff)
-
src/epdfview.h (modified) (1 diff)
-
src/gtk/MainView.cxx (modified) (16 diffs)
-
src/gtk/MainView.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/epdfview-ui.xml
r185 r200 4 4 <menuitem name="OpenFile" action="OpenFile"/> 5 5 <menuitem name="ReloadFile" action="ReloadFile"/> 6 <menuitem name="SaveFile" action="SaveFile"/> 6 7 <separator/> 7 8 <menuitem name="Quit" action="Quit"/> -
trunk/src/Config.cxx
r192 r200 23 23 24 24 // 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; 25 static const gchar *DEFAULT_EXTERNAL_BROWSER_COMMAND_LINE = "firefox %s"; 26 static const gchar *DEFAULT_OPEN_FILE_FOLDER = NULL; 27 static const gchar *DEFAULT_SAVE_FILE_FOLDER = NULL; 28 static const gboolean DEFAULT_SHOW_STATUSBAR = TRUE; 29 static const gboolean DEFAULT_SHOW_TOOLBAR = TRUE; 30 static const gint DEFAULT_WINDOW_HEIGHT = 650; 31 static const gint DEFAULT_WINDOW_WIDTH = 600; 32 static const gint DEFAULT_WINDOW_X = 0; 33 static const gint DEFAULT_WINDOW_Y = 0; 34 static const gboolean DEFAULT_ZOOM_TO_FIT = FALSE; 35 static const gboolean DEFAULT_ZOOM_TO_WIDTH = FALSE; 35 36 36 37 // Static member attributes. … … 138 139 key, group, error->message); 139 140 g_error_free (error); 140 } 141 } 141 142 } 142 143 … … 207 208 { 208 209 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 /// 219 gchar * 220 Config::getSaveFileFolder () 221 { 222 return getString ("save dialog", "folder", DEFAULT_SAVE_FILE_FOLDER); 209 223 } 210 224 … … 346 360 347 361 /// 362 /// @brief Saves the last folder used to osave a file. 363 /// 364 /// @param folder The path to the last folder used. 365 /// 366 void 367 Config::setSaveFileFolder (const gchar *folder) 368 { 369 g_key_file_set_string (m_Values, "save dialog", "folder", folder); 370 } 371 372 /// 348 373 /// @brief Save if show the status bar. 349 374 /// -
trunk/src/Config.h
r192 r200 32 32 class Config 33 33 { 34 public: 34 public: 35 35 static void destroy (void); 36 36 static Config &getConfig (void); 37 37 static void loadFile (gboolean load); 38 38 39 39 ~Config (void); 40 40 41 41 gchar *getExternalBrowserCommandLine (void); 42 42 gchar *getOpenFileFolder (void); 43 gchar *getSaveFileFolder (void); 43 44 gint getWindowHeight (void); 44 45 gint getWindowWidth (void); … … 46 47 gint getWindowY (void); 47 48 gboolean showStatusbar (void); 48 gboolean showToolbar (void); 49 gboolean showToolbar (void); 49 50 gboolean zoomToFit (void); 50 51 gboolean zoomToWidth (void); … … 52 53 void setExternalBrowserCommandLine (const gchar *commandLine); 53 54 void setOpenFileFolder (const gchar *folder); 55 void setSaveFileFolder (const gchar *folder); 54 56 void setShowStatusbar (gboolean show); 55 57 void setShowToolbar (gboolean show); … … 58 60 void setZoomToFit (gboolean active); 59 61 void setZoomToWidth (gboolean active); 60 62 61 63 protected: 62 64 /// The configuration values. -
trunk/src/IDocument.cxx
r196 r200 113 113 break; 114 114 default: 115 errorMessage = g_strdup_printf (_("Unknown error (%d)."), errorCode); 115 errorMessage = g_strdup_printf (_("Unknown error (%d)."), errorCode); 116 116 } 117 117 … … 186 186 { 187 187 g_assert (NULL != observer && "Tried to attach a NULL observer."); 188 188 189 189 m_Observers = g_list_prepend (m_Observers, (gpointer)observer); 190 190 } … … 225 225 } 226 226 m_FindPage = pageNum; 227 227 228 228 for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 229 229 item = g_list_next (item) ) … … 437 437 438 438 /// 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 /// 444 void 445 IDocument::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 /// 463 void 464 IDocument::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 /// 439 475 /// @brief Loads a file. 440 476 /// … … 451 487 m_Rotation = 0; 452 488 m_Scale = 1.0f; 453 489 454 490 JobLoad *job = new JobLoad (); 455 491 job->setDocument (this); … … 472 508 job->setPassword (getPassword ()); 473 509 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 /// 520 void 521 IDocument::save (const gchar *fileName) 522 { 523 JobSave *job = new JobSave (); 524 job->setDocument (this); 525 job->setFileName (fileName); 474 526 IJob::enqueue (job); 475 527 } -
trunk/src/IDocument.h
r172 r200 60 60 DocumentErrorFileIO = 10 61 61 } DocumentError; 62 62 63 63 /// 64 64 /// @brief Defines the document's page mode when opened. … … 148 148 virtual GList *findTextInPage (gint pageNum, 149 149 const gchar *textToFind) = 0; 150 150 151 151 /// 152 152 /// @brief Checks if the document has been loaded. … … 164 164 /// The rotation degree is reset to 0 and the scale level to 1.0f 165 165 /// 166 /// @param filename The path, absolute or relative, to the f lame166 /// @param filename The path, absolute or relative, to the file name 167 167 /// to open. 168 168 /// @param password The password to use to decrypt @a filename. If … … 173 173 /// 174 174 /// @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, 178 178 GError **error) = 0; 179 179 180 180 /// 181 181 /// @brief Gets a document's page's unscaled size. … … 188 188 /// @param height The location to save the page's height. 189 189 /// 190 virtual void getPageSizeForPage (gint pageNum, gdouble *width, 190 virtual void getPageSizeForPage (gint pageNum, gdouble *width, 191 191 gdouble *height) = 0; 192 192 … … 203 203 /// 204 204 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; 205 220 206 221 void attach (const IDocumentObserver *observer); … … 220 235 void notifyPageZoomed (void); 221 236 void notifyReload (void); 222 237 void notifySave (void); 238 void notifySaveError (const GError *error); 239 223 240 const gchar *getTitle (void); 224 241 void setTitle (gchar *title); … … 261 278 void load (const gchar *fileName, const gchar *password); 262 279 void reload (void); 280 void save (const gchar *fileName); 263 281 264 282 void goToFirstPage (void); -
trunk/src/IDocumentObserver.h
r156 r200 50 50 /// 51 51 virtual void notifyFindFinished (void) { } 52 52 53 53 /// 54 54 /// @brief A find has been started. … … 58 58 /// 59 59 virtual void notifyFindStarted (void) { } 60 60 61 61 /// 62 62 /// @brief The document has been loaded. … … 66 66 /// 67 67 virtual void notifyLoad (void) { } 68 68 69 69 /// 70 70 /// @brief The document couldn't be loaded due an error. … … 132 132 virtual void notifyReload (void) { } 133 133 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 134 153 protected: 135 154 /// -
trunk/src/IMainView.h
r199 r200 108 108 109 109 /// 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 /// 110 126 /// @brief Changes the sensitivity of the "Find" action. 111 127 /// … … 236 252 /// 237 253 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; 238 267 239 268 /// -
trunk/src/JobLoad.cxx
r148 r200 224 224 job->getDocument ().notifyLoad (); 225 225 JOB_NOTIFIER_END(); 226 226 227 227 return FALSE; 228 228 } … … 244 244 job->getDocument ().notifyLoadError (job->getError ()); 245 245 JOB_NOTIFIER_END(); 246 246 247 247 return FALSE; 248 248 } -
trunk/src/MainPter.cxx
r199 r200 123 123 view.sensitiveRotateRight (TRUE); 124 124 view.sensitiveRotateLeft (TRUE); 125 view.sensitiveSave (TRUE); 125 126 view.sensitiveZoomIn (TRUE); 126 127 view.sensitiveZoomOut (TRUE); … … 150 151 view.sensitiveRotateRight (FALSE); 151 152 view.sensitiveRotateLeft (FALSE); 153 view.sensitiveSave (FALSE); 152 154 view.sensitiveZoomIn (FALSE); 153 155 view.sensitiveZoomOut (FALSE); … … 199 201 view.sensitiveRotateRight (FALSE); 200 202 view.sensitiveRotateLeft (FALSE); 203 view.sensitiveSave (FALSE); 201 204 view.sensitiveZoomIn (FALSE); 202 205 view.sensitiveZoomOut (FALSE); … … 292 295 g_assert (NULL != m_Document && 293 296 "Tried to go to the last page of a NULL document."); 294 297 295 298 m_PagePter->setNextPageScroll (PAGE_SCROLL_START); 296 299 m_Document->goToLastPage (); … … 380 383 IMainView &view = getView (); 381 384 gchar *fileName = view.openFileDialog (lastFolder); 382 g_free (lastFolder); 385 g_free (lastFolder); 383 386 if ( NULL != fileName ) 384 387 { … … 389 392 setOpenState (fileName, FALSE); 390 393 m_Document->load (fileName, NULL); 394 g_free (fileName); 391 395 } 392 396 } … … 465 469 checkZoomSettings (); 466 470 } 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 /// 481 void 482 MainPter::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 467 506 468 507 /// … … 720 759 view.setGoToPageText (goToPageText); 721 760 g_free (goToPageText); 722 761 723 762 // Set the page navigation sensitivity. 724 763 gboolean documentLoaded = m_Document->isLoaded (); … … 761 800 } 762 801 802 void 803 MainPter::notifySave () 804 { 805 // Remove the status text. 806 getView ().setStatusBarText (NULL); 807 } 808 809 void 810 MainPter::notifySaveError (const GError *error) 811 { 812 getView ().showErrorMessage (_("Error Saving File"), error->message); 813 } 814 763 815 #if defined (DEBUG) 764 816 /// -
trunk/src/MainPter.h
r199 r200 45 45 IMainView &getView (void); 46 46 void setView (IMainView *view); 47 47 48 48 void findActivated (void); 49 49 void goToFirstPageActivated (void); … … 60 60 void rotateLeftActivated (void); 61 61 void rotateRightActivated (void); 62 void saveFileActivated (void); 62 63 void showIndexActivated (gboolean show); 63 64 void showStatusbarActivated (gboolean show); … … 76 77 void notifyPageZoomed (gdouble zoom); 77 78 void notifyReload (void); 78 79 void notifySave (void); 80 void notifySaveError (const GError *error); 81 79 82 #if defined (DEBUG) 80 83 void waitForFileLoaded (void); -
trunk/src/Makefile.am
r198 r200 13 13 DocumentOutline.cxx \ 14 14 DocumentOutline.h \ 15 DocumentPage.h \15 DocumentPage.h \ 16 16 DocumentPage.cxx \ 17 17 DocumentRectangle.cxx \ … … 22 22 gettext.h \ 23 23 IDocument.cxx \ 24 IDocument.h \24 IDocument.h \ 25 25 IDocumentLink.cxx \ 26 26 IDocumentLink.h \ … … 34 34 JobFind.cxx \ 35 35 JobFind.h \ 36 JobLoad.cxx \37 JobLoad.h \36 JobLoad.cxx \ 37 JobLoad.h \ 38 38 JobRender.cxx \ 39 39 JobRender.h \ 40 JobSave.cxx \ 41 JobSave.h \ 40 42 MainPter.cxx \ 41 MainPter.h \43 MainPter.h \ 42 44 PagePter.cxx \ 43 45 PagePter.h \ -
trunk/src/PDFDocument.cxx
r196 r200 181 181 // Try to open the PDF document. 182 182 GError *loadError = NULL; 183 PopplerDocument *newDocument = 183 PopplerDocument *newDocument = 184 184 poppler_document_new_from_file (filename_uri, password, &loadError); 185 185 g_free (filename_uri); … … 262 262 gchar *subject = NULL; 263 263 gchar *title = NULL; 264 264 265 265 g_object_get (m_Document, 266 266 "author", &author, … … 461 461 return NULL; 462 462 } 463 463 464 464 // First create the document's page. 465 465 gdouble pageWidth; … … 488 488 } 489 489 g_object_unref (pixbuf); 490 490
