~ubuntu-branches/ubuntu/utopic/cdrdao/utopic

« back to all changes in this revision

Viewing changes to xdao/DeviceList.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Suffield
  • Date: 2004-06-24 22:33:16 UTC
  • Revision ID: james.westby@ubuntu.com-20040624223316-534onzugaeeyq61j
Tags: upstream-1.1.9
ImportĀ upstreamĀ versionĀ 1.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  cdrdao - write audio CD-Rs in disc-at-once mode
 
2
 *
 
3
 *  Copyright (C) 1998-2002  Andreas Mueller <andreas@daneb.de>
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 */
 
19
 
 
20
#include <stdio.h>
 
21
#include <limits.h>
 
22
#include <math.h>
 
23
#include <assert.h>
 
24
#include <string>
 
25
 
 
26
#include <gtkmm.h>
 
27
#include <gnome.h>
 
28
 
 
29
#include "DeviceList.h"
 
30
#include "MessageBox.h"
 
31
#include "xcdrdao.h"
 
32
#include "Settings.h"
 
33
 
 
34
#include "CdDevice.h"
 
35
#include "guiUpdate.h"
 
36
#include "TocEdit.h"
 
37
 
 
38
#include "util.h"
 
39
 
 
40
DeviceList::DeviceList(CdDevice::DeviceType filterType)
 
41
{
 
42
  Gtk::HBox *hbox;
 
43
 
 
44
  filterType_ = filterType;
 
45
 
 
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);
 
51
 
 
52
  Gtk::VBox *contents = new Gtk::VBox;
 
53
  contents->set_spacing(10);
 
54
 
 
55
  // available device list
 
56
  Gtk::HBox *listHBox = new Gtk::HBox;
 
57
  Gtk::VBox *listVBox = new Gtk::VBox;
 
58
 
 
59
  hbox = new Gtk::HBox;
 
60
  hbox->pack_start(list_, TRUE, TRUE);
 
61
 
 
62
  Gtk::Adjustment *adjust = new Gtk::Adjustment(0.0, 0.0, 0.0);
 
63
 
 
64
  Gtk::VScrollbar *scrollBar = new Gtk::VScrollbar(*adjust);
 
65
  hbox->pack_start(*scrollBar, FALSE, FALSE);
 
66
 
 
67
  list_.set_vadjustment(*adjust);
 
68
 
 
69
  listHBox->pack_start(*hbox, TRUE, TRUE, 5);
 
70
  listVBox->pack_start(*listHBox, TRUE, TRUE, 5);
 
71
 
 
72
  switch (filterType_) {
 
73
  case CdDevice::CD_ROM:
 
74
    set_label(_(" Available Reader Devices "));
 
75
    break;
 
76
  case CdDevice::CD_R:
 
77
    set_label(_(" Available Recorder Devices "));
 
78
    break;
 
79
  case CdDevice::CD_RW:
 
80
    set_label(_(" Available Recorder (RW) Devices "));
 
81
    break;
 
82
  }
 
83
 
 
84
  add(*listVBox);
 
85
}
 
86
 
 
87
std::string DeviceList::selection()
 
88
{
 
89
  Gtk::TreeIter i = list_.get_selection()->get_selected();
 
90
 
 
91
  if (i) {
 
92
    return ((std::string)((*i)[listColumns_.dev])).c_str();
 
93
  } else
 
94
    return std::string();
 
95
}
 
96
 
 
97
void DeviceList::appendTableEntry(CdDevice *dev)
 
98
{
 
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());
 
105
 
 
106
  if (dev->status() == CdDevice::DEV_READY)
 
107
    list_.get_selection()->select(newiter);
 
108
}
 
109
 
 
110
void DeviceList::import()
 
111
{
 
112
  CdDevice *drun;
 
113
  unsigned int i;
 
114
 
 
115
  listModel_->clear();
 
116
 
 
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);
 
125
      }
 
126
      break;
 
127
    case CdDevice::CD_R:
 
128
      if (drun->driverId() > 0 &&
 
129
          (drun->deviceType() == CdDevice::CD_R ||
 
130
           drun->deviceType() == CdDevice::CD_RW)) {
 
131
        appendTableEntry(drun);
 
132
      }
 
133
      break;
 
134
    case CdDevice::CD_RW:
 
135
      if (drun->driverId() > 0 &&
 
136
          (drun->deviceType() == CdDevice::CD_RW)) {
 
137
        appendTableEntry(drun);
 
138
      }
 
139
      break;
 
140
    }
 
141
  }
 
142
 
 
143
  if (listModel_->children().size() > 0) {
 
144
    list_.columns_autosize();
 
145
    list_.get_selection()->select(Gtk::TreeModel::Path((unsigned)1));
 
146
  }
 
147
}
 
148
 
 
149
void DeviceList::importStatus()
 
150
{
 
151
  std::string data;
 
152
  CdDevice *cddev;
 
153
 
 
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];
 
158
 
 
159
    if (cddev = CdDevice::find(data.c_str())) {
 
160
      if (cddev->status() == CdDevice::DEV_READY)
 
161
        list_.get_column(i)->set_clickable(true);
 
162
      else
 
163
        list_.get_column(i)->set_clickable(false);
 
164
 
 
165
      row[listColumns_.status] = CdDevice::status2string(cddev->status());
 
166
    }
 
167
  }
 
168
 
 
169
  list_.columns_autosize();
 
170
}
 
171
 
 
172
void DeviceList::selectOne()
 
173
{
 
174
  if (list_.get_selection()->count_selected_rows() > 0)
 
175
    return;
 
176
 
 
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)
 
180
      break;
 
181
  }
 
182
}
 
183
 
 
184
void DeviceList::selectOneBut(const char *targetData)
 
185
{
 
186
  if (!targetData)
 
187
    return selectOne();
 
188
 
 
189
  if (list_.get_selection()->count_selected_rows() == 0) {
 
190
 
 
191
    Gtk::TreeNodeChildren ch = listModel_->children();
 
192
 
 
193
    for (int i = 0; i < ch.size(); i++) {
 
194
 
 
195
      std::string sourceData = (ch[i])[listColumns_.dev];
 
196
 
 
197
      if (sourceData != targetData) {
 
198
        list_.get_selection()->select(ch[i]);
 
199
        break;
 
200
      }
 
201
    }
 
202
 
 
203
    if (list_.get_selection()->count_selected_rows() == 0) {
 
204
      selectOne();
 
205
    }
 
206
  }
 
207
}