From b90bfb734af89fd7bc1ff1fd312993fb4931366d Mon Sep 17 00:00:00 2001 From: Lucki Date: Sun, 11 Dec 2022 23:57:59 +0100 Subject: [PATCH] Rework UI in preparation for multiple sources --- build.sh | 26 +- install.sh | 4 +- randomwallpaper@iflow.space/prefs.js | 282 ++-- .../schemas/.gitignore | 1 + .../schemas/gschemas.compiled | Bin 3404 -> 0 bytes ...ns.space.iflow.randomwallpaper.gschema.xml | 86 +- randomwallpaper@iflow.space/settings.ui | 1245 ----------------- randomwallpaper@iflow.space/sourceAdapter.js | 52 +- randomwallpaper@iflow.space/ui/.gitignore | 1 + .../ui/generic_json.blp | 107 ++ .../ui/page_general.blp | 161 +++ .../ui/page_sources.blp | 24 + randomwallpaper@iflow.space/ui/reddit.blp | 19 + randomwallpaper@iflow.space/ui/source_row.blp | 102 ++ randomwallpaper@iflow.space/ui/unsplash.blp | 89 ++ randomwallpaper@iflow.space/ui/wallhaven.blp | 97 ++ .../wallpaperController.js | 3 +- 17 files changed, 899 insertions(+), 1400 deletions(-) create mode 100644 randomwallpaper@iflow.space/schemas/.gitignore delete mode 100644 randomwallpaper@iflow.space/schemas/gschemas.compiled delete mode 100644 randomwallpaper@iflow.space/settings.ui create mode 100644 randomwallpaper@iflow.space/ui/.gitignore create mode 100644 randomwallpaper@iflow.space/ui/generic_json.blp create mode 100644 randomwallpaper@iflow.space/ui/page_general.blp create mode 100644 randomwallpaper@iflow.space/ui/page_sources.blp create mode 100644 randomwallpaper@iflow.space/ui/reddit.blp create mode 100644 randomwallpaper@iflow.space/ui/source_row.blp create mode 100644 randomwallpaper@iflow.space/ui/unsplash.blp create mode 100644 randomwallpaper@iflow.space/ui/wallhaven.blp diff --git a/build.sh b/build.sh index 8bf25944..d32703d8 100755 --- a/build.sh +++ b/build.sh @@ -3,11 +3,21 @@ BASEDIR="randomwallpaper@iflow.space" ZIPNAME="$BASEDIR.zip" -rm $ZIPNAME -rm $BASEDIR/schemas/gschemas.compiled -rm $BASEDIR/wallpapers/* -glib-compile-schemas $BASEDIR/schemas/ - -cd $BASEDIR -zip -r $ZIPNAME . -mv $ZIPNAME .. \ No newline at end of file +rm "$ZIPNAME" +rm "$BASEDIR/schemas/gschemas.compiled" +rm "$BASEDIR/wallpapers/"* +glib-compile-schemas "$BASEDIR/schemas/" + +# cd "$BASEDIR/ui" || exit 1 +blueprint-compiler batch-compile "$BASEDIR/ui" "$BASEDIR/ui" \ + "$BASEDIR/ui/generic_json.blp" \ + "$BASEDIR/ui/page_general.blp" \ + "$BASEDIR/ui/page_sources.blp" \ + "$BASEDIR/ui/reddit.blp" \ + "$BASEDIR/ui/source_row.blp" \ + "$BASEDIR/ui/unsplash.blp" \ + "$BASEDIR/ui/wallhaven.blp" + +cd "$BASEDIR" || exit 1 +zip -r "$ZIPNAME" . +mv "$ZIPNAME" .. diff --git a/install.sh b/install.sh index 5bf814f2..8c0599e6 100755 --- a/install.sh +++ b/install.sh @@ -1,8 +1,10 @@ #!/bin/bash +datahome="${XDG_DATA_HOME:-HOME/.local/share}" + extensionFolder="randomwallpaper@iflow.space" sourcepath="$PWD/$extensionFolder" -targetpath="/home/$USER/.local/share/gnome-shell/extensions" +targetpath="$datahome/gnome-shell/extensions" if [ "$1" = "uninstall" ]; then echo "# Removing $targetpath/$extensionFolder" diff --git a/randomwallpaper@iflow.space/prefs.js b/randomwallpaper@iflow.space/prefs.js index 0ceec2ff..2156f7b6 100644 --- a/randomwallpaper@iflow.space/prefs.js +++ b/randomwallpaper@iflow.space/prefs.js @@ -1,9 +1,11 @@ +const Adw = imports.gi.Adw; const Gio = imports.gi.Gio; const GLib = imports.gi.GLib; +const GObject = imports.gi.GObject; const Gtk = imports.gi.Gtk; -const Utils = imports.misc.extensionUtils; +const ExtensionUtils = imports.misc.extensionUtils; -const Self = Utils.getCurrentExtension(); +const Self = ExtensionUtils.getCurrentExtension(); const WallpaperController = Self.imports.wallpaperController; const LoggerModule = Self.imports.logger; @@ -17,60 +19,139 @@ function init(metaData) { //Convenience.initTranslations(); } -function buildPrefsWidget() { - let settings = new RandomWallpaperSettings(); - let widget = settings.widget; - widget.show(); +// https://gitlab.gnome.org/GNOME/gjs/-/blob/master/examples/gtk4-template.js +const SourceRow = GObject.registerClass({ + GTypeName: 'SourceRow', + Template: GLib.filename_to_uri(Self.path + '/ui/source_row.ui', null), + Children: [ + 'source_combo', + 'source_settings_container', + 'source_id', + ] +}, class SourceRow extends Adw.ExpanderRow { + constructor(params = {}) { + super(params); + } +}); + +const UnsplashRow = GObject.registerClass({ + GTypeName: 'UnsplashRow', + Template: GLib.filename_to_uri(Self.path + '/ui/unsplash.ui', null), + Children: [ + 'unsplash_keyword', + 'unsplash_featured_only', + 'unsplash_image_width', + 'unsplash_image_height', + 'unsplash_constraint_type', + 'unsplash_constraint_value' + ] +}, class UnsplashRow extends Adw.PreferencesGroup { + constructor(params = {}) { + super(params); + } +}); + +const WallhavenRow = GObject.registerClass({ + GTypeName: 'WallhavenRow', + Template: GLib.filename_to_uri(Self.path + '/ui/wallhaven.ui', null), + Children: [ + 'wallhaven_keyword', + 'wallhaven_api_key', + 'wallhaven_resolutions', + 'wallhaven_allow_sfw', + 'wallhaven_allow_sketchy', + 'wallhaven_allow_nsfw', + 'wallhaven_category_general', + 'wallhaven_category_anime', + 'wallhaven_category_people' + ] +}, class WallhavenRow extends Adw.PreferencesGroup { + constructor(params = {}) { + super(params); + } +}); + +const RedditRow = GObject.registerClass({ + GTypeName: 'RedditRow', + Template: GLib.filename_to_uri(Self.path + '/ui/reddit.ui', null), + Children: [ + 'reddit_allow_sfw', + 'reddit_subreddits' + ] +}, class RedditRow extends Adw.PreferencesGroup { + constructor(params = {}) { + super(params); + } +}); + +const GenericJsonRow = GObject.registerClass({ + GTypeName: 'GenericJsonRow', + Template: GLib.filename_to_uri(Self.path + '/ui/generic_json.ui', null), + Children: [ + 'generic_json_domain', + 'generic_json_request_url', + 'generic_json_image_path', + 'generic_json_image_prefix', + 'generic_json_post_path', + 'generic_json_post_prefix', + 'generic_json_author_name_path', + 'generic_json_author_url_path', + 'generic_json_author_url_prefix' + ] +}, class GenericJsonRow extends Adw.PreferencesGroup { + constructor(params = {}) { + super(params); + } +}); - return widget; +// https://gjs.guide/extensions/development/preferences.html#preferences-window +function fillPreferencesWindow(window) { + new RandomWallpaperSettings(window); } /* UI Setup */ var RandomWallpaperSettings = class { - - constructor() { + constructor(window) { this.logger = new LoggerModule.Logger('RWG3', 'RandomWallpaper.Settings'); this._wallpaperController = null; - this._settings = Utils.getSettings(RWG_SETTINGS_SCHEMA); + this._settings = ExtensionUtils.getSettings(RWG_SETTINGS_SCHEMA); this._builder = new Gtk.Builder(); //this._builder.set_translation_domain(Self.metadata['gettext-domain']); - this._builder.add_from_file(Self.path + '/settings.ui'); + this._builder.add_from_file(Self.path + '/ui/page_general.ui'); + this._builder.add_from_file(Self.path + '/ui/page_sources.ui'); - this.noSettings = this._builder.get_object('no-settings'); + this.source_row = new SourceRow(); + this._builder.get_object('sources_list').add(this.source_row); // Unsplash Settings - this._unsplash_settings = Utils.getSettings(RWG_SETTINGS_SCHEMA_UNSPLASH); - this.unsplashSettings = this._builder.get_object('unsplash-settings'); - this.bindUnsplash(); + this._unsplash_settings = ExtensionUtils.getSettings(RWG_SETTINGS_SCHEMA_UNSPLASH); + this.unsplashSettings = new UnsplashRow(); + this.bindUnsplash(this.unsplashSettings); // Wallhaven Settings - this._wallhaven_settings = Utils.getSettings(RWG_SETTINGS_SCHEMA_WALLHAVEN); - this.wallhavenSettings = this._builder.get_object('wallhaven-settings'); - this.bindWallhaven(); + this._wallhaven_settings = ExtensionUtils.getSettings(RWG_SETTINGS_SCHEMA_WALLHAVEN); + this.wallhavenSettings = new WallhavenRow(); + this.bindWallhaven(this.wallhavenSettings); // Reddit Settings - this._reddit_settings = Utils.getSettings(RWG_SETTINGS_SCHEMA_REDDIT); - this.redditSettings = this._builder.get_object('reddit-settings'); - this.bindReddit(); + this._reddit_settings = ExtensionUtils.getSettings(RWG_SETTINGS_SCHEMA_REDDIT); + this.redditSettings = new RedditRow(); + this.bindReddit(this.redditSettings); // Generic JSON Settings - this._generic_json_settings = Utils.getSettings(RWG_SETTINGS_SCHEMA_GENERIC_JSON); - this.genericJsonSettings = this._builder.get_object('generic-json-settings'); - this.bindGenericJSON(); + this._generic_json_settings = ExtensionUtils.getSettings(RWG_SETTINGS_SCHEMA_GENERIC_JSON); + this.genericJsonSettings = new GenericJsonRow(); + this.bindGenericJSON(this.genericJsonSettings); this._toggleAfSliders(); - this.widget = this._builder.get_object('main-widget'); - - this._builder.get_object('af-switch').connect('notify::active', function (toggleSwitch) { + this._builder.get_object('af_switch').connect('notify::active', function (toggleSwitch) { this._toggleAfSliders(); }.bind(this)); - this._builder.get_object('source-combo').connect('changed', (sourceCombo) => { - let container = this._builder.get_object('source-settings-container'); - + this.source_row.source_combo.connect('changed', (sourceCombo) => { let targetWidget = null; switch (sourceCombo.active) { case 0: // unsplash @@ -92,87 +173,91 @@ var RandomWallpaperSettings = class { } if (targetWidget !== null) { - container.set_child(targetWidget); + this.source_row.source_settings_container.set_child(targetWidget); } }); this._settings.bind('history-length', - this._builder.get_object('history-length'), + this._builder.get_object('history_length'), 'value', Gio.SettingsBindFlags.DEFAULT); this._settings.bind('minutes', - this._builder.get_object('duration-minutes'), + this._builder.get_object('duration_minutes'), 'value', Gio.SettingsBindFlags.DEFAULT); this._settings.bind('hours', - this._builder.get_object('duration-hours'), + this._builder.get_object('duration_hours'), 'value', Gio.SettingsBindFlags.DEFAULT); + // FIXME: I've changed the gsettings schema to int this._settings.bind('source', - this._builder.get_object('source-combo'), - 'active-id', + this.source_row.source_combo, + 'active', Gio.SettingsBindFlags.DEFAULT); this._settings.bind('auto-fetch', - this._builder.get_object('af-switch'), - 'active', + this._builder.get_object('af_switch'), + 'enable-expansion', Gio.SettingsBindFlags.DEFAULT); this._settings.bind('change-lock-screen', - this._builder.get_object('change-lock-screen'), + this._builder.get_object('change_lock_screen'), 'active', Gio.SettingsBindFlags.DEFAULT); this._settings.bind('disable-hover-preview', - this._builder.get_object('disable-hover-preview'), + this._builder.get_object('disable_hover_preview'), 'active', Gio.SettingsBindFlags.DEFAULT) this._settings.bind('hide-panel-icon', - this._builder.get_object('hide-panel-icon'), + this._builder.get_object('hide_panel_icon'), 'active', Gio.SettingsBindFlags.DEFAULT); this._settings.bind('fetch-on-startup', - this._builder.get_object('fetch-on-startup'), + this._builder.get_object('fetch_on_startup'), 'active', Gio.SettingsBindFlags.DEFAULT); this._wallpaperController = new WallpaperController.WallpaperController(true); this._bindButtons(); + + window.add(this._builder.get_object('page_general')); + window.add(this._builder.get_object('page_sources')); } _toggleAfSliders() { - if (this._builder.get_object('af-switch').active) { - this._builder.get_object('duration-slider-hours').set_sensitive(true); - this._builder.get_object('duration-slider-minutes').set_sensitive(true); + if (this._builder.get_object('af_switch').get_enable_expansion()) { + this._builder.get_object('duration_slider_hours').set_sensitive(true); + this._builder.get_object('duration_slider_minutes').set_sensitive(true); } else { - this._builder.get_object('duration-slider-hours').set_sensitive(false); - this._builder.get_object('duration-slider-minutes').set_sensitive(false); + this._builder.get_object('duration_slider_hours').set_sensitive(false); + this._builder.get_object('duration_slider_minutes').set_sensitive(false); } } - bindUnsplash() { + bindUnsplash(widget) { this._unsplash_settings.bind('unsplash-keyword', - this._builder.get_object('unsplash-keyword'), + widget.unsplash_keyword, 'text', Gio.SettingsBindFlags.DEFAULT); this._unsplash_settings.bind('unsplash-image-width', - this._builder.get_object('unsplash-image-width'), + widget.unsplash_image_width, 'value', Gio.SettingsBindFlags.DEFAULT); this._unsplash_settings.bind('unsplash-image-height', - this._builder.get_object('unsplash-image-height'), + widget.unsplash_image_height, 'value', Gio.SettingsBindFlags.DEFAULT); - const unsplash_featured_only = this._builder.get_object('unsplash-featured-only'); + const unsplash_featured_only = widget.unsplash_featured_only; + const unsplash_constraint_type = widget.unsplash_constraint_type; + const unsplash_constraint_value = widget.unsplash_constraint_value; + this._unsplash_settings.bind('unsplash-featured-only', unsplash_featured_only, 'active', Gio.SettingsBindFlags.DEFAULT); - - const unsplash_constraint_type = this._builder.get_object('unsplash-constraint-type'); - const unsplash_constraint_value = this._builder.get_object('unsplash-constraint-value'); - + // FIXME: I've changed the gsettings schema to int this._unsplash_settings.bind('unsplash-constraint-type', unsplash_constraint_type, - 'active-id', + 'active', Gio.SettingsBindFlags.DEFAULT); this._unsplash_settings.bind('unsplash-constraint-value', unsplash_constraint_value, @@ -190,120 +275,133 @@ var RandomWallpaperSettings = class { } _unsplashUnconstrained(combobox, enable, targetElement) { - if(combobox.active_id === 'unconstrained') { + // FIXME: I've changed the gsettings schema to int + if (combobox.active === 0) { targetElement.set_sensitive(enable); } else { targetElement.set_sensitive(!enable); } } - bindWallhaven() { + bindWallhaven(widget) { this._wallhaven_settings.bind('wallhaven-keyword', - this._builder.get_object('wallhaven-keyword'), + widget.wallhaven_keyword, 'text', Gio.SettingsBindFlags.DEFAULT); this._wallhaven_settings.bind('wallhaven-api-key', - this._builder.get_object('wallhaven-api-key'), + widget.wallhaven_api_key, 'text', Gio.SettingsBindFlags.DEFAULT); this._wallhaven_settings.bind('resolutions', - this._builder.get_object('wallhaven-resolutions'), + widget.wallhaven_resolutions, 'text', Gio.SettingsBindFlags.DEFAULT); this._wallhaven_settings.bind('category-general', - this._builder.get_object('wallhaven-category-general'), + widget.wallhaven_category_general, 'active', Gio.SettingsBindFlags.DEFAULT); this._wallhaven_settings.bind('category-anime', - this._builder.get_object('wallhaven-category-anime'), + widget.wallhaven_category_anime, 'active', Gio.SettingsBindFlags.DEFAULT); this._wallhaven_settings.bind('category-people', - this._builder.get_object('wallhaven-category-people'), + widget.wallhaven_category_people, 'active', Gio.SettingsBindFlags.DEFAULT); this._wallhaven_settings.bind('allow-sfw', - this._builder.get_object('wallhaven-allow-sfw'), + widget.wallhaven_allow_sfw, 'active', Gio.SettingsBindFlags.DEFAULT); this._wallhaven_settings.bind('allow-sketchy', - this._builder.get_object('wallhaven-allow-sketchy'), + widget.wallhaven_allow_sketchy, 'active', Gio.SettingsBindFlags.DEFAULT); this._wallhaven_settings.bind('allow-nsfw', - this._builder.get_object('wallhaven-allow-nsfw'), + widget.wallhaven_allow_nsfw, 'active', Gio.SettingsBindFlags.DEFAULT); } - bindReddit() { + bindReddit(widget) { this._reddit_settings.bind('subreddits', - this._builder.get_object('reddit-subreddits'), + widget.reddit_subreddits, 'text', Gio.SettingsBindFlags.DEFAULT); this._reddit_settings.bind('allow-sfw', - this._builder.get_object('reddit-allow-sfw'), + widget.reddit_allow_sfw, 'active', Gio.SettingsBindFlags.DEFAULT); } - bindGenericJSON() { + bindGenericJSON(widget) { this._generic_json_settings.bind('generic-json-id', - this._builder.get_object('generic-json-id'), + this.source_row.source_id, + 'text', + Gio.SettingsBindFlags.DEFAULT); + this._generic_json_settings.bind('generic-json-domain', + widget.generic_json_domain, 'text', Gio.SettingsBindFlags.DEFAULT); this._generic_json_settings.bind('generic-json-request-url', - this._builder.get_object('generic-json-request-url'), + widget.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'), + this._generic_json_settings.bind('generic-json-image-path', + widget.generic_json_image_path, 'text', Gio.SettingsBindFlags.DEFAULT); - this._generic_json_settings.bind('generic-json-url-prefix', - this._builder.get_object('generic-json-url-prefix'), + this._generic_json_settings.bind('generic-json-image-prefix', + widget.generic_json_image_prefix, 'text', Gio.SettingsBindFlags.DEFAULT); - this._generic_json_settings.bind('generic-json-link-path', - this._builder.get_object('generic-json-link-path'), + this._generic_json_settings.bind('generic-json-post-path', + widget.generic_json_post_path, 'text', Gio.SettingsBindFlags.DEFAULT); - this._generic_json_settings.bind('generic-json-link-prefix', - this._builder.get_object('generic-json-link-prefix'), + this._generic_json_settings.bind('generic-json-post-prefix', + widget.generic_json_post_prefix, 'text', Gio.SettingsBindFlags.DEFAULT); - this._generic_json_settings.bind('generic-json-domain', - this._builder.get_object('generic-json-domain'), + this._generic_json_settings.bind('generic-json-author-name-path', + widget.generic_json_author_name_path, + 'text', + Gio.SettingsBindFlags.DEFAULT); + this._generic_json_settings.bind('generic-json-author-url-path', + widget.generic_json_author_url_path, + 'text', + Gio.SettingsBindFlags.DEFAULT); + this._generic_json_settings.bind('generic-json-author-url-prefix', + widget.generic_json_author_url_prefix, 'text', Gio.SettingsBindFlags.DEFAULT); } _bindButtons() { - let newWallpaperButton = this._builder.get_object('request-new-wallpaper'); - let origNewWallpaperText = newWallpaperButton.get_label(); - newWallpaperButton.connect('clicked', () => { - newWallpaperButton.set_label("Loading ..."); + let newWallpaperButton = this._builder.get_object('request_new_wallpaper'); + let origNewWallpaperText = newWallpaperButton.get_child().get_label(); + newWallpaperButton.connect('activated', () => { + newWallpaperButton.get_child().set_label("Loading ..."); newWallpaperButton.set_sensitive(false); this._wallpaperController.update(); this._wallpaperController.fetchNewWallpaper(() => { this._wallpaperController.update(); - newWallpaperButton.set_label(origNewWallpaperText); + newWallpaperButton.get_child().set_label(origNewWallpaperText); newWallpaperButton.set_sensitive(true); }); }); - this._builder.get_object('clear-history').connect('clicked', () => { + this._builder.get_object('clear_history').connect('clicked', () => { this._wallpaperController.update(); this._wallpaperController.deleteHistory(); }); - this._builder.get_object('open-wallpaper-folder').connect('clicked', () => { + this._builder.get_object('open_wallpaper_folder').connect('clicked', () => { let uri = GLib.filename_to_uri(this._wallpaperController.wallpaperlocation, ""); Gio.AppInfo.launch_default_for_uri(uri, Gio.AppLaunchContext.new()); }); } -}; +}; \ No newline at end of file diff --git a/randomwallpaper@iflow.space/schemas/.gitignore b/randomwallpaper@iflow.space/schemas/.gitignore new file mode 100644 index 00000000..a9bbac5d --- /dev/null +++ b/randomwallpaper@iflow.space/schemas/.gitignore @@ -0,0 +1 @@ +gschemas.compiled diff --git a/randomwallpaper@iflow.space/schemas/gschemas.compiled b/randomwallpaper@iflow.space/schemas/gschemas.compiled deleted file mode 100644 index e25444dc68434c2adbd9c1bdf652c62ba660bdc1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3404 zcmb_eTWB0r7(TtEO`1#7+N*d8N@bQhyJ<~J+S0U2X-kbZSglqNI@vwh88ev~=aNk* zP4glMD)^9Ky+M6YidaEG&4a-_cnMO8)Ccjw8x#?YeeuD9m-YM3?AhHEpB4{%`+xJD zf9IU}&;Oruj-0eY$MRxPXd5sX~uAe$iy{S!z z{m>7=egrga6rzl_s~w%9U-ZKE1AbV{7CnDNW+Pj=ZdQ)P(u*A5i?UH*^ zw7h~pQnFk(umTxo$!u#>dU%=9%2%S{Qxy2U_27IkWzhm)ieg#VdYEzHcejX9F#!7r zu<^tm6)*C&&~4ZeK+m0=a}QvrfaiYQt|any_+Ny*1T17qt6>yh1APV$v%um@`}(Mp zw?dzXU5<&)otw)W5f!Ez;#ZWO3@sPlDy|JCdE!NZYehB(W!|ze$GHYv z57s&Jnqd5y-$d|xYX|*UzZg3GV^RTZ0E!&Q~O`Uur^cmPWK*z~+My#SVOHLuSCm9sO$uRGAyf7^l9~c!c zx>Wz0_gz=!RZg;Bt#e(c7sa9Fc(ECe2NJ!Bmq+$0O)@R0v6Yv0lsVsW63GyTb1A#d zu#7~Rb1K)y#FHp@Ah(QhE6HU3Yv57KO*jhjui8B%tvCr~!Sp>>R~+gqEe*c2;rh@+ zusk$3`5m5B$@uzt)Ro7Q`K1eDOQ&d8PO4reF4m>Nl2C=^D&@TO7{UP{%t6V?%H~Sa%vI*Xo{yP*%^9V_)6-InQz4Ayy-v zov_=1(XU@zOP!qY?}ojfdU@|H)X7&d{;(eadcDZ$KL`6KkW3x>mj2{Clbi9-4s5-t z?>KdG?kT)Xm_T#q>+ew~Ul08tY(H?>-|gDI$gAeJxw1(>3&u{7b|-jcA$cz z3OwD{>XHqwDYqb}(tWL#$c>)c$XzRmeRGJH3{H~wmVy&mgRV4fe^iF7o>52gQllFB zW1P~ViK7(Tcjy$0+>LcJ#xk}O#k}>n(ktRhp&Ij*UaU{m_en9?mt_&kvhX zK9uU#%kOTiPP4V;5{BM~bglAP*O0omBiH6J(KRS+otxy$%{JH#0PoZMKRNHyU9j7L ziODP1sFSnix?y?$uVq2w=TrI(+{)58ai6Kb&#JtLlEKsuPL+L^evB)>Q^)yVI3yHI 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 b62b8963..961918bd 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 @@ -2,20 +2,20 @@ - - - - + + + + + id='org.gnome.shell.extensions.space.iflow.randomwallpaper'> 5 History size Number of wallpapers stored locally - + @@ -34,18 +34,18 @@ 30 Duration Minutes to wait before a new wallpaper is fetched - + 1 Duration Minutes to wait before a new wallpaper is fetched - + - - 'unsplash' + + 0 Wallpaper Source Describes the adapter that will be used. @@ -60,7 +60,7 @@ 0 Timestamp of the last timer trigger. A JS timestamp of the last timer callback trigger. Zero if no last change registered. - + @@ -84,14 +84,14 @@ - - - - + + + + + id='org.gnome.shell.extensions.space.iflow.randomwallpaper.unsplash'> "" Keyword @@ -122,25 +122,22 @@ Featured images only This results in a smaller wallpaper pool but the images are considered to have higher quality. - + - - - 'unconstrained' + + 0 Constraint Type The constraint of the Unsplash Source API. - "" Constraint Value This value should match the constraint type for. Has no effect in the case of an unconstrained search. - + id='org.gnome.shell.extensions.space.iflow.randomwallpaper.wallhaven'> "" Keyword @@ -190,7 +187,7 @@ + id='org.gnome.shell.extensions.space.iflow.randomwallpaper.reddit'> "" Subreddits @@ -204,41 +201,56 @@ + id='org.gnome.shell.extensions.space.iflow.randomwallpaper.genericJSON'> "" Identifier Identifier for this source. + + "" + Website URL + Main domain for this source. + "" The request URL The URL where the JSON will be requested. - + "" - JSON Path + Image JSON Path The JSON path that describes the picture URL. - + "" Image URL prefix This prefix is added to the final image URL. - + "" - Link JSON Path - The JSON path that describes the picture link. + Post JSON Path + The JSON path that describes the post link. - + "" - Link prefix - This prefix is added to the final image link. + Post URL prefix + This prefix is added to the post link. - + "" - Website URL - Main domain for this source. + Author name JSON Path + The JSON path that describes the author name path. + + + "" + Author link JSON Path + The JSON path that describes the author link path. + + + "" + Author link URL prefix + This prefix is added to the final author link. diff --git a/randomwallpaper@iflow.space/settings.ui b/randomwallpaper@iflow.space/settings.ui deleted file mode 100644 index 64d735f1..00000000 --- a/randomwallpaper@iflow.space/settings.ui +++ /dev/null @@ -1,1245 +0,0 @@ - - - - - 1 - user-trash - - - 23 - 1 - 1 - 10 - - - 1 - 59 - 30 - 1 - 10 - - - 1 - 10 - 10 - 10 - 10 - vertical - 10 - - - 1 - start - This feature requires some know how. However, many different wallpaper providers can be used with this generic JSON source. - -You have to specify an URL to a JSON response and a path to the target image URL within the JSON response. - -You can also define a prefix that will be added to the image URL. - fill - 1 - - - - - More Information Here - 1 - 1 - 1 - https://github.com/ifl0w/RandomWallpaperGnome3/wiki/Generic-JSON-Source - - - - - 1 - vertical - - - 1 - start - Identifier - - - - - 1 - 1 - Identifier - - - - - - - 1 - vertical - - - 1 - start - Request URL - - - - - 1 - 1 - Request URL - url - - - - - - - 1 - vertical - - - 1 - start - Image JSON Path - - - - - 1 - 1 - Image JSON Path - - - - - - - 1 - vertical - - - 1 - start - Image URL prefix - - - - - 1 - 1 - Image URL prefix - - - - - - - 1 - vertical - - - 1 - start - Link JSON Path - optional - - - - - 1 - 1 - Link JSON Path - optional - - - - - - - 1 - vertical - - - 1 - start - Link prefix - optional - - - - - 1 - 1 - Link prefix - optional - - - - - - - 1 - vertical - - - 1 - start - Website URL - optional - - - - - 1 - 1 - Website URL - optional - - - - - - - 1 - 100 - 10 - 1 - 10 - - - 1 - 10 - 10 - 10 - 10 - No Settings Available - - - - 1 - folder-open - - - 1 - 10 - 10 - 10 - 10 - vertical - - - 1 - start - Subreddits... (comma separated) - - - - - 1 - 1 - e.g.: wallpaper, wallpapers, minimalwallpaper - - - - - 10 - 1 - - - SFW (Safe for work) - 1 - 1 - - - - - - - 1 - emblem-synchronizing-symbolic - 1 - - - 400 - 600 - 1 - - - 1 - 1 - 1 - 1 - - - 1 - - - 1 - 10 - 10 - 10 - 10 - vertical - 10 - - - 1 - - - Request New Wallpaper - 60 - 50 - 1 - 1 - 1 - 5 - 5 - 5 - 5 - - - - - - - - - 1 - - - - 1 - 15 - 15 - 15 - 15 - - - 1 - vertical - 5 - - - 1 - start - Change lock screen - - - - - 1 - 1 - Change the gnome lock screen image to the new wallpaper. - 1 - 1 - 1 - 0 - - - - - - - - 1 - vertical - - - 1 - 1 - end - start - - - - - - - - - - - - 1 - - - - 1 - 15 - 15 - 15 - 15 - - - 1 - vertical - 5 - - - 1 - start - Hide the panel icon - - - - - 1 - 1 - This option hides the panel icon. Therefore, you won't be able to access the history and the settings through the panel menu. Enabling this option currently is only reasonable in conjunction with the Auto-Fetching feature. - 1 - 1 - 1 - 0 - - - - - - 1 - 10 - 1 - Only enable this option if you know how to open the settings without the panel icon! - 1 - 1 - 1 - 0 - - - - - - - - - - - 1 - vertical - - - 1 - 1 - end - start - - - - - - - - - - - - 1 - - - - 1 - 15 - 15 - 15 - 15 - - - 1 - vertical - 5 - - - 1 - start - Disable hover preview - - - - - 1 - 1 - Disable the desktop preview of the background while hovering the history items. Try enabling if you encounter crashes or lags of the gnome-shell while using the extension. - 1 - 1 - 1 - 0 - - - - - - - - 1 - vertical - - - 1 - 1 - end - start - - - - - - - - - - - - - - - - - - 1 - General - - - - - 1 - 1 - 1 - 1 - - - 1 - - - 1 - 10 - 10 - 10 - 10 - vertical - 10 - - - 1 - - - Open Wallpaper Folder - 50 - 1 - 1 - 1 - 5 - 5 - 5 - 5 - - - - - - - - 1 - - - - 1 - 15 - 15 - 15 - 15 - - - 1 - vertical - 5 - - - 1 - start - History length - - - - - 1 - 1 - The number of wallpapers that will be shown in the history and stored in the wallpaper folder of this extension. - 1 - 1 - 0 - - - - - - - - 1 - 1 - center - 10 - history-length - 10 - - - - - - - - - - 1 - - - Clear History - 50 - 1 - 1 - 1 - 5 - 5 - 5 - 5 - - - - - - - - - - - - - - - 1 - History - - - - - 1 - 1 - 1 - 1 - - - 1 - - - 1 - 10 - 10 - 10 - 10 - vertical - 10 - - - 1 - - - - 1 - vertical - 15 - 15 - 15 - 15 - 10 - - - - 1 - 10 - - - - 1 - vertical - 5 - - - 1 - start - Auto-Fetching - - - - - 1 - 1 - Automatically fetch new wallpapers based on an interval. - 1 - 1 - 1 - 0 - - - - - - - - 1 - vertical - - - 1 - 1 - end - start - - - - - - - - - - 1 - 10 - - - 1 - start - center - Hours - - - - - 1 - 1 - 1 - duration-hours - 1 - 0 - 0 - 0 - 0 - 1 - - - - - - - 1 - 10 - - - 1 - start - center - Minutes - - - - - 1 - 1 - 1 - duration-minutes - 1 - 0 - 0 - 0 - 0 - 1 - - - - - - - - - - - - True - False - 0 - - - True - horizontal - 15 - 15 - 15 - 15 - 10 - - - True - vertical - 5 - - - True - False - start - Fetch on startup (experimental) - - - - - 1 - 1 - Fetch a new wallpaper during the startup of the extension. Rebooting your system, and enabling the extension will trigger a new wallpaper request. - 1 - 1 - 1 - 0 - - - - - - 1 - 1 - 10 - WARNING: Do not enable this feature if you observe crashes when requesting new wallpapers! This could render your system unstable as crashes could repeatedly happen on startup! In the case, you encounter such a problem, you will have to disable the extension or the feature manually from the commandline for your user. - 1 - 1 - 1 - 0 - - - - - - - - - - - True - False - vertical - - - True - True - end - start - - - - - - - - - - - - - - - - - 1 - Auto-Fetching - - - - - 1 - 1 - 1 - 1 - - - 1 - - - 1 - vertical - - - 1 - 10 - 10 - 10 - 10 - - - - 1 - 15 - 15 - 15 - 15 - 10 - vertical - - - 1 - vertical - 5 - - - 1 - start - Wallpaper Source - - - - - 1 - 1 - The source that is used to fetch random wallpapers. You can select between built-in ones or the generic JSON source for experienced users. - 1 - 1 - 0 - - - - - - - - 1 - 20 - - - 1 - 0 - - Unsplash - Wallhaven - Reddit - Generic JSON - - - - - - - - 1 - 1 - - - - - - - - - - - - - - - - 1 - Wallpaper Sources - - - - - 1 - 1000000 - 1 - 10 - - - 1 - 1000000 - 1 - 10 - - - 1 - 10 - 10 - 10 - 10 - vertical - - - - 1 - start - Keyword - - - - - 1 - 1 - 10 - Keywords... (comma separated) - - - - - - 1 - 10 - - - 1 - 1 - vertical - 5 - - - 1 - start - Only Featured Images - - - - - 1 - This option results in a smaller wallpaper pool, but the images are considered to be of higher quality. - 1 - 1 - 0 - - - - - - - - 1 - 1 - end - start - - - - - - - - 1 - 10 - 10 - - - 1 - 1 - vertical - - - 1 - start - Image Width - - - - - 1 - 1 - unsplash-image-width - - - - - - - 1 - 1 - vertical - - - 1 - start - Image Height - - - - - 1 - 1 - unsplash-image-height - - - - - - - - - - - start - Constraint Type - - - - - 1 - 0 - 10 - - Unconstrained - User - User's Likes - Collection ID - - - - - - - start - Constraint Value - - - - - 1 - 1 - Username or Collection ID - - - - - 1 - 10 - 10 - 10 - 10 - vertical - - - 1 - start - Keyword - - - - - 1 - 1 - 10 - Keywords... (comma separated) - - - - - 1 - start - Api Key - - - - - 1 - 1 - 10 - The api key, can be empty... - - - - - 1 - start - Allowed Content Ratings - - - - - 1 - - - SFW (Safe for work) - 1 - 1 - - - - - Sketchy - 1 - 1 - - - - - NSFW (API key required) - 1 - 1 - - - - - - - 1 - start - 10 - Categories - - - - - 1 - - - General - 1 - 1 - - - - - Anime - 1 - 1 - - - - - People - 1 - 1 - - - - - - - 1 - 10 - start - Resolutions - - - - - 1 - 1 - 1920x1080, 1920x1200 - - - - diff --git a/randomwallpaper@iflow.space/sourceAdapter.js b/randomwallpaper@iflow.space/sourceAdapter.js index 7a6ce21b..7bce2481 100755 --- a/randomwallpaper@iflow.space/sourceAdapter.js +++ b/randomwallpaper@iflow.space/sourceAdapter.js @@ -58,7 +58,7 @@ var BaseAdapter = class { } _error(err, callback) { - let error = {"error": err}; + let error = { "error": err }; this.logger.error(JSON.stringify(error)); if (callback) { @@ -220,8 +220,8 @@ var WallhavenAdapter = class extends BaseAdapter { let siteURL = entry.url; let apiKey = this.options["apikey"]; - if(apiKey){ - downloadURL += "?apikey="+apiKey; + if (apiKey) { + downloadURL += "?apikey=" + apiKey; } if (callback) { @@ -357,34 +357,54 @@ var GenericJsonAdapter = class extends BaseAdapter { const response_body = JSON.parse(ByteArray.toString(response_body_bytes)); let identifier = this._settings.get("generic-json-id", "string"); - let imageJSONPath = this._settings.get("generic-json-response-path", "string"); - let linkJSONPath = this._settings.get("generic-json-link-path", "string"); + let imageJSONPath = this._settings.get("generic-json-image-path", "string"); + let postJSONPath = this._settings.get("generic-json-post-path", "string"); let domainUrl = this._settings.get("generic-json-domain", "string"); + let authorNameJSONPath = this._settings.get("generic-json-author-name-path", "string"); + let authorUrlJSONPath = this._settings.get("generic-json-author-url-path", "string"); if (identifier === null || identifier === "") { identifier = 'Generic JSON Source'; } let rObject = this._jsonPathParser.access(response_body, imageJSONPath); - let imageDownloadUrl = this._settings.get("generic-json-url-prefix", "string") + rObject.Object; - + let imageDownloadUrl = this._settings.get("generic-json-image-prefix", "string") + rObject.Object; + // '@random' would yield different results so lets make sure the values stay // the same as long as the path is identical - let samePath = imageJSONPath.substring(0, this.findFirstDifference(imageJSONPath, linkJSONPath)); + let samePath = imageJSONPath.substring(0, this.findFirstDifference(imageJSONPath, postJSONPath)); // count occurrences of '@random' to slice the array later // https://stackoverflow.com/a/4009768 let occurrences = (samePath.match(/@random/g) || []).length; + let slicedRandomElements = rObject.RandomElements.slice(0, occurrences); - let linkUrl = this._jsonPathParser.access(response_body, linkJSONPath, rObject.RandomElements.slice(0, occurrences), false).Object; - linkUrl = this._settings.get("generic-json-link-prefix", "string") + linkUrl; + let postUrl = this._jsonPathParser.access(response_body, postJSONPath, slicedRandomElements, false).Object; + postUrl = this._settings.get("generic-json-post-prefix", "string") + postUrl; + if (typeof postUrl !== 'string' || !postUrl instanceof String) { + postUrl = null; + } + + let authorName = this._jsonPathParser.access(response_body, authorNameJSONPath, slicedRandomElements, false).Object; + if (typeof authorName !== 'string' || !authorName instanceof String) { + authorName = null; + } + + let authorUrl = this._jsonPathParser.access(response_body, authorUrlJSONPath, slicedRandomElements, false).Object; + authorUrl = this._settings.get("generic-json-author-url-prefix", "string") + authorUrl; + if (typeof authorUrl !== 'string' || !authorUrl instanceof String) { + authorUrl = null; + } if (callback) { - let historyEntry = new HistoryModule.HistoryEntry(null, identifier, rObject.Object); - historyEntry.source.sourceUrl = imageDownloadUrl; + let historyEntry = new HistoryModule.HistoryEntry(authorName, identifier, imageDownloadUrl); + + if (authorUrl !== null && authorUrl !== "") { + historyEntry.source.authorUrl = authorUrl; + } - if (linkUrl !== null && linkUrl !== "") { - historyEntry.source.imageLinkUrl = linkUrl; + if (postUrl !== null && postUrl !== "") { + historyEntry.source.imageLinkUrl = postUrl; } if (domainUrl !== null && domainUrl !== "") { @@ -401,11 +421,11 @@ var GenericJsonAdapter = class extends BaseAdapter { } // https://stackoverflow.com/a/32859917 - findFirstDifference (jsonPath1, jsonPath2) { + findFirstDifference(jsonPath1, jsonPath2) { let i = 0; if (jsonPath1 === jsonPath2) return -1; while (jsonPath1[i] === jsonPath2[i]) i++; return i; } -}; +}; \ No newline at end of file diff --git a/randomwallpaper@iflow.space/ui/.gitignore b/randomwallpaper@iflow.space/ui/.gitignore new file mode 100644 index 00000000..1a826ead --- /dev/null +++ b/randomwallpaper@iflow.space/ui/.gitignore @@ -0,0 +1 @@ +*.ui diff --git a/randomwallpaper@iflow.space/ui/generic_json.blp b/randomwallpaper@iflow.space/ui/generic_json.blp new file mode 100644 index 00000000..064780a3 --- /dev/null +++ b/randomwallpaper@iflow.space/ui/generic_json.blp @@ -0,0 +1,107 @@ +using Gtk 4.0; +using Adw 1; + +template GenericJsonRow : Adw.PreferencesGroup { + // title: _("Source Settings"); + description: _("This feature requires some know how. However, many different wallpaper providers can be used with this generic JSON source.\nYou have to specify an URL to a JSON response and a path to the target image URL within the JSON response.\nYou can also define a prefix that will be added to the image URL."); + + header-suffix: LinkButton { + valign: center; + uri: "https://github.com/ifl0w/RandomWallpaperGnome3/wiki/Generic-JSON-Source"; + + Adw.ButtonContent { + icon-name: "globe-symbolic"; + } + + styles [ + "flat", + ] + }; + + Adw.PreferencesGroup { + title: _("General"); + + Adw.EntryRow generic_json_domain { + title: _("Domain"); + input-purpose: url; + + LinkButton { + valign: center; + // uri: bind text; + + Adw.ButtonContent { + icon-name: "globe-symbolic"; + } + + styles [ + "flat", + ] + } + } + + Adw.EntryRow generic_json_request_url { + title: _("Request URL"); + input-purpose: url; + + LinkButton { + valign: center; + // uri: bind text; + + Adw.ButtonContent { + icon-name: "globe-symbolic"; + } + + styles [ + "flat", + ] + } + } + } + + Adw.PreferencesGroup { + title: _("Image"); + + Adw.EntryRow generic_json_image_path { + title: _("JSON Path"); + input-purpose: free_form; + } + + Adw.EntryRow generic_json_image_prefix { + title: _("URL prefix"); + input-purpose: free_form; + } + } + + Adw.PreferencesGroup { + title: _("Post"); + + Adw.EntryRow generic_json_post_path { + title: _("JSON Path"); + input-purpose: free_form; + } + + Adw.EntryRow generic_json_post_prefix { + title: _("URL Prefix"); + input-purpose: free_form; + } + } + + Adw.PreferencesGroup { + title: _("Author"); + + Adw.EntryRow generic_json_author_name_path { + title: _("Name JSON Path"); + input-purpose: free_form; + } + + Adw.EntryRow generic_json_author_url_path { + title: _("URL JSON Path"); + input-purpose: free_form; + } + + Adw.EntryRow generic_json_author_url_prefix { + title: _("URL URL prefix"); + input-purpose: free_form; + } + } +} diff --git a/randomwallpaper@iflow.space/ui/page_general.blp b/randomwallpaper@iflow.space/ui/page_general.blp new file mode 100644 index 00000000..e2fcf746 --- /dev/null +++ b/randomwallpaper@iflow.space/ui/page_general.blp @@ -0,0 +1,161 @@ +using Gtk 4.0; +using Adw 1; + +Adw.PreferencesPage page_general { + title: _("General"); + icon-name: "preferences-system-symbolic"; + + Adw.PreferencesGroup { + Adw.ActionRow request_new_wallpaper { + title: _("Request New Wallpaper"); + activatable: true; + + styles [ + "suggested-action", + "title-3", + ] + + // I don't know how to center the title so just overwrite it with a label + child: Label { + label: _("Request New Wallpaper"); + height-request: 50; + }; + } + } + + Adw.PreferencesGroup { + title: _("General Settings"); + + Adw.ActionRow { + title: _("Change lock screen"); + subtitle: _("Change the gnome lock screen image to the new wallpaper."); + + Switch change_lock_screen { + valign: center; + } + } + + Adw.ActionRow { + title: _("Hide the panel icon"); + subtitle: _("You won't be able to access the history and the settings through the panel menu. Enabling this option currently is only reasonable in conjunction with the Auto-Fetching feature.\nOnly enable this option if you know how to open the settings without the panel icon!"); + + Switch hide_panel_icon { + valign: center; + } + } + + Adw.ActionRow { + title: _("Disable hover preview"); + subtitle: _("Disable the desktop preview of the background while hovering the history items. Try enabling if you encounter crashes or lags of the gnome-shell while using the extension."); + + Switch disable_hover_preview { + valign: center; + } + } + } + + Adw.PreferencesGroup { + title: _("History"); + + Adw.ActionRow { + title: _("History length"); + subtitle: _("The number of wallpapers that will be shown in the history and stored in the wallpaper folder of this extension."); + + SpinButton { + valign: center; + numeric: true; + + adjustment: Adjustment history_length { + lower: 1; + upper: 100; + value: 10; + step-increment: 1; + page-increment: 10; + }; + } + } + + header-suffix: Box { + spacing: 14; + + Button open_wallpaper_folder { + Adw.ButtonContent { + icon-name: "folder-open-symbolic"; + label: _("Open"); + } + + styles [ + "flat", + ] + } + + Button clear_history { + Adw.ButtonContent { + icon-name: "user-trash-symbolic"; + label: _("Delete"); + } + + styles [ + "destructive-action", + ] + } + }; + } + + Adw.PreferencesGroup { + title: "Auto-Fetching"; + + Adw.ExpanderRow af_switch { + title: _("Auto-Fetching"); + subtitle: _("Automatically fetch new wallpapers based on an interval."); + show-enable-switch: true; + + Adw.ActionRow { + title: _("Hours"); + + Scale duration_slider_hours { + draw-value: true; + orientation: horizontal; + hexpand: true; + digits: 0; + + adjustment: Adjustment duration_hours { + value: 1; + step-increment: 1; + page-increment: 10; + lower: 0; + upper: 23; + }; + } + } + + Adw.ActionRow { + title: _("Minutes"); + + Scale duration_slider_minutes { + draw-value: true; + orientation: horizontal; + hexpand: true; + digits: 0; + + adjustment: Adjustment duration_minutes { + value: 30; + step-increment: 1; + page-increment: 10; + lower: 1; + upper: 59; + }; + } + } + } + + Adw.ActionRow { + title: _("Fetch on startup (experimental)"); + subtitle: _("Fetch a new wallpaper during the startup of the extension. Rebooting your system, and enabling the extension will trigger a new wallpaper request.\nWARNING: Do not enable this feature if you observe crashes when requesting new wallpapers! This could render your system unstable as crashes could repeatedly happen on startup! In the case, you encounter such a problem, you will have to disable the extension or the feature manually from the commandline for your user."); + + Switch fetch_on_startup { + valign: center; + } + } + } +} diff --git a/randomwallpaper@iflow.space/ui/page_sources.blp b/randomwallpaper@iflow.space/ui/page_sources.blp new file mode 100644 index 00000000..0dbce0ac --- /dev/null +++ b/randomwallpaper@iflow.space/ui/page_sources.blp @@ -0,0 +1,24 @@ +using Gtk 4.0; +using Adw 1; + +Adw.PreferencesPage page_sources { + title: _("Wallpaper Sources"); + icon-name: "download-symbolic"; + + Adw.PreferencesGroup sources_list { + title: _("Configured Wallpaper Sources"); + + // Placeholder + header-suffix: Button { + sensitive: false; + styles [ + "suggested-action", + ] + + Adw.ButtonContent { + icon-name: "add-symbolic"; + label: _("Add Source"); + } + }; + } +} diff --git a/randomwallpaper@iflow.space/ui/reddit.blp b/randomwallpaper@iflow.space/ui/reddit.blp new file mode 100644 index 00000000..c84237ba --- /dev/null +++ b/randomwallpaper@iflow.space/ui/reddit.blp @@ -0,0 +1,19 @@ +using Gtk 4.0; +using Adw 1; + +template RedditRow : Adw.PreferencesGroup { + // title: _("Source Settings"); + + Adw.EntryRow reddit_subreddits { + title: _("Subreddits - e.g.: wallpaper, wallpapers, minimalwallpaper"); + } + + Adw.ActionRow { + title: "SFW"; + subtitle: _("Safe for work"); + + Switch reddit_allow_sfw { + valign: center; + } + } +} diff --git a/randomwallpaper@iflow.space/ui/source_row.blp b/randomwallpaper@iflow.space/ui/source_row.blp new file mode 100644 index 00000000..d0af044f --- /dev/null +++ b/randomwallpaper@iflow.space/ui/source_row.blp @@ -0,0 +1,102 @@ +using Gtk 4.0; +using Adw 1; + +template SourceRow : Adw.ExpanderRow { + title: bind source_id.text; + subtitle: bind enabled.active; + + Box { + orientation: vertical; + spacing: 14; + + Adw.EntryRow source_id { + title: _("Identifier - Currently only used for Generic JSON Sources"); + input-purpose: free_form; + text: _("My Source - (1080p)"); + } + + Adw.ActionRow { + title: _("Type"); + + ComboBoxText source_combo { + valign: center; + active: 0; + + items [ + "Unsplash", + "Wallhaven", + "Reddit", + _("Generic JSON"), + ] + } + } + + // Don't know how I can connect a change signal to a Adw.ComboRow - nothing works + // Adw.ComboRow source_combo { + // title: _("Type"); + // use-subtitle: true; + + // model: StringList { + // strings [ + // "Unsplash", + // "Wallhaven", + // "Reddit", + // _("Generic JSON"), + // ] + // }; + // Adw.EnumListModel { ?????? + // enum-type: string; + + // Adw.EnumListItem [ + // { + // value: 0; + // nick: "Unsplash"; + // }, { + // value: 1; + // nick: "Wallhaven"; + // }, { + // value: 2; + // nick: "Reddit"; + // }, { + // value: 3; + // nick: _("Generic JSON"); + // }, + // ] + // }; + // } + + Adw.ActionRow { + title: _("Enabled"); + // Placeholder + sensitive: false; + + Switch enabled { + valign: center; + active: true; + } + } + + Adw.ActionRow { + title: _("Delete this source"); + + Button { + // Placeholder + sensitive: false; + valign: center; + + styles [ + "destructive-action", + ] + + Adw.ButtonContent { + icon-name: "user-trash-symbolic"; + valign: center; + } + } + } + + Adw.Clamp source_settings_container { + sensitive: bind enabled.active; + } + } +} diff --git a/randomwallpaper@iflow.space/ui/unsplash.blp b/randomwallpaper@iflow.space/ui/unsplash.blp new file mode 100644 index 00000000..7b6801b8 --- /dev/null +++ b/randomwallpaper@iflow.space/ui/unsplash.blp @@ -0,0 +1,89 @@ +using Gtk 4.0; +using Adw 1; + +template UnsplashRow : Adw.PreferencesGroup { + // title: _("Source Settings"); + + Adw.EntryRow unsplash_keyword { + title: _("Keywords - Comma seperated"); + input-purpose: free_form; + } + + Adw.ActionRow { + title: _("Only Featured Images"); + subtitle: _("This option results in a smaller image pool, but the images are considered to be of higher quality."); + + Switch unsplash_featured_only { + valign: center; + } + } + + Adw.ActionRow { + title: _("Image Dimensions"); + + SpinButton { + valign: center; + numeric: true; + + adjustment: Adjustment unsplash_image_width { + step-increment: 1; + page-increment: 10; + lower: 1; + upper: 1000000; + }; + } + + Label { + label: "x"; + } + + SpinButton { + valign: center; + numeric: true; + + adjustment: Adjustment unsplash_image_height { + step-increment: 1; + page-increment: 10; + lower: 1; + upper: 1000000; + }; + } + } + + Adw.PreferencesGroup { + title: _("Contraint"); + + Adw.ActionRow { + title: _("Type"); + + ComboBoxText unsplash_constraint_type { + valign: center; + active: 0; + + items [ + _("Unconstraint"), + _("User"), + _("User's Likes"), + _("Collection ID"), + ] + } + } + + // Don't know how I can connect a change signal to a Adw.ComboRow - nothing works + // Adw.ComboRow unsplash_constraint_type { + // title: _("Type"); + // model: StringList { + // strings [ + // _("Unconstraint"), + // _("User"), + // _("User's Likes"), + // _("Collection ID"), + // ] + // }; + // } + + Adw.EntryRow unsplash_constraint_value { + title: _("Value"); + } + } +} diff --git a/randomwallpaper@iflow.space/ui/wallhaven.blp b/randomwallpaper@iflow.space/ui/wallhaven.blp new file mode 100644 index 00000000..ba2dae9b --- /dev/null +++ b/randomwallpaper@iflow.space/ui/wallhaven.blp @@ -0,0 +1,97 @@ +using Gtk 4.0; +using Adw 1; + +template WallhavenRow : Adw.PreferencesGroup { + // title: _("Source Settings"); + + Adw.PreferencesGroup { + title: _("General"); + + Adw.EntryRow wallhaven_keyword { + title: _("Keywords - Comma seperated"); + input-purpose: free_form; + } + + Adw.PasswordEntryRow wallhaven_api_key { + title: _("API key"); + input-purpose: password; + + LinkButton { + valign: center; + uri: "https://wallhaven.cc/settings/account"; + + Adw.ButtonContent { + icon-name: "globe-symbolic"; + } + + styles [ + "flat", + ] + } + } + + Adw.EntryRow wallhaven_resolutions { + title: _("Resolutions: 1920x1080, 2560x1440"); + input-purpose: free_form; + text: ""; + } + } + + Adw.PreferencesGroup { + title: _("Allowed content ratings"); + + Adw.ActionRow { + title: "SFW"; + subtitle: _("Safe for work"); + + Switch wallhaven_allow_sfw { + valign: center; + } + } + + Adw.ActionRow { + title: "Sketchy"; + + Switch wallhaven_allow_sketchy { + valign: center; + } + } + + Adw.ActionRow { + title: "NSFW"; + subtitle: _("Not safe for work"); + + Switch wallhaven_allow_nsfw { + valign: center; + } + } + } + + Adw.PreferencesGroup { + title: _("Categories"); + + Adw.ActionRow { + title: "General"; + + Switch wallhaven_category_general { + valign: center; + } + } + + Adw.ActionRow { + title: "Anime"; + + Switch wallhaven_category_anime { + valign: center; + } + } + + Adw.ActionRow { + title: "People"; + + Switch wallhaven_category_people { + valign: center; + } + } + } +} diff --git a/randomwallpaper@iflow.space/wallpaperController.js b/randomwallpaper@iflow.space/wallpaperController.js index afb147e6..ca3699d9 100644 --- a/randomwallpaper@iflow.space/wallpaperController.js +++ b/randomwallpaper@iflow.space/wallpaperController.js @@ -98,7 +98,8 @@ var WallpaperController = class { _requestRandomImageFromAdapter(callback) { this.imageSourceAdapter = this._unsplashAdapter; - switch (this._settings.get('source', 'enum')) { + // FIXME: gsettings schema changed from enum to int + switch (this._settings.get('source', 'int')) { case 0: this.imageSourceAdapter = this._unsplashAdapter; break;