Add some very minimal telepathy support

Original code from Will Thompson

https://bugzilla.gnome.org/show_bug.cgi?id=599193
This commit is contained in:
Dan Winship 2009-10-27 11:49:21 -04:00
parent 01138d55ca
commit c985c3cf78
2 changed files with 171 additions and 0 deletions

View File

@ -14,6 +14,7 @@ const St = imports.gi.St;
const Chrome = imports.ui.chrome;
const Environment = imports.ui.environment;
const Messaging = imports.ui.messaging;
const Overview = imports.ui.overview;
const Panel = imports.ui.panel;
const RunDialog = imports.ui.runDialog;
@ -32,6 +33,7 @@ let overview = null;
let runDialog = null;
let lookingGlass = null;
let wm = null;
let messaging = null;
let recorder = null;
let shellDBusService = null;
let modalCount = 0;
@ -101,6 +103,7 @@ function start() {
panel = new Panel.Panel();
sidebar = new Sidebar.Sidebar();
wm = new WindowManager.WindowManager();
messaging = new Messaging.Messaging();
global.screen.connect('toggle-recording', function() {
if (recorder == null) {

168
js/ui/messaging.js Normal file
View File

@ -0,0 +1,168 @@
const DBus = imports.dbus;
const Shell = imports.gi.Shell;
const TELEPATHY = "org.freedesktop.Telepathy.";
const CONN = TELEPATHY + "Connection";
const CHANNEL = TELEPATHY + "Channel";
const CHANNELTEXT = CHANNEL + ".Type.Text";
const ClientIface = {
name: TELEPATHY + "Client",
properties: [{ name: "Interfaces",
signature: "as",
access: "read" }]
};
const ClientObserverIface = {
name: TELEPATHY + "Client.Observer",
methods: [{ name: "ObserveChannels",
inSignature: "ooa(oa{sv})oaoa{sv}",
outSignature: "" }],
properties: [{ name: "ObserverChannelFilter",
signature: "aa{sv}",
access: "read" }]
};
const ConnectionIface = {
name: CONN
};
const ConnectionAvatarsIface = {
name: CONN + '.Interface.Avatars',
methods: [
{ name: 'RequestAvatar',
inSignature: 'u',
outSignature: 'ays'
}
]
};
function Connection(path) {
this._init(path);
};
Connection.prototype = {
_init: function(path) {
DBus.session.proxifyObject(this, nameify(path), path);
}
};
DBus.proxifyPrototype(Connection.prototype, ConnectionIface);
DBus.proxifyPrototype(Connection.prototype, ConnectionAvatarsIface);
const ChannelIface = {
name: CHANNEL,
signals: [
{ name: 'Closed', inSignature: '' }
]
};
function Channel(name, path) {
this._init(name, path);
};
Channel.prototype = {
_init: function(name, path) {
DBus.session.proxifyObject(this, name, path);
}
};
DBus.proxifyPrototype(Channel.prototype, ChannelIface);
const ChannelTextIface = {
name: CHANNELTEXT,
signals: [
{ name: 'Received', inSignature: 'uuuuus' }
]
};
function ChannelText(name, path) {
this._init(name, path);
};
ChannelText.prototype = {
_init: function(name, path) {
DBus.session.proxifyObject(this, name, path);
}
};
DBus.proxifyPrototype(ChannelText.prototype, ChannelTextIface);
let nameify = function(path) {
return path.substr(1).replace('/', '.', 'g');
};
let pathify = function(name) {
return '/' + name.replace('.', '/', 'g');
};
function Messaging() {
this._init();
};
Messaging.prototype = {
_init : function() {
let name = TELEPATHY + "Client.GnomeShell";
DBus.session.exportObject(pathify(name), this);
DBus.session.acquire_name(name, DBus.SINGLE_INSTANCE,
function(name){log("Acquired name " + name);},
function(name){log("Lost name " + name);});
},
get Interfaces() {
return [TELEPATHY + "Client.Observer"];
},
get ObserverChannelFilter() {
return [
{ 'org.freedesktop.Telepathy.Channel.ChannelType': CHANNELTEXT }
];
},
ObserveChannels: function(account, conn_path, channels,
dispatch_operation, requests_satisfied,
observer_info) {
log('observing ' + conn_path);
let conn = new Connection(conn_path);
let conn_name = conn_path.substr(1).replace('/','.','g');
for (var i = 0; i < channels.length; i++) {
let path = channels[i][0];
let props = channels[i][1];
let targethandle = props[CHANNEL + '.TargetHandle'];
let targetid = props[CHANNEL + '.TargetID'];
// conn.RequestAvatarRemote(targethandle,
// function(result, excp) {
// log("called for " + targetid);
// let avatar;
// if (result) {
// let bytes = result[0];
// avatar = Shell.TextureCache.get_default().load_from_data(bytes, bytes.length, -1, TRAY_HEIGHT);
// } else {
// // fallback avatar
// avatar = Shell.TextureCache.get_default().load_icon_name("stock_person", TRAY_HEIGHT);
// }
// });
let channel = new Channel(conn_name, path);
let id = channel.connect('Closed',
function(emitter) {
log('closed');
channel.disconnect(id);
});
let text = new ChannelText(conn_name, path);
text.connect('Received',
function(chan, id, timestamp, sender, type, flags, text) {
log('Received: id ' + id + ', time ' + timestamp + ', sender ' + sender + ', type ' + type + ', flags ' + flags + ': ' + text);
});
}
return [true];
}
};
DBus.conformExport(Messaging.prototype, ClientIface);
DBus.conformExport(Messaging.prototype, ClientObserverIface);