2008-12-01 19:51:43 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2008-11-21 00:53:11 +00:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
|
|
|
const Shell = imports.gi.Shell;
|
2009-02-02 23:02:16 +00:00
|
|
|
const Signals = imports.signals;
|
2008-11-21 00:53:11 +00:00
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
const GenericDisplay = imports.ui.genericDisplay;
|
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
// TODO - move this into GConf once we're not a plugin anymore
|
|
|
|
// but have taken over metacity
|
|
|
|
// This list is taken from GNOME Online popular applications
|
|
|
|
// http://online.gnome.org/applications
|
2009-01-13 20:07:57 +00:00
|
|
|
// but with nautilus removed (since it should already be running)
|
|
|
|
// and evince, totem, and gnome-file-roller removed (since they're
|
|
|
|
// usually started by opening documents, not by opening the app
|
|
|
|
// directly)
|
2008-11-25 19:58:49 +00:00
|
|
|
const DEFAULT_APPLICATIONS = [
|
2008-12-01 19:51:43 +00:00
|
|
|
'mozilla-firefox.desktop',
|
|
|
|
'gnome-terminal.desktop',
|
|
|
|
'evolution.desktop',
|
|
|
|
'gedit.desktop',
|
|
|
|
'mozilla-thunderbird.desktop',
|
|
|
|
'rhythmbox.desktop',
|
|
|
|
'epiphany.desktop',
|
|
|
|
'xchat.desktop',
|
|
|
|
'openoffice.org-1.9-writer.desktop',
|
|
|
|
'emacs.desktop',
|
|
|
|
'gnome-system-monitor.desktop',
|
|
|
|
'openoffice.org-1.9-calc.desktop',
|
|
|
|
'eclipse.desktop',
|
|
|
|
'openoffice.org-1.9-impress.desktop',
|
|
|
|
'vncviewer.desktop'
|
|
|
|
];
|
2008-11-25 19:58:49 +00:00
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
/* This class represents a single display item containing information about an application.
|
|
|
|
*
|
|
|
|
* appInfo - GAppInfo object containing information about the application
|
|
|
|
* availableWidth - total width available for the item
|
|
|
|
*/
|
|
|
|
function AppDisplayItem(appInfo, availableWidth) {
|
|
|
|
this._init(appInfo, availableWidth);
|
2008-11-21 00:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AppDisplayItem.prototype = {
|
2008-12-20 04:27:57 +00:00
|
|
|
__proto__: GenericDisplay.GenericDisplayItem.prototype,
|
|
|
|
|
|
|
|
_init : function(appInfo, availableWidth) {
|
|
|
|
GenericDisplay.GenericDisplayItem.prototype._init.call(this, availableWidth);
|
2008-12-09 22:10:43 +00:00
|
|
|
this._appInfo = appInfo;
|
2008-12-01 19:51:43 +00:00
|
|
|
|
2008-12-09 22:10:43 +00:00
|
|
|
let name = appInfo.get_name();
|
2008-12-01 19:51:43 +00:00
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
let description = appInfo.get_description();
|
2008-12-01 19:51:43 +00:00
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
let iconTheme = Gtk.IconTheme.get_default();
|
2008-12-01 19:51:43 +00:00
|
|
|
|
2009-01-09 01:09:35 +00:00
|
|
|
let icon = new Clutter.Texture({ width: GenericDisplay.ITEM_DISPLAY_ICON_SIZE, height: GenericDisplay.ITEM_DISPLAY_ICON_SIZE});
|
2008-12-09 22:10:43 +00:00
|
|
|
let gicon = appInfo.get_icon();
|
2008-12-01 19:51:43 +00:00
|
|
|
let path = null;
|
|
|
|
if (gicon != null) {
|
2009-01-09 01:09:35 +00:00
|
|
|
let iconinfo = iconTheme.lookup_by_gicon(gicon, GenericDisplay.ITEM_DISPLAY_ICON_SIZE, Gtk.IconLookupFlags.NO_SVG);
|
2008-12-01 19:51:43 +00:00
|
|
|
if (iconinfo)
|
|
|
|
path = iconinfo.get_filename();
|
|
|
|
}
|
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
if (path) {
|
|
|
|
try {
|
|
|
|
icon.set_from_file(path);
|
2009-01-09 01:09:35 +00:00
|
|
|
icon.x = GenericDisplay.ITEM_DISPLAY_PADDING;
|
|
|
|
icon.y = GenericDisplay.ITEM_DISPLAY_PADDING;
|
2008-12-20 04:27:57 +00:00
|
|
|
} catch (e) {
|
|
|
|
// we can get an error here if the file path doesn't exist on the system
|
|
|
|
log('Error loading AppDisplayItem icon ' + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._setItemInfo(name, description, icon);
|
2008-12-01 19:51:43 +00:00
|
|
|
},
|
2008-12-20 04:27:57 +00:00
|
|
|
|
|
|
|
//// Public methods ////
|
|
|
|
|
|
|
|
// Returns the application info associated with this display item.
|
|
|
|
getAppInfo : function () {
|
2008-12-09 22:10:43 +00:00
|
|
|
return this._appInfo;
|
2008-12-01 19:51:43 +00:00
|
|
|
},
|
2008-12-20 04:27:57 +00:00
|
|
|
|
|
|
|
//// Public method overrides ////
|
|
|
|
|
|
|
|
// Opens an application represented by this display item.
|
|
|
|
launch : function() {
|
|
|
|
this._appInfo.launch([], null);
|
2008-12-01 19:51:43 +00:00
|
|
|
}
|
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
};
|
2008-11-21 00:53:11 +00:00
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
/* This class represents a display containing a collection of application items.
|
|
|
|
* The applications are sorted based on their popularity by default, and based on
|
|
|
|
* their name if some search filter is applied.
|
|
|
|
*
|
|
|
|
* width - width available for the display
|
|
|
|
* height - height available for the display
|
|
|
|
*/
|
2008-12-01 22:43:06 +00:00
|
|
|
function AppDisplay(width, height) {
|
|
|
|
this._init(width, height);
|
2008-11-21 00:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AppDisplay.prototype = {
|
2008-12-20 04:27:57 +00:00
|
|
|
__proto__: GenericDisplay.GenericDisplay.prototype,
|
|
|
|
|
2008-12-01 22:43:06 +00:00
|
|
|
_init : function(width, height) {
|
2009-01-21 21:50:57 +00:00
|
|
|
GenericDisplay.GenericDisplay.prototype._init.call(this, width, height);
|
|
|
|
|
|
|
|
// map<itemId, array of category names>
|
|
|
|
this._categories = {};
|
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
let me = this;
|
2008-12-09 22:10:43 +00:00
|
|
|
this._appMonitor = new Shell.AppMonitor();
|
2008-12-01 19:51:43 +00:00
|
|
|
this._appsStale = true;
|
2008-12-09 22:10:43 +00:00
|
|
|
this._appMonitor.connect('changed', function(mon) {
|
2008-12-01 19:51:43 +00:00
|
|
|
me._appsStale = true;
|
2008-12-20 04:27:57 +00:00
|
|
|
// We still need to determine what events other than search can trigger
|
|
|
|
// a change in the set of applications that are being shown while the
|
|
|
|
// user in in the overlay mode, however let's redisplay just in case.
|
|
|
|
me._redisplay();
|
2008-12-01 19:51:43 +00:00
|
|
|
});
|
2009-01-13 20:45:54 +00:00
|
|
|
|
|
|
|
// Load the GAppInfos now so it doesn't slow down the first
|
|
|
|
// transition into the overlay
|
|
|
|
this._refreshCache();
|
2008-12-01 19:51:43 +00:00
|
|
|
},
|
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
//// Protected method overrides ////
|
2008-12-01 19:51:43 +00:00
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
// Gets information about all applications by calling Gio.app_info_get_all().
|
|
|
|
_refreshCache : function() {
|
|
|
|
let me = this;
|
2008-12-01 19:51:43 +00:00
|
|
|
if (!this._appsStale)
|
|
|
|
return;
|
2008-12-20 04:27:57 +00:00
|
|
|
this._allItems = {};
|
2009-01-21 21:50:57 +00:00
|
|
|
this._categories = {};
|
2008-12-01 19:51:43 +00:00
|
|
|
let apps = Gio.app_info_get_all();
|
|
|
|
for (let i = 0; i < apps.length; i++) {
|
2008-12-09 22:10:43 +00:00
|
|
|
let appInfo = apps[i];
|
2009-01-22 21:28:19 +00:00
|
|
|
|
|
|
|
if (!appInfo.should_show())
|
|
|
|
continue;
|
|
|
|
|
2008-12-09 22:10:43 +00:00
|
|
|
let appId = appInfo.get_id();
|
2008-12-20 04:27:57 +00:00
|
|
|
this._allItems[appId] = appInfo;
|
2009-01-21 21:50:57 +00:00
|
|
|
// [] is returned if we could not get the categories or the list of categories was empty
|
|
|
|
let categories = Shell.get_categories_for_desktop_file(appId);
|
|
|
|
this._categories[appId] = categories;
|
2008-12-01 19:51:43 +00:00
|
|
|
}
|
|
|
|
this._appsStale = false;
|
|
|
|
},
|
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
// Sets the list of the displayed items based on the list of DEFAULT_APPLICATIONS.
|
|
|
|
_setDefaultList : function() {
|
|
|
|
this._removeAllDisplayItems();
|
2008-12-01 19:51:43 +00:00
|
|
|
let added = 0;
|
2008-12-09 22:10:43 +00:00
|
|
|
for (let i = 0; i < DEFAULT_APPLICATIONS.length && added < this._maxItems; i++) {
|
|
|
|
let appId = DEFAULT_APPLICATIONS[i];
|
2008-12-20 04:27:57 +00:00
|
|
|
let appInfo = this._allItems[appId];
|
2008-12-09 22:10:43 +00:00
|
|
|
if (appInfo) {
|
2008-12-20 04:27:57 +00:00
|
|
|
this._addDisplayItem(appId);
|
|
|
|
added += 1;
|
2008-12-01 19:51:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
// Sorts the list of item ids in-place based on the alphabetical order of the names of
|
|
|
|
// the items associated with the ids.
|
|
|
|
_sortItems : function(itemIds) {
|
2008-12-01 19:51:43 +00:00
|
|
|
let me = this;
|
2008-12-20 04:27:57 +00:00
|
|
|
itemIds.sort(function (a,b) {
|
|
|
|
let appA = me._allItems[a];
|
|
|
|
let appB = me._allItems[b];
|
|
|
|
return appA.get_name().localeCompare(appB.get_name());
|
2008-12-01 19:51:43 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
// Checks if the item info can be a match for the search string by checking
|
2009-01-21 21:50:57 +00:00
|
|
|
// the name, description, execution command, and categories for the application.
|
2008-12-20 04:27:57 +00:00
|
|
|
// Item info is expected to be GAppInfo.
|
|
|
|
// Returns a boolean flag indicating if itemInfo is a match.
|
|
|
|
_isInfoMatching : function(itemInfo, search) {
|
2008-12-01 19:51:43 +00:00
|
|
|
if (search == null || search == '')
|
|
|
|
return true;
|
2009-01-21 21:50:57 +00:00
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
let name = itemInfo.get_name().toLowerCase();
|
2008-12-01 19:51:43 +00:00
|
|
|
if (name.indexOf(search) >= 0)
|
|
|
|
return true;
|
2009-01-21 21:50:57 +00:00
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
let description = itemInfo.get_description();
|
2008-12-01 19:51:43 +00:00
|
|
|
if (description) {
|
|
|
|
description = description.toLowerCase();
|
|
|
|
if (description.indexOf(search) >= 0)
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-21 21:50:57 +00:00
|
|
|
|
2009-01-22 21:28:19 +00:00
|
|
|
if (itemInfo.get_executable() == null) {
|
|
|
|
log("Missing an executable for " + itemInfo.get_name());
|
|
|
|
} else {
|
|
|
|
let exec = itemInfo.get_executable().toLowerCase();
|
|
|
|
if (exec.indexOf(search) >= 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-01-21 21:50:57 +00:00
|
|
|
// we expect this._categories.hasOwnProperty(itemInfo.get_id()) to always be true here
|
|
|
|
let categories = this._categories[itemInfo.get_id()];
|
|
|
|
for (let i = 0; i < categories.length; i++) {
|
|
|
|
let category = categories[i].toLowerCase();
|
|
|
|
if (category.indexOf(search) >= 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2008-12-20 04:27:57 +00:00
|
|
|
// Creates an AppDisplayItem based on itemInfo, which is expected be a GAppInfo object.
|
|
|
|
_createDisplayItem: function(itemInfo) {
|
2009-02-03 22:58:33 +00:00
|
|
|
return new AppDisplayItem(itemInfo, this._columnWidth);
|
2008-12-20 04:27:57 +00:00
|
|
|
}
|
2008-12-01 19:51:43 +00:00
|
|
|
};
|
2008-11-21 00:53:11 +00:00
|
|
|
|
2008-12-01 19:51:43 +00:00
|
|
|
Signals.addSignalMethods(AppDisplay.prototype);
|