[glom/feature_backup2] Show progress in the UI during backup saving and restoring.



commit e1111517779a31d9642bfe5e32179b22f5a27626
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Jul 5 09:57:38 2010 +0200

    Show progress in the UI during backup saving and restoring.
    
    * glom/application.[h|cc]: on_document_load(),
        on_menu_developer_export_backup(): Show a pulsing progress dialog while
        waiting for backup exporting and restoring.
        on_menu_developer_export_backup(): Close the file chooser dialog as soon
        as we stop using it.

 ChangeLog           |   66 +++++++++++++++++++++++++-------------------
 glom/application.cc |   76 ++++++++++++++++++++++++++++++++++++++++-----------
 glom/application.h  |    5 +++
 3 files changed, 103 insertions(+), 44 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0139106..e2a1ad5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,76 +1,86 @@
+2010-07-05  Murray Cumming  <murrayc murrayc com>
+
+	Show progress in the UI during backup saving and restoring.
+
+	* glom/application.[h|cc]: on_document_load(),
+    on_menu_developer_export_backup(): Show a pulsing progress dialog while
+    waiting for backup exporting and restoring.
+    on_menu_developer_export_backup(): Close the file chooser dialog as soon
+    as we stop using it.
+
 2010-07-03  Murray Cumming  <murrayc murrayc com>
 
 	Improve backup saving and add backup restoring.
-	
-	* glom/libglom/document/document.[h|cc]: Added get/set_is_backup_file(), 
+
+	* glom/libglom/document/document.[h|cc]: Added get/set_is_backup_file(),
 	saved in the XML document..
   on_menu_developer_export_backup(): Mark the .glom file as a backup file.
 	Rename recreate_database() to recreate_database_from_example().
-	on_document_load(): Handle backup .glom files similarly to examples files, 
+	on_document_load(): Handle backup .glom files similarly to examples files,
 	but using the backup file instead of example data.
 	* glom/frame_glom.cc:
 	* glom/libglom/connection_pool.[h|cc]:
-	* glom/libglom/connectionpool_backends/backend.[h|cc]: startup(): Return a 
-	StartupErrors enum, to provide more clues, for instance to say that backup 
+	* glom/libglom/connectionpool_backends/backend.[h|cc]: startup(): Return a
+	StartupErrors enum, to provide more clues, for instance to say that backup
 	data was found.
-	Add get/set_database_directory_uri(), replacing the one in sqlite.[h|cc] and 
+	Add get/set_database_directory_uri(), replacing the one in sqlite.[h|cc] and
 	replacing set_self_hosting_data_uri() in postgres_self.[hc|cc].
-	save_backup(): Don't take a filepath - use get_database_directory_uri() 
+	save_backup(): Don't take a filepath - use get_database_directory_uri()
 	instead.
 	Added convert_backup() to restore from a backup.
 	* glom/libglom/connectionpool_backends/sqlite.[h|cc]:
 	* glom/libglom/connectionpool_backends/postgres.[h|cc]:
 	get_path_to_postgres_executable(): Catch exceptions from Glib::build_filename().
-	save_backup(): Use --format=c with pg_dump, because the default one can't be 
+	save_backup(): Use --format=c with pg_dump, because the default one can't be
 	used with pg_restore.
 	Implement convert_backup(), using pg_restore.
-	Added get_self_hosting_config_path(), get_self_hosting_data_path() and 
+	Added get_self_hosting_config_path(), get_self_hosting_data_path() and
 	get_self_hosting_backup_path() to avoid copy/pasting magic paths.
 	* glom/libglom/connectionpool_backends/postgres_self.[h|cc]:
 	Adapted.
 	* glom/application.[h|cc]:
-	* tests/test_selfhosting_new_empty.cc: Adapted to check the enum result from 
+	* tests/test_selfhosting_new_empty.cc: Adapted to check the enum result from
 	startup().
-	
+
 2010-07-02  Murray Cumming  <murrayc murrayc com>
 
 	Document: Avoid a crash when creating the parent directory.
-	
-	* glom/libglom/docment/bakery/document.cc: write_to_disk(): Check the 
-	result of Gio::File::get_parent() for null, because that happens if we 
+
+	* glom/libglom/docment/bakery/document.cc: write_to_disk(): Check the
+	result of Gio::File::get_parent() for null, because that happens if we
 	provide a path instead of a URI.
-	
+
 2010-07-02  Murray Cumming  <murrayc murrayc com>
 
 	Save as Example: Reset the old file URI and allow auto-saving again.
 
-	* glom/application.cc: on_menu_file_save_as_example(): reset the old file 
-	URI and turn auto-saving back on again, because it makes no sense to leave 
+	* glom/application.cc: on_menu_file_save_as_example(): reset the old file
+	URI and turn auto-saving back on again, because it makes no sense to leave
 	the user editing an example document. This is really an export anyway.
 	This allows the user to close the window again after saving as an example.
