diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0defb5c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+**/*~
diff --git a/README.md b/README.md
index 16d5ac0..6bbc023 100644
--- a/README.md
+++ b/README.md
@@ -3,14 +3,22 @@ RandomWallpaperGnome3
Random Wallpapers for Gnome 3 is a gnome shell extension which fetches a random wallpaper from an online source and sets it as desktop background.
-## Installation
+## Installation
Open the commandline and type the following lines:
```
git clone git@github.com:ifl0w/RandomWallpaperGnome3.git
-cp RandomWallpaperGnome3/randomwallpaper@iflow.productions ~/.local/share/gnome-shell/extensions/
+cd ~/.local/share/gnome-shell/extensions/
+ln -s /path/to/source/randomwallpaper@iflow.productions .
```
Then open the command prompt (Alt+F2) end enter `r` without qotes.
Now you should be able to activate the extension through the gnome-tweak-tool.
+
+## Debuging
+Debuging can be started via `sh debug.sh`. Information can be printed with `global.log()`.
+To debug the prefs.js use `sh debug.sh perfs`. In this case you should print debug messages with `print()`.
+
+## Compiling schemas
+This can be done with the command: `glib-compile-schemas schemas/`
diff --git a/debug.sh b/debug.sh
new file mode 100644
index 0000000..2fdc876
--- /dev/null
+++ b/debug.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+if [[ $1 == 'prefs' ]]; then
+ gnome-shell-extension-prefs randomwallpaper@iflow.space
+else
+ journalctl -f /usr/bin/gnome-shell
+fi
diff --git a/randomwallpaper@iflow.space/Timer.js b/randomwallpaper@iflow.space/Timer.js
new file mode 100644
index 0000000..931df0c
--- /dev/null
+++ b/randomwallpaper@iflow.space/Timer.js
@@ -0,0 +1,39 @@
+const Lang = imports.lang;
+const GLib = imports.gi.GLib;
+const Convenience = Self.imports.convenience;
+
+let AFTimer = new Lang.Class({
+
+ _timeout: null,
+ _timoutEndCallback: null,
+
+ _init: function() {
+ this._settings = Convenience.getSettings();
+ this._settings.connect('changed::minutes_elapsed', this._loadSettings.bind(this));
+ this._settings.connect('changed::minutes_', this._loadSettings.bind(this));
+ }
+
+ registerCallback: function(callback) {
+ this._timoutEndCallback = callback;
+ }
+
+ start: function(delay) {
+ if (this._timeout) {
+ this.stop();
+ }
+
+ // TODO: calc elapsed time
+ // TODO: check > 0
+
+ this._timeout = GLib.timeout_add(, delay, function() {
+
+ });
+ }
+
+ stop: function(delay, callback) {
+ if (_timeout) {
+ Glib.source_remove(_timeout)
+ }
+ }
+
+});
diff --git a/randomwallpaper@iflow.space/extension.js b/randomwallpaper@iflow.space/extension.js
index b1cf06e..334e489 100644
--- a/randomwallpaper@iflow.space/extension.js
+++ b/randomwallpaper@iflow.space/extension.js
@@ -164,7 +164,7 @@ let RandomWallpaperEntry = new Lang.Class({
function enable() {
// Extension enabled
this.settings = Convenience.getSettings();
-
+
// UI
panelEntry = new RandomWallpaperEntry(0, "Random wallpaper");
diff --git a/randomwallpaper@iflow.space/prefs.js b/randomwallpaper@iflow.space/prefs.js
index 65e4917..421f8b2 100644
--- a/randomwallpaper@iflow.space/prefs.js
+++ b/randomwallpaper@iflow.space/prefs.js
@@ -1,121 +1,78 @@
+const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const Gdk = imports.gi.Gdk;
const Lang = imports.lang;
+const ExtensionUtils = imports.misc.extensionUtils;
-const Self = imports.misc.extensionUtils.getCurrentExtension();
-//const Convenience = Self.imports.convenience;
+const Self = ExtensionUtils.getCurrentExtension();
+const Convenience = Self.imports.convenience;
-//const Gettext = imports.gettext.domain('space.iflow.randomwallpaper');
+const Gettext = imports.gettext.domain('space.iflow.randomwallpaper');
//const _ = Gettext.gettext;
-/* Settings Keys */
-const SETTINGS_HIDE_CORNERS = 'hide-corners';
-const SETTINGS_TRANSITION_SPEED = 'transition-speed';
-const SETTINGS_FORCE_ANIMATION = 'force-animation';
-const SETTINGS_UNMAXIMIZED_OPACITY = 'unmaximized-opacity';
-const SETTINGS_MAXIMIZED_OPACITY = 'maximized-opacity';
-const SETTINGS_PANEL_COLOR = 'panel-color';
-
-/* Color Scaling Factor (Byte to Decimal) */
-const SCALE_FACTOR = 255.9999999;
+const RWG_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.space.iflow.randomwallpaper';
function init() {
- // Convenience.initTranslations();
+ //Convenience.initTranslations();
}
function buildPrefsWidget() {
- let widget = new RandomWallpaperSettingsWidget();
+ let settings = new RandomWallpaperSettings();
+ let widget = settings.widget;
widget.show_all();
return widget;
}
/* UI Setup */
-const RandomWallpaperSettingsWidget = new Lang.Class({
- Name: 'RandomWallpaper.Prefs.SettingsUI',
- GTypeName: 'RandomWallpaperSettingsWidget',
- Extends: Gtk.Grid,
+const RandomWallpaperSettings = new Lang.Class({
+ Name: 'RandomWallpaper.Settings',
- _init: function(params) {
- this.parent(params);
-
- this.margin = this.row_spacing = this.column_spacing = 20;
+ _init: function() {
+ 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');
- //this._settings = Convenience.getSettings();
+ this._toggleAfSliders();
- let i = 0;
+ this.widget = this._builder.get_object('main-widget');
- this.attach(new Gtk.Label({ label: 'Poll Sensors Every (sec)', halign : Gtk.Align.END}), 0, i++, 1, 1);
- let updateTime = Gtk.SpinButton.new_with_range (1, 60, 1);
- this.attach(updateTime, 1, i++, 1, 1);
- // this._settings.bind('update-time', updateTime, 'value', Gio.SettingsBindFlags.DEFAULT);
-
- let adjustment = new Gtk.Adjustment({
- lower: 10,
- upper: 60,
- step_increment: 1
- });
- let scale = new Gtk.HScale({
- digits:2,
- adjustment: adjustment,
- value_pos: Gtk.PositionType.RIGHT
- });
-
- this.add(scale);
-
- this._addSwitch({key : 'group-voltage', y : i++, x : 2,
- label : 'Group Voltage Items',
- help : "Works if you have more than three voltage sensors"});
-
- /*
- this._addComboBox({
- items : {
- 'none' : 'None',
- 'nvidia-settings' : 'NVIDIA',
- 'aticonfig' : 'Catalyst',
- 'bumblebee-nvidia-smi': 'Bumblebee + NVIDIA' },
- key: 'gpu-utility', y : i, x : 2,
- label: 'Video Card Temperature Utility'
- }); */
+ this._builder.get_object('af-switch').connect('notify::active', function(toggleSwitch) {
+ this._toggleAfSliders();
+ }.bind(this))
+ 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);
},
- _addSwitch : function(params){
- let lbl = new Gtk.Label({label: params.label,halign : Gtk.Align.END});
- this.attach(lbl, params.x, params.y, 1, 1);
- let sw = new Gtk.Switch({halign : Gtk.Align.END, valign : Gtk.Align.CENTER});
- this.attach(sw, params.x + 1, params.y, 1, 1);
- if(params.help){
- lbl.set_tooltip_text(params.help);
- sw.set_tooltip_text(params.help);
- }
- //this._settings.bind(params.key, sw, 'active', Gio.SettingsBindFlags.DEFAULT);
- },
-
- _addComboBox : function(params){
- let model = new Gtk.ListStore();
- model.set_column_types([GObject.TYPE_STRING, GObject.TYPE_STRING]);
-
- let combobox = new Gtk.ComboBox({model: model});
- let renderer = new Gtk.CellRendererText();
- combobox.pack_start(renderer, true);
- combobox.add_attribute(renderer, 'text', 1);
-
- for(let k in params.items){
- model.set(model.append(), [0, 1], [k, params.items[k]]);
- }
-
- //combobox.set_active(Object.keys(params.items).indexOf(this._settings.get_string(params.key)));
-
- combobox.connect('changed', Lang.bind(this, function(entry) {
- let [success, iter] = combobox.get_active_iter();
- if (!success)
- return;
- //this._settings.set_string(params.key, model.get_value(iter, 0))
- }));
-
- this.attach(new Gtk.Label({ label: params.label, halign : Gtk.Align.END}), params.x, params.y, 1, 1);
- this.attach(combobox, params.x + 1, params.y, 1, 1);
+ _toggleAfSliders: function() {
+ 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);
+ }
}
-});
\ No newline at end of file
+
+});
diff --git a/randomwallpaper@iflow.space/schemas/gschemas.compiled b/randomwallpaper@iflow.space/schemas/gschemas.compiled
index 5af116b..16e327e 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 423fd6c..71b93bd 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
@@ -1,13 +1,59 @@
-
-
+
+
-
- 15
- Time to wait before first check (seconds)
- A first check is made this number of seconds after startup
-
-
+
+
+
+
+
-
+
+
+
+ 10
+ History size
+ Number of wallpapers stored locally
+
+
+
+
+ false
+ Auto-Fetch
+ Update the wallpaper based on a duration
+
+
+
+ 30
+ Duration
+ Minutes to wait before a new wallpaper is fetched
+
+
+
+
+ 1
+ Duration
+ Minutes to wait before a new wallpaper is fetched
+
+
+
+
+ 'desktoppr'
+ Wallpaper Source
+ Describs the adapter that will be used.
+
+
+
+ []
+ History
+ Stores the history objects as stringified JSONs
+
+
+
+ 0
+ Elapsed Time
+ The time that already elapsed.
+
+
+
diff --git a/randomwallpaper@iflow.space/settings.ui b/randomwallpaper@iflow.space/settings.ui
new file mode 100644
index 0000000..0323fa3
--- /dev/null
+++ b/randomwallpaper@iflow.space/settings.ui
@@ -0,0 +1,464 @@
+
+
+
+
+
+
+
+
+
diff --git a/randomwallpaper@iflow.space/wallpaperController.js b/randomwallpaper@iflow.space/wallpaperController.js
index daa8b61..4d0c3f8 100644
--- a/randomwallpaper@iflow.space/wallpaperController.js
+++ b/randomwallpaper@iflow.space/wallpaperController.js
@@ -11,6 +11,7 @@ const Gio = imports.gi.Gio;
//self
const Self = imports.misc.extensionUtils.getCurrentExtension();
const SourceAdapter = Self.imports.sourceAdapter;
+const Convenience = Self.imports.convenience;
let WallpaperController = new Lang.Class({
Name: "WallpaperController",
@@ -22,13 +23,38 @@ let WallpaperController = new Lang.Class({
history: [],
imageSourceAdapter: undefined,
+ autoFetch : {
+ active: false,
+ duration: 30,
+ },
+
_init: function(extensionMeta){
this.extensionMeta = extensionMeta;
this.wallpaperlocation = this.extensionMeta.path + '/wallpapers/';
+
+ this._settings = Convenience.getSettings();
+ this._settings.connect('changed', this._loadSettings.bind(this));
+ this._loadSettings();
+
this.history = this._loadHistory();
this.currentWallpaper = this._getCurrentWallpaper();
+
this.imageSourceAdapter = new SourceAdapter.DesktopperAdapter();
this.imageSourceAdapter = new SourceAdapter.WallheavenAdapter();
+
+ if (autoFetch.active) {
+
+ }
+ },
+
+ _loadSettings: function() {
+ this.historySize = this._settings.get_int('history-length');
+ this.autoFetch.active = this._settings.get_boolean('auto-fetch');
+
+ let duration = 0;
+ duration += this._settings.get_int('minutes');
+ duration += this._settings.get_int('hours') * 60;
+ this.autoFetch.duration = duration;
},
/*
@@ -83,6 +109,8 @@ let WallpaperController = new Lang.Class({
file.move(newFile, Gio.FileCopyFlags.NONE, null, function(){
});
+ // TODO: error handling, what if move fails?
+
this.history[i] = name;
this.history.sort();
@@ -97,6 +125,7 @@ let WallpaperController = new Lang.Class({
_setBackground: function(path, callback){
let background_setting = new Gio.Settings({schema: "org.gnome.desktop.background"});
+ this.deleteOldPictures();
/*
inspired from:
@@ -118,7 +147,6 @@ let WallpaperController = new Lang.Class({
// TODO: error handling
}
- this.deleteOldPictures();
},
_getCurrentWallpaper: function() {
@@ -156,6 +184,7 @@ let WallpaperController = new Lang.Class({
},
deleteOldPictures: function() {
+ this.historySize = this._settings.get_int('history-length');
let deleteFile;
while(this.history.length > this.historySize) {
deleteFile = Gio.file_new_for_path(this.wallpaperlocation + this.history.pop());