From 281c2ae5551c3b04fd10032aa9ebae67769a74d8 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Wed, 9 Aug 2017 05:34:11 +0200 Subject: [PATCH 1/9] Add UI elements --- randomwallpaper@iflow.space/settings.ui | 1061 +++++++++++++---------- 1 file changed, 620 insertions(+), 441 deletions(-) diff --git a/randomwallpaper@iflow.space/settings.ui b/randomwallpaper@iflow.space/settings.ui index 6d6d54c..904a0a1 100644 --- a/randomwallpaper@iflow.space/settings.ui +++ b/randomwallpaper@iflow.space/settings.ui @@ -45,363 +45,95 @@ 1 10 - - 500 + + 600 True - False - 15 - 15 - 15 - 15 - vertical - 10 + True + in + 300 + True + True - + True False - 0 - in + none - - 500 + True False - 10 - 10 - 10 - 10 - True - 10 + 20 + 20 + 20 + 20 + vertical + 20 - + True False - True - 10 - 2 - - - True - False - True - True - - - True - False - start - Wallpaper Source - - - 0 - 0 - - - - - True - False - True - The source that is used to fetch random wallpapers. You can select between desktoppr.co (default) and an experimental version of wallheaven.cc and unsplash.com. - True - 1 - 0 - - - - 0 - 1 - - - - - 0 - 0 - - - - - 0 - 0 - - - - - True - False - 20 - - - True - False - 0 - - desktoppr.co - unsplash.com (experimental) - alpha.wallheaven.cc (experimental) - - - - 0 - 0 - - - - - 0 - 1 - - - - - True - False - True 0 in - - - - - - True - False - Source Settings - - - - - 0 - 2 - - - - - - - - - - False - True - 1 - - - - - 500 - True - False - 0 - in - - - True - False - 10 - 10 - 10 - 10 - 10 - True - - - True - False - False - True - - - True - False - start - History length - - - 0 - 0 - - - - - True - False - True - The number of wallpapers that will be shown in the history and stored in the wallpaper folder of this extension. - True - 1 - 0 - - - - 0 - 1 - - - - - 0 - 0 - - - - - True - True - center - history-length - - - 0 - 1 - - - - - - - - - - False - True - 2 - - - - - True - False - 0 - in - - - True - False - 10 - 10 - 10 - 10 - 10 - 2 - - - True - False - True - True - - - True - False - start - Change lock screen - - - 0 - 0 - - - - - True - False - True - Also change the gnome lock screen image to the new wallpaper. - True - True - 1 - 0 - - - - 0 - 1 - - - - - 0 - 0 - - - - - True - False - vertical - - - True - True - end - start - - - False - True - 0 - - - - - 1 - 0 - - - - - - - - - - False - True - 3 - - - - - 500 - True - False - 0 - in - - - True - False - 10 - 10 - 10 - 10 - 10 - True - - - True - False - 10 - 2 + 500 True False + 10 + 10 + 10 + 10 True - True + 10 - + True False - start - Auto-Fetching + True + 10 + 2 + + + True + False + True + True + + + True + False + start + Wallpaper Source + + + 0 + 0 + + + + + True + False + True + The source that is used to fetch random wallpapers. You can select between desktoppr.co (default) and an experimental version of wallheaven.cc and unsplash.com. + True + 1 + 0 + + + + 0 + 1 + + + + + 0 + 0 + + 0 @@ -409,18 +141,134 @@ - + + True + False + 20 + + + True + False + 0 + + desktoppr.co + unsplash.com (experimental) + alpha.wallheaven.cc (experimental) + + + + 0 + 0 + + + + + 0 + 1 + + + + True False True - Automatically fetch a new wallpaper based on a period. - True - True - 1 - 0 - + 0 + in + + + + + + True + False + Source Settings + + + + + 0 + 2 + + + + + + + + + + False + True + 0 + + + + + 500 + True + False + 0 + in + + + True + False + 10 + 10 + 10 + 10 + 10 + True + + + True + False + False + True + + + True + False + start + History length + + + 0 + 0 + + + + + True + False + True + The number of wallpapers that will be shown in the history and stored in the wallpaper folder of this extension. + True + 1 + 0 + + + + 0 + 1 + + + + + 0 + 0 + + + + + True + True + center + 10 + history-length + 10 0 @@ -428,123 +276,387 @@ - - 0 - 0 - - - - True - False - vertical - - - True - True - end - start - - - False - True - 0 - - - - - 1 - 0 - + + - 0 - 0 + False + True + 1 - + True False - 20 + 0 + in - + True False - start - end - Minutes + 10 + 10 + 10 + 10 + 10 + 2 + + + True + False + True + True + + + True + False + start + Change lock screen + + + 0 + 0 + + + + + True + False + True + Also change the gnome lock screen image to the new wallpaper. + True + True + 1 + 0 + + + + 0 + 1 + + + + + 0 + 0 + + + + + True + False + vertical + + + True + True + end + start + + + False + True + 0 + + + + + 1 + 0 + + - - 0 - 1 - - - - True - False - start - end - Hours - - - 0 - 0 - - - - - True - True - True - duration-hours - True - False - 0 - 0 - 0 - - - 1 - 0 - - - - - True - True - True - duration-minutes - True - False - 0 - 0 - 0 - - - 1 - 1 - + + - 0 - 1 + False + True + 2 + + + + + 500 + True + False + 0 + in + + + True + False + 10 + 10 + 10 + 10 + 10 + True + + + True + False + 10 + 2 + + + True + False + True + True + + + True + False + start + Auto-Fetching + + + 0 + 0 + + + + + True + False + True + Automatically fetch a new wallpaper based on a period. + True + True + 1 + 0 + + + + 0 + 1 + + + + + 0 + 0 + + + + + True + False + vertical + + + True + True + end + start + + + False + True + 0 + + + + + 1 + 0 + + + + + 0 + 0 + + + + + True + False + 20 + + + True + False + start + end + Minutes + + + 0 + 1 + + + + + True + False + start + end + Hours + + + 0 + 0 + + + + + True + True + True + duration-hours + True + False + 0 + 0 + 0 + + + 1 + 0 + + + + + True + True + True + duration-minutes + True + False + 0 + 0 + 0 + + + 1 + 1 + + + + + 0 + 1 + + + + + + + + + + False + True + 3 + + + + + True + False + 0 + in + + + True + False + 10 + 10 + 10 + 2 + + + True + False + True + True + + + True + False + start + Change lock screen + + + 0 + 0 + + + + + True + False + True + Also change the gnome lock screen image to the new wallpaper. + True + True + 1 + 0 + + + + 0 + 1 + + + + + 0 + 0 + + + + + True + False + vertical + + + True + True + end + start + + + False + True + 0 + + + + + 1 + 0 + + + + + + + + + + False + True + 4 - - - - - False - True - 4 - @@ -722,6 +834,73 @@ 4 + + + True + False + + + True + False + True + vertical + + + True + False + start + Only Featured Images + + + False + True + 0 + + + + + True + False + This results in a smaller wallpaper pool but the images are considered to have higher quality. + True + 1 + 0 + + + + False + True + 1 + + + + + 0 + 0 + + + + + True + True + end + center + + + 1 + 0 + + + + + False + True + 10 + 5 + + True From 56afb665eadfb4023f57bfab87ee34657b8dda35 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Wed, 9 Aug 2017 05:49:49 +0200 Subject: [PATCH 2/9] Connect UI to source adapter. Closes #17 --- randomwallpaper@iflow.space/prefs.js | 4 ++++ .../schemas/gschemas.compiled | Bin 2264 -> 2328 bytes ...ns.space.iflow.randomwallpaper.gschema.xml | 5 +++++ randomwallpaper@iflow.space/settings.ui | 2 +- randomwallpaper@iflow.space/sourceAdapter.js | 5 ++++- .../wallpaperController.js | 3 ++- 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/randomwallpaper@iflow.space/prefs.js b/randomwallpaper@iflow.space/prefs.js index b00abcc..eb71770 100644 --- a/randomwallpaper@iflow.space/prefs.js +++ b/randomwallpaper@iflow.space/prefs.js @@ -161,6 +161,10 @@ const RandomWallpaperSettings = new Lang.Class({ 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); }, bindWallheaven: function () { diff --git a/randomwallpaper@iflow.space/schemas/gschemas.compiled b/randomwallpaper@iflow.space/schemas/gschemas.compiled index 4ee17980ba7924e61a80556fd7ea79f716530f78..b0ca0b1513b2c6d1fbe78047ea85a8a1454fc1d5 100644 GIT binary patch delta 955 zcmYL{Ur1A77{=eT|8tdQih~LwDjc%rjge8}h)g6%>}C`MM|SpyJli;Db4s)YMK^Vk ztY8J*1{H{))h;4-BYDwiH-SM(UIdaRMMThr_B>mM4m|vxJ>Pr2z2AGj<=y4>yTfWl z5xM{J)QVk1ZrVhS$*{ZvKO%T~@zyuyQ%;dEbFk_XadwJq<8gSfDCdOifTHUsE3Bty zeFR*Xd2&{9&-~b1bYmqK`WnFo!hiM2q%47T=uFMO#hl)Qd>Q-%X^X3GnbWr+{|^3w zs@DoWc0lh$F6j6)G`qSn#(Mf4$Vb5lbm;YXG0z45*olP%s6*CK=y{Y3$T1{!HLeBo z$!Ipg1-Z`dyOV*OsTnC%*YLv(ZNx+IR9e?c zf0X`#=C%nf8Bb*8xTCpeOjENtLyHE}sfp?49^(NJ(-xNSVS7p`Y%`1eFg)@aXvgyA zMxm8Mr*B8@2lqp{dm|s1)3+e+27{1wVtSsq7aWBqw@>V2J-rL{5%4i&jhY_+82>x4$?;Wy0bnYV#G(2;k2o6PBVAs+-ULGPbk4lt*0MVfoZgGP7wm(q-sw5BLGT9j@Zj$)*3+|< zGWZDUywH#9*Ys%Ryv!kd4&7Pr(YZj+>$3#bpp|m1k<)YdpTRGXHDr1Yc@1=U<_oSD i%D@6P;@zx*i;&eMJ)5k9d%XYmpywVPpx;|EJh8vFlgfht delta 873 zcmXw&Ur1A77{=dCw;f%n3F5%6x`;-oL4R0Lfn+8Y1a>1r!I7PLM$N{~IZ9M+T_i#V zlPO4e(M_-lBpQ@gG0+i2qk#(ZLeYyrn#sC|?p)6^J%fkmIluG$dC&WOn`-K4;KXn8fJ>x{9G-BCxLQOi_$_)-6$+LvFLFFH z$NLl!bNcNKhkN=@TYO=Aw;u}#cRV7al7@ePwA}W0a^@!REIbEY&-?btnHBH?d=0WX ze+`f`d%?HhJ5cuNxR+HiyTHrvv-pz3YKJO(V7ceu{M2wn9oE`)Ej+B7fm*ye74};r zM)ZMd=PP+y_zD>*ZH0bYVm{y4u!&fEZw)uattdwWq+@FL!i8&J(W*e$T1kR#^pA!n`wFT?*rcJ0jU8S0U1 z(5n;w_Bo!Jr3}FDLM?YL;$j?RlyY05fEF}WIvwE)=A)P}34aM~&gH9|nazIImage Width The height of the image. + + false + Featured images only + This results in a smaller wallpaper pool but the images are considered to have higher quality. + True True end - center + start 1 diff --git a/randomwallpaper@iflow.space/sourceAdapter.js b/randomwallpaper@iflow.space/sourceAdapter.js index 3305226..59b4f46 100644 --- a/randomwallpaper@iflow.space/sourceAdapter.js +++ b/randomwallpaper@iflow.space/sourceAdapter.js @@ -95,6 +95,7 @@ let UnsplashAdapter = new Lang.Class({ 'query': '', 'w': 1920, 'h': 1080, + 'featured': false }, _init: function () { @@ -152,12 +153,14 @@ let UnsplashAdapter = new Lang.Class({ this.options.query = this._settings.get('unsplash-keyword', 'string'); this.options.username = this._settings.get('username', 'string'); - if (this.options.username[0] === '@') { + if (this.options.username && this.options.username[0] === '@') { this.options.username = this.options.username.substring(1); // remove @ prefix } this.options.w = this._settings.get('image-width', 'int'); this.options.h = this._settings.get('image-height', 'int'); + + this.options.featured = this._settings.get('featured-only', 'boolean'); } }); diff --git a/randomwallpaper@iflow.space/wallpaperController.js b/randomwallpaper@iflow.space/wallpaperController.js index 86a0c7f..a453c4b 100644 --- a/randomwallpaper@iflow.space/wallpaperController.js +++ b/randomwallpaper@iflow.space/wallpaperController.js @@ -178,7 +178,8 @@ let WallpaperController = new Lang.Class({ */ if (settings.is_writable("picture-uri")) { // Set a new Background-Image (should show up immediately): - if (settings.set_string("picture-uri", path)) { + let rc = settings.set_string("picture-uri", path); + if (rc) { Gio.Settings.sync(); // Necessary: http://stackoverflow.com/questions/9985140 // call callback if given From 477cd0a01191a37caa12e1e1299c16c1e4c41ef0 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Wed, 9 Aug 2017 06:03:19 +0200 Subject: [PATCH 3/9] Remove duplicate change lock screen settings --- randomwallpaper@iflow.space/settings.ui | 93 ------------------------- 1 file changed, 93 deletions(-) diff --git a/randomwallpaper@iflow.space/settings.ui b/randomwallpaper@iflow.space/settings.ui index cb610fc..9bb5c25 100644 --- a/randomwallpaper@iflow.space/settings.ui +++ b/randomwallpaper@iflow.space/settings.ui @@ -561,99 +561,6 @@ 3 - - - True - False - 0 - in - - - True - False - 10 - 10 - 10 - 2 - - - True - False - True - True - - - True - False - start - Change lock screen - - - 0 - 0 - - - - - True - False - True - Also change the gnome lock screen image to the new wallpaper. - True - True - 1 - 0 - - - - 0 - 1 - - - - - 0 - 0 - - - - - True - False - vertical - - - True - True - end - start - - - False - True - 0 - - - - - 1 - 0 - - - - - - - - - - False - True - 4 - - From 0813f8c2aa9c92b3a1553cb6ed56399d7f3e92be Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Wed, 23 Aug 2017 20:24:15 +0200 Subject: [PATCH 4/9] Implement JSONPathParser --- .../jsonpath/jsonpath.js | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 randomwallpaper@iflow.space/jsonpath/jsonpath.js diff --git a/randomwallpaper@iflow.space/jsonpath/jsonpath.js b/randomwallpaper@iflow.space/jsonpath/jsonpath.js new file mode 100644 index 0000000..eec26c5 --- /dev/null +++ b/randomwallpaper@iflow.space/jsonpath/jsonpath.js @@ -0,0 +1,136 @@ +let JSONPathParser = function () { + + /** + * Access a simple json path expression of an object. + * Returns the accessed value or null if the access was not possible. + * + * @param inputObject the object to access + * @param inputString the json path expression + * @returns {*} + */ + this.access = function(inputObject, inputString) { + if (inputObject === null || inputObject === undefined) { + return null; + } + + if (inputString.length === 0) { + return inputObject; + } + + let startDot = inputString.indexOf('.'); + if (startDot === -1) { + startDot = inputString.length; + } + + let keyString = inputString.slice(0, startDot); + let inputStringTail = inputString.slice(startDot+1); + + let startParentheses = keyString.indexOf('['); + + if (startParentheses === -1) { + + if (!keyString.empty && !inputObject.hasOwnProperty(keyString)) { + return null; + } + + return this.access(inputObject[keyString], inputStringTail) + + } else { + + let indexString = keyString.slice(startParentheses+1, keyString.length-1); + keyString = keyString.slice(0, startParentheses); + + if (!keyString.empty && !inputObject.hasOwnProperty(keyString)) { + return null; + } + + switch (indexString) { + case "@random": + return this.access(this.randomElement(inputObject[keyString]), inputStringTail); + // add special keywords here + default: + // expecting integer + return this.access(inputObject[keyString][parseInt(indexString)], inputStringTail); + } + + } + + }; + + /** + * Returns the value of a random key of a given object. + * + * @param inputObject + * @returns {*} + */ + this.randomElement = function(inputObject) { + let keys = Object.keys(inputObject); + let randomIndex = Math.floor(Math.random()*keys.length); + + return inputObject[keys[randomIndex]]; + } + +}; + +/* + Tests + */ + +let parser = new JSONPathParser(); + +let accessString = "naise"; +let object = {naise: "one"}; +let val; + +console.log(`Accessing "${accessString}"`); +val = parser.access(object, accessString); +console.log(`Value: ${val}`); +console.log(`=================`); + +accessString = "going.deep.anyArrayOrObject[1].someKey"; +object = { + naise: "one", + going: { + deep: { + anyArrayOrObject: [ + {someKey: "I am 1!"}, + {someKey: "I am 2!"}, + {someKey: "I am 3!"}, + {someKey: "I am 4!"}, + {someKey: "I am 5!"}, + {someKey: "I am 6!"}, + {someKey: "I am 7!"}, + {someKey: "I am 8!"}, + ] + } + } +}; + +console.log(`Accessing "${accessString}"`); +val = parser.access(object, accessString); +console.log(`Value: ${val}`); +console.log(`=================`); + +accessString = "going.deep.anyArrayOrObject[@random].someKey"; +object = { + naise: "one", + going: { + deep: { + anyArrayOrObject: [ + {someKey: "I am 1!"}, + {someKey: "I am 2!"}, + {someKey: "I am 3!"}, + {someKey: "I am 4!"}, + {someKey: "I am 5!"}, + {someKey: "I am 6!"}, + {someKey: "I am 7!"}, + {someKey: "I am 8!"}, + ] + } + } +}; + +console.log(`Accessing "${accessString}"`); +val = parser.access(object, accessString); +console.log(`Value: ${val}`); +console.log(`=================`); \ No newline at end of file From c0add336ba228d68d3c7f19c78a192c6400b92b6 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Wed, 23 Aug 2017 20:47:49 +0200 Subject: [PATCH 5/9] Rework settings ui --- randomwallpaper@iflow.space/settings.ui | 904 +++++++++++++----------- 1 file changed, 497 insertions(+), 407 deletions(-) diff --git a/randomwallpaper@iflow.space/settings.ui b/randomwallpaper@iflow.space/settings.ui index 9bb5c25..d4e6367 100644 --- a/randomwallpaper@iflow.space/settings.ui +++ b/randomwallpaper@iflow.space/settings.ui @@ -59,51 +59,90 @@ False none - + True - False - 20 - 20 - 20 - 20 - vertical - 20 + True - + True False - 0 - in + 20 + 20 + 20 + 20 + vertical + 10 - - 500 + True False - 10 - 10 - 10 - 10 - True - 10 + 0 + in - + True False - True - 10 - 2 + 15 + 15 + 15 + 15 + 0 + 500 True False True - True + 10 - + True False - start - Wallpaper Source + True + 10 + 2 + + + True + False + True + True + + + True + False + start + Wallpaper Source + + + 0 + 0 + + + + + True + False + True + The source that is used to fetch random wallpapers. You can select between desktoppr.co (default) and an experimental version of wallheaven.cc and unsplash.com. + True + 1 + 0 + + + + 0 + 1 + + + + + 0 + 0 + + 0 @@ -111,17 +150,261 @@ - + + True + False + 20 + + + True + False + 0 + + desktoppr.co + unsplash.com (experimental) + alpha.wallheaven.cc (experimental) + + + + 0 + 0 + + + + + 0 + 1 + + + + True False True - The source that is used to fetch random wallpapers. You can select between desktoppr.co (default) and an experimental version of wallheaven.cc and unsplash.com. - True - 1 - 0 - + 0 + in + + + + + + True + False + Source Settings + + + + + 0 + 2 + + + + + + + + + + + + False + True + 0 + + + + + True + False + 0 + in + + + True + False + 15 + 15 + 15 + 15 + + + True + False + 10 + 2 + + + True + False + True + True + + + True + False + start + Change lock screen + + + 0 + 0 + + + + + True + False + True + Also change the gnome lock screen image to the new wallpaper. + True + True + 1 + 0 + + + + 0 + 1 + + + + + 0 + 0 + + + + + True + False + vertical + + + True + True + end + start + + + False + True + 0 + + + + + 1 + 0 + + + + + + + + + + + + False + True + 1 + + + + + + + True + False + General + + + False + + + + + True + False + 20 + 20 + 20 + 20 + vertical + + + True + False + 0 + in + + + True + False + 15 + 15 + 15 + 15 + + + True + False + 10 + True + + + True + False + False + True + + + True + False + start + History length + + + 0 + 0 + + + + + True + False + True + The number of wallpapers that will be shown in the history and stored in the wallpaper folder of this extension. + True + 1 + 0 + + + + 0 + 1 + + + + + 0 + 0 + + + + + True + True + center + 10 + history-length + 10 0 @@ -129,294 +412,138 @@ - - 0 - 0 - - - 0 - 0 - - - - True - False - 20 - - - True - False - 0 - - desktoppr.co - unsplash.com (experimental) - alpha.wallheaven.cc (experimental) - - - - 0 - 0 - - - - - 0 - 1 - - - - - True - False - True - 0 - in - - - - - - True - False - Source Settings - - - - - 0 - 2 - + + - - - + + False + True + 0 + - False - True - 0 - - - - - 500 - True - False - 0 - in - - - True - False - 10 - 10 - 10 - 10 - 10 - True - - - True - False - False - True - - - True - False - start - History length - - - 0 - 0 - - - - - True - False - True - The number of wallpapers that will be shown in the history and stored in the wallpaper folder of this extension. - True - 1 - 0 - - - - 0 - 1 - - - - - 0 - 0 - - - - - True - True - center - 10 - history-length - 10 - - - 0 - 1 - - - - - - - - - - False - True 1 - - + + True False - 0 - in - - - True - False - 10 - 10 - 10 - 10 - 10 - 2 - - - True - False - True - True - - - True - False - start - Change lock screen - - - 0 - 0 - - - - - True - False - True - Also change the gnome lock screen image to the new wallpaper. - True - True - 1 - 0 - - - - 0 - 1 - - - - - 0 - 0 - - - - - True - False - vertical - - - True - True - end - start - - - False - True - 0 - - - - - 1 - 0 - - - - - - - + History - False - True - 2 + 1 + False - - 500 + True False - 0 - in + 20 + 20 + 20 + 20 + vertical + 10 - + True False - 10 - 10 - 10 - 10 - 10 - True + 0 + in - + True False - 10 - 2 + 15 + 15 + 15 + 15 True False - True + 10 True - + True False - start - Auto-Fetching + 10 + 2 + + + True + False + True + True + + + True + False + start + Auto-Fetching + + + 0 + 0 + + + + + True + False + True + Automatically fetch a new wallpaper based on a period. + True + True + 1 + 0 + + + + 0 + 1 + + + + + 0 + 0 + + + + + True + False + vertical + + + True + True + end + start + + + False + True + 0 + + + + + 1 + 0 + + 0 @@ -424,18 +551,70 @@ - + True False - True - Automatically fetch a new wallpaper based on a period. - True - True - 1 - 0 - + 20 + + + True + False + start + end + Minutes + + + 0 + 1 + + + + + True + False + start + end + Hours + + + 0 + 0 + + + + + True + True + True + duration-hours + True + False + 0 + 0 + 0 + + + 1 + 0 + + + + + True + True + True + duration-minutes + True + False + 0 + 0 + 0 + + + 1 + 1 + + 0 @@ -443,122 +622,33 @@ - - 0 - 0 - - - - - True - False - vertical - - - True - True - end - start - - - False - True - 0 - - - - - 1 - 0 - - - 0 - 0 - - - - True - False - 20 - - - True - False - start - end - Minutes - - - 0 - 1 - - - - - True - False - start - end - Hours - - - 0 - 0 - - - - - True - True - True - duration-hours - True - False - 0 - 0 - 0 - - - 1 - 0 - - - - - True - True - True - duration-minutes - True - False - 0 - 0 - 0 - - - 1 - 1 - - - - - 0 - 1 - + + - - - + + False + True + 0 + - False - True - 3 + 2 + + + + + True + False + Auto-Fetching + + + 2 + False From 9a8eb2fa6d83d169fe974c4360b7d5dce9222723 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Sat, 7 Oct 2017 14:45:38 +0200 Subject: [PATCH 6/9] Add disable preview option --- randomwallpaper@iflow.space/prefs.js | 4 + .../schemas/gschemas.compiled | Bin 2328 -> 2368 bytes ...ns.space.iflow.randomwallpaper.gschema.xml | 6 + randomwallpaper@iflow.space/settings.ui | 231 ++++++++++++++---- .../wallpaperController.js | 16 +- 5 files changed, 202 insertions(+), 55 deletions(-) diff --git a/randomwallpaper@iflow.space/prefs.js b/randomwallpaper@iflow.space/prefs.js index eb71770..e3b36d3 100644 --- a/randomwallpaper@iflow.space/prefs.js +++ b/randomwallpaper@iflow.space/prefs.js @@ -124,6 +124,10 @@ const RandomWallpaperSettings = new Lang.Class({ this._builder.get_object('change-lock-screen'), 'active', Gio.SettingsBindFlags.DEFAULT); + this._settings.bind('disable-hover-preview', + this._builder.get_object('disable-hover-preview'), + 'active', + Gio.SettingsBindFlags.DEFAULT); }, _toggleAfSliders: function () { diff --git a/randomwallpaper@iflow.space/schemas/gschemas.compiled b/randomwallpaper@iflow.space/schemas/gschemas.compiled index b0ca0b1513b2c6d1fbe78047ea85a8a1454fc1d5..a9c89ee8ab8e34b5b83fb21a715a9b448cf697a5 100644 GIT binary patch delta 926 zcmYjQO=uHA7@gE?k~Y?aNQeaw>OppCS5OeKMoIiBwI~)vDaF4u8MBLNHtcR9MQuEJ zsfWr67EfM!(1=pJNC+hfb zxCZf$kBgd4vh@9boVB!A)A!+YmnwZUD8;@J{;FA^1%)PVuR6RijTGgTDj3 z3#fg39HURIh-^)$5GR1v-PtI6N39@X6g&rPuFv`j)Cu@c!R)(XI<95Uc%9(TwSwv7 zrb<#bteUj-iY;rVyd{J>rRA!wrQeWl-oS5SjxXEHmi7P~sO7hrSHPCz9=pZ$k}MZp z!y8t1M;)tb=OxyJ@Gb?%k58NBsw*8`mU0zG7W@T#R8un$=|Hle{l`y{Ra2c&O;gjf zeU%)_X2K^2j9j@W^^%ppsXKXF%Cet;oj!bV$a|&4yf@1JI^R|lXK#ZKV2>~7>gV|~ zsN?Jv_$&~xqa*aGd*M%juK?ZNQnR-PxB)!b^Ya(usd=d_@LM2x;jrHlYFyrB@fqSP z@L+9lnhDhXNcax^0eo9{@B7reqzHogf$nRf=4*vo>!VDdZibIdQNVb8W5KX((=`2Mb=1G8clI{H zW*obReg-S-B5D*D=gnCDJAFc(E>3${|Bp7-mbG24;4B2eek0PKI5aXjD?jID#lNec zNYC5(l4rRYD>q$qt=WU4gRfzmD=*LbTPor2s52G*^Elp62gh*ttL4fSmO|YD|2X&* zpgHkT`qZuP2f%|s*lTL`dKi2Mcyx0AFXO4%yDIoG(0z3%cq%n|HzlhOZ-INeee+D9 zK7xc#;0@qgbtCYpIW6D8KY(y5s5uqeU=FKexrJQGvkUp)PrTWWKG80$VWSPnHSh-@ ZteTot*TJ2b-SALq9@+)&@i$xM{sDGkro;dM 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 a1e53e8..1f33f2d 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 @@ -61,6 +61,12 @@ Weather the gnome lock screen should also be set to the new wallpaper. + + false + Disable hover preview + Disables the preview of the background while hovering the history list + + - + @@ -45,23 +45,23 @@ 1 10 - + + 400 600 True True - in - 300 - True - True - + True - False - none + True + in + True + True - + True - True + False + none True @@ -314,18 +314,135 @@ 1 + + + True + False + 0 + in + + + True + False + 15 + 15 + 15 + 15 + + + True + False + 10 + 2 + + + True + False + True + True + + + True + False + start + Disable hover preview + + + 0 + 0 + + + + + True + False + True + Disable the desktop preview of the background while hovering the history items. Try enabeling if you encounter crashes or laggs of the gnome shell while using the extension. + True + True + 1 + 0 + + + + 0 + 1 + + + + + 0 + 0 + + + + + True + False + vertical + + + True + True + end + start + + + False + True + 0 + + + + + 1 + 0 + + + + + + + + + + + + False + True + 2 + + - - - True - False - General - - - False - - + + + + + + + True + False + General + + + False + + + + + True + True + in + True + True + + + True + False + none True @@ -426,21 +543,37 @@ - - 1 - - - - - True - False - History - - - 1 - False - + + + + + 1 + + + + + True + False + History + + + 1 + False + + + + + True + True + in + True + True + + + True + False + none True @@ -636,24 +769,24 @@ - - 2 - - - - - True - False - Auto-Fetching - - - 2 - False - + + 2 + + + + + True + False + Auto-Fetching + + + 2 + False + diff --git a/randomwallpaper@iflow.space/wallpaperController.js b/randomwallpaper@iflow.space/wallpaperController.js index a453c4b..15b9289 100644 --- a/randomwallpaper@iflow.space/wallpaperController.js +++ b/randomwallpaper@iflow.space/wallpaperController.js @@ -241,7 +241,7 @@ let WallpaperController = new Lang.Class({ }); }, - _backgroundTimout: function (delay) { + _backgroundTimeout: function (delay) { if (this.timeout) { return; } @@ -261,15 +261,19 @@ let WallpaperController = new Lang.Class({ }, previewWallpaper: function (historyid, delay) { - this.previewId = historyid; - this._resetWallpaper = false; + if (!this._settings.get('disable-hover-preview', 'boolean')) { + this.previewId = historyid; + this._resetWallpaper = false; - this._backgroundTimout(delay); + this._backgroundTimeout(delay); + } }, resetWallpaper: function () { - this._resetWallpaper = true; - this._backgroundTimout(); + if (!this._settings.get('disable-hover-preview', 'boolean')) { + this._resetWallpaper = true; + this._backgroundTimeout(); + } }, getHistoryController: function () { From 5de0aa28b3b9d214a536d1b5b7de1fe544332fe1 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Sat, 7 Oct 2017 17:08:35 +0200 Subject: [PATCH 7/9] Add interface for generic JSON source --- .../jsonpath/jsonpath.js | 63 --------- randomwallpaper@iflow.space/prefs.js | 26 +++- .../schemas/gschemas.compiled | Bin 2328 -> 2712 bytes ...ns.space.iflow.randomwallpaper.gschema.xml | 16 +++ randomwallpaper@iflow.space/settings.ui | 125 +++++++++++++++++- randomwallpaper@iflow.space/sourceAdapter.js | 67 ++++++++++ .../wallpaperController.js | 4 + 7 files changed, 232 insertions(+), 69 deletions(-) diff --git a/randomwallpaper@iflow.space/jsonpath/jsonpath.js b/randomwallpaper@iflow.space/jsonpath/jsonpath.js index eec26c5..4cf864e 100644 --- a/randomwallpaper@iflow.space/jsonpath/jsonpath.js +++ b/randomwallpaper@iflow.space/jsonpath/jsonpath.js @@ -71,66 +71,3 @@ let JSONPathParser = function () { } }; - -/* - Tests - */ - -let parser = new JSONPathParser(); - -let accessString = "naise"; -let object = {naise: "one"}; -let val; - -console.log(`Accessing "${accessString}"`); -val = parser.access(object, accessString); -console.log(`Value: ${val}`); -console.log(`=================`); - -accessString = "going.deep.anyArrayOrObject[1].someKey"; -object = { - naise: "one", - going: { - deep: { - anyArrayOrObject: [ - {someKey: "I am 1!"}, - {someKey: "I am 2!"}, - {someKey: "I am 3!"}, - {someKey: "I am 4!"}, - {someKey: "I am 5!"}, - {someKey: "I am 6!"}, - {someKey: "I am 7!"}, - {someKey: "I am 8!"}, - ] - } - } -}; - -console.log(`Accessing "${accessString}"`); -val = parser.access(object, accessString); -console.log(`Value: ${val}`); -console.log(`=================`); - -accessString = "going.deep.anyArrayOrObject[@random].someKey"; -object = { - naise: "one", - going: { - deep: { - anyArrayOrObject: [ - {someKey: "I am 1!"}, - {someKey: "I am 2!"}, - {someKey: "I am 3!"}, - {someKey: "I am 4!"}, - {someKey: "I am 5!"}, - {someKey: "I am 6!"}, - {someKey: "I am 7!"}, - {someKey: "I am 8!"}, - ] - } - } -}; - -console.log(`Accessing "${accessString}"`); -val = parser.access(object, accessString); -console.log(`Value: ${val}`); -console.log(`=================`); \ No newline at end of file diff --git a/randomwallpaper@iflow.space/prefs.js b/randomwallpaper@iflow.space/prefs.js index eb71770..9aa1ad6 100644 --- a/randomwallpaper@iflow.space/prefs.js +++ b/randomwallpaper@iflow.space/prefs.js @@ -15,6 +15,7 @@ const RWG_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.space.iflow.randomwallpa 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_WALLHEAVEN = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.wallheaven'; +const RWG_SETTINGS_SCHEMA_GENERIC_JSON = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.genericJSON'; const LoggerModule = Self.imports.logger; @@ -41,6 +42,7 @@ const RandomWallpaperSettings = new Lang.Class({ desktopperSettings: null, unsplashSettings: null, wallheavenSettings: null, + genericJsonSettings: null, _init: function () { this._settings = Convenience.getSettings(RWG_SETTINGS_SCHEMA); @@ -67,6 +69,11 @@ const RandomWallpaperSettings = new Lang.Class({ this.wallheavenSettings = this._builder.get_object('wallheaven-settings'); this.bindWallheaven(); + // 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(); this.widget = this._builder.get_object('main-widget'); @@ -76,7 +83,7 @@ const RandomWallpaperSettings = new Lang.Class({ }.bind(this)); this._builder.get_object('source-combo').connect('changed', (sourceCombo) => { - let container = this._builder.get_object('source-settings-frame'); + let container = this._builder.get_object('source-settings-container'); if (this.currentSourceSettingsWidget !== null) { container.remove(this.currentSourceSettingsWidget); } @@ -91,13 +98,16 @@ const RandomWallpaperSettings = new Lang.Class({ case 2: // wallheaven this.currentSourceSettingsWidget = this.wallheavenSettings; break; + case 3: // generic JSON + this.currentSourceSettingsWidget = this.genericJsonSettings; + break; default: this.currentSourceSettingsWidget = this.noSettings; break; } container.add(this.currentSourceSettingsWidget); - + container.getParent }); this._settings.bind('history-length', @@ -198,6 +208,18 @@ const RandomWallpaperSettings = new Lang.Class({ this._builder.get_object('wallheaven-allow-sketchy'), 'active', Gio.SettingsBindFlags.DEFAULT); + }, + + bindGenericJSON: function () { + 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); } }); diff --git a/randomwallpaper@iflow.space/schemas/gschemas.compiled b/randomwallpaper@iflow.space/schemas/gschemas.compiled index b0ca0b1513b2c6d1fbe78047ea85a8a1454fc1d5..824348e9c0b16b275ad34ac3e1a866aac0143651 100644 GIT binary patch delta 1183 zcmZ8gT}YEr7(R1z&S^Q+kwigc#FkEk(pcD!LCcn<=#6+0F8$h!IoCe78KLXKLMp-W z6^tP8qHdg6VUiHo2tpyn-AMF7!i4s>v^_)7xlrz^YFaycg}m>^PX67%sg5e znHTBLqR+6{IV6cGM)Vc77!5^rzt59>51u#o?dA+@1ThJ%Fu1Sn22}7Gw zYB(PKRukbd3b4i+cndhUShm9!Q5)cIgZ}{1`_%>d)F${Q9Mue{wNSH`1K>_za&@DH z`P8i45AFvJ&0Y=Dr`{z(m0}oT1W=2oX7Qt7_O-jm<(6#W?yf$MGN<`jQstI>QlPuj z+1hlOnZlxr{wR^uI@o^J;Q_~~vpu2avJ>D}Kq_%+nr))qi~J;b8F+haW{Ey^8T>6U zud&MSLII10^A}hjnjo@u*sjaHK3hPN{k=X}vM~)oVUex>CEN%~a-S_2@G{JJbfQ*y zlVgu?Fj#UMSOzvX28*}}bus*5@CXom==?;V+6X@eegddRq~;OFzzHCfI}+kbyn7W*q5_q4V&=ZSWnynXI3qPfdRm90v|B)ojwI-VHwi{sJt= zuUP3*7s1~GZ|5nWweQMlr~bXclo8Fa+;j!4)^wAnp6lv05xxq}Wi$95FnK@Hg2$59 zoWC)6&j3xJz(JonAN~vQG@u@mn$1mswRlyJ5B}a^J~eAD1MdgSt#-_NMx*8?Q4O;O zc(7j4!vHk~Ry2Sw0V}b^v`@`j>HtfCdK=Wd4G(z8I5n$xXi9l{ejFbT8Rkm-1y^GS AVE_OC delta 922 zcmYL{PiPZC7{$L$vPm|vwzLV&K|%aSLP(8=3N8L=5Q7B85-&kPSZPcPO%qy^RK)H< z@uCN16@nn>#e<5pR51sUAQXErn2V^O#U4rvjYTNpt?|8;#ev8B@n&|unQyiltajfC zXwStOVbwgS_8N1K_C%csm>!dp(t_6%k^8TYEHS^~5IKbW4g4E|r{`||WInBmB$&hN zZV@#o(#CLkF)62n9)L#H57)S!%=H=gOQ&s0P%+E^JU_HN-Wf9(lPBcPW*wSJz z@-N7~L)nGp56sD3$bZ3qL-lJje%2En&$uxYH%F(VFSxb;;exL-3tY z>0at9bFvS47#@S{iey%d!-t`AdvFKWligUKfj@!ltCCSSC$oS}sP}3u$q&dLe1KU| zp;R;Ro;jI$7d#5>|Jc95oV*?R5d1v!>Dh${b8;v0B79mkQ|@;?J_%2Sujr*nq_3#| z>%{y4PeL*H{(QeC+~+~xZy9MkvBi9+UC8!9%A`NZoU9>_!}}roQe-xB2!0)Uu=~#z z*OPh1D*Pc7JUbxF$vEQ~nFYLpZm&o4oFL<2Wf9(hmZ}XaC-YT)z*iu<`($>14es*J zAJvjd2mU2NFRkG)A3F!{wj-zc=kiag!xtd? + Weather the people category should be searched. + + + + "" + The request URL + The URL where the JSON will be requested. + + + "" + JSON Path + The JSON path that describes the picture URL. + + + diff --git a/randomwallpaper@iflow.space/settings.ui b/randomwallpaper@iflow.space/settings.ui index d4e6367..001854d 100644 --- a/randomwallpaper@iflow.space/settings.ui +++ b/randomwallpaper@iflow.space/settings.ui @@ -1,5 +1,5 @@ - + @@ -38,6 +38,122 @@ 1 10 + + True + False + 10 + 10 + 10 + 10 + vertical + 10 + + + True + False + start + This feature requires some know how but many different wallpaper providers can be used with this generic JSON source. +You have to specify an URL to a JSON response and a path to the target picture url within the JSON response. + True + + + False + True + 0 + + + + + button + True + True + True + start + none + https://github.com/ifl0w/RandomWallpaperGnome3/wiki/Generic-JSON-Source + + + False + True + 1 + + + + + True + False + vertical + + + True + False + start + Request URL + + + False + True + 0 + + + + + True + True + Request URL + url + + + False + True + 1 + + + + + False + True + 2 + + + + + True + False + vertical + + + True + False + start + JSON Path + + + False + True + 0 + + + + + True + True + JSON Path + + + False + True + 1 + + + + + False + True + 3 + + + 1 100 @@ -161,8 +277,9 @@ 0 desktoppr.co - unsplash.com (experimental) - alpha.wallheaven.cc (experimental) + unsplash.com + alpha.wallheaven.cc + Generic JSON @@ -177,7 +294,7 @@ - + True False True diff --git a/randomwallpaper@iflow.space/sourceAdapter.js b/randomwallpaper@iflow.space/sourceAdapter.js index 59b4f46..9b7537d 100644 --- a/randomwallpaper@iflow.space/sourceAdapter.js +++ b/randomwallpaper@iflow.space/sourceAdapter.js @@ -8,11 +8,13 @@ const Json = imports.gi.Json; 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_WALLHEAVEN = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.wallheaven'; +const RWG_SETTINGS_SCHEMA_GENERIC_JSON = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.genericJSON'; const SettingsModule = Self.imports.settings; const HistoryModule = Self.imports.history; const LoggerModule = Self.imports.logger; +const JSONPath = Self.imports.jsonpath.jsonpath; let BaseAdapter = new Lang.Class({ Name: "BaseAdapter", @@ -267,3 +269,68 @@ let WallheavenAdapter = new Lang.Class({ this.options.purity = purity.join(''); } }); + +let GenericJsonAdapter = new Lang.Class({ + Name: "GenericJsonAdapter", + Extends: BaseAdapter, + + _settings: null, + + _init: function () { + this.parent(); + + this._settings = new SettingsModule.Settings(RWG_SETTINGS_SCHEMA_GENERIC_JSON); + }, + + requestRandomImage: function (callback) { + this.logger.debug(JSONPath); + + let session = new Soup.SessionAsync(); + + let url = 'https://api.desktoppr.co/1/wallpapers/random'; + let allowUnsafe = this._settings.get('allow-unsafe', 'boolean'); + if (allowUnsafe) { + url += '?safe_filter=all'; + } else { + url += '?safe_filter=safe'; + } + url = encodeURI(url); + this.logger.debug("Base URL: " + url); + + let message = Soup.Message.new('GET', url); + + session.queue_message(message, (session, message) => { + let data = JSON.parse(message.response_body.data); + let response = data.response; + let imageUrl = encodeURI(response.image.url); + + if (callback) { + let historyEntry = new HistoryModule.HistoryEntry(null, 'desktopper.co', imageUrl); + historyEntry.source.sourceUrl = 'https://www.desktoppr.co/'; + callback(historyEntry); + } + }); + + /* + let session = new Soup.SessionAsync(); + + let url = this._settings.get("generic-json-request-url", "string"); + url = encodeURI(url); + this.logger.debug("Base URL: " + url); + + let message = Soup.Message.new('GET', url); + + session.queue_message(message, (session, message) => { + let data = JSON.parse(message.response_body.data); + let response = data.response; + let imageUrl = encodeURI(response.image.url); + + if (callback) { + let historyEntry = new HistoryModule.HistoryEntry(null, 'desktopper.co', imageUrl); + historyEntry.source.sourceUrl = 'https://www.desktoppr.co/'; + callback(historyEntry); + } + }); + */ + } +}); diff --git a/randomwallpaper@iflow.space/wallpaperController.js b/randomwallpaper@iflow.space/wallpaperController.js index a453c4b..ebbf35c 100644 --- a/randomwallpaper@iflow.space/wallpaperController.js +++ b/randomwallpaper@iflow.space/wallpaperController.js @@ -60,6 +60,7 @@ let WallpaperController = new Lang.Class({ this._desktopperAdapter = new SourceAdapter.DesktopperAdapter(); this._unsplashAdapter = new SourceAdapter.UnsplashAdapter(); this._wallheavenAdapter = new SourceAdapter.WallheavenAdapter(); + this._genericJsonAdapter = new SourceAdapter.GenericJsonAdapter(); this.logger = new LoggerModule.Logger('RWG3', 'WallpaperController'); }, @@ -98,6 +99,9 @@ let WallpaperController = new Lang.Class({ case 2: this.imageSourceAdapter = this._wallheavenAdapter; break; + case 3: + this.imageSourceAdapter = this._genericJsonAdapter; + break; default: this.imageSourceAdapter = this._desktopperAdapter; break; From 79685069b8e29175db50007317daf6e64516dbc7 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Sat, 7 Oct 2017 19:09:33 +0200 Subject: [PATCH 8/9] Finish basic generic JSON source --- .../jsonpath/jsonpath.js | 27 ++++++++-- randomwallpaper@iflow.space/sourceAdapter.js | 54 +++++-------------- 2 files changed, 35 insertions(+), 46 deletions(-) diff --git a/randomwallpaper@iflow.space/jsonpath/jsonpath.js b/randomwallpaper@iflow.space/jsonpath/jsonpath.js index 4cf864e..81c75a4 100644 --- a/randomwallpaper@iflow.space/jsonpath/jsonpath.js +++ b/randomwallpaper@iflow.space/jsonpath/jsonpath.js @@ -29,34 +29,51 @@ let JSONPathParser = function () { if (startParentheses === -1) { - if (!keyString.empty && !inputObject.hasOwnProperty(keyString)) { + let targetObject = this._getTargetObject(inputObject, keyString); + if (targetObject == null) { return null; } - return this.access(inputObject[keyString], inputStringTail) + return this.access(targetObject, inputStringTail) } else { let indexString = keyString.slice(startParentheses+1, keyString.length-1); keyString = keyString.slice(0, startParentheses); - if (!keyString.empty && !inputObject.hasOwnProperty(keyString)) { + let targetObject = this._getTargetObject(inputObject, keyString); + if (targetObject == null) { return null; } switch (indexString) { case "@random": - return this.access(this.randomElement(inputObject[keyString]), inputStringTail); + return this.access(this.randomElement(targetObject), inputStringTail); // add special keywords here default: // expecting integer - return this.access(inputObject[keyString][parseInt(indexString)], inputStringTail); + return this.access(targetObject[parseInt(indexString)], inputStringTail); } } }; + /** + * Check validity of the key string and return the target object or null. + * @param inputObject + * @param keyString + * @returns {*} + * @private + */ + this._getTargetObject = function (inputObject, keyString) { + if (!keyString.empty && keyString !== "$" && !inputObject.hasOwnProperty(keyString)) { + return null; + } + + return (keyString === "$") ? inputObject : inputObject[keyString]; + }; + /** * Returns the value of a random key of a given object. * diff --git a/randomwallpaper@iflow.space/sourceAdapter.js b/randomwallpaper@iflow.space/sourceAdapter.js index 9b7537d..684482c 100644 --- a/randomwallpaper@iflow.space/sourceAdapter.js +++ b/randomwallpaper@iflow.space/sourceAdapter.js @@ -35,7 +35,11 @@ let BaseAdapter = new Lang.Class({ }, fileName: function (uri) { - let base = new String(uri).substring(uri.lastIndexOf('/') + 1); + let base = decodeURIComponent(uri); + base = base.substring(base.lastIndexOf('/') + 1); + if(base.indexOf('?') >= 0) { + base = base.substr(0, base.indexOf('?')); + } return base; }, @@ -64,7 +68,6 @@ let DesktopperAdapter = new Lang.Class({ url += '?safe_filter=safe'; } url = encodeURI(url); - this.logger.debug("Base URL: " + url); let message = Soup.Message.new('GET', url); @@ -114,7 +117,6 @@ let UnsplashAdapter = new Lang.Class({ let url = 'https://api.unsplash.com/photos/random?' + optionsString; url += 'client_id=64daf439e9b579dd566620c0b07022706522d87b255d06dd01d5470b7f193b8d'; url = encodeURI(url); - this.logger.debug("Base URL: " + url); let message = Soup.Message.new('GET', url); @@ -193,7 +195,6 @@ let WallheavenAdapter = new Lang.Class({ let optionsString = this._generateOptionsString(); let url = 'http://alpha.wallhaven.cc/search?' + optionsString; url = encodeURI(url); - this.logger.debug("Base URL: " + url); let message = Soup.Message.new('GET', url); @@ -275,62 +276,33 @@ let GenericJsonAdapter = new Lang.Class({ Extends: BaseAdapter, _settings: null, + _jsonPathParser: null, _init: function () { this.parent(); - + this._jsonPathParser = new JSONPath.JSONPathParser(); this._settings = new SettingsModule.Settings(RWG_SETTINGS_SCHEMA_GENERIC_JSON); }, requestRandomImage: function (callback) { - this.logger.debug(JSONPath); - - let session = new Soup.SessionAsync(); - - let url = 'https://api.desktoppr.co/1/wallpapers/random'; - let allowUnsafe = this._settings.get('allow-unsafe', 'boolean'); - if (allowUnsafe) { - url += '?safe_filter=all'; - } else { - url += '?safe_filter=safe'; - } - url = encodeURI(url); - this.logger.debug("Base URL: " + url); - - let message = Soup.Message.new('GET', url); - - session.queue_message(message, (session, message) => { - let data = JSON.parse(message.response_body.data); - let response = data.response; - let imageUrl = encodeURI(response.image.url); - - if (callback) { - let historyEntry = new HistoryModule.HistoryEntry(null, 'desktopper.co', imageUrl); - historyEntry.source.sourceUrl = 'https://www.desktoppr.co/'; - callback(historyEntry); - } - }); - - /* let session = new Soup.SessionAsync(); let url = this._settings.get("generic-json-request-url", "string"); url = encodeURI(url); - this.logger.debug("Base URL: " + url); let message = Soup.Message.new('GET', url); session.queue_message(message, (session, message) => { - let data = JSON.parse(message.response_body.data); - let response = data.response; - let imageUrl = encodeURI(response.image.url); + 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); if (callback) { - let historyEntry = new HistoryModule.HistoryEntry(null, 'desktopper.co', imageUrl); - historyEntry.source.sourceUrl = 'https://www.desktoppr.co/'; + let historyEntry = new HistoryModule.HistoryEntry(null, 'Generic JSON Source', imageUrl); + historyEntry.source.sourceUrl = imageUrl; callback(historyEntry); } }); - */ + } }); From 1d71ac073d140664b091b4a1e2b5958c44b50a0d Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Sat, 7 Oct 2017 19:25:26 +0200 Subject: [PATCH 9/9] 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 --- randomwallpaper@iflow.space/prefs.js | 4 ++ .../schemas/gschemas.compiled | Bin 2760 -> 2832 bytes ...ns.space.iflow.randomwallpaper.gschema.xml | 5 +++ randomwallpaper@iflow.space/settings.ui | 37 ++++++++++++++++++ randomwallpaper@iflow.space/sourceAdapter.js | 1 + 5 files changed, 47 insertions(+) diff --git a/randomwallpaper@iflow.space/prefs.js b/randomwallpaper@iflow.space/prefs.js index 7a924bf..d839d13 100644 --- a/randomwallpaper@iflow.space/prefs.js +++ b/randomwallpaper@iflow.space/prefs.js @@ -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); } }); diff --git a/randomwallpaper@iflow.space/schemas/gschemas.compiled b/randomwallpaper@iflow.space/schemas/gschemas.compiled index 9fc79979329ae7a063d8af2532606edc7bcdc621..86238554d0509b533519ca409de5ce1da16d7146 100644 GIT binary patch delta 786 zcmY+CKWGzi6vtoET$(h*1WUA5T@<7u*{ZZc0$rp8QBY7&aH&_RXl>J85L%nfMTbBv z7C~?n|DhH!gJKpj2(_XJb+8m%1Wj?XL)-ZI9vtYw_defz-@Erq-ldVLY^zKcrXyyv zFLTR|ndP`0vO$}KPoriJ&RlOQ_hM!Phs9n9>&n+Ut#VS+)=kUGL*eIab+~?6)$DSitg~pRkLcc?Ns-F z)uKD@xf7G>qTGy3m9?67#@FC$RQNdXPQ&GuH{f@)qceY8xqOCv4Q?RsR^h91`3~|} zyIB$idyv;2(y$lpTRga`e)%m{D%&7t2$fogcc~yBWzZP>guXmHw_mw@iu?!sjY^+y zrBpVkbr z-6&K{98oSGC+~q-6r3rqGyC8ay0hocruyaiu~vbzD08ykl*{v*j@f<8V|4T9fy*k$ iCwZU_-=gKY1wWV9mtTV4P_SirZFvQ*&yUAXhyDW2R;gV8 delta 722 zcmXw%Pe>GD7{=e(byjzmRFaj{x+H{B)}ay%T=WvM^att?bPzoRdl8pa7ZG(lb*K&t zqa=0dC>o-;(w|Fvi58+CcgEhX}^sgXLf zrBD5Pu9^LVdu_;W@Q{v}tv-Kwq`arWY>+&IPe#q$gjtoV5M$6Dn7kD8e>;7f)uWI{ zmEdx?ht5@;n~!UWwsS3KX?#t5UP`P|AMpaJ7L(grFK%ak8LyykcRueZ7hfVj!S&iV zGozDf@>}CszcV~gZ($xn=Fil1`W^0-aMwh)Uv_%^3Af)^=$;ZmY3Gxkm8%-^yc9n}`8uZ*_b)AIukDRDHasVQW2- z40-yFak2&cD_Vc;Jz+TDX4N38ASWBYuUs4@|BLUV+MZ(Vd4k{OKX`Zb^uOkdY1W4D zhbZy1&y5+{9FVLHV>th-aUtqyBK8N;}e+9W%FQ3PkQ0JSON Path The JSON path that describes the picture URL. + + "" + Image URL prefix + This prefix is added to the final image URL. + diff --git a/randomwallpaper@iflow.space/settings.ui b/randomwallpaper@iflow.space/settings.ui index 8c54bd8..2134cbd 100644 --- a/randomwallpaper@iflow.space/settings.ui +++ b/randomwallpaper@iflow.space/settings.ui @@ -153,6 +153,43 @@ You have to specify an URL to a JSON response and a path to the target picture u 3 + + + True + False + vertical + + + True + False + start + Image URL prefix + + + False + True + 0 + + + + + True + True + Image URL prefix + + + False + True + 1 + + + + + False + True + 4 + + 1 diff --git a/randomwallpaper@iflow.space/sourceAdapter.js b/randomwallpaper@iflow.space/sourceAdapter.js index 684482c..6b80657 100644 --- a/randomwallpaper@iflow.space/sourceAdapter.js +++ b/randomwallpaper@iflow.space/sourceAdapter.js @@ -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);