[gnome-games] ui: Add MediaSelector
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] ui: Add MediaSelector
- Date: Fri, 19 Aug 2016 21:09:45 +0000 (UTC)
commit cd4bd67950c186eed1ce84405c72c62bc299a7f0
Author: Ricard Gascons <gascons1995 gmail com>
Date: Thu Aug 18 16:22:00 2016 +0200
ui: Add MediaSelector
This ui component allows selecting a media of a multi-source game.
This is part of a series of commits to add multi-source support.
data/Makefile.am | 1 +
data/org.gnome.Games.gresource.xml | 1 +
data/ui/media-selector.ui | 17 +++++++
src/Makefile.am | 1 +
src/ui/media-selector.vala | 83 ++++++++++++++++++++++++++++++++++++
5 files changed, 103 insertions(+), 0 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index edfe579..565261e 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -17,6 +17,7 @@ EXTRA_DIST = \
ui/dummy-display.ui \
ui/empty-collection.ui \
ui/header-bar.ui \
+ ui/media-selector.ui \
ui/quit-dialog.ui \
ui/remote-display.ui \
ui/resume-dialog.ui \
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 3bd2c27..e11eb58 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -15,6 +15,7 @@
<file preprocess="xml-stripblanks">ui/error-display.ui</file>
<file preprocess="xml-stripblanks">ui/error-info-bar.ui</file>
<file preprocess="xml-stripblanks">ui/game-icon-view.ui</file>
+ <file preprocess="xml-stripblanks">ui/media-selector.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-window.ui</file>
diff --git a/data/ui/media-selector.ui b/data/ui/media-selector.ui
new file mode 100644
index 0000000..8b451d8
--- /dev/null
+++ b/data/ui/media-selector.ui
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.16"/>
+ <template class="GamesMediaSelector" parent="GtkPopover">
+ <child>
+ <object class="GtkListBox" id="list_box">
+ <property name="margin-top">12</property>
+ <property name="margin-bottom">12</property>
+ <property name="margin-start">21</property>
+ <property name="margin-end">21</property>
+ <signal name="row-selected" after="yes" handler="on_row_selected"/>
+ <child>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 774962a..0c1f6e8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -104,6 +104,7 @@ gnome_games_SOURCES = \
ui/error-info-bar.vala \
ui/game-icon-view.vala \
ui/game-thumbnail.vala \
+ ui/media-selector.vala \
ui/preferences-page.vala \
ui/preferences-page-plugins.vala \
ui/preferences-page-plugins-item.vala \
diff --git a/src/ui/media-selector.vala b/src/ui/media-selector.vala
new file mode 100644
index 0000000..9c0c031
--- /dev/null
+++ b/src/ui/media-selector.vala
@@ -0,0 +1,83 @@
+// This file is part of GNOME Games. License: GPLv3
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/media-selector.ui")]
+private class Games.MediaSelector : Gtk.Popover {
+ private MediaSet _media_set;
+ public MediaSet media_set {
+ set {
+ _media_set = value;
+
+ remove_media ();
+ update_media ();
+ }
+ }
+
+ [GtkChild]
+ private Gtk.ListBox list_box;
+
+ private HashTable<Gtk.ListBoxRow, int> row_to_int;
+
+ construct {
+ row_to_int = new HashTable<Gtk.ListBoxRow, int> (direct_hash, direct_equal);
+ }
+
+ private void update_media () {
+ var media_number = 0;
+ _media_set.foreach_media ((media) => {
+ string media_name;
+ if (media.title == null)
+ media_name = _("Media %d").printf (media_number);
+ else {
+ try {
+ media_name = media.title.get_title ();
+ }
+ catch (Error e) {
+ warning (e.message);
+
+ media_name = "";
+ }
+ }
+
+ var row = new Gtk.ListBoxRow ();
+ var label = new Gtk.Label (media_name);
+ row.add (label);
+ if (media_number == _media_set.selected_media_number)
+ list_box.select_row (row);
+
+ row_to_int.insert (row, media_number);
+
+ add_row (row);
+
+ media_number++;
+ });
+ }
+
+ private void remove_media () {
+ row_to_int.remove_all ();
+ list_box.unselect_all ();
+ list_box.foreach ((child) => child.destroy ());
+ }
+
+ private void add_row (Gtk.ListBoxRow row) {
+ list_box.insert (row, -1);
+ list_box.show_all ();
+ }
+
+ [GtkCallback]
+ private void on_row_selected (Gtk.ListBoxRow? row) {
+ if (row == null)
+ return;
+
+ if (!row_to_int.contains (row))
+ return;
+
+ var media_number = row_to_int[row];
+
+ if (media_number == _media_set.selected_media_number)
+ return;
+
+ _media_set.selected_media_number = media_number;
+
+ hide ();
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]