2 /// \file DatabaseSelectDlg.cc
3 /// Dialog wrapper class for user selection of device databases
7 Copyright (C) 2007-2008, 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"
24 #include <barry/barry.h>
27 DatabaseSelectDlg::DatabaseSelectDlg(const Barry::DatabaseDatabase
&dbdb
,
28 const ConfigFile::DBListType
&selections
,
29 const Glib::ustring
&label
)
32 m_selections(selections
)
34 Glib::RefPtr
<Gnome::Glade::Xml
> xml
= LoadXml("DatabaseSelectDlg.glade");
37 xml
->get_widget("DatabaseSelectDlg", pD
);
40 xml
->get_widget("toplabel", m_pTopLabel
);
41 xml
->get_widget("treeview1", m_pTree
);
43 Gtk::Button
*pButton
= 0;
44 xml
->get_widget("select_all", pButton
);
45 pButton
->signal_clicked().connect(
46 sigc::mem_fun(*this, &DatabaseSelectDlg::on_select_all
));
49 xml
->get_widget("deselect_all", pButton
);
50 pButton
->signal_clicked().connect(
51 sigc::mem_fun(*this, &DatabaseSelectDlg::on_deselect_all
));
53 m_pTopLabel
->set_text(label
);
55 m_pListStore
= Gtk::ListStore::create(m_Columns
);
56 m_pListStore
->set_sort_column(m_Columns
.m_name
, Gtk::SORT_ASCENDING
);
60 DatabaseSelectDlg::~DatabaseSelectDlg()
64 void DatabaseSelectDlg::LoadTree(const Barry::DatabaseDatabase
&dbdb
)
66 Barry::DatabaseDatabase::DatabaseArrayType::const_iterator i
=
67 dbdb
.Databases
.begin();
69 for( ; i
!= dbdb
.Databases
.end(); ++i
) {
70 Gtk::TreeModel::iterator row
= m_pListStore
->append();
71 (*row
)[m_Columns
.m_selected
] = IsSelected(i
->Name
);
72 (*row
)[m_Columns
.m_name
] = i
->Name
;
74 m_pTree
->set_model(m_pListStore
);
75 m_pTree
->append_column_editable("Active", m_Columns
.m_selected
);
76 m_pTree
->append_column("Name", m_Columns
.m_name
);
79 bool DatabaseSelectDlg::IsSelected(const std::string
&dbname
)
81 return m_selections
.IsSelected(dbname
);
84 void DatabaseSelectDlg::SaveSelections()
89 // cycle through tree control and add all selected names
90 Gtk::TreeModel::Children children
= m_pListStore
->children();
91 Gtk::TreeModel::Children::const_iterator i
= children
.begin();
92 for( ; i
!= children
.end(); ++i
) {
93 if( (*i
)[m_Columns
.m_selected
] ) {
94 Glib::ustring uname
= (*i
)[m_Columns
.m_name
];
95 std::string name
= uname
;
96 m_selections
.push_back( name
);
101 int DatabaseSelectDlg::run()
103 int ret
= m_pDialog
->run();
104 if( ret
== Gtk::RESPONSE_OK
) {
110 void DatabaseSelectDlg::on_select_all()
112 // cycle through tree control and add all selected names
113 Gtk::TreeModel::Children children
= m_pListStore
->children();
114 Gtk::TreeModel::Children::const_iterator i
= children
.begin();
115 for( ; i
!= children
.end(); ++i
) {
116 (*i
)[m_Columns
.m_selected
] = true;
120 void DatabaseSelectDlg::on_deselect_all()
122 // cycle through tree control and add all selected names
123 Gtk::TreeModel::Children children
= m_pListStore
->children();
124 Gtk::TreeModel::Children::const_iterator i
= children
.begin();
125 for( ; i
!= children
.end(); ++i
) {
126 (*i
)[m_Columns
.m_selected
] = false;