Bumped copyright dates for 2013
[barry.git] / gui / src / DatabaseSelectDlg.cc
blobb04b8df665e8a4cc1d89e631ce92e3aef020f9c6
1 ///
2 /// \file DatabaseSelectDlg.cc
3 /// Dialog wrapper class for user selection of device databases
4 ///
6 /*
7 Copyright (C) 2007-2013, 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 if( !m_backupMode ) {
61 m_pAutoSelectAllCheck->hide();
64 m_pTopLabel->set_text(label);
66 m_pListStore = Gtk::ListStore::create(m_Columns);
67 m_pListStore->set_sort_column(m_Columns.m_name, Gtk::SORT_ASCENDING);
68 LoadTree(dbdb);
71 DatabaseSelectDlg::~DatabaseSelectDlg()
75 void DatabaseSelectDlg::LoadTree(const Barry::DatabaseDatabase &dbdb)
77 Barry::DatabaseDatabase::DatabaseArrayType::const_iterator i =
78 dbdb.Databases.begin();
80 for( ; i != dbdb.Databases.end(); ++i ) {
81 Gtk::TreeModel::iterator row = m_pListStore->append();
82 (*row)[m_Columns.m_selected] = IsSelected(i->Name);
83 (*row)[m_Columns.m_name] = i->Name;
85 m_pTree->set_model(m_pListStore);
86 m_pTree->append_column_editable(_("Active"), m_Columns.m_selected);
87 m_pTree->append_column(_("Name"), m_Columns.m_name);
90 bool DatabaseSelectDlg::IsSelected(const std::string &dbname)
92 return m_selections.IsSelected(dbname);
95 void DatabaseSelectDlg::SaveSelections()
97 // start fresh
98 m_selections.clear();
100 // cycle through tree control and add all selected names
101 Gtk::TreeModel::Children children = m_pListStore->children();
102 Gtk::TreeModel::Children::const_iterator i = children.begin();
103 for( ; i != children.end(); ++i ) {
104 if( (*i)[m_Columns.m_selected] ) {
105 Glib::ustring uname = (*i)[m_Columns.m_name];
106 std::string name = uname;
107 m_selections.push_back( name );
111 // save the auto flag
112 m_auto_select_all = m_pAutoSelectAllCheck->get_active();
115 int DatabaseSelectDlg::run()
117 int ret = m_pDialog->run();
118 if( ret == Gtk::RESPONSE_OK ) {
119 SaveSelections();
121 return ret;
124 void DatabaseSelectDlg::on_select_all()
126 // cycle through tree control and add all selected names
127 Gtk::TreeModel::Children children = m_pListStore->children();
128 Gtk::TreeModel::Children::const_iterator i = children.begin();
129 for( ; i != children.end(); ++i ) {
130 (*i)[m_Columns.m_selected] = true;
134 void DatabaseSelectDlg::on_deselect_all()
136 // cycle through tree control and add all selected names
137 Gtk::TreeModel::Children children = m_pListStore->children();
138 Gtk::TreeModel::Children::const_iterator i = children.begin();
139 for( ; i != children.end(); ++i ) {
140 (*i)[m_Columns.m_selected] = false;