-	
+
 2010-07-01  Murray Cumming  <murrayc murrayc com>
 
 	Add Save Backup menu item.
-	
+
 	* glom/libglom/connectionpool_backends/backend.[h|cc]:
 	* glom/libglom/connectionpool_backends/posgres.[h|cc]:
-	* glom/libglom/connectionpool_backends/sqlite.[h|cc]: Added save_backup() 
+	* glom/libglom/connectionpool_backends/sqlite.[h|cc]: Added save_backup()
 	virtual method, using pg_dump for PostgreSQL.
-	* glom/libglom/connectionpool.[h|cc]: Add save_backup() here, calling the 
+	* glom/libglom/connectionpool.[h|cc]: Add save_backup() here, calling the
 	backend.
-	* glom/application.cc: Add a Developer/Export Backup menu item, to use 
+	* glom/application.cc: Add a Developer/Export Backup menu item, to use
 	this feature. This also saves the .glom file.
-		
+
 2010-07-01  Murray Cumming  <murrayc murrayc com>
 
 	Spawn functions: Catch some exceptions.
-	
-	* glom/libglom/spawn_with_feedback.cc(): 
-	execute_command_line(), execute_command_line_and_wait(): Catch exceptions 
-	so that these functions don't throw, simplifying caller code. For instance, 
+
+	* glom/libglom/spawn_with_feedback.cc():
+	execute_command_line(), execute_command_line_and_wait(): Catch exceptions
+	so that these functions don't throw, simplifying caller code. For instance,
 	a command may be malformed and rejected by the shell.
-	
+
 2010-06-29  Murray Cumming  <murrayc murrayc com>
 
 	* glom/application.[h|cc]: Developer menu: Added an Export Backup menu item.
diff --git a/glom/application.cc b/glom/application.cc
index e74b723..fc434ae 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -86,6 +86,8 @@ Application::Application(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builde
   m_ui_save_extra_showextras(false),
   m_ui_save_extra_newdb_hosting_mode(Document::HOSTING_MODE_DEFAULT),
   m_avahi_progress_dialog(0),
+  m_dialog_progess_save_backup(0),
+  m_dialog_progess_convert_backup(0),
 #endif // !GLOM_ENABLE_CLIENT_ONLY
   m_show_sql_debug(false)
 {
@@ -127,6 +129,18 @@ Application::~Application()
     delete m_avahi_progress_dialog;
     m_avahi_progress_dialog = 0;
   }
+
+  if(m_dialog_progess_save_backup)
+  {
+    delete m_dialog_progess_save_backup;
+    m_dialog_progess_save_backup = 0;
+  }
+
+  if(m_dialog_progess_convert_backup)
+  {
+    delete m_dialog_progess_convert_backup;
+    m_dialog_progess_convert_backup = 0;
+  }
   #endif // !GLOM_ENABLE_CLIENT_ONLY
 
   #ifdef GLOM_ENABLE_MAEMO
@@ -1027,24 +1041,24 @@ bool Application::on_document_load()
     // would need to be saved, but saving support is disabled.
 #ifndef GLOM_ENABLE_CLIENT_ONLY
     const bool is_example = pDocument->get_is_example_file();
-    const bool is_backup = pDocument->get_is_backup_file(); 
+    const bool is_backup = pDocument->get_is_backup_file();
 #endif // !GLOM_ENABLE_CLIENT_ONLY
     const std::string original_uri = pDocument->get_file_uri();
 
     if(is_example || is_backup)
     {
-#ifndef GLOM_ENABLE_CLIENT_ONLY  
+#ifndef GLOM_ENABLE_CLIENT_ONLY
       // Remember the URI to the example file to be able to prevent
       // adding the URI to the recently used files in document_history_add.
       // We want to add the document that is created from the example
       // instead of the example itself.
       // TODO: This is a weird hack. Find a nicer way. murrayc.
-      m_example_uri = original_uri;  
+      m_example_uri = original_uri;
 
       pDocument->set_file_uri(Glib::ustring()); //Prevent it from defaulting to the read-only examples directory when offering saveas.
       //m_ui_save_extra_* are used by offer_saveas() if it's not empty:
       m_ui_save_extra_showextras = true;
-      
+
       if(is_example)
       {
         m_ui_save_extra_title = _("Creating From Example File");
@@ -1055,7 +1069,7 @@ bool Application::on_document_load()
         m_ui_save_extra_title = _("Creating From Backup File");
         m_ui_save_extra_message = _("To use this backup file you must save an editable copy of the file. A new database will also be created on the server.");
       }
-    
+
       m_ui_save_extra_newdb_title = "TODO";
       m_ui_save_extra_newdb_hosting_mode = Document::HOSTING_MODE_DEFAULT;
 
@@ -1227,7 +1241,7 @@ bool Application::on_document_load()
       else if(is_backup)
       {
         std::string original_dir_path;
-         
+
         Glib::RefPtr<Gio::File> gio_file = Gio::File::create_for_uri(original_uri);
         if(gio_file)
         {
@@ -1244,16 +1258,23 @@ bool Application::on_document_load()
             }
           }
         }
-        
+
         if(original_dir_path.empty())
         {
           std::cerr << G_STRFUNC << ": original_dir_path is empty." << std::endl;
           return false;
         }
-      
+
         //Restore the database from the backup:
         std::cout << "DEBUG: original_dir_path=" << original_dir_path << std::endl;
-        const bool restored = connection_pool->convert_backup(ConnectionPool::SlotProgress() /* TODO */, original_dir_path);
+        const bool restored = connection_pool->convert_backup(
+          sigc::mem_fun(*this, &Application::on_connection_convert_backup_progress), original_dir_path);
+
+        if(m_dialog_progess_convert_backup)
+        {
+          delete m_dialog_progess_convert_backup;
+          m_dialog_progess_convert_backup = 0;
+        }
       }
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
@@ -1303,6 +1324,22 @@ void Application::on_connection_close_progress()
   //TODO_murrayc
 }
 
