📄 psblacklist.cs
字号:
namespace Imps.Client.Pc.Options
{
using Imps.Client.Core;
using Imps.Client.Pc;
using Imps.Client.Pc.BizControls;
using Imps.Client.Pc.Controls;
using Imps.Client.Resource;
using Imps.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
public class PsBlackList : OptionsControlBase
{
private List<Imps.Client.Core.Contact> _contacts;
private IFrameworkWindow _iFrameworkWindow;
private BlackListAddForm blackListAddForm;
private XButton btnRemove;
private IContainer components;
private GroupBox groupBox1;
private XLabel lbBlackListTips;
private listbox_widget_t<headicon> lsBlackList;
private int selIndex;
private XButton xbAdd;
public PsBlackList() : this(null)
{
}
public PsBlackList(IFrameworkWindow frmWnd)
{
this._iFrameworkWindow = frmWnd;
this.InitializeComponent();
this.InitializeCustomComponent();
headiconlist_drawer _drawer = new headiconlist_drawer();
_drawer.stretch_textarea = true;
_drawer.noicon_string_alignment = StringAlignment.Near;
_drawer.item_height = 20;
this.lsBlackList.drawer = _drawer;
this.LoadResource();
this.lsBlackList.Items.Clear();
}
private void BlackList_Changed(object sender, EventArgs e)
{
this.displayBlackList();
}
private void btnRemove_Click(object sender, EventArgs e)
{
try
{
int selectedIndex = this.lsBlackList.SelectedIndex;
if ((selectedIndex > -1) && (this._contacts != null))
{
this.selIndex = selectedIndex;
Imps.Client.Core.Contact contact = this._contacts.get_Item(this.lsBlackList.SelectedIndex);
AsyncBizOperation op = new AsyncBizOperation();
this._user.ContactList.AsyncRemoveFromBlackList(new string[] { contact.Uri.Raw }, op);
}
}
catch
{
}
}
private void ClearContacts()
{
if (this._contacts != null)
{
List<Imps.Client.Core.Contact>.Enumerator enumerator = this._contacts.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
enumerator.get_Current().PersonalInfo.PropertiesChanged -= new EventHandler<PropertiesChangedEventArgs>(this, (IntPtr) this.PersonalInfo_PropertiesChanged);
}
}
finally
{
enumerator.Dispose();
}
this._contacts = null;
}
}
public override bool ControlLoad()
{
this._user.BlackList.Changed += new EventHandler(this.BlackList_Changed);
return true;
}
public override bool ControlUnload()
{
this._user.BlackList.Changed -= new EventHandler(this.BlackList_Changed);
this.ClearContacts();
return base.ControlUnload();
}
private void displayBlackList()
{
this.lsBlackList.Items.Clear();
this.ClearContacts();
this._contacts = new List<Imps.Client.Core.Contact>();
ContactCollection contacts = new ContactCollection();
lock (this._user.BlackList.SyncRoot)
{
using (IEnumerator<IicUri> enumerator = this._user.BlackList.GetEnumerator())
{
while (enumerator.MoveNext())
{
IicUri uri = enumerator.get_Current();
Imps.Client.Core.Contact item = this._user.ContactList.FindOrCreateContact(uri.Raw, new AsyncBizOperation());
item.PersonalInfo.PropertiesChanged += new EventHandler<PropertiesChangedEventArgs>(this, (IntPtr) this.PersonalInfo_PropertiesChanged);
this._contacts.Add(item);
contacts.Add(item);
}
}
}
AsyncBizOperation op = new AsyncBizOperation();
op.IsImpsErrorHandled = true;
this._user.ContactList.AsyncGetContactsInfo(contacts, op, null, false, new string[] { "nickname" });
this.lsBlackList.BeginUpdate();
if (this._contacts != null)
{
List<Imps.Client.Core.Contact>.Enumerator enumerator2 = this._contacts.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
Imps.Client.Core.Contact contact = enumerator2.get_Current();
string text = this.getDisplayString(contact);
this.lsBlackList.add(new headicon(null, text, text));
}
}
finally
{
enumerator2.Dispose();
}
}
this.lsBlackList.EndUpdate();
if (this.selIndex > 0)
{
this.lsBlackList.SelectedIndex = --this.selIndex;
}
else if (this.lsBlackList.Items.Count > 0)
{
this.lsBlackList.SelectedIndex = 0;
}
this.btnRemove.Enabled = this.lsBlackList.Items.Count > 0;
}
protected override void Dispose(bool disposing)
{
if (this.blackListAddForm != null)
{
this.blackListAddForm.Dispose();
this.blackListAddForm = null;
}
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private string getDisplayString(Imps.Client.Core.Contact contact)
{
if (contact.Type != ContactType.Stranger)
{
if (contact.Type == ContactType.Buddy)
{
return (contact.DisplayName + string.Format(StringTable.BlackList.BuddyTitle, contact.Uri.Sid));
}
if (contact.Type == ContactType.MobileBuddy)
{
return (contact.DisplayName + string.Format(StringTable.BlackList.MobileBuddyTitle, contact.PersonalInfo.MobileNo));
}
if (contact.Type == ContactType.Vodafone)
{
return (contact.DisplayName + string.Format(StringTable.BlackList.VodafoneTitle, contact.Uri.Id));
}
}
else
{
if (contact.Uri.IsImpsContactUri)
{
if (contact.Uri.Belongs(IicUriType.ImpsContactSip))
{
return (contact.DisplayName + string.Format(StringTable.BlackList.ImpsContactTitle, contact.Uri.Sid));
}
return (contact.DisplayName + string.Format(StringTable.BlackList.MobileTitle, contact.Uri.MobileNo));
}
if (contact.Uri.IsVodafoneUri)
{
return (contact.DisplayName + string.Format(StringTable.BlackList.VodafoneTitle, contact.Uri.Id));
}
}
return (contact.DisplayName + string.Format(StringTable.BlackList.ContactTitle, contact.Uri.Id));
}
private void InitializeComponent()
{
ComponentResourceManager manager = new ComponentResourceManager(typeof(PsBlackList));
this.lbBlackListTips = new XLabel();
this.btnRemove = new XButton();
this.groupBox1 = new GroupBox();
this.xbAdd = new XButton();
this.groupBox1.SuspendLayout();
base.SuspendLayout();
this.lbBlackListTips.BorderColor = Color.Empty;
this.lbBlackListTips.ButtonBorderStyle = ButtonBorderStyle.None;
this.lbBlackListTips.Location = new System.Drawing.Point(6, 0x11);
this.lbBlackListTips.Name = "lbBlackListTips";
this.lbBlackListTips.Size = new Size(0x184, 0x12);
this.lbBlackListTips.TabIndex = 1;
this.lbBlackListTips.Text = "下列黑名单中的人不能看到您的在线状态,且不能向您发送消息。";
this.lbBlackListTips.UseMnemonic = false;
this.btnRemove.AutoArrangementX = true;
this.btnRemove.AutoSizeToImage = false;
this.btnRemove.BackColor = Color.Transparent;
this.btnRemove.BackgroundImage = (Image) manager.GetObject("btnRemove.BackgroundImage");
this.btnRemove.BackgroundImageDisable = (Image) manager.GetObject("btnRemove.BackgroundImageDisable");
this.btnRemove.BackgroundImageDown = (Image) manager.GetObject("btnRemove.BackgroundImageDown");
this.btnRemove.BackgroundImageHover = (Image) manager.GetObject("btnRemove.BackgroundImageHover");
this.btnRemove.ChangeSkin = false;
this.btnRemove.Location = new System.Drawing.Point(10, 0x19c);
this.btnRemove.Name = "btnRemove";
this.btnRemove.Size = new Size(0x4b, 0x15);
this.btnRemove.TabIndex = 3;
this.btnRemove.Text = "移出黑名单";
this.btnRemove.set_UseVisualStyleBackColor(false);
this.btnRemove.Click += new EventHandler(this.btnRemove_Click);
this.groupBox1.Controls.Add(this.xbAdd);
this.groupBox1.Controls.Add(this.lbBlackListTips);
this.groupBox1.Controls.Add(this.btnRemove);
this.groupBox1.Location = new System.Drawing.Point(10, 3);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new Size(400, 0x1b7);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "黑名单";
this.xbAdd.AutoArrangementX = true;
this.xbAdd.AutoSizeToImage = false;
this.xbAdd.BackColor = Color.Transparent;
this.xbAdd.BackgroundImage = (Image) manager.GetObject("xbAdd.BackgroundImage");
this.xbAdd.BackgroundImageDisable = (Image) manager.GetObject("xbAdd.BackgroundImageDisable");
this.xbAdd.BackgroundImageDown = (Image) manager.GetObject("xbAdd.BackgroundImageDown");
this.xbAdd.BackgroundImageHover = (Image) manager.GetObject("xbAdd.BackgroundImageHover");
this.xbAdd.ChangeSkin = false;
this.xbAdd.Location = new System.Drawing.Point(0x5b, 0x19c);
this.xbAdd.Name = "xbAdd";
this.xbAdd.Size = new Size(0x52, 0x15);
this.xbAdd.TabIndex = 4;
this.xbAdd.Text = "加入黑名单...";
this.xbAdd.set_UseVisualStyleBackColor(false);
this.xbAdd.Click += new EventHandler(this.xbAdd_Click);
base.set_AutoScaleDimensions(new SizeF(6f, 12f));
base.set_AutoScaleMode(1);
base.Controls.Add(this.groupBox1);
base.Name = "PsBlackList";
base.Size = new Size(420, 480);
this.groupBox1.ResumeLayout(false);
base.ResumeLayout(false);
}
private void InitializeCustomComponent()
{
headiconlist_drawer _drawer = new headiconlist_drawer();
this.lsBlackList = new listbox_widget_t<headicon>();
_drawer.border_color = Color.Gray;
_drawer.drawmode = DrawMode.OwnerDrawVariable;
_drawer.font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0x86);
_drawer.item_height = 0x1a;
_drawer.noicon_string_alignment = StringAlignment.Center;
_drawer.show_focus = true;
_drawer.stretch_textarea = false;
this.lsBlackList.drawer = _drawer;
this.lsBlackList.DrawMode = DrawMode.OwnerDrawVariable;
this.lsBlackList.set_FormattingEnabled(true);
this.lsBlackList.Location = new System.Drawing.Point(10, 40);
this.lsBlackList.Name = "lsBlackList";
this.lsBlackList.Size = new Size(380, 0x16d);
this.lsBlackList.TabIndex = 0;
this.lsBlackList.BorderStyle = BorderStyle.FixedSingle;
this.groupBox1.Controls.Add(this.lsBlackList);
}
private void LoadResource()
{
}
private void PersonalInfo_PropertiesChanged(object sender, PropertiesChangedEventArgs e)
{
Imps.Client.Core.ContactInfo info = sender as Imps.Client.Core.ContactInfo;
if (((info != null) && (this._contacts != null)) && e.ContainsAnyOfProperties(new string[] { "name", "nickname" }))
{
Imps.Client.Core.Contact owner = info.Owner;
int index = this._contacts.IndexOf(owner);
if (index != -1)
{
((headicon) this.lsBlackList.Items[index]).text = this.getDisplayString(owner);
}
}
}
public override bool UpdateData(bool update)
{
if (!update)
{
this.displayBlackList();
this.btnRemove.Enabled = this.lsBlackList.Items.Count > 0;
}
base.Modified = false;
return true;
}
private void xbAdd_Click(object sender, EventArgs e)
{
if (this.blackListAddForm == null)
{
this.blackListAddForm = new BlackListAddForm(this._iFrameworkWindow);
}
this.blackListAddForm.ShowDialog();
}
private Imps.Client.Core.User _user
{
get
{
return this._iFrameworkWindow.AccountManager.CurrentUser;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -