Vkeybd: use ArdourWidgets for all GUI elements
[ardour.git] / gtk2_ardour / interthread_progress_window.cc
1 /*
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>
5  *
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.
10  *
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.
15  *
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.
19  */
20
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"
26 #include "pbd/i18n.h"
27
28 using namespace std;
29 using namespace Gtk;
30
31 /** @param i Status information.
32  *  @param t Window title.
33  *  @param c Label to use for Cancel button.
34  */
35 InterthreadProgressWindow::InterthreadProgressWindow (ARDOUR::InterThreadInfo* i, string const & t, string const & c)
36         : ArdourDialog (t, true)
37         , _interthread_info (i)
38 {
39         _interthread_info->cancel = false;
40
41         _bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
42
43         set_border_width (12);
44         get_vbox()->set_spacing (6);
45
46         get_vbox()->pack_start (_bar, false, false);
47
48         Button* b = add_button (Stock::CANCEL, RESPONSE_CANCEL);
49         b->signal_clicked().connect (sigc::mem_fun (*this, &InterthreadProgressWindow::cancel_clicked));
50
51         _cancel_label.set_text (c);
52         _cancel_button.add (_cancel_label);
53
54         set_default_size (200, 100);
55         show_all ();
56
57         Glib::signal_timeout().connect (sigc::mem_fun (*this, &InterthreadProgressWindow::update), 100);
58 }
59
60 void
61 InterthreadProgressWindow::on_hide ()
62 {
63         if (_interthread_info && !_interthread_info->done) {
64                 //catch user pressing 'esc' or WM close
65                 _interthread_info->cancel = true;
66         }
67 }
68
69 void
70 InterthreadProgressWindow::cancel_clicked ()
71 {
72         _interthread_info->cancel = true;
73 }
74
75 bool
76 InterthreadProgressWindow::update ()
77 {
78         _bar.set_fraction (_interthread_info->progress);
79         return !(_interthread_info->done || _interthread_info->cancel);
80 }
81
82 /** @param i Status information.
83  *  @param t Window title.
84  *  @param c Label to use for Cancel button.
85  */
86 ImportProgressWindow::ImportProgressWindow (ARDOUR::ImportStatus* s, string const & t, string const & c)
87         : InterthreadProgressWindow (s, t, c)
88         , _import_status (s)
89 {
90         _label.set_alignment (0, 0.5);
91         _label.set_use_markup (true);
92
93         get_vbox()->pack_start (_label, false, false);
94
95         _label.show ();
96 }
97
98 bool
99 ImportProgressWindow::update ()
100 {
101         _cancel_button.set_sensitive (!_import_status->freeze);
102         _label.set_markup ("<i>" + Gtkmm2ext::markup_escape_text (_import_status->doing_what) + "</i>");
103
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);
106
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
109         */
110         uint32_t c = _import_status->current;
111         if (c > _import_status->total) {
112                 c = _import_status->total;
113         }
114
115         _bar.set_text (string_compose (_("Importing file: %1 of %2"), c, _import_status->total));
116
117         return !(_import_status->all_done || _import_status->cancel);
118 }