[gnome-games/wip/aplazas/run-uri: 1/21] core: Add PluginRegisterIterator
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/aplazas/run-uri: 1/21] core: Add PluginRegisterIterator
- Date: Thu, 13 Apr 2017 14:21:40 +0000 (UTC)
commit de65ca784dd600a2b7b8d98deaba886587af71b0
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu Apr 13 10:28:34 2017 +0200
core: Add PluginRegisterIterator
Allow to loop through the content of PluginRegister in a synchronous or
asynchronous way.
src/Makefile.am | 1 +
src/core/plugin-register-iterator.vala | 45 ++++++++++++++++++++++++++++++++
src/core/plugin-register.vala | 4 +++
3 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 69126be..f7fbd4a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -48,6 +48,7 @@ gnome_games_SOURCES = \
core/media-set/media-set-error.vala \
core/plugin.vala \
core/plugin-register.vala \
+ core/plugin-register-iterator.vala \
core/plugin-registrar.vala \
core/runner.vala \
core/title.vala \
diff --git a/src/core/plugin-register-iterator.vala b/src/core/plugin-register-iterator.vala
new file mode 100644
index 0000000..5448336
--- /dev/null
+++ b/src/core/plugin-register-iterator.vala
@@ -0,0 +1,45 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.PluginRegisterIterator {
+ private PluginRegister plugin_register;
+ private PluginRegistrar? plugins_registrar;
+ private FileEnumerator enumerator;
+
+ internal PluginRegisterIterator (PluginRegister plugin_register) {
+ this.plugin_register = plugin_register;
+ enumerator = null;
+ }
+
+ public new PluginRegistrar? get () {
+ return plugins_registrar;
+ }
+
+ public bool next () {
+ try {
+ var directory = File.new_for_path (PLUGINS_DIR);
+ if (enumerator == null) {
+ enumerator = directory.enumerate_children (FileAttribute.STANDARD_NAME, 0);
+ }
+
+ FileInfo info;
+ while ((info = enumerator.next_file ()) != null) {
+ var name = info.get_name ();
+ if (!name.has_suffix (".plugin"))
+ continue;
+
+ var descriptor = directory.get_child (name);
+ var descriptor_path = descriptor.get_path ();
+ plugins_registrar = plugin_register.get_plugin_registrar (descriptor_path);
+
+ return true;
+ }
+ }
+ catch (Error e) {
+ debug (e.message);
+ }
+
+ plugins_registrar = null;
+
+ return false;
+ }
+}
diff --git a/src/core/plugin-register.vala b/src/core/plugin-register.vala
index 7bdf023..3a1fd6c 100644
--- a/src/core/plugin-register.vala
+++ b/src/core/plugin-register.vala
@@ -17,6 +17,10 @@ private class Games.PluginRegister : Object {
return instance;
}
+ public PluginRegisterIterator iterator () {
+ return new PluginRegisterIterator (this);
+ }
+
public void foreach_plugin_registrar (PluginRegistrarFunc func) {
var directory = File.new_for_path (PLUGINS_DIR);
try {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]