ardour
interthread_progress_window.cc
Go to the documentation of this file.
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"
24 #include "i18n.h"
25 
26 using namespace std;
27 using namespace Gtk;
28 
34  : ArdourDialog (t, true)
35  , _interthread_info (i)
36 {
37  _bar.set_orientation (Gtk::PROGRESS_LEFT_TO_RIGHT);
38 
39  set_border_width (12);
40  get_vbox()->set_spacing (6);
41 
42  get_vbox()->pack_start (_bar, false, false);
43 
44  Button* b = add_button (Stock::CANCEL, RESPONSE_CANCEL);
45  b->signal_clicked().connect (sigc::mem_fun (*this, &InterthreadProgressWindow::cancel_clicked));
46 
47  _cancel_label.set_text (c);
49 
50  set_default_size (200, 100);
51  show_all ();
52  hide ();
53 
54  Glib::signal_timeout().connect (sigc::mem_fun (*this, &InterthreadProgressWindow::update), 100);
55 }
56 
57 void
59 {
60  _interthread_info->cancel = true;
61 }
62 
63 bool
65 {
66  _bar.set_fraction (_interthread_info->progress);
68 }
69 
74 ImportProgressWindow::ImportProgressWindow (ARDOUR::ImportStatus* s, string const & t, string const & c)
75  : InterthreadProgressWindow (s, t, c)
76  , _import_status (s)
77 {
78  _label.set_alignment (0, 0.5);
79  _label.set_use_markup (true);
80 
81  get_vbox()->pack_start (_label, false, false);
82 
83  _label.show ();
84 }
85 
86 bool
88 {
89  _cancel_button.set_sensitive (!_import_status->freeze);
90  _label.set_markup ("<i>" + _import_status->doing_what + "</i>");
91 
92  /* use overall progress for the bar, rather than that for individual files */
94 
95  /* some of the code which sets up _import_status->current may briefly increment it too far
96  at the end of an import, so check for that to avoid a visual glitch
97  */
98  uint32_t c = _import_status->current;
99  if (c > _import_status->total) {
100  c = _import_status->total;
101  }
102 
103  _bar.set_text (string_compose (_("Importing file: %1 of %2"), c, _import_status->total));
104 
106 }
std::string doing_what
Definition: import_status.h:36
ARDOUR::InterThreadInfo * _interthread_info
InterthreadProgressWindow(ARDOUR::InterThreadInfo *, std::string const &, std::string const &)
Definition: ardour_ui.h:130
Definition: Beats.hpp:239
ARDOUR::ImportStatus * _import_status
volatile bool freeze
Definition: import_status.h:42
#define _(Text)
Definition: i18n.h:11
ImportProgressWindow(ARDOUR::ImportStatus *, std::string const &, std::string const &)
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208