1 /* Copyright 2009 Yorba Foundation
3 * This software is licensed under the GNU Lesser General Public License
4 * (version 2.1 or later). See the COPYING file in this distribution.
9 public interface MultiFileProgressInterface : Object {
10 public signal void fraction_updated(double d);
11 public signal void file_updated(string filename, int index);
12 public signal void done();
14 public abstract void cancel();
15 public abstract void complete();
18 public class MultiFileProgress : Gtk.Window {
19 Gtk.ProgressBar progress_bar;
21 Gtk.Label number_label;
22 Gtk.Button cancel_button;
26 MultiFileProgressInterface provider_interface;
30 public MultiFileProgress(Gtk.Window parent, int num_files,
31 string dialog_title, MultiFileProgressInterface provider) {
32 this.num_files = num_files;
34 file_label = new Gtk.Label("");
35 number_label = new Gtk.Label("");
36 progress_bar = new Gtk.ProgressBar();
38 Gtk.VBox vbox = new Gtk.VBox(true, 0);
40 vbox.pack_start(number_label, false, false, 0);
41 vbox.pack_start(file_label, false, false, 0);
42 vbox.pack_start(progress_bar, false, false, 0);
44 Gtk.HButtonBox button_area = new Gtk.HButtonBox();
45 button_area.set("layout-style", Gtk.ButtonBoxStyle.CENTER);
47 cancel_button = new Gtk.Button.from_stock(Gtk.STOCK_CANCEL);
48 cancel_button.clicked.connect(on_cancel_clicked);
50 button_area.add(cancel_button);
52 vbox.pack_start(button_area, false, false, 0);
55 set_transient_for(parent);
56 set_title(dialog_title);
57 this.dialog_title = dialog_title;
59 provider_interface = provider;
61 provider_interface.fraction_updated.connect(on_fraction_updated);
62 provider_interface.file_updated.connect(on_file_updated);
63 provider_interface.done.connect(on_done);
67 emit(this, Facility.SIGNAL_HANDLERS, Level.INFO, "on_done");
71 void on_cancel_clicked() {
72 emit(this, Facility.SIGNAL_HANDLERS, Level.INFO, "on_cancel_clicked");
77 emit(this, Facility.SIGNAL_HANDLERS, Level.INFO, "on_destroy");
78 if (progress_bar.get_fraction() < 1.0)
79 provider_interface.cancel();
81 provider_interface.complete();
84 void on_fraction_updated(double d) {
85 emit(this, Facility.SIGNAL_HANDLERS, Level.INFO, "on_fraction_updated");
92 destroy.connect(on_destroy);
97 progress_bar.set_fraction(d);
99 if (progress_bar.get_fraction() == 1.0)
107 void on_file_updated(string filename, int index) {
108 emit(this, Facility.SIGNAL_HANDLERS, Level.INFO, "on_file_updated");
109 number_label.set_text("%sing %d of %d".printf(dialog_title, index + 1, num_files));
110 file_label.set_text("%s".printf(filename));