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 
25 #include <gtkmm.h>
26 #include <gnome.h>
27 
28 #include "RecordTocSource.h"
29 #include "MessageBox.h"
30 #include "xcdrdao.h"
31 #include "Settings.h"
32 
33 #include "CdDevice.h"
34 #include "guiUpdate.h"
35 #include "TocEdit.h"
36 
37 #include "DeviceList.h"
38 
39 #include "util.h"
40 
RecordTocSource(TocEdit * tocEdit)41 RecordTocSource::RecordTocSource(TocEdit *tocEdit)
42 {
43   Gtk::Table *table;
44   Gtk::Label *label;
45 
46   active_ = false;
47   tocEdit_ = tocEdit;
48 
49   // device settings
50   Gtk::Frame *infoFrame = manage(new Gtk::Frame(_(" Project Information ")));
51 
52   table = manage(new Gtk::Table(5, 2, FALSE));
53   table->set_row_spacings(5);
54   table->set_col_spacings(5);
55   table->set_border_width(10);
56 
57   label = manage(new Gtk::Label(_("Project name: "), 1));
58   table->attach(*label, 0, 1, 0, 1);
59   table->attach(projectLabel_, 1, 2, 0, 1);
60 
61   label = manage(new Gtk::Label(_("Toc Type: "), 1));
62   table->attach(*label, 0, 1, 1, 2);
63   table->attach(tocTypeLabel_, 1, 2, 1, 2);
64 
65   label = manage(new Gtk::Label(_("Tracks: "), 1));
66   table->attach(*label, 0, 1, 2, 3);
67   table->attach(nofTracksLabel_, 1, 2, 2, 3);
68 
69   label = manage(new Gtk::Label(_("Length: "), 1));
70   table->attach(*label, 0, 1, 3, 4);
71   table->attach(tocLengthLabel_, 1, 2, 3, 4);
72 
73   infoFrame->add(*table);
74   pack_start(*infoFrame, Gtk::PACK_SHRINK);
75 }
76 
start()77 void RecordTocSource::start()
78 {
79   active_ = true;
80   update(UPD_ALL);
81   show_all();
82 }
83 
stop()84 void RecordTocSource::stop()
85 {
86   if (active_) {
87     hide();
88     active_ = false;
89   }
90 }
91 
update(unsigned long level)92 void RecordTocSource::update(unsigned long level)
93 {
94   update(level, tocEdit_);
95 }
96 
update(unsigned long level,TocEdit * tedit)97 void RecordTocSource::update(unsigned long level, TocEdit *tedit)
98 {
99   if (!active_)
100     return;
101 
102   if (tocEdit_ != tedit) {
103     level = UPD_ALL;
104     tocEdit_ = tedit;
105   }
106 
107   if (tocEdit_ == NULL) {
108     projectLabel_.set_text("");
109     tocTypeLabel_.set_text("");
110     nofTracksLabel_.set_text("");
111     tocLengthLabel_.set_text("");
112   }
113   else {
114     if (level & UPD_TOC_DATA) {
115       char label[256];
116       char buf[50];
117       const Toc *toc = tocEdit_->toc();
118 
119       projectLabel_.set_text(tocEdit_->filename());
120 
121       tocTypeLabel_.set_text(toc->tocType2String(toc->tocType()));
122 
123       sprintf(label, "%d", toc->nofTracks());
124       nofTracksLabel_.set_text(label);
125 
126       sprintf(buf, "%d:%02d:%02d", toc->length().min(),
127 	      toc->length().sec(), toc->length().frac());
128       tocLengthLabel_.set_text(buf);
129     }
130   }
131 }
132