2 * Copyright (C) 2010-2016 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2010 Carl Hetherington <carl@carlh.net>
4 * Copyright (C) 2015-2016 Robin Gareus <robin@gareus.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <glibmm/main.h>
22 #include <gtkmm/stock.h>
23 #include "gtkmm2ext/utils.h"
24 #include "ardour/import_status.h"
25 #include "interthread_progress_window.h"
31 /** @param i Status information.
32 * @param t Window title.
33 * @param c Label to use for Cancel button.
35 InterthreadProgressWindow::InterthreadProgressWindow (ARDOUR::InterThreadInfo* i, string const & t, string const & c)
36 : ArdourDialog (t, true)
37 , _interthread_info (i)
39 _interthread_info->cancel = false;
41 _bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
43 set_border_width (12);
44 get_vbox()->set_spacing (6);
46 get_vbox()->pack_start (_bar, false, false);
48 Button* b = add_button (Stock::CANCEL, RESPONSE_CANCEL);
49 b->signal_clicked().connect (sigc::mem_fun (*this, &InterthreadProgressWindow::cancel_clicked));
51 _cancel_label.set_text (c);
52 _cancel_button.add (_cancel_label);
54 set_default_size (200, 100);
57 Glib::signal_timeout().connect (sigc::mem_fun (*this, &InterthreadProgressWindow::update), 100);
61 InterthreadProgressWindow::on_hide ()
63 if (_interthread_info && !_interthread_info->done) {
64 //catch user pressing 'esc' or WM close
65 _interthread_info->cancel = true;
70 InterthreadProgressWindow::cancel_clicked ()
72 _interthread_info->cancel = true;
76 InterthreadProgressWindow::update ()
78 _bar.set_fraction (_interthread_info->progress);
79 return !(_interthread_info->done || _interthread_info->cancel);
82 /** @param i Status information.
83 * @param t Window title.
84 * @param c Label to use for Cancel button.
86 ImportProgressWindow::ImportProgressWindow (ARDOUR::ImportStatus* s, string const & t, string const & c)
87 : InterthreadProgressWindow (s, t, c)
90 _label.set_alignment (0, 0.5);
91 _label.set_use_markup (true);
93 get_vbox()->pack_start (_label, false, false);
99 ImportProgressWindow::update ()
101 _cancel_button.set_sensitive (!_import_status->freeze);
102 _label.set_markup ("<i>" + Gtkmm2ext::markup_escape_text (_import_status->doing_what) + "</i>");
104 /* use overall progress for the bar, rather than that for individual files */
105 _bar.set_fraction ((_import_status->current - 1 + _import_status->progress) / _import_status->total);
107 /* some of the code which sets up _import_status->current may briefly increment it too far
108 at the end of an import, so check for that to avoid a visual glitch
110 uint32_t c = _import_status->current;
111 if (c > _import_status->total) {
112 c = _import_status->total;
115 _bar.set_text (string_compose (_("Importing file: %1 of %2"), c, _import_status->total));
117 return !(_import_status->all_done || _import_status->cancel);