implement collections filter for unsplash

closes #23
This commit is contained in:
Wolfgang Rumpler 2018-07-27 19:34:10 +02:00
parent d87c8da3a0
commit 5537aa6ffb
5 changed files with 51 additions and 11 deletions

View file

@ -161,11 +161,14 @@ var RandomWallpaperSettings = new Lang.Class({
this._builder.get_object('unsplash-keyword'),
'text',
Gio.SettingsBindFlags.DEFAULT);
this._unsplash_settings.bind('username',
this._unsplash_settings.bind('unsplash-username',
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);
this._unsplash_settings.bind('image-width',
this._builder.get_object('unsplash-image-width'),
'value',

View file

@ -87,11 +87,16 @@
<summary>Keyword</summary>
<description>The keyword will be used to search images.</description>
</key>
<key type='s' name='username'>
<key type='s' name='unsplash-username'>
<default>""</default>
<summary>Username</summary>
<description>Only fetch random images of a given user.</description>
</key>
<key type='s' name='unsplash-collections'>
<default>""</default>
<summary>Collections</summary>
<description>Only fetch random images from a comma separated list of collections.</description>
</key>
<key type='i' name='image-width'>
<default>1920</default>
<summary>Image Width</summary>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.1 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="desktopper-settings">
@ -1007,7 +1007,7 @@ You can also define a prefix that will be added to the image URL.</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Keyword</property>
<property name="label" translatable="yes">Collections</property>
</object>
<packing>
<property name="expand">False</property>
@ -1016,11 +1016,11 @@ You can also define a prefix that will be added to the image URL.</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="unsplash-keyword">
<object class="GtkEntry" id="unsplash-collections">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_bottom">10</property>
<property name="placeholder_text" translatable="yes">Enter a keyword ...</property>
<property name="placeholder_text" translatable="yes">ID1, ID2, ...</property>
</object>
<packing>
<property name="expand">False</property>
@ -1028,6 +1028,32 @@ You can also define a prefix that will be added to the image URL.</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Keyword</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="unsplash-keyword">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_bottom">10</property>
<property name="placeholder_text" translatable="yes">Some keyword ...</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@ -1116,7 +1142,7 @@ You can also define a prefix that will be added to the image URL.</property>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
<property name="position">6</property>
</packing>
</child>
<child>
@ -1183,7 +1209,7 @@ You can also define a prefix that will be added to the image URL.</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">10</property>
<property name="position">5</property>
<property name="position">7</property>
</packing>
</child>
</object>

View file

@ -51,7 +51,7 @@ var BaseAdapter = new Lang.Class({
try {
return uri !== decodeURIComponent(uri);
} catch(err) {
} catch (err) {
this.logger.error(err);
return false;
}
@ -112,6 +112,7 @@ var UnsplashAdapter = new Lang.Class({
options: {
'username': '',
'query': '',
'collections': [],
'w': 1920,
'h': 1080,
'featured': false
@ -179,11 +180,16 @@ var UnsplashAdapter = new Lang.Class({
_readOptionsFromSettings: function () {
this.options.query = this._settings.get('unsplash-keyword', 'string');
this.options.username = this._settings.get('username', 'string');
this.options.username = this._settings.get('unsplash-username', 'string');
if (this.options.username && this.options.username[0] === '@') {
this.options.username = this.options.username.substring(1); // remove @ prefix
}
this.options.collections = this._settings.get('unsplash-collections', 'string').split(',').map(
(elem) => {
return elem.trim();
});
this.options.w = this._settings.get('image-width', 'int');
this.options.h = this._settings.get('image-height', 'int');