[gnome-games/wip/exalm/cache2: 24/25] grilo: Provide default values
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/cache2: 24/25] grilo: Provide default values
- Date: Sun, 7 Oct 2018 07:30:24 +0000 (UTC)
commit b65d81ca864c2823cf775ccacb3a6d227cf29698
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sat Oct 6 21:36:00 2018 +0500
grilo: Provide default values
Provide default non-null values for loaded, but missing metadata fields.
This allows to differentiate them for values that haven't been loaded yet.
Fixes #115
src/grilo/grilo-cooperative.vala | 12 +++---------
src/grilo/grilo-description.vala | 12 +++---------
src/grilo/grilo-developer.vala | 10 ++--------
src/grilo/grilo-genre.vala | 14 ++------------
src/grilo/grilo-players.vala | 22 ++++++++--------------
src/grilo/grilo-publisher.vala | 12 +++---------
src/grilo/grilo-rating.vala | 12 +++---------
src/grilo/grilo-release-date.vala | 12 +++---------
8 files changed, 27 insertions(+), 79 deletions(-)
---
diff --git a/src/grilo/grilo-cooperative.vala b/src/grilo/grilo-cooperative.vala
index ca792e71..808c78f4 100644
--- a/src/grilo/grilo-cooperative.vala
+++ b/src/grilo/grilo-cooperative.vala
@@ -11,6 +11,7 @@ public class Games.GriloCooperative : Object, Cooperative {
this.media = media;
media.resolved.connect (on_media_resolved);
resolving = false;
+ cooperative = false;
}
public bool get_cooperative () {
@@ -32,15 +33,8 @@ public class Games.GriloCooperative : Object, Cooperative {
var registry = Grl.Registry.get_default ();
var metadata_key = registry.lookup_metadata_key ("coop");
- if (grl_media.length (metadata_key) == 0)
- return;
-
- var coop = grl_media.get_boolean (metadata_key);
- load_media_cooperative (coop);
- }
-
- private void load_media_cooperative (bool coop) {
- cooperative = coop;
+ if (grl_media.length (metadata_key) != 0)
+ cooperative = grl_media.get_boolean (metadata_key);
has_loaded = true;
}
diff --git a/src/grilo/grilo-description.vala b/src/grilo/grilo-description.vala
index 61081500..87ccdfe3 100644
--- a/src/grilo/grilo-description.vala
+++ b/src/grilo/grilo-description.vala
@@ -11,6 +11,7 @@ public class Games.GriloDescription : Object, Description {
this.media = media;
media.resolved.connect (on_media_resolved);
resolving = false;
+ description = "";
}
public string get_description () {
@@ -32,15 +33,8 @@ public class Games.GriloDescription : Object, Description {
if (grl_media == null)
return;
- if (grl_media.length (Grl.MetadataKey.DESCRIPTION) == 0)
- return;
-
- var description_string = grl_media.get_description ();
- load_media_description (description_string);
- }
-
- private void load_media_description (string description_string) {
- description = description_string;
+ if (grl_media.length (Grl.MetadataKey.DESCRIPTION) != 0)
+ description = grl_media.get_description ();
has_loaded = true;
}
diff --git a/src/grilo/grilo-developer.vala b/src/grilo/grilo-developer.vala
index 7412fe77..83118b76 100644
--- a/src/grilo/grilo-developer.vala
+++ b/src/grilo/grilo-developer.vala
@@ -32,15 +32,9 @@ public class Games.GriloDeveloper : Object, Developer {
var registry = Grl.Registry.get_default ();
var metadata_key = registry.lookup_metadata_key ("developer");
- if (grl_media.length (metadata_key) == 0)
- return;
-
- var developer_string = grl_media.get_string (metadata_key);
- load_media_developer (developer_string);
- }
+ if (grl_media.length (metadata_key) != 0)
+ developer = grl_media.get_string (metadata_key);
- private void load_media_developer (string developer_string) {
- developer = developer_string;
has_loaded = true;
}
}
diff --git a/src/grilo/grilo-genre.vala b/src/grilo/grilo-genre.vala
index 0894e11c..da3a7925 100644
--- a/src/grilo/grilo-genre.vala
+++ b/src/grilo/grilo-genre.vala
@@ -11,6 +11,7 @@ public class Games.GriloGenre : Object, Genre {
this.media = media;
media.resolved.connect (on_media_resolved);
resolving = false;
+ genre = new List<string> ();
}
public unowned List<string> get_genre () {
@@ -34,19 +35,8 @@ public class Games.GriloGenre : Object, Genre {
var genre_count = grl_media.length (Grl.MetadataKey.GENRE);
- if (genre_count == 0)
- return;
-
- var genre_list = new List<string> ();
-
for (uint index = 0; index < genre_count; index++)
- genre_list.append (grl_media.get_genre_nth (index));
-
- load_media_genre (genre_list);
- }
-
- private void load_media_genre (List<string> genre_list) {
- genre = genre_list.copy ();
+ genre.append (grl_media.get_genre_nth (index));
has_loaded = true;
}
diff --git a/src/grilo/grilo-players.vala b/src/grilo/grilo-players.vala
index dd9b33e8..864546a7 100644
--- a/src/grilo/grilo-players.vala
+++ b/src/grilo/grilo-players.vala
@@ -11,6 +11,7 @@ public class Games.GriloPlayers : Object, Players {
this.media = media;
media.resolved.connect (on_media_resolved);
resolving = false;
+ players = "";
}
public string get_players () {
@@ -35,21 +36,14 @@ public class Games.GriloPlayers : Object, Players {
var registry = Grl.Registry.get_default ();
var metadata_key = registry.lookup_metadata_key ("players");
- if (grl_media.length (metadata_key) == 0)
- return;
-
- var player = grl_media.get_string (metadata_key);
-
- if (int.parse (player) == 1)
- player = _("Single-player");
- else
- player = _("Multi-player");
-
- load_media_players (player);
- }
+ if (grl_media.length (metadata_key) != 0) {
+ players = grl_media.get_string (metadata_key);
- private void load_media_players (string player) {
- players = player;
+ if (int.parse (players) == 1)
+ players = _("Single-player");
+ else
+ players = _("Multi-player");
+ }
has_loaded = true;
}
diff --git a/src/grilo/grilo-publisher.vala b/src/grilo/grilo-publisher.vala
index b0c8d175..fa656081 100644
--- a/src/grilo/grilo-publisher.vala
+++ b/src/grilo/grilo-publisher.vala
@@ -11,6 +11,7 @@ public class Games.GriloPublisher : Object, Publisher {
this.media = media;
media.resolved.connect (on_media_resolved);
resolving = false;
+ publisher = "";
}
public string get_publisher () {
@@ -35,15 +36,8 @@ public class Games.GriloPublisher : Object, Publisher {
var registry = Grl.Registry.get_default ();
var metadata_key = registry.lookup_metadata_key ("publisher");
- if (grl_media.length (metadata_key) == 0)
- return;
-
- var publisher_string = grl_media.get_string (metadata_key);
- load_media_publisher (publisher_string);
- }
-
- private void load_media_publisher (string publisher_string) {
- publisher = publisher_string;
+ if (grl_media.length (metadata_key) != 0)
+ publisher = grl_media.get_string (metadata_key);
has_loaded = true;
}
diff --git a/src/grilo/grilo-rating.vala b/src/grilo/grilo-rating.vala
index 8edc301c..4a6e18b1 100644
--- a/src/grilo/grilo-rating.vala
+++ b/src/grilo/grilo-rating.vala
@@ -11,6 +11,7 @@ public class Games.GriloRating : Object, Rating {
this.media = media;
media.resolved.connect (on_media_resolved);
resolving = false;
+ rating = 0;
}
public float get_rating () {
@@ -28,15 +29,8 @@ public class Games.GriloRating : Object, Rating {
if (grl_media == null)
return;
- if (grl_media.length (Grl.MetadataKey.RATING) == 0)
- return;
-
- var media_rating = grl_media.get_rating ();
- load_media_rating (media_rating);
- }
-
- private void load_media_rating (float media_rating) {
- rating = media_rating;
+ if (grl_media.length (Grl.MetadataKey.RATING) != 0)
+ rating = grl_media.get_rating ();
has_loaded = true;
}
diff --git a/src/grilo/grilo-release-date.vala b/src/grilo/grilo-release-date.vala
index 4f03074d..30de60b8 100644
--- a/src/grilo/grilo-release-date.vala
+++ b/src/grilo/grilo-release-date.vala
@@ -11,6 +11,7 @@ public class Games.GriloReleaseDate : Object, ReleaseDate {
this.media = media;
media.resolved.connect (on_media_resolved);
resolving = false;
+ release_date = null;
}
public DateTime get_release_date () {
@@ -32,15 +33,8 @@ public class Games.GriloReleaseDate : Object, ReleaseDate {
if (grl_media == null)
return;
- if (grl_media.length (Grl.MetadataKey.PUBLICATION_DATE) == 0)
- return;
-
- var release = grl_media.get_publication_date ();
- load_media_release_date (release);
- }
-
- private void load_media_release_date (DateTime release) {
- release_date = release;
+ if (grl_media.length (Grl.MetadataKey.PUBLICATION_DATE) != 0)
+ release_date = grl_media.get_publication_date ();
has_loaded = true;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]