public void AddFriend(Friend firend)
        {
            if (FriendKey==null)
            {
                FriendKey = new Dictionary<string, Friend>();
            }

            if (!FriendKey.ContainsKey(firend.Ritem.Jid.ToString()))
            {
                FriendControl friend = new FriendControl();
                friend.XmppConnection = XmppConn;

                friend.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Left) | AnchorStyles.Right)));
                friend.BackColor = this.BackColor;
                friend.Location = new Point(1, ItemHeight + 1 * this.Controls.Count);
                friend.Name = firend.Ritem.Jid.Bare;
                friend.Size = new Size(this.Width - 2, ItemHeight);
                friend.MJID = firend.Ritem.Jid;
                friend.FriendInfo = firend;
                friend.OpenChat += new CSS.IM.UI.Control.FriendControl.OpenChatEventHandler(friend_OpenChat);
                friend.UpdateImage();//更新头像信息
                Controls.Add(friend);
                FriendKey.Add(firend.Ritem.Jid.ToString(), firend);
                this.Height += (ItemHeight + 1);
            }

            System.GC.Collect();
        }
        public void AddFriendMessage(Jid jid, XmppClientConnection con, string nickname)
        {
            int UserCount = panel_userList.Controls.Count;

            //如果已经有此联系人的消息就不添加
            if (panel_userList.Controls.ContainsKey("FI" + jid.Bare.ToString()))
                return;

            Friend friend = new Friend();
            friend.NikeName = jid.User;
            friend.Description = "";//心情
            friend.HeadIMG = "big194";
            friend.IsSysHead = true;

            MiniFriendControl firneItem = new MiniFriendControl(con, jid);
            firneItem.FriendInfo = friend;
            firneItem.Height = 28;
            firneItem.Width = 210;
            firneItem.Name = "FI" + jid.Bare;
            firneItem.Location = new Point(0, UserCount * 28);
            firneItem.OpenChat += new MiniFriendControl.OpenChatEventHandler(firneItem_OpenChat);
            panel_userList.Controls.Add(firneItem);
            if (panel_userList.Controls.Count>10)
            {
                panel_userList.AutoScroll = true;
            }
            else
            {
                panel_userList.AutoScroll = false;
                if (UserCount * 28 > panel_userList.Height)
                {
                    oldPanle = panel_userList.Height;
                    panel_userList.Height = UserCount * 28;
                    this.Height = this.Height - oldPanle + panel_userList.Height;

                }
            }
        }
