diff --git a/randomwallpaper@iflow.space/jsonpath/jsonpath.js b/randomwallpaper@iflow.space/jsonpath/jsonpath.js
new file mode 100644
index 0000000..81c75a4
--- /dev/null
+++ b/randomwallpaper@iflow.space/jsonpath/jsonpath.js
@@ -0,0 +1,90 @@
+let JSONPathParser = function () {
+
+ /**
+ * Access a simple json path expression of an object.
+ * Returns the accessed value or null if the access was not possible.
+ *
+ * @param inputObject the object to access
+ * @param inputString the json path expression
+ * @returns {*}
+ */
+ this.access = function(inputObject, inputString) {
+ if (inputObject === null || inputObject === undefined) {
+ return null;
+ }
+
+ if (inputString.length === 0) {
+ return inputObject;
+ }
+
+ let startDot = inputString.indexOf('.');
+ if (startDot === -1) {
+ startDot = inputString.length;
+ }
+
+ let keyString = inputString.slice(0, startDot);
+ let inputStringTail = inputString.slice(startDot+1);
+
+ let startParentheses = keyString.indexOf('[');
+
+ if (startParentheses === -1) {
+
+ let targetObject = this._getTargetObject(inputObject, keyString);
+ if (targetObject == null) {
+ return null;
+ }
+
+ return this.access(targetObject, inputStringTail)
+
+ } else {
+
+ let indexString = keyString.slice(startParentheses+1, keyString.length-1);
+ keyString = keyString.slice(0, startParentheses);
+
+ let targetObject = this._getTargetObject(inputObject, keyString);
+ if (targetObject == null) {
+ return null;
+ }
+
+ switch (indexString) {
+ case "@random":
+ return this.access(this.randomElement(targetObject), inputStringTail);
+ // add special keywords here
+ default:
+ // expecting integer
+ return this.access(targetObject[parseInt(indexString)], inputStringTail);
+ }
+
+ }
+
+ };
+
+ /**
+ * Check validity of the key string and return the target object or null.
+ * @param inputObject
+ * @param keyString
+ * @returns {*}
+ * @private
+ */
+ this._getTargetObject = function (inputObject, keyString) {
+ if (!keyString.empty && keyString !== "$" && !inputObject.hasOwnProperty(keyString)) {
+ return null;
+ }
+
+ return (keyString === "$") ? inputObject : inputObject[keyString];
+ };
+
+ /**
+ * Returns the value of a random key of a given object.
+ *
+ * @param inputObject
+ * @returns {*}
+ */
+ this.randomElement = function(inputObject) {
+ let keys = Object.keys(inputObject);
+ let randomIndex = Math.floor(Math.random()*keys.length);
+
+ return inputObject[keys[randomIndex]];
+ }
+
+};
diff --git a/randomwallpaper@iflow.space/prefs.js b/randomwallpaper@iflow.space/prefs.js
index b00abcc..d839d13 100644
--- a/randomwallpaper@iflow.space/prefs.js
+++ b/randomwallpaper@iflow.space/prefs.js
@@ -15,6 +15,7 @@ const RWG_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.space.iflow.randomwallpa
const RWG_SETTINGS_SCHEMA_DESKTOPPER = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.desktopper';
const RWG_SETTINGS_SCHEMA_UNSPLASH = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.unsplash';
const RWG_SETTINGS_SCHEMA_WALLHEAVEN = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.wallheaven';
+const RWG_SETTINGS_SCHEMA_GENERIC_JSON = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.genericJSON';
const LoggerModule = Self.imports.logger;
@@ -41,6 +42,7 @@ const RandomWallpaperSettings = new Lang.Class({
desktopperSettings: null,
unsplashSettings: null,
wallheavenSettings: null,
+ genericJsonSettings: null,
_init: function () {
this._settings = Convenience.getSettings(RWG_SETTINGS_SCHEMA);
@@ -67,6 +69,11 @@ const RandomWallpaperSettings = new Lang.Class({
this.wallheavenSettings = this._builder.get_object('wallheaven-settings');
this.bindWallheaven();
+ // Generic JSON Settings
+ this._generic_json_settings = Convenience.getSettings(RWG_SETTINGS_SCHEMA_GENERIC_JSON);
+ this.genericJsonSettings = this._builder.get_object('generic-json-settings');
+ this.bindGenericJSON();
+
this._toggleAfSliders();
this.widget = this._builder.get_object('main-widget');
@@ -76,7 +83,7 @@ const RandomWallpaperSettings = new Lang.Class({
}.bind(this));
this._builder.get_object('source-combo').connect('changed', (sourceCombo) => {
- let container = this._builder.get_object('source-settings-frame');
+ let container = this._builder.get_object('source-settings-container');
if (this.currentSourceSettingsWidget !== null) {
container.remove(this.currentSourceSettingsWidget);
}
@@ -91,13 +98,16 @@ const RandomWallpaperSettings = new Lang.Class({
case 2: // wallheaven
this.currentSourceSettingsWidget = this.wallheavenSettings;
break;
+ case 3: // generic JSON
+ this.currentSourceSettingsWidget = this.genericJsonSettings;
+ break;
default:
this.currentSourceSettingsWidget = this.noSettings;
break;
}
container.add(this.currentSourceSettingsWidget);
-
+ container.getParent
});
this._settings.bind('history-length',
@@ -124,6 +134,10 @@ const RandomWallpaperSettings = new Lang.Class({
this._builder.get_object('change-lock-screen'),
'active',
Gio.SettingsBindFlags.DEFAULT);
+ this._settings.bind('disable-hover-preview',
+ this._builder.get_object('disable-hover-preview'),
+ 'active',
+ Gio.SettingsBindFlags.DEFAULT);
},
_toggleAfSliders: function () {
@@ -161,6 +175,10 @@ const RandomWallpaperSettings = new Lang.Class({
this._builder.get_object('unsplash-image-height'),
'value',
Gio.SettingsBindFlags.DEFAULT);
+ this._unsplash_settings.bind('featured-only',
+ this._builder.get_object('unsplash-featured-only'),
+ 'active',
+ Gio.SettingsBindFlags.DEFAULT);
},
bindWallheaven: function () {
@@ -194,6 +212,22 @@ const RandomWallpaperSettings = new Lang.Class({
this._builder.get_object('wallheaven-allow-sketchy'),
'active',
Gio.SettingsBindFlags.DEFAULT);
+ },
+
+ bindGenericJSON: function () {
+ this._builder.get_object('generic-json-docs-link').set_label("More information here");
+ this._generic_json_settings.bind('generic-json-request-url',
+ this._builder.get_object('generic-json-request-url'),
+ 'text',
+ Gio.SettingsBindFlags.DEFAULT);
+ this._generic_json_settings.bind('generic-json-response-path',
+ this._builder.get_object('generic-json-response-path'),
+ 'text',
+ Gio.SettingsBindFlags.DEFAULT);
+ this._generic_json_settings.bind('generic-json-url-prefix',
+ this._builder.get_object('generic-json-url-prefix'),
+ 'text',
+ Gio.SettingsBindFlags.DEFAULT);
}
});
diff --git a/randomwallpaper@iflow.space/schemas/gschemas.compiled b/randomwallpaper@iflow.space/schemas/gschemas.compiled
index 4ee1798..8623855 100644
Binary files a/randomwallpaper@iflow.space/schemas/gschemas.compiled and b/randomwallpaper@iflow.space/schemas/gschemas.compiled differ
diff --git a/randomwallpaper@iflow.space/schemas/org.gnome.shell.extensions.space.iflow.randomwallpaper.gschema.xml b/randomwallpaper@iflow.space/schemas/org.gnome.shell.extensions.space.iflow.randomwallpaper.gschema.xml
index ec17645..86d4705 100644
--- a/randomwallpaper@iflow.space/schemas/org.gnome.shell.extensions.space.iflow.randomwallpaper.gschema.xml
+++ b/randomwallpaper@iflow.space/schemas/org.gnome.shell.extensions.space.iflow.randomwallpaper.gschema.xml
@@ -5,6 +5,7 @@
+
Weather the gnome lock screen should also be set to the new wallpaper.
+
+ false
+ Disable hover preview
+ Disables the preview of the background while hovering the history list
+
+
Image Width
The height of the image.
+
+ false
+ Featured images only
+ This results in a smaller wallpaper pool but the images are considered to have higher quality.
+
Weather the people category should be searched.
+
+
+
+ ""
+ The request URL
+ The URL where the JSON will be requested.
+
+
+ ""
+ JSON Path
+ The JSON path that describes the picture URL.
+
+
+ ""
+ Image URL prefix
+ This prefix is added to the final image URL.
+
+
+
diff --git a/randomwallpaper@iflow.space/settings.ui b/randomwallpaper@iflow.space/settings.ui
index 6d6d54c..2134cbd 100644
--- a/randomwallpaper@iflow.space/settings.ui
+++ b/randomwallpaper@iflow.space/settings.ui
@@ -1,5 +1,5 @@
-
+
-
-