Separate interthread progress window out into its own class and HIG-ify it a bit...
[ardour.git] / gtk2_ardour / interthread_progress_window.cc
1 /*
2     Copyright (C) 2010 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <glibmm/main.h>
21 #include <gtkmm/stock.h>
22 #include "ardour/import_status.h"
23 #include "interthread_progress_window.h"
24
25 using namespace std;
26 using namespace Gtk;
27
28 /** @param i Status information.
29  *  @param t Window title.
30  *  @param c Label to use for Cancel button.
31  */
32 InterthreadProgressWindow::InterthreadProgressWindow (ARDOUR::InterThreadInfo* i, string const & t, string const & c)
33         : ArdourDialog (t, true)
34         , _interthread_info (i)
35 {
36         _bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
37
38         set_border_width (12);
39         get_vbox()->set_spacing (6);
40
41         get_vbox()->pack_start (_bar, false, false);
42
43         Button* b = add_button (Stock::CANCEL, RESPONSE_CANCEL);
44         b->signal_clicked().connect (sigc::mem_fun (*this, &InterthreadProgressWindow::cancel_clicked));
45
46         _cancel_label.set_text (c);
47         _cancel_button.add (_cancel_label);
48
49         set_default_size (200, 100);
50         show_all ();
51
52         Glib::signal_timeout().connect (sigc::mem_fun (*this, &InterthreadProgressWindow::update), 100);
53 }
54
55 void
56 InterthreadProgressWindow::cancel_clicked ()
57 {
58         _interthread_info->cancel = true;
59 }
60
61 bool
62 InterthreadProgressWindow::update ()
63 {
64         _bar.set_fraction (_interthread_info->progress);
65         return !(_interthread_info->done || _interthread_info->cancel);
66 }
67
68 /** @param i Status information.
69  *  @param t Window title.
70  *  @param c Label to use for Cancel button.
71  */
72 ImportProgressWindow::ImportProgressWindow (ARDOUR::ImportStatus* s, string const & t, string const & c)
73         : InterthreadProgressWindow (s, t, c)
74         , _import_status (s)
75 {
76         _label.set_alignment (0, 0.5);
77         _label.set_use_markup (true);
78
79         get_vbox()->pack_start (_label, false, false);
80
81         _label.show ();
82 }
83
84 bool
85 ImportProgressWindow::update ()
86 {
87         _cancel_button.set_sensitive (!_import_status->freeze);
88         _label.set_markup ("<i>" + _import_status->doing_what + "</i>");
89
90         /* use overall progress for the bar, rather than that for individual files */
91         _bar.set_fraction ((_import_status->current - 1 + _import_status->progress) / _import_status->total);
92         
93         return !(_import_status->done || _import_status->cancel);
94 }