Skip to content

Commit

Permalink
Version 45 (#194)
Browse files Browse the repository at this point in the history
* Added Turkish language .po file (#193) #14

* build Turkish translation

* fix notifications #195

* NEW: favorite images & shuffle only favorites

* update example image

* update copyright dates

---------

Co-authored-by: Serhat KILIÇ <github@leparutill.com>
  • Loading branch information
neffo and Serhat KILIÇ committed Mar 28, 2023
1 parent 33a35fc commit 84bd171
Show file tree
Hide file tree
Showing 20 changed files with 657 additions and 52 deletions.
2 changes: 1 addition & 1 deletion BWClipboard.js
@@ -1,5 +1,5 @@
// Bing Wallpaper GNOME extension
// Copyright (C) 2017-2021 Michael Carroll
// Copyright (C) 2017-2023 Michael Carroll
// This extension is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -17,8 +17,8 @@ Also, check out my related [Google Earth View wallpaper extension](https://githu
* Shuffle/randomise wallpapers at adjustable intervals (including from your stored Bing images)
* Image gallery to view, select and curate stored images
* Optionally delete old images after a week, or you can keep (and curate) them forever
* Override the lockscreen blur
* Language support: English (en), German (de), Dutch (nl), Italian (it), Polish (pl), Chinese (zh_CN, zh_TW), French (fr_FR), Portuguese (pt, pt_BR), Ukrainian (uk), Russian (ru_RU), Spanish (es), Korean (ko), Indonesian (id), Catalan (ca), Norwegian Bokmål (nb) & Nynorsk (ni), Swedish (sv), Arabic (ar), Hungarian (hu) and Japanese (ja) - a HUGE thanks to the translators
* Override the lockscreen blur (NEW: lockscreen blur is now dynamic!)
* Language support: English (en), German (de), Dutch (nl), Italian (it), Polish (pl), Chinese (zh_CN, zh_TW), French (fr_FR), Portuguese (pt, pt_BR), Ukrainian (uk), Russian (ru_RU), Spanish (es), Korean (ko), Indonesian (id), Catalan (ca), Norwegian Bokmål (nb) & Nynorsk (nn), Swedish (sv), Arabic (ar), Hungarian (hu), Japanese (ja), Czech (cs_CZ), Finnish (fi_FI) and Turkish (tr) - a HUGE thanks to the translators
* Image preview in menus & ability to manually set wallpapers individually or copy image to clipboard
* A selection of different theme-aware indicator (tray) icons to choose (or hide it completely)

Expand Down
2 changes: 1 addition & 1 deletion blur.js
@@ -1,5 +1,5 @@
// Bing Wallpaper GNOME extension
// Copyright (C) 2017-2021 Michael Carroll
// Copyright (C) 2017-2023 Michael Carroll
// This extension is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
Expand Down
28 changes: 27 additions & 1 deletion carousel.js
@@ -1,5 +1,5 @@
// Bing Wallpaper GNOME extension
// Copyright (C) 2017-2021 Michael Carroll
// Copyright (C) 2017-2023 Michael Carroll
// This extension is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
Expand Down Expand Up @@ -111,6 +111,16 @@ var Carousel = class Carousel {
let applyButton = buildable.get_object('applyButton');
let infoButton = buildable.get_object('infoButton');
let deleteButton = buildable.get_object('deleteButton');
let favButton = buildable.get_object('favButton');
let unfavButton = buildable.get_object('unfavButton');

if (Utils.isFavourite(image)) {
favButton.set_visible(false);
this.log('image is favourited');
}
else {
unfavButton.set_visible(false);
}

try {
this._load_image(galleryImage, filename);
Expand Down Expand Up @@ -151,6 +161,22 @@ var Carousel = class Carousel {
if (this.callbackfunc)
this.callbackfunc();
});

// button is unchecked, so we want to make the checked one visible
favButton.connect('clicked', (widget) => {
this.log('favourited '+Utils.getImageUrlBase(image));
widget.set_visible(false);
unfavButton.set_visible(true);
Utils.setImageFavouriteStatus(this.settings, image.urlbase, true);
});

// button is checked, so we want to make the unchecked one visible
unfavButton.connect('clicked', (widget) => {
this.log('unfavourited '+Utils.getImageUrlBase(image));
widget.set_visible(false);
favButton.set_visible(true);
Utils.setImageFavouriteStatus(this.settings, image.urlbase, false);
});

let item = buildable.get_object('flowBoxChild');
return item;
Expand Down
85 changes: 73 additions & 12 deletions extension.js
@@ -1,5 +1,5 @@
// Bing Wallpaper GNOME extension
// Copyright (C) 2017-2022 Michael Carroll
// Copyright (C) 2017-2023 Michael Carroll
// This extension is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
Expand Down Expand Up @@ -40,6 +40,8 @@ const ICON_PAUSE_MODE_BUTTON = 'media-playback-pause-symbolic';
const ICON_PLAY_MODE_BUTTON = 'media-playback-start-symbolic';
const ICON_REFRESH = 'view-refresh-symbolic';
const ICON_RANDOM = Me.dir.get_child('icons').get_path() + '/'+'game-die-symbolic.svg';
const ICON_FAVE_BUTTON = Me.dir.get_child('icons').get_path() + '/'+'fav-symbolic.svg';
const ICON_UNFAVE_BUTTON = Me.dir.get_child('icons').get_path() + '/'+'unfav-symbolic.svg';

let bingWallpaperIndicator = null;
let blur = null;
Expand Down Expand Up @@ -111,6 +113,7 @@ class BingWallpaperIndicator extends PanelMenu.Button {
this.clipboard = new BWClipboard.BWClipboard();
this.imageIndex = null;
this.logger = null;
this.favourite_status = false;

if (!blur) // as Blur isn't disabled on screen lock (like the rest of the extension is)
blur = new Blur.Blur();
Expand Down Expand Up @@ -156,11 +159,12 @@ class BingWallpaperIndicator extends PanelMenu.Button {
this.toggleSetBackground = newMenuSwitchItem(_("Set background image"), this._settings.get_boolean('set-background'));
this.toggleSelectNew = newMenuSwitchItem(_("Always show new images"), this._settings.get_boolean('revert-to-current-image'));
this.toggleShuffle = newMenuSwitchItem(_("Image shuffle mode"), true);
this.toggleShuffleOnlyFaves = newMenuSwitchItem(_("Image shuffle only favourites"), this._settings.get_boolean('random-mode-include-only-favourites'));
this.toggleNotifications = newMenuSwitchItem(_("Enable desktop notifications"), this._settings.get_boolean('notify'));
this.toggleImageCount = newMenuSwitchItem(_("Show image count"), this._settings.get_boolean('show-count-in-image-title'));

[this.toggleNotifications, this.toggleImageCount, this.toggleSetBackground, this.toggleSelectNew,
this.toggleShuffle]
this.toggleShuffle, this.toggleShuffleOnlyFaves]
.forEach(e => this.settingsSubMenu.menu.addMenuItem(e));

// these items are a bit unique, we'll populate them in _setControls()
Expand Down Expand Up @@ -289,11 +293,14 @@ class BingWallpaperIndicator extends PanelMenu.Button {
this._settings.set_boolean('show-count-in-image-title', state);
this._selectImage(false);
});
this.toggleShuffleOnlyFaves.connect('toggled', (item, state) => {
this._settings.set_boolean('random-mode-include-only-favourites', state);
});

// shuffle is a special case
this._setShuffleToggleState();
this.toggleShuffle.connect('toggled', this._toggleShuffle.bind(this));

this.folderItem.connect('activate', Utils.openImageFolder.bind(this, this._settings));
if (this.clipboard.clipboard) { // only if we have a clipboard
this.clipboardImageItem.connect('activate', this._copyImageToClipboard.bind(this));
Expand Down Expand Up @@ -429,6 +436,7 @@ class BingWallpaperIndicator extends PanelMenu.Button {
else {
this.explainItem.label.set_text(this.explanation ? this.explanation : '');
}
this._setFavouriteIcon(this.favourite_status?ICON_FAVE_BUTTON:ICON_UNFAVE_BUTTON);
}

_wrapLabelItem(menuItem) {
Expand All @@ -440,6 +448,10 @@ class BingWallpaperIndicator extends PanelMenu.Button {
}

_setControls() {
this.favouriteBtn = this._newMenuIcon(
this.favourite_status?ICON_FAVE_BUTTON:ICON_UNFAVE_BUTTON,
this.controlItem,
this._favouriteImage);
this.prevBtn = this._newMenuIcon(
ICON_PREVIOUS_BUTTON,
this.controlItem,
Expand Down Expand Up @@ -478,7 +490,7 @@ class BingWallpaperIndicator extends PanelMenu.Button {
y_expand: true
});

if (position) {
if (position !== null) {
getActorCompat(parent).insert_child_at_index(iconBtn, position);
}
else {
Expand Down Expand Up @@ -546,6 +558,10 @@ class BingWallpaperIndicator extends PanelMenu.Button {
this.toggleShuffle.setToggleState(this._settings.get_string('selected-image') == 'random');
}

_toggleShuffleOnlyFaves() {

}

_toggleShuffle() {
if (this._settings.get_string('selected-image') == 'random') {
this._settings.set_string('selected-image', 'current');
Expand All @@ -557,6 +573,20 @@ class BingWallpaperIndicator extends PanelMenu.Button {
log('switched mode to ' + this._settings.get_string('selected-image'));
}

_favouriteImage() {
log('favourite image '+this.imageURL+' status was '+this.favourite_status);
this.favourite_status = !this.favourite_status;
Utils.setImageFavouriteStatus(this._settings, this.imageURL, this.favourite_status);
this._setFavouriteIcon(this.favourite_status?ICON_FAVE_BUTTON:ICON_UNFAVE_BUTTON);
}

_setFavouriteIcon(icon_name) {
let gicon = Gio.icon_new_for_string(icon_name);
this.favouriteBtn.get_children().forEach( (x, i) => {
x.set_gicon(gicon);
});
}

_gotoImage(relativePos) {
let imageList = Utils.getImageList(this._settings);
let curIndex = 0;
Expand Down Expand Up @@ -697,10 +727,21 @@ class BingWallpaperIndicator extends PanelMenu.Button {
}

if (this._settings.get_boolean('notify')) {
newImages.forEach((image, index) => {
log('New image to notify: ' + Utils.getImageTitle(image));
this._createNotification(image);
});
if (!this._settings.get_boolean('notify-only-latest')) {
// notify all new images
newImages.forEach((image, index) => {
log('New image to notify: ' + Utils.getImageTitle(image));
this._createNotification(image);
});
}
else {
// notify only the most recent image
let last = newImages.pop();
if (last) {
log('New image to notify: ' + Utils.getImageTitle(last));
this._createNotification(last);
}
}
}

this._restartTimeoutFromLongDate(parsed.images[0].fullstartdate); // timing is set by Bing, and possibly varies by market
Expand All @@ -721,19 +762,26 @@ class BingWallpaperIndicator extends PanelMenu.Button {
// set notifications icon
let source = new MessageTray.Source('Bing Wallpaper', 'preferences-desktop-wallpaper-symbolic');
Main.messageTray.add(source);
let msg = _('Bing Wallpaper of the Day for') + ' ' + this._localeDate(image.longstartdate);
let msg = _('Bing Wallpaper of the Day for') + ' ' + this._localeDate(image.fullstartdate);
let details = Utils.getImageTitle(image);
let notification = new MessageTray.Notification(source, msg, details);
notification.setTransient(this._settings.get_boolean('transient'));
source.showNotification(notification);
}

_selectImage(force_shuffle = false) {
let imageList = JSON.parse(this._settings.get_string('bing-json'));
let imageList = Utils.getImageList(this._settings);
let image = null;
// special values, 'current' is most recent (default mode), 'random' picks one at random, anything else should be filename

if (this.selected_image == 'random' || force_shuffle) {
if (this._settings.get_boolean('random-mode-include-only-favourites')) {
let favImageList = imageList.filter(Utils.isFavourite);
if (favImageList.length > 0)
imageList = favImageList;
else
log('not enough favourites available to shuffle');
}
this.imageIndex = Utils.getRandomInt(imageList.length);
image = imageList[this.imageIndex];
this._restartShuffleTimeout();
Expand Down Expand Up @@ -763,6 +811,13 @@ class BingWallpaperIndicator extends PanelMenu.Button {
this.imageinfolink = image.copyrightlink.replace(/^http:\/\//i, 'https://');
this.imageURL = BingURL + image.urlbase + '_' + resolution + '.jpg'; // generate image url for user's resolution
this.filename = toFilename(BingWallpaperDir, image.startdate, image.urlbase, resolution);

if (("favourite" in image) && image.favourite === true ) {
this.favourite_status = true;
}
else {
this.favourite_status = false;
}

let file = Gio.file_new_for_path(this.filename);
let file_exists = file.query_exists(null);
Expand Down Expand Up @@ -796,7 +851,7 @@ class BingWallpaperIndicator extends PanelMenu.Button {
let maxLongDate = Utils.getMaxLongDate(this._settings); // refresh date from most recent Bing image
let state = {maxlongdate: maxLongDate, title: this.title, explanation: this.explanation, copyright: this.copyright,
longstartdate: this.longstartdate, imageinfolink: this.imageinfolink, imageURL: this.imageURL,
filename: this.filename};
filename: this.filename, favourite: this.favourite_status};
let stateJSON = JSON.stringify(state);

log('Storing state as JSON: ' + stateJSON);
Expand All @@ -822,6 +877,12 @@ class BingWallpaperIndicator extends PanelMenu.Button {
this.imageURL = state.imageURL;
this.filename = state.filename;
this._selected_image = this._settings.get_string('selected-image');
if ("favourite" in state && state.favourite === true) {
this.favourite_status = true;
}
else {
this.favourite_status = false;
}
// update menus and thumbnail
this._setMenuText();
this._setBackground();
Expand All @@ -832,7 +893,7 @@ class BingWallpaperIndicator extends PanelMenu.Button {
}

if (this.selected_image == 'random') {
this._setRandom();
this._shuffleImage();
this._restartTimeoutFromLongDate(maxLongDate);
}
else {
Expand Down
1 change: 1 addition & 0 deletions icons/checked-symbolic.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions icons/fav-symbolic.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions icons/unchecked-symbolic.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions icons/unfav-symbolic.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 84bd171

Please sign in to comment.