lib + gui: added Auto Select All checkbox to the backup GUI
[barry/progweb.git] / gui / src / DatabaseSelectDlg.cc
blob142382a7c6006af9d39b5e2b6d1e9d0f16ebacb3
1 ///
2 /// \file DatabaseSelectDlg.cc
3 /// Dialog wrapper class for user selection of device databases
4 ///
6 /*
7 Copyright (C) 2007-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "DatabaseSelectDlg.h"
23 #include "util.h"
24 #include "i18n.h"
25 #include <barry/barry.h>
26 #include <sstream>
28 DatabaseSelectDlg::DatabaseSelectDlg(const Barry::DatabaseDatabase &dbdb,
29 const Barry::ConfigFile::DBListType &selections,
30 bool auto_select_all,
31 const Glib::ustring &label,
32 bool backup_mode)
33 : m_backupMode(backup_mode)
34 , m_pTopLabel(0)
35 , m_pTree(0)
36 , m_selections(selections)
37 , m_auto_select_all(auto_select_all)
39 Glib::RefPtr<Gnome::Glade::Xml> xml = LoadXml("DatabaseSelectDlg.glade");
41 Gtk::Dialog *pD = 0;
42 xml->get_widget("DatabaseSelectDlg", pD);
43 m_pDialog.reset(pD);
45 xml->get_widget("toplabel", m_pTopLabel);
46 xml->get_widget("treeview1", m_pTree);
48 Gtk::Button *pButton = 0;
49 xml->get_widget("select_all", pButton);
50 pButton->signal_clicked().connect(
51 sigc::mem_fun(*this, &DatabaseSelectDlg::on_select_all));
53 pButton = 0;
54 xml->get_widget("deselect_all", pButton);
55 pButton->signal_clicked().connect(
56 sigc::mem_fun(*this, &DatabaseSelectDlg::on_deselect_all));
58 xml->get_widget("auto_select_all", m_pAutoSelectAllCheck);
59 m_pAutoSelectAllCheck->set_active(m_auto_select_all);
60 m_pAutoSelectAllCheck->set_visible(m_backupMode);
62 m_pTopLabel->set_text(label);
64 m_pListStore = Gtk::ListStore::create(m_Columns);
65 m_pListStore->set_sort_column(m_Columns.m_name, Gtk::SORT_ASCENDING);
66 LoadTree(dbdb);
69 DatabaseSelectDlg::~DatabaseSelectDlg()
73 void DatabaseSelectDlg::LoadTree(const Barry::DatabaseDatabase &dbdb)
75 Barry::DatabaseDatabase::DatabaseArrayType::const_iterator i =
76 dbdb.Databases.begin();
78 for( ; i != dbdb.Databases.end(); ++i ) {
79 Gtk::TreeModel::iterator row = m_pListStore->append();
80 (*row)[m_Columns.m_selected] = IsSelected(i->Name);
81 (*row)[m_Columns.m_name] = i->Name;
83 m_pTree->set_model(m_pListStore);
84 m_pTree->append_column_editable(_("Active"), m_Columns.m_selected);
85 m_pTree->append_column(_("Name"), m_Columns.m_name);
88 bool DatabaseSelectDlg::IsSelected(const std::string &dbname)
90 return m_selections.IsSelected(dbname);
93 void DatabaseSelectDlg::SaveSelections()
95 // start fresh
96 m_selections.clear();
98 // cycle through tree control and add all selected names
99 Gtk::TreeModel::Children children = m_pListStore->children();
100 Gtk::TreeModel::Children::const_iterator i = children.begin();
101 for( ; i != children.end(); ++i ) {
102 if( (*i)[m_Columns.m_selected] ) {
103 Glib::ustring uname = (*i)[m_Columns.m_name];
104 std::string name = uname;
105 m_selections.push_back( name );
109 // save the auto flag
110 m_auto_select_all = m_pAutoSelectAllCheck->get_active();
113 int DatabaseSelectDlg::run()
115 int ret = m_pDialog->run();
116 if( ret == Gtk::RESPONSE_OK ) {
117 SaveSelections();
119 return ret;
122 void DatabaseSelectDlg::on_select_all()
124 // cycle through tree control and add all selected names
125 Gtk::TreeModel::Children children = m_pListStore->children();
126 Gtk::TreeModel::Children::const_iterator i = children.begin();
127 for( ; i != children.end(); ++i ) {
128 (*i)[m_Columns.m_selected] = true;
132 void DatabaseSelectDlg::on_deselect_all()
134 // cycle through tree control and add all selected names
135 Gtk::TreeModel::Children children = m_pListStore->children();
136 Gtk::TreeModel::Children::const_iterator i = children.begin();
137 for( ; i != children.end(); ++i ) {
138 (*i)[m_Columns.m_selected] = false;