1
/* cdrdao - write audio CD-Rs in disc-at-once mode
3
* Copyright (C) 1998-2002 Andreas Mueller <andreas@daneb.de>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29
#include "DeviceList.h"
30
#include "MessageBox.h"
35
#include "guiUpdate.h"
40
DeviceList::DeviceList(CdDevice::DeviceType filterType)
44
filterType_ = filterType;
46
listModel_ = Gtk::ListStore::create(listColumns_);
47
list_.set_model(listModel_);
48
list_.append_column(_("Vendor"), listColumns_.vendor);
49
list_.append_column(_("Model"), listColumns_.model);
50
list_.append_column(_("Status"), listColumns_.status);
52
Gtk::VBox *contents = new Gtk::VBox;
53
contents->set_spacing(10);
55
// available device list
56
Gtk::HBox *listHBox = new Gtk::HBox;
57
Gtk::VBox *listVBox = new Gtk::VBox;
60
hbox->pack_start(list_, TRUE, TRUE);
62
Gtk::Adjustment *adjust = new Gtk::Adjustment(0.0, 0.0, 0.0);
64
Gtk::VScrollbar *scrollBar = new Gtk::VScrollbar(*adjust);
65
hbox->pack_start(*scrollBar, FALSE, FALSE);
67
list_.set_vadjustment(*adjust);
69
listHBox->pack_start(*hbox, TRUE, TRUE, 5);
70
listVBox->pack_start(*listHBox, TRUE, TRUE, 5);
72
switch (filterType_) {
73
case CdDevice::CD_ROM:
74
set_label(_(" Available Reader Devices "));
77
set_label(_(" Available Recorder Devices "));
80
set_label(_(" Available Recorder (RW) Devices "));
87
std::string DeviceList::selection()
89
Gtk::TreeIter i = list_.get_selection()->get_selected();
92
return ((std::string)((*i)[listColumns_.dev])).c_str();
97
void DeviceList::appendTableEntry(CdDevice *dev)
99
Gtk::TreeIter newiter = listModel_->append();
100
Gtk::TreeModel::Row row = *newiter;
101
row[listColumns_.dev] = dev->dev();
102
row[listColumns_.vendor] = dev->vendor();
103
row[listColumns_.model] = dev->product();
104
row[listColumns_.status] = CdDevice::status2string(dev->status());
106
if (dev->status() == CdDevice::DEV_READY)
107
list_.get_selection()->select(newiter);
110
void DeviceList::import()
117
for (drun = CdDevice::first(); drun != NULL; drun = CdDevice::next(drun)) {
118
switch (filterType_) {
119
case CdDevice::CD_ROM:
120
if (drun->driverId() > 0 &&
121
(drun->deviceType() == CdDevice::CD_ROM ||
122
drun->deviceType() == CdDevice::CD_R ||
123
drun->deviceType() == CdDevice::CD_RW)) {
124
appendTableEntry(drun);
128
if (drun->driverId() > 0 &&
129
(drun->deviceType() == CdDevice::CD_R ||
130
drun->deviceType() == CdDevice::CD_RW)) {
131
appendTableEntry(drun);
134
case CdDevice::CD_RW:
135
if (drun->driverId() > 0 &&
136
(drun->deviceType() == CdDevice::CD_RW)) {
137
appendTableEntry(drun);
143
if (listModel_->children().size() > 0) {
144
list_.columns_autosize();
145
list_.get_selection()->select(Gtk::TreeModel::Path((unsigned)1));
149
void DeviceList::importStatus()
154
Gtk::TreeNodeChildren ch = listModel_->children();
155
for (int i = 0; i < ch.size(); i++) {
156
Gtk::TreeRow row = ch[i];
157
data = row[listColumns_.dev];
159
if (cddev = CdDevice::find(data.c_str())) {
160
if (cddev->status() == CdDevice::DEV_READY)
161
list_.get_column(i)->set_clickable(true);
163
list_.get_column(i)->set_clickable(false);
165
row[listColumns_.status] = CdDevice::status2string(cddev->status());
169
list_.columns_autosize();
172
void DeviceList::selectOne()
174
if (list_.get_selection()->count_selected_rows() > 0)
177
for (int i = 0; i < listModel_->children().size(); i++) {
178
list_.get_selection()->select(Gtk::TreePath((unsigned)1, i));
179
if (list_.get_selection()->count_selected_rows() > 0)
184
void DeviceList::selectOneBut(const char *targetData)
189
if (list_.get_selection()->count_selected_rows() == 0) {
191
Gtk::TreeNodeChildren ch = listModel_->children();
193
for (int i = 0; i < ch.size(); i++) {
195
std::string sourceData = (ch[i])[listColumns_.dev];
197
if (sourceData != targetData) {
198
list_.get_selection()->select(ch[i]);
203
if (list_.get_selection()->count_selected_rows() == 0) {