Esempio n. 1
0
 public RosterNode GetRosterItem(Jid jid)
 {
     if (m_Roster.ContainsKey(jid.Bare))
     {
         RosterData d = m_Roster[jid.Bare];
         return(d.RosterNode);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 2
0
        private void treeView_MouseMove(object sender, MouseEventArgs e)
        {
            RosterNode rn = this.treeView.GetNodeAt(e.X, e.Y) as RosterNode;

            if (rn != null && rn.NodeType == RosterNodeType.RosterNode)
            {
                int currentNodeIndex = rn.Index;
                if (currentNodeIndex != oldNodeIndex)
                {
                    // Node Changed
                    tool.Active = false;

                    oldNodeIndex = currentNodeIndex;

                    if (rn.RosterItem != null)
                    {
                        if (m_Roster.ContainsKey(rn.RosterItem.Jid.Bare))
                        {
                            tool.Tooltiptext  = rn.RosterItem.Jid.ToString();
                            tool.Tooltiptext += "\r\nSubscription: " + rn.RosterItem.Subscription.ToString();

                            RosterData d = m_Roster[rn.RosterItem.Jid.Bare];
                            if (d != null)
                            {
                                foreach (PresenceData p in d.Presences.Values)
                                {
                                    tool.Tooltiptext += "\r\n\r\n" + "Resource: " + p.Presence.From.Resource;
                                    if (p.Presence.Status != null)
                                    {
                                        tool.Tooltiptext += "\r\n" + "Status: " + p.Presence.Status;
                                    }
                                }
                            }
                            tool.Active = true;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Remove a RosterItem from the roster
        /// </summary>
        /// <param name="jid">The items Jid to remove</param>
        /// <returns
        /// >returns true if the item was removed, false if it didn't exist
        /// and could not be removed
        /// </returns>
        public bool RemoveRosterItem(Jid jid)
        {
            if (m_Roster.ContainsKey(jid.ToString()))
            {
                RosterData d      = m_Roster[jid.ToString()];
                TreeNode   Parent = d.RosterNode.Parent;
                d.RosterNode.Remove();
                m_Roster.Remove(jid.ToString());

                if (m_HideEmptyGroups)
                {
                    if (Parent.Nodes.Count == 0)
                    {
                        Parent.Remove();
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Moves a Node from the online section to the offline section or vice versa
        /// </summary>
        /// <param name="rdata"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        private void MoveRoster(RosterData rdata, RosterNode from, RosterNode to)
        {
            RosterNode groupNode;

            string groupName = rdata.Group;

            groupNode = GetGroup(to, groupName);
            if (groupNode == null)
            {
                groupNode = AddGroup(groupName, to);
            }

            RosterNode newNode = rdata.RosterNode.Clone() as RosterNode;

            groupNode.Nodes.Add(newNode);

            // Expand all groupes in the Online Node
            if (to == m_RootOnline)
            {
                groupNode.Expand();
                m_RootOnline.Expand();
            }

            TreeNode Parent = rdata.RosterNode.Parent;

            rdata.RosterNode.Remove();
            rdata.RosterNode = null;
            rdata.RosterNode = newNode;

            if (m_HideEmptyGroups)
            {
                if (Parent.Nodes.Count == 0)
                {
                    Parent.Remove();
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Moves a Node from the online section to the offline section or vice versa
        /// </summary>
        /// <param name="rdata"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        private void MoveRoster(RosterData rdata, RosterNode from, RosterNode to)
        {
            RosterNode groupNode;

            string groupName = rdata.Group;

            groupNode = GetGroup(to, groupName);
            if (groupNode  == null)
                groupNode = AddGroup(groupName, to);

            RosterNode newNode = rdata.RosterNode.Clone() as RosterNode;
            groupNode.Nodes.Add(newNode);

            // Expand all groupes in the Online Node
            if (to == m_RootOnline)
            {
                groupNode.Expand();
                m_RootOnline.Expand();
            }

            TreeNode Parent = rdata.RosterNode.Parent;
            rdata.RosterNode.Remove();
            rdata.RosterNode = null;
            rdata.RosterNode = newNode;

            if (m_HideEmptyGroups)
            {
                if (Parent.Nodes.Count == 0)
                    Parent.Remove();
            }
        }
Esempio n. 6
0
        public void SetPresence(Presence pres)
        {
            // Dont handle presence errors for now
            if (pres.Type == PresenceType.error)
            {
                return;
            }

            // We need a node all the time here
            RosterNode n;

            if (pres.Type == PresenceType.unavailable)
            {
                // The presence could also be a presence from a hroup chat.
                // So check here if its a presence from a rosterItem
                if (m_Roster.ContainsKey(pres.From.Bare))
                {
                    RosterData d = m_Roster[pres.From.Bare];
                    if (d != null)
                    {
                        if (d.Presences.ContainsKey(pres.From.ToString()))
                        {
                            PresenceData presData = d.Presences[pres.From.ToString()];
                            RosterNode   parent   = (RosterNode)presData.Node.Parent;

                            presData.Node.Remove();
                            d.Presences.Remove(pres.From.ToString());

                            // Last Presence goes Offline
                            if (d.Presences.Count == 0)
                            {
                                parent.ImageIndex         = IMAGE_OFFLINE;
                                parent.SelectedImageIndex = IMAGE_OFFLINE;

                                // If Online Move it to the Offline Section
                                if (GetRootFromLeaf(d.RosterNode) == m_RootOnline)
                                {
                                    MoveRoster(d, m_RootOnline, m_RootOffline);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                // Online Presence
                // The presence could also be a presence from a hroup chat.
                // So check here if its a presence from a rosterItem
                if (m_Roster.ContainsKey(pres.From.Bare))
                {
                    RosterData d = m_Roster[pres.From.Bare];
                    // Check if the roster is in the online section, when not then move it from Offline to Online
                    if (!d.Online)
                    {
                        MoveRoster(d, m_RootOffline, m_RootOnline);
                    }

                    if (d != null)
                    {
                        int img = (int)pres.Show;
                        if (img == -1)
                        {
                            img = IMAGE_ONLINE;
                        }

                        if (d.Presences.ContainsKey(pres.From.ToString()))
                        {
                            // Presence for this item available
                            PresenceData presData = (PresenceData)d.Presences[pres.From.ToString()];

                            presData.Node.SelectedImageIndex = img;
                            presData.Node.ImageIndex         = img;
                            presData.Node.Presence           = pres;

                            presData.Node.Parent.SelectedImageIndex = img;
                            presData.Node.Parent.ImageIndex         = img;

                            presData.Presence = pres;
                        }
                        else
                        {
                            // Presence not available yet, so add it
                            n = new RosterNode(pres.From.Resource, RosterNodeType.ResourceNode);

                            n.SelectedImageIndex = img;
                            n.ImageIndex         = img;
                            n.Presence           = pres;

                            d.RosterNode.Nodes.Add(n);

                            n.Parent.SelectedImageIndex = img;
                            n.Parent.ImageIndex         = img;

                            n.Name = ((RosterNode)n.Parent).Name;

                            d.Presences.Add(pres.From.ToString(), new PresenceData(n, pres));
                        }
                    }
                }
            }
        }