[gnome-chess/chess-telepathy-networking-support-664946-rebase: 6/64] [Chess Screen] UI for prompting robot installation and related control functions
- From: Chandni Verma <vchandni src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess/chess-telepathy-networking-support-664946-rebase: 6/64] [Chess Screen] UI for prompting robot installation and related control functions
- Date: Sun, 23 Dec 2012 03:39:07 +0000 (UTC)
commit 473d7fd5c43c7bed38a3efefe3431714988d23a8
Author: Chandni Verma <chandniverma2112 gmail com>
Date: Fri Apr 27 19:41:03 2012 +0530
[Chess Screen] UI for prompting robot installation and related control functions
data/gnome-chess.ui | 62 ++++++++++++++++++++++++++++++++++++++
src/gnome-chess.vala | 81 +++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 136 insertions(+), 7 deletions(-)
---
diff --git a/data/gnome-chess.ui b/data/gnome-chess.ui
index 150b031..6bb6232 100644
--- a/data/gnome-chess.ui
+++ b/data/gnome-chess.ui
@@ -644,6 +644,7 @@
<property name="margin_bottom">10</property>
<property name="row_spacing">12</property>
<property name="column_homogeneous">True</property>
+ <property name="n_rows">4</property>
<child>
<object class="GtkLabel" id="label_choice_of_robot">
<property name="visible">True</property>
@@ -705,6 +706,67 @@
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <object class="GtkGrid" id="grid_installable_robots">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="row_spacing">12</property>
+ <property name="column_spacing">6</property>
+ <property name="column_homogeneous">True</property>
+ <property name="n_rows">2</property>
+ <child>
+ <object class="GtkLabel" id="label_install_robots">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="hexpand">True</property>
+ <property name="label" translatable="yes"><information on supporte robots></property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">3</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_preferences_back">
+ <property name="label" translatable="yes">_Back</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="margin_top">20</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="preferences_back_clicked_cb" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ <property name="width">3</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="left_attach">1</property>
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index debe061..8388c77 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -40,6 +40,8 @@ public class Application : Gtk.Application
private Gtk.TreeView treeview_robots;
private Gtk.ListStore robot_list_model;
private Gtk.Widget done_button;
+ private Gtk.Widget grid_installable_robots;
+ private Gtk.Label label_install_robots;
/* Chess game screen widgets */
private Gtk.Widget game_vbox;
@@ -94,6 +96,39 @@ public class Application : Gtk.Application
this.game_file = game_file;
}
+ private StringBuilder get_supported_engines (string filename)
+ {
+ var file = new KeyFile ();
+ StringBuilder names = new StringBuilder ();
+
+ debug ("Loading AI names");
+ try
+ {
+ file.load_from_file (filename, KeyFileFlags.NONE);
+ }
+ catch (KeyFileError e)
+ {
+ warning ("Failed to load AI names: %s", e.message);
+ return names;
+ }
+ catch (FileError e)
+ {
+ warning ("Failed to load AI names: %s", e.message);
+ return names;
+ }
+
+ foreach (string name in file.get_groups ())
+ {
+ if (name != null)
+ {
+ names.append (name);
+ names.append_c ('\n');
+ }
+ }
+
+ return names;
+ }
+
public override void startup ()
{
base.startup ();
@@ -146,6 +181,8 @@ public class Application : Gtk.Application
treeview_robots = (Gtk.TreeView) builder.get_object ("treeview_robots");
robot_list_model = (Gtk.ListStore) treeview_robots.model;
done_button = (Gtk.Widget) builder.get_object ("button_preferences_done");
+ grid_installable_robots = (Gtk.Widget) builder.get_object ("grid_installable_robots");
+ label_install_robots = (Gtk.Label) builder.get_object ("label_install_robots");
game_vbox = (Gtk.Widget) builder.get_object ("game_vbox");
save_menu = (Gtk.Widget) builder.get_object ("menu_save_item");
@@ -200,16 +237,23 @@ public class Application : Gtk.Application
settings.changed.connect (settings_changed_cb);
settings_changed_cb (settings, "show-3d");
- ai_profiles = load_ai_profiles (Path.build_filename (PKGDATADIR, "engines.conf", null));
+ string engines_file = Path.build_filename (PKGDATADIR, "engines.conf", null);
+ ai_profiles = load_ai_profiles (engines_file);
+
foreach (var profile in ai_profiles)
message ("Detected AI profile %s in %s", profile.name, profile.path);
if (ai_profiles == null)
{
- /* TODO: We may optionally allow one to install compatible AI
- * engines using something like Packagekit, here or elsewhere */
togglebutton_robot.hide ();
show_robot_opponent_widgets (false);
+
+ StringBuilder engine_names = get_supported_engines (engines_file);
+ engine_names.prepend ("No robot is currently installed.\n" +
+ "Here is a list of suported robots. Install atleast one for " +
+ "advanced options.\n\n");
+
+ label_install_robots.set_label (engine_names.str);
}
else
{
@@ -258,7 +302,6 @@ public class Application : Gtk.Application
}
}
- window.set_default_size (settings.get_int ("width"), settings.get_int ("height"));
if (settings.get_boolean ("fullscreen"))
window.fullscreen ();
else if (settings.get_boolean ("maximized"))
@@ -1158,6 +1201,22 @@ public class Application : Gtk.Application
radioaction_black.activate ();
}
+ private void show_robot_installation_choice (bool install)
+ {
+ if (install)
+ {
+ treeview_robots.hide ();
+ done_button.hide ();
+ grid_installable_robots.show ();
+ }
+ else
+ {
+ treeview_robots.show ();
+ done_button.show ();
+ grid_installable_robots.hide ();
+ }
+ }
+
private void show_preferences ()
{
game_vbox.hide ();
@@ -1174,6 +1233,9 @@ public class Application : Gtk.Application
if (((Gtk.TreeModel)robot_list_model).iter_n_children (null) != 0)
{
Gtk.TreeIter iter;
+
+ show_robot_installation_choice (false);
+
for (bool valid_iter = robot_list_model.get_iter_first (out iter);
valid_iter;
valid_iter = robot_list_model.iter_next (ref iter))
@@ -1188,12 +1250,11 @@ public class Application : Gtk.Application
}
break;
}
-
- done_button.show ();
}
else
{
- /* TODO: Present an option to install chess engines */
+ /* Present an option to install chess engines */
+ show_robot_installation_choice (true);
}
}
@@ -1305,6 +1366,12 @@ public class Application : Gtk.Application
show_preferences ();
}
+ [CCode (cname = "G_MODULE_EXPORT preferences_back_clicked_cb", instance_pos = -1)]
+ public void preferences_back_clicked_cb (Gtk.Button button)
+ {
+ show_game_options ();
+ }
+
[CCode (cname = "G_MODULE_EXPORT game_options_go_back_clicked_cb", instance_pos = -1)]
public void game_options_go_back_clicked_cb (Gtk.Button button)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]