+void Application::on_connection_save_backup_progress()
+{
+  if(!m_dialog_progess_save_backup)
+    m_dialog_progess_save_backup = Utils::get_and_show_pulse_dialog(_("Exporting Backup"), this);
+
+  m_dialog_progess_save_backup->pulse();
+}
+
+void Application::on_connection_convert_backup_progress()
+{
+  if(!m_dialog_progess_convert_backup)
+    m_dialog_progess_convert_backup = Utils::get_and_show_pulse_dialog(_("Restoring Backup"), this);
+
+  m_dialog_progess_convert_backup->pulse();
+}
+
 void Application::on_document_close()
 {
 #ifndef GLOM_ENABLE_CLIENT_ONLY
@@ -2537,27 +2574,28 @@ void Application::on_menu_developer_export_backup()
   // Ask the user to choose a new directory name. This actually creates the directory:
   Gtk::FileChooserDialog dialog(*this, _("Save Backup"), Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER);
   dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
-  dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); 
+  dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   const int result = dialog.run();
+  dialog.hide();
   if(result != Gtk::RESPONSE_ACCEPT)
     return;
-    
+
   const std::string& path_dir = dialog.get_filename();
   if(path_dir.empty())
-    return; 
-        
+    return;
+
   //Save a copy of the document there:
   Document* document = dynamic_cast<Document*>(get_document());
   if(!document)
     return;
-  
+
   const std::string& filepath_document = Glib::build_filename(path_dir, "backup.glom");
   document->set_allow_autosave(false); //Prevent saving while we modify the document:
   const Glib::ustring fileuri_old = document->get_file_uri();
   document->set_file_uri(Glib::filename_to_uri(filepath_document), true); //true = enforce file extension;
   document->set_is_backup_file(true);
   bool saved = document->save();
-  
+
   document->set_file_uri(fileuri_old);
   document->set_is_backup_file(false);
   document->set_allow_autosave(true);
@@ -2565,7 +2603,13 @@ void Application::on_menu_developer_export_backup()
   if(saved)
   {
     ConnectionPool* connection_pool = ConnectionPool::get_instance();
-    saved = connection_pool->save_backup(ConnectionPool::SlotProgress() /* TODO */, path_dir);
+    saved = connection_pool->save_backup(sigc::mem_fun(*this, &Application::on_connection_save_backup_progress), path_dir);
+
+    if(m_dialog_progess_save_backup)
+    {
+      delete m_dialog_progess_save_backup;
+      m_dialog_progess_save_backup = 0;
+    }
   }
 
   if(!saved)
diff --git a/glom/application.h b/glom/application.h
index 3b70e49..40710a6 100644
--- a/glom/application.h
+++ b/glom/application.h
@@ -52,6 +52,7 @@ namespace Glom
 {
 
 class Window_Translations;
+class Dialog_ProgressCreating; //TODO: Rename this because it's not just about creating databases.
 
 class Application : public GlomBakery::App_WithDoc_Gtk
 {
@@ -200,6 +201,8 @@ private:
   virtual void new_instance(const Glib::ustring& uri = Glib::ustring()); //Override
 
   void on_connection_close_progress();
+  void on_connection_save_backup_progress();
+  void on_connection_convert_backup_progress();
 
 #ifndef G_OS_WIN32
   void open_browsed_document(const EpcServiceInfo* server, const Glib::ustring& service_name);
@@ -257,6 +260,8 @@ private:
   Document::HostingMode m_ui_save_extra_newdb_hosting_mode;
 
   Gtk::MessageDialog* m_avahi_progress_dialog;
+  Dialog_ProgressCreating* m_dialog_progess_save_backup;
+  Dialog_ProgressCreating* m_dialog_progess_convert_backup;
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
   // This is set to the URI of an example file that is loaded to be able to



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]