Added balxparse to RPM and DEB binary packages
[barry.git] / gui / src / DatabaseSelectDlg.cc
blob709e429db3c4376ae33ab3f93fb427317cfc7860
1 ///
2 /// \file DatabaseSelectDlg.cc
3 /// Dialog wrapper class for user selection of device databases
4 ///
6 /*
7 Copyright (C) 2007-2010, 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 const Glib::ustring &label)
31 : m_pTopLabel(0),
32 m_pTree(0),
33 m_selections(selections)
35 Glib::RefPtr<Gnome::Glade::Xml> xml = LoadXml("DatabaseSelectDlg.glade");
37 Gtk::Dialog *pD = 0;
38 xml->get_widget("DatabaseSelectDlg", pD);
39 m_pDialog.reset(pD);
41 xml->get_widget("toplabel", m_pTopLabel);
42 xml->get_widget("treeview1", m_pTree);
44 Gtk::Button *pButton = 0;
45 xml->get_widget("select_all", pButton);
46 pButton->signal_clicked().connect(
47 sigc::mem_fun(*this, &DatabaseSelectDlg::on_select_all));
49 pButton = 0;
50 xml->get_widget("deselect_all", pButton);
51 pButton->signal_clicked().connect(
52 sigc::mem_fun(*this, &DatabaseSelectDlg::on_deselect_all));
54 m_pTopLabel->set_text(label);
56 m_pListStore = Gtk::ListStore::create(m_Columns);
57 m_pListStore->set_sort_column(m_Columns.m_name, Gtk::SORT_ASCENDING);
58 LoadTree(dbdb);
61 DatabaseSelectDlg::~DatabaseSelectDlg()
65 void DatabaseSelectDlg::LoadTree(const Barry::DatabaseDatabase &dbdb)
67 Barry::DatabaseDatabase::DatabaseArrayType::const_iterator i =
68 dbdb.Databases.begin();
70 for( ; i != dbdb.Databases.end(); ++i ) {
71 Gtk::TreeModel::iterator row = m_pListStore->append();
72 (*row)[m_Columns.m_selected] = IsSelected(i->Name);
73 (*row)[m_Columns.m_name] = i->Name;
75 m_pTree->set_model(m_pListStore);
76 m_pTree->append_column_editable(_("Active"), m_Columns.m_selected);
77 m_pTree->append_column(_("Name"), m_Columns.m_name);
80 bool DatabaseSelectDlg::IsSelected(const std::string &dbname)
82 return m_selections.IsSelected(dbname);
85 void DatabaseSelectDlg::SaveSelections()
87 // start fresh
88 m_selections.clear();
90 // cycle through tree control and add all selected names
91 Gtk::TreeModel::Children children = m_pListStore->children();
92 Gtk::TreeModel::Children::const_iterator i = children.begin();
93 for( ; i != children.end(); ++i ) {
94 if( (*i)[m_Columns.m_selected] ) {
95 Glib::ustring uname = (*i)[m_Columns.m_name];
96 std::string name = uname;
97 m_selections.push_back( name );
102 int DatabaseSelectDlg::run()
104 int ret = m_pDialog->run();
105 if( ret == Gtk::RESPONSE_OK ) {
106 SaveSelections();
108 return ret;
111 void DatabaseSelectDlg::on_select_all()
113 // cycle through tree control and add all selected names
114 Gtk::TreeModel::Children children = m_pListStore->children();
115 Gtk::TreeModel::Children::const_iterator i = children.begin();
116 for( ; i != children.end(); ++i ) {
117 (*i)[m_Columns.m_selected] = true;
121 void DatabaseSelectDlg::on_deselect_all()
123 // cycle through tree control and add all selected names
124 Gtk::TreeModel::Children children = m_pListStore->children();
125 Gtk::TreeModel::Children::const_iterator i = children.begin();
126 for( ; i != children.end(); ++i ) {
127 (*i)[m_Columns.m_selected] = false;