2014-08-20 18:36:32 +00:00
|
|
|
const Lang = imports.lang;
|
2016-04-08 12:50:25 +00:00
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
|
const Shell = imports.gi.Shell;
|
2014-08-20 00:25:47 +00:00
|
|
|
|
2014-09-01 13:28:46 +00:00
|
|
|
//self
|
|
|
|
|
const Self = imports.misc.extensionUtils.getCurrentExtension();
|
|
|
|
|
const WallpaperController = Self.imports.wallpaperController;
|
|
|
|
|
|
2017-07-20 11:48:13 +00:00
|
|
|
const LoggerModule = Self.imports.logger;
|
|
|
|
|
|
2014-08-20 18:36:32 +00:00
|
|
|
// UI Imports
|
2014-08-20 00:25:47 +00:00
|
|
|
const Main = imports.ui.main;
|
2014-08-20 18:36:32 +00:00
|
|
|
const St = imports.gi.St;
|
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2017-07-19 13:08:50 +00:00
|
|
|
const CustomElements = Self.imports.elements;
|
2014-10-22 13:17:46 +00:00
|
|
|
const Tweener = imports.ui.tweener;
|
2014-08-20 18:36:32 +00:00
|
|
|
|
2018-07-26 17:14:39 +00:00
|
|
|
const Timer = Self.imports.timer;
|
|
|
|
|
|
2014-08-20 18:36:32 +00:00
|
|
|
// Filesystem
|
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
|
|
2016-04-08 16:40:52 +00:00
|
|
|
// Settings
|
2018-07-29 14:02:38 +00:00
|
|
|
const Prefs = Self.imports.settings;
|
2016-04-08 16:40:52 +00:00
|
|
|
|
2014-09-01 13:28:46 +00:00
|
|
|
let wallpaperController;
|
2018-01-16 18:14:18 +00:00
|
|
|
let panelEntry;
|
2014-08-20 18:36:32 +00:00
|
|
|
|
2018-07-29 14:02:38 +00:00
|
|
|
let settings;
|
|
|
|
|
let hidePanelIconHandler = null;
|
|
|
|
|
|
2014-09-01 13:28:46 +00:00
|
|
|
function init(metaData) {
|
2018-07-29 14:02:38 +00:00
|
|
|
settings = new Prefs.Settings();
|
2018-07-29 16:15:21 +00:00
|
|
|
wallpaperController = new WallpaperController.WallpaperController();
|
2014-08-20 00:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-16 18:14:18 +00:00
|
|
|
function enable() {
|
|
|
|
|
// enable Extension
|
2018-07-29 14:02:38 +00:00
|
|
|
|
2018-01-16 18:14:18 +00:00
|
|
|
// UI
|
|
|
|
|
panelEntry = new RandomWallpaperEntry(0, "Random wallpaper");
|
|
|
|
|
|
|
|
|
|
// add to panel
|
|
|
|
|
Main.panel.addToStatusArea("random-wallpaper-menu", panelEntry);
|
2018-07-29 14:02:38 +00:00
|
|
|
|
|
|
|
|
hidePanelIconHandler = settings.observe('hide-panel-icon', updatePanelMenuVisibility);
|
|
|
|
|
updatePanelMenuVisibility();
|
2018-01-16 18:14:18 +00:00
|
|
|
}
|
2014-08-20 00:25:47 +00:00
|
|
|
|
2018-01-16 18:14:18 +00:00
|
|
|
function disable() {
|
|
|
|
|
// disable Extension
|
2018-11-01 18:40:57 +00:00
|
|
|
panelEntry.clearHistoryList();
|
2018-01-16 18:14:18 +00:00
|
|
|
panelEntry.destroy();
|
2018-07-25 14:01:28 +00:00
|
|
|
|
2018-07-29 14:02:38 +00:00
|
|
|
// remove all signal handlers
|
|
|
|
|
if (hidePanelIconHandler !== null) {
|
|
|
|
|
settings.disconnect(hidePanelIconHandler);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 14:01:28 +00:00
|
|
|
// cleanup the timer singleton
|
|
|
|
|
let timer = new Timer.AFTimer();
|
|
|
|
|
timer.cleanup();
|
2018-01-16 18:14:18 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-29 14:02:38 +00:00
|
|
|
function updatePanelMenuVisibility(isVisible) {
|
|
|
|
|
|
|
|
|
|
if (settings.get('hide-panel-icon', 'boolean')) {
|
|
|
|
|
panelEntry.actor.hide();
|
|
|
|
|
} else {
|
|
|
|
|
panelEntry.actor.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-16 18:14:18 +00:00
|
|
|
var RandomWallpaperEntry = new Lang.Class({
|
2014-10-21 21:13:21 +00:00
|
|
|
Extends: PanelMenu.Button,
|
|
|
|
|
Name: "RandomWallpaperEntry",
|
2017-07-20 11:48:13 +00:00
|
|
|
logger: null,
|
2014-08-20 00:25:47 +00:00
|
|
|
|
2018-07-27 15:36:47 +00:00
|
|
|
_init: function (menuAlignment, nameText) {
|
2014-10-21 21:13:21 +00:00
|
|
|
this.parent(menuAlignment, nameText);
|
2017-07-20 11:48:13 +00:00
|
|
|
this.logger = new LoggerModule.Logger('RWG3', 'RandomWallpaperEntry');
|
2014-10-19 09:01:05 +00:00
|
|
|
|
2014-10-23 14:34:19 +00:00
|
|
|
// Panelmenu Icon
|
2014-10-22 13:17:46 +00:00
|
|
|
this.statusIcon = new CustomElements.StatusElement();
|
2018-11-01 19:03:30 +00:00
|
|
|
this.actor.add_child(this.statusIcon.icon);
|
2014-08-20 18:36:32 +00:00
|
|
|
|
2014-10-23 14:34:19 +00:00
|
|
|
// new wallpaper button
|
2017-02-24 22:31:35 +00:00
|
|
|
this.newWallpaperItem = new CustomElements.NewWallpaperElement();
|
2014-08-20 18:36:32 +00:00
|
|
|
|
2014-10-23 14:34:19 +00:00
|
|
|
this.menu.addMenuItem(this.newWallpaperItem);
|
|
|
|
|
|
2014-10-21 21:13:21 +00:00
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2014-10-19 09:01:05 +00:00
|
|
|
|
2017-07-20 19:49:54 +00:00
|
|
|
// current background section
|
|
|
|
|
this.currentBackgroundSection = new PopupMenu.PopupMenuSection();
|
|
|
|
|
this.menu.addMenuItem(this.currentBackgroundSection);
|
|
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
|
|
|
|
|
2014-10-23 14:34:19 +00:00
|
|
|
// history section
|
2018-07-29 18:31:07 +00:00
|
|
|
this.historySection = new CustomElements.HistorySection();
|
2014-10-21 21:13:21 +00:00
|
|
|
this.menu.addMenuItem(this.historySection);
|
2014-10-19 09:01:05 +00:00
|
|
|
|
2014-10-21 21:13:21 +00:00
|
|
|
this.setHistoryList();
|
2014-10-19 09:01:05 +00:00
|
|
|
|
2014-10-21 21:13:21 +00:00
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2017-02-03 16:27:29 +00:00
|
|
|
|
2014-10-23 14:34:19 +00:00
|
|
|
// clear history button
|
|
|
|
|
this.clearHistoryItem = new PopupMenu.PopupMenuItem('Clear History');
|
|
|
|
|
this.menu.addMenuItem(this.clearHistoryItem);
|
2014-09-01 13:28:46 +00:00
|
|
|
|
2016-04-08 12:50:25 +00:00
|
|
|
// open wallpaper folder button
|
|
|
|
|
this.openFolder = new PopupMenu.PopupMenuItem('Open Wallpaper Folder');
|
|
|
|
|
this.menu.addMenuItem(this.openFolder);
|
|
|
|
|
|
2017-07-20 12:16:08 +00:00
|
|
|
// settings button
|
|
|
|
|
this.openSettings = new PopupMenu.PopupMenuItem('Settings');
|
|
|
|
|
this.menu.addMenuItem(this.openSettings);
|
|
|
|
|
|
2014-10-23 14:34:19 +00:00
|
|
|
/*
|
|
|
|
|
add eventlistener
|
|
|
|
|
*/
|
2017-02-24 22:31:35 +00:00
|
|
|
wallpaperController.registerStartLoadingHook(this.statusIcon.startLoading.bind(this.statusIcon));
|
|
|
|
|
wallpaperController.registerStopLoadingHook(this.statusIcon.stopLoading.bind(this.statusIcon));
|
|
|
|
|
wallpaperController.registerStopLoadingHook(this.setHistoryList.bind(this));
|
|
|
|
|
|
2014-10-23 14:34:19 +00:00
|
|
|
// new wallpaper event
|
2018-07-27 15:36:47 +00:00
|
|
|
this.newWallpaperItem.connect('activate', function () {
|
2017-02-24 22:31:35 +00:00
|
|
|
wallpaperController.fetchNewWallpaper();
|
2014-10-21 21:13:21 +00:00
|
|
|
});
|
2014-08-20 00:25:47 +00:00
|
|
|
|
2014-10-23 14:34:19 +00:00
|
|
|
// clear history event
|
2018-07-27 15:36:47 +00:00
|
|
|
this.clearHistoryItem.connect('activate', function () {
|
2014-10-23 14:34:19 +00:00
|
|
|
wallpaperController.deleteHistory();
|
|
|
|
|
});
|
|
|
|
|
|
2016-04-08 12:50:25 +00:00
|
|
|
// Open Wallpaper Folder
|
2018-07-27 15:36:47 +00:00
|
|
|
this.openFolder.connect('activate', function (event) {
|
2016-04-08 12:50:25 +00:00
|
|
|
let uri = GLib.filename_to_uri(wallpaperController.wallpaperlocation, "");
|
2017-02-03 16:27:29 +00:00
|
|
|
Gio.AppInfo.launch_default_for_uri(uri, global.create_app_launch_context(0, -1))
|
|
|
|
|
});
|
|
|
|
|
|
2018-07-27 15:36:47 +00:00
|
|
|
this.openSettings.connect("activate", function () {
|
2017-07-20 12:16:08 +00:00
|
|
|
// call gnome settings tool for this extension
|
|
|
|
|
let app = Shell.AppSystem.get_default().lookup_app("gnome-shell-extension-prefs.desktop");
|
2018-07-27 15:36:47 +00:00
|
|
|
if (app != null) {
|
2017-07-20 12:16:08 +00:00
|
|
|
// only works in Gnome >= 3.12
|
|
|
|
|
let info = app.get_app_info();
|
|
|
|
|
let timestamp = global.display.get_current_time_roundtrip();
|
|
|
|
|
info.launch_uris([Self.uuid], global.create_app_launch_context(timestamp, -1));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-07-27 15:36:47 +00:00
|
|
|
this.menu.actor.connect('show', function () {
|
2017-02-24 22:31:35 +00:00
|
|
|
this.newWallpaperItem.show();
|
|
|
|
|
}.bind(this));
|
2016-04-08 12:50:25 +00:00
|
|
|
|
2014-10-21 21:13:21 +00:00
|
|
|
// when the popupmenu disapears, check if the wallpaper is the original and
|
|
|
|
|
// reset it if needed
|
2017-02-24 22:31:35 +00:00
|
|
|
this.menu.actor.connect('hide', () => {
|
2017-02-03 16:27:29 +00:00
|
|
|
wallpaperController.resetWallpaper();
|
2014-10-21 21:13:21 +00:00
|
|
|
});
|
2014-10-23 14:34:19 +00:00
|
|
|
|
2017-07-23 01:14:23 +00:00
|
|
|
this.menu.actor.connect('leave-event', () => {
|
2017-02-03 16:27:29 +00:00
|
|
|
wallpaperController.resetWallpaper();
|
2014-10-23 14:34:19 +00:00
|
|
|
});
|
2017-02-03 16:27:29 +00:00
|
|
|
|
2018-08-03 15:01:43 +00:00
|
|
|
settings.observe('history', this.setHistoryList.bind(this));
|
2014-10-21 21:13:21 +00:00
|
|
|
},
|
2014-09-01 13:28:46 +00:00
|
|
|
|
2017-07-20 19:49:54 +00:00
|
|
|
setCurrentBackgroundElement: function () {
|
|
|
|
|
this.currentBackgroundSection.removeAll();
|
|
|
|
|
|
|
|
|
|
let historyController = wallpaperController.getHistoryController();
|
|
|
|
|
let history = historyController.history;
|
|
|
|
|
|
|
|
|
|
if (history.length > 0) {
|
|
|
|
|
let currentImage = new CustomElements.CurrentImageElement(history[0]);
|
|
|
|
|
this.currentBackgroundSection.addMenuItem(currentImage);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2018-07-27 15:36:47 +00:00
|
|
|
setHistoryList: function () {
|
2018-08-03 15:01:43 +00:00
|
|
|
wallpaperController.update();
|
2017-07-20 19:49:54 +00:00
|
|
|
this.setCurrentBackgroundElement();
|
|
|
|
|
|
2017-07-20 11:48:13 +00:00
|
|
|
let historyController = wallpaperController.getHistoryController();
|
|
|
|
|
let history = historyController.history;
|
2014-10-19 09:01:05 +00:00
|
|
|
|
2014-10-23 14:34:19 +00:00
|
|
|
if (history.length <= 1) {
|
|
|
|
|
this.clearHistoryList();
|
|
|
|
|
return;
|
2017-07-20 11:48:13 +00:00
|
|
|
}
|
2014-10-21 21:13:21 +00:00
|
|
|
|
2016-04-08 10:17:45 +00:00
|
|
|
function onLeave(actor) {
|
2017-02-03 16:27:29 +00:00
|
|
|
wallpaperController.resetWallpaper();
|
2016-04-08 10:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onEnter(actor) {
|
|
|
|
|
wallpaperController.previewWallpaper(actor.historyId);
|
|
|
|
|
}
|
2018-07-27 15:36:47 +00:00
|
|
|
|
2016-04-08 10:17:45 +00:00
|
|
|
function onSelect(actor) {
|
2017-07-20 23:10:26 +00:00
|
|
|
wallpaperController.setWallpaper(actor.historyEntry.id);
|
2016-04-08 10:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-03 15:28:31 +00:00
|
|
|
this.historySection.updateList(history, onEnter, onLeave, onSelect);
|
2018-07-29 22:29:02 +00:00
|
|
|
},
|
|
|
|
|
|
2018-07-27 15:36:47 +00:00
|
|
|
clearHistoryList: function () {
|
2018-08-03 15:28:31 +00:00
|
|
|
this.historySection.clear();
|
2014-10-21 21:13:21 +00:00
|
|
|
},
|
2014-10-19 09:01:05 +00:00
|
|
|
|
2014-09-01 13:28:46 +00:00
|
|
|
});
|