init timer feature, implement a simple settings interface

This commit is contained in:
Wolfgang Rumpler 2017-02-10 10:08:27 +01:00
parent dfac751fc3
commit c119247182
4 changed files with 102 additions and 44 deletions

View file

@ -1,39 +1,53 @@
const Lang = imports.lang;
const GLib = imports.gi.GLib;
const Convenience = Self.imports.convenience;
const Prefs = Self.imports.settings;
let AFTimer = new Lang.Class({
_timeout: null,
_timoutEndCallback: null,
_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();
_init: function() {
this._settings = new Prefs.Settings();
// this._settings.observe('minutes_elapsed', function() { // TODO: determine what to do });
this._settings.observe('minutes', this._loadSettings.bind(this));
}
// TODO: calc elapsed time
// TODO: check > 0
this._timeout = GLib.timeout_add(, delay, function() {
});
}
stop: function(delay, callback) {
if (_timeout) {
Glib.source_remove(_timeout)
_remainingMinutes: function() {
// TODO
}
registerCallback: function(callback) {
this._timoutEndCallback = callback;
},
begin: function() {
if (this._timeout) {
this.pause();
}
//this._settings.get()
// TODO: calc elapsed time
// TODO: check > 0
this._timeout = GLib.timeout_add(Glib.PRIORITY_DEFAULT, delay, function() {
this._settings.set(minutes_elapsed)
}.bind(this));
},
stop: function() {
if (_timeout) {
Glib.source_remove(_timeout)
this._settings.set('minutes_elapsed', 'int', 0)
}
},
pause: function() {
if (_timeout) {
Glib.source_remove(_timeout)
this._settings.set('minutes_elapsed', 'int', this._remainingMinutes())
}
}
}
});

View file

@ -0,0 +1,34 @@
const Lang = imports.lang;
const Glib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const Self = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Self.imports.convenience;
let Settings = new Lang.Class({
Name: "Settings",
_init: function() {
this._settings = Convenience.getSettings();
},
observe: function(key, callback) {
this._settings.connect('changed::'+key, callback);
},
set: function(key, type, value) {
if (this._settings['set_'+type](key, value)){
Gio.Settings.sync(); // wait for write
} else {
throw "Could not set " + key + " (type: " + type + ") with the value " + value;
}
},
get: function(key, type) {
return this._settings['get_'+type](key);
},
getSourceAdapter: function() {
return null;
}
});

View file

@ -216,7 +216,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">History lenght</property>
<property name="label" translatable="yes">History length</property>
</object>
<packing>
<property name="left_attach">0</property>

View file

@ -12,6 +12,7 @@ const Gio = imports.gi.Gio;
const Self = imports.misc.extensionUtils.getCurrentExtension();
const SourceAdapter = Self.imports.sourceAdapter;
const Convenience = Self.imports.convenience;
const Prefs = Self.imports.settings;
let WallpaperController = new Lang.Class({
Name: "WallpaperController",
@ -23,7 +24,7 @@ let WallpaperController = new Lang.Class({
history: [],
imageSourceAdapter: undefined,
autoFetch : {
_autoFetch : {
active: false,
duration: 30,
},
@ -32,29 +33,38 @@ let WallpaperController = new Lang.Class({
this.extensionMeta = extensionMeta;
this.wallpaperlocation = this.extensionMeta.path + '/wallpapers/';
this._settings = Convenience.getSettings();
this._settings.connect('changed', this._loadSettings.bind(this));
this._loadSettings();
this._settings = new Prefs.Settings();
this._settings.observe('history-length', this._updateHistory.bind(this));
this._settings.observe('auto-fetch', this._updateAutoFetching.bind(this));
this._settings.observe('minutes', this._updateAutoFetching.bind(this));
this._settings.observe('hours', this._updateAutoFetching.bind(this));
this._updateHistory();
this._updateAutoFetching();
this.history = this._loadHistory();
this.currentWallpaper = this._getCurrentWallpaper();
this.imageSourceAdapter = new SourceAdapter.DesktopperAdapter();
this.imageSourceAdapter = new SourceAdapter.WallheavenAdapter();
if (this.autoFetch.active) {
}
},
_loadSettings: function() {
this.historySize = this._settings.get_int('history-length');
this.autoFetch.active = this._settings.get_boolean('auto-fetch');
_updateHistory: function() {
this.historySize = this._settings.get('history-length', 'int');
},
_updateAutoFetching: function() {
let duration = 0;
duration += this._settings.get_int('minutes');
duration += this._settings.get_int('hours') * 60;
this.autoFetch.duration = duration;
duration += this._settings.get('minutes', 'int');
duration += this._settings.get('hours', 'int') * 60;
this._autoFetch.duration = duration;
this._autoFetch.active = this._settings.get('auto-fetch', 'boolean');
if (this._autoFetch.active) {
// TODO: this._timer.begin(this._autoFetch.duration);
} else {
// TODO: this._timer.end(this._autoFetch.duration);
}
},
/*
@ -184,7 +194,7 @@ let WallpaperController = new Lang.Class({
},
deleteOldPictures: function() {
this.historySize = this._settings.get_int('history-length');
this.historySize = this._settings.get('history-length', 'int');
let deleteFile;
while(this.history.length > this.historySize) {
deleteFile = Gio.file_new_for_path(this.wallpaperlocation + this.history.pop());