From ccf7c4f373fdcc10924ac2b6f0befa83361b2df3 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Tue, 8 May 2018 19:27:07 +0300 Subject: [PATCH] Fix GSchema with custom plugins directories. + Separate Settings.vala. --- ...s.backbone.laview.data-example.gschema.xml | 2 +- src/CMakeLists.txt | 14 +------- src/laview-core/CMakeLists.txt | 1 + .../data-plugins}/AppDirs.vala | 0 src/laview-core/data-plugins/CMakeLists.txt | 13 +++++++ .../data-plugins}/PreferencesDialog.vala | 0 src/laview-core/data-plugins/Settings.vala | 35 +++++++++++++++++++ src/{ => laview-core/data-plugins}/main.vala | 6 ++++ 8 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 src/laview-core/CMakeLists.txt rename src/{ => laview-core/data-plugins}/AppDirs.vala (100%) create mode 100644 src/laview-core/data-plugins/CMakeLists.txt rename src/{ => laview-core/data-plugins}/PreferencesDialog.vala (100%) create mode 100644 src/laview-core/data-plugins/Settings.vala rename src/{ => laview-core/data-plugins}/main.vala (93%) diff --git a/config/ws.backbone.laview.data-example.gschema.xml b/config/ws.backbone.laview.data-example.gschema.xml index 5de5b0c..065188f 100644 --- a/config/ws.backbone.laview.data-example.gschema.xml +++ b/config/ws.backbone.laview.data-example.gschema.xml @@ -1,5 +1,5 @@ - + "Hello, earthlings" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 724d151..3ba34db 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,13 +1 @@ -SET (LibName laview-data-example) -FILE (GLOB_RECURSE LibSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.vala) -SET (LibPackages gtk+-3.0 gee-0.8 gobject-plugin-iface-0 laview-core-iface-0 laview-core-0) -SET (LibPkgModules gtk+-3.0 gee-0.8 gobject-plugin-0 laview-core-0) -SET (LibCustomVapis ${CMAKE_SOURCE_DIR}/config/Config.vapi) -INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/config") -SET (LibIsPlugin ON) -SET (LibInstall ON) -SET (LibExtraSources ${CMAKE_CURRENT_BINARY_DIR}/library_constructor.c) -SET (LC_RELATIVE_PREFIX "../../../..") -CONFIGURE_FILE ("${CMAKE_SOURCE_DIR}/cmake/backbone/templates/library_constructor.c.in" "${LibExtraSources}") -SET (LibInstallPrefix "laview-core-0/data-plugins") -INCLUDE (ValaLibCommonRules) +ADD_SUBDIRECTORY (laview-core) diff --git a/src/laview-core/CMakeLists.txt b/src/laview-core/CMakeLists.txt new file mode 100644 index 0000000..190a099 --- /dev/null +++ b/src/laview-core/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY (data-plugins) diff --git a/src/AppDirs.vala b/src/laview-core/data-plugins/AppDirs.vala similarity index 100% rename from src/AppDirs.vala rename to src/laview-core/data-plugins/AppDirs.vala diff --git a/src/laview-core/data-plugins/CMakeLists.txt b/src/laview-core/data-plugins/CMakeLists.txt new file mode 100644 index 0000000..724d151 --- /dev/null +++ b/src/laview-core/data-plugins/CMakeLists.txt @@ -0,0 +1,13 @@ +SET (LibName laview-data-example) +FILE (GLOB_RECURSE LibSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.vala) +SET (LibPackages gtk+-3.0 gee-0.8 gobject-plugin-iface-0 laview-core-iface-0 laview-core-0) +SET (LibPkgModules gtk+-3.0 gee-0.8 gobject-plugin-0 laview-core-0) +SET (LibCustomVapis ${CMAKE_SOURCE_DIR}/config/Config.vapi) +INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/config") +SET (LibIsPlugin ON) +SET (LibInstall ON) +SET (LibExtraSources ${CMAKE_CURRENT_BINARY_DIR}/library_constructor.c) +SET (LC_RELATIVE_PREFIX "../../../..") +CONFIGURE_FILE ("${CMAKE_SOURCE_DIR}/cmake/backbone/templates/library_constructor.c.in" "${LibExtraSources}") +SET (LibInstallPrefix "laview-core-0/data-plugins") +INCLUDE (ValaLibCommonRules) diff --git a/src/PreferencesDialog.vala b/src/laview-core/data-plugins/PreferencesDialog.vala similarity index 100% rename from src/PreferencesDialog.vala rename to src/laview-core/data-plugins/PreferencesDialog.vala diff --git a/src/laview-core/data-plugins/Settings.vala b/src/laview-core/data-plugins/Settings.vala new file mode 100644 index 0000000..a1e5bd8 --- /dev/null +++ b/src/laview-core/data-plugins/Settings.vala @@ -0,0 +1,35 @@ +namespace LAview.DataExample { + + public class AppSettings : Object { + Settings settings; + + string _greeting; + + public string greeting { + get { return _greeting; } + set { + if (settings != null) settings.set_string ("greeting", value); + _greeting = value; + } + default = "lyx"; + } + + public AppSettings () throws Error { + string schema_file = AppDirs.settings_dir+"/gschemas.compiled"; + if (!File.new_for_path (schema_file).query_exists ()) + throw new IOError.NOT_FOUND ("File "+schema_file+" not found"); + SettingsSchemaSource sss = new SettingsSchemaSource.from_directory (AppDirs.settings_dir, null, false); + string schema_name = "ws.backbone.laview.data-example-"+Config.VERSION_MAJOR.to_string(); + SettingsSchema schema = sss.lookup (schema_name, false); + if (schema == null) { + throw new IOError.NOT_FOUND ("Schema "+schema_name+" not found in "+schema_file); + } + settings = new Settings.full (schema, null, null); + + _greeting = settings.get_string("greeting"); + settings.changed["greeting"].connect (() => { + _greeting = settings.get_string("greeting"); + }); + } + } +} diff --git a/src/main.vala b/src/laview-core/data-plugins/main.vala similarity index 93% rename from src/main.vala rename to src/laview-core/data-plugins/main.vala index d1d8a39..ec7be83 100644 --- a/src/main.vala +++ b/src/laview-core/data-plugins/main.vala @@ -9,6 +9,7 @@ namespace LAview.DataExample { public class Plugin : LAview.Core.PluginData { PreferencesDialog preferences_dialog = null; + AppSettings settings; /** * Constructs a new ``Plugin``. @@ -17,6 +18,11 @@ namespace LAview.DataExample { // Initialize the data object, open database connection for example. stdout.puts ("DataExample.Plugin init () called\n"); AppDirs.init (); + try { + settings = new AppSettings(); + } catch (Error err) { + stderr.printf("Error: %s\n", err.message); + } } /**