⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cs

📁 语音视频功能 里面实现了基本的QQ与语音对话
💻 CS
📖 第 1 页 / 共 3 页
字号:
using System;
using System.IO;
using System.Xml;
using System.Threading;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;

using gowk.core.managers;
using gowk.core.packets;
using gowk.core.packets.querys;
using gowk.net.Sockets;
using gowk.core;
using gowk.net;
using gowk.controls;

namespace gowk.forms
{
	/// <summary>
	/// MainForm 的摘要说明。
	/// </summary>
	public class MainForm:gowk.controls.GForm
	{
		#region
		private gowk.forms.LoginPanel loginPanel1;
		private gowk.controls.GTabControl gTabControl1;
		private gowk.controls.GTabPage tpChat;
		private gowk.controls.GTabPage tpSms;
		private gowk.controls.GTabPage tpEmail;
		private gowk.controls.GTabPage tpBlog;
		private gowk.controls.GListView gListView1;
		private gowk.controls.GContextMenu gContextMenu1;
		private System.Windows.Forms.NotifyIcon notifyIcon1;
		private System.Windows.Forms.ContextMenu contextMenu1;
		private System.ComponentModel.IContainer components;
		private gowk.controls.GButton gButton1;
		private gowk.controls.GButton gButton3;
		private gowk.controls.GButton gButton2;
		private gowk.controls.GPanel gPanel1;
		private gowk.controls.GButton gButton4;
		private gowk.controls.GToolTip gToolTip1;

		RosterManager rm;
		AuthenticateManager am;
		PresenceManager pm;
		MessageManager mm;
		SearchManager sm;
		vCardManager vm;
		JabberClient jc;
		FormCollection _fs;
		#endregion

NofityIconAnimateHelper niah;
		gowk.common.SkinConfig skf;
		private System.Windows.Forms.ImageList imageList1;
		private gowk.controls.GImage gImage1;
		private gowk.controls.GButton btnStatus;
		private ContextMenu _contextmenu_present;
		public MainForm()
		{
			jc=new gowk.core.JabberClient();
			jc.Control=this;

			this.RegisteManagers();



			InitializeComponent();
			this.btnStatus.Visible=false;
			this._fs=new FormCollection();

			this.RequireUILogin();
			this.LoadMainContextMenu();

			//////////////////////////////skin////////////////////////////////////
			skf=gowk.common.SkinConfig.Instance;
			skf.SkinChanged+=new EventHandler(skf_SkinChanged);
			this.UpdateSkin();

			this.niah=new NofityIconAnimateHelper(this.notifyIcon1);
			this.niah.NormalIcon=this.notifyIcon1.Icon=gowk.controls.UT.ConvertImage2Icon(this.skf.GetImage("/gowk_skin/images/status/status3"));
			this.niah.Rate=2;

		}
		#region skin
		private void UpdateSkin()
		{
			this.ImageTopLeft=skf.GetImage("/gowk_skin/images/form/t1");
			this.ImageTopCenter=skf.GetImage("/gowk_skin/images/form/t2");
			this.ImageTopRight=skf.GetImage("/gowk_skin/images/form/t3");

			this.ImageMiddleLeft=skf.GetImage("/gowk_skin/images/form/m1");
			this.ImageMiddleCenter=skf.GetImage("/gowk_skin/images/form/m2");
			this.ImageMiddleRight=skf.GetImage("/gowk_skin/images/form/m3");

			this.ImageBottomLeft=skf.GetImage("/gowk_skin/images/form/b1");
			this.ImageBottomCenter=skf.GetImage("/gowk_skin/images/form/b2");
			this.ImageBottomRight=skf.GetImage("/gowk_skin/images/form/b3");
		}