Example #3
0
        /// <summary>
        /// 查看联系人详细信息事件、删除、备注
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="item"></param>
        public void friendListView_friend_qcm_MouseClickEvent(object sender, Friend item, String type)
        {
            CSS.IM.XMPP.protocol.iq.roster.RosterItem ritem = friendListView.SelectedFriend.Ritem;

            switch (type)
            {
                case "vcar":
                    VcardForm vcardForm = new VcardForm(ritem.Jid, XmppCon);
                    try
                    {
                        vcardForm.Show();
                    }
                    catch (Exception)
                    {

                    }

                    break;
                case "chat":
                    if (!Util.ChatForms.ContainsKey(item.Ritem.Jid.ToString()))
                    {
                        try
                        {
                            ChatForm chat = new ChatForm(item.Ritem.Jid, XmppCon, item.NikeName);
                            chat.UpdateFriendOnline(item.IsOnline);//设置好友在线状态
                            chat.Show();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }

                    }
                    else
                    {
                        try
                        {
                            ChatForm chatform = Util.ChatForms[item.Ritem.Jid.ToString()] as ChatForm;
                            chatform.WindowState = FormWindowState.Normal;
                            chatform.Activate();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    break;
                case "dele":
                    Jid jid = item.Ritem.Jid;
                    Friend friend = new Friend();
                    friend.NikeName = item.Ritem.Jid.User;
                    friend.Description = "";//心情
                    friend.HeadIMG = "big1";
                    friend.IsSysHead = true;
                    friend.State = 1;

                    if (item.Ritem.GetGroups().Count > 0)
                    {
                        CSS.IM.XMPP.protocol.Base.Group g = (CSS.IM.XMPP.protocol.Base.Group)item.Ritem.GetGroups().Item(0);
                        int groupID = 0;

                        foreach (var groups in friendListView.Groups)
                        {
                            if (groups.Value.Title == g.Name)
                            {
                                groupID = groups.Value.Id;
                            }
                        }
                        //if (groupID == 0)
                        //{
                        //    friendListView.AddGroup(g.Name);
                        //    groupID = friendListView.Groups[g.Name].Id;
                        //    friendListView.UpdateLayout(3, groupID);

                        //}
                        friend.GroupID = groupID;
                        friend.GroupName = g.Name;
                    }
                    else
                    {
                        //离线联系人
                        Group group = friendListView.Groups["我的联系人"];
                        friend.GroupID = group.Id;
                        friend.GroupName = group.Title;
                    }
                    friend.Ritem = item.Ritem;
                    friend.IsOnline = false;

                    DialogResult msgResult=MsgBox.Show(this, "CSS&IM", "确认要删除联系人么?", MessageBoxButtons.YesNo);

                    if (msgResult==DialogResult.Yes)
                    {
                        friendListView.RemoveFriend(friend);

                        try
                        {
                            RosterIq riq = new RosterIq();
                            riq.Type = IqType.set;
                            XmppCon.RosterManager.RemoveRosterItem(jid);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    break;
                case "move":
                    MoveFriendGroup _MoveFriendGroup = new MoveFriendGroup();
                    Dictionary<string, Group> group_args = friendListView.Groups;
                    string[] strvalue = new string[group_args.Count];
                    int index = 0;
                    foreach (String keystr in group_args.Keys)
                    {
                        Group groupargs = group_args[keystr];
                        strvalue[index] = groupargs.Title;
                        index++;

                    }

                    _MoveFriendGroup.basicComboBox1.Items = strvalue;
                    _MoveFriendGroup.basicComboBox1.SelectIndex = 0;
                    DialogResult reslut = _MoveFriendGroup.ShowDialog();

                    String groupupdate = _MoveFriendGroup.basicComboBox1.SelectItem.ToString();

                    String name_move = friendListView.SelectedFriend.Ritem.Jid.User;
                    if (reslut == DialogResult.Yes)
                    {

                        foreach (String user_key in friendListView.Rosters.Keys)
                        {
                            if (friendListView.Rosters[user_key].Ritem.Jid.User == name_move)
                            {

                                Friend friend_old = friendListView.Rosters[user_key];
                                friendListView.RemoveFriend(friendListView.Rosters[user_key].Ritem.Jid.User);

                                Group fgroup = friendListView.Groups[groupupdate];
                                friend_old.GroupID = fgroup.Id;
                                friend_old.GroupName = fgroup.Title;

                                friendListView.AddFriend(friend_old);

                                friendListView.UpdateLayout(3, 0);
                                break;

                            }
                        }

                        CSS.IM.XMPP.protocol.Base.Group group_move = new CSS.IM.XMPP.protocol.Base.Group(groupupdate);
                        CSS.IM.XMPP.protocol.Base.Item item_move = new CSS.IM.XMPP.protocol.Base.Item();
                        item_move.Namespace = null;
                        item_move.AddChild(group_move);
                        item_move.SetAttribute("jid", friendListView.SelectedFriend.Ritem.Jid);
                        item_move.SetAttribute("subscripton", "from");

                        CSS.IM.XMPP.protocol.Base.Query query_move = new CSS.IM.XMPP.protocol.Base.Query();
                        query_move.Namespace = CSS.IM.XMPP.Uri.IQ_ROSTER;
                        query_move.AddChild(item_move);

                        IQ iq = new IQ(IqType.set);
                        iq.GenerateId();
                        iq.Namespace = null;
                        iq.AddChild(query_move);

                        XmppCon.IqGrabber.SendIq(iq);
                    }
                    break;
                case "g_dele":

                    break;
                case "remark":

                    //RemarkFriendGroup _RemarkFriendGroup = new RemarkFriendGroup();
                    //Dictionary<string, Group> group_args = friendListView.Groups;
                    //string[] strvalue = new string[group_args.Count];
                    //int index = 0;
                    //foreach (String keystr in group_args.Keys)
                    //{
                    //    Group groupargs = group_args[keystr];
                    //    strvalue[index] = groupargs.Title;
                    //    index++;

                    //}

                    //_MoveFriendGroup.basicComboBox1.Items = strvalue;
                    //_MoveFriendGroup.basicComboBox1.SelectIndex = 0;
                    //DialogResult reslut = _MoveFriendGroup.ShowDialog();

                    //String groupupdate = _MoveFriendGroup.basicComboBox1.SelectItem.ToString();

                    //String name_move = friendListView.SelectedFriend.Ritem.Jid.User;
                    //if (reslut == DialogResult.Yes)
                    //{

                    //    foreach (String user_key in friendListView.Rosters.Keys)
                    //    {
                    //        if (friendListView.Rosters[user_key].Ritem.Jid.User == name_move)
                    //        {

                    //            Friend friend_old = friendListView.Rosters[user_key];
                    //            friendListView.RemoveFriend(friendListView.Rosters[user_key].Ritem.Jid.User);

                    //            Group fgroup = friendListView.Groups[groupupdate];
                    //            friend_old.GroupID = fgroup.Id;
                    //            friend_old.GroupName = fgroup.Title;

                    //            friendListView.AddFriend(friend_old);

                    //            friendListView.UpdateLayout(3, 0);
                    //            break;

                    //        }
                    //    }

                    //    CSS.IM.XMPP.protocol.Base.Group group_move = new CSS.IM.XMPP.protocol.Base.Group(groupupdate);
                    //    CSS.IM.XMPP.protocol.Base.Item item_move = new CSS.IM.XMPP.protocol.Base.Item();
                    //    item_move.Namespace = null;
                    //    item_move.AddChild(group_move);
                    //    item_move.SetAttribute("jid", friendListView.SelectedFriend.Ritem.Jid);
                    //    item_move.SetAttribute("subscripton", "from");

                    //    CSS.IM.XMPP.protocol.Base.Query query_move = new CSS.IM.XMPP.protocol.Base.Query();
                    //    query_move.Namespace = CSS.IM.XMPP.Uri.IQ_ROSTER;
                    //    query_move.AddChild(item_move);

                    //    IQ iq = new IQ(IqType.set);
                    //    iq.GenerateId();
                    //    iq.Namespace = null;
                    //    iq.AddChild(query_move);

                    //    XmppCon.IqGrabber.SendIq(iq);
                    break;
                default:
                    break;
            }
        }
Example #4
0
        public void XmppCon_OnRosterItem(object sender, CSS.IM.XMPP.protocol.iq.roster.RosterItem item)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new CSS.IM.XMPP.XmppClientConnection.RosterHandler(XmppCon_OnRosterItem), new object[] { this, item });
                return;
            }
            if (item.Jid.User == null)
            {
                return;
            }
            if (item.Subscription != SubscriptionType.remove)
            {

                Friend friend = new Friend();
                friend.NikeName = item.Jid.User;
                friend.Description = "";//心情
                friend.HeadIMG = "big194";
                friend.IsSysHead = true;
                friend.State = 1;
                friend.NameRmark = Util.getFriendReamrk(item.Jid.User);

                if (item.GetGroups().Count > 0)
                {
                    CSS.IM.XMPP.protocol.Base.Group g = (CSS.IM.XMPP.protocol.Base.Group)item.GetGroups().Item(0);
                    int groupID = 0;

                    foreach (var groups in friendListView.Groups)
                    {
                        if (groups.Value.Title == g.Name)
                        {
                            groupID = groups.Value.Id;
                        }
                    }
                    if (groupID == 0)
                    {
                        friendListView.AddGroup(g.Name);
                        groupID = friendListView.Groups[g.Name].Id;
                        friendListView.UpdateLayout(3, groupID);

                    }
                    friend.GroupID = groupID;
                    friend.GroupName = g.Name;
                }
                else
                {
                    //离线联系人
                    Group group = friendListView.Groups["我的联系人"];
                    friend.GroupID = group.Id;
                    friend.GroupName = group.Title;

                    try
                    {
                        if (friendListView.Rosters.ContainsKey(friend.NikeName))
                            return;
                    }
                    catch (Exception)
                    {

                        //throw ex;
                    }

                }
                friend.Ritem = item;
                friend.IsOnline = false;

                try
                {
                    friendListView.AddFriend(friend);
                }
                catch (Exception)
                {

                    //throw ex;
                }

            }
            else
            {
                friendListView.RemoveFriend(item.Jid.User);
            }
        }
Example #5
0
        /// <summary>
        /// 状态头像更改
        /// </summary>
        /// <param name="friend"></param>
        private void ChangeInfo(Friend friend)
        {
            Bitmap state = null;
            Bitmap headMark = null;
            System.Drawing.Graphics grap = null;

            if (!FriendInfo.IsOnline)
            {
                headImg = null;
                headImg = ResClass.MarkTopHead(headImgbak);//制作黑白头像;
            }

            FriendInfo.State = friend.State;

            switch (friend.State)
            {
                case 0:
                    if (!FriendInfo.IsOnline)
                        break;
                    headImg = null;
                    headImg = new Bitmap(headImgbak);
                    break;
                case 1:
                    break;
                case 2:
                    if (!FriendInfo.IsOnline)
                        break;
                    state = new Bitmap(ResClass.GetImgRes("away"), new Size(11, 11));
                    headMark = new Bitmap(headImgbak,new Size(HeadWidth, HeadHeight));
                    grap = System.Drawing.Graphics.FromImage(headMark);
                    //grap.DrawImage(state, 28, 28);
                    grap.DrawImage(state, HeadWidth - 12, HeadHeight-12);

                    headImg = null;
                    headImg = new Bitmap(headMark, new Size(HeadWidth, HeadHeight));
                    break;
                case 3:
                    break;
                case 4:
                    if (!FriendInfo.IsOnline)
                        break;
                    state = new Bitmap(ResClass.GetImgRes("busy"), new Size(11, 11));
                    headMark = new Bitmap(headImgbak, new Size(HeadWidth, HeadHeight));
                    grap = System.Drawing.Graphics.FromImage(headMark);
                    //grap.DrawImage(state, 28, 28);
                    grap.DrawImage(state, HeadWidth - 12, HeadHeight-12);

                    headImg = null;
                    headImg = new Bitmap(headMark);
                    break;
                default:
                    if (!FriendInfo.IsOnline)
                        break;
                    headImg = null;
                    headImg = new Bitmap(headImgbak);
                    break;
            }

            if (state != null)
            {
                state.Dispose();
                state = null;
            }

            if (headMark != null)
            {
                headMark.Dispose();
                headMark = null;
            }

            if (grap != null)
            {
                grap.Dispose();
                grap = null;
            }

            System.GC.Collect();
        }
Example #6
0
        protected override void Dispose(bool disposing)
        {
            if (bgImg != null)
            {
                bgImg.Dispose();
                bgImg = null;
            }

            if (headImg != null)
            {
                headImg.Dispose();
                headImg = null;
            }
            if (headImgbak != null)
            {
                headImgbak.Dispose();
                headImgbak = null;
            }

            if (headBorder != null)
            {
                headBorder.Dispose();
                headBorder = null;
            }

            if (_friendInfo != null)
            {
                _friendInfo = null;
            }

            if (f != null)
            {
                f.Dispose();
                f = null;
            }

            if (timer_flicker != null)
            {
                timer_flicker.Enabled = false;
                timer_flicker.Dispose();
                timer_flicker = null;
            }

            if (g != null)
            {
                g.Dispose();
                g = null;
            }

            if (disposing && (components != null))
            {
                components.Dispose();
            }

            try
            {
                base.Dispose(disposing);
            }
            catch (System.Exception)
            {

            }
            System.GC.Collect();
        }
        public void AddFriend(Friend firend)
        {
            if (!Rosters.ContainsKey(firend.Ritem.Jid.Bare))
            {
                FriendControl friend = new FriendControl(XmppConn,firend.Ritem.Jid);
                friend.FCType = FCType;;
                friend.Location = new Point(1, (ItemHeight + 1) * this.Controls.Count);
                friend.Name = firend.Ritem.Jid.Bare;
                friend.Size = new Size(this.Width - 2, ItemHeight);
                friend.FriendInfo = firend;
                friend.OpenChat += new CSS.IM.UI.Control.FriendControl.OpenChatEventHandler(friend_OpenChat);
                friend.Selecting += new FriendControl.SelectedEventHandler(friend_Selecting);
                friend.UpdateImage();//更新头像信息
                Controls.Add(friend);
                Rosters.Add(firend.Ritem.Jid.Bare, firend);
                this.Height += (ItemHeight + 1);
            }

            System.GC.Collect();
        }
        void firneItem_OpenChat(Friend friend,Jid sender, string CName)
        {
            RosterItem ritem = new RosterItem(sender);
            friend.Ritem = ritem;
            if (panel_userList.Controls.ContainsKey("FI" + friend.Ritem.Jid.Bare))
            {
                panel_userList.Controls.RemoveByKey(CName);
                UpdateControls();

                if (OpenChatEvent != null)
                {
                    OpenChatEvent(friend, sender, CName);
                }
            }
            Debug.WriteLine("打开:"+sender.ToString());
        }
Example #9
0
 private void friend_Selecting(Friend sender)
 {
     SelectedFriend = sender;
 }
Example #10
0
        public int addFriend(Friend item)
        {
            FriendID += 1;
            int groupid = item.GroupID;
            item.Uin = FriendID;

            int panel_index=Controls.IndexOfKey(StringFinal.UserPanelName + groupid);
            int group_index = Controls.IndexOfKey(StringFinal.GroupName + groupid);

            Panel panel_user = Controls[panel_index] as Panel;
            GroupControl gruop_user = Controls[group_index] as GroupControl;

            gruop_user.GroupInfo.Count++;//好友总数
            //gruop_user.GroupInfo.OnlineCount++;//在线好友
            m_Roster.Add(item.NikeName, item);
            FriendControl friend = new FriendControl();
            friend.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Left) | AnchorStyles.Right)));
            friend.BackColor = this.BackColor;
            friend.Location = new Point(1, 56 * panel_user.Controls.Count);
            friend.Name = "friend_" + item.Uin;
            friend.Size = new Size(panel_user.Width - 2, 55);
            friend.FriendInfo = item;
            friend.Selecting += new FriendControl.SelectedEventHandler(friend_Selecting);
            friend.ShowContextMenu += new FriendControl.ShowContextMenuEventHandler(friend_ShowContextMenu);
            friend.MouseDoubleClick += new MouseEventHandler(friend_MouseDoubleClick);

            panel_user.Controls.Add(friend);
            System.Diagnostics.Debug.WriteLine("count:"+panel_user.Controls.Count);
            //panel_user.Controls.Add(item);
            panel_user.Height += 56;

            //if (item.State != 0 && item.State != 5)
            //{
            //    cGroup.GroupInfo.OnlineCount++;
            //}
            //friendInfo.GroupID = groups[i].Id;

            return 0;
        }
        protected override void Dispose(bool disposing)
        {
            if (bgImg != null)
            {
                bgImg.Dispose();
                bgImg = null;
            }

            if (headImg != null)
            {
                headImg.Dispose();
                headImg = null;
            }

            if (headBorder != null)
            {
                headBorder.Dispose();
                headBorder = null;
            }

            if (HeadBmp != null)
            {
                HeadBmp.Dispose();
                HeadBmp = null;
            }

            if (_friendInfo != null)
            {
                _friendInfo = null;
            }

            if (f != null)
            {
                f.Dispose();
                f = null;
            }

            if (g != null)
            {
                g.Dispose();
                g = null;
            }

            try
            {
                base.Dispose(disposing);
            }
            catch (System.Exception)
            {

            }
            System.GC.Collect();
        }
