[gnome-games/wip/exalm/platform-preferences: 15/17] ui: Add platform rows
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/platform-preferences: 15/17] ui: Add platform rows
- Date: Wed, 20 Mar 2019 05:04:39 +0000 (UTC)
commit a8798e17f9d46157fdd3b4fb6cff47df341fcc0b
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Wed Mar 13 09:34:03 2019 +0500
ui: Add platform rows
Make PreferencesPagePlatformsGenericRow and PreferencesPagePlatformRetroRow
implement a common interface, this is a requirement for on_activated()
function.
data/gtk-style.css | 4 +
data/org.gnome.Games.gresource.xml | 2 +
data/ui/preferences-page-platforms-generic-row.ui | 16 +++
data/ui/preferences-page-platforms-retro-row.ui | 69 ++++++++++++
src/core/platform.vala | 2 +
src/dummy/dummy-platform.vala | 4 +
src/generic/generic-platform.vala | 4 +
src/meson.build | 3 +
src/retro/retro-platform.vala | 4 +
src/ui/preferences-page-platforms-generic-row.vala | 21 ++++
src/ui/preferences-page-platforms-retro-row.vala | 118 +++++++++++++++++++++
src/ui/preferences-page-platforms-row.vala | 5 +
12 files changed, 252 insertions(+)
---
diff --git a/data/gtk-style.css b/data/gtk-style.css
index 1d136531..bb5db57b 100644
--- a/data/gtk-style.css
+++ b/data/gtk-style.css
@@ -33,3 +33,7 @@ stacksidebar list {
.list-icon {
opacity: 0.7;
}
+
+.combo-list-box {
+ background: none;
+}
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 789498a1..f985c3f9 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -32,6 +32,8 @@
<file preprocess="xml-stripblanks">ui/media-selector.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page-controllers.ui</file>
+ <file preprocess="xml-stripblanks">ui/preferences-page-platforms-generic-row.ui</file>
+ <file preprocess="xml-stripblanks">ui/preferences-page-platforms-retro-row.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page-plugins.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page-plugins-item.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page-video.ui</file>
diff --git a/data/ui/preferences-page-platforms-generic-row.ui
b/data/ui/preferences-page-platforms-generic-row.ui
new file mode 100644
index 00000000..450b8af2
--- /dev/null
+++ b/data/ui/preferences-page-platforms-generic-row.ui
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.16 -->
+ <template class="GamesPreferencesPagePlatformsGenericRow" parent="GtkListBoxRow">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkLabel" id="title_label">
+ <property name="visible">True</property>
+ <property name="ellipsize">end</property>
+ <property name="halign">start</property>
+ <property name="hexpand">true</property>
+ <property name="margin">6</property>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/data/ui/preferences-page-platforms-retro-row.ui b/data/ui/preferences-page-platforms-retro-row.ui
new file mode 100644
index 00000000..2ff9cfc9
--- /dev/null
+++ b/data/ui/preferences-page-platforms-retro-row.ui
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.16 -->
+ <template class="GamesPreferencesPagePlatformsRetroRow" parent="GtkListBoxRow">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="margin">6</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="hexpand">true</property>
+ <child>
+ <object class="GtkLabel" id="name_label">
+ <property name="visible">True</property>
+ <property name="ellipsize">end</property>
+ <property name="halign">start</property>
+ <property name="hexpand">true</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="core_label">
+ <property name="visible">True</property>
+ <property name="ellipsize">end</property>
+ <property name="halign">start</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImage" id="dropdown_arrow">
+ <property name="visible">False</property>
+ <property name="icon-name">pan-down-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+ <object class="GtkPopover" id="details_popover">
+ <property name="visible">False</property>
+ <property name="relative-to">dropdown_arrow</property>
+ <property name="position">bottom</property>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="visible">True</property>
+ <property name="hscrollbar-policy">never</property>
+ <property name="max-content-height">400</property>
+ <property name="propagate_natural_height">True</property>
+ <child>
+ <object class="GtkListBox" id="list_box">
+ <property name="visible">True</property>
+ <property name="selection-mode">none</property>
+ <property name="margin">6</property>
+ <signal name="row-activated" handler="on_row_activated"/>
+ <style>
+ <class name="combo-list-box"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/src/core/platform.vala b/src/core/platform.vala
index 9d907872..a5a57f77 100644
--- a/src/core/platform.vala
+++ b/src/core/platform.vala
@@ -5,6 +5,8 @@ public interface Games.Platform : Object {
public abstract string get_name ();
+ public abstract PreferencesPagePlatformsRow get_row ();
+
public static uint hash (Platform platform) {
return str_hash (platform.get_id ());
}
diff --git a/src/dummy/dummy-platform.vala b/src/dummy/dummy-platform.vala
index 696d7b96..6d83eee3 100644
--- a/src/dummy/dummy-platform.vala
+++ b/src/dummy/dummy-platform.vala
@@ -8,4 +8,8 @@ public class Games.DummyPlatform : Object, Platform {
public string get_name () {
return _("Unknown");
}
+
+ public PreferencesPagePlatformsRow get_row () {
+ return new PreferencesPagePlatformsGenericRow (_("Unknown"));
+ }
}
diff --git a/src/generic/generic-platform.vala b/src/generic/generic-platform.vala
index 18c6e90f..09abf1c4 100644
--- a/src/generic/generic-platform.vala
+++ b/src/generic/generic-platform.vala
@@ -16,4 +16,8 @@ public class Games.GenericPlatform : Object, Platform {
public string get_name () {
return name;
}
+
+ public PreferencesPagePlatformsRow get_row () {
+ return new PreferencesPagePlatformsGenericRow (name);
+ }
}
diff --git a/src/meson.build b/src/meson.build
index 24ed087d..3bc8bff9 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -163,6 +163,9 @@ vala_sources = [
'ui/platforms-view.vala',
'ui/preferences-page.vala',
'ui/preferences-page-controllers.vala',
+ 'ui/preferences-page-platforms-generic-row.vala',
+ 'ui/preferences-page-platforms-retro-row.vala',
+ 'ui/preferences-page-platforms-row.vala',
'ui/preferences-page-plugins.vala',
'ui/preferences-page-plugins-item.vala',
'ui/preferences-page-video.vala',
diff --git a/src/retro/retro-platform.vala b/src/retro/retro-platform.vala
index 9e4a80ec..b5faf0f9 100644
--- a/src/retro/retro-platform.vala
+++ b/src/retro/retro-platform.vala
@@ -22,4 +22,8 @@ public class Games.RetroPlatform : Object, Platform {
public string[] get_mime_types () {
return mime_types;
}
+
+ public PreferencesPagePlatformsRow get_row () {
+ return new PreferencesPagePlatformsRetroRow (this);
+ }
}
diff --git a/src/ui/preferences-page-platforms-generic-row.vala
b/src/ui/preferences-page-platforms-generic-row.vala
new file mode 100644
index 00000000..73021930
--- /dev/null
+++ b/src/ui/preferences-page-platforms-generic-row.vala
@@ -0,0 +1,21 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-platforms-generic-row.ui")]
+private class Games.PreferencesPagePlatformsGenericRow : PreferencesPagePlatformsRow, Gtk.ListBoxRow {
+ [GtkChild]
+ private Gtk.Label title_label;
+
+ public string title {
+ get { return title_label.label; }
+ construct set {
+ title_label.label = value;
+ }
+ }
+
+ public PreferencesPagePlatformsGenericRow (string title) {
+ Object (title:title);
+ }
+
+ public void on_activated () {
+ }
+}
diff --git a/src/ui/preferences-page-platforms-retro-row.vala
b/src/ui/preferences-page-platforms-retro-row.vala
new file mode 100644
index 00000000..49ca9c56
--- /dev/null
+++ b/src/ui/preferences-page-platforms-retro-row.vala
@@ -0,0 +1,118 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-platforms-retro-row.ui")]
+private class Games.PreferencesPagePlatformsRetroRow : PreferencesPagePlatformsRow, Gtk.ListBoxRow {
+ [GtkChild]
+ private Gtk.Label name_label;
+ [GtkChild]
+ private Gtk.Label core_label;
+ [GtkChild]
+ private Gtk.Popover details_popover;
+ [GtkChild]
+ private Gtk.ListBox list_box;
+ [GtkChild]
+ private Gtk.Image dropdown_arrow;
+
+ private Settings settings;
+
+ private HashTable<Gtk.Widget, Retro.CoreDescriptor> row_cores;
+ private int num_cores;
+
+ private RetroPlatform _platform;
+ public RetroPlatform platform {
+ get { return _platform; }
+ construct {
+ _platform = value;
+ name_label.label = value.get_name ();
+
+ refresh_cores ();
+
+ var path = "/org/gnome/Games/platforms/%s/".printf (value.get_id ());
+ settings = new Settings.with_path ("org.gnome.Games.platforms", path);
+
+ settings.changed.connect (update_label);
+ }
+ }
+
+ construct {
+ list_box.set_header_func (update_header);
+ }
+
+ public PreferencesPagePlatformsRetroRow (RetroPlatform platform) {
+ Object (platform: platform);
+ }
+
+ private void update_label () {
+ var core_manager = RetroCoreManager.get_instance ();
+ var preferred_core = core_manager.get_preferred_core (platform);
+
+ if (preferred_core == null)
+ core_label.label = _("None");
+ else {
+ try {
+ core_label.label = preferred_core.get_name ();
+ }
+ catch (Error e) {
+ critical (e.message);
+ core_label.label = _("None");
+ }
+ }
+ }
+
+ private void refresh_cores () {
+ var core_manager = RetroCoreManager.get_instance ();
+ var cores = core_manager.get_cores_for_platform (platform);
+
+ num_cores = cores.length;
+
+ sensitive = (num_cores > 0);
+ dropdown_arrow.visible = (num_cores > 1);
+
+ row_cores = new HashTable<Gtk.Widget, Retro.CoreDescriptor> (null, null);
+
+ foreach (var core in cores) {
+ try {
+ var label = new Gtk.Label (core.get_name ());
+ label.halign = Gtk.Align.START;
+ label.margin = 12;
+ label.show ();
+
+ var row = new Gtk.ListBoxRow ();
+ row.add (label);
+ row.show ();
+ row_cores[row] = core;
+
+ list_box.add (row);
+ }
+ catch (Error e) {
+ critical (e.message);
+ }
+ }
+
+ update_label ();
+ }
+
+ public void on_activated () {
+ if (num_cores <= 1)
+ return;
+
+ details_popover.popup ();
+ }
+
+ private void update_header (Gtk.ListBoxRow row, Gtk.ListBoxRow? before) {
+ if (before != null && row.get_header () == null) {
+ var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
+ row.set_header (separator);
+ }
+ }
+
+ [GtkCallback]
+ private void on_row_activated (Gtk.ListBoxRow row) {
+ var core = row_cores[row];
+
+ var core_manager = RetroCoreManager.get_instance ();
+ core_manager.set_preferred_core (platform, core);
+
+ details_popover.popdown ();
+ }
+}
diff --git a/src/ui/preferences-page-platforms-row.vala b/src/ui/preferences-page-platforms-row.vala
new file mode 100644
index 00000000..a5480716
--- /dev/null
+++ b/src/ui/preferences-page-platforms-row.vala
@@ -0,0 +1,5 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public interface Games.PreferencesPagePlatformsRow : Gtk.ListBoxRow {
+ public abstract void on_activated ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]