2799327c84
Use GSettings for all Shell configuration. GConf is kept to read configuration from external programs (Metacity, Nautilus and Magnifier), but ShellGConf is removed because it's mostly useless for the few calls we still have. Also get rid of unused GConf code in ShellAppSystem. A basic GConf schema is still used to override Metacity defaults and configure Magnifier in a system-wide fashion. GConf is also used as GSettings backend via the GSETTINGS_BACKEND environment variable. All of this will be removed when these programs have been ported to GSettings and able to use dconf. GLib 2.25.9 is required. Schemas are converted to the new XML format, and compiled at build time in data/ so that the Shell can be run from the source tree. This also requires setting the GSETTINGS_SCHEMA_DIR environment variable both when running installed or from source tree, in src/gnome-shell.in and src/gnome-shell-clock-preferences.in. https://bugzilla.gnome.org/show_bug.cgi?id=617917
120 lines
3.2 KiB
JavaScript
120 lines
3.2 KiB
JavaScript
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
const Shell = imports.gi.Shell;
|
|
const Lang = imports.lang;
|
|
const Signals = imports.signals;
|
|
const Gettext = imports.gettext.domain('gnome-shell');
|
|
const _ = Gettext.gettext;
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
function AppFavorites() {
|
|
this._init();
|
|
}
|
|
|
|
AppFavorites.prototype = {
|
|
FAVORITE_APPS_KEY: 'favorite-apps',
|
|
|
|
_init: function() {
|
|
this._favorites = {};
|
|
global.settings.connect('changed::' + this.FAVORITE_APPS_KEY, Lang.bind(this, this._onFavsChanged));
|
|
this._reload();
|
|
},
|
|
|
|
_onFavsChanged: function() {
|
|
this._reload();
|
|
this.emit('changed');
|
|
},
|
|
|
|
_reload: function() {
|
|
let ids = global.settings.get_strv(this.FAVORITE_APPS_KEY);
|
|
let appSys = Shell.AppSystem.get_default();
|
|
let apps = ids.map(function (id) {
|
|
return appSys.get_app(id);
|
|
}).filter(function (app) {
|
|
return app != null;
|
|
});
|
|
this._favorites = {};
|
|
for (let i = 0; i < apps.length; i++) {
|
|
let app = apps[i];
|
|
this._favorites[app.get_id()] = app;
|
|
}
|
|
},
|
|
|
|
_getIds: function() {
|
|
let ret = [];
|
|
for (let id in this._favorites)
|
|
ret.push(id);
|
|
return ret;
|
|
},
|
|
|
|
getFavoriteMap: function() {
|
|
return this._favorites;
|
|
},
|
|
|
|
getFavorites: function() {
|
|
let ret = [];
|
|
for (let id in this._favorites)
|
|
ret.push(this._favorites[id]);
|
|
return ret;
|
|
},
|
|
|
|
isFavorite: function(appId) {
|
|
return appId in this._favorites;
|
|
},
|
|
|
|
_addFavorite: function(appId) {
|
|
if (appId in this._favorites)
|
|
return false;
|
|
|
|
let app = Shell.AppSystem.get_default().get_app(appId);
|
|
|
|
if (!app)
|
|
return false;
|
|
|
|
let ids = this._getIds();
|
|
ids.push(appId);
|
|
global.settings.set_strv(this.FAVORITE_APPS_KEY, ids);
|
|
this._favorites[appId] = app;
|
|
return true;
|
|
},
|
|
|
|
addFavorite: function(appId) {
|
|
if (!this._addFavorite(appId))
|
|
return;
|
|
|
|
let app = Shell.AppSystem.get_default().get_app(appId);
|
|
|
|
Main.overview.infoBar.setMessage(_("%s has been added to your favorites.").format(app.get_name()), Lang.bind(this, function () {
|
|
this._removeFavorite(appId);
|
|
}));
|
|
},
|
|
|
|
_removeFavorite: function(appId) {
|
|
if (!appId in this._favorites)
|
|
return false;
|
|
|
|
let ids = this._getIds().filter(function (id) { return id != appId; });
|
|
global.settings.set_strv(this.FAVORITE_APPS_KEY, ids);
|
|
return true;
|
|
},
|
|
|
|
removeFavorite: function(appId) {
|
|
if (!this._removeFavorite(appId))
|
|
return;
|
|
|
|
Main.overview.infoBar.setMessage(_("%s has been removed from your favorites.").format(this._favorites[appId].get_name()),
|
|
Lang.bind(this, function () {
|
|
this._addFavorite(appId);
|
|
}));
|
|
}
|
|
};
|
|
Signals.addSignalMethods(AppFavorites.prototype);
|
|
|
|
var appFavoritesInstance = null;
|
|
function getAppFavorites() {
|
|
if (appFavoritesInstance == null)
|
|
appFavoritesInstance = new AppFavorites();
|
|
return appFavoritesInstance;
|
|
}
|