/// <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; } }
private void OnRegistrationFieldsResult(object sender, IQ iq, object data) { if (iq.Type != IqType.error) { if (iq.Query != null && iq.Query.GetType() == typeof(Register)) { RegisterEventArgs args = new RegisterEventArgs(iq.Query as Register); if (OnRegisterInformation != null) OnRegisterInformation(this, args); DoChangeXmppConnectionState(XmppConnectionState.Registering); IQ regIq = new IQ(IqType.set); regIq.GenerateId(); regIq.To = new Jid(base.Server); //RegisterIq regIq = new RegisterIq(IqType.set, new Jid(base.Server)); if (args.Auto) { Register reg = new Register(this.m_Username, this.m_Password); regIq.Query = reg; } else { regIq.Query = args.Register; } IqGrabber.SendIq(regIq, new IqCB(OnRegisterResult), data); } } else { if (OnRegisterError != null) OnRegisterError(this, iq); } }
/// <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; } }
private void OnGetAuthInfo(object sender, IQ iq, object data) { // We get smth like this and should add password (digest) and ressource // Recv:<iq type="result" id="MX_7"><query xmlns="jabber:iq:auth"><username>gnauck</username><password/><digest/><resource/></query></iq> // Send:<iq type='set' id='mx_login'> // <query xmlns='jabber:iq:auth'><username>gnauck</username><digest>27c05d464e3f908db3b2ca1729674bfddb28daf2</digest><resource>Office</resource></query> // </iq> // Recv:<iq id="mx_login" type="result"/> iq.GenerateId(); iq.SwitchDirection(); iq.Type = IqType.set; Auth auth = (Auth) iq.Query; auth.Resource = this.m_Resource; auth.SetAuth(this.m_Username, this.m_Password, this.StreamId); IqGrabber.SendIq(iq, new IqCB(OnAuthenticate), null); }