Humble Bundle support
[GameHub.git] / src / ui / dialogs / GameInstallDialog.vala
blob6f291906d52d6907abe0382d39f1743be09ab791
1 using Gtk;
2 using GLib;
3 using Gee;
4 using GameHub.Utils;
6 using GameHub.Data;
7 using GameHub.Data.Sources.GOG;
8 using GameHub.Data.Sources.Humble;
10 namespace GameHub.UI.Dialogs
12 public class GameInstallDialog: Granite.MessageDialog
14 public signal void install(Game.Installer installer);
15 public signal void canceled();
17 private ListBox installers_list;
19 private bool is_finished = false;
21 public GameInstallDialog(Game game, ArrayList<Game.Installer> installers)
23 Object(transient_for: Windows.MainWindow.instance, deletable: false, resizable: false);
25 set_modal(true);
27 image_icon = Icon.new_for_string("go-down");
29 primary_text = game.name;
31 installers_list = new ListBox();
33 var sys_langs = Intl.get_language_names();
35 foreach(var installer in installers)
37 var row = new InstallerRow(installer);
38 installers_list.add(row);
40 if(installer is GOGGame.Installer && (installer as GOGGame.Installer).lang in sys_langs)
42 installers_list.select_row(row);
46 if(installers.size > 1)
48 secondary_text = _("Select game installer");
49 custom_bin.child = installers_list;
52 destroy.connect(() => { if(!is_finished) canceled(); });
54 response.connect((source, response_id) => {
55 switch(response_id)
57 case ResponseType.CANCEL:
58 destroy();
59 break;
61 case ResponseType.ACCEPT:
62 var installer = installers[0];
63 if(installers.size > 1)
65 var row = installers_list.get_selected_row() as InstallerRow;
66 installer = row.installer;
68 is_finished = true;
69 install(installer);
70 destroy();
71 break;
73 });
75 add_button(_("Cancel"), ResponseType.CANCEL);
76 var install_btn = add_button(_("Install"), ResponseType.ACCEPT);
77 install_btn.get_style_context().add_class(STYLE_CLASS_SUGGESTED_ACTION);
78 install_btn.grab_default();
80 show_all();
83 private class InstallerRow: ListBoxRow
85 public Game.Installer installer;
87 public InstallerRow(Game.Installer installer)
89 this.installer = installer;
91 var label = new Label(installer.name);
92 label.xpad = 16;
93 label.ypad = 4;
94 child = label;