Add prefix for image url. This is needed for relative urls that do not contain the domain (e.g.: Bing picture of the day). Closes #22

This commit is contained in:
Wolfgang Rumpler 2017-10-07 19:25:26 +02:00
parent 79685069b8
commit 1d71ac073d
5 changed files with 47 additions and 0 deletions

View file

@ -224,6 +224,10 @@ const RandomWallpaperSettings = new Lang.Class({
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);
}
});

View file

@ -160,6 +160,11 @@
<summary>JSON Path</summary>
<description>The JSON path that describes the picture URL.</description>
</key>
<key type='s' name='generic-json-url-prefix'>
<default>""</default>
<summary>Image URL prefix</summary>
<description>This prefix is added to the final image URL.</description>
</key>
</schema>
</schemalist>

View file

@ -153,6 +153,43 @@ You have to specify an URL to a JSON response and a path to the target picture u
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<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">Image URL prefix</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="generic-json-url-prefix">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="placeholder_text" translatable="yes">Image URL prefix</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
<object class="GtkAdjustment" id="history-length">
<property name="lower">1</property>

View file

@ -296,6 +296,7 @@ let GenericJsonAdapter = new Lang.Class({
let response = JSON.parse(message.response_body.data);
let JSONPath = this._settings.get("generic-json-response-path", "string");
let imageUrl = this._jsonPathParser.access(response, JSONPath);
imageUrl = this._settings.get("generic-json-url-prefix", "string")+imageUrl;
if (callback) {
let historyEntry = new HistoryModule.HistoryEntry(null, 'Generic JSON Source', imageUrl);