PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/o3o/MainWindow.xaml.cs

http://github.com/zahndy/o3o
C# | 330 lines | 247 code | 62 blank | 21 comment | 24 complexity | 88c38d71a21f9d461e00926ae1068b76 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using System.Runtime.InteropServices;
  15. using System.Windows.Interop;
  16. using System.Windows.Media.Effects;
  17. using System.Collections.ObjectModel;
  18. using System.Windows.Forms;
  19. using Twitterizer;
  20. namespace o3o
  21. {
  22. /// <summary>
  23. /// Interaction logic for MainWindow.xaml
  24. /// </summary>
  25. public partial class MainWindow : Window
  26. {
  27. TweetStack o3o;
  28. System.Windows.Threading.Dispatcher maindispatcher;
  29. public delegate void dostuff(string message, string user, DateTime date, string url, string id);
  30. public dostuff dostuffdel;
  31. public MainWindow()
  32. {
  33. if (String.IsNullOrEmpty(Properties.Settings.Default.OAuth_AccessToken))
  34. {
  35. o3o = new TweetStack(false);
  36. o3o.OAuth.AuthenticateTwitter();
  37. o3o.OAuth.SaveOAuth();
  38. }
  39. else
  40. {
  41. o3o = new TweetStack(true,true);
  42. }
  43. maindispatcher = this.Dispatcher;
  44. InitializeComponent();
  45. o3o.NewTweet += new TweetStack.newtweetDel(o3o_NewTweet);
  46. MouseDown += delegate { if (MouseButtonState.Pressed == System.Windows.Input.Mouse.LeftButton) { DragMove(); } };
  47. this.Loaded += new RoutedEventHandler(Window1_Loaded);
  48. }
  49. void o3o_NewTweet(TwitterStatus status)
  50. {
  51. dostuffdel = new dostuff(FillHome);
  52. maindispatcher.Invoke(dostuffdel, new object[] { status.Text, status.User.ScreenName, status.CreatedDate, status.User.ProfileImageLocation, status.Id.ToString() });
  53. dostuffdel = new dostuff(Notification);
  54. maindispatcher.Invoke(dostuffdel, new object[] { status.Text, status.User.ScreenName, status.CreatedDate, status.User.ProfileImageLocation, status.Id.ToString() });
  55. }
  56. void Window1_Loaded(object sender, RoutedEventArgs e)
  57. {
  58. this.SetAeroGlass();
  59. if (Properties.Settings.Default.use_system_color == true)
  60. {
  61. checkBox1.IsChecked = true;
  62. }
  63. }
  64. [DllImport("dwmapi.dll", EntryPoint = "#127", PreserveSig = false)]
  65. public static extern void DwmGetColorizationParameters(out WDM_COLORIZATION_PARAMS parameters);
  66. public struct WDM_COLORIZATION_PARAMS
  67. {
  68. public uint Color1;
  69. public uint Color2;
  70. public uint Intensity;
  71. public uint Unknown1;
  72. public uint Unknown2;
  73. public uint Unknown3;
  74. public uint Opaque;
  75. }
  76. void get_mentions()
  77. {
  78. //TweetMentions.Items.Clear();
  79. //foreach (Twitterizer.TwitterStatus lama in mentions)
  80. //{
  81. // FillMentions(lama.Text, lama.User.ScreenName, lama.CreatedDate, lama.User.ProfileImageLocation, lama.Id.ToString());
  82. //}
  83. }
  84. private void testbutton_Click(object sender, RoutedEventArgs e)
  85. {
  86. if (textBox1.Visibility == Visibility.Collapsed)
  87. {
  88. testbutton.Content = "Cancel";
  89. TweetElements.Margin = new Thickness(0, 0, 0, 70);
  90. textBox1.Visibility = Visibility.Visible;
  91. charleft.Visibility = Visibility.Visible;
  92. TweetLbl.Visibility = Visibility.Visible;
  93. }
  94. else if (textBox1.Visibility == Visibility.Visible)
  95. {
  96. if (textBox1.Text.Length <= 140)
  97. {
  98. if (!String.IsNullOrEmpty(textBox1.Text))
  99. {
  100. o3o.Twitter.SendTweet(textBox1.Text);
  101. textBox1.Text = "";
  102. charleft.Text = "140";
  103. }
  104. else
  105. {
  106. //charleft.Foreground = new SolidColorBrush(Colors.Red);
  107. //charleft.Text = "no text";
  108. testbutton.Content = "Tweet";
  109. TweetElements.Margin = new Thickness(0, 0, 0, 17);
  110. textBox1.Visibility = Visibility.Collapsed;
  111. charleft.Visibility = Visibility.Collapsed;
  112. TweetLbl.Visibility = Visibility.Collapsed;
  113. }
  114. }
  115. else
  116. {
  117. charleft.Foreground = new SolidColorBrush(Colors.Red);
  118. charleft.Text = "Too long";
  119. }
  120. }
  121. }
  122. public void FillHome(string message, string user, DateTime date, string url, string id)
  123. {
  124. TweetElement element = new TweetElement(this);
  125. element.Tweet = message;
  126. element.name = user;
  127. element.Date = date.Month.ToString() + "/" + date.Day.ToString() + " " + date.Hour.ToString() + ":" + date.Minute.ToString();
  128. element.imagelocation = url;
  129. element.ID = id;
  130. TweetElements.Items.Insert(0, element);
  131. }
  132. public void FillMentions(string message, string user, DateTime date, string url, string id)
  133. {
  134. TweetElement element = new TweetElement(this);
  135. element.Tweet = message;
  136. element.name = user;
  137. element.Date = date.Month.ToString() + "/" + date.Day.ToString() + " " + date.Hour.ToString() + ":" + date.Minute.ToString();
  138. element.imagelocation = url;
  139. element.ID = id;
  140. TweetMentions.Items.Add( element);
  141. }
  142. public void Notification(string message, string user, DateTime date, string url, string id)
  143. {
  144. notify notification = new notify();
  145. TweetElement element = new TweetElement(this);
  146. element.Tweet = message;
  147. element.name = user;
  148. element.Date = date.Month.ToString() + "/" + date.Day.ToString() + " " + date.Hour.ToString() + ":" + date.Minute.ToString();
  149. element.imagelocation = url;
  150. element.ID = id;
  151. element.replyBtn.Source = new BitmapImage(new Uri("/o3o;component/Images/reply.png", UriKind.Relative));
  152. notification.content.Items.Add(element);
  153. }
  154. private void closebutton_Click(object sender, RoutedEventArgs e)
  155. {
  156. this.Close();
  157. }
  158. private void minimisebutton_Click(object sender, RoutedEventArgs e)
  159. {
  160. WindowState = WindowState.Minimized;
  161. }
  162. private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
  163. {
  164. int left = 140 - (textBox1.Text.Length);
  165. charleft.Text = left.ToString();
  166. if (left < 0)
  167. {
  168. charleft.Foreground = new SolidColorBrush(Colors.Red);
  169. }
  170. else if (left == 140)
  171. {
  172. testbutton.Content = "Cancel";
  173. }
  174. else
  175. {
  176. charleft.Foreground = new SolidColorBrush(Colors.Black);
  177. testbutton.Content = "Send";
  178. }
  179. }
  180. private void Button_Click(object sender, RoutedEventArgs e)
  181. {
  182. AboutBox1 about = new AboutBox1();
  183. about.Show();
  184. }
  185. private void checkBox1_Checked(object sender, RoutedEventArgs e)
  186. {
  187. Properties.Settings.Default.use_system_color = true;
  188. Properties.Settings.Default.Save();
  189. }
  190. private void checkBox1_Unchecked(object sender, RoutedEventArgs e)
  191. {
  192. Properties.Settings.Default.use_system_color = false;
  193. Properties.Settings.Default.Save();
  194. }
  195. private void colorpicker_SelectedColorChanged(Color obj)
  196. {
  197. Properties.Settings.Default.system_color = System.Drawing.Color.FromArgb(obj.A,obj.R,obj.G,obj.B);
  198. Properties.Settings.Default.Save();
  199. }
  200. private void button1_Click(object sender, RoutedEventArgs e)
  201. {
  202. get_mentions();
  203. }
  204. private void textBox1_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  205. {
  206. if (e.Key == Key.Enter)
  207. {
  208. if (textBox1.Text.Length <= 140)
  209. {
  210. if (!String.IsNullOrEmpty(textBox1.Text))
  211. {
  212. o3o.Twitter.SendTweet(textBox1.Text);
  213. textBox1.Text = "";
  214. charleft.Text = "140";
  215. }
  216. else
  217. {
  218. charleft.Foreground = new SolidColorBrush(Colors.Red);
  219. charleft.Text = "no text";
  220. }
  221. }
  222. else
  223. {
  224. charleft.Foreground = new SolidColorBrush(Colors.Red);
  225. charleft.Text = "too long";
  226. }
  227. }
  228. if (e.Key == Key.Escape)
  229. {
  230. textBox1.Text = "";
  231. testbutton.Content = "Tweet";
  232. TweetElements.Margin = new Thickness(0, 0, 0, 17);
  233. textBox1.Visibility = Visibility.Collapsed;
  234. charleft.Visibility = Visibility.Collapsed;
  235. TweetLbl.Visibility = Visibility.Collapsed;
  236. }
  237. }
  238. private void btn_right_MouseUp(object sender, MouseButtonEventArgs e)
  239. {
  240. }
  241. private void btn_Left_MouseUp(object sender, MouseButtonEventArgs e)
  242. {
  243. }
  244. //private void reload_MouseDown(object sender, MouseButtonEventArgs e)
  245. //{
  246. //}
  247. //private void reload_MouseLeave(object sender, MouseEventArgs e)
  248. //{
  249. // reload.Source = new BitmapImage(new Uri("/o3o;component/Images/Reload_normal.png", UriKind.Relative));
  250. //}
  251. //private void reload_MouseEnter(object sender, MouseEventArgs e)
  252. //{
  253. // reload.Source = new BitmapImage(new Uri("/o3o;component/Images/Reload_Hover.png", UriKind.Relative));
  254. //}
  255. public void tbox(string inc) // somehow use this in TweetElement.xaml.cs
  256. {
  257. textBox1.Text = inc;
  258. if (textBox1.Visibility == Visibility.Collapsed)
  259. {
  260. testbutton.Content = "Tweet";
  261. TweetElements.Margin = new Thickness(0, 0, 0, 70);
  262. textBox1.Visibility = Visibility.Visible;
  263. charleft.Visibility = Visibility.Visible;
  264. TweetLbl.Visibility = Visibility.Visible;
  265. }
  266. }
  267. }
  268. }