do-plugins team mailing list archive
-
do-plugins team
-
Mailing list archive
-
Message #01398
[Merge] lp:~xavier-calland/do-plugins/empathy into lp:do-plugins
xavier calland has proposed merging lp:~xavier-calland/do-plugins/empathy into lp:do-plugins.
Requested reviews:
Do Plugins Team (do-plugins)
I have written a plugin for Empathy.
It is based on D-Bus Telepathy spec, it use telepathy-sharp and it is inspired by the Pidgin plugin.
Plug-in allows to : enable/disable accounts, chat with contacts, set activity status.
--
https://code.launchpad.net/~xavier-calland/do-plugins/empathy/+merge/32706
Your team Do Plugins Team is requested to review the proposed merge of lp:~xavier-calland/do-plugins/empathy into lp:do-plugins.
=== modified file 'DoPlugins.mds'
--- DoPlugins.mds 2009-11-08 23:58:01 +0000
+++ DoPlugins.mds 2010-08-15 12:39:41 +0000
@@ -1,6 +1,7 @@
<Combine fileversion="2.0" outputpath="build/bin/" name="DoPlugins" releaseversion="0.4.9.9">
<Configurations active="Debug">
<Configuration name="Debug" ctype="CombineConfiguration">
+ <Entry build="True" name="Empathy" configuration="Debug" />
<Entry build="True" name="Rhythmbox" configuration="Debug" />
<Entry build="True" name="Epiphany" configuration="Debug" />
<Entry build="True" name="Evolution" configuration="Debug" />
@@ -80,6 +81,7 @@
<Entry build="True" name="GNOME-Calculator" configuration="Debug" />
</Configuration>
<Configuration name="Release" ctype="CombineConfiguration">
+ <Entry build="True" name="Empathy" configuration="Release" />
<Entry build="True" name="Rhythmbox" configuration="Release" />
<Entry build="True" name="Epiphany" configuration="Release" />
<Entry build="True" name="Evolution" configuration="Release" />
@@ -160,6 +162,7 @@
</Configuration>
</Configurations>
<StartMode startupentry="Rhythmbox" single="True">
+ <Execute type="None" entry="Empathy" />
<Execute type="None" entry="Rhythmbox" />
<Execute type="None" entry="Epiphany" />
<Execute type="None" entry="Evolution" />
@@ -240,6 +243,7 @@
</StartMode>
<MonoDevelop.ChangeLogAddIn.ChangeLogInfo policy="UpdateNearestChangeLog" />
<Entries>
+ <Entry filename="Empathy/Empathy.mdp" />
<Entry filename="Rhythmbox/Rhythmbox.mdp" />
<Entry filename="Epiphany/Epiphany.mdp" />
<Entry filename="Evolution/Evolution.mdp" />
=== added directory 'Empathy'
=== added file 'Empathy/Empathy.mdp'
--- Empathy/Empathy.mdp 1970-01-01 00:00:00 +0000
+++ Empathy/Empathy.mdp 2010-08-15 12:39:41 +0000
@@ -0,0 +1,53 @@
+<Project name="Empathy" fileversion="2.0" DefaultNamespace="EmpathyPlugin" language="C#" targetFramework="3.5" ctype="DotNetProject">
+ <Policies>
+ <StandardHeader inheritsSet="LGPLv3License" />
+ </Policies>
+ <Deployment.LinuxDeployData scriptName="empathy" />
+ <Configurations active="Debug">
+ <Configuration name="Debug" ctype="DotNetProjectConfiguration">
+ <Output directory="bin/Debug" assembly="Empathy" />
+ <Build debugmode="True" target="Library" />
+ <Execution consolepause="False" runwithwarnings="True" runtime="MsNet" />
+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+ </Configuration>
+ <Configuration name="Release" ctype="DotNetProjectConfiguration">
+ <Output directory="bin/Release" assembly="Empathy" />
+ <Build debugmode="False" target="Library" />
+ <Execution consolepause="False" runwithwarnings="True" runtime="MsNet" />
+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+ </Configuration>
+ </Configurations>
+ <Contents>
+ <File subtype="Code" buildaction="Compile" name="src/AccountManagerQuery.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathyPlugin.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathyChatAction.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathyAccountItem.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathyAccountItemSource.cs" />
+ <File subtype="Directory" buildaction="Compile" name="Resources" />
+ <File subtype="Code" buildaction="EmbedAsResource" name="Resources/Empathy.addin.xml" />
+ <File subtype="Code" buildaction="Compile" name="src/Account.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathyBrowseAccountItem.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathyContactItemSource.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathyBrowseBuddyItem.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/Contact.cs" />
+ <File subtype="Code" buildaction="Nothing" name="telepathy-sharp.dll" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathySetStatusAction.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathyStatusItem.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathySavedStatusItemSource.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathyBrowseStatusItem.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/Status.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathySavedStatusItem.cs" />
+ <File subtype="Code" buildaction="Compile" name="src/EmpathyAccountActions.cs" />
+ </Contents>
+ <References>
+ <ProjectReference type="Gac" localcopy="True" refto="Do.Platform, Version=0.9.0.0, Culture=neutral" />
+ <ProjectReference type="Gac" localcopy="True" refto="Do.Universe, Version=0.9.0.0, Culture=neutral" />
+ <ProjectReference type="Gac" localcopy="True" refto="NDesk.DBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099" />
+ <ProjectReference type="Gac" localcopy="True" refto="NDesk.DBus.GLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099" />
+ <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <ProjectReference type="Gac" localcopy="True" refto="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <ProjectReference type="Gac" localcopy="True" refto="Mono.Addins, Version=0.4.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
+ <ProjectReference specificVersion="False" type="Assembly" localcopy="True" refto="telepathy-sharp.dll" />
+ <ProjectReference type="Gac" localcopy="True" refto="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ </References>
+</Project>
\ No newline at end of file
=== added directory 'Empathy/Resources'
=== added file 'Empathy/Resources/Empathy.addin.xml'
--- Empathy/Resources/Empathy.addin.xml 1970-01-01 00:00:00 +0000
+++ Empathy/Resources/Empathy.addin.xml 2010-08-15 12:39:41 +0000
@@ -0,0 +1,37 @@
+<Addin
+ id="Empathy"
+ namespace="Do"
+ version="0.1"
+ name="Empathy"
+ description="Search contacts and initiate chats in Empathy."
+ author="Xavier Calland"
+ category="Community"
+ defaultEnabled="false"
+ url="http://do.davebsd.com/wiki/Empathy_Plugin"
+>
+
+ <Runtime>
+ <Import assembly="Empathy.dll"/>
+ <Import assembly="telepathy-sharp.dll"/>
+ </Runtime>
+
+ <Localizer type="Gettext" catalog="gnome-do-plugins" location="/usr/local/share/locale" />
+
+ <Dependencies>
+ <Addin id="Universe" version="1.0" />
+ </Dependencies>
+
+ <Extension path="/Do/ItemSource">
+ <ItemSource type="EmpathyPlugin.EmpathyContactItemSource" />
+ <ItemSource type="EmpathyPlugin.EmpathyAccountItemSource" />
+ <ItemSource type="EmpathyPlugin.EmpathySavedStatusItemSource" />
+ </Extension>
+
+ <Extension path= "/Do/Action">
+ <Action type="EmpathyPlugin.EmpathyChatAction" />
+ <Action type="EmpathyPlugin.EmpathySetStatusAction" />
+ <Action type="EmpathyPlugin.EmpathyEnableAccount" />
+ <Action type="EmpathyPlugin.EmpathyDisableAccount" />
+ </Extension>
+
+</Addin>
=== added directory 'Empathy/src'
=== added file 'Empathy/src/Account.cs'
--- Empathy/src/Account.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/Account.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,242 @@
+// Account.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using NDesk.DBus;
+using org.freedesktop.DBus;
+using System.Collections.Generic;
+using AccountManagerQuery;
+using Telepathy;
+
+namespace EmpathyPlugin
+{
+ public enum Criteria : uint
+ {
+ Channel = 0,
+ ChannelType = 1,
+ HandleType = 2,
+ Handle = 3
+ }
+
+ public class Account
+ {
+ public ObjectPath accountPath {get; private set;}
+ public IAccount iAccount {get; private set;}
+ public Properties iAccountProp {get; private set;}
+
+ public ObjectPath connectionPath {get; private set;}
+ public string connectionBusIFace {get; private set;}
+ public IConnection iConnection {get; private set;}
+
+ private List<ConnectionPresenceType> AvailablePresencesType = new List<ConnectionPresenceType>( new ConnectionPresenceType[] {
+ ConnectionPresenceType.Available,
+ ConnectionPresenceType.Away,
+ ConnectionPresenceType.Error,
+ ConnectionPresenceType.Busy,
+ ConnectionPresenceType.ExtendedAway,
+ ConnectionPresenceType.Hidden,
+ ConnectionPresenceType.Unknown,
+ ConnectionPresenceType.Offline
+ });
+
+ public string name;
+ public string proto;
+ public string cm;
+
+ public Account (ObjectPath accountPath)
+ {
+ this.accountPath = accountPath;
+
+ this.iAccount = Bus.Session.GetObject<IAccount> (EmpathyPlugin.ACCOUNTMANAGER_IFACE, accountPath);
+ this.iAccountProp = Bus.Session.GetObject<Properties> (EmpathyPlugin.ACCOUNTMANAGER_IFACE, accountPath);
+ ConnectionStatus connectionStatus = (ConnectionStatus)this.iAccountProp.Get (EmpathyPlugin.ACCOUNT_IFACE, "ConnectionStatus");
+
+ string[] tabStr = accountPath.ToString().Split("/".ToCharArray());
+ int length = tabStr.Length;
+ this.proto = tabStr[length - 2];
+ this.cm = tabStr[length - 3];
+
+ this.connectionPath = (ObjectPath)this.iAccountProp.Get (EmpathyPlugin.ACCOUNT_IFACE, "Connection");
+ this.connectionBusIFace = connectionPath.ToString ().Replace ("/", ".").Substring (1);
+ if (connectionStatus == ConnectionStatus.Connected) {
+ this.iConnection = Bus.Session.GetObject<IConnection> (connectionBusIFace, connectionPath);
+ } else {
+ this.iConnection = null;
+ }
+
+// this.iAccount.Nickname
+// this.name = (string)this.iAccountProp.Get (TelepathyPlugin.ACCOUNT_IFACE, "Nickname");
+// this.iAccount.DisplayName
+ this.name = (string)this.iAccountProp.Get (EmpathyPlugin.ACCOUNT_IFACE, "DisplayName");
+ }
+
+ public bool IsConnected ()
+ {
+ ConnectionStatus connectionStatus = (ConnectionStatus)this.iAccountProp.Get (EmpathyPlugin.ACCOUNT_IFACE, "ConnectionStatus");
+ return connectionStatus == ConnectionStatus.Connected;
+ }
+
+ public override string ToString ()
+ {
+ return this.name + " [" + this.proto + "] : " + IsConnected ();
+ }
+
+ public bool HasContact (string @name)
+ {
+ return this.FindContact(name) != null;
+ }
+
+ public Contact FindContact (string @name)
+ {
+ foreach (ChannelInfo channelInfo in this.iConnection.ListChannels ()) {
+
+ Properties contactGroupProperties = Bus.Session.GetObject<Properties> (this.connectionBusIFace, channelInfo.Channel);
+
+ if (channelInfo.ChannelType == EmpathyPlugin.CHANNEL_TYPE_CONTACTLIST &&
+ (channelInfo.HandleType == HandleType.List)) {
+ string[] strTab = channelInfo.Channel.ToString().Split("/".ToCharArray());
+ if(strTab[strTab.Length - 1] == "subscribe")
+ {
+ foreach (UInt32 i in (UInt32[])contactGroupProperties.Get (EmpathyPlugin.CHANNEL_GROUP_IFACE, "Members")) {
+ Contact contact = new Contact(i, this);
+ if (contact.ContactId == name) {
+
+ if(AvailablePresencesType.Contains(contact.SimplePresence.Type)) {
+ return new Contact(i, this);
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public void SetStatus (ConnectionPresenceType status, string message)
+ {
+ ISimplePresence simplePresence = Bus.Session.GetObject<ISimplePresence> (connectionBusIFace, connectionPath);
+// Properties simplePresenceProperties = Bus.Session.GetObject<Properties> (connectionBusIFace, connectionPath);
+// IDictionary<string, object> lstStatus = (IDictionary<string, object>) simplePresenceProperties.Get("org.freedesktop.Telepathy.Connection.Interface.SimplePresence", "Statuses");
+
+ List<BaseStatus> possibleStatusLst = EmpathyStatus.GetStatusList(status);
+
+ // TODO: utiliser SimplePresence au lieu de Presence
+ IPresence presence = Bus.Session.GetObject<IPresence> (connectionBusIFace, connectionPath);
+ IDictionary<string, StatusSpec> lstStatus = presence.GetStatuses();
+
+ foreach(BaseStatus oneStatus in possibleStatusLst)
+ {
+ StatusSpec statusSpec;
+ if(lstStatus.TryGetValue(oneStatus.ToString(), out statusSpec) )
+ {
+ if (statusSpec.MaySetOnSelf)
+ {
+ simplePresence.SetPresence(oneStatus.ToString(), message);
+ return;
+ }
+ }
+ }
+ }
+
+ public IEnumerable<Contact> FindContact ()
+ {
+ List<Contact> res = new List<Contact>();
+ if(! this.IsConnected()) {
+ return res;
+ }
+ foreach (ChannelInfo channelInfo in iConnection.ListChannels ()) {
+ Properties contactGroupProperties = Bus.Session.GetObject<Properties> (this.connectionBusIFace, channelInfo.Channel);
+
+ if (channelInfo.ChannelType == EmpathyPlugin.CHANNEL_TYPE_CONTACTLIST &&
+ (channelInfo.HandleType == HandleType.List)) {
+ string[] strTab = channelInfo.Channel.ToString().Split("/".ToCharArray());
+ if(strTab[strTab.Length - 1] == "subscribe")
+ {
+ foreach (UInt32 i in (UInt32[])contactGroupProperties.Get (EmpathyPlugin.CHANNEL_GROUP_IFACE, "Members")) {
+ Contact contact = new Contact(i, this);
+ res.Add(contact);
+ }
+ }
+ }
+ }
+ return res;
+ }
+
+ public void OpenConversationWithBuddy(string contactId, string message)
+ {
+ Contact contact = FindContact(contactId);
+
+ ObjectPath opath = new ObjectPath (EmpathyPlugin.CHANNELDISPATCHER_PATH);
+ IChannelDispatcher iChannelDispatcherBus = Bus.Session.GetObject<IChannelDispatcher> (EmpathyPlugin.CHANNELDISPATCHER_IFACE, opath);
+
+ Dictionary<string, object> channelRequestParameters = new Dictionary<string, object> ();
+ channelRequestParameters.Add (EmpathyPlugin.CHANNEL_TYPE, EmpathyPlugin.CHANNEL_TYPE_TEXT);
+ channelRequestParameters.Add (EmpathyPlugin.CHANNEL_TARGETHANDLETYPE, HandleType.Contact);
+ channelRequestParameters.Add (EmpathyPlugin.CHANNEL_TARGETHANDLE, contact.ContactUInt);
+
+ ObjectPath messageChannelPath = iChannelDispatcherBus.EnsureChannel (this.accountPath, channelRequestParameters, DateTime.Now.Ticks, "org.freedesktop.Telepathy.Client.Empathy");
+
+ IChannelRequest iChannelRequest = Bus.Session.GetObject<IChannelRequest> (EmpathyPlugin.ACCOUNTMANAGER_IFACE, messageChannelPath);
+ iChannelRequest.Proceed();
+
+ if(message == null)
+ {
+ return;
+ }
+
+ foreach (ChannelInfo channelInfo in this.iConnection.ListChannels ())
+ {
+ if (channelInfo.ChannelType == EmpathyPlugin.CHANNEL_TYPE_TEXT &&
+ channelInfo.HandleType == HandleType.Contact && channelInfo.Handle == contact.ContactUInt)
+ {
+
+ IMessages messageChannel = Bus.Session.GetObject<IMessages> (this.connectionBusIFace, channelInfo.Channel);
+
+ IDictionary<string, object> header = new Dictionary<string, object>() {
+ {"message-type", ChannelTextMessageType.Notice}
+ };
+ IDictionary<string, object> alternative = new Dictionary<string, object>() {
+ {"alternative", "main"},
+ {"content-type", "text/plain"},
+ {"content", message}
+ };
+ messageChannel.SendMessage(new IDictionary<string, object>[] { header, alternative}, MessageSendingFlags.None);
+ }
+ }
+ }
+
+ public void EnableAccount()
+ {
+ iAccountProp.Set("org.freedesktop.Telepathy.Account", "Enabled", true);
+ }
+
+ public void DisableAccount()
+ {
+ iAccountProp.Set("org.freedesktop.Telepathy.Account", "Enabled", false);
+ }
+
+
+ public string GetIconName()
+ {
+ return (string) iAccountProp.Get("org.freedesktop.Telepathy.Account", "Icon");
+ }
+ }
+}
+
=== added file 'Empathy/src/AccountManagerQuery.cs'
--- Empathy/src/AccountManagerQuery.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/AccountManagerQuery.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,34 @@
+// IAccountManagerQuery.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using System.Collections.Generic;
+using NDesk.DBus;
+
+namespace AccountManagerQuery
+{
+ [Interface ("com.nokia.AccountManager.Interface.Query")]
+ public interface IAccountManagerQuery
+ {
+ // Method
+ ObjectPath[] FindAccounts(IDictionary<string,object> @params);
+ }
+}
+
=== added file 'Empathy/src/Contact.cs'
--- Empathy/src/Contact.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/Contact.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,89 @@
+// Contact.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using NDesk.DBus;
+using org.freedesktop.DBus;
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+using AccountManagerQuery;
+using Telepathy;
+
+namespace EmpathyPlugin
+{
+ public class Contact
+ {
+
+ public UInt32 ContactUInt {get; private set;}
+ public Account Account {get; private set;}
+ public IDictionary<string, object> Attributes {get; private set;}
+ public SimplePresence SimplePresence ;
+ public string Alias {get {return (string)GetPropertyValue(EmpathyPlugin.CONTACT_PROP_ALIAS);} }
+ public string ContactId {get {return (string)GetPropertyValue(EmpathyPlugin.CONTACT_PROP_ID);} }
+ public string AvatarToken {get; private set;}
+
+ public Contact (UInt32 contactUInt, Account account)
+ {
+ ContactUInt = contactUInt;
+ Account = account;
+
+ IContacts contacts = Bus.Session.GetObject<IContacts> (Account.connectionBusIFace, Account.connectionPath);
+ ISimplePresence presence = Bus.Session.GetObject<ISimplePresence> (Account.connectionBusIFace, Account.connectionPath);
+ IAvatars avatars = Bus.Session.GetObject<IAvatars> (Account.connectionBusIFace, Account.connectionPath);
+ Properties connectionProperties = Bus.Session.GetObject<Properties> (Account.connectionBusIFace, Account.connectionPath);
+
+ // TODO: géré les protocols sans IAvatars
+ IDictionary<uint, string> tokens = avatars.GetKnownAvatarTokens(new uint[] { ContactUInt });
+ string strTmp = "";
+ if(tokens.TryGetValue(contactUInt, out strTmp) && strTmp.Length > 0)
+ {
+ // ajout du préfix "_3" si le premier token commence par un nombre
+ if(Regex.IsMatch(strTmp.Substring(0,1), "[0-9]"))
+ {
+ strTmp = "_3"+strTmp;
+ }
+ }
+ AvatarToken = strTmp;
+ SimplePresence sTmp;
+ presence.GetPresences (new uint[] { ContactUInt }).TryGetValue (ContactUInt, out sTmp);
+ SimplePresence = sTmp;
+
+ IDictionary<string, object> tmp;
+
+ string[] itf = (string[])connectionProperties.Get (EmpathyPlugin.CONNECTION_CONTACT_IFACE, "ContactAttributeInterfaces");
+ // FIXME: cette interface fait planter DBus avec MSN, on remet un interface bidon
+ int idx = Array.IndexOf(itf, EmpathyPlugin.CONNECTION_CAPABILITIES_IFACE);
+ itf[idx] = EmpathyPlugin.CONNECTION_IFACE;
+
+ IDictionary<uint, IDictionary<string, object>> allAttributes =
+ contacts.GetContactAttributes (new uint[] { ContactUInt }, itf, false);
+ allAttributes.TryGetValue (ContactUInt, out tmp);
+ Attributes = tmp;
+ }
+
+ private object GetPropertyValue(string propName)
+ {
+ object res;
+ Attributes.TryGetValue(propName, out res);
+ return res;
+ }
+ }
+}
+
=== added file 'Empathy/src/EmpathyAccountActions.cs'
--- Empathy/src/EmpathyAccountActions.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathyAccountActions.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,114 @@
+// EmpathyAccountActions.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using System.Linq;
+using System.Collections.Generic;
+
+using Mono.Addins;
+
+using Do.Universe;
+using Do.Platform;
+
+namespace EmpathyPlugin
+{
+
+ public class EmpathyEnableAccount : Act
+ {
+ public override string Name
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Sign on"); }
+ }
+
+ public override string Description
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Enable empathy account"); }
+ }
+
+ public override string Icon
+ {
+ get { return "empathy"; }
+ }
+
+ public override IEnumerable<Type> SupportedItemTypes
+ {
+ get { yield return typeof (EmpathyAccountItem); }
+ }
+
+ public override bool SupportsItem (Item item)
+ {
+ if(! (item is EmpathyAccountItem))
+ {
+ return false;
+ }
+ EmpathyAccountItem accountItem = (item as EmpathyAccountItem);
+ return ! accountItem.Account.IsConnected();
+ }
+
+ public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
+ {
+ EmpathyAccountItem account = items.First () as EmpathyAccountItem;
+ account.Account.EnableAccount();
+ yield break;
+ }
+ }
+
+ public class EmpathyDisableAccount : Act
+ {
+ public override string Name
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Sign off"); }
+ }
+
+ public override string Description
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Disable empathy account"); }
+ }
+
+ public override string Icon
+ {
+ get { return "empathy"; }
+ }
+
+ public override IEnumerable<Type> SupportedItemTypes
+ {
+ get { yield return typeof (EmpathyAccountItem); }
+ }
+
+ public override bool SupportsItem (Item item)
+ {
+ if(! (item is EmpathyAccountItem))
+ {
+ return false;
+ }
+ EmpathyAccountItem accountItem = (item as EmpathyAccountItem);
+ return accountItem.Account.IsConnected();
+
+ }
+
+ public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
+ {
+ EmpathyAccountItem account = items.First () as EmpathyAccountItem;
+ account.Account.DisableAccount();
+
+ yield break;
+ }
+ }
+}
=== added file 'Empathy/src/EmpathyAccountItem.cs'
--- Empathy/src/EmpathyAccountItem.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathyAccountItem.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,57 @@
+// EmpathyAccountItem.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System.IO;
+
+using Do.Universe;
+using Do.Platform;
+
+namespace EmpathyPlugin
+{
+
+ public class EmpathyAccountItem : Item
+ {
+ public EmpathyAccountItem (Account account)
+ {
+ Account = account;
+ Proto = Account.proto.ToLower();
+ }
+
+ public int Id { get; protected set; }
+ public string Proto { get; protected set; }
+ public Account Account { get; protected set; }
+
+ public override string Name
+ {
+ get { return Account.name; }
+ }
+
+ public override string Description
+ {
+ get { return Proto; }
+ }
+
+ public override string Icon
+ {
+ get { return EmpathyPlugin.GetProtocolIcon (Account.GetIconName()); }
+ }
+
+ }
+}
=== added file 'Empathy/src/EmpathyAccountItemSource.cs'
--- Empathy/src/EmpathyAccountItemSource.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathyAccountItemSource.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,95 @@
+// EmpathyAccountItemSource.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using System.Collections.Generic;
+using Mono.Addins;
+using Do.Universe;
+using Do.Platform;
+
+namespace EmpathyPlugin
+{
+
+ public class EmpathyAccountItemSource : ItemSource
+ {
+
+ List<Item> items;
+
+ public EmpathyAccountItemSource ()
+ {
+ items = new List<Item> ();
+ }
+
+ public override string Name
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Empathy Accounts"); }
+ }
+
+ public override string Description
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Available Empathy IM Accounts"); }
+ }
+
+ public override string Icon
+ {
+ get { return "empathy"; }
+ }
+
+ public override IEnumerable<Type> SupportedItemTypes
+ {
+ get {
+ yield return typeof (EmpathyAccountItem);
+ yield return typeof (IApplicationItem);
+ yield return typeof (EmpathyBrowseAccountItem);
+ }
+ }
+
+ public override IEnumerable<Item> ChildrenOfItem (Item item)
+ {
+ if (EmpathyPlugin.IsTelepathy (item)) {
+ yield return new EmpathyBrowseAccountItem ();
+ } else if (item is EmpathyBrowseAccountItem) {
+ foreach (EmpathyAccountItem account in items) {
+ yield return account;
+ }
+ }
+ }
+
+ public override IEnumerable<Item> Items
+ {
+ get { return items; }
+ }
+
+ public override void UpdateItems ()
+ {
+ if (EmpathyPlugin.InstanceIsRunning) {
+ items.Clear ();
+ try {
+ foreach (Account account in EmpathyPlugin.GetAllAccounts) {
+ items.Add (new EmpathyAccountItem (account));
+ }
+ } catch (Exception e) {
+ Log<EmpathyAccountItemSource>.Error ("Could not get Empathy accounts: {0}", e.Message);
+ Log<EmpathyAccountItemSource>.Debug (e.StackTrace);
+ }
+ }
+ }
+ }
+}
=== added file 'Empathy/src/EmpathyBrowseAccountItem.cs'
--- Empathy/src/EmpathyBrowseAccountItem.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathyBrowseAccountItem.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,44 @@
+// EmpathyBrowseAccountItem.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using Do.Universe;
+using Mono.Addins;
+
+namespace EmpathyPlugin
+{
+ public class EmpathyBrowseAccountItem : Item
+ {
+ public override string Name
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Accounts"); }
+ }
+
+ public override string Description
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Browse Empathy Accounts"); }
+ }
+
+ public override string Icon
+ {
+ get { return "empathy"; }
+ }
+ }
+}
=== added file 'Empathy/src/EmpathyBrowseBuddyItem.cs'
--- Empathy/src/EmpathyBrowseBuddyItem.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathyBrowseBuddyItem.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,43 @@
+// EmpathyBrowseBuddyItem.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using Mono.Addins;
+using Do.Universe;
+
+namespace EmpathyPlugin
+{
+ public class EmpathyBrowseBuddyItem : Item
+ {
+ public override string Name
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Contacts"); }
+ }
+
+ public override string Description
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Browse Empathy Contacts"); }
+ }
+
+ public override string Icon
+ {
+ get { return "empathy"; }
+ }
+ }
+}
=== added file 'Empathy/src/EmpathyBrowseStatusItem.cs'
--- Empathy/src/EmpathyBrowseStatusItem.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathyBrowseStatusItem.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,46 @@
+// EmpathyBrowseStatusItem.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+
+using Mono.Addins;
+
+using Do.Universe;
+
+namespace EmpathyPlugin
+{
+ public class EmpathyBrowseStatusItem : Item
+ {
+ public override string Name
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Statuses"); }
+ }
+
+ public override string Description
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Browse Empathy Statuses"); }
+ }
+
+ public override string Icon
+ {
+ get { return "empathy"; }
+ }
+ }
+}
=== added file 'Empathy/src/EmpathyChatAction.cs'
--- Empathy/src/EmpathyChatAction.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathyChatAction.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,105 @@
+// EmpathyChatAction.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using System.Linq;
+using System.Threading;
+using System.Collections.Generic;
+using Mono.Addins;
+using Do.Platform;
+using Do.Universe;
+
+namespace EmpathyPlugin
+{
+
+ public class EmpathyChatAction : Act
+ {
+
+ public EmpathyChatAction ()
+ {
+ }
+
+ public override string Name
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Chat"); }
+ }
+
+ public override string Description
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Send an instant message to a friend."); }
+ }
+
+ public override string Icon
+ {
+ get { return EmpathyPlugin.ChatIcon; }
+ }
+
+ public override IEnumerable<Type> SupportedItemTypes
+ {
+ get {
+ yield return typeof (ContactItem);
+ }
+ }
+
+ public override bool SupportsItem (Item item)
+ {
+ if (item is ContactItem) {
+ ContactItem contact = item as ContactItem;
+
+ return contact.Details.Contains("is-empathy");
+ }
+ return true;
+ }
+
+ public override IEnumerable<Type> SupportedModifierItemTypes
+ {
+ get { yield return typeof (ITextItem); }
+ }
+
+ public override bool ModifierItemsOptional
+ {
+ get { return true; }
+ }
+
+
+ public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
+ {
+ string message = "";
+
+ if (modItems.Any ())
+ message = (modItems.First () as ITextItem).Text;
+
+ foreach (Item item in items) {
+ if (item is ContactItem) {
+ ContactItem contactItem = item as ContactItem;
+ string contactId = contactItem["email"];
+
+ if (!string.IsNullOrEmpty (message))
+ EmpathyPlugin.OpenConversationWithBuddy (contactId, message);
+ else
+ EmpathyPlugin.OpenConversationWithBuddy (contactId);
+ }
+ }
+
+ yield break;
+ }
+
+ }
+}
=== added file 'Empathy/src/EmpathyContactItemSource.cs'
--- Empathy/src/EmpathyContactItemSource.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathyContactItemSource.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,104 @@
+// EmpathyContactItemSource.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using System.IO;
+using System.Linq;
+using System.Collections.Generic;
+using Mono.Addins;
+using Do.Universe;
+using Do.Platform;
+
+namespace EmpathyPlugin
+{
+
+ public class EmpathyContactItemSource : ItemSource
+ {
+
+ const string iconPrefix = "icon-";
+
+ List<Item> contacts;
+
+ public EmpathyContactItemSource ()
+ {
+ contacts = new List<Item> ();
+ }
+
+ public override IEnumerable<Type> SupportedItemTypes {
+ get {
+ yield return typeof (ContactItem);
+ yield return typeof (IApplicationItem);
+ yield return typeof (EmpathyBrowseBuddyItem);
+ }
+ }
+
+ public override string Name {
+ get { return AddinManager.CurrentLocalizer.GetString ("Empathy Contacts"); }
+ }
+
+ public override string Description {
+ get { return AddinManager.CurrentLocalizer.GetString ("Contacts on your Empathy contact alist."); }
+ }
+
+ public override string Icon {
+ get { return "empathy"; }
+ }
+
+ public override IEnumerable<Item> Items {
+ get { return contacts; }
+ }
+
+ public override IEnumerable<Item> ChildrenOfItem (Item item)
+ {
+ if (EmpathyPlugin.IsTelepathy (item)) {
+ yield return new EmpathyBrowseBuddyItem ();
+ } else if (item is EmpathyBrowseBuddyItem) {
+ foreach (ContactItem contact in contacts)
+ {
+ yield return contact;
+ }
+ }
+ }
+
+ public override void UpdateItems ()
+ {
+ if (EmpathyPlugin.InstanceIsRunning) {
+ contacts.Clear ();
+ try {
+
+ foreach (Contact contact in EmpathyPlugin.GetAllContacts) {
+ ContactItem contactItem = ContactItem.Create (contact.Alias);
+ contactItem["email"] = contact.ContactId;
+ contactItem["is-empathy"] = "true";
+ if(contact.AvatarToken != null && contact.AvatarToken != "")
+ {
+ string[] elts = new string[]{Environment.GetFolderPath (Environment.SpecialFolder.Personal), EmpathyPlugin.AVATAR_PATH, contact.Account.cm, contact.Account.proto, contact.AvatarToken};
+ contactItem["photo"] = elts.Aggregate((aggregation, val) => Path.Combine (aggregation, val));
+ }
+ contacts.Add (contactItem);
+ }
+ } catch (Exception e) {
+ Log<EmpathyContactItemSource>.Error ("Could not get Empathy contacts: {0}", e.Message);
+ Log<EmpathyContactItemSource>.Error (e.StackTrace);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
=== added file 'Empathy/src/EmpathyPlugin.cs'
--- Empathy/src/EmpathyPlugin.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathyPlugin.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,212 @@
+// EmpathyPlugin.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using NDesk.DBus;
+using org.freedesktop.DBus;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using AccountManagerQuery;
+using Do.Universe;
+using Telepathy;
+
+namespace EmpathyPlugin
+{
+
+ public class EmpathyPlugin
+ {
+ public const string ACCOUNTMANAGER_IFACE = "org.freedesktop.Telepathy.AccountManager";
+ public const string ACCOUNTMANAGER_PATH = "/org/freedesktop/Telepathy/AccountManager";
+
+ public const string CHANNELDISPATCHER_IFACE = "org.freedesktop.Telepathy.ChannelDispatcher";
+ public const string CHANNELDISPATCHER_PATH = "/org/freedesktop/Telepathy/ChannelDispatcher";
+
+ public const string ACCOUNT_IFACE = "org.freedesktop.Telepathy.Account";
+
+ public const string CONNMANAGER_GABBLE_IFACE = "org.freedesktop.Telepathy.ConnectionManager.gabble";
+ public const string CONNMANAGER_GABBLE_PATH = "/org/freedesktop/Telepathy/ConnectionManager/gabble";
+
+ public const string CONNECTION_IFACE = "org.freedesktop.Telepathy.Connection";
+ public const string REQUESTS_IFACE = "org.freedesktop.Telepathy.Connection.Interface.Requests";
+
+ public const string CHANNEL_TYPE = "org.freedesktop.Telepathy.Channel.ChannelType";
+ public const string CHANNEL_TYPE_TEXT = "org.freedesktop.Telepathy.Channel.Type.Text";
+
+ public const string CHANNEL_IFACE = "org.freedesktop.Telepathy.Channel";
+ public const string CHANNEL_GROUP_IFACE = "org.freedesktop.Telepathy.Channel.Interface.Group";
+ public const string CHANNEL_LIST_IFACE = "org.freedesktop.Telepathy.Channel.Interface.List";
+
+ public const string CONNECTION_CONTACT_IFACE = "org.freedesktop.Telepathy.Connection.Interface.Contacts";
+
+ public const string CONTACT_PROP_ID = "org.freedesktop.Telepathy.Connection/contact-id";
+ public const string CONTACT_PROP_ALIAS = "org.freedesktop.Telepathy.Connection.Interface.Aliasing/alias";
+
+ public const string CHANNEL_TARGETHANDLETYPE = "org.freedesktop.Telepathy.Channel.TargetHandleType";
+ public const string CHANNEL_TARGETHANDLE = "org.freedesktop.Telepathy.Channel.TargetHandle";
+ public const string CHANNEL_TYPE_CONTACTLIST = "org.freedesktop.Telepathy.Channel.Type.ContactList";
+
+ public const string CONNECTION_CAPABILITIES_IFACE = "org.freedesktop.Telepathy.Connection.Interface.Capabilities";
+
+ public const string DBUS_PROPERTIES = "org.freedesktop.DBus.Properties";
+
+ public const string AVATAR_PATH = ".cache/telepathy/avatars";
+
+ public const string PROTO_ICON_PATH = "/usr/share/empathy/icons/hicolor/48x48/apps";
+
+ public const string PRESETS_STATUS_PLACE = ".config/Empathy/status-presets.xml";
+
+ public static string ChatIcon
+ {
+ get { return "empathy"; }
+ }
+
+ public static bool IsTelepathy (Item item)
+ {
+ return item.Equals (Do.Platform.Services.UniverseFactory.MaybeApplicationItemFromCommand ("empathy"));
+ }
+
+ public static List<Account> ConnectedAccounts {
+ get {
+ List<Account> res = new List<Account>();
+ IAccountManagerQuery iAccountManagerQueryBus = Bus.Session.GetObject<IAccountManagerQuery> (ACCOUNTMANAGER_IFACE, new ObjectPath (ACCOUNTMANAGER_PATH));;
+ ObjectPath[] accountPathArray = iAccountManagerQueryBus.FindAccounts (new Dictionary<string, object> ());
+
+ foreach(ObjectPath accountPath in accountPathArray) {
+ Account account = new Account(accountPath);
+ if(account.IsConnected()) {
+ res.Add(account);
+ }
+ }
+ return res;
+ }
+ }
+
+ public static List<Account> GetAllAccounts {
+ get {
+ List<Account> res = new List<Account>();
+ IAccountManagerQuery iAccountManagerQueryBus = Bus.Session.GetObject<IAccountManagerQuery> (ACCOUNTMANAGER_IFACE, new ObjectPath (ACCOUNTMANAGER_PATH));;
+ ObjectPath[] accountPathArray = iAccountManagerQueryBus.FindAccounts (new Dictionary<string, object> ());
+
+ foreach(ObjectPath accountPath in accountPathArray) {
+ Account account = new Account(accountPath);
+
+ res.Add(account);
+ }
+ return res;
+ }
+ }
+
+ public static List<Contact> GetAllContacts {
+ get {
+ List<Contact> res = new List<Contact>();
+ foreach(Account account in ConnectedAccounts) {
+
+ foreach(Contact contact in account.FindContact()) {
+ res.Add(contact);
+ }
+ }
+ return res;
+ }
+ }
+
+ public static bool InstanceIsRunning
+ {
+ get {
+ Process pidof;
+ ProcessStartInfo pidofInfo = new ProcessStartInfo ("pidof", "empathy");
+ pidofInfo.UseShellExecute = false;
+ pidofInfo.RedirectStandardError = true;
+ pidofInfo.RedirectStandardOutput = true;
+
+ try {
+ // Use pidof command to look for empathy process. Exit
+ // status is 0 if at least one matching process is found.
+ // If there's any error, just assume some Purple client
+ // is running.
+ pidof = Process.Start (pidofInfo);
+ pidof.WaitForExit ();
+ return pidof.ExitCode == 0;
+ } catch {
+ return true;
+ }
+ }
+ }
+
+ public static bool BuddyIsOnline (string contactName)
+ {
+ Account account;
+ return GetBuddyIsOnlineAndAccount (contactName, out account);
+ }
+
+ public static bool GetBuddyIsOnlineAndAccount (string contactName, out Account account_out)
+ {
+ account_out = null;
+
+ try {
+ foreach (Account account in ConnectedAccounts) {
+ if (account.HasContact(contactName) )
+ {
+ account_out = account;
+ return true;
+ }
+ }
+ } catch (Exception e) {
+ Console.WriteLine ("Could not get Empathy contacts: {0}", e.Message);
+ Console.WriteLine (e.StackTrace);
+ }
+
+ return false;
+ }
+
+
+ public static string GetProtocolIcon (string proto)
+ {
+ string icon = null;
+ proto = proto.ToLower ();
+
+ icon = Path.Combine (PROTO_ICON_PATH, proto + ".png");
+ return File.Exists (icon) ? icon : EmpathyPlugin.ChatIcon;
+ }
+
+ public static void OpenConversationWithBuddy(string contactId, string message)
+ {
+ Account account;
+ if ( GetBuddyIsOnlineAndAccount(contactId, out account) )
+ {
+ account.OpenConversationWithBuddy(contactId, message);
+ }
+ }
+
+ public static void OpenConversationWithBuddy(string contactId)
+ {
+ OpenConversationWithBuddy(contactId, null);
+ }
+
+ public static void SetAvailabilityStatus(ConnectionPresenceType status, string message)
+ {
+ foreach (Account account in ConnectedAccounts) {
+ account.SetStatus(status, message);
+ }
+ }
+ }
+}
+
+
=== added file 'Empathy/src/EmpathySavedStatusItem.cs'
--- Empathy/src/EmpathySavedStatusItem.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathySavedStatusItem.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,51 @@
+// EmpathySavedStatusItem.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using System.IO;
+using System.Text.RegularExpressions;
+
+using Do.Universe;
+
+using Telepathy;
+
+namespace EmpathyPlugin
+{
+ public class EmpathySavedStatusItem : EmpathyStatusItem
+ {
+ public EmpathySavedStatusItem (ConnectionPresenceType status, string message) : base(status)
+ {
+ Message = message;
+ }
+
+
+ public override string Name {
+ get { return StripHTML(Message); }
+ }
+
+ public string Message { get; private set; }
+
+ string StripHTML (string message)
+ {
+ return Regex.Replace(message, @"<(.|\n)*?>", string.Empty);
+ }
+ }
+
+}
=== added file 'Empathy/src/EmpathySavedStatusItemSource.cs'
--- Empathy/src/EmpathySavedStatusItemSource.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathySavedStatusItemSource.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,121 @@
+// EmpathySavedStatusItemSource.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using System.Linq;
+using System.IO;
+using System.Xml;
+using System.Collections.Generic;
+
+using Mono.Addins;
+
+using Do.Universe;
+using Do.Platform;
+
+using Telepathy;
+
+namespace EmpathyPlugin
+{
+
+ public class EmpathySavedStatusItemSource : ItemSource
+ {
+
+ static readonly string PresetsFile;
+
+ List<Item> statuses;
+ static EmpathySavedStatusItemSource ()
+ {
+ string home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
+ string[] PresetsFileParts = new string[] {home, EmpathyPlugin.PRESETS_STATUS_PLACE};
+ PresetsFile = PresetsFileParts.Aggregate ((aggregation, val) => Path.Combine (aggregation, val));
+ }
+
+ public EmpathySavedStatusItemSource ()
+ {
+ statuses = new List<Item> ();
+ statuses.Add (new EmpathyStatusItem(ConnectionPresenceType.Offline));
+ statuses.Add (new EmpathyStatusItem(ConnectionPresenceType.Available));
+ statuses.Add (new EmpathyStatusItem(ConnectionPresenceType.Away));
+ statuses.Add (new EmpathyStatusItem(ConnectionPresenceType.Busy));
+ statuses.Add (new EmpathyStatusItem(ConnectionPresenceType.Hidden));
+ }
+
+ public override string Name
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Empathy Statuses"); }
+ }
+
+ public override string Description
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Saved Empathy statuses"); }
+ }
+
+ public override string Icon
+ {
+ get { return "empathy"; }
+ }
+
+ public override IEnumerable<Type> SupportedItemTypes
+ {
+ get {
+ yield return typeof (EmpathySavedStatusItem);
+ yield return typeof (EmpathyStatusItem);
+ yield return typeof (EmpathyBrowseStatusItem);
+ }
+ }
+
+ public override IEnumerable<Item> ChildrenOfItem (Item item)
+ {
+ if (EmpathyPlugin.IsTelepathy (item))
+ {
+ yield return new EmpathyBrowseStatusItem ();
+ }
+ else if (item is EmpathyBrowseStatusItem)
+ {
+ foreach (Item status in statuses)
+ yield return status;
+ }
+ }
+
+ public override IEnumerable<Item> Items {
+ get { return statuses; }
+ }
+
+ public override void UpdateItems ()
+ {
+ // lire les status enregistrés
+ XmlDocument statusList = new XmlDocument ();
+ try {
+ statusList.Load (PresetsFile);
+
+ foreach (XmlNode statusNode in statusList.GetElementsByTagName ("status")) {
+ string pres = statusNode.Attributes.GetNamedItem("presence").Value;
+ string message = statusNode.InnerText;
+
+ statuses.Add (new EmpathySavedStatusItem (EmpathyStatus.GetPresence(pres), message));
+ }
+
+ } catch (Exception e) {
+ Log<EmpathySavedStatusItemSource>.Error ("Error reading presets statuses: {0}", e.Message);
+ Log<EmpathySavedStatusItemSource>.Debug (e.StackTrace);
+ }
+ }
+ }
+}
=== added file 'Empathy/src/EmpathySetStatusAction.cs'
--- Empathy/src/EmpathySetStatusAction.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathySetStatusAction.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,124 @@
+// EmpathySetStatusAction.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using System.Linq;
+
+using System.Collections.Generic;
+
+using Mono.Addins;
+
+using Do.Universe;
+using Do.Platform;
+using EmpathyPlugin;
+using Telepathy;
+
+namespace EmpathyPlugin
+{
+
+ public class EmpathySetStatusAction : Act
+ {
+
+
+ public EmpathySetStatusAction ()
+ {
+ }
+
+ public override string Name
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Set status"); }
+ }
+
+ public override string Description
+ {
+ get { return AddinManager.CurrentLocalizer.GetString ("Set empathy status message"); }
+ }
+
+ public override string Icon
+ {
+ get { return "empathy"; }
+ }
+
+ public override IEnumerable<Type> SupportedItemTypes {
+ get {
+ yield return typeof (EmpathyStatusItem);
+ yield return typeof (ITextItem);
+ }
+ }
+
+ public override IEnumerable<Type> SupportedModifierItemTypes {
+ get {
+ yield return typeof (ITextItem);
+ yield return typeof (EmpathyStatusItem);
+ }
+ }
+
+ public override bool ModifierItemsOptional {
+ get { return true; }
+ }
+
+ public override bool SupportsModifierItemForItems (IEnumerable<Item> items, Item modItem)
+ {
+ if (items.First () is EmpathySavedStatusItem || modItem is EmpathySavedStatusItem)
+ return false;
+ if (items.First () is EmpathyStatusItem && modItem is ITextItem)
+ return true;
+ if (items.First () is ITextItem && modItem is EmpathyStatusItem)
+ return true;
+ return false;
+ }
+
+ public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
+ {
+ ConnectionPresenceType status;
+ string message = "";
+ try {
+
+ if (items.First () is EmpathySavedStatusItem)
+ {
+ status = (items.First () as EmpathySavedStatusItem).Status;
+ message = (items.First () as EmpathySavedStatusItem).Message;
+ EmpathyPlugin.SetAvailabilityStatus(status, message);
+ }
+ else if (items.First () is EmpathyStatusItem)
+ {
+ status = (items.First () as EmpathyStatusItem).Status;
+ if (modItems.Any ())
+ message = (modItems.First () as ITextItem).Text;
+ EmpathyPlugin.SetAvailabilityStatus(status, message);
+ }
+ else if (items.First () is ITextItem)
+ {
+ if (modItems.Any ())
+ status = (modItems.First () as EmpathyStatusItem).Status;
+ else
+ status = ConnectionPresenceType.Available;
+ message = (items.First () as ITextItem).Text;
+ EmpathyPlugin.SetAvailabilityStatus(status, message);
+ }
+ } catch (Exception e) {
+ Log<EmpathySetStatusAction>.Error ("Could not set Empathy status: {0}", e.Message);
+ Log<EmpathySetStatusAction>.Debug (e.StackTrace);
+ }
+
+ yield break;
+ }
+ }
+}
=== added file 'Empathy/src/EmpathyStatusItem.cs'
--- Empathy/src/EmpathyStatusItem.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/EmpathyStatusItem.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,81 @@
+// EmapthyStatusItem.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using System.IO;
+
+using Mono.Addins;
+
+using Do.Universe;
+using Do.Platform;
+
+using Telepathy;
+
+namespace EmpathyPlugin
+{
+
+ public class EmpathyStatusItem : Item
+ {
+
+ public EmpathyStatusItem (ConnectionPresenceType status)
+ {
+ this.Status = status;
+ }
+
+ public EmpathyStatusItem (ConnectionPresenceType status, string message)
+ {
+ this.Status = status;
+ }
+
+ public override string Name {
+ get {
+ return Description;
+ }
+ }
+
+ public override string Description {
+ get {
+ switch (this.Status) {
+ case ConnectionPresenceType.Offline: return AddinManager.CurrentLocalizer.GetString ("Offline");
+ case ConnectionPresenceType.Available: return AddinManager.CurrentLocalizer.GetString ("Available");
+ case ConnectionPresenceType.Away: return AddinManager.CurrentLocalizer.GetString ("Away");
+ case ConnectionPresenceType.Hidden: return AddinManager.CurrentLocalizer.GetString ("Invisible");
+ case ConnectionPresenceType.Busy: return AddinManager.CurrentLocalizer.GetString ("Busy");
+ default: return AddinManager.CurrentLocalizer.GetString ("Unknown Status");
+ }
+ }
+ }
+
+ public override string Icon {
+ get {
+ switch (this.Status) {
+ case ConnectionPresenceType.Offline: return "user-offline";
+ case ConnectionPresenceType.Available: return "user-available";
+ case ConnectionPresenceType.Away: return "user-away";
+ case ConnectionPresenceType.Hidden: return "user-invisible";
+ case ConnectionPresenceType.Busy: return "user-busy";
+ default: return "empathy";
+ }
+ }
+ }
+
+ public ConnectionPresenceType Status { get; private set; }
+ }
+}
=== added file 'Empathy/src/Status.cs'
--- Empathy/src/Status.cs 1970-01-01 00:00:00 +0000
+++ Empathy/src/Status.cs 2010-08-15 12:39:41 +0000
@@ -0,0 +1,117 @@
+// Status.cs
+//
+// Author:
+// Xavier Calland <xavier.calland@xxxxxxxxx>
+//
+// Copyright (c) 2010
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+using System;
+using System.Collections.Generic;
+using Telepathy;
+
+namespace EmpathyPlugin
+{
+
+ public enum BaseStatus
+ {
+ available,
+ away,
+ brb,
+ busy,
+ dnd,
+ xa,
+ hidden,
+ offline,
+ unknown,
+ error
+ }
+
+ public class EmpathyStatus
+ {
+
+ public BaseStatus identifier {get; private set;}
+ public string message {get; private set;}
+
+ public EmpathyStatus(BaseStatus identifier, string message)
+ {
+ this.identifier = identifier;
+ this.message = message;
+ }
+
+ public static List<BaseStatus> GetStatusList(ConnectionPresenceType presenceType)
+ {
+ List<BaseStatus> res = new List<BaseStatus>();
+
+ switch (presenceType) {
+ case ConnectionPresenceType.Available:
+ res.Add(BaseStatus.available);
+ break;
+ case ConnectionPresenceType.Away:
+ res.Add(BaseStatus.away);
+ res.Add(BaseStatus.brb);
+ break;
+ case ConnectionPresenceType.Busy:
+ res.Add(BaseStatus.busy);
+ res.Add(BaseStatus.dnd);
+ break;
+ case ConnectionPresenceType.Error:
+ res.Add(BaseStatus.error);
+ break;
+ case ConnectionPresenceType.ExtendedAway:
+ res.Add(BaseStatus.xa);
+ break;
+ case ConnectionPresenceType.Hidden:
+ res.Add(BaseStatus.hidden);
+ break;
+ case ConnectionPresenceType.Offline:
+ res.Add(BaseStatus.offline);
+ break;
+ case ConnectionPresenceType.Unknown:
+ res.Add(BaseStatus.unknown);
+ break;
+ default:
+ break;
+ }
+
+ return res;
+ }
+
+ public static ConnectionPresenceType GetPresence(string pres)
+ {
+ switch (pres) {
+ case "available":
+ return ConnectionPresenceType.Available;
+ case "away":
+ return ConnectionPresenceType.Away;
+ case "busy":
+ return ConnectionPresenceType.Busy;
+ case "error":
+ return ConnectionPresenceType.Error;
+ case "extended-away":
+ return ConnectionPresenceType.ExtendedAway;
+ case "hidden":
+ return ConnectionPresenceType.Hidden;
+ case "offline":
+ return ConnectionPresenceType.Offline;
+ case "unknown":
+ return ConnectionPresenceType.Unknown;
+ default:
+ return ConnectionPresenceType.Unknown;
+ }
+ }
+ }
+}
+
=== added file 'Empathy/telepathy-sharp.dll'
Binary files Empathy/telepathy-sharp.dll 1970-01-01 00:00:00 +0000 and Empathy/telepathy-sharp.dll 2010-08-15 12:39:41 +0000 differ