/// <summary> /// 将P2PChatClient与新建的FormGroup互相绑定 /// </summary> /// <param name="p2pClient"></param> /// <param name="targetName">发起方的用户名</param> /// <param name="targetNames">群聊的好友列表</param> public void SetGroupFormClient(P2PGroupClient p2pClient, string targetName, string[] targetNames) { FormGroup fg = new FormGroup(this, targetNames); formGroups.Add(fg); fg.SetHandlerForSocket(p2pClient, targetName); }
/// <summary> /// 将P2PGroupClient与FormGroup绑定 /// </summary> /// <param name="owner">拥有它的群聊窗口</param> public void SetOwner(FormGroup owner) { if (this.owner != null) { throw new Exception("P2PGroupClient.SetOwner只允许调用一次。"); } this.owner = owner; }
/// <summary> /// 开始对话,如果已经打开对话框则跳转 /// </summary> protected void StartChatting() { // 选中的好友数 int count = listViewFriends.SelectedItems.Count; if (count == 1) // 私聊 { string key = listViewFriends.SelectedItems[0].Text; if (!formChats.ContainsKey(key)) { formChats.Add(key, new FormChat(this, key)); } else if (formChats[key].Disposing || formChats[key].IsDisposed) { formChats.Remove(key); formChats.Add(key, new FormChat(this, key)); } formChats[key].Show(); } else if (count > 1) // 群聊 { string[] keys = new string[count]; // 保证自己在列表内 bool contained = false; for (int i = 0; i < count; i++) { keys[i] = listViewFriends.SelectedItems[i].Text; if (keys[i] == MyName) { contained = true; } } if (!contained) { string[] tmp = keys; keys = new string[count + 1]; keys[0] = MyName; for (int i = 1; i < count + 1; i++) { keys[i] = tmp[i - 1]; } } FormGroup fg = new FormGroup(this, keys); formGroups.Add(fg); foreach (ListViewItem lvi in listViewFriends.SelectedItems) { if (lvi.ImageIndex == 0) // 不在线 { fg.OnLogoffRefresh(lvi.Text); } else // 在线 { fg.OnLoginRefresh(lvi.Text); } } fg.Show(); } }
/// <summary> /// 由主窗体来打开指定的FormGroup /// </summary> /// <param name="formGroup">要打开的FormGroup</param> public void OnShowFormGroup(FormGroup formGroup) { formGroup.Show(); }
/// <summary> /// 构造函数,主动连接时 /// </summary> /// <param name="main">主窗体</param> /// <param name="owner">聊天窗口</param> /// <param name="targetName">要连接的用户名</param> public P2PGroupClient(FormMain main, FormGroup owner, string targetName) { this.main = main; this.owner = owner; this.targetName = targetName; }