RandomWallpaperGnome3/randomwallpaper@iflow.space/prefs.js

281 lines
9.3 KiB
JavaScript
Raw Permalink Normal View History

2017-02-04 23:48:52 +00:00
const Gio = imports.gi.Gio;
2016-04-08 16:40:52 +00:00
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
2017-02-04 23:48:52 +00:00
const ExtensionUtils = imports.misc.extensionUtils;
2016-04-08 16:40:52 +00:00
2017-02-04 23:48:52 +00:00
const Self = ExtensionUtils.getCurrentExtension();
const Convenience = Self.imports.convenience;
2016-04-08 16:40:52 +00:00
const WallpaperController = Self.imports.wallpaperController;
2017-02-04 23:48:52 +00:00
const RWG_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.space.iflow.randomwallpaper';
2017-07-20 18:54:23 +00:00
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';
2018-08-12 21:43:30 +00:00
const RWG_SETTINGS_SCHEMA_REDDIT = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.reddit';
2017-10-07 15:08:35 +00:00
const RWG_SETTINGS_SCHEMA_GENERIC_JSON = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.genericJSON';
2017-07-20 18:54:23 +00:00
const LoggerModule = Self.imports.logger;
2016-04-08 16:40:52 +00:00
function init(metaData) {
//Convenience.initTranslations();
2016-04-08 16:40:52 +00:00
}
function buildPrefsWidget() {
let settings = new RandomWallpaperSettings();
let widget = settings.widget;
widget.show_all();
2016-04-08 16:40:52 +00:00
return widget;
2016-04-08 16:40:52 +00:00
}
/* UI Setup */
var RandomWallpaperSettings = class {
2017-07-20 18:54:23 +00:00
constructor() {
this.logger = new LoggerModule.Logger('RWG3', 'RandomWallpaper.Settings');
2017-07-20 18:54:23 +00:00
this.currentSourceSettingsWidget = null;
2017-02-04 23:48:52 +00:00
this._wallpaperController = null;
this._settings = Convenience.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');
2017-02-04 23:48:52 +00:00
2017-07-20 18:54:23 +00:00
this.noSettings = this._builder.get_object('no-settings');
// Desktopper Settings
this._desktopper_settings = Convenience.getSettings(RWG_SETTINGS_SCHEMA_DESKTOPPER);
this.desktopperSettings = this._builder.get_object('desktopper-settings');
this.bindDesktopper();
// Unsplash Settings
this._unsplash_settings = Convenience.getSettings(RWG_SETTINGS_SCHEMA_UNSPLASH);
this.unsplashSettings = this._builder.get_object('unsplash-settings');
this.bindUnsplash();
// Wallhaven Settings
this._wallhaven_settings = Convenience.getSettings(RWG_SETTINGS_SCHEMA_WALLHAVEN);
this.wallhavenSettings = this._builder.get_object('wallhaven-settings');
this.bindWallhaven();
2017-07-20 18:54:23 +00:00
2018-08-12 21:43:30 +00:00
// Reddit Settings
this._reddit_settings = Convenience.getSettings(RWG_SETTINGS_SCHEMA_REDDIT);
this.redditSettings = this._builder.get_object('reddit-settings');
this.bindReddit();
2017-10-07 15:08:35 +00:00
// 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();
2017-02-04 23:48:52 +00:00
this.widget = this._builder.get_object('main-widget');
2017-02-04 23:48:52 +00:00
this._builder.get_object('af-switch').connect('notify::active', function (toggleSwitch) {
this._toggleAfSliders();
}.bind(this));
2017-02-04 23:48:52 +00:00
2017-07-20 18:54:23 +00:00
this._builder.get_object('source-combo').connect('changed', (sourceCombo) => {
2017-10-07 15:08:35 +00:00
let container = this._builder.get_object('source-settings-container');
2017-07-20 18:54:23 +00:00
if (this.currentSourceSettingsWidget !== null) {
container.remove(this.currentSourceSettingsWidget);
}
switch (sourceCombo.active) {
case 0: // unsplash
2017-07-20 18:54:23 +00:00
this.currentSourceSettingsWidget = this.unsplashSettings;
break;
case 1: // desktopper
this.currentSourceSettingsWidget = this.desktopperSettings;
break;
case 2: // wallhaven
this.currentSourceSettingsWidget = this.wallhavenSettings;
2017-07-20 18:54:23 +00:00
break;
2018-08-12 21:43:30 +00:00
case 3: // reddit
this.currentSourceSettingsWidget = this.redditSettings;
break;
case 4: // generic JSON
2017-10-07 15:08:35 +00:00
this.currentSourceSettingsWidget = this.genericJsonSettings;
break;
2017-07-20 18:54:23 +00:00
default:
this.currentSourceSettingsWidget = this.noSettings;
break;
}
container.add(this.currentSourceSettingsWidget);
});
this._settings.bind('history-length',
this._builder.get_object('history-length'),
'value',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('minutes',
this._builder.get_object('duration-minutes'),
'value',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('hours',
this._builder.get_object('duration-hours'),
'value',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('source',
this._builder.get_object('source-combo'),
'active-id',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('auto-fetch',
this._builder.get_object('af-switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
2017-07-22 19:56:17 +00:00
this._settings.bind('change-lock-screen',
this._builder.get_object('change-lock-screen'),
'active',
Gio.SettingsBindFlags.DEFAULT);
2017-10-07 12:45:38 +00:00
this._settings.bind('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'),
'active',
2017-10-07 12:45:38 +00:00
Gio.SettingsBindFlags.DEFAULT);
this._wallpaperController = new WallpaperController.WallpaperController();
this._bindButtons();
}
2016-04-08 16:40:52 +00:00
_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);
} else {
this._builder.get_object('duration-slider-hours').set_sensitive(false);
this._builder.get_object('duration-slider-minutes').set_sensitive(false);
}
}
2017-07-20 18:54:23 +00:00
bindDesktopper() {
2017-07-20 18:54:23 +00:00
this._desktopper_settings.bind('allow-unsafe',
this._builder.get_object('desktopper-allow-unsafe'),
'active',
Gio.SettingsBindFlags.DEFAULT);
}
2017-07-20 18:54:23 +00:00
bindUnsplash() {
2017-07-20 18:54:23 +00:00
this._unsplash_settings.bind('unsplash-keyword',
this._builder.get_object('unsplash-keyword'),
'text',
Gio.SettingsBindFlags.DEFAULT);
this._unsplash_settings.bind('unsplash-username',
2017-07-20 18:54:23 +00:00
this._builder.get_object('unsplash-username'),
'text',
Gio.SettingsBindFlags.DEFAULT);
this._unsplash_settings.bind('unsplash-collections',
this._builder.get_object('unsplash-collections'),
'text',
Gio.SettingsBindFlags.DEFAULT);
2017-07-20 18:54:23 +00:00
this._unsplash_settings.bind('image-width',
this._builder.get_object('unsplash-image-width'),
'value',
Gio.SettingsBindFlags.DEFAULT);
this._unsplash_settings.bind('image-height',
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);
}
2017-07-20 18:54:23 +00:00
bindWallhaven() {
this._wallhaven_settings.bind('wallhaven-keyword',
this._builder.get_object('wallhaven-keyword'),
2017-07-20 18:54:23 +00:00
'text',
Gio.SettingsBindFlags.DEFAULT);
this._wallhaven_settings.bind('resolutions',
this._builder.get_object('wallhaven-resolutions'),
2017-07-20 18:54:23 +00:00
'text',
Gio.SettingsBindFlags.DEFAULT);
this._wallhaven_settings.bind('category-general',
this._builder.get_object('wallhaven-category-general'),
2017-07-20 18:54:23 +00:00
'active',
Gio.SettingsBindFlags.DEFAULT);
this._wallhaven_settings.bind('category-anime',
this._builder.get_object('wallhaven-category-anime'),
2017-07-20 18:54:23 +00:00
'active',
Gio.SettingsBindFlags.DEFAULT);
this._wallhaven_settings.bind('category-people',
this._builder.get_object('wallhaven-category-people'),
2017-07-20 18:54:23 +00:00
'active',
Gio.SettingsBindFlags.DEFAULT);
this._wallhaven_settings.bind('allow-sfw',
this._builder.get_object('wallhaven-allow-sfw'),
2017-07-20 18:54:23 +00:00
'active',
Gio.SettingsBindFlags.DEFAULT);
this._wallhaven_settings.bind('allow-sketchy',
this._builder.get_object('wallhaven-allow-sketchy'),
2017-07-20 18:54:23 +00:00
'active',
Gio.SettingsBindFlags.DEFAULT);
}
2017-10-07 15:08:35 +00:00
bindReddit() {
2018-08-12 21:43:30 +00:00
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);
}
2018-08-12 21:43:30 +00:00
bindGenericJSON() {
2017-10-07 15:08:35 +00:00
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);
}
_bindButtons() {
let newWallpaperButton = this._builder.get_object('request-new-wallpaper');
2018-08-03 15:01:43 +00:00
let origNewWallpaperText = newWallpaperButton.get_label();
newWallpaperButton.connect('clicked', () => {
newWallpaperButton.set_label("Loading ...");
2018-08-03 15:01:43 +00:00
newWallpaperButton.set_sensitive(false);
2018-08-03 15:01:43 +00:00
this._wallpaperController.update();
this._wallpaperController.fetchNewWallpaper(() => {
this._wallpaperController.update();
2018-08-03 15:01:43 +00:00
newWallpaperButton.set_label(origNewWallpaperText);
newWallpaperButton.set_sensitive(true);
});
});
this._builder.get_object('clear-history').connect('clicked', () => {
this._wallpaperController.update();
this._wallpaperController.deleteHistory();
});
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());
});
}
2017-02-04 23:48:52 +00:00
};