From f5780f7ab1e54710fdfe17afaca74ed68fd13038 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Thu, 2 Feb 2012 19:29:51 -0500 Subject: [PATCH] lib + gui: added Auto Select All checkbox to the backup GUI If the checkbox is checked, in the backup database list config, then on every backup, the backup list is taken from the device's DBDB, not the database list selection. If you regularly backup everything, this setting prevents you from ignoring new databases that appear when installing new applications on your device, etc. --- gui/src/BackupWindow.cc | 3 ++- gui/src/ConfigDlg.cc | 11 ++++++---- gui/src/ConfigDlg.h | 2 ++ gui/src/DatabaseSelectDlg.cc | 19 ++++++++++++---- gui/src/DatabaseSelectDlg.glade | 24 +++++++++++++++++++++ gui/src/DatabaseSelectDlg.h | 9 +++++++- gui/src/Thread.cc | 15 +++++++++++-- src/configfile.cc | 48 ++++++++++++++++++++++++++++++++++------- src/configfile.h | 6 ++++++ 9 files changed, 117 insertions(+), 20 deletions(-) diff --git a/gui/src/BackupWindow.cc b/gui/src/BackupWindow.cc index db631244..b200992d 100644 --- a/gui/src/BackupWindow.cc +++ b/gui/src/BackupWindow.cc @@ -456,7 +456,7 @@ void BackupWindow::on_backup() } // anything to do? - if( thread->GetBackupList().size() == 0 ) { + if( thread->GetBackupList().size() == 0 && !thread->AutoSelectAll() ) { Gtk::MessageDialog msg(_("No databases selected in configuration.")); msg.run(); return; @@ -580,6 +580,7 @@ void BackupWindow::on_config() thread->SetDeviceName(dlg.GetDeviceName()); thread->SetBackupPath(dlg.GetBackupPath()); thread->SetPromptBackupLabel(dlg.GetPromptBackupLabel()); + thread->SetAutoSelectAll(dlg.GetAutoSelectAll()); if( !thread->Save() ) StatusbarSet(_("Error saving config: ") + thread->LastConfigError()); diff --git a/gui/src/ConfigDlg.cc b/gui/src/ConfigDlg.cc index 76a9a7ea..9ccae1f9 100644 --- a/gui/src/ConfigDlg.cc +++ b/gui/src/ConfigDlg.cc @@ -31,6 +31,8 @@ ConfigDlg::ConfigDlg(const Barry::DatabaseDatabase &dbdb, , m_backupList(config.GetBackupList()) , m_restoreList(config.GetRestoreList()) , m_backupPath(config.GetPath()) + , m_promptBackupLabel(config.PromptBackupLabel()) + , m_autoSelectAll(config.AutoSelectAll()) { Glib::RefPtr xml = LoadXml("ConfigDlg.glade"); @@ -73,20 +75,21 @@ int ConfigDlg::run() void ConfigDlg::on_configure_backup() { - DatabaseSelectDlg dlg(m_dbdb, m_backupList, - _("Select the device databases you wish to backup:")); + DatabaseSelectDlg dlg(m_dbdb, m_backupList, m_autoSelectAll, + _("Select the device databases you wish to backup:"), true); if( dlg.run() == Gtk::RESPONSE_OK ) { m_backupList = dlg.GetSelections(); + m_autoSelectAll = dlg.AutoSelectAll(); } } void ConfigDlg::on_configure_restore() { - DatabaseSelectDlg dlg(m_dbdb, m_restoreList, + DatabaseSelectDlg dlg(m_dbdb, m_restoreList, m_autoSelectAll, _("Select the device databases you wish to recover. " "This selection acts like a filter, in that only the databases " "you select here will be restored, even if more exist in the " - "backup data.")); + "backup data."), false); if( dlg.run() == Gtk::RESPONSE_OK ) { m_restoreList = dlg.GetSelections(); } diff --git a/gui/src/ConfigDlg.h b/gui/src/ConfigDlg.h index 73d9a958..7fe692ef 100644 --- a/gui/src/ConfigDlg.h +++ b/gui/src/ConfigDlg.h @@ -47,6 +47,7 @@ class ConfigDlg std::string m_deviceName; std::string m_backupPath; bool m_promptBackupLabel; + bool m_autoSelectAll; public: ConfigDlg(const Barry::DatabaseDatabase &dbdb, @@ -58,6 +59,7 @@ public: const std::string& GetDeviceName() const { return m_deviceName; } const std::string& GetBackupPath() const { return m_backupPath; } bool GetPromptBackupLabel() const { return m_promptBackupLabel; } + bool GetAutoSelectAll() const { return m_autoSelectAll; } int run(); diff --git a/gui/src/DatabaseSelectDlg.cc b/gui/src/DatabaseSelectDlg.cc index 6fa6762a..142382a7 100644 --- a/gui/src/DatabaseSelectDlg.cc +++ b/gui/src/DatabaseSelectDlg.cc @@ -27,10 +27,14 @@ DatabaseSelectDlg::DatabaseSelectDlg(const Barry::DatabaseDatabase &dbdb, const Barry::ConfigFile::DBListType &selections, - const Glib::ustring &label) - : m_pTopLabel(0), - m_pTree(0), - m_selections(selections) + bool auto_select_all, + const Glib::ustring &label, + bool backup_mode) + : m_backupMode(backup_mode) + , m_pTopLabel(0) + , m_pTree(0) + , m_selections(selections) + , m_auto_select_all(auto_select_all) { Glib::RefPtr xml = LoadXml("DatabaseSelectDlg.glade"); @@ -51,6 +55,10 @@ DatabaseSelectDlg::DatabaseSelectDlg(const Barry::DatabaseDatabase &dbdb, pButton->signal_clicked().connect( sigc::mem_fun(*this, &DatabaseSelectDlg::on_deselect_all)); + xml->get_widget("auto_select_all", m_pAutoSelectAllCheck); + m_pAutoSelectAllCheck->set_active(m_auto_select_all); + m_pAutoSelectAllCheck->set_visible(m_backupMode); + m_pTopLabel->set_text(label); m_pListStore = Gtk::ListStore::create(m_Columns); @@ -97,6 +105,9 @@ void DatabaseSelectDlg::SaveSelections() m_selections.push_back( name ); } } + + // save the auto flag + m_auto_select_all = m_pAutoSelectAllCheck->get_active(); } int DatabaseSelectDlg::run() diff --git a/gui/src/DatabaseSelectDlg.glade b/gui/src/DatabaseSelectDlg.glade index 8174074e..8b359567 100644 --- a/gui/src/DatabaseSelectDlg.glade +++ b/gui/src/DatabaseSelectDlg.glade @@ -173,6 +173,30 @@ + + + True + + + Automatically select all databases on every backup + True + True + + + False + False + end + 0 + + + + + False + True + 5 + + + True diff --git a/gui/src/DatabaseSelectDlg.h b/gui/src/DatabaseSelectDlg.h index b88dd1a9..95d74af4 100644 --- a/gui/src/DatabaseSelectDlg.h +++ b/gui/src/DatabaseSelectDlg.h @@ -45,15 +45,20 @@ class DatabaseSelectDlg } }; + // meta class flags + bool m_backupMode; // if true, the checkbox is visible + // Widgets std::auto_ptr m_pDialog; Gtk::Label *m_pTopLabel; + Gtk::CheckButton *m_pAutoSelectAllCheck; Gtk::TreeView *m_pTree; Columns m_Columns; Glib::RefPtr m_pListStore; // data Barry::ConfigFile::DBListType m_selections; + bool m_auto_select_all; // holds checkbox setting protected: void LoadTree(const Barry::DatabaseDatabase &dbdb); @@ -63,10 +68,12 @@ protected: public: DatabaseSelectDlg(const Barry::DatabaseDatabase &dbdb, const Barry::ConfigFile::DBListType &selections, - const Glib::ustring &label); + bool auto_select_all, + const Glib::ustring &label, bool backup_mode); ~DatabaseSelectDlg(); const Barry::ConfigFile::DBListType& GetSelections() const { return m_selections; } + bool AutoSelectAll() const { return m_auto_select_all; } int run(); diff --git a/gui/src/Thread.cc b/gui/src/Thread.cc index 1f577dad..66a7eb4b 100644 --- a/gui/src/Thread.cc +++ b/gui/src/Thread.cc @@ -142,7 +142,18 @@ bool Thread::Backup(std::string label) if( Working() ) return false; - m_recordTotal = m_interface.GetRecordTotal(GetBackupList()); + // grab copy of backup list + Barry::ConfigFile::DBListType list; + if( AutoSelectAll() ) { + // set list to full DBDB + list = m_interface.GetDBDB(); + } + else { + // copy our current saved list + list = GetBackupList(); + } + + m_recordTotal = m_interface.GetRecordTotal(list); m_recordFinished = 0; bool started = m_interface.StartBackup( @@ -151,7 +162,7 @@ bool Thread::Backup(std::string label) &m_signal_done, &m_signal_erase_db, &m_signal_restored_db), - GetBackupList(), GetPath(), label); + list, GetPath(), label); if( started ) { m_thread_state = THREAD_STATE_BACKUP; SetStatus(_("Backup...")); diff --git a/src/configfile.cc b/src/configfile.cc index b917c9fe..29ef5650 100644 --- a/src/configfile.cc +++ b/src/configfile.cc @@ -99,6 +99,7 @@ ConfigFile::ConfigFile(Barry::Pin pin) : m_pin(pin) , m_loaded(false) , m_promptBackupLabel(false) + , m_autoSelectAll(false) { if( m_pin == 0 ) throw ConfigFileError("Configfile: empty pin"); @@ -116,6 +117,7 @@ ConfigFile::ConfigFile(Barry::Pin pin, : m_pin(pin) , m_loaded(false) , m_promptBackupLabel(false) + , m_autoSelectAll(false) { if( m_pin == 0 ) throw ConfigFileError("Configfile: empty pin"); @@ -166,6 +168,7 @@ void ConfigFile::Clear() m_restoreList.clear(); m_deviceName.clear(); m_promptBackupLabel = false; + m_autoSelectAll = false; } /// Attempt to load the configuration file, but do not fail if not available @@ -223,6 +226,11 @@ void ConfigFile::Load() iss >> flag; m_promptBackupLabel = flag; } + else if( keyword == "auto_select_all" ) { + int flag; + iss >> flag; + m_autoSelectAll = flag; + } } } @@ -232,34 +240,37 @@ void ConfigFile::Load() /// Saves current device's config, overwriting or creating a config file bool ConfigFile::Save() { + using namespace std; + if( !CheckPath(m_path, &m_last_error) ) return false; - std::ofstream out(m_filename.c_str(), std::ios::out | std::ios::binary); + ofstream out(m_filename.c_str(), std::ios::out | std::ios::binary); if( !out ) { m_last_error = "Unable to open " + m_filename + " for writing."; return false; } - out << "backup_list" << std::endl; + out << "backup_list" << endl; for( DBListType::iterator i = m_backupList.begin(); i != m_backupList.end(); ++i ) { - out << " " << *i << std::endl; + out << " " << *i << endl; } - out << "restore_list" << std::endl; + out << "restore_list" << endl; for( DBListType::iterator i = m_restoreList.begin(); i != m_restoreList.end(); ++i ) { - out << " " << *i << std::endl; + out << " " << *i << endl; } if( m_deviceName.size() ) { - out << "device_name " << m_deviceName << std::endl; + out << "device_name " << m_deviceName << endl; } if( m_path.size() ) { - out << "backup_path " << m_path << std::endl; + out << "backup_path " << m_path << endl; } - out << "prompt_backup_label " << (m_promptBackupLabel ? 1 : 0) << std::endl; + out << "prompt_backup_label " << (m_promptBackupLabel ? 1 : 0) << endl; + out << "auto_select_all " << (m_autoSelectAll ? 1 : 0) << endl; if( !out ) { m_last_error = "Error during write. Config may be incomplete."; @@ -298,6 +309,22 @@ void ConfigFile::Enlighten(const Barry::DatabaseDatabase &db) } } +// fill list with all databases from dbdb +ConfigFile:: DBListType& ConfigFile::DBListType::operator=(const DatabaseDatabase &dbdb) +{ + // start empty + clear(); + + // copy over all DB names + DatabaseDatabase::DatabaseArrayType::const_iterator + i = dbdb.Databases.begin(), e = dbdb.Databases.end(); + for( ; i != e; ++i ) { + push_back(i->Name); + } + + return *this; +} + /// Sets list with new config void ConfigFile::SetBackupList(const DBListType &list) { @@ -332,6 +359,11 @@ void ConfigFile::SetPromptBackupLabel(bool prompt) m_promptBackupLabel = prompt; } +void ConfigFile::SetAutoSelectAll(bool asa) +{ + m_autoSelectAll = asa; +} + /// Checks that the path in path exists, and if not, creates it. /// Returns false if unable to create path, true if ok. bool ConfigFile::CheckPath(const std::string &path, std::string *perr) diff --git a/src/configfile.h b/src/configfile.h index 84623b0e..eabdb120 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -41,6 +41,8 @@ public: { public: bool IsSelected(const std::string &dbname) const; + + DBListType& operator=(const DatabaseDatabase &dbdb); }; private: @@ -58,6 +60,8 @@ private: bool m_promptBackupLabel; // if true, prompt the user on every // backup for a string to label the // backup file with + bool m_autoSelectAll; // if true, automatically select all + // databases on every backup protected: void BuildFilename(); @@ -98,6 +102,7 @@ public: const std::string& GetDeviceName() const { return m_deviceName; } bool HasDeviceName() const { return m_deviceName.size(); } bool PromptBackupLabel() const { return m_promptBackupLabel; } + bool AutoSelectAll() const { return m_autoSelectAll; } // // operations @@ -123,6 +128,7 @@ public: void SetDeviceName(const std::string &name); void SetBackupPath(const std::string &path); void SetPromptBackupLabel(bool prompt = true); + void SetAutoSelectAll(bool asa = true); // // Utility functions -- 2.11.4.GIT