1 /*
2  * Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef _ardour_gtk_simpple_progress_dialog_h_
20 #define _ardour_gtk_simpple_progress_dialog_h_
21 
22 #include <gtkmm/button.h>
23 #include <gtkmm/messagedialog.h>
24 #include <gtkmm/progressbar.h>
25 #include <gtkmm/stock.h>
26 
27 #include "ardour/types.h"
28 
29 class SimpleProgressDialog : public Gtk::MessageDialog
30 {
31 public:
SimpleProgressDialog(std::string title,const Glib::SignalProxy0<void>::SlotType & cancel)32 	SimpleProgressDialog (std::string title, const Glib::SignalProxy0< void >::SlotType & cancel)
33 		: MessageDialog (title, false, MESSAGE_OTHER, BUTTONS_NONE, true)
34 	{
35 		get_vbox()->set_size_request(400,-1);
36 		set_title (title);
37 		pbar = manage (new Gtk::ProgressBar());
38 		pbar->show();
39 		get_vbox()->pack_start (*pbar, PACK_SHRINK, 4);
40 
41 		Gtk::Button *cancel_button = add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
42 		cancel_button->signal_clicked().connect (cancel);
43 		cancel_button->show();
44 		get_vbox()->pack_start (*cancel_button, PACK_SHRINK);
45 	}
46 
update_progress(samplecnt_t c,samplecnt_t t)47 	void update_progress (samplecnt_t c, samplecnt_t t) {
48 		pbar->set_fraction ((float) c / (float) t);
49 		// see also ARDOUR_UI::gui_idle_handler();
50 		int timeout = 30;
51 		while (gtk_events_pending() && --timeout) {
52 			gtk_main_iteration ();
53 		}
54 	}
55 private:
56 	Gtk::ProgressBar *pbar;
57 };
58 #endif
59