diff --git a/build.sh b/build.sh
index eb966cce..fc84dcf6 100755
--- a/build.sh
+++ b/build.sh
@@ -17,6 +17,7 @@ blueprint-compiler batch-compile "$BASEDIR/ui" "$BASEDIR/ui" \
"$BASEDIR/ui/reddit.blp" \
"$BASEDIR/ui/sourceRow.blp" \
"$BASEDIR/ui/unsplash.blp" \
+ "$BASEDIR/ui/urlSource.blp" \
"$BASEDIR/ui/wallhaven.blp"
cd "$BASEDIR" || exit 1
diff --git a/randomwallpaper@iflow.space/adapter/urlSource.js b/randomwallpaper@iflow.space/adapter/urlSource.js
new file mode 100644
index 00000000..8619f6b3
--- /dev/null
+++ b/randomwallpaper@iflow.space/adapter/urlSource.js
@@ -0,0 +1,59 @@
+const Self = imports.misc.extensionUtils.getCurrentExtension();
+const HistoryModule = Self.imports.history;
+const JSONPath = Self.imports.jsonpath.jsonpath;
+const SettingsModule = Self.imports.settings;
+
+const BaseAdapter = Self.imports.adapter.baseAdapter;
+
+const RWG_SETTINGS_SCHEMA_URL_SOURCE = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.sources.urlSource';
+
+var UrlSourceAdapter = class extends BaseAdapter.BaseAdapter {
+ constructor(id, wallpaperLocation) {
+ super(wallpaperLocation);
+ let path = `/org/gnome/shell/extensions/space-iflow-randomwallpaper/sources/urlSource/${id}/`;
+ this._settings = new SettingsModule.Settings(RWG_SETTINGS_SCHEMA_URL_SOURCE, path);
+ }
+
+ requestRandomImage(callback) {
+ let imageDownloadUrl = this._settings.get("image-url", "string");
+ let authorName = this._settings.get("author-name", "string");
+ let authorUrl = this._settings.get("author-url", "string");
+ let domainUrl = this._settings.get("domain", "string");
+ let postUrl = this._settings.get("domain", "string");
+
+ let identifier = this._settings.get("name", "string");
+ if (identifier === null || identifier === "") {
+ identifier = 'Static URL';
+ }
+
+ if (typeof postUrl !== 'string' || !postUrl instanceof String) {
+ postUrl = null;
+ }
+
+ if (typeof authorName !== 'string' || !authorName instanceof String) {
+ authorName = null;
+ }
+
+ if (typeof authorUrl !== 'string' || !authorUrl instanceof String) {
+ authorUrl = null;
+ }
+
+ if (callback) {
+ let historyEntry = new HistoryModule.HistoryEntry(authorName, identifier, imageDownloadUrl);
+
+ if (authorUrl !== null && authorUrl !== "") {
+ historyEntry.source.authorUrl = authorUrl;
+ }
+
+ if (postUrl !== null && postUrl !== "") {
+ historyEntry.source.imageLinkUrl = postUrl;
+ }
+
+ if (domainUrl !== null && domainUrl !== "") {
+ historyEntry.source.sourceUrl = domainUrl;
+ }
+
+ callback(historyEntry);
+ }
+ }
+};
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 61de8bac..a6f81715 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
@@ -326,6 +326,7 @@
+
"Local Folder"
Name
@@ -340,4 +341,44 @@
+
+
+
+ "Static URL"
+ Name
+ Name for this source.
+
+
+
+ ""
+ Image URL
+ The URL to fetch.
+
+
+
+ ""
+ Domain
+ The domain used for linking the main page.
+
+
+
+ ""
+ Author name
+ The name of the image author.
+
+
+
+ ""
+ Author URL
+ The URL to link to the author.
+
+
+
+ ""
+ Post URL
+ The URL to link to the image page.
+
+
+
+
diff --git a/randomwallpaper@iflow.space/ui/localFolder.blp b/randomwallpaper@iflow.space/ui/localFolder.blp
index 5e3ef6eb..ffec228e 100644
--- a/randomwallpaper@iflow.space/ui/localFolder.blp
+++ b/randomwallpaper@iflow.space/ui/localFolder.blp
@@ -5,7 +5,7 @@ template LocalFolderSettingsGroup : Adw.PreferencesGroup {
title: _("General");
Adw.EntryRow folder_row {
- title: "Folder";
+ title: _("Folder");
Button folder {
valign: center;
diff --git a/randomwallpaper@iflow.space/ui/sourceRow.blp b/randomwallpaper@iflow.space/ui/sourceRow.blp
index b57359ba..32e3b87c 100644
--- a/randomwallpaper@iflow.space/ui/sourceRow.blp
+++ b/randomwallpaper@iflow.space/ui/sourceRow.blp
@@ -5,6 +5,21 @@ template SourceRow : Adw.ExpanderRow {
title: bind source_name.text;
show-enable-switch: true;
+ // Doesn't look good and prone to missclicks
+ // [action]
+ // Button button_delete {
+ // valign: center;
+
+ // styles [
+ // "destructive-action",
+ // ]
+
+ // Adw.ButtonContent {
+ // icon-name: "user-trash-symbolic";
+ // valign: center;
+ // }
+ // }
+
Box {
orientation: vertical;
spacing: 14;
@@ -30,6 +45,7 @@ template SourceRow : Adw.ExpanderRow {
"Reddit",
_("Generic JSON"),
_("Local Folder"),
+ _("Static URL"),
]
};
}
diff --git a/randomwallpaper@iflow.space/ui/sourceRow.js b/randomwallpaper@iflow.space/ui/sourceRow.js
index f90ae465..551cf18c 100644
--- a/randomwallpaper@iflow.space/ui/sourceRow.js
+++ b/randomwallpaper@iflow.space/ui/sourceRow.js
@@ -12,6 +12,7 @@ const Wallhaven = Self.imports.ui.wallhaven;
const Reddit = Self.imports.ui.reddit;
const GenericJson = Self.imports.ui.genericJson;
const LocalFolder = Self.imports.ui.localFolder;
+const UrlSource = Self.imports.ui.urlSource;
// https://gitlab.gnome.org/GNOME/gjs/-/blob/master/examples/gtk4-template.js
var SourceRow = GObject.registerClass({
@@ -74,6 +75,9 @@ var SourceRow = GObject.registerClass({
case 4: // Local Folder
targetWidget = new LocalFolder.LocalFolderSettingsGroup(this);
break;
+ case 5: // Static URL
+ targetWidget = new UrlSource.UrlSourceSettingsGroup(this);
+ break;
default:
targetWidget = null;
this.logger.error("The selected source has no corresponding widget!")
diff --git a/randomwallpaper@iflow.space/ui/urlSource.blp b/randomwallpaper@iflow.space/ui/urlSource.blp
new file mode 100644
index 00000000..f1aff9fa
--- /dev/null
+++ b/randomwallpaper@iflow.space/ui/urlSource.blp
@@ -0,0 +1,75 @@
+using Gtk 4.0;
+using Adw 1;
+
+template UrlSourceSettingsGroup : Adw.PreferencesGroup {
+ Adw.PreferencesGroup {
+ title: _("General");
+
+ Adw.EntryRow domain {
+ title: _("Domain");
+ input-purpose: url;
+
+ LinkButton {
+ valign: center;
+ uri: bind domain.text;
+
+ Adw.ButtonContent {
+ icon-name: "globe-symbolic";
+ }
+
+ styles [
+ "flat",
+ ]
+ }
+ }
+
+ Adw.EntryRow image_url {
+ title: _("Image URL");
+
+ LinkButton {
+ valign: center;
+ uri: bind image_url.text;
+
+ Adw.ButtonContent {
+ icon-name: "globe-symbolic";
+ }
+
+ styles [
+ "flat",
+ ]
+ }
+ }
+
+ Adw.EntryRow post_url {
+ title: _("Post URL");
+ input-purpose: free_form;
+
+ LinkButton {
+ valign: center;
+ uri: bind post_url.text;
+
+ Adw.ButtonContent {
+ icon-name: "globe-symbolic";
+ }
+
+ styles [
+ "flat",
+ ]
+ }
+ }
+ }
+
+ Adw.PreferencesGroup {
+ title: _("Author");
+
+ Adw.EntryRow author_name {
+ title: _("Name");
+ input-purpose: free_form;
+ }
+
+ Adw.EntryRow author_url {
+ title: _("URL");
+ input-purpose: free_form;
+ }
+ }
+}
diff --git a/randomwallpaper@iflow.space/ui/urlSource.js b/randomwallpaper@iflow.space/ui/urlSource.js
new file mode 100644
index 00000000..891ccf8e
--- /dev/null
+++ b/randomwallpaper@iflow.space/ui/urlSource.js
@@ -0,0 +1,55 @@
+const Adw = imports.gi.Adw;
+const ExtensionUtils = imports.misc.extensionUtils;
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
+
+const Self = ExtensionUtils.getCurrentExtension();
+const Convenience = Self.imports.convenience;
+
+const RWG_SETTINGS_SCHEMA_LOCAL_FOLDER = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.sources.urlSource';
+
+var UrlSourceSettingsGroup = GObject.registerClass({
+ GTypeName: 'UrlSourceSettingsGroup',
+ Template: GLib.filename_to_uri(Self.path + '/ui/urlSource.ui', null),
+ InternalChildren: [
+ 'author_name',
+ 'author_url',
+ 'domain',
+ 'image_url',
+ 'post_url',
+ ]
+}, class UrlSourceSettingsGroup extends Adw.PreferencesGroup {
+ constructor(parent_row, params = {}) {
+ super(params);
+
+ const path = `/org/gnome/shell/extensions/space-iflow-randomwallpaper/sources/urlSource/${parent_row.id}/`;
+ this._settings = Convenience.getSettings(RWG_SETTINGS_SCHEMA_LOCAL_FOLDER, path);
+
+ this._settings.bind('name',
+ parent_row.source_name,
+ 'text',
+ Gio.SettingsBindFlags.DEFAULT);
+
+ this._settings.bind('author-name',
+ this._author_name,
+ 'text',
+ Gio.SettingsBindFlags.DEFAULT);
+ this._settings.bind('author-url',
+ this._author_url,
+ 'text',
+ Gio.SettingsBindFlags.DEFAULT);
+ this._settings.bind('domain',
+ this._domain,
+ 'text',
+ Gio.SettingsBindFlags.DEFAULT);
+ this._settings.bind('image-url',
+ this._image_url,
+ 'text',
+ Gio.SettingsBindFlags.DEFAULT);
+ this._settings.bind('post-url',
+ this._post_url,
+ 'text',
+ Gio.SettingsBindFlags.DEFAULT);
+ }
+});
diff --git a/randomwallpaper@iflow.space/wallpaperController.js b/randomwallpaper@iflow.space/wallpaperController.js
index fa31b666..d7add6df 100644
--- a/randomwallpaper@iflow.space/wallpaperController.js
+++ b/randomwallpaper@iflow.space/wallpaperController.js
@@ -16,6 +16,7 @@ const GenericJsonAdapter = Self.imports.adapter.genericJson;
const LocalFolderAdapter = Self.imports.adapter.localFolder;
const RedditAdapter = Self.imports.adapter.reddit;
const UnsplashAdapter = Self.imports.adapter.unsplash;
+const UrlSourceAdapter = Self.imports.adapter.urlSource;
const WallhavenAdapter = Self.imports.adapter.wallhaven;
const RWG_SETTINGS_SCHEMA_BACKEND_CONNECTION = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.backend-connection';
@@ -160,6 +161,9 @@ var WallpaperController = class {
case 4:
imageSourceAdapter = new LocalFolderAdapter.LocalFolderAdapter(source.id, this.wallpaperlocation);
break;
+ case 5:
+ imageSourceAdapter = new UrlSourceAdapter.UrlSourceAdapter(source.id, this.wallpaperlocation);
+ break;
default:
imageSourceAdapter = new UnsplashAdapter.UnsplashAdapter(null, this.wallpaperlocation);
// TODO: log error and abort, raise exception?