1: public MainWindow()
2: {
3: this.InitializeComponent();
4:
5: #if DEBUG
6: Title = Title + " Debug";
7: #endif
8:
9: // Trap unhandled exceptions
10: LayoutRoot.Dispatcher.UnhandledException += new DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException);
11:
12: #region Minimize to tray setup
13:
14: _notifyIcon = new System.Windows.Forms.NotifyIcon();
15: _notifyIcon.BalloonTipText = "Right-click for more options";
16: _notifyIcon.BalloonTipTitle = "Witty";
17: _notifyIcon.Text = "Witty - The WPF Twitter Client";
18: _notifyIcon.Icon = Witty.Properties.Resources.AppIcon;
19: _notifyIcon.DoubleClick += new EventHandler(m_notifyIcon_Click);
20:
21: System.Windows.Forms.ContextMenu notifyMenu = new System.Windows.Forms.ContextMenu();
22: System.Windows.Forms.MenuItem openMenuItem = new System.Windows.Forms.MenuItem();
23: System.Windows.Forms.MenuItem exitMenuItem = new System.Windows.Forms.MenuItem();
24:
25: notifyMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { openMenuItem, exitMenuItem });
26: openMenuItem.Index = 0;
27: openMenuItem.Text = "Open";
28: openMenuItem.Click += new EventHandler(openMenuItem_Click);
29: exitMenuItem.Index = 1;
30: exitMenuItem.Text = "Exit";
31: exitMenuItem.Click += new EventHandler(exitMenuItem_Click);
32:
33: _notifyIcon.ContextMenu = notifyMenu;
34: this.Closed += new EventHandler(OnClosed);
35: this.StateChanged += new EventHandler(OnStateChanged);
36: this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(OnIsVisibleChanged);
37:
38: // used to override closings and minimize instead
39: this.Closing += new CancelEventHandler(MainWindow_Closing);
40:
41: #endregion
42:
43: #region Single instance setup
44: // Enforce single instance for release mode
45: #if !DEBUG
46: Application.Current.Exit += new ExitEventHandler(Current_Exit);
47: _instanceManager = new SingleInstanceManager(this, ShowApplication);
48: #endif
49: #endregion
50:
51: // Set the data context for all of the tabs
52: LayoutRoot.DataContext = tweets;
53: RepliesListBox.ItemsSource = replies;
54: UserTab.DataContext = userTweets;
55: MessagesListBox.ItemsSource = messages;
56:
57: // Set how often to get updates from Twitter
58: refreshInterval = new TimeSpan(0, int.Parse(AppSettings.RefreshInterval), 0);
59:
60: this.Topmost = AlwaysOnTopMenuItem.IsChecked = AppSettings.AlwaysOnTop;
61:
62: // Does the user need to login?
63: if (string.IsNullOrEmpty(AppSettings.Username))
64: {
65: PlayStoryboard("ShowLogin");
66: }
67: else
68: {
69: LoginControl.Visibility = Visibility.Hidden;
70:
71: System.Security.SecureString password = TwitterNet.DecryptString(AppSettings.Password);
72:
73: // Jason Follas: Reworked Web Proxy - don't need to explicitly pass into TwitterNet ctor
74: //twitter = new TwitterNet(AppSettings.Username, password, WebProxyHelper.GetConfiguredWebProxy());
75: twitter = new TwitterNet(AppSettings.Username, password);
76:
77: // Jason Follas: Twitter proxy servers, anyone? (Network Nazis who block twitter.com annoy me)
78: twitter.TwitterServerUrl = AppSettings.TwitterHost;
79:
80: // Let the user know what's going on
81: StatusTextBlock.Text = Properties.Resources.TryLogin;
82: PlayStoryboard("Fetching");
83:
84: // Create a Dispatcher to attempt login on new thread
85: NoArgDelegate loginFetcher = new NoArgDelegate(this.TryLogin);
86: loginFetcher.BeginInvoke(null, null);
87: }
88:
89: InitializeClickOnceTimer();
90:
91: InitializeSoundPlayer();
92:
93: ScrollViewer.SetCanContentScroll(TweetsListBox, !AppSettings.SmoothScrolling);
94:
95: //Register with Snarl if available
96: if (SnarlConnector.GetSnarlWindow().ToInt32() != 0)
97: {
98: //We Create a Message Only window for communication
99:
100: this.SnarlConfighWnd = Win32.CreateWindowEx(0, "Message", null, 0, 0, 0, 0, 0, new IntPtr(Win32.HWND_MESSAGE), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
101: WindowsMessage wndMsg = new WindowsMessage();
102: SnarlConnector.RegisterConfig(this.SnarlConfighWnd,"Witty",wndMsg);
103:
104: SnarlConnector.RegisterAlert("Witty", "New tweet");
105: SnarlConnector.RegisterAlert("Witty", "New tweets summarized");
106: SnarlConnector.RegisterAlert("Witty", "New reply");
107: SnarlConnector.RegisterAlert("Witty", "New direct message");
108:
109: }
110: }