diff --git a/buildzip.sh b/buildzip.sh index d43969bb..7205768b 100755 --- a/buildzip.sh +++ b/buildzip.sh @@ -1,8 +1,11 @@ #!/bin/bash glib-compile-schemas schemas/ +intltool-extract --type=gettext/glade Settings.ui +xgettext -k -k_ -kN_ -o locale/BingWallpaper.pot Settings.ui.h extension.js prefs.js --from-code=UTF-8 + +rm BingWallpaper@ineffable-gmail.com.zip zip -r BingWallpaper@ineffable-gmail.com.zip * zip -d BingWallpaper@ineffable-gmail.com.zip screenshot/* screenshot buildzip.sh - diff --git a/extension.js b/extension.js index d0385b75..d9dc6cf5 100644 --- a/extension.js +++ b/extension.js @@ -10,6 +10,8 @@ const GLib = imports.gi.GLib; const Util = imports.misc.util; const PanelMenu = imports.ui.panelMenu; const PopupMenu = imports.ui.popupMenu; +const Clipboard = St.Clipboard.get_default(); +const CLIPBOARD_TYPE = St.ClipboardType.CLIPBOARD; const ExtensionUtils = imports.misc.extensionUtils; const Me = ExtensionUtils.getCurrentExtension(); @@ -19,12 +21,12 @@ const Convenience = Me.imports.convenience; const Gettext = imports.gettext.domain('BingWallpaper'); const _ = Gettext.gettext; -const BingImageURL = "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt="; +const BingImageURL = "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mbl=1&mkt="; const BingURL = "https://bing.com"; const IndicatorName = "BingWallpaperIndicator"; const TIMEOUT_SECONDS = 24 * 3600; // FIXME: this should use the end data from the json data const TIMEOUT_SECONDS_ON_HTTP_ERROR = 1 * 3600; // retry in on-hour if there is a http error -const ICON = "bing" +const ICON = "bing"; let monitors; let validresolutions = [ '800x600' , '1024x768', '1280x720', '1280x768', '1366x768', '1920x1080', '1920x1200']; @@ -36,7 +38,6 @@ let autores; // automatically selected resolution let bingWallpaperIndicator=null; - function log(msg) { if (bingWallpaperIndicator==null || bingWallpaperIndicator._settings.get_boolean('debug-logging')) print("BingWallpaper extension: " + msg); // disable to keep the noise down in journal @@ -63,37 +64,19 @@ const LongNotification = new Lang.Class({ } }); -function notify(msg, details, transient) { - // set notifications icon - let source = new MessageTray.Source("BingWallpaper", ICON); - // force expanded notification - source.policy = new MessageTray.NotificationPolicy({ enable: true, - enableSound: false, - showBanners: true, - forceExpanded: true, - showInLockScreen: true, - detailsInLockScreen: true - }); - Main.messageTray.add(source); - let notification = new LongNotification(source, msg, details); - notification.setTransient(transient); - // Add action to open Bing website with default browser - notification.addAction(_("Bing website"), Lang.bind(this, function() { - Util.spawn(["xdg-open", BingURL]); - })); - source.notify(notification); -} - function notifyError(msg) { Main.notifyError("BingWallpaper extension error", msg); } function doSetBackground(uri, schema) { let gsettings = new Gio.Settings({schema: schema}); - gsettings.set_string('picture-uri', 'file://' + uri); + let prev = gsettings.get_string('picture-uri'); + uri = 'file://'+ uri; + gsettings.set_string('picture-uri', uri); gsettings.set_string('picture-options', 'zoom'); Gio.Settings.sync(); gsettings.apply(); + return (prev != uri); // return true if background uri has changed } let httpSession = new Soup.SessionAsync(); @@ -117,6 +100,8 @@ const BingWallpaperIndicator = new Lang.Class({ this._updatePending = false; this._timeout = null; this.longstartdate = null; + this.imagelink = ""; + this.imageURL= ""; this._settings = Utils.getSettings(); this._settings.connect('changed::hide', Lang.bind(this, function() { @@ -127,16 +112,19 @@ const BingWallpaperIndicator = new Lang.Class({ this.refreshDueItem = new PopupMenu.PopupMenuItem(_("")); this.showItem = new PopupMenu.PopupMenuItem(_("Show description")); + this.clipboardItem = new PopupMenu.PopupMenuItem(_("Copy image URL to clipboard")); this.wallpaperItem = new PopupMenu.PopupMenuItem(_("Set wallpaper")); this.refreshItem = new PopupMenu.PopupMenuItem(_("Refresh Now")); this.settingsItem = new PopupMenu.PopupMenuItem(_("Settings")); this.menu.addMenuItem(this.refreshDueItem); this.menu.addMenuItem(this.showItem); + this.menu.addMenuItem(this.clipboardItem); this.menu.addMenuItem(this.wallpaperItem); this.menu.addMenuItem(this.refreshItem); this.menu.addMenuItem(this.settingsItem); this.refreshDueItem.setSensitive(false); this.showItem.connect('activate', Lang.bind(this, this._showDescription)); + this.clipboardItem.connect('activate', Lang.bind(this, this._copyURLToClipboard)); this.wallpaperItem.connect('activate', Lang.bind(this, this._setBackground)); this.refreshItem.connect('activate', Lang.bind(this, this._refresh)); this.settingsItem.connect('activate', function() { @@ -146,21 +134,56 @@ const BingWallpaperIndicator = new Lang.Class({ this.actor.connect('button-press-event', Lang.bind(this, function () { // Grey out menu items if an update is pending this.refreshItem.setSensitive(!this._updatePending); + this.clipboardItem.setSensitive(!this._updatePending && this.imageURL != ""); this.showItem.setSensitive(!this._updatePending && this.title != "" && this.explanation != ""); this.wallpaperItem.setSensitive(!this._updatePending && this.filename != ""); })); this._restartTimeout(60); // wait 60 seconds before performing refresh }, + _notify: function(msg, details, transient, show_prefs) { + // set notifications icon + let source = new MessageTray.Source("BingWallpaper", ICON); + // force expanded notification + source.policy = new MessageTray.NotificationPolicy({ enable: true, + enableSound: false, + showBanners: true, + forceExpanded: true, + showInLockScreen: true, + detailsInLockScreen: true + }); + Main.messageTray.add(source); + let notification = new LongNotification(source, msg, details); + notification.setTransient(transient); + // Add action to open Bing website with default browser + if (show_prefs !== false) { + notification.addAction(_("Open extension settings"), Lang.bind(this, function() { + Util.spawn(["gnome-shell-extension-prefs", Me.metadata.uuid]); + })); + } + else { + notification.addAction(_("Bing website"), Lang.bind(this, function() { + Util.spawn(["xdg-open", this.imagelink ? this.imagelink : BingURL]); + })); + } + source.notify(notification); + }, + _setBackground: function() { + let changed = false; if (this.filename == "") return; if (this._settings.get_boolean('set-background')) { - doSetBackground(this.filename, 'org.gnome.desktop.background'); + changed = doSetBackground(this.filename, 'org.gnome.desktop.background'); } if (this._settings.get_boolean('set-lock-screen')) { - doSetBackground(this.filename, 'org.gnome.desktop.screensaver'); + changed = changed || doSetBackground(this.filename, 'org.gnome.desktop.screensaver'); } + return changed; + }, + + _copyURLToClipboard: function() { + Clipboard.set_text(CLIPBOARD_TYPE, this.imageURL); }, _restartTimeout: function(seconds = null) { @@ -180,13 +203,13 @@ const BingWallpaperIndicator = new Lang.Class({ // 201708041400 YYYYMMDDHHMM // 012345678901 let timezone = GLib.TimeZone.new_utc(); - let refreshDue = GLib.DateTime.new(timezone, + let refreshDue = GLib.DateTime.new(timezone, parseInt(longdate.substr(0,4)), // year parseInt(longdate.substr(4,2)), // month parseInt(longdate.substr(6,2)), // day parseInt(longdate.substr(8,2)), // hour parseInt(longdate.substr(10,2)), // mins - 0 ).add_seconds(86400); // seconds + 0 ).add_seconds(86400); // seconds let now = GLib.DateTime.new_now(timezone); let difference = refreshDue.difference(now)/1000000; @@ -200,14 +223,25 @@ const BingWallpaperIndicator = new Lang.Class({ this._restartTimeout(difference); }, + // convert shortdate format into human friendly format + _localeDate: function (shortdate) { + let timezone = GLib.TimeZone.new_local(); // TZ doesn't really matter for this + let date = GLib.DateTime.new(timezone, + parseInt(shortdate.substr(0,4)), // year + parseInt(shortdate.substr(4,2)), // month + parseInt(shortdate.substr(6,2)), // day + 0, 0, 0 ); + return date.format('%Y-%m-%d'); // ISO 8601 - https://xkcd.com/1179/ + }, + _showDescription: function() { if (this.title == "" && this.explanation == "") { this._refresh(); } else { let message = this.explanation; if (this.copyright != "") - message += "\n" + this.copyright + "" - notify(this.title, message, this._settings.get_boolean('transient')); + message += "\n" + this.copyright; + this._notify(this.title, message, this._settings.get_boolean('transient'), false); } }, @@ -246,26 +280,38 @@ const BingWallpaperIndicator = new Lang.Class({ _parseData: function(data) { let parsed = JSON.parse(data); let imagejson = parsed['images'][0]; + let datamarket = parsed['market']['mkt']; + let prefmarket = this._settings.get_string('market'); + + if (datamarket != prefmarket) { + this._notify( + _("Market not available in your region"),_("The selected market is not available in your country or geographic region.\n") + + '(Mismatch Req: '+prefmarket +' != Recv: ' + datamarket +')', + false, true + ); + log('Mismatched market data, Req: '+prefmarket +' != Recv: ' + datamarket +')'); + } if (imagejson['url'] != '') { this.title = imagejson['copyright'].replace(/\s*\(.*?\)\s*/g, ""); - this.explanation = _("Bing Wallpaper of the Day for")+" "+imagejson['startdate']+""; + this.explanation = _("Bing Wallpaper of the Day for")+' '+this._localeDate(imagejson['startdate'])+' ('+datamarket+')'; this.copyright = imagejson['copyright'].match(/\(([^)]+)\)/)[1].replace('\*\*','');; this.longstartdate = imagejson['fullstartdate']; + this.imagelink = BingURL+imagejson['quiz']; let resolution = this._settings.get_string('resolution'); if (resolution == "auto") { log("auto resolution selected ("+autores+")"); resolution = autores; } - - if (validresolutions.indexOf(resolution) == -1 || imagejson['wp'] == false || + + if (validresolutions.indexOf(resolution) == -1 || imagejson['wp'] == false || (this._settings.get_string('resolution') == "auto" && autores == "1920x1200") ) { // resolution invalid, animated background, or override auto selected 1920x1200 to avoid bing logo unless user wants it - resolution = "1920x1080"; + resolution = "1920x1080"; } - let url = BingURL+imagejson['url'].replace('1920x1080',resolution); // mangle url to user's resolution + this.imageURL = BingURL+imagejson['url'].replace('1920x1080',resolution); // mangle url to user's resolution let BingWallpaperDir = this._settings.get_string('download-folder'); let userHomeDir = GLib.get_home_dir(); @@ -277,8 +323,8 @@ const BingWallpaperIndicator = new Lang.Class({ BingWallpaperDir = userHomeDir + "/Pictures/BingWallpaper/"; else if (!BingWallpaperDir.endsWith('/')) BingWallpaperDir += '/'; - - this.filename = BingWallpaperDir+imagejson['startdate']+'-'+url.replace(/^.*[\\\/]/, ''); + + this.filename = BingWallpaperDir+imagejson['startdate']+'-'+this.imageURL.replace(/^.*[\\\/]/, ''); let file = Gio.file_new_for_path(this.filename); let file_exists = file.query_exists(null); let file_info = file_exists ? file.query_info ('*',Gio.FileQueryInfoFlags.NONE,null): 0; @@ -288,10 +334,12 @@ const BingWallpaperIndicator = new Lang.Class({ if (!dir.query_exists(null)) { dir.make_directory_with_parents(null); } - this._download_image(url, file); + this._download_image(this.imageURL, file); } else { log("Image already downloaded"); - this._setBackground(); + let changed = this._setBackground(); + if (changed === true) + this._showDescription(); // notify only if the background was changed this._updatePending = false; } } else { @@ -356,7 +404,7 @@ const BingWallpaperIndicator = new Lang.Class({ while(imagelist.length > maxpictures+1) { var to_delete = imagelist.shift(); // get the first (oldest item from the list) log("image: "+to_delete); - if (deletepictures) { + if (deletepictures && to_delete != '') { var file = Gio.file_new_for_path(to_delete); if (file.query_exists(null)) { file.delete(null); diff --git a/icons/bing.svg b/icons/bing.svg index 91d2bdde..192bf090 100644 --- a/icons/bing.svg +++ b/icons/bing.svg @@ -9,12 +9,15 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="302.14868" - height="431.53552" + width="128" + height="128" id="svg2" version="1.1" - inkscape:version="0.92.1 r15371" - sodipodi:docname="File-Bing_logo2016.svg"> + inkscape:version="0.91 r13725" + sodipodi:docname="bing.svg" + inkscape:export-filename="/home/giulio/Scaricati/bing.svg.png" + inkscape:export-xdpi="90" + inkscape:export-ydpi="90"> + inkscape:window-maximized="1"> @@ -67,10 +70,10 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(332.76667,-848.74697)"> + transform="translate(226.45871,-1000.5147)"> diff --git a/locale/BingWallpaper.pot b/locale/BingWallpaper.pot index d2359909..52f51c81 100644 --- a/locale/BingWallpaper.pot +++ b/locale/BingWallpaper.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-09-12 20:35+1000\n" +"POT-Creation-Date: 2017-10-02 14:40+1000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -73,7 +73,7 @@ msgstr "" msgid "Override automatic resolution selection" msgstr "" -#: Settings.ui.h:15 extension.js:132 +#: Settings.ui.h:15 extension.js:118 msgid "Settings" msgstr "" @@ -110,38 +110,67 @@ msgstr "" msgid "About" msgstr "" -#: extension.js:81 -msgid "Bing website" -msgstr "" - -#: extension.js:128 +#: extension.js:113 msgid "" msgstr "" -#: extension.js:129 +#: extension.js:114 msgid "Show description" msgstr "" -#: extension.js:130 +#: extension.js:115 +msgid "Copy image URL to clipboard" +msgstr "" + +#: extension.js:116 msgid "Set wallpaper" msgstr "" -#: extension.js:131 +#: extension.js:117 msgid "Refresh Now" msgstr "" -#: extension.js:174 +#: extension.js:160 +msgid "Open extension settings" +msgstr "" + +#: extension.js:165 +msgid "Bing website" +msgstr "" + +#: extension.js:197 msgid "Next refresh" msgstr "" -#: extension.js:252 +#: extension.js:288 +msgid "Market not available in your region" +msgstr "" + +#: extension.js:288 +msgid "" +"The selected market is not available in your country or geographic region.\n" +msgstr "" + +#: extension.js:297 msgid "Bing Wallpaper of the Day for" msgstr "" -#: extension.js:298 +#: extension.js:346 msgid "No wallpaper available" msgstr "" -#: extension.js:299 +#: extension.js:347 msgid "No picture for today ๐Ÿ˜ž." msgstr "" + +#: prefs.js:151 +msgid "Fetching data..." +msgstr "" + +#: prefs.js:163 +msgid "This market is not available in your region" +msgstr "" + +#: prefs.js:167 +msgid "A network error occured" +msgstr "" diff --git a/locale/it/LC_MESSAGES/BingWallpaper.mo b/locale/it/LC_MESSAGES/BingWallpaper.mo new file mode 100644 index 00000000..f582c3c0 Binary files /dev/null and b/locale/it/LC_MESSAGES/BingWallpaper.mo differ diff --git a/locale/it/LC_MESSAGES/BingWallpaper.po b/locale/it/LC_MESSAGES/BingWallpaper.po new file mode 100644 index 00000000..3ffc36ff --- /dev/null +++ b/locale/it/LC_MESSAGES/BingWallpaper.po @@ -0,0 +1,158 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-09-12 20:35+1000\n" +"PO-Revision-Date: 2017-09-30 20:15+0000\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.4\n" +"Last-Translator: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"Language: it\n" + +#: Settings.ui.h:1 +msgid "Hide the indicator" +msgstr "Nascondi l'indicatore" + +#: Settings.ui.h:2 +msgid "Send a notification with explanation when a new image is downloaded." +msgstr "" +"Invia una notifica con la descrizione quando una nuova immagine viene " +"scaricata." + +#: Settings.ui.h:3 +msgid "Notifications" +msgstr "Notifiche" + +#: Settings.ui.h:4 +msgid "Use transient notifications (auto dismiss)" +msgstr "Usa notifiche transitorie (rimozione automatica)" + +#: Settings.ui.h:5 +msgid "Set background image" +msgstr "Imposta l'immagine dello sfondo" + +#: Settings.ui.h:6 +msgid "Set lock screen image" +msgstr "Imposta l'immagine della schermata di blocco" + +#: Settings.ui.h:7 +msgid "Download folder:" +msgstr "Cartella di scaricamento:" + +#: Settings.ui.h:8 +msgid "Bing Wallpaper pictures folder" +msgstr "Cartella degli sfondi Bing" + +#: Settings.ui.h:9 +msgid "Delete previously downloaded wallpapers:" +msgstr "Cancella gli sfondi scaricati in precedenza:" + +#: Settings.ui.h:10 +msgid "Days to store wallpapers before deleting:" +msgstr "Giorni per cui mantenere gli sfondi prima di cancellarli:" + +#: Settings.ui.h:11 +msgid "Bing locale:" +msgstr "Localizzazione di Bing:" + +#: Settings.ui.h:12 +msgid "Default is English - United States" +msgstr "Predefinito รจ Inglese - Stati Uniti" + +#: Settings.ui.h:13 +msgid "Screen resolution:" +msgstr "Risoluzione dello schermo:" + +#: Settings.ui.h:14 +msgid "Override automatic resolution selection" +msgstr "Escludi la selezione automatica della risoluzione" + +#: Settings.ui.h:15 extension.js:132 +msgid "Settings" +msgstr "Impostazioni" + +#: Settings.ui.h:16 +msgid "Gnome shell extension version: " +msgstr "Versione dell'estensione per Gnome shell: " + +#: Settings.ui.h:17 +msgid "" +"Changes your wallpaper daily to the Bing picture of the day for your region. " +"Creates a notification for the picture description and copyright information." +msgstr "" +"Cambia il tuo sfondo giornalmente con l'immagine del giorno di Bing per la " +"tua regione. Crea una notifica con la descrizione dell'immagine e le " +"informazioni sui diritti d'autore." + +#: Settings.ui.h:18 +msgid "Maintained by Michael Carroll" +msgstr "Mantenuto da Michael Carroll" + +#: Settings.ui.h:19 +msgid "https://github.com/neffo/bing-wallpaper-gnome-extension" +msgstr "https://github.com/neffo/bing-wallpaper-gnome-extension" + +#: Settings.ui.h:20 +msgid "Based on NASA APOD Gnome shell extension by Elia Argentieri" +msgstr "Basato sull'estensione per Gnome shell NASA APOD di Elia Argentieri" + +#: Settings.ui.h:21 +msgid "" +"This program comes with ABSOLUTELY NO WARRANTY.\n" +"See the GNU General Public License, version 3 or later for details." +msgstr "" +"Questo programma viene fornito ASSOLUTAMENTE SENZA " +"GARANZIA.\n" +"Vedi la Licenza Pubblica Generale GNU, versione 3 o successiva per i dettagli." +"" + +#: Settings.ui.h:23 +msgid "About" +msgstr "Informazioni" + +#: extension.js:81 +msgid "Bing website" +msgstr "Sito web Bing" + +#: extension.js:128 +msgid "" +msgstr "" + +#: extension.js:129 +msgid "Show description" +msgstr "Mostra la descrizione" + +#: extension.js:130 +msgid "Set wallpaper" +msgstr "Imposta lo sfondo" + +#: extension.js:131 +msgid "Refresh Now" +msgstr "Aggiorna ora" + +#: extension.js:174 +msgid "Next refresh" +msgstr "Prossimo aggiornamento" + +#: extension.js:252 +msgid "Bing Wallpaper of the Day for" +msgstr "Sfondo Bing del giorno per" + +#: extension.js:298 +msgid "No wallpaper available" +msgstr "Nessuno sfondo disponibile" + +#: extension.js:299 +msgid "No picture for today ๐Ÿ˜ž." +msgstr "Nessuna immagine per oggi ๐Ÿ˜ž." diff --git a/metadata.json b/metadata.json index 8bbe8678..70dfc882 100644 --- a/metadata.json +++ b/metadata.json @@ -1,9 +1,9 @@ { - "uuid": "BingWallpaper@ineffable-gmail.com", - "shell-version": ["3.18", "3.20", "3.22", "3.24", "3.24.2"], - "name": "Bing Wallpaper Changer", + "uuid": "BingWallpaper@ineffable-gmail.com", + "shell-version": ["3.18", "3.20", "3.22", "3.24", "3.24.2", "3.26"], + "name": "Bing Wallpaper Changer", "settings-schema": "org.gnome.shell.extensions.bingwallpaper", - "description": "Lightweight GNOME shell extension to change your wallpaper every day to Microsoft Bing's wallpaper (the image you see when you visit Bing.com). It will also show a notification containing the title and the explanation of the image.\n\n *Disclaimer*: this extension is unofficial and not affiliated with Bing or Microsoft in any way. Images are protected by copyright and are licensed only for use as wallpapers.\n\nThis extension is based extensively on the NASA APOD extension by Elinvention (https://github.com/Elinvention) and inspired by Bing Desktop Wallpaper Changer by Utkarsh Gupta (https://github.com/UtkarshGpta).\n\nFeatures:\n* Fetches the Bing wallpaper of the day and sets as both lock screen and desktop wallpaper (these are both user selectable)\n* Optionally force a specific region (i.e. locale)\n* Automatically selects the highest resolution (and most appropriate wallpaper) in multiple monitor setups\n* Optionally clean up Wallpaper directory after between 1 and 7 days (delete oldest first)\n* Only attempts to download wallpapers when they have been updated\n* Doesn't poll continuously - only once per day and on startup (schedules a refresh when Bing is due to update)", - "version": "14", + "description": "Lightweight GNOME shell extension to change your wallpaper every day to Microsoft Bing's wallpaper (the image you see when you visit Bing.com). It will also show a notification containing the title and the explanation of the image.\n\n *Disclaimer*: this extension is unofficial and not affiliated with Bing or Microsoft in any way. Images are protected by copyright and are licensed only for use as wallpapers.\n\nThis extension is based extensively on the NASA APOD extension by Elinvention (https://github.com/Elinvention) and inspired by Bing Desktop Wallpaper Changer by Utkarsh Gupta (https://github.com/UtkarshGpta).\n\nFeatures:\n* Fetches the Bing wallpaper of the day and sets as both lock screen and desktop wallpaper (these are both user selectable)\n* Optionally force a specific region (i.e. locale)\n* Automatically selects the highest resolution (and most appropriate wallpaper) in multiple monitor setups\n* Optionally clean up Wallpaper directory after between 1 and 7 days (delete oldest first)\n* Only attempts to download wallpapers when they have been updated\n* Doesn't poll continuously - only once per day and on startup (schedules a refresh when Bing is due to update)", + "version": "15", "url": "https://github.com/neffo/bing-wallpaper-gnome-extension" } diff --git a/prefs.js b/prefs.js index 730c8cd5..fb2c85d9 100644 --- a/prefs.js +++ b/prefs.js @@ -4,6 +4,11 @@ const Gio = imports.gi.Gio; const GLib = imports.gi.GLib; const Me = imports.misc.extensionUtils.getCurrentExtension(); const Utils = Me.imports.utils; +const Soup = imports.gi.Soup; +const Lang = imports.lang; + +let httpSession = new Soup.SessionAsync(); +Soup.Session.prototype.add_feature.call(httpSession, new Soup.ProxyResolverDefault()); const Convenience = Me.imports.convenience; const Gettext = imports.gettext.domain('BingWallpaper'); @@ -12,28 +17,31 @@ const _ = Gettext.gettext; let settings; let markets = ['ar-XA', 'bg-BG','cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'el-GR', 'en-AU', 'en-CA', 'en-GB', -'en-ID', 'en-IE', 'en-IN', 'en-MY', 'en-NZ', 'en-PH', 'en-SG', 'en-US', 'en-XA', 'en-ZA', 'es-AR', +'en-ID', 'en-IE', 'en-IN', 'en-MY', 'en-NZ', 'en-PH', 'en-SG', 'en-US', 'en-WW', 'en-XA', 'en-ZA', 'es-AR', 'es-CL', 'es-ES', 'es-MX', 'es-US', 'es-XL', 'et-EE', 'fi-FI', 'fr-BE', 'fr-CA', 'fr-CH', 'fr-FR', 'he-IL', 'hr-HR', 'hu-HU', 'it-IT', 'ja-JP', 'ko-KR', 'lt-LT', 'lv-LV', 'nb-NO', 'nl-BE', 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sl-SL', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'zh-CN', 'zh-HK', 'zh-TW']; -let marketName = ['Arabic โ€“ Arabia', 'Bulgarian โ€“ Bulgaria', 'Czech โ€“ Czech Republic', 'Danish โ€“ Denmark', - 'German โ€“ Austria', 'German โ€“ Switzerland', 'German โ€“ Germany', 'Greek โ€“ Greece', - 'English โ€“ Australia', 'English โ€“ Canada', 'English โ€“ United Kingdom', 'English โ€“ Indonesia', - 'English โ€“ Ireland', 'English โ€“ India', 'English โ€“ Malaysia', 'English โ€“ New Zealand', - 'English โ€“ Philippines', 'English โ€“ Singapore', 'English โ€“ United States', - 'English โ€“ Arabia', 'English โ€“ South Africa', 'Spanish โ€“ Argentina', 'Spanish โ€“ Chile', - 'Spanish โ€“ Spain', 'Spanish โ€“ Mexico', 'Spanish โ€“ United States', 'Spanish โ€“ Latin America', - 'Estonian โ€“ Estonia', 'Finnish โ€“ Finland', 'French โ€“ Belgium', 'French โ€“ Canada', - 'French โ€“ Switzerland', 'French โ€“ France', 'Hebrew โ€“ Israel', 'Croatian โ€“ Croatia', - 'Hungarian โ€“ Hungary', 'Italian โ€“ Italy', 'Japanese โ€“ Japan', 'Korean โ€“ Korea', - 'Lithuanian โ€“ Lithuania', 'Latvian โ€“ Latvia', 'Norwegian โ€“ Norway', 'Dutch โ€“ Belgium', - 'Dutch โ€“ Netherlands', 'Polish โ€“ Poland', 'Portuguese โ€“ Brazil', 'Portuguese โ€“ Portugal', - 'Romanian โ€“ Romania', 'Russian โ€“ Russia', 'Slovak โ€“ Slovak Republic', 'Slovenian โ€“ Slovenia', - 'Swedish โ€“ Sweden', 'Thai โ€“ Thailand', 'Turkish โ€“ Turkey', 'Ukrainian โ€“ Ukraine', +let marketName = ['Arabic โ€“ Arabia', 'Bulgarian โ€“ Bulgaria', 'Czech โ€“ Czech Republic', 'Danish โ€“ Denmark', + 'German โ€“ Austria', 'German โ€“ Switzerland', 'German โ€“ Germany', 'Greek โ€“ Greece', + 'English โ€“ Australia', 'English โ€“ Canada', 'English โ€“ United Kingdom', 'English โ€“ Indonesia', + 'English โ€“ Ireland', 'English โ€“ India', 'English โ€“ Malaysia', 'English โ€“ New Zealand', + 'English โ€“ Philippines', 'English โ€“ Singapore', 'English โ€“ United States', 'English - International', + 'English โ€“ Arabia', 'English โ€“ South Africa', 'Spanish โ€“ Argentina', 'Spanish โ€“ Chile', + 'Spanish โ€“ Spain', 'Spanish โ€“ Mexico', 'Spanish โ€“ United States', 'Spanish โ€“ Latin America', + 'Estonian โ€“ Estonia', 'Finnish โ€“ Finland', 'French โ€“ Belgium', 'French โ€“ Canada', + 'French โ€“ Switzerland', 'French โ€“ France', 'Hebrew โ€“ Israel', 'Croatian โ€“ Croatia', + 'Hungarian โ€“ Hungary', 'Italian โ€“ Italy', 'Japanese โ€“ Japan', 'Korean โ€“ Korea', + 'Lithuanian โ€“ Lithuania', 'Latvian โ€“ Latvia', 'Norwegian โ€“ Norway', 'Dutch โ€“ Belgium', + 'Dutch โ€“ Netherlands', 'Polish โ€“ Poland', 'Portuguese โ€“ Brazil', 'Portuguese โ€“ Portugal', + 'Romanian โ€“ Romania', 'Russian โ€“ Russia', 'Slovak โ€“ Slovak Republic', 'Slovenian โ€“ Slovenia', + 'Swedish โ€“ Sweden', 'Thai โ€“ Thailand', 'Turkish โ€“ Turkey', 'Ukrainian โ€“ Ukraine', 'Chinese โ€“ China', 'Chinese โ€“ Hong Kong SAR', 'Chinese โ€“ Taiwan']; let resolutions = [ 'auto', '1920x1200', '1920x1080', '1366x768', '1280x720', '1024x768', '800x600']; +let marketDescription = null; + +const BingImageURL = "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mbl=1&mkt="; function init() { settings = Utils.getSettings(Me); @@ -60,7 +68,7 @@ function buildPrefsWidget(){ let resolutionEntry = buildable.get_object('resolution'); let deleteSwitch = buildable.get_object('delete_previous'); let daysSpin = buildable.get_object('days_after_spinbutton'); - let marketDescription = buildable.get_object('market_description'); + marketDescription = buildable.get_object('market_description'); // previous wallpaper images let images=[]; @@ -135,4 +143,28 @@ function validate_market() { let market = settings.get_string('market'); if (market == "" || markets.indexOf(market) == -1 ) // if not a valid market settings.reset('market'); -} \ No newline at end of file + + log('Testing : '+BingImageURL); + + let request = Soup.Message.new('GET', BingImageURL+market); // + market + log("fetching: " + BingImageURL+market); + marketDescription.set_label(_("Fetching data...")); + + // queue the http request + httpSession.queue_message(request, Lang.bind(this, function(httpSession, message) { + if (message.status_code == 200) { + let data = message.response_body.data; + log("Recieved "+data.length+" bytes"); + let checkData = JSON.parse(data); + let checkStatus = checkData['market']['mkt']; + if (checkStatus == market) { + marketDescription.set_label('Data OK, '+data.length+' bytes recieved'); + } else { + marketDescription.set_label(_("This market is not available in your region")); + } + } else { + log("Network error occured: "+message.status_code); + marketDescription.set_label(_("A network error occured")+": "+message.status_code); + } + })); +}