[glom/glom-1-14] Added --restore command-line option.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/glom-1-14] Added --restore command-line option.
- Date: Thu, 22 Jul 2010 14:31:13 +0000 (UTC)
commit 17423eba2a5578a0dd98cc673d425a6b1a8b4abb
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Jul 22 16:31:00 2010 +0200
Added --restore command-line option.
* glom/application.[h|cc]: Added init() with a bool restore option,
calling do_backup_restore() if appropriate.
* glom/main.cc: Added a --restore command and pass the bool result to
Application::init().
This allows the user to restore from a backup without first loading an
existing file, though this is so far only possible via the terminal.
ChangeLog | 12 ++++++++++++
glom/application.cc | 43 +++++++++++++++++++++++++++++++------------
glom/application.h | 6 ++++++
glom/main.cc | 9 ++++++++-
4 files changed, 57 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 626032c..a137826 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2010-07-22 Murray Cumming <murrayc murrayc com>
+ Added --restore command-line option.
+
+ * glom/application.[h|cc]: Added init() with a bool restore option,
+ calling do_backup_restore() if appropriate.
+ * glom/main.cc: Added a --restore command and pass the bool result to
+ Application::init().
+
+ This allows the user to restore from a backup without first loading an
+ existing file, though this is so far only possible via the terminal.
+
+2010-07-22 Murray Cumming <murrayc murrayc com>
+
Added Developer/Restore Backup menu item.
* glom/application.[h.cc]: Added a Developer/Restore Backup menu item,
diff --git a/glom/application.cc b/glom/application.cc
index 5e52aa8..4d5b11c 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -188,6 +188,11 @@ void Application::on_connection_avahi_done()
bool Application::init(const Glib::ustring& document_uri)
{
+ return init(document_uri, false);
+}
+
+bool Application::init(const Glib::ustring& document_uri, bool restore)
+{
type_vec_strings vecAuthors;
vecAuthors.push_back("Murray Cumming <murrayc murrayc com>");
set_about_information(PACKAGE_VERSION, vecAuthors, _("© 2000-2010 Murray Cumming"), _("A Database GUI"));
@@ -201,14 +206,19 @@ bool Application::init(const Glib::ustring& document_uri)
Document* pDocument = static_cast<Document*>(get_document());
if(pDocument && pDocument->get_connection_database().empty()) //If it is a new (default) document.
{
- return offer_new_or_existing();
+ return offer_new_or_existing();
}
}
else
{
- const bool test = open_document(document_uri);
- if(!test)
- return offer_new_or_existing();
+ if(restore)
+ return do_restore_backup(document_uri);
+ else
+ {
+ const bool test = open_document(document_uri);
+ if(!test)
+ return offer_new_or_existing();
+ }
}
return true;
@@ -2806,7 +2816,7 @@ void Application::on_menu_developer_export_backup()
" --directory \"" + parent_dir + "\"" + //This must be right before the mention of the file name:
" \"" + basename + "\"";
- std::cout << "DEBUG: command_tar=" << command_tar << std::endl;
+ //std::cout << "DEBUG: command_tar=" << command_tar << std::endl;
saved = Glom::Spawn::execute_command_line_and_wait(command_tar,
sigc::mem_fun(*this, &Application::on_connection_save_backup_progress));
@@ -2848,16 +2858,23 @@ void Application::on_menu_developer_restore_backup()
if(result != Gtk::RESPONSE_OK)
return;
- // We cannot use an uri here, because we cannot untar remote files.
- const std::string filename_tarball = file_dlg.get_filename();
- if(filename_tarball.empty())
+ const std::string uri_tarball = file_dlg.get_uri();
+ if(uri_tarball.empty())
return;
+ do_restore_backup(uri_tarball);
+}
+
+bool Application::do_restore_backup(const Glib::ustring& backup_uri)
+{
+ // We cannot use an uri here, because we cannot untar remote files.
+ const std::string filename_tarball = Glib::filename_from_uri(backup_uri);
+
const std::string path_tar = Glib::find_program_in_path("tar");
if(path_tar.empty())
{
std::cerr << G_STRFUNC << ": The tar executable could not be found." << std::endl;
- return;
+ return false;
}
//Create a temporary directory into which we will untar the tarball:
@@ -2870,7 +2887,7 @@ void Application::on_menu_developer_restore_backup()
if(!Utils::delete_directory(uri_tmp))
{
std::cerr << G_STRFUNC << "Error from Utils::delete_directory() while trying to remove directory: " << uri_tmp << std::endl;
- return;
+ return false;
}
//Create the tmp directory:
@@ -2880,7 +2897,7 @@ void Application::on_menu_developer_restore_backup()
std::cerr << G_STRFUNC << "Error from g_mkdir_with_parents() while trying to create directory: " << path_tmp << std::endl;
perror("Error from g_mkdir_with_parents");
- return;
+ return false;
}
//Untar into the tmp directory:
@@ -2915,7 +2932,7 @@ void Application::on_menu_developer_restore_backup()
if(untarred_uri.empty())
{
ui_warning(_("Restore Backup failed."), _("There was an error while restoring the backup. The .glom file could not be found."));
- return;
+ return false;
}
//std::cout << "DEBUG: untarred_uri=" << untarred_uri << std::endl;
@@ -2926,6 +2943,8 @@ void Application::on_menu_developer_restore_backup()
//because open_document() starts a new process,
//so we don't know when we can safely delete the files.
//Utils::delete_directory(uri_tmp);
+
+ return true;
}
void Application::on_menu_developer_show_layout_toolbar()
diff --git a/glom/application.h b/glom/application.h
index 0978b0b..706932d 100644
--- a/glom/application.h
+++ b/glom/application.h
@@ -66,6 +66,11 @@ public:
virtual bool init(const Glib::ustring& document_uri = Glib::ustring()); //override
+ /**
+ * @param restore Whether @a document_uri is a .tar.gz backup file to restore.
+ */
+ bool init(const Glib::ustring& document_uri, bool restore);
+
//virtual void statusbar_set_text(const Glib::ustring& strText);
//virtual void statusbar_clear();
@@ -107,6 +112,7 @@ public:
#ifndef GLOM_ENABLE_CLIENT_ONLY
void do_menu_developer_fields(Gtk::Window& parent, const Glib::ustring table_name);
void do_menu_developer_relationships(Gtk::Window& parent, const Glib::ustring table_name);
+ bool do_restore_backup(const Glib::ustring& backup_uri);
#endif //GLOM_ENABLE_CLIENT_ONLY
///Whether to show the generated SQL queries on stdout, for debugging.
diff --git a/glom/main.cc b/glom/main.cc
index 9ceb9b0..78ffc75 100644
--- a/glom/main.cc
+++ b/glom/main.cc
@@ -188,6 +188,7 @@ public:
//and as long as the OptionContext to which those OptionGroups are added.
std::string m_arg_filename;
bool m_arg_version;
+ bool m_arg_restore;
bool m_arg_debug_sql;
bool m_arg_debug_date_check;
};
@@ -195,6 +196,7 @@ public:
OptionGroup::OptionGroup()
: Glib::OptionGroup("Glom", _("Glom options"), _("Command-line options for glom")),
m_arg_version(false),
+ m_arg_restore(false),
m_arg_debug_sql(false),
m_arg_debug_date_check(false)
{
@@ -210,6 +212,11 @@ OptionGroup::OptionGroup()
entry_version.set_description(_("The version of this application."));
add_entry(entry_version, m_arg_version);
+ Glib::OptionEntry entry_restore;
+ entry_restore.set_long_name("restore");
+ entry_restore.set_description(_("Whether the filename is a .tar.gz backup to be restored."));
+ add_entry(entry_restore, m_arg_restore);
+
Glib::OptionEntry entry_debug_sql;
entry_debug_sql.set_long_name("debug_sql");
entry_debug_sql.set_description(_("Show the generated SQL queries on stdout, for debugging."));
@@ -630,7 +637,7 @@ main(int argc, char* argv[])
pApplication->set_command_line_args(argc, argv);
pApplication->set_show_sql_debug(group.m_arg_debug_sql);
- const bool test = pApplication->init(input_uri); //Sets it up and shows it.
+ const bool test = pApplication->init(input_uri, group.m_arg_restore); //Sets it up and shows it.
#ifdef GLOM_ENABLE_MAEMO
//TODO: What is this really for?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]