diff --git a/randomwallpaper@iflow.space/prefs.js b/randomwallpaper@iflow.space/prefs.js
index baea0b1..5d194a0 100644
--- a/randomwallpaper@iflow.space/prefs.js
+++ b/randomwallpaper@iflow.space/prefs.js
@@ -17,6 +17,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_WALLHAVEN = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.wallhaven';
+const RWG_SETTINGS_SCHEMA_REDDIT = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.reddit';
const RWG_SETTINGS_SCHEMA_GENERIC_JSON = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.genericJSON';
const LoggerModule = Self.imports.logger;
@@ -44,6 +45,7 @@ var RandomWallpaperSettings = new Lang.Class({
desktopperSettings: null,
unsplashSettings: null,
wallhavenSettings: null,
+ redditSettings: null,
genericJsonSettings: null,
_wallpaperController: null,
@@ -73,6 +75,11 @@ var RandomWallpaperSettings = new Lang.Class({
this.wallhavenSettings = this._builder.get_object('wallhaven-settings');
this.bindWallhaven();
+ // Reddit Settings
+ this._reddit_settings = Convenience.getSettings(RWG_SETTINGS_SCHEMA_REDDIT);
+ this.redditSettings = this._builder.get_object('reddit-settings');
+ this.bindReddit();
+
// Generic JSON Settings
this._generic_json_settings = Convenience.getSettings(RWG_SETTINGS_SCHEMA_GENERIC_JSON);
this.genericJsonSettings = this._builder.get_object('generic-json-settings');
@@ -102,7 +109,10 @@ var RandomWallpaperSettings = new Lang.Class({
case 2: // wallhaven
this.currentSourceSettingsWidget = this.wallhavenSettings;
break;
- case 3: // generic JSON
+ case 3: // reddit
+ this.currentSourceSettingsWidget = this.redditSettings;
+ break;
+ case 4: // generic JSON
this.currentSourceSettingsWidget = this.genericJsonSettings;
break;
default:
@@ -227,6 +237,17 @@ var RandomWallpaperSettings = new Lang.Class({
Gio.SettingsBindFlags.DEFAULT);
},
+ bindReddit: function () {
+ this._reddit_settings.bind('subreddits',
+ this._builder.get_object('reddit-subreddits'),
+ 'text',
+ Gio.SettingsBindFlags.DEFAULT);
+ this._reddit_settings.bind('allow-sfw',
+ this._builder.get_object('reddit-allow-sfw'),
+ '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',
diff --git a/randomwallpaper@iflow.space/schemas/gschemas.compiled b/randomwallpaper@iflow.space/schemas/gschemas.compiled
index bee5c6b..3f9c5ec 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 0911d56..3a6d22b 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,7 +5,8 @@
-
+
+
+
+
+ ""
+ Subreddits
+ These subreddits will be searched.
+
+
+ false
+ SFW
+ Whether safe images are allowed.
+
+
+
diff --git a/randomwallpaper@iflow.space/settings.ui b/randomwallpaper@iflow.space/settings.ui
index 535014a..5c65552 100644
--- a/randomwallpaper@iflow.space/settings.ui
+++ b/randomwallpaper@iflow.space/settings.ui
@@ -199,6 +199,93 @@ You can also define a prefix that will be added to the image URL.
1
10
+
+
+
+
+ True
+ False
+ gtk-refresh
+
+
+ True
+ False
+ gtk-delete
+
400
600
@@ -727,6 +814,7 @@ You can also define a prefix that will be added to the image URL.
- unsplash.com
- desktoppr.co
- alpha.wallhaven.cc
+ - reddit
- Generic JSON
@@ -1213,33 +1301,6 @@ You can also define a prefix that will be added to the image URL.
-
- True
- False
- 10
- 10
- 10
- 10
- No Settings Available
-
-
-
- True
- False
- gtk-open
-
-
- True
- False
- gtk-refresh
-
-
- True
- False
- gtk-delete
-
1
1000000
diff --git a/randomwallpaper@iflow.space/sourceAdapter.js b/randomwallpaper@iflow.space/sourceAdapter.js
index a9f2f7e..8c6de28 100644
--- a/randomwallpaper@iflow.space/sourceAdapter.js
+++ b/randomwallpaper@iflow.space/sourceAdapter.js
@@ -8,6 +8,7 @@ const Json = imports.gi.Json;
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_WALLHAVEN = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.wallhaven';
+const RWG_SETTINGS_SCHEMA_REDDIT = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.reddit';
const RWG_SETTINGS_SCHEMA_GENERIC_JSON = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.genericJSON';
const SettingsModule = Self.imports.settings;
@@ -352,6 +353,59 @@ var WallhavenAdapter = new Lang.Class({
}
});
+var RedditAdapter = new Lang.Class({
+ Name: "RedditAdapter",
+ Extends: BaseAdapter,
+
+ _settings: null,
+
+ _init: function () {
+ this.parent();
+ this._settings = new SettingsModule.Settings(RWG_SETTINGS_SCHEMA_REDDIT);
+ },
+
+ requestRandomImage: function (callback) {
+ let session = new Soup.SessionAsync();
+
+ const subreddits = this._settings.get('subreddits', 'string').split(',').map(s => s.trim()).join('+');
+ const require_sfw = this._settings.get('allow-sfw', 'boolean');
+ const url = encodeURI(`https://www.reddit.com/r/${subreddits}.json`);
+
+ let message = Soup.Message.new('GET', url);
+
+ if (message === null) {
+ this._error("Could not create request.", callback);
+ return;
+ }
+
+ session.queue_message(message, (session, message) => {
+ try {
+ const submissions = JSON.parse(message.response_body.data).data.children.filter(child => {
+ if(child.data.post_hint !== 'image') return false;
+ if(require_sfw) return child.data.over_18 === false;
+ return true;
+ });
+ if(submissions.length === 0) {
+ this._error("No suitable submissions found!", callback);
+ return;
+ }
+ const random = Math.floor(Math.random() * submissions.length);
+ const submission = submissions[random].data;
+ const imageDownloadUrl = submission.preview.images[0].source.url;
+
+ if (callback) {
+ let historyEntry = new HistoryModule.HistoryEntry(null, 'reddit', imageDownloadUrl);
+ historyEntry.source.sourceUrl = 'https://www.reddit.com/' + submission.permalink;
+ callback(historyEntry);
+ }
+ } catch (e) {
+ this._error("Could not create request. (" + e + ")", callback);
+ return;
+ }
+ });
+ }
+});
+
var GenericJsonAdapter = new Lang.Class({
Name: "GenericJsonAdapter",
Extends: BaseAdapter,
diff --git a/randomwallpaper@iflow.space/wallpaperController.js b/randomwallpaper@iflow.space/wallpaperController.js
index f9e9e23..b9d2901 100644
--- a/randomwallpaper@iflow.space/wallpaperController.js
+++ b/randomwallpaper@iflow.space/wallpaperController.js
@@ -54,6 +54,7 @@ var WallpaperController = new Lang.Class({
this._desktopperAdapter = new SourceAdapter.DesktopperAdapter();
this._unsplashAdapter = new SourceAdapter.UnsplashAdapter();
this._wallhavenAdapter = new SourceAdapter.WallhavenAdapter();
+ this._redditAdapter = new SourceAdapter.RedditAdapter();
this._genericJsonAdapter = new SourceAdapter.GenericJsonAdapter();
this._updateHistory();
@@ -98,6 +99,9 @@ var WallpaperController = new Lang.Class({
this.imageSourceAdapter = this._wallhavenAdapter;
break;
case 3:
+ this.imageSourceAdapter = this._redditAdapter;
+ break;
+ case 4:
this.imageSourceAdapter = this._genericJsonAdapter;
break;
default: