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.
27
#include "ProgressDialog.h"
28
#include "MessageBox.h"
30
#include "guiUpdate.h"
35
ProgressDialog::ProgressDialog(ProgressDialogPool *father)
39
Gtk::VBox *contents = manage(new Gtk::VBox);
41
Gtk::Alignment *align;
48
contents->set_spacing(5);
50
statusMsg_ = manage(new Gtk::Label());
51
trackProgress_ = manage(new Gtk::ProgressBar);
52
totalProgress_ = manage(new Gtk::ProgressBar);
53
bufferFillRate_ = manage(new Gtk::ProgressBar);
54
writerFillRate_ = manage(new Gtk::ProgressBar);
55
tocName_ = manage(new Gtk::Label);
57
hbox = manage(new Gtk::HBox);
58
label = manage(new Gtk::Label(_("Project: ")));
59
hbox->pack_start(*label, Gtk::PACK_SHRINK);
60
hbox->pack_start(*tocName_, Gtk::PACK_SHRINK);
61
contents->pack_start(*hbox, Gtk::PACK_SHRINK);
63
hbox = manage(new Gtk::HBox);
64
hbox->pack_start(*statusMsg_, Gtk::PACK_SHRINK);
65
contents->pack_start(*hbox, Gtk::PACK_SHRINK);
67
hbox = manage(new Gtk::HBox(true, true));
68
label = manage(new Gtk::Label(_("Elapsed Time: "), 1));
69
hbox->pack_start(*label, Gtk::PACK_SHRINK);
70
currentTime_ = manage(new Gtk::Label());
71
hbox->pack_start(*currentTime_, Gtk::PACK_SHRINK);
72
label = manage(new Gtk::Label(_("Remaining Time: "), 1));
73
hbox->pack_start(*label, Gtk::PACK_SHRINK);
74
remainingTime_ = manage(new Gtk::Label("", 0));
75
hbox->pack_start(*remainingTime_, Gtk::PACK_SHRINK);
76
contents->pack_start(*hbox, Gtk::PACK_SHRINK);
78
table = manage(new Gtk::Table(4, 2, false));
79
table->set_row_spacings(5);
80
table->set_col_spacings(5);
81
contents->pack_start(*table, Gtk::PACK_SHRINK);
83
trackLabel_ = manage(new Gtk::Label(_("Track:")));
84
align = manage(new Gtk::Alignment(1.0, 0.5, 0.0, 0.0));
85
align->add(*trackLabel_);
86
table->attach(*align, 0, 1, 0, 1, Gtk::FILL);
88
hbox = manage(new Gtk::HBox);
89
hbox->pack_start(*trackProgress_);
90
table->attach(*hbox, 1, 2, 0, 1);
92
label = manage(new Gtk::Label(_("Total:")));
93
align = manage(new Gtk::Alignment(1.0, 0.5, 0.0, 0.0));
95
table->attach(*align, 0, 1, 1, 2, Gtk::FILL);
97
hbox = manage(new Gtk::HBox);
98
hbox->pack_start(*totalProgress_);
99
table->attach(*hbox, 1, 2, 1, 2);
101
bufferFillRateLabel_ = manage(new Gtk::Label(_("Input Buffer:")));
102
align = manage(new Gtk::Alignment(1.0, 0.5, 0.0, 0.0));
103
align->add(*bufferFillRateLabel_);
104
table->attach(*align, 0, 1, 2, 3, Gtk::FILL);
106
hbox = manage(new Gtk::HBox);
107
hbox->pack_start(*bufferFillRate_);
108
table->attach(*hbox, 1, 2, 2, 3);
110
writerFillRateLabel_ = manage(new Gtk::Label(_("Write Buffer:")));
111
table->attach(*writerFillRateLabel_, 0, 1, 3, 4, Gtk::FILL);
112
table->attach(*writerFillRate_, 1, 2, 3, 4);
114
hbox = manage(new Gtk::HBox);
115
hbox->pack_start(*contents, true, true, 10);
116
get_vbox()->pack_start(*hbox, false, false, 10);
118
Gtk::HButtonBox *bbox = manage(new Gtk::HButtonBox(Gtk::BUTTONBOX_SPREAD));
120
cancelButton_ = manage(new Gtk::Button(Gtk::StockID(Gtk::Stock::CANCEL)));
121
bbox->pack_start(*cancelButton_);
123
closeButton_ = manage(new Gtk::Button(Gtk::StockID(Gtk::Stock::CLOSE)));
124
bbox->pack_start(*closeButton_);
126
actCloseButtonLabel_ = 2;
128
cancelButton_->signal_clicked().
129
connect(SigC::slot(*this, &ProgressDialog::closeAction));
130
closeButton_->signal_clicked().
131
connect(SigC::slot(*this, &ProgressDialog::closeAction));
133
get_action_area()->pack_start(*bbox);
134
set_size_request(400, -1);
138
ProgressDialog::~ProgressDialog()
142
void ProgressDialog::start(CdDevice *device, const char *tocFileName)
159
Glib::signal_timeout().connect(slot(*this, &ProgressDialog::time), 1000);
161
statusMsg_->set_text(_("Initializing..."));
162
tocName_->set_text(tocFileName);
164
setCloseButtonLabel(1);
165
cancelButton_->set_sensitive(true);
167
s = device->vendor();
169
s += device->product();
176
void ProgressDialog::stop()
185
bool ProgressDialog::on_delete_event(GdkEventAny*)
188
poolFather_->stop(this);
193
void ProgressDialog::closeAction()
196
poolFather_->stop(this);
200
switch (device_->action()) {
201
case CdDevice::A_RECORD:
203
Ask2Box msg(this, _("Abort Recording"), 0, 2,
204
_("Abort recording process?"), NULL);
206
if (msg.run() == 1 && device_ != NULL) {
207
cancelButton_->set_sensitive(false);
208
device_->abortDaoRecording();
213
case CdDevice::A_READ:
215
Ask2Box msg(this, _("Abort Reading"), 0, 2, _("Abort reading process?"),
218
if (msg.run() == 1 && device_ != NULL) {
219
cancelButton_->set_sensitive(false);
220
device_->abortDaoReading();
225
case CdDevice::A_DUPLICATE:
227
Ask2Box msg(this, _("Abort Process"), 0, 2,
228
_("Abort duplicating process?"), NULL);
230
if (msg.run() == 1 && device_ != NULL) {
231
cancelButton_->set_sensitive(false);
232
device_->abortDaoDuplication();
237
case CdDevice::A_BLANK:
239
Ask2Box msg(this, _("Abort Process"), 0, 2, _("Abort blanking process?"),
242
if (msg.run() == 1 && device_ != NULL) {
243
cancelButton_->set_sensitive(false);
244
device_->abortBlank();
252
void ProgressDialog::clear()
257
actTrackProgress_ = 0;
258
actTotalProgress_ = 0;
262
gettimeofday(&time_, NULL);
263
currentTime_->set_text("0:00:00");
264
remainingTime_->set_text("");
265
leadTimeFilled_ = false;
266
statusMsg_->set_text("");
267
trackProgress_->set_fraction(0.0);
268
totalProgress_->set_fraction(0.0);
269
bufferFillRate_->set_fraction(0.0);
270
writerFillRate_->set_fraction(0.0);
275
void ProgressDialog::update(unsigned long level)
287
if (!active_ || device_ == NULL)
294
if ((level & UPD_PROGRESS_STATUS) && device_->progressStatusChanged()) {
295
device_->progress(&status, &totalTracks, &track, &trackProgress,
296
&totalProgress, &bufferFill, &writerFill);
298
if (status != actStatus_ || track != actTrack_) {
303
case PGSMSG_RCD_ANALYZING:
306
s = _("Analyzing track ");
307
sprintf(buf, "%d of %d", track, totalTracks);
310
statusMsg_->set_text(s);
313
case PGSMSG_RCD_EXTRACTING:
316
s = _("Extracting ");
317
sprintf(buf, "%d", totalTracks);
319
s += _(" tracks...");
321
statusMsg_->set_text(s);
324
case PGSMSG_WCD_LEADIN:
325
statusMsg_->set_text(_("Writing lead-in..."));
328
case PGSMSG_WCD_DATA:
331
s = _("Writing track ");
332
sprintf(buf, "%d of %d", track, totalTracks);
335
statusMsg_->set_text(s);
338
case PGSMSG_WCD_LEADOUT:
339
statusMsg_->set_text(_("Writing lead-out..."));
343
statusMsg_->set_text(_("Blanking..."));
349
if (trackProgress != actTrackProgress_) {
350
actTrackProgress_ = trackProgress;
351
if (trackProgress <= 1000)
352
trackProgress_->set_fraction(trackProgress / 1000.0);
355
if (totalProgress != actTotalProgress_) {
356
if (actTotalProgress_ == 0)
357
gettimeofday(&time_, 0);
358
actTotalProgress_ = totalProgress;
359
if (totalProgress <= 1000)
360
totalProgress_->set_fraction(totalProgress / 1000.0);
363
if (bufferFill != actBufferFill_) {
364
actBufferFill_ = bufferFill;
365
if (bufferFill <= 1000)
366
bufferFillRate_->set_fraction(bufferFill / 100.0);
369
if (writerFill != actWriterFill_) {
370
actWriterFill_ = writerFill;
371
if (writerFill <= 1000)
372
writerFillRate_->set_fraction(writerFill / 100.0);
376
switch (device_->action()) {
377
case CdDevice::A_RECORD:
378
if (device_->status() != CdDevice::DEV_RECORDING) {
379
switch (device_->exitStatus()) {
381
statusMsg_->set_text(_("Recording finished successfully."));
385
statusMsg_->set_text(_("Cannot execute cdrdao. Please check "
390
statusMsg_->set_text(_("Recording aborted with error."));
396
setCloseButtonLabel(2);
400
case CdDevice::A_READ:
401
if (device_->status() != CdDevice::DEV_READING) {
402
switch (device_->exitStatus()) {
404
statusMsg_->set_text(_("Reading finished successfully."));
408
statusMsg_->set_text(_("Cannot execute cdrdao. Please check "
413
statusMsg_->set_text(_("Reading aborted."));
419
setCloseButtonLabel(2);
424
case CdDevice::A_DUPLICATE:
425
if (device_->status() != CdDevice::DEV_RECORDING) {
426
switch (device_->exitStatus()) {
428
statusMsg_->set_text(_("CD copying finished successfully."));
432
statusMsg_->set_text(_("Cannot execute cdrdao. Please check "
437
statusMsg_->set_text(_("CD copying aborted with error."));
443
setCloseButtonLabel(2);
448
case CdDevice::A_BLANK:
449
if (device_->status() != CdDevice::DEV_BLANKING) {
450
switch (device_->exitStatus()) {
452
statusMsg_->set_text(_("Blanking finished successfully."));
456
statusMsg_->set_text(_("Cannot execute cdrdao. Please check "
461
statusMsg_->set_text(_("Blanking aborted with error."));
467
setCloseButtonLabel(2);
473
statusMsg_->set_text(_("Unknow device action!"));
478
// Sets label of close button.
479
// l: 1: 'abort' --> CANCEL gnome stock button (i18n)
480
// 2: 'dismiss' --> CLOSE gnome stock button (i18n)
481
void ProgressDialog::setCloseButtonLabel(int l)
483
if (actCloseButtonLabel_ == l)
488
closeButton_->hide();
489
cancelButton_->show();
492
cancelButton_->hide();
493
closeButton_->show();
497
actCloseButtonLabel_ = l;
500
bool ProgressDialog::time()
503
struct timeval timenow;
504
long time, time_remain, hours, mins, secs;
506
gettimeofday(&timenow, NULL);
508
time = timenow.tv_sec - time_.tv_sec;
511
mins = (time - (hours * 3600)) / 60;
512
secs = time - ((hours * 3600) + (mins * 60));
514
sprintf(buf, "%ld:%02ld:%02ld", hours, mins, secs);
515
currentTime_->set_text(buf);
517
if (actTotalProgress_ > 10)
521
gfloat aux1, aux2, aux3;
523
if (!leadTimeFilled_)
526
leadTimeFilled_ = true;
530
(((double)time / ((double)actTotalProgress_ / 1000.0)) + 0.5);
532
if (time_remain < 0) time_remain = 0;
534
hours = time_remain / 3600;
535
mins = (time_remain - (hours * 3600)) / 60;
536
secs = time_remain - ((hours * 3600) + (mins * 60));
538
sprintf(buf, "%ld:%02ld:%02ld", hours, mins, secs);
539
remainingTime_->set_text(buf);
548
void ProgressDialog::needBufferProgress(bool visible)
551
bufferFillRate_->show();
552
bufferFillRateLabel_->show();
553
writerFillRate_->show();
554
writerFillRateLabel_->show();
556
bufferFillRate_->hide();
557
bufferFillRateLabel_->hide();
558
writerFillRate_->hide();
559
writerFillRateLabel_->hide();
563
void ProgressDialog::needTrackProgress(bool visible)
566
trackProgress_->show();
569
trackProgress_->hide();
575
ProgressDialogPool::ProgressDialogPool()
577
activeDialogs_ = NULL;
581
ProgressDialogPool::~ProgressDialogPool()
585
void ProgressDialogPool::update(unsigned long status)
589
for (run = activeDialogs_; run != NULL; run = run->poolNext_)
593
ProgressDialog *ProgressDialogPool::start(CdDevice *device,
594
const char *tocFileName,
595
bool showBuffer, bool showTrack)
597
ProgressDialog *dialog;
600
dialog = new ProgressDialog(this);
604
pool_ = pool_->poolNext_;
607
dialog->poolNext_ = activeDialogs_;
608
activeDialogs_ = dialog;
610
dialog->needBufferProgress(showBuffer);
611
dialog->needTrackProgress(showTrack);
613
dialog->start(device, tocFileName);
618
ProgressDialog *ProgressDialogPool::start(Gtk::Window& parent,
620
const char *tocFileName,
621
bool showBuffer, bool showTrack)
623
ProgressDialog* dialog = start(device, tocFileName, showBuffer, showTrack);
624
dialog->set_transient_for(parent);
628
void ProgressDialogPool::stop(ProgressDialog *dialog)
630
ProgressDialog *run, *pred;
632
for (pred = NULL, run = activeDialogs_; run != NULL;
633
pred = run, run = run->poolNext_) {
644
activeDialogs_ = activeDialogs_->poolNext_;
646
pred->poolNext_ = run->poolNext_;
648
dialog->poolNext_ = pool_;