Example #12
0
        /// <summary>
        /// 聊天窗口打开事件
        /// </summary>
        /// <param name="sender"></param>
        public void listView_fd_OpenChatEvent(Friend sender)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new QQListViewEx.delegate_openChat(listView_fd_OpenChatEvent), new object[] { sender });
                return;
            }

            System.GC.Collect();

            //for (int i = 0; i < 50; i++)
            //{
            //    ChatFromMsg chat = new ChatFromMsg(sender.Ritem.Jid, XmppCon);
            //    chat.Show();
            //}

            if (!Util.ChatForms.ContainsKey(sender.Ritem.Jid.Bare))
            {
                try
                {
                    string nickName = listView_fd.GetFriendNickName(sender.Ritem.Jid.Bare);
                    ChatFromMsg chat = new ChatFromMsg(sender.Ritem.Jid, XmppCon, nickName);
                    chat.UpdateFriendOnline(sender.IsOnline);//设置好友在线状态
                    ChatMessageBox.GetInstance(this).RemoveFriend(sender.Ritem.Jid);
                    if (msgBox.ContainsKey(sender.Ritem.Jid.ToString()))
                    {
                        chat.FristMessage(msgBox[sender.Ritem.Jid.ToString()]);
                        msgBox.Remove(sender.Ritem.Jid.ToString());
                    }
                    chat.Show();
                    if (ChatMessageBox.GetInstance(this).FrienMessageCount() > 0)
                        Debug.WriteLine("?");
                    else
                    {
                        notifyIcon_MessageQueue.Icon = CSS.IM.UI.Properties.Resources.Iico;
                        timer_MessageAlert.Enabled = false;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

            }
            else
            {
                try
                {
                    ChatFromMsg chatform = Util.ChatForms[sender.Ritem.Jid.Bare] as ChatFromMsg;
                    chatform.WindowState = FormWindowState.Normal;
                    chatform.Activate();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            System.GC.Collect();
        }
Example #13
0
        /// <summary>
        /// 查看联系人详细信息事件、删除、备注
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="item"></param>
        public void listView_fd_friend_qcm_MouseClickEvent(object sender, Friend item, String type)
        {
            CSS.IM.XMPP.protocol.iq.roster.RosterItem ritem = null;

            if (listView_fd.SelectFriend!=null)
            {
                ritem = listView_fd.SelectFriend.Ritem;
            }

            Document doc_setting = new Document();
            Settings.Settings config = new Settings.Settings();
            Settings.Paths path = null;

            switch (type)
            {
                case "vcar":
                    if (vcardForm == null || vcardForm.IsDisposed)
                    {
                        vcardForm = new VcardInfoForm(ritem.Jid, XmppCon);
                    }
                    vcardForm.Show();
                    vcardForm.Activate();

                    break;
                case "chat":
                    if (!Util.ChatForms.ContainsKey(item.Ritem.Jid.Bare))
                    {
                        try
                        {
                            string nickName = listView_fd.GetFriendNickName(item.Ritem.Jid.Bare);
                            ChatFromMsg chat = new ChatFromMsg(item.Ritem.Jid, XmppCon, nickName);
                            chat.UpdateFriendOnline(item.IsOnline);//设置好友在线状态
                            chat.Show();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }

                    }
                    else
                    {
                        try
                        {
                            ChatFromMsg chatform = Util.ChatForms[item.Ritem.Jid.Bare] as ChatFromMsg;
                            chatform.WindowState = FormWindowState.Normal;
                            chatform.Activate();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    break;
                case "dele":
                    Jid jid = item.Ritem.Jid;
                    Friend friend = new Friend();
                    friend.NikeName = item.Ritem.Jid.User;
                    friend.Description = "";//心情
                    friend.HeadIMG = "big1";
                    friend.IsSysHead = true;
                    friend.State = 1;

                    if (item.Ritem.GetGroups().Count > 0)
                    {
                        CSS.IM.XMPP.protocol.Base.Group g = (CSS.IM.XMPP.protocol.Base.Group)item.Ritem.GetGroups().Item(0);
                        int groupID = 0;

                        foreach (var groups in listView_fd.Groups)
                        {
                            if (groups.Value.Title == g.Name)
                            {
                                groupID = groups.Value.Id;
                            }
                        }
                        //if (groupID == 0)
                        //{
                        //    friendListView.AddGroup(g.Name);
                        //    groupID = friendListView.Groups[g.Name].Id;
                        //    friendListView.UpdateLayout(3, groupID);

                        //}
                        friend.GroupID = groupID;
                        friend.GroupName = g.Name;
                    }
                    else
                    {
                        //离线联系人
                        Group group = listView_fd.Groups["我的联系人"];
                        friend.GroupID = group.Id;
                        friend.GroupName = group.Title;
                    }
                    friend.Ritem = item.Ritem;
                    friend.IsOnline = false;

                    DialogResult msgResult = MsgBox.Show(this, "CSS&IM", "确认要删除联系人么?", MessageBoxButtons.YesNo);

                    if (msgResult == DialogResult.Yes)
                    {
                        listView_fd.RemoveFriend(friend);

                        try
                        {
                            RosterIq riq = new RosterIq();
                            riq.Type = IqType.set;
                            XmppCon.RosterManager.RemoveRosterItem(jid);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    break;
                case "move":

                    if (moveFriendGroup == null || moveFriendGroup.IsDisposed)
                    {
                        moveFriendGroup = new MoveFriendGroup();
                    }
                    Dictionary<string, Group> group_args = listView_fd.Groups;
                    string[] strvalue = new string[group_args.Count];
                    int index = 0;
                    foreach (String keystr in group_args.Keys)
                    {
                        Group groupargs = group_args[keystr];
                        strvalue[index] = groupargs.Title;
                        index++;

                    }

                    moveFriendGroup.basicComboBox1.Items = strvalue;
                    moveFriendGroup.basicComboBox1.SelectIndex = 0;
                    DialogResult reslut = moveFriendGroup.ShowDialog();

                    String groupupdate = moveFriendGroup.basicComboBox1.SelectItem.ToString();

                    String Bare_move = listView_fd.SelectFriend.Ritem.Jid.Bare;
                    if (reslut == DialogResult.Yes)
                    {

                        foreach (String user_key in listView_fd.Rosters.Keys)
                        {
                            if (listView_fd.Rosters[user_key].Ritem.Jid.Bare == Bare_move)
                            {

                                Friend friend_old = listView_fd.Rosters[user_key];
                                listView_fd.RemoveFriend(listView_fd.Rosters[user_key].Ritem.Jid.Bare);

                                Group fgroup = listView_fd.Groups[groupupdate];
                                friend_old.GroupID = fgroup.Id;
                                friend_old.GroupName = fgroup.Title;

                                listView_fd.AddFriend(friend_old);
                                listView_fd.RefreshGroup();
                                break;

                            }
                        }

                        CSS.IM.XMPP.protocol.Base.Group group_move = new CSS.IM.XMPP.protocol.Base.Group(groupupdate);
                        CSS.IM.XMPP.protocol.Base.Item item_move = new CSS.IM.XMPP.protocol.Base.Item();
                        item_move.Namespace = null;
                        item_move.AddChild(group_move);
                        item_move.SetAttribute("jid", listView_fd.SelectFriend.Ritem.Jid);
                        item_move.SetAttribute("subscripton", "from");

                        CSS.IM.XMPP.protocol.Base.Query query_move = new CSS.IM.XMPP.protocol.Base.Query();
                        query_move.Namespace = CSS.IM.XMPP.Uri.IQ_ROSTER;
                        query_move.AddChild(item_move);

                        IQ iq = new IQ(IqType.set);
                        iq.GenerateId();
                        iq.Namespace = null;
                        iq.AddChild(query_move);

                        XmppCon.IqGrabber.SendIq(iq);

                    }
                    break;
                case "g_dele":

                    break;
                case "remark":

                    //RemarkFriendGroup _RemarkFriendGroup = new RemarkFriendGroup();
                    //Dictionary<string, Group> group_args = friendListView.Groups;
                    //string[] strvalue = new string[group_args.Count];
                    //int index = 0;
                    //foreach (String keystr in group_args.Keys)
                    //{
                    //    Group groupargs = group_args[keystr];
                    //    strvalue[index] = groupargs.Title;
                    //    index++;

                    //}

                    //_MoveFriendGroup.basicComboBox1.Items = strvalue;
                    //_MoveFriendGroup.basicComboBox1.SelectIndex = 0;
                    //DialogResult reslut = _MoveFriendGroup.ShowDialog();

                    //String groupupdate = _MoveFriendGroup.basicComboBox1.SelectItem.ToString();

                    //String name_move = friendListView.SelectedFriend.Ritem.Jid.User;
                    //if (reslut == DialogResult.Yes)
                    //{

                    //    foreach (String user_key in friendListView.Rosters.Keys)
                    //    {
                    //        if (friendListView.Rosters[user_key].Ritem.Jid.User == name_move)
                    //        {

                    //            Friend friend_old = friendListView.Rosters[user_key];
                    //            friendListView.RemoveFriend(friendListView.Rosters[user_key].Ritem.Jid.User);

                    //            Group fgroup = friendListView.Groups[groupupdate];
                    //            friend_old.GroupID = fgroup.Id;
                    //            friend_old.GroupName = fgroup.Title;

                    //            friendListView.AddFriend(friend_old);

                    //            friendListView.UpdateLayout(3, 0);
                    //            break;

                    //        }
                    //    }

                    //    CSS.IM.XMPP.protocol.Base.Group group_move = new CSS.IM.XMPP.protocol.Base.Group(groupupdate);
                    //    CSS.IM.XMPP.protocol.Base.Item item_move = new CSS.IM.XMPP.protocol.Base.Item();
                    //    item_move.Namespace = null;
                    //    item_move.AddChild(group_move);
                    //    item_move.SetAttribute("jid", friendListView.SelectedFriend.Ritem.Jid);
                    //    item_move.SetAttribute("subscripton", "from");

                    //    CSS.IM.XMPP.protocol.Base.Query query_move = new CSS.IM.XMPP.protocol.Base.Query();
                    //    query_move.Namespace = CSS.IM.XMPP.Uri.IQ_ROSTER;
                    //    query_move.AddChild(item_move);

                    //    IQ iq = new IQ(IqType.set);
                    //    iq.GenerateId();
                    //    iq.Namespace = null;
                    //    iq.AddChild(query_move);

                    //    XmppCon.IqGrabber.SendIq(iq);
                    break;
                case "HeadSmall":
                    //listView_fd.FCType = FriendContainerType.Small;
                    CSS.IM.UI.Util.Path.FriendContainerType = false;
                    doc_setting.LoadFile(string.Format(CSS.IM.UI.Util.Path.ConfigFilename, Program.UserName));
                    path = doc_setting.RootElement.SelectSingleElement(typeof(Settings.Paths),false) as Settings.Paths;
                    path.FriendContainerType = CSS.IM.UI.Util.Path.FriendContainerType;
                    config.Paths = path;
                    config.Font = doc_setting.RootElement.SelectSingleElement(typeof(Settings.SFont), false) as Settings.SFont;
                    config.Color = doc_setting.RootElement.SelectSingleElement(typeof(Settings.SColor), false) as Settings.SColor;

                    doc_setting.Clear();
                    doc_setting.ChildNodes.Add(config);

                    try
                    {
                        doc_setting.Save(string.Format(CSS.IM.UI.Util.Path.ConfigFilename, Program.UserName));
                    }
                    catch (Exception)
                    {

                    }

                    listView_fd.FCType = CSS.IM.UI.Util.Path.FriendContainerType == true ? FriendContainerType.Big : FriendContainerType.Small;
                    chatHistory_lt.FCType = listView_fd.FCType;
                    listView_gp.FCType = listView_fd.FCType;
                    break;
                case "HeadBig":
                    //listView_fd.FCType = FriendContainerType.Small;
                    CSS.IM.UI.Util.Path.FriendContainerType = true;
                    doc_setting.LoadFile(string.Format(CSS.IM.UI.Util.Path.ConfigFilename, Program.UserName));
                    path = doc_setting.RootElement.SelectSingleElement(typeof(Settings.Paths),false) as Settings.Paths;
                    path.FriendContainerType = CSS.IM.UI.Util.Path.FriendContainerType;
                    config.Paths = path;
                    config.Font = doc_setting.RootElement.SelectSingleElement(typeof(Settings.SFont), false) as Settings.SFont;
                    config.Color = doc_setting.RootElement.SelectSingleElement(typeof(Settings.SColor), false) as Settings.SColor;

                    doc_setting.Clear();
                    doc_setting.ChildNodes.Add(config);
                    try
                    {
                        doc_setting.Save(string.Format(CSS.IM.UI.Util.Path.ConfigFilename, Program.UserName));
                    }
                    catch (Exception)
                    {

                    }
                    listView_fd.FCType = CSS.IM.UI.Util.Path.FriendContainerType == true ? FriendContainerType.Big : FriendContainerType.Small;
                    chatHistory_lt.FCType = listView_fd.FCType;
                    listView_gp.FCType = listView_fd.FCType;
                    break;
                default:
                    break;
            }
        }
 protected override void OnMouseDoubleClick(MouseEventArgs e)
 {
     base.OnMouseDoubleClick(e);
     if (e.Button == MouseButtons.Left)
     {
         if (!IsSelected)
         {
             bgImg = ResClass.GetImgRes("friendTitleOpenbg");
             headBorder = ResClass.GetImgRes("Padding4Press");
             this.Invalidate();
         }
         if (OpenChat != null)
         {
             Friend friendinfo = new Friend();
             CSS.IM.XMPP.protocol.iq.roster.RosterItem Ritem = new XMPP.protocol.iq.roster.RosterItem();
             Ritem.Jid = MJid;
             friendinfo.Ritem = Ritem;
             OpenChat(friendinfo, NickName);
             x = 8; y = 8;
             this.Invalidate();
         }
     }
     System.GC.Collect();
 }
Example #15
0
        /// <summary>
        /// 通过消息盒子打开消息窗体
        /// </summary>
        /// <param name="friend"></param>
        /// <param name="sender"></param>
        /// <param name="CName"></param>
        void QQMainForm_OpenChatEvent(Friend friend, Jid sender, string CName)
        {
            RosterItem ritem = new RosterItem(sender);
            friend.Ritem = ritem;
            //throw new NotImplementedException();
            //friendListView_OpenChatEvent(friend);
            if (!Util.ChatForms.ContainsKey(friend.Ritem.Jid.Bare.ToString()))
            {
                friendListView.UpdateFriendFlicker(friend.NikeName);
                ChatForm chat = new ChatForm(friend.Ritem.Jid, XmppCon, friend.NikeName);

                Friend flfriend = friendListView.Rosters[friend.NikeName];
                if (flfriend!=null)
                {
                    chat.UpdateFriendOnline(flfriend.IsOnline);
                }

                if (msgBox.ContainsKey(friend.Ritem.Jid.Bare.ToString()))
                {
                    chat.FristMessage(msgBox[friend.Ritem.Jid.Bare.ToString()]);
                    msgBox.Remove(friend.Ritem.Jid.Bare.ToString());
                }
                chat.Show();
            }
            else
            {
                try
                {
                    ChatForm chatform = Util.ChatForms[friend.Ritem.Jid.ToString()] as ChatForm;
                    chatform.WindowState = FormWindowState.Normal;
                    chatform.Activate();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            if (ChatMessageBox.GetInstance(this).FrienMessageCount() > 0)
                Debug.WriteLine("?");
            else
            {
                notifyIcon1.Icon = CSS.IM.UI.Properties.Resources.Iico;
                timer_notifyIco.Enabled = false;
            }
        }
Example #16
0
        /// <summary>
        /// 聊天窗口打开事件
        /// </summary>
        /// <param name="sender"></param>
        public void friendListView_OpenChatEvent(Friend sender)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new QQListViewEx.delegate_openChat(friendListView_OpenChatEvent), new object[] { sender });
                return;
            }

            if (!Util.ChatForms.ContainsKey(sender.Ritem.Jid.ToString()))
            {
                try
                {

                    ChatForm chat = new ChatForm(sender.Ritem.Jid, XmppCon, sender.NikeName);
                    chat.UpdateFriendOnline(sender.IsOnline);//设置好友在线状态

                    ChatMessageBox.GetInstance(this).RemoveFriend(sender.Ritem.Jid);
                    if (msgBox.ContainsKey(sender.Ritem.Jid.ToString()))
                    {
                        chat.FristMessage(msgBox[sender.Ritem.Jid.ToString()]);
                        msgBox.Remove(sender.Ritem.Jid.ToString());
                    }
                    chat.Show();

                    if (ChatMessageBox.GetInstance(this).FrienMessageCount() > 0)
                        Debug.WriteLine("?");
                    else
                    {
                        notifyIcon1.Icon = CSS.IM.UI.Properties.Resources.Iico;
                        timer_notifyIco.Enabled = false;
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

            }
            else
            {
                try
                {
                    ChatForm chatform = Util.ChatForms[sender.Ritem.Jid.ToString()] as ChatForm;
                    chatform.WindowState = FormWindowState.Normal;
                    chatform.Activate();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #17
0
 public void AddFriend(Friend item)
 {
     lock (AddFriendLock)
     {
         int panel_index = Controls.IndexOfKey(StringFinal.UserPanelName + item.GroupID);
         Group group_item = Groups[item.GroupName];
         int group_index = Controls.IndexOfKey(StringFinal.GroupName + item.GroupID);
         friendIndex += 1;
         item.Uin = friendIndex;
         Panel panel_user = Controls[panel_index] as Panel;
         GroupControl gruop_user = Controls[group_index] as GroupControl;
         if (!Rosters.ContainsKey(item.Ritem.Jid.Bare))
         {
             group_item.Count += 1;
         }
         if (item.IsOnline)
         {
             group_item.OnlineCount += 1;
         }
         gruop_user.GroupInfo = group_item;//好友总数
         Rosters.Add(item.Ritem.Jid.Bare, item);
         FriendControl friend = new FriendControl(XmppConn, item.Ritem.Jid);
         friend.FCType = FriendContainerType.Small;
         friend.Location = new Point(1, ItemHeight + 1 * panel_user.Controls.Count);
         friend.Name = StringFinal.FriendName + item.Uin;
         friend.Size = new Size(panel_user.Width - 2, ItemHeight);
         friend.FriendInfo = item;
         friend.Selecting += new FriendControl.SelectedEventHandler(friend_Selecting);
         friend.ShowContextMenu += new FriendControl.ShowContextMenuEventHandler(friend_ShowContextMenu);
         friend.OpenChat += new FriendControl.OpenChatEventHandler(friend_OpenChat);
         friend.UpdateImage();//更新头像信息
         panel_user.Controls.Add(friend);
         panel_user.Height += (ItemHeight + 1);
         UpdateLayout(3, 0);
         //UpdateLayout(1, group_item.Id);
     }
 }
Example #18
0
        public void RemoveFriend(Friend item)
        {
            lock (RemoveFriendLock)
            {
                Friend friend = Rosters[item.Ritem.Jid.Bare];
                Group group_item = Groups[friend.GroupName];

                int group_index = Controls.IndexOfKey(StringFinal.GroupName + friend.GroupID);
                int panel_index = Controls.IndexOfKey(StringFinal.UserPanelName + friend.GroupID);

                group_item.Count -= 1;

                if (friend.IsOnline)
                {
                    group_item.OnlineCount -= 1;
                }

                Panel panel_user = Controls[panel_index] as Panel;
                GroupControl gruop_user = Controls[group_index] as GroupControl;

                gruop_user.GroupInfo = group_item;//好友总数
                panel_user.Controls.RemoveAt(panel_user.Controls.IndexOfKey(StringFinal.FriendName + friend.Uin));
                Rosters.Remove(item.Ritem.Jid.Bare);

                UpdateLayout(panel_user);
                UpdateLayout(3, 0);
                System.GC.Collect();
            }
        }
Example #19
0
 private void friend_OpenChat(Friend sender)
 {
     if (OpenChatEvent != null)
         OpenChatEvent(sender);
     System.GC.Collect();
 }
 public void friend_Selecting(Friend sender)
 {
     SelectFriend = sender;
     System.GC.Collect();
 }
        private void ChangeInfo(Friend friend, bool isX)
        {
            #region 制作黑白色的头像
            Bitmap OldHeadImg = null;
            if (isX)
            {
                OldHeadImg = ResClass.GetHead(friend.HeadIMG);
            }
            else
            {
                try
                {
                    OldHeadImg = new Bitmap(headImgbak);
                }
                catch (Exception)
                {
                    OldHeadImg = ResClass.GetHead(friend.HeadIMG);
                }

            }

            try
            {
                int Height = OldHeadImg.Height;
                int Width = OldHeadImg.Width;
                if (!FriendInfo.IsOnline)
                {
                    headImg = new Bitmap(Width, Height);
                    Color pixel;
                    for (int x = 0; x < Width; x++)
                        for (int y = 0; y < Height; y++)
                        {
                            pixel = OldHeadImg.GetPixel(x, y);
                            int r, g, b, Result = 0;
                            r = pixel.R;
                            g = pixel.G;
                            b = pixel.B;
                            //实例程序以加权平均值法产生黑白图像
                            int iType = 2;
                            switch (iType)
                            {
                                case 0://平均值法
                                    Result = ((r + g + b) / 3);
                                    break;
                                case 1://最大值法
                                    Result = r > g ? r : g;
                                    Result = Result > b ? Result : b;
                                    break;
                                case 2://加权平均值法
                                    Result = ((int)(0.7 * r) + (int)(0.2 * g) + (int)(0.1 * b));
                                    break;
                            }
                            headImg.SetPixel(x, y, Color.FromArgb(Result, Result, Result));
                        }

                }
                else
                {
                    headImg = new Bitmap(headImgbak);
                }
            }
            catch (Exception) { }
            #endregion

            Bitmap state = null;
            Bitmap headMark = null;
            System.Drawing.Graphics grap = null;
            switch (friend.State)
            {
                case 0:
                    if (!FriendInfo.IsOnline)
                        break;
                    headImg = new Bitmap(headImgbak);
                    break;
                case 1:
                    break;
                case 2:
                    if (!FriendInfo.IsOnline)
                        break;
                    state = new Bitmap(ResClass.GetImgRes("away"), new Size(11, 11));
                    headMark = headImg;
                    grap = System.Drawing.Graphics.FromImage(headMark);
                    grap.DrawImage(state, 28, 28);
                    headImg = headMark;
                    break;
                case 3:
                    break;
                case 4:
                    if (!FriendInfo.IsOnline)
                        break;
                    state = new Bitmap(ResClass.GetImgRes("busy"), new Size(11, 11));
                    headMark = headImg;
                    grap = System.Drawing.Graphics.FromImage(headMark);
                    grap.DrawImage(state, 28, 28);
                    headImg = headMark;
                    break;
                default:
                    if (!FriendInfo.IsOnline)
                        break;
                    headImg = new Bitmap(headImgbak);
                    break;
            }
            System.GC.Collect();
        }