[gnome-games/wip/exalm/cache2: 5/27] developer: Add 'has-loaded' property
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/cache2: 5/27] developer: Add 'has-loaded' property
- Date: Sun, 7 Oct 2018 10:23:29 +0000 (UTC)
commit 9c3457bf475015e449892f6987bb64dc8c2f7854
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sun Sep 30 13:33:11 2018 +0500
developer: Add 'has-loaded' property
This will be used in subsequent commits to get rid of changed() signal.
Use 'true' value for GenericDeveloper, because it's a simple string that
is always available.
Use 'false' for DummyDeveloper, because it doesn't have any value.
Use 'notify::has-loaded' instead of 'connect' signal in DatabaseDeveloper,
and connect signal lazily because it's impossible to handle already loaded
(such as GenericDeveloper) case otherwise.
src/core/developer.vala | 2 ++
src/database/database-developer.vala | 28 +++++++++++++++++++++++++---
src/dummy/dummy-developer.vala | 2 ++
src/generic/generic-developer.vala | 6 ++++++
src/grilo/grilo-developer.vala | 7 ++++---
5 files changed, 39 insertions(+), 6 deletions(-)
---
diff --git a/src/core/developer.vala b/src/core/developer.vala
index a0507c17..c86c4e18 100644
--- a/src/core/developer.vala
+++ b/src/core/developer.vala
@@ -3,6 +3,8 @@
public interface Games.Developer : Object {
public signal void changed ();
+ public abstract bool has_loaded { get; protected set; }
+
public abstract string get_developer ();
public static uint hash (Developer developer) {
diff --git a/src/database/database-developer.vala b/src/database/database-developer.vala
index ef17dd87..3affeebc 100644
--- a/src/database/database-developer.vala
+++ b/src/database/database-developer.vala
@@ -15,6 +15,8 @@ private class Games.DatabaseDeveloper : Object, Developer {
private Sqlite.Statement save_statement;
private string loaded;
+ public bool has_loaded { get; protected set; }
+
public DatabaseDeveloper (Sqlite.Database database, Developer developer, Uid uid) {
this.developer = developer;
this.uid = uid;
@@ -30,14 +32,31 @@ private class Games.DatabaseDeveloper : Object, Developer {
}
}
+ private void on_developer_loaded () {
+ if (!developer.has_loaded)
+ return;
+
+ has_loaded = true;
+
+ try {
+ save_developer ();
+ }
+ catch (Error e) {
+ warning (e.message);
+ }
+ }
+
public string get_developer () {
+ if (!has_loaded) {
+ on_developer_loaded ();
+ developer.notify["has-loaded"].connect (on_developer_loaded);
+ }
+
try {
if (loaded == null)
load_developer ();
- if (loaded != "")
+ if (loaded != "" && loaded != null)
return loaded;
- else
- save_developer ();
}
catch (Error e) {
warning (e.message);
@@ -56,6 +75,9 @@ private class Games.DatabaseDeveloper : Object, Developer {
loaded = load_statement.column_text (0) ?? "";
else
warning ("Execution failed.");
+
+ if (loaded != "" && loaded != null)
+ has_loaded = true;
}
private void save_developer () throws Error {
diff --git a/src/dummy/dummy-developer.vala b/src/dummy/dummy-developer.vala
index e3462812..84b5d759 100644
--- a/src/dummy/dummy-developer.vala
+++ b/src/dummy/dummy-developer.vala
@@ -1,6 +1,8 @@
// This file is part of GNOME Games. License: GPL-3.0+.
public class Games.DummyDeveloper : Object, Developer {
+ public bool has_loaded { get; protected set; }
+
public string get_developer () {
return "";
}
diff --git a/src/generic/generic-developer.vala b/src/generic/generic-developer.vala
index 3499c940..cd791e37 100644
--- a/src/generic/generic-developer.vala
+++ b/src/generic/generic-developer.vala
@@ -3,6 +3,12 @@
public class Games.GenericDeveloper : Object, Developer {
private string developer;
+ public bool has_loaded { get; protected set; }
+
+ construct {
+ has_loaded = true;
+ }
+
public GenericDeveloper (string developer) {
this.developer = developer;
}
diff --git a/src/grilo/grilo-developer.vala b/src/grilo/grilo-developer.vala
index 8a5d8eb4..8b056a92 100644
--- a/src/grilo/grilo-developer.vala
+++ b/src/grilo/grilo-developer.vala
@@ -4,7 +4,8 @@ public class Games.GriloDeveloper : Object, Developer {
private GriloMedia media;
private string developer;
private bool resolving;
- private bool resolved;
+
+ public bool has_loaded { get; protected set; }
public GriloDeveloper (GriloMedia media) {
this.media = media;
@@ -13,7 +14,7 @@ public class Games.GriloDeveloper : Object, Developer {
}
public string get_developer () {
- if (resolving || resolved)
+ if (resolving || has_loaded)
return developer;
resolving = true;
@@ -40,7 +41,7 @@ public class Games.GriloDeveloper : Object, Developer {
private void load_media_developer (string developer_string) {
developer = developer_string;
- resolved = true;
+ has_loaded = true;
changed ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]