protected virtual void Dispose(bool disposing) { if (!disposing) { return; } if (contact_list != null) { contact_list.ChannelReady -= OnContactListChannelReady; contact_list.MembersAdded -= OnMembersAdded; contact_list.MembersRemoved -= OnMembersRemoved; contact_list.Dispose(); contact_list = null; } if (presence != null) { try { presence.PresencesChanged -= OnPresencesChanged; } catch (Exception) {} presence = null; } lock (roster) { foreach (KeyValuePair <uint, Contact> kv in roster) { kv.Value.Dispose(); } } roster.Clear(); conn = null; }
private void ProcessContacts(string bus_name, ObjectPath op) { if (transfer_partner == null) { Console.WriteLine(MSG_PREFIX + "No transfer_partner. Will wait for file."); return; } // the easy way string[] tmp = { transfer_partner }; uint[] tmp_handles = iconn.RequestHandles(HandleType.Contact, tmp); Console.WriteLine(MSG_PREFIX + "Handle for {0} the easy way: {1}", transfer_partner, tmp_handles[0]); ISimplePresence ipresence = bus.GetObject <ISimplePresence> (bus_name, op); IDictionary <uint, SimplePresence> presences = ipresence.GetPresences(tmp_handles); Console.WriteLine(MSG_PREFIX + "{0} is {1}", transfer_partner, presences[tmp_handles[0]].Type.ToString()); if (presences[tmp_handles[0]].Type == ConnectionPresenceType.Available) { transfer_partner_handle = tmp_handles[0]; Console.WriteLine(MSG_PREFIX + "{0} is {1}", transfer_partner, presences[tmp_handles[0]].Type.ToString()); } /* * // ensure contact can handle the type of tube * if (tube_partner_handle > 0 && !IsContactCapable (bus_name, op, tube_partner_handle)) { * Console.WriteLine ("{0} is not capable of handling the test tube.", tube_partner); * tube_partner_handle = 0; * } */ }
private uint GetTubePartnerHandle(uint[] contacts, ISimplePresence ipresence) { string[] member_names; member_names = iconn.InspectHandles(HandleType.Contact, contacts); // get status information for contacts IDictionary <uint, SimplePresence> presence_info = new Dictionary <uint, SimplePresence>(); presence_info = ipresence.GetPresences(contacts); uint tp_handle = 0; for (int i = 0; i < contacts.Length; i++) { if (presence_info.ContainsKey(contacts[i])) { Console.WriteLine(MSG_PREFIX + "Member: " + member_names[i]); Console.WriteLine(MSG_PREFIX + "Presences Key: " + contacts[i].ToString()); Console.WriteLine(MSG_PREFIX + "Presences Status: " + presence_info[contacts[i]].Status); if (member_names[i].Equals(tube_partner) && !presence_info[contacts[i]].Status.Equals("offline")) { tp_handle = contacts[i]; // remember hardcoded handle so we can message later Console.WriteLine(MSG_PREFIX + "Saving handle for tube partner {0}", tube_partner); } } } return(tp_handle); }
private void ProcessContacts(string bus_name, ObjectPath op) { ISimplePresence ipresence = bus.GetObject <ISimplePresence> (bus_name, op); ipresence.PresencesChanged += OnPresencesChanged; // handle contacts changing status uint[] contacts = GetContacts(bus_name); if (tube_partner == null) { Console.WriteLine(MSG_PREFIX + "No tube_partner. Will wait for tube offer."); return; } // the hard way tube_partner_handle = GetTubePartnerHandle(contacts, ipresence); Console.WriteLine(MSG_PREFIX + "Handle for {0} the hard way (if online only): {1}", tube_partner, tube_partner_handle); // the easy way string[] tmp = { tube_partner }; uint[] tmp_handles = iconn.RequestHandles(HandleType.Contact, tmp); Console.WriteLine(MSG_PREFIX + "Handle for {0} the easy way: {1}", tube_partner, tmp_handles[0]); // ensure contact can handle the type of tube if (tube_partner_handle > 0 && !IsContactCapable(bus_name, op, tube_partner_handle)) { Console.WriteLine("{0} is not capable of handling the test tube.", tube_partner); tube_partner_handle = 0; } }
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; } } } }
protected virtual void OnContactListChannelReady(object sender, EventArgs args) { uint [] contacts = contact_list.GetContacts(); //Log.DebugFormat ("Account {0} has {1} contacts", conn.AccountId, contacts.Length); presence = DBusUtility.GetProxy <ISimplePresence> (conn.Bus, conn.BusName, conn.ObjectPath); GetPresenceInfo(contacts); presence.PresencesChanged += OnPresencesChanged; state = RosterState.Loaded; OnRosterStateChanged(new RosterEventArgs(state)); }
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); if (idx != -1) { 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; }
public void OnConnectionStateChanged(ConnectionStatus status, ConnectionStatusReason reason) { Console.WriteLine(MSG_PREFIX + "Connection state changed, Status: {0}, Reason: {1}", status, reason); if (status == ConnectionStatus.Connected) { try { // show supported interfaces string[] interfaces; interfaces = iconn.GetInterfaces(); foreach (string s in interfaces) { Console.WriteLine(MSG_PREFIX + s); } string[] args = { "subscribe" }; uint[] handles; handles = iconn.RequestHandles(HandleType.List, args); ISimplePresence ipresence = bus.GetObject <ISimplePresence> (BusName, op); ipresence.PresencesChanged += OnPresencesChanged; // handle contacts changing status ObjectPath chann_op; chann_op = iconn.RequestChannel(Constants.CHANNEL_TYPE_CONTACTLIST, HandleType.List, handles[0], true); IGroup contact_list = bus.GetObject <IGroup> (BusName, chann_op); // use Group interface with Channel // get contacts uint[] contacts; //, local_pending, remote_pending; //contact_list.GetAllMembers(out contacts, out local_pending, out remote_pending); contacts = contact_list.Members; Console.WriteLine(MSG_PREFIX + "Got {0} Contacts!", contacts.Length); string[] members_str; members_str = iconn.InspectHandles(HandleType.Contact, contacts); // get status information for contacts IDictionary <uint, SimplePresence> dic = new Dictionary <uint, SimplePresence>(); dic = ipresence.GetPresences(contacts); for (int i = 0; i < contacts.Length; i++) { if (dic.ContainsKey(contacts[i])) { Console.WriteLine(MSG_PREFIX + "Member: " + members_str[i]); Console.WriteLine(MSG_PREFIX + "Presences Key: " + contacts[i].ToString()); Console.WriteLine(MSG_PREFIX + "Presences Status: " + dic[contacts[i]].Status); if (members_str[i].Equals(ACCOUNT_BANSHEE_TEST2) && !dic[contacts[i]].Status.Equals("offine")) { myhandle = contacts[i]; // remember hardcoded handle so we can message later } } } } catch (Exception e) { Console.WriteLine(MSG_PREFIX + e); } Timer timer = new Timer(); timer.Interval = 10000; // delay logoff by 10 seconds timer.Elapsed += new ElapsedEventHandler(Disconnect); timer.Start(); } if (status == ConnectionStatus.Disconnected) { running = false; } }
private uint GetTubePartnerHandle(uint[] contacts, ISimplePresence ipresence) { string[] member_names; member_names = iconn.InspectHandles (HandleType.Contact, contacts); // get status information for contacts IDictionary<uint,SimplePresence> presence_info = new Dictionary<uint,SimplePresence>(); presence_info = ipresence.GetPresences (contacts); uint tp_handle = 0; for (int i = 0; i < contacts.Length; i++) { if (presence_info.ContainsKey(contacts[i])) { Console.WriteLine(MSG_PREFIX + "Member: " + member_names[i]); Console.WriteLine(MSG_PREFIX + "Presences Key: " + contacts[i].ToString()); Console.WriteLine(MSG_PREFIX + "Presences Status: " + presence_info[contacts[i]].Status); if (member_names[i].Equals(tube_partner) && !presence_info[contacts[i]].Status.Equals("offline")) { tp_handle = contacts[i]; // remember hardcoded handle so we can message later Console.WriteLine (MSG_PREFIX + "Saving handle for tube partner {0}", tube_partner); } } } return tp_handle; }