00001 using System;
00002 using System.Collections.Generic;
00003 using System.ComponentModel;
00004 using System.Data;
00005 using System.Drawing;
00006 using System.Linq;
00007 using System.Text;
00008 using System.Windows.Forms;
00009
00010 using NicoLiveTools;
00011
00012 namespace NicoLiveAlert {
00013
00017 public partial class Form1 : Form {
00018
00020 private Alert m_alert = new Alert();
00021
00023 private Alert Alert {
00024 get {
00025 return m_alert;
00026 }
00027 }
00028
00030 private AlertConfigure m_configure = new AlertConfigure("conf.xml");
00031
00033 private AlertConfigure Configure {
00034 get {
00035 return m_configure;
00036 }
00037 }
00038
00042 public Form1() {
00043 Control.CheckForIllegalCrossThreadCalls = false;
00044 InitializeComponent();
00045 }
00046
00051 public void RestoreLocation() {
00052 try {
00053 string strx = Configure["window"]["location"]["x"],
00054 stry = Configure["window"]["location"]["y"];
00055 int x = Convert.ToInt32(strx, 10),
00056 y = Convert.ToInt32(stry, 10);
00057
00058 Location = new Point(x, y);
00059 } catch {
00060
00061
00062
00063
00064 }
00065 }
00066
00070 public void SaveLocation() {
00071 if (WindowState == FormWindowState.Normal) {
00072
00073 Configure["window"]["location"]["x"].Value = Location.X.ToString();
00074 Configure["window"]["location"]["y"].Value = Location.Y.ToString();
00075 } else {
00076
00077 FormWindowState state = WindowState;
00078 WindowState = FormWindowState.Normal;
00079 Configure["window"]["location"]["x"].Value = Location.X.ToString();
00080 Configure["window"]["location"]["y"].Value = Location.Y.ToString();
00081 WindowState = state;
00082 }
00083 }
00084
00089 public void RestoreSize() {
00090 try {
00091 string strw = Configure["window"]["size"]["width"],
00092 strh = Configure["window"]["size"]["height"];
00093 int width = Convert.ToInt32(strw, 10),
00094 height = Convert.ToInt32(strh, 10);
00095
00096 Size = new Size(width, height);
00097 } catch {
00098
00099
00100
00101
00102 }
00103 }
00104
00108 public void SaveSize() {
00109 if (WindowState == FormWindowState.Normal) {
00110
00111 Configure["window"]["size"]["width"].Value = Size.Width.ToString();
00112 Configure["window"]["size"]["height"].Value = Size.Height.ToString();
00113 } else {
00114
00115 FormWindowState state = WindowState;
00116 WindowState = FormWindowState.Normal;
00117 Configure["window"]["size"]["width"].Value = Size.Width.ToString();
00118 Configure["window"]["size"]["height"].Value = Size.Height.ToString();
00119 WindowState = state;
00120 }
00121 }
00122
00126 public void RestoreWindowState() {
00127 try {
00128 FormWindowState laststate;
00129 switch(Configure["window"]["state"]){
00130 case "Normal":
00131 laststate = FormWindowState.Normal;
00132 break;
00133 case "Maximized":
00134 laststate = FormWindowState.Maximized;
00135 break;
00136 case "Minimized":
00137 laststate = FormWindowState.Minimized;
00138 break;
00139 default:
00140 laststate = FormWindowState.Normal;
00141 break;
00142 }
00143 WindowState = laststate;
00144 } catch {
00145
00146 }
00147 }
00148
00152 public void SaveWindowState() {
00153 Configure["window"]["state"].Value = WindowState.ToString();
00154 }
00155
00161 private void Form1_Load(object sender, EventArgs e) {
00162
00163
00164 Siki.Styles.SetListViewDoubleBuffered(listView1);
00165 Siki.Styles.SetListViewDoubleBuffered(listView2);
00166 Siki.Styles.SetListViewDoubleBuffered(listView3);
00167
00168 RestoreLocation();
00169 RestoreSize();
00170 RestoreWindowState();
00171
00172 Alert.Log += new EventHandler<NicoLiveTools.DebugEventArgs>(Alert_Log);
00173 Alert.LiveStarted += new EventHandler<AlertEventArgs>(Alert_LiveStarted);
00174 Alert.Connect();
00175 }
00176
00182 private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
00183
00184 SaveWindowState();
00185 SaveSize();
00186 SaveLocation();
00187 Configure.Save();
00188
00189 Alert.Disconnect();
00190 Form1_FormClosed(sender, new FormClosedEventArgs(CloseReason.ApplicationExitCall));
00191 }
00192
00198 private void Form1_FormClosed(object sender, FormClosedEventArgs e) {
00199
00200 }
00201
00207 private void Form1_Resize(object sender, EventArgs e) {
00208
00209 }
00210
00216 private void ExitToolStripMenuItem_Click(object sender, EventArgs e) {
00217 this.Close();
00218 }
00219
00225 private void ConnectToolStripMenuItem_Click(object sender, EventArgs e) {
00226 m_alert.Connect();
00227 }
00228
00234 private void DisconnectToolStripMenuItem_Click(object sender, EventArgs e) {
00235 lock (m_alert) {
00236 m_alert.Disconnect();
00237 }
00238 }
00239
00245 private void ToolsToolStripMenuItem_Click(object sender, EventArgs e) {
00246
00247 }
00248
00255 private void ToolsToolStripMenuItem_CheckedChanged(object sender, EventArgs e) {
00256
00257 if (ツールTToolStripMenuItem.Checked) {
00258 toolStripContainer1.RightToolStripPanelVisible = true;
00259 }
00260
00261 else {
00262 toolStripContainer1.RightToolStripPanelVisible = false;
00263 tabControl1.Invalidate(false);
00264 tabControl1.Update();
00265 }
00266 }
00267
00273 private void listView2_DoubleClick(object sender, EventArgs e) {
00274 ListViewHitTestInfo hittest = listView2.HitTest(listView2.PointToClient(Cursor.Position));
00275 if (hittest.Item != null) {
00276 Uri uri = Alert.GetLiveUri(hittest.Item.SubItems[3].Text);
00277 try {
00278
00279 System.Diagnostics.Process.Start(uri.AbsoluteUri);
00280 } catch (System.ComponentModel.Win32Exception noBrowser) {
00281 if (noBrowser.ErrorCode == -2147467259) {
00282
00283 }
00284 } catch {
00285
00286 }
00287 }
00288 }
00289
00295 private void Alert_LiveStarted(object sender, AlertEventArgs e) {
00296 ListViewItem item = new ListViewItem(new string[]{"alert",e.Community,e.User,"lv"+e.LiveId,"about","now"});
00297 if (e.Community == "co38261" || e.Community == "co106774" || e.Community == "co16016") {
00298 System.Diagnostics.Process.Start(Alert.GetLiveUri(e.LiveId).ToString());
00299 }
00300 listView2.Items.Insert(0, item);
00301 }
00302
00308 private void Alert_Log(object sender, NicoLiveTools.DebugEventArgs e) {
00309
00310 ListViewItem item = new ListViewItem(new string[] { e.Time.ToString(), e.Text });
00311 try {
00312 if (!Disposing) {
00313 listView3.Items.Add(item);
00314
00315 if(autoScroll.Checked){
00316 int count = listView3.Items.Count;
00317 listView3.EnsureVisible(count - 1);
00318 }
00319 }
00320 } catch {
00321
00322 }
00323 }
00324 }
00325 }