2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2011-08-26 14:15:38 +00:00
|
|
|
|
|
|
|
const Folks = imports.gi.Folks
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Meta = imports.gi.Meta;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
2012-03-14 12:45:57 +00:00
|
|
|
const Atk = imports.gi.Atk;
|
2011-08-26 14:15:38 +00:00
|
|
|
|
|
|
|
const Util = imports.misc.util;
|
|
|
|
const IconGrid = imports.ui.iconGrid;
|
|
|
|
const Search = imports.ui.search;
|
|
|
|
const SearchDisplay = imports.ui.searchDisplay;
|
|
|
|
|
|
|
|
const MAX_SEARCH_RESULTS_ROWS = 1;
|
|
|
|
const ICON_SIZE = 81;
|
|
|
|
|
|
|
|
function launchContact(id) {
|
|
|
|
Util.spawn(['gnome-contacts', '-i', id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This class represents a shown contact search result in the overview */
|
2011-11-20 17:56:27 +00:00
|
|
|
const Contact = new Lang.Class({
|
|
|
|
Name: 'Contact',
|
2011-08-26 14:15:38 +00:00
|
|
|
|
|
|
|
_init: function(id) {
|
2011-09-30 22:33:36 +00:00
|
|
|
this._contactSys = Shell.ContactSystem.get_default();
|
|
|
|
this.individual = this._contactSys.get_individual(id);
|
2011-08-26 14:15:38 +00:00
|
|
|
|
|
|
|
this.actor = new St.Bin({ style_class: 'contact',
|
|
|
|
reactive: true,
|
2011-11-12 04:40:56 +00:00
|
|
|
can_focus: true,
|
2012-03-14 12:45:57 +00:00
|
|
|
track_hover: true,
|
|
|
|
accessible_role: Atk.Role.PUSH_BUTTON });
|
2011-08-26 14:15:38 +00:00
|
|
|
|
|
|
|
let content = new St.BoxLayout( { style_class: 'contact-content',
|
|
|
|
vertical: false });
|
|
|
|
this.actor.set_child(content);
|
|
|
|
|
|
|
|
let icon = new St.Icon({ icon_type: St.IconType.FULLCOLOR,
|
|
|
|
icon_size: ICON_SIZE,
|
|
|
|
style_class: 'contact-icon' });
|
|
|
|
if (this.individual.avatar != null)
|
|
|
|
icon.gicon = this.individual.avatar;
|
|
|
|
else
|
|
|
|
icon.icon_name = 'avatar-default';
|
|
|
|
|
|
|
|
content.add(icon, { x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.MIDDLE });
|
|
|
|
|
|
|
|
let details = new St.BoxLayout({ style_class: 'contact-details',
|
|
|
|
vertical: true });
|
|
|
|
content.add(details, { x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.MIDDLE });
|
|
|
|
|
2011-09-30 22:33:36 +00:00
|
|
|
let email = this._contactSys.get_email_for_display(this.individual);
|
|
|
|
let aliasText = this.individual.alias ||
|
|
|
|
this.individual.full_name ||
|
|
|
|
this.individual.nickname ||
|
|
|
|
email ||
|
|
|
|
_("Unknown");
|
2011-08-26 14:15:38 +00:00
|
|
|
let aliasLabel = new St.Label({ text: aliasText,
|
|
|
|
style_class: 'contact-details-alias' });
|
|
|
|
details.add(aliasLabel, { x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
|
2012-03-14 12:45:57 +00:00
|
|
|
this.actor.label_actor = aliasLabel;
|
|
|
|
|
2011-08-26 14:15:38 +00:00
|
|
|
let presence = this._createPresence(this.individual.presence_type);
|
|
|
|
details.add(presence, { x_fill: false,
|
|
|
|
y_fill: true,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.END });
|
|
|
|
},
|
|
|
|
|
|
|
|
_createPresence: function(presence) {
|
|
|
|
let text;
|
|
|
|
let iconName;
|
|
|
|
|
|
|
|
switch(presence) {
|
|
|
|
case Folks.PresenceType.AVAILABLE:
|
|
|
|
text = _("Available");
|
|
|
|
iconName = 'user-available';
|
|
|
|
break;
|
|
|
|
case Folks.PresenceType.AWAY:
|
|
|
|
case Folks.PresenceType.EXTENDED_AWAY:
|
|
|
|
text = _("Away");
|
|
|
|
iconName = 'user-away';
|
|
|
|
break;
|
|
|
|
case Folks.PresenceType.BUSY:
|
|
|
|
text = _("Busy");
|
|
|
|
iconName = 'user-busy';
|
|
|
|
break;
|
2011-10-25 16:06:14 +00:00
|
|
|
case Folks.PresenceType.OFFLINE:
|
2011-08-26 14:15:38 +00:00
|
|
|
text = _("Offline");
|
|
|
|
iconName = 'user-offline';
|
2011-10-25 16:06:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
text = '';
|
|
|
|
iconName = null;
|
2011-08-26 14:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let box = new St.BoxLayout({ vertical: false,
|
|
|
|
style_class: 'contact-details-status' });
|
2011-10-25 16:06:14 +00:00
|
|
|
|
|
|
|
if (iconName) {
|
|
|
|
let icon = new St.Icon({ icon_name: iconName,
|
|
|
|
icon_type: St.IconType.FULLCOLOR,
|
|
|
|
icon_size: 16,
|
|
|
|
style_class: 'contact-details-status-icon' });
|
|
|
|
box.add(icon, { x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.START,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
}
|
|
|
|
|
|
|
|
let label = new St.Label({ text: text });
|
2011-08-26 14:15:38 +00:00
|
|
|
|
|
|
|
box.add(label, { x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.END,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
|
|
|
|
return box;
|
|
|
|
},
|
|
|
|
|
|
|
|
createIcon: function(size) {
|
|
|
|
let tc = St.TextureCache.get_default();
|
|
|
|
let icon = this.individual.avatar;
|
|
|
|
|
|
|
|
if (icon != null) {
|
|
|
|
return tc.load_gicon(null, icon, size);
|
|
|
|
} else {
|
|
|
|
return tc.load_icon_name(null, 'avatar-default', St.IconType.FULLCOLOR, size);
|
|
|
|
}
|
|
|
|
},
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|
2011-08-26 14:15:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Searches for and returns contacts */
|
2011-11-20 16:07:14 +00:00
|
|
|
const ContactSearchProvider = new Lang.Class({
|
|
|
|
Name: 'ContactSearchProvider',
|
|
|
|
Extends: Search.SearchProvider,
|
2011-08-26 14:15:38 +00:00
|
|
|
|
|
|
|
_init: function() {
|
2011-11-20 16:07:14 +00:00
|
|
|
this.parent(_("CONTACTS"));
|
2012-05-02 19:45:37 +00:00
|
|
|
this.async = true;
|
2011-08-26 14:15:38 +00:00
|
|
|
this._contactSys = Shell.ContactSystem.get_default();
|
|
|
|
},
|
|
|
|
|
2012-05-02 19:45:37 +00:00
|
|
|
getResultMetasAsync: function(ids, callback) {
|
2012-02-17 15:39:27 +00:00
|
|
|
let metas = [];
|
|
|
|
for (let i = 0; i < ids.length; i++) {
|
|
|
|
let contact = new Contact(ids[i]);
|
|
|
|
metas.push({ 'id': ids[i],
|
|
|
|
'name': contact.alias,
|
|
|
|
'createIcon': function(size) {
|
|
|
|
return contact.createIcon(size);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-05-02 19:45:37 +00:00
|
|
|
callback(metas);
|
2011-08-26 14:15:38 +00:00
|
|
|
},
|
|
|
|
|
2012-05-02 19:45:37 +00:00
|
|
|
getInitialResultSetAsync: function(terms) {
|
|
|
|
this.searchSystem.pushResults(this, this._contactSys.initial_search(terms));
|
2011-08-26 14:15:38 +00:00
|
|
|
},
|
|
|
|
|
2012-05-02 19:45:37 +00:00
|
|
|
getSubsearchResultSetAsync: function(previousResults, terms) {
|
|
|
|
this.searchSystem.pushResults(this, this._contactSys.subsearch(previousResults, terms));
|
2011-08-26 14:15:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
createResultActor: function(resultMeta, terms) {
|
|
|
|
let contact = new Contact(resultMeta.id);
|
|
|
|
return contact.actor;
|
|
|
|
},
|
|
|
|
|
|
|
|
createResultContainerActor: function() {
|
|
|
|
let grid = new IconGrid.IconGrid({ rowLimit: MAX_SEARCH_RESULTS_ROWS,
|
|
|
|
xAlign: St.Align.START });
|
|
|
|
grid.actor.style_class = 'contact-grid';
|
|
|
|
|
|
|
|
let actor = new SearchDisplay.GridSearchResults(this, grid);
|
|
|
|
return actor;
|
|
|
|
},
|
|
|
|
|
|
|
|
activateResult: function(id, params) {
|
|
|
|
launchContact(id);
|
|
|
|
}
|
2011-11-20 16:07:14 +00:00
|
|
|
});
|