2 /// \file DatabaseSelectDlg.cc
3 /// Dialog wrapper class for user selection of device databases
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"
25 #include <barry/barry.h>
28 DatabaseSelectDlg::DatabaseSelectDlg(const Barry::DatabaseDatabase
&dbdb
,
29 const Barry::ConfigFile::DBListType
&selections
,
31 const Glib::ustring
&label
,
33 : m_backupMode(backup_mode
)
36 , m_selections(selections
)
37 , m_auto_select_all(auto_select_all
)
39 Glib::RefPtr
<Gnome::Glade::Xml
> xml
= LoadXml("DatabaseSelectDlg.glade");
42 xml
->get_widget("DatabaseSelectDlg", 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
));
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
);
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()
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
) {
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;