1 //  Copyright (C) 2020 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 //  02110-1301, USA.
17 
18 #include <config.h>
19 
20 #include <sigc++/functors/mem_fun.h>
21 
22 #include "load-progress-window.h"
23 #include "builder-cache.h"
24 
LoadProgressWindow(Gtk::Window * w)25 LoadProgressWindow::LoadProgressWindow(Gtk::Window *w)
26 {
27   Glib::RefPtr<Gtk::Builder> xml =
28     BuilderCache::get("load-progress-window.ui");
29 
30   xml->get_widget("window", window);
31   xml->get_widget("progress_treeview", progress_treeview);
32   if (w)
33     window->set_transient_for(*w);
34 }
35 
run()36 int LoadProgressWindow::run()
37 {
38   window->set_modal ();
39   window->show_all();
40   progress_treeview->property_headers_visible () = false;
41   progress_liststore = Gtk::ListStore::create(progress_columns);
42   progress_treeview->set_model (progress_liststore);
43   row = *(progress_liststore->append());
44   auto cell = Gtk::manage (new Gtk::CellRendererProgress());
45   cell->property_text () = "";
46   int cols_count = progress_treeview->append_column ("progress", *cell);
47   auto pColumn = progress_treeview->get_column(cols_count -1);
48   if (pColumn)
49     pColumn->add_attribute(cell->property_value (), progress_columns.perc);
50   return 0;
51 }
52 
hide()53 void LoadProgressWindow::hide()
54 {
55   window->hide();
56 }
57 
tick_progress()58 void LoadProgressWindow::tick_progress ()
59 {
60   if (!progress_treeview)
61     return;
62   if (row[progress_columns.perc] < 98)
63     {
64       row[progress_columns.perc] = row[progress_columns.perc] + 3;
65       while (g_main_context_iteration(NULL, FALSE)); //doEvents
66     }
67 }
68 
finish_progress()69 void LoadProgressWindow::finish_progress ()
70 {
71   if (!progress_treeview)
72     return;
73   //finish off the progressbar
74   while (row[progress_columns.perc] < 100)
75     {
76       row[progress_columns.perc] = row[progress_columns.perc] + 1;
77       while (g_main_context_iteration(NULL, FALSE)); //doEvents
78       Glib::usleep (10000);
79     }
80   row[progress_columns.perc] = 100;
81   hide ();
82 }
83