Changeset 117
- Timestamp:
- 04/25/06 09:27:46 (2 years ago)
- Location:
- trunk
- Files:
-
- 9 modified
-
src/IMainView.h (modified) (4 diffs)
-
src/JobLoad.cxx (modified) (26 diffs)
-
src/JobLoad.h (modified) (1 diff)
-
src/MainPter.cxx (modified) (8 diffs)
-
src/gtk/MainView.cxx (modified) (4 diffs)
-
src/gtk/MainView.h (modified) (2 diffs)
-
src/main.cxx (modified) (2 diffs)
-
tests/DumbMainView.cxx (modified) (3 diffs)
-
tests/DumbMainView.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/IMainView.h
r107 r117 27 27 class DocumentOutline; 28 28 29 /// 30 /// @brief How to show the new page. 31 /// 29 32 enum PageScroll 30 33 { … … 38 41 39 42 /// 43 /// @brief Main view's cursor. 44 /// 45 enum ViewCursor 46 { 47 /// Normal cursor. 48 MAIN_VIEW_CURSOR_NORMAL, 49 /// Hour glass wait cursor. 50 MAIN_VIEW_CURSOR_WAIT, 51 /// Drag cursor. 52 MAIN_VIEW_CURSOR_DRAG 53 }; 54 55 /// 40 56 /// @class IMainView 41 57 /// @brief Interface class for the main view. … … 168 184 /// 169 185 virtual void sensitiveGoToPreviousPage (gboolean sensitive) = 0; 186 187 /// 188 /// @brief Changes the sensitivity of the "Open" action. 189 /// 190 /// The view must change the sensitivity (it's called enabled or 191 /// disabled on some toolkits) of the "Open" action 192 /// (both on the menu and the toolbar or any other place). 193 /// 194 /// @param sensitive Set to TRUE if need to make sensitive (enable) 195 /// the action (enable) or FALSE to 196 /// insensitive (disable) it. 197 /// 198 virtual void sensitiveOpen (gboolean sensitive) = 0; 170 199 171 200 /// … … 259 288 /// 260 289 virtual void sensitiveZoomWidth (gboolean sensitive) = 0; 290 291 /// 292 /// @brief Sets the page view's cursor. 293 /// 294 /// The main view must show the cursor as given by @a cursorType 295 /// for the page's view. 296 /// 297 /// @param cursorType The type of cursor to show. 298 /// 299 virtual void setCursor (ViewCursor cursorType) = 0; 300 301 /// 302 /// @brief Sets the text of the status bar. 303 /// 304 /// The view must show the text at @a text unless it's NULL, 305 /// which means show nothing. 306 /// 307 /// @param text The text to shown on the status bar or NULL if 308 /// no text should be shown on the status bar. 309 /// 310 virtual void setStatusBarText (const gchar *text) = 0; 261 311 262 312 /// -
trunk/src/JobLoad.cxx
r115 r117 22 22 23 23 // Forward declarations. 24 gboolean job_load_done (gpointer data); 25 gboolean job_load_error (gpointer data); 26 gboolean job_load_password (gpointer data); 27 gpointer job_load_run (gpointer data); 28 24 static gboolean job_load_done (gpointer data); 25 static gboolean job_load_error (gpointer data); 26 static gboolean job_load_password (gpointer data); 27 static gpointer job_load_run (gpointer data); 28 29 /// 30 /// @brief Constructs a new JobLoad object. 31 /// 29 32 JobLoad::JobLoad () 30 33 { … … 40 43 } 41 44 45 /// 46 /// @brief Deletes all dynamically allocated memory by JobLoad. 47 /// 42 48 JobLoad::~JobLoad () 43 49 { … … 50 56 } 51 57 58 /// 59 /// @brief Checks if a new password can be tried. 60 /// 61 /// This function checks if we passed the number of time we can try a 62 /// password. 63 /// 64 /// Be warned that this function alters the number of tries left. 65 /// 66 /// @return TRUE if we can try another password, FALSE otherwise. 67 /// 52 68 gboolean 53 69 JobLoad::canTryPassword () … … 62 78 } 63 79 80 /// 81 /// @brief Gets the file name to load or reload. 82 /// 83 /// @return The file name to load or reload. 84 /// 64 85 const gchar * 65 86 JobLoad::getFileName () … … 68 89 } 69 90 91 /// 92 /// @brief Gets the last error. 93 /// 94 /// @return The last load error. 95 /// 70 96 GError * 71 97 JobLoad::getError () … … 74 100 } 75 101 102 /// 103 /// @brief Gets the previously used page num. 104 /// 105 /// This is for reloading, gives the page where we were before reloading 106 /// the document. 107 /// 108 /// @return The numbe of the page where we were. 109 /// 76 110 gint 77 111 JobLoad::getPageNum () … … 80 114 } 81 115 116 /// 117 /// @brief Gets the password. 118 /// 119 /// @return The password to use to open the document. 120 /// 82 121 const gchar * 83 122 JobLoad::getPassword () … … 86 125 } 87 126 127 /// 128 /// @brief The presenter that's opening the file. 129 /// 130 /// @return The presenter that is loading or reloading the document. 131 /// 88 132 MainPter & 89 133 JobLoad::getPresenter () … … 94 138 } 95 139 140 /// 141 /// @brief Gets the previously used rotation. 142 /// 143 /// This is for reloading. Gets the rotation of the document before reloading. 144 /// 145 /// @return The degrees the document was rotated before. 146 /// 96 147 gint 97 148 JobLoad::getRotation () … … 100 151 } 101 152 153 /// 154 /// @brief Gets the previously used zoom. 155 /// 156 /// This is for reloading. Gets the zoom of the document before reloading. 157 /// 158 /// @return The degrees the document was zoomed before. 159 /// 102 160 gdouble 103 161 JobLoad::getZoom () … … 106 164 } 107 165 166 /// 167 /// @brief Checks if we are reloading. 168 /// 169 /// @return TRUE if we are reloading, FALSE otherwise. 170 /// 108 171 gboolean 109 172 JobLoad::isReload () … … 112 175 } 113 176 177 /// 178 /// @brief Open the document. 179 /// 180 /// This function will insensitive the Open and Reload actions, set 181 /// the view's status bar text, sets the wait cursor, and creates a new thread 182 /// that opens the document. 183 /// 114 184 void 115 185 JobLoad::run () … … 119 189 g_thread_init (NULL); 120 190 } 191 192 // Unsensitive the open and reload actions. 193 IMainView &view = getPresenter ().getView (); 194 view.sensitiveOpen (FALSE); 195 view.sensitiveReload (FALSE); 196 // Show the statusbar text. 197 gchar *statusText = NULL; 198 if ( isReload () ) 199 { 200 statusText = g_strdup_printf (_("Reloading file %s..."), 201 getFileName ()); 202 } 203 else 204 { 205 statusText = g_strdup_printf (_("Loading file %s..."), getFileName ()); 206 } 207 view.setStatusBarText (statusText); 208 g_free (statusText); 209 // Set the cursor. 210 view.setCursor (MAIN_VIEW_CURSOR_WAIT); 121 211 122 212 GError *error = NULL; … … 128 218 } 129 219 220 /// 221 /// @brief Sets the file name to open. 222 /// 223 /// @param fileName The file name to load or reload. 224 /// 130 225 void 131 226 JobLoad::setFileName (const gchar *fileName) … … 135 230 } 136 231 232 /// 233 /// @brief Sets the last error. 234 /// 235 /// @param error The last error opening a file. 236 /// 137 237 void 138 238 JobLoad::setError (GError *error) … … 145 245 } 146 246 247 /// 248 /// @brief Sets the page number. 249 /// 250 /// This is used for reloading, see getPageNum(). 251 /// 252 /// @param pageNum The page to go when the document is reloaded. 253 /// 147 254 void 148 255 JobLoad::setPage (gint pageNum) … … 151 258 } 152 259 260 /// 261 /// @brief Sets the password to open the document. 262 /// 263 /// @param password The password to use. 264 /// 153 265 void 154 266 JobLoad::setPassword (const gchar *password) … … 158 270 } 159 271 272 /// 273 /// @brief Sets the presenter that loads the document. 274 /// 275 /// @param pter The MainPter that will load the document. 276 /// 160 277 void 161 278 JobLoad::setPresenter (MainPter *pter) … … 164 281 } 165 282 283 /// 284 /// @brief Sets if we are reloading. 285 /// 286 /// @param reload TRUE if we are reloading, false otherwise. 287 /// 166 288 void 167 289 JobLoad::setReload (gboolean reload) … … 170 292 } 171 293 294 /// 295 /// @brief Sets the rotation to use after reloading. 296 /// 297 /// @param rotation The degrees of rotation. 298 /// 172 299 void 173 300 JobLoad::setRotation (gint rotation) … … 176 303 } 177 304 305 /// 306 /// @brief Sets the zoom to use after reloading. 307 /// 308 /// @param zoom The level of zoom. 309 /// 178 310 void 179 311 JobLoad::setZoom (gdouble zoom) … … 182 314 } 183 315 184 /// 185 316 //////////////////////////////////////////////////////////////// 317 // Static threaded functions. 318 //////////////////////////////////////////////////////////////// 319 320 /// 321 /// @brief The load is finished. 322 /// 323 /// This can be called either when the document was loaded correctly or 324 /// after an error. What it does is set the presenter in a known state 325 /// ready to be used again. 326 /// 327 /// @param data This parameter hold the JobLoad to open. 328 /// 186 329 gboolean 187 330 job_load_done (gpointer data) … … 201 344 } 202 345 346 /// 347 /// @brief The load had errors. 348 /// 349 /// This is called when the load of the document had any error except 350 /// when it's encrypted. 351 /// 352 /// @param data This parameter hold the JobLoad to open. 353 /// 203 354 gboolean 204 355 job_load_error (gpointer data) … … 209 360 job->getPresenter ().getView ().showErrorMessage (_("Error Loading File"), 210 361 job->getError ()->message); 211 delete job; 212 213 return FALSE; 214 } 215 362 job->setReload (FALSE); 363 return job_load_done (data); 364 } 365 366 /// 367 /// @brief The document is encrypted. 368 /// 369 /// This function is called when the document is encrypted. It asks to the 370 /// user the password and tries until the user doesn't supply a password 371 /// anymore (returned NULL) or canTryPassword() returns FALSE. 372 /// 373 /// When trying a new password, it creates a new thread. 374 /// 375 /// @param data This parameter hold the JobLoad to open. 376 /// 216 377 gboolean 217 378 job_load_password (gpointer data) … … 234 395 g_error_free (error); 235 396 } 236 } 237 else 238 { 239 delete job; 397 return FALSE; 240 398 } 241 399 } … … 246 404 _("The password you have supplier is not a valid password " 247 405 "for this file.")); 248 delete job; 249 } 250 251 return FALSE; 252 } 253 406 } 407 408 return job_load_done (data); 409 } 410 411 /// 412 /// @brief Opens the files. 413 /// 414 /// This is the threaded function that will try to call the presenter's 415 /// loading function with the given file name and password. This function 416 /// just tests if the load was successful or not and then tells glib to 417 /// call the actual end function, that will show the result to the user. 418 /// 419 /// When this function is compiled with DEBUG defined, the calls to the 420 /// "end" functions aren't scheduled by glib, since the test framework doesn't 421 /// use it. 422 /// 423 /// @param data This parameter hold the JobLoad to open. 424 /// 254 425 gpointer 255 426 job_load_run (gpointer data) -
trunk/src/JobLoad.h
r115 r117 23 23 // Forward declarations. 24 24 class MainPter; 25 25 26 /// 27 /// @class JobLoad 28 /// @brief A background job that loads a file. 29 /// 30 /// This class is used to load and reload the PDF files. It creates 31 /// a thread that loads a file name. 32 /// 26 33 class JobLoad 27 34 { -
trunk/src/MainPter.cxx
r115 r117 136 136 } 137 137 138 // Sensitive the open file action. 139 view.sensitiveOpen (TRUE); 138 140 // Show the toolbar and statusbar depending on the configuration. 139 141 view.showToolbar (config.showToolbar ()); … … 141 143 view.setOutline (m_Document->getOutline ()); 142 144 view.showSidebar (showSidebar); 145 // Remove the status bar text. 146 view.setStatusBarText (NULL); 143 147 // Show the first page *AFTER* showing the sidebar because 144 148 // the view change the row to the first outline that doesn't need … … 146 150 // by the first outline is selected and we don't want this. 147 151 m_Document->goToFirstPage (); 152 // Show the normal cursor. 153 view.setCursor (MAIN_VIEW_CURSOR_NORMAL); 148 154 view.show (); 149 155 } … … 278 284 Config &config = Config::getConfig (); 279 285 gchar *lastFolder = config.getOpenFileFolder (); 280 gchar *fileName = getView ().openFileDialog (lastFolder); 286 IMainView &view = getView (); 287 gchar *fileName = view.openFileDialog (lastFolder); 281 288 g_free (lastFolder); 282 289 if ( NULL != fileName ) … … 287 294 } 288 295 296 // Open the file. 289 297 JobLoad *job = new JobLoad (); 290 298 job->setPresenter (this); … … 356 364 void 357 365 MainPter::reloadActivated () 358 { 366 { 367 // Reopen the document. 359 368 JobLoad *job = new JobLoad (); 360 369 job->setPresenter (this); … … 366 375 job->setRotation (m_Document->getRotation ()); 367 376 job->setZoom ( m_Document->getZoom ()); 368 // Reopen the document.369 377 job->run (); 370 378 } … … 617 625 return TRUE; 618 626 } 619 /*620 {621 // Now that the document has been loaded, just reset the initial622 // state.623 setInitialState (canShowPage);624 }625 else626 {627 // We got an error, but also can be that the file is encrypted.628 if ( DocumentErrorEncrypted == error->code )629 {630 // Now we got an encrypted file.631 // Prompt for the password up to three time, until the password632 // is correct or the user cancels the password dialog.633 int passwordTries = 0;634 gchar *password = NULL;635 gboolean loaded = FALSE;636 do637 {638 g_free (password);639 password = getView ().promptPasswordDialog ();640 loaded = m_Document->loadFile (fileName, password, NULL);641 } while ( 3 > ++passwordTries &&642 NULL != password &&643 !loaded);644 645 // We are go, just check if we could load it or show the646 // error.647 if ( loaded )648 {649 // Phew, finally loaded. Set the initial state.650 setInitialState (canShowPage);651 }652 else if ( NULL != password )653 {654 // We didn't get the correct password, but the user655 // tried, because the password is not NULL.656 getView ().showErrorMessage (_("Error Loading File"),657 _("The password you have supplier is not a"658 " valid password for this file."));659 g_free (password);660 }661 }662 else663 {664 // It was an error. Show the error message.665 getView ().showErrorMessage (_("Error Loading File"),666 error->message);667 668 }669 g_free (error);670 }671 }672 673 }674 */675 627 676 628 /// -
trunk/src/gtk/MainView.cxx
r114 r117 357 357 358 358 void 359 MainView::sensitiveOpen (gboolean sensitive) 360 { 361 GtkAction *open = 362 gtk_ui_manager_get_action (m_UIManager, "/MenuBar/FileMenu/OpenFile"); 363 gtk_action_set_sensitive (open, sensitive); 364 } 365 366 void 359 367 MainView::sensitiveReload (gboolean sensitive) 360 368 { … … 479 487 } 480 488 489 void 490 MainView::setCursor (ViewCursor cursorType) 491 { 492 GdkCursor *cursor = NULL; 493 switch (cursorType) 494 { 495 case MAIN_VIEW_CURSOR_WAIT: 496 cursor = gdk_cursor_new (GDK_WATCH); 497 break; 498 case MAIN_VIEW_CURSOR_DRAG: 499 cursor = gdk_cursor_new (GDK_FLEUR); 500 break; 501 default: 502 cursor = NULL; 503 } 504 505 if ( NULL != m_MainWindow && GDK_IS_WINDOW (m_MainWindow->window) ) 506 { 507 gdk_window_set_cursor (m_MainWindow->window, cursor); 508 } 509 if ( NULL != cursor ) 510 { 511 gdk_cursor_unref (cursor); 512 } 513 gdk_flush (); 514 } 515 481 516 void 482 517 MainView::setTotalPages (gint pages) … … 497 532 { 498 533 return gtk_entry_get_text (GTK_ENTRY (m_CurrentPage)); 534 } 535 536 void 537 MainView::setStatusBarText (const gchar *text) 538 { 539 gint contextId = gtk_statusbar_get_context_id (GTK_STATUSBAR (m_StatusBar), 540 "general_message"); 541 gtk_statusbar_pop (GTK_STATUSBAR (m_StatusBar), contextId); 542 if ( NULL != text ) 543 { 544 gtk_statusbar_push (GTK_STATUSBAR (m_StatusBar), contextId, text); 545 } 499 546 } 500 547 … … 1074 1121 DragInfo *info = (DragInfo *)data; 1075 1122 delete info; 1076 1077 1123 return TRUE; 1078 1124 } -
trunk/src/gtk/MainView.h
r110 r117 42 42 void sensitiveGoToPreviousPage (gboolean sensitive); 43 43 void sensitiveReload (gboolean sensitive); 44 void sensitiveOpen (gboolean sensitive); 44 45 void sensitiveRotateLeft (gboolean sensitive); 45 46 void sensitiveRotateRight (gboolean sensitive); … … 52 53 void showPage (DocumentPage *page, PageScroll scroll); 53 54 void showSidebar (gboolean show); 55 void setCursor (ViewCursor cursorType); 54 56 void setTotalPages (gint pages); 55 57 void setGoToPageText (const gchar *text); 58 void setStatusBarText (const gchar *text); 56 59 const gchar *getGoToPageText (void); 57 60 void getPageViewSize (gint *width, gint *height); -
trunk/src/main.cxx
r115 r117 54 54 // Create the main presenter. 55 55 MainPter *mainPter = new MainPter (); 56 // Create the main view. 57 MainView *mainView = new MainView (mainPter); 58 // Let know to the presenter which is its view. 59 mainPter->setView (mainView); 60 // Enter the main loop and wait for user interaction. */ 56 61 // Now check if we have additional parameters. Any additional parameter 57 62 // will be a file name to open. … … 63 68 job->run (); 64 69 } 65 // Create the main view.66 MainView *mainView = new MainView (mainPter);67 // Let know to the presenter which is its view.68 mainPter->setView (mainView);69 // Enter the main loop and wait for user interaction. */70 70 gtk_main(); 71 71 -
trunk/tests/DumbMainView.cxx
r107 r117 126 126 127 127 void 128 DumbMainView::sensitiveOpen (gboolean sensitive) 129 { 130 } 131 132 void 128 133 DumbMainView::sensitiveReload (gboolean sensitive) 129 134 {
