[gnome-games/wip/exalm/platform-preferences: 24/26] preferences-page-retro-platform: List cores



commit 0d433133bc08a0a99b6d15c17d14a6422a3b4639
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Thu Sep 27 15:49:47 2018 +0500

    preferences-page-retro-platform: List cores

 data/ui/preferences-page-retro-platform.ui  |  1 +
 src/ui/preferences-page-retro-platform.vala | 46 ++++++++++++++++++++++++-----
 2 files changed, 39 insertions(+), 8 deletions(-)
---
diff --git a/data/ui/preferences-page-retro-platform.ui b/data/ui/preferences-page-retro-platform.ui
index ae6c9a78..bd28d173 100644
--- a/data/ui/preferences-page-retro-platform.ui
+++ b/data/ui/preferences-page-retro-platform.ui
@@ -30,6 +30,7 @@
                           <object class="GtkListBox" id="core_list_box">
                             <property name="selection-mode">none</property>
                             <property name="visible">true</property>
+                            <signal name="row-activated" handler="core_list_box_row_activated"/>
                           </object>
                         </child>
                       </object>
diff --git a/src/ui/preferences-page-retro-platform.vala b/src/ui/preferences-page-retro-platform.vala
index 7ae2299e..4324fb91 100644
--- a/src/ui/preferences-page-retro-platform.vala
+++ b/src/ui/preferences-page-retro-platform.vala
@@ -18,6 +18,18 @@ private class Games.PreferencesPageRetroPlatform: Gtk.Bin, PreferencesPage {
        [GtkChild]
        private Gtk.ListBox core_list_box;
 
+       private Settings settings;
+
+       private string _current_core;
+       public string current_core {
+               get { return _current_core; }
+               set {
+                       _current_core = value;
+
+                       update_core_list ();
+               }
+       }
+
        private static Retro.CoreDescriptor[] core_descriptors;
 
        static construct {
@@ -32,6 +44,12 @@ private class Games.PreferencesPageRetroPlatform: Gtk.Bin, PreferencesPage {
                _title = platform.get_name ();
 
                build_core_list ();
+
+               var path = "/org/gnome/Games/platforms/%s/".printf (platform.get_id ());
+               settings = new Settings.with_path ("org.gnome.Games.platforms", path);
+
+               settings.bind ("libretro-core", this, "current-core",
+                              SettingsBindFlags.DEFAULT);
        }
 
        private void build_core_list () {
@@ -60,15 +78,27 @@ private class Games.PreferencesPageRetroPlatform: Gtk.Bin, PreferencesPage {
                }
        }
 
-       private void add_core_descriptor (Retro.CoreDescriptor core_descriptor) throws Error {
-               var name = core_descriptor.get_name ();
+       private void update_core_list () {
+               core_list_box.foreach ((item) => {
+                       var core_item = item as CoreItem;
+                       var core_descriptor = core_item.core_descriptor;
+                       var core_id = core_descriptor.get_id ();
+
+                       core_item.checkmark_visible = (core_id == current_core);
+               });
+       }
+
+       private void add_core_descriptor (Retro.CoreDescriptor core_descriptor) {
+               var item = new CoreItem (core_descriptor);
+               core_list_box.add (item);
+       }
+
+       [GtkCallback]
+       private void core_list_box_row_activated (Gtk.ListBoxRow row_item) {
+               var core_item = row_item as CoreItem;
 
-               var item = new CheckmarkItem (name);
-               var row = new Gtk.ListBoxRow ();
-               row.add (item);
-               core_list_box.add (row);
+               var core_descriptor = core_item.core_descriptor;
 
-               item.show ();
-               row.show ();
+               current_core = core_descriptor.get_id ();
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]