		private void skf_SkinChanged(object sender, EventArgs e)
		{
			this.UpdateSkin();
		}
		#endregion
		#region RegisteManagers
		private void RegisteManagers()
		{
			//	this.jc.JabberStream.JabberStreamEnd+=new EventHandler(JabberStream_JabberStreamEnd);
			this.jc.StateChange+=new EventHandler(jc_StateChange);

			//author
			am=new AuthenticateManager(this.jc);
			am.LoginResult+=new JabberEventHandler(am_LoginResult);
			this.jc.Managers.Add(typeof(AuthenticateManager),am);

			//roster
			rm=new RosterManager(this.jc);
			rm.RosterReceived+=new JabberEventHandler(rm_RosterReceived);
			rm.GetRosterResult+=new JabberEventHandler(rm_GetRosterResult);
			this.jc.Managers.Add(typeof(RosterManager),rm);

			//message
			mm=new MessageManager(this.jc);
			mm.ChatMessageReceived+=new JabberEventHandler(mm_ChatMessageReceived);
			mm.GroupChatMessageReceived+=new JabberEventHandler(mm_GroupChatMessageReceived);
			mm.HeadLineMessageReceived+=new JabberEventHandler(mm_HeadLineMessageReceived);
			mm.ChatMessageError+=new JabberEventHandler(mm_ChatMessageError);
			mm.VideoChatReceived+=new JabberEventHandler(mm_VideoChatReceived);
			this.jc.Managers.Add(typeof(MessageManager),mm);

			//presence
			pm=new PresenceManager(jc);
			this.jc.Managers.Add(typeof(PresenceManager),pm);
			pm.StatusChanaged+=new JabberEventHandler(pm_StatusChanaged);
			pm.Subcribe+=new JabberEventHandler(pm_Subcribe);
			pm.Subscribed+=new JabberEventHandler(pm_Subscribed);

			sm=new SearchManager(jc);
			//		this.jc.Managers.Add(typeof(SearchManager),sm);

			vm=new vCardManager(jc);
			vm.vCardReceived+=new JabberEventHandler(vm_vCardReceived);
			this.jc.Managers.Add(typeof(vCardManager),vm);
		}

		private void mm_ChatMessageReceived(JabberEventArgs e)
		{
			gowk.core.packets.Message msg=(gowk.core.packets.Message)e.Packet;
			MessageForm mf=null;
			string bare=Jid.GetBareJid(msg.From);
			string id=bare+"messageForm";
			if(this._fs.ContainsKey(id))
			{
				mf=(MessageForm)this._fs[id];
				if(!mf.Visible)mf.Visible=true;
				mf.Activate();
			}
			else
			{
				if(this.gListView1==null)return;
				Item item=this.FindItem(bare);
				if(item==null)
				{
					item=new Item();
					item.Jid=bare;
					item.Name=Jid.GetUsername(bare);
				}
				mf=new MessageForm(this.jc,item);
				this._fs.Add(id,mf);
				mf.Show();
				mf.OnChatMessageReceived(e);
			}
		}
		private Item FindItem(string jid)
		{
			foreach(gowk.controls.GListViewItem folder in this.gListView1.Items)
			{
				foreach(gowk.controls.GListViewItem group in folder.Items)
				{
					foreach(gowk.controls.GListViewItem item in group.Items)
					{
						Item itm=item.Tag as Item;
						if(itm.Jid==jid)return itm;
					}
				}
			}
			return null;
		}
		private void mm_GroupChatMessageReceived(JabberEventArgs e)
		{

		}

		private void mm_HeadLineMessageReceived(JabberEventArgs e)
		{

		}

		private void mm_ChatMessageError(JabberEventArgs e)
		{

		}
		private void mm_VideoChatReceived(JabberEventArgs e)
		{
			
			gowk.core.packets.Message msg=(gowk.core.packets.Message)e.Packet;
			MessageForm mf=null;
			string bare=Jid.GetBareJid(msg.From);
			string id=bare+"messageForm";
			if(this._fs.ContainsKey(id))
			{
				mf=(MessageForm)this._fs[id];
				if(!mf.Visible)mf.Visible=true;
				mf.Activate();
			}
			else
			{
				if(this.gListView1==null)return;
				Item item=this.FindItem(bare);
				if(item==null)
				{
					item=new Item();
					item.Jid=bare;
					item.Name=Jid.GetUsername(bare);
				}
				mf=new MessageForm(this.jc,item);
				this._fs.Add(id,mf);
				mf.Show();
				mf.ResponseVideoChat(msg);
			}
		}
		#endregion
		#region
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(this.jc.State!=gowk.core.State.Disconnected)
				{
					this.Logout();
				}
				if(this.notifyIcon1!=null)
				{
					this.notifyIcon1.Dispose();
				}
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
			this.gContextMenu1 = new gowk.controls.GContextMenu();
			this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
			this.contextMenu1 = new System.Windows.Forms.ContextMenu();
			this.gButton1 = new gowk.controls.GButton();
			this.gButton3 = new gowk.controls.GButton();
			this.gButton2 = new gowk.controls.GButton();
			this.gPanel1 = new gowk.controls.GPanel();
			this.gButton4 = new gowk.controls.GButton();
			this.btnStatus = new gowk.controls.GButton();
			this.gImage1 = new gowk.controls.GImage();
			this.gToolTip1 = new gowk.controls.GToolTip();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.gPanel1.SuspendLayout();
			this.SuspendLayout();
			// 
			// gContextMenu1
			// 
			this.gContextMenu1.Image = null;
			// 
			// notifyIcon1
			// 
			this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
			this.notifyIcon1.Text = "notifyIcon1";
			this.notifyIcon1.Visible = true;
			this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
			// 
			// gButton1
			// 
			this.gButton1.BackColor = System.Drawing.Color.Transparent;
			this.gButton1.GBorderStyle = gowk.controls.GBorderStyle.Solid;
			this.gButton1.IsRound = true;
			this.gButton1.Location = new System.Drawing.Point(4, 4);
			this.gButton1.Name = "gButton1";
			this.gButton1.Size = new System.Drawing.Size(16, 16);
			this.gButton1.TabIndex = 1;
			this.gButton1.Click += new System.EventHandler(this.gButton1_Click);
			// 
			// gButton3
			// 
			this.gButton3.BackColor = System.Drawing.Color.Transparent;
			this.gButton3.GBorderStyle = gowk.controls.GBorderStyle.Solid;
			this.gButton3.IsRound = true;
			this.gButton3.Location = new System.Drawing.Point(36, 4);
			this.gButton3.Name = "gButton3";
			this.gButton3.Size = new System.Drawing.Size(16, 16);
			this.gButton3.TabIndex = 4;
			this.gButton3.Click += new System.EventHandler(this.gButton3_Click);
			// 
			// gButton2
			// 
			this.gButton2.BackColor = System.Drawing.Color.Transparent;
			this.gButton2.GBorderStyle = gowk.controls.GBorderStyle.Solid;
			this.gButton2.IsRound = true;
			this.gButton2.Location = new System.Drawing.Point(20, 4);
			this.gButton2.Name = "gButton2";
			this.gButton2.Size = new System.Drawing.Size(16, 16);
			this.gButton2.TabIndex = 3;
			this.gButton2.Click += new System.EventHandler(this.gButton2_Click);
			// 
			// gPanel1
			// 
			this.gPanel1.BackColor = System.Drawing.Color.Transparent;
			this.gPanel1.Controls.Add(this.gButton1);
			this.gPanel1.Controls.Add(this.gButton3);
			this.gPanel1.Controls.Add(this.gButton2);
			this.gPanel1.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.gPanel1.IsRound = false;
			this.gPanel1.Location = new System.Drawing.Point(16, 8);
			this.gPanel1.Name = "gPanel1";
			this.gPanel1.Size = new System.Drawing.Size(56, 24);
			this.gPanel1.TabIndex = 0;
			// 
			// gButton4
			// 
			this.gButton4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.gButton4.BackColor = System.Drawing.Color.Transparent;
			this.gButton4.GBorderStyle = gowk.controls.GBorderStyle.Solid;
			this.gButton4.IsRound = true;
			this.gButton4.Location = new System.Drawing.Point(104, 336);
			this.gButton4.Name = "gButton4";
			this.gButton4.Size = new System.Drawing.Size(48, 24);
			this.gButton4.TabIndex = 1;
			this.gButton4.Visible = false;
			this.gButton4.MouseUp += new System.Windows.Forms.MouseEventHandler(this.gButton4_MouseUp);
			// 
			// btnStatus
			// 
			this.btnStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.btnStatus.BackColor = System.Drawing.Color.Transparent;
			this.btnStatus.GBorderStyle = gowk.controls.GBorderStyle.Solid;
			this.btnStatus.GImage = this.gImage1;
			this.btnStatus.IsRound = true;
			this.btnStatus.Location = new System.Drawing.Point(8, 328);
			this.btnStatus.Name = "btnStatus";
			this.btnStatus.Size = new System.Drawing.Size(24, 24);
			this.btnStatus.TabIndex = 2;
			this.btnStatus.Click += new System.EventHandler(this.gButton5_Click);
			// 
			// gImage1
			// 
			this.gImage1.ActiveImage = ((System.Drawing.Image)(resources.GetObject("gImage1.ActiveImage")));
			this.gImage1.Image = ((System.Drawing.Image)(resources.GetObject("gImage1.Image")));
			this.gImage1.NormalImage = ((System.Drawing.Image)(resources.GetObject("gImage1.NormalImage")));
			this.gImage1.PressedImage = ((System.Drawing.Image)(resources.GetObject("gImage1.PressedImage")));
			// 
			// gToolTip1
			// 
			this.gToolTip1.BackColor = System.Drawing.Color.Empty;
			this.gToolTip1.Icon = null;
			this.gToolTip1.MaxTipWidth = 0;
			// 
			// imageList1
			// 
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.Gray;
			this.ClientSize = new System.Drawing.Size(152, 360);
			this.Controls.Add(this.btnStatus);
			this.Controls.Add(this.gButton4);
			this.Controls.Add(this.gPanel1);
			this.DockPadding.Top = 15;
			this.IsRound = false;
			this.Name = "MainForm";
			this.ShowInTaskbar = false;
			this.StretchOption = gowk.controls.StretchOption.HRepeat;
			this.Text = "MainForm";
			this.TopMost = true;
			this.TransparencyKey = System.Drawing.Color.Gray;
			this.Load += new System.EventHandler(this.MainForm_Load);
			this.gPanel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion
		#endregion
		#region tab
		private void LoadTab()
		{
			this.btnStatus.Visible=true;
			
			this.niah.NormalIcon=this.notifyIcon1.Icon=gowk.controls.UT.ConvertImage2Icon(this.skf.GetImage("/gowk_skin/images/status/status1"));

			this.gTabControl1 = new gowk.controls.GTabControl();
			this.tpChat = new gowk.controls.GTabPage();
			this.gListView1 = new gowk.controls.GListView();
			this.SuspendLayout();
			this.gTabControl1.SuspendLayout();
			this.gListView1.SuspendLayout();
			this.tpChat.SuspendLayout();


			// 
			// gTabControl1
			// 
			this.gTabControl1.Alignment = gowk.controls.GAlignment.Left;
			this.gTabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.gTabControl1.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.gTabControl1.Dock=DockStyle.Fill;
			this.gTabControl1.IsRound = true;
			this.gTabControl1.ItemSize = new System.Drawing.Size(32, 32);
			this.gTabControl1.ItemBackGround.Image=skf.GetImage("/gowk_skin/images/tab/itembackground");
			this.gTabControl1.BackColor=Color.Transparent;
			this.gTabControl1.SelectedIndexChanged+=new EventHandler(gTabControl1_SelectedIndexChanged);
			// 
			// tpChat
			// 
			this.tpChat.BackColor = System.Drawing.Color.Transparent;
			this.tpChat.Dock = System.Windows.Forms.DockStyle.Fill;
			this.tpChat.Text="聊天";
			this.tpChat.BackColor=Color.Transparent;
			this.tpChat.GImage.Image=skf.GetImage("/gowk_skin/images/tab/chat");
			this.gTabControl1.GTabPages.Add(this.tpChat);

			this.tpSms=new GTabPage();
			this.tpSms.Text="短信";
			this.tpSms.BackColor=Color.Transparent;
			this.tpSms.GImage.Image=skf.GetImage("/gowk_skin/images/tab/sms");
			this.gTabControl1.GTabPages.Add(this.tpSms);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -