~ubuntu-branches/ubuntu/karmic/gtwitter/karmic

« back to all changes in this revision

Viewing changes to gtwitter/MainWindow.cs

  • Committer: Bazaar Package Importer
  • Author(s): Michael Janssen
  • Date: 2007-08-09 17:14:13 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20070809171413-28ppa0f2oxmr6qyt
Tags: upstream-1.0~beta
ImportĀ upstreamĀ versionĀ 1.0~beta

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
using System;
 
2
using System.Text.RegularExpressions;
2
3
using Gtk;
3
4
using System.IO;
4
5
using System.Threading;
5
6
using System.Diagnostics;
6
7
using Cairo;
7
8
using GConf;
 
9
using Sexy;
 
10
using Mono.Unix;
 
11
using System.Net;
8
12
 
9
13
namespace gtwitter
10
14
{
11
15
        
12
16
        public partial class MainWindow: Gtk.Window
13
17
        {
 
18
                public static Window mainWindow;
 
19
                
14
20
                //classes
15
21
                GetTwitterData getTwitterData = new GetTwitterData();
16
22
                PostToTwitter postToTwitter = new PostToTwitter();
17
 
                CompositeInterface compositeInterface = new CompositeInterface();
18
 
                ReadInfo readInfo = new ReadInfo();
 
23
                //CompositeInterface compositeInterface = new CompositeInterface();
 
24
                public static int navigation = 0;
 
25
                public static ReadInfo readInfo = new ReadInfo();
19
26
                
 
27
                //dialogs
20
28
                PreferencesWindow preferencesWindow;
21
 
                AboutDialog aboutDialog;
22
 
                Window window1;
23
 
                
24
 
                StatusIcon statusIcon = new StatusIcon();
 
29
                AboutDialog aboutDialog; 
 
30
                
 
31
//#if GTK_2_10
 
32
                //status icon
 
33
                StatusIcon statusIcon = new StatusIcon();
 
34
//#endif
 
35
                
 
36
                //sexy widgets
 
37
                public UrlLabel urlLabel1  = new UrlLabel();
 
38
                public IconEntry PostEntry = new IconEntry();
25
39
                
26
40
                public string imageUrl = "";
27
 
                public string screenName = "";
 
41
                public static string screenName = "";
28
42
                public string TwitterPostUrl = "http://twitter.com/statuses/update.xml";
29
43
                public string TwitterFriendsUrl = "http://twitter.com/statuses/friends_timeline.xml";
30
44
                public string TwitterPublicUrl = "http://twitter.com/statuses/public_timeline.xml";
 
45
                public string TwitterDirectUrl = "http://twitter.com/direct_messages.xml";
31
46
                
32
47
                //gconf
33
48
                public static GConf.Client client;
41
56
                public static String WINDOW_WIDTH_KEY = GCONF_APP_PATH + "/window_width";
42
57
                public static String WINDOW_HEIGHT_KEY = GCONF_APP_PATH + "/window_height";
43
58
                public static String HIDDEN_KEY = GCONF_APP_PATH + "/hidden_at_startup";
 
59
                public static String FANCY_UI_KEY = GCONF_APP_PATH + "/fancy_ui";
 
60
                //notifications keys
 
61
                public static String NOTIFY_KEY = GCONF_APP_PATH + "/notify_on";
 
62
                public static String NOTIFY_DIRECT_KEY = GCONF_APP_PATH + "/notify_direct";
 
63
                public static String NOTIFY_PUBFRIE_KEY = GCONF_APP_PATH + "/notify_public_friends";
 
64
                public static String NOTIFY_ALL_KEY = GCONF_APP_PATH + "/notify_all";
44
65
        
45
66
                public static int x = 100;
46
67
                public static int y = 100;
47
68
                
 
69
                public static bool directM = false;
 
70
                
48
71
                //threads
49
72
                Thread getDataThread;
50
73
                Thread imageThread;
54
77
                Thread populateTreeview;
55
78
                //bool threadOK = true;
56
79
                
 
80
                //columns needed for hiding/showing
 
81
                TreeViewColumn imageColumn;
 
82
                TreeViewColumn timeColumn;
 
83
                TreeViewColumn nameColumn;
 
84
                
57
85
                //set config directory in users /home
58
86
                public static string configDir = Environment.GetEnvironmentVariable("HOME") + "/.gtwitter/";
59
87
                
60
88
                //list store for treeview
61
 
                public ListStore liststore = new Gtk.ListStore (typeof (string), typeof (string), typeof (string));
 
89
                public ListStore liststore = new Gtk.ListStore (typeof (string), typeof (Gdk.Pixbuf), typeof (string), typeof (string));
62
90
                
63
91
                public MainWindow (): base (Gtk.WindowType.Toplevel)
64
92
                {
 
93
                        //Catalog.Init ("i18n", "./locale");
 
94
                        
65
95
                        if (MainClass.composite) {
66
96
                                //composite - transparency
67
97
                                Gdk.Screen screen = this.Screen;
75
105
                        
76
106
                        //window
77
107
                        Build();
 
108
                        mainWindow = this;
78
109
                        Title = "gTwitter " + MainClass.version;
79
 
                        window1 = this;
 
110
                        vpaned1.Position = 84;
 
111
                        TopNotebook.Page = 0;
 
112
                                                
 
113
                        //url label sexy
 
114
                        vbox2.Add(urlLabel1);
 
115
                        urlLabel1.LineWrap = true;
 
116
                        urlLabel1.Selectable = true;
 
117
                        urlLabel1.Xalign = 0.0f;
 
118
                        urlLabel1.Yalign = 0.0f;
 
119
                        urlLabel1.WidthRequest = 100;
 
120
                        urlLabel1.Markup = String.Format("<span foreground='darkblue'>{0}</span>",
 
121
                                Catalog.GetString ("Click on Preferences button to enter username and password"));
 
122
                        urlLabel1.Show();
 
123
                        
 
124
                        urlLabel1.UrlActivated += delegate(object o, UrlActivatedArgs args) {
 
125
                                Process.Start("gnome-open", args.Url);
 
126
                        };
 
127
                        
 
128
                        //post entry sexy
 
129
                        hbox2.Add(PostEntry);
 
130
                        PostEntry.AddClearButton();
 
131
                        //PostEntry.SetIcon(IconEntryPosition.Primary, new Image(Stock.Network, IconSize.Menu));
 
132
                        PostEntry.Text = Catalog.GetString ("What are you doing?");
 
133
                        PostEntry.Show();
 
134
                        
 
135
                        PostEntry.Activated += OnPostEntryActivated;
 
136
                        PostEntry.FocusInEvent += OnPostEntryFocusInEvent;
 
137
                        PostEntry.FocusOutEvent += OnPostEntryFocusOutEvent;
 
138
                        PostEntry.Changed += OnPostEntryChanged;
 
139
                        //PostEntry.IconPressed += delegate(object o, IconPressedArgs args) {
 
140
                        //};
80
141
                        
81
142
                        if (MainClass.composite) {
82
143
                                scrolledwindow1.BorderWidth = 10;
90
151
                        try {
91
152
                                passCheck = (string) client.Get (PASSWORD_KEY);
92
153
 
93
 
                                window1.Move((int) client.Get (WINDOW_X_KEY), (int) client.Get (WINDOW_Y_KEY));
94
 
                                window1.Resize((int) client.Get (WINDOW_WIDTH_KEY), (int) client.Get (WINDOW_HEIGHT_KEY));
 
154
                                mainWindow.Move((int) client.Get (WINDOW_X_KEY), (int) client.Get (WINDOW_Y_KEY));
 
155
                                mainWindow.Resize((int) client.Get (WINDOW_WIDTH_KEY), (int) client.Get (WINDOW_HEIGHT_KEY));
 
156
                                
 
157
                                int sourceStart = (int) client.Get (SOURCE_KEY);
 
158
                                if (sourceStart == 0) {
 
159
                                        Friends.Active = true;
 
160
                                        Source.Label = Friends.Label;
 
161
                                }
 
162
                                if (sourceStart == 1) {
 
163
                                        Public.Active = true;
 
164
                                        Source.Label = Public.Label;
 
165
                                }
 
166
                                if (sourceStart == 2) {
 
167
                                        Direct.Active = true;
 
168
                                        Source.Label = Direct.Label;
 
169
                                }
 
170
                                
 
171
                                TweetView.Active = (bool) client.Get (FANCY_UI_KEY);
 
172
                                
 
173
                                x = (int) client.Get (WINDOW_X_KEY);
 
174
                                y = (int) client.Get (WINDOW_Y_KEY);
95
175
                        }
96
176
                        catch (NoSuchKeyException) { }
97
177
                        
102
182
                        CellRendererText numbersCell = new CellRendererText();
103
183
                        numbersColumn.PackStart(numbersCell, true);
104
184
                        
105
 
                        TreeViewColumn nameColumn = new TreeViewColumn();
 
185
                        imageColumn = new TreeViewColumn();
 
186
                        imageColumn.Title = "Image";
 
187
                        CellRendererPixbuf imageCell = new CellRendererPixbuf();
 
188
                        imageColumn.PackStart(imageCell, true);
 
189
                        
 
190
                        nameColumn = new TreeViewColumn();
106
191
                        nameColumn.Title = "Name";
107
192
                        nameColumn.Expand = true;
108
193
                        CellRendererText nameCell = new CellRendererText();
 
194
                        nameCell.Yalign = 0.0f;
 
195
                        nameCell.WrapWidth = 260;
 
196
                        nameCell.WrapMode = Pango.WrapMode.WordChar;
 
197
                        nameColumn.Sizing = Gtk.TreeViewColumnSizing.Autosize;
109
198
                        nameColumn.PackStart (nameCell, true);
110
199
                        
111
 
                        TreeViewColumn timeColumn = new TreeViewColumn();
 
200
                        timeColumn = new TreeViewColumn();
112
201
                        timeColumn.Title = "Time";
113
202
                        CellRendererText timeCell = new CellRendererText();
114
203
                        timeColumn.PackStart (timeCell, true);
115
204
 
116
205
                        Treeview1.AppendColumn(numbersColumn);
 
206
                        Treeview1.AppendColumn(imageColumn);
117
207
                        Treeview1.AppendColumn(nameColumn);
118
208
                        Treeview1.AppendColumn(timeColumn);
119
209
                        
120
210
                        numbersColumn.AddAttribute (numbersCell, "text", 0);
121
 
                        nameColumn.AddAttribute (nameCell, "markup", 1);
122
 
                        timeColumn.AddAttribute (timeCell, "markup", 2);
 
211
                        imageColumn.AddAttribute (imageCell, "pixbuf", 1);
 
212
                        nameColumn.AddAttribute (nameCell, "markup", 2);
 
213
                        timeColumn.AddAttribute (timeCell, "markup", 3);
123
214
                        
124
215
                        //create config and images directory
125
216
                        Gnome.Vfs.Vfs.Initialize();
128
219
                        //Directory.CreateDirectory(configDir);
129
220
                        //Directory.CreateDirectory(configDir + "images");
130
221
                        
 
222
//#if GTK_2_10
131
223
                        //status icon
132
224
                        statusIcon.FromPixbuf = new Gdk.Pixbuf(null, "gtwitter-22.png");
133
225
                        statusIcon.Tooltip = String.Format("gTwitter {0}", MainClass.version);
134
226
                        statusIcon.Activate += StatusIconActivate;
135
227
                        statusIcon.PopupMenu += StatusIconPopupMenu;
136
228
                        
 
229
                        PreferencesButton.Visible = false;
 
230
                        AboutButton.Visible = false;
 
231
                        QuitButton.Visible = false;
 
232
                        
 
233
//#endif
 
234
                        
 
235
                        AboutButton.Clicked += new EventHandler(this.AboutDialogActivate);
137
236
                        //Viewport vp1 = (Viewport)scrolledwindow1.Child;
138
237
                        //vp1.ModifyBg(StateType.Normal , new Gdk.Color(61,120,183));
139
238
                        
140
239
                        //PostEntry.GrabFocus();
141
240
                        Statusbar1.Push(0, "Connecting...");
 
241
                        
 
242
                        //create dialogs
 
243
                        aboutDialog = new AboutDialog(this);
 
244
                        preferencesWindow = new PreferencesWindow();
142
245
 
143
246
                        if ( passCheck.Length > 2 ) {
144
247
                                
147
250
                                getDataThread.Start();
148
251
                                //timeout n seconds if it takes to much time, kill the thread
149
252
                                //GLib.Timeout.Add (40000, new GLib.TimeoutHandler (TooLong));
150
 
 
151
253
                        }
152
254
                        else {
153
 
                                Statusbar1.Push(0, "You should enter username/password in Preferences.");
 
255
                                Statusbar1.Push(0, Catalog.GetString ("Enter username/password in Preferences."));
154
256
                                RefreshButton.Sensitive = true;
155
 
                                PostEntry.Sensitive = true;
 
257
                                //PostEntry.Sensitive = true;
 
258
                                menubar1.Sensitive = true;
 
259
                                preferencesWindow.Show();
156
260
                        }
157
261
 
158
262
                        ActivateRefresh();
159
263
                        
160
264
                        Gnome.Vfs.Vfs.Shutdown();
161
 
                        
162
 
                        aboutDialog = new AboutDialog(this);
163
265
                }
164
 
                
 
266
 
165
267
                //status icon click
166
268
                void StatusIconActivate(object o, EventArgs e)
167
269
                {
168
 
                        if (window1.Visible) {
 
270
                        if (mainWindow.Visible) {
169
271
                                
170
 
                                if (window1.IsActive) {
171
 
                                        window1.GetPosition(out x, out y);
172
 
                                        window1.Hide();
 
272
                                if (mainWindow.IsActive) {
 
273
                                        mainWindow.GetPosition(out x, out y);
 
274
                                        mainWindow.Hide();
173
275
                                }
174
276
                                else
175
 
                                        window1.Present();
 
277
                                        mainWindow.Present();
176
278
                        }
177
279
                        else {
178
 
                                window1.Move(x, y);
179
 
                                window1.Show();
 
280
                                mainWindow.Move(x, y);
 
281
                                mainWindow.Show();
 
282
                                
 
283
                                //stop blinking the status icon
 
284
                                //statusIcon.Blinking = false;
180
285
                        }       
181
286
                }
182
287
                void SHActivate(object o, EventArgs e)
183
288
                {
184
 
                        if (window1.Visible) {
 
289
                        if (mainWindow.Visible) {
185
290
 
186
 
                                window1.GetPosition(out x, out y);
187
 
                                window1.Hide();
 
291
                                mainWindow.GetPosition(out x, out y);
 
292
                                mainWindow.Hide();
188
293
                        }
189
294
                        else {
190
 
                                window1.Move(x, y);
191
 
                                window1.Show();
 
295
                                mainWindow.Move(x, y);
 
296
                                mainWindow.Show();
192
297
                        }       
193
298
                }
194
299
                //status icon menu
251
356
                //treeview change event
252
357
                protected virtual void OnTreeview1CursorChanged(object sender, System.EventArgs e)
253
358
                {
254
 
                        imageThread = new Thread(new ThreadStart(ImageThreadRoutine));
255
 
                        
256
 
                        //clear statusbar and image
257
 
                        //Statusbar1.Pop(0);
258
 
                        //Statusbar1.Pop(0);
259
 
                        UserImage.Stock = "gtk-missing-image";
260
 
                        UserImage.IconSize = 6;
261
 
 
262
 
                        //navigation
263
 
                        TreeIter iter = new TreeIter();
264
 
                    TreeModel model;
265
 
                    GLib.Value val = new GLib.Value ();
266
 
                    Treeview1.Selection.GetSelected (out model, out iter);
267
 
                    liststore.GetValue (iter, 0, ref val);
268
 
                    string navigation = (string) val;
269
 
                        
270
 
                        try {
271
 
                                
272
 
                                string text = readInfo.text[Int32.Parse(navigation) - 1];
273
 
                                UserName.Markup = "<span size='large' weight='bold'>" + readInfo.name[Int32.Parse(navigation) -1] + "</span>";
274
 
                                UserNLabel.Markup = "<span foreground='gray'>" + readInfo.screenName[Int32.Parse(navigation) -1] + "</span>";
275
 
                                UserText.Markup = "<span foreground='darkblue'>" + text + "</span>";
276
 
                                //UserText.Text =  readInfo.text[Int32.Parse(navigation) - 1];
277
 
                                
278
 
                                screenName = readInfo.screenName[Int32.Parse(navigation) -1];
279
 
                                
280
 
                                //use saved image
281
 
                                UserImage.FromFile = (configDir+"images/"+screenName+".png");
 
359
                        directM = false;
 
360
                        
 
361
                        if (!TweetView.Active) {
 
362
                                
 
363
                                TopNotebook.Page = 0;
 
364
                                NameLabel.Text = "";
 
365
                                ScreenNameLabel.Text = "";
 
366
                                LocationLabel.Text = "";
 
367
                                DescriptionLabel.Text = "";
 
368
                                urlLabel2.Text = "";
 
369
                                
 
370
                                imageThread = new Thread(new ThreadStart(ImageThreadRoutine));
 
371
                                
 
372
                                //clear statusbar and image
 
373
                                //Statusbar1.Pop(0);
 
374
                                //Statusbar1.Pop(0);
 
375
                                UserImage.Stock = "gtk-missing-image";
282
376
                                UserImage.IconSize = 6;
 
377
                                
 
378
                                //TODO: Add the user image in the notification
 
379
                                //TODO: atach the notification to the statusIcon
 
380
                                
 
381
                                //navigation
 
382
                                TreeIter iter = new TreeIter();
 
383
                            TreeModel model;
 
384
                            GLib.Value val = new GLib.Value ();
 
385
                            Treeview1.Selection.GetSelected (out model, out iter);
 
386
                            liststore.GetValue (iter, 0, ref val);
 
387
                            string navigation1 = (string) val;
 
388
                                
 
389
                                try {
 
390
                                        navigation = Int32.Parse(navigation1)-1;
 
391
                                } catch (ArgumentNullException) {}
 
392
                                
 
393
                                try {
 
394
                                        
 
395
                                        if ((int) client.Get (SOURCE_KEY) != 2) {
 
396
                                                
 
397
                                                string text = readInfo.text[navigation];
283
398
 
284
 
                                //if it doesn't exist fetch it
285
 
                                if (UserImage.Stock == "gtk-missing-image") {
286
 
                                        
287
 
                                        Statusbar1.Push(0, "Fetching user image...");
288
 
                                        imageUrl = readInfo.image[Int32.Parse(navigation) -1];
289
 
                                        
290
 
                                        imageThread.Start();
291
 
                                }
292
 
                        }
293
 
                        catch (ArgumentNullException) {
294
 
                                Statusbar1.Push(0, "No connection or wrong username/password.");
295
 
                        }
296
 
                        catch (NullReferenceException) {
297
 
                        }
 
399
                                                //call url detection
 
400
                                                text = UrlDetection(text);
 
401
                                                
 
402
                                                UserName.Markup = "<span size='large' weight='bold'>" + readInfo.name[navigation] + "</span>";
 
403
                                                UserNLabel.Markup = "<span foreground='gray'>" + readInfo.screenName[navigation] + "</span>";
 
404
                                                
 
405
                                                //fix & character
 
406
                                                text = text.Replace("&amp;lt;", "&lt;");
 
407
                                                text = text.Replace("&amp;gt;", "&gt;");
 
408
                                                urlLabel1.Markup = "<span foreground='darkblue'>" + text + "</span>";
 
409
                                                                                        
 
410
                                                screenName = readInfo.screenName[navigation];
 
411
                                                
 
412
                                                //use saved image
 
413
                                                UserImage.FromFile = (configDir+"images/"+screenName+".png");
 
414
                                                UserImage.IconSize = 6;
 
415
                                                
 
416
                                                /*
 
417
                                                if (mainWindow.Visible == false) {
 
418
                                                        if ((bool) client.Get (NOTIFY_KEY) == true)
 
419
                                                        {
 
420
                                                                if ((bool) client.Get (NOTIFY_PUBFRIE_KEY) == true || (bool) client.Get (NOTIFY_ALL_KEY) == true)
 
421
                                                                {
 
422
                                                                        
 
423
                                                                        Notification notify = new Notification ();
 
424
                                                                        notify.Summary = screenName;
 
425
                                                                        notify.Body = text;
 
426
                                                                        notify.Icon = Gdk.Pixbuf.LoadFromResource ("gtwitter-48.png");
 
427
                                                                        notify.Urgency = Urgency.Normal;
 
428
                                                                
 
429
                                                                        notify.Timeout = 4500;
 
430
                                                                        notify.Show ();
 
431
                                                                        //statusIcon.Blinking = true;
 
432
                                                                }
 
433
                                                        }
 
434
                                                }*/
 
435
                                                //if it doesn't exist fetch it
 
436
                                                if (UserImage.Stock == "gtk-missing-image") {
 
437
                                                        
 
438
                                                        Statusbar1.Push(0, Catalog.GetString ("Fetching user image..."));
 
439
                                                        imageUrl = readInfo.image[navigation];
 
440
                                                        
 
441
                                                        imageThread.Start();
 
442
                                                }
 
443
                                        }
 
444
                                        else {
 
445
                                                
 
446
                                                string text = readInfo.direct_text[navigation];
 
447
                
 
448
                                                //call url detection
 
449
                                                text = UrlDetection(text);
 
450
                                                
 
451
                                                UserName.Markup = String.Format("<span size='large' weight='bold'>{0}</span>",
 
452
                                                        Catalog.GetString ("Direct Messages"));
 
453
                                                UserNLabel.Markup = "<span foreground='gray'>" + readInfo.direct_screenName[navigation] + "</span>";
 
454
                                                urlLabel1.Markup = "<span foreground='darkblue'>" + text + "</span>";
 
455
                                                //urlLabel1.Text =  readInfo.text[Int32.Parse(navigation) - 1];
 
456
                                                
 
457
                                                screenName = readInfo.direct_screenName[navigation];
 
458
                                                
 
459
                                                //use saved image
 
460
                                                UserImage.FromFile = (configDir+"images/"+screenName+".png");
 
461
                                                UserImage.IconSize = 6;
 
462
                                                
 
463
                                                /*
 
464
                                                if (mainWindow.Visible == false) {
 
465
                                                        if ((bool) client.Get (NOTIFY_DIRECT_KEY) == true)
 
466
                                                        {
 
467
                                                                Notification notify = new Notification ();
 
468
                                                                notify.Summary = "Direct Tweet from " + readInfo.direct_screenName[navigation];
 
469
                                                                notify.Summary = text;
 
470
                                                                notify.Icon = Gdk.Pixbuf.LoadFromResource ("gtwitter-48.png");
 
471
                                                                notify.Timeout = 4500;
 
472
                                                                notify.Show ();
 
473
                                                                //statusIcon.Blinking = true;
 
474
                                                        }
 
475
                                                        
 
476
                                                        if ((bool) client.Get (NOTIFY_ALL_KEY) == true)
 
477
                                                        {
 
478
                                                                Notification notify = new Notification ();
 
479
                                                                notify.Summary = readInfo.direct_screenName[navigation];
 
480
                                                                notify.Summary = text;
 
481
                                                                notify.Icon = Gdk.Pixbuf.LoadFromResource ("gtwitter-48.png");
 
482
                                                                notify.Timeout = 4500;
 
483
                                                                notify.Show ();
 
484
                                                                //statusIcon.Blinking = true;
 
485
                                                        }
 
486
                                                }*/
 
487
                                        }
 
488
                                        
 
489
                                }
 
490
                                catch (ArgumentNullException) {
 
491
                                        Statusbar1.Push(0, Catalog.GetString ("No connection or wrong username/password."));
 
492
                                }
 
493
                                catch (NullReferenceException) {
 
494
                                }
 
495
                        }
 
496
                }
 
497
                
 
498
                //web url detection
 
499
                public static string UrlDetection(string text)
 
500
                {
 
501
                        // match protocol://url
 
502
                        Regex httpRegex = new Regex(@"([a-z]+://[^)(,!\s]+)", RegexOptions.IgnoreCase);
 
503
                        // match www. url
 
504
                        Regex wwwRegex = new Regex(@"(?:^|\s)(www\.[^)(,!\s]+)", RegexOptions.IgnoreCase);
 
505
                        // match @nickname
 
506
                        Regex atRegex = new Regex(@"@([^\s:,!]+)", RegexOptions.IgnoreCase);
 
507
                        
 
508
                        text = httpRegex.Replace(text, "<a href=\"$1\">$1</a>");
 
509
                        text = atRegex.Replace(text, "@<a href=\"http://twitter.com/$1\">$1</a>");
 
510
                        text = wwwRegex.Replace(text, "<a href=\"http://$1\">$1</a>");
 
511
                        
 
512
                        return text;
298
513
                }
299
514
 
300
515
                //preferences button
301
 
                bool once = true;
302
516
                protected virtual void OnPreferencesButtonClicked(object sender, System.EventArgs e)
303
517
                {
304
 
                        if (once) {
305
 
                                preferencesWindow = new PreferencesWindow();
306
 
                                once = false;
307
 
                        }
308
 
                        
309
518
                        preferencesWindow.Show();
310
519
                }
311
520
                
362
571
                                
363
572
                                RefreshButton.Sensitive = false;
364
573
                                PostEntry.Sensitive = false;
 
574
                                menubar1.Sensitive = false;
365
575
                                
366
 
                                Statusbar1.Push(0, "Connecting...");
 
576
                                Statusbar1.Push(0, Catalog.GetString ("Connecting..."));
367
577
                                refreshThread = new Thread(new ThreadStart(DataThreadRoutine));
368
578
 
369
579
                                refreshThread.Start();
375
585
                //refresh button
376
586
                protected virtual void OnRefreshButtonClicked(object sender, System.EventArgs e)
377
587
                {
378
 
                        Statusbar1.Push(0, "Connecting...");
 
588
                        Statusbar1.Push(0, Catalog.GetString ("Connecting..."));
379
589
                        refreshThread = new Thread(new ThreadStart(DataThreadRoutine));
380
590
        
381
591
                        UserImage.Stock = "gtk-network";
382
592
                        UserImage.IconSize = 6;
383
 
                        UserName.Markup = "<span size='large' weight='bold'>Fetching data...</span>";
 
593
                        UserName.Markup = String.Format("<span size='large' weight='bold'>{0}</span>",
 
594
                                Catalog.GetString ("Fetching data..."));
384
595
                        UserNLabel.Markup = "";
385
 
                        UserText.Text = "";
 
596
                        urlLabel1.Text = "";
386
597
                        
387
598
                        refreshThread.Start();
388
599
                        //GLib.Timeout.Add (40000, new GLib.TimeoutHandler (TooLong));
389
600
                        
390
601
                        RefreshButton.Sensitive = false;
391
602
                        PostEntry.Sensitive = false;
 
603
                        menubar1.Sensitive = false;
392
604
                }
393
605
                
394
606
                //user image set
398
610
                                Gtk.Application.Invoke (delegate {
399
611
                                        //get user image
400
612
                                        //try {
401
 
                                                UserImage.FromPixbuf = getTwitterData.GetUserImage(imageUrl, configDir);
 
613
                                                UserImage.FromPixbuf = getTwitterData.GetUserImage(imageUrl);
402
614
                                        //} catch (NullReferenceException) {Console.WriteLine("nullll");}
403
615
                                        if (UserImage.Pixbuf == null) {
404
 
                                                Statusbar1.Push(0, "Unable to get user image");
 
616
                                                Statusbar1.Push(0, Catalog.GetString ("Unable to get user image"));
405
617
                                                UserImage.Stock = "gtk-missing-image";
406
618
                                                UserImage.IconSize = 6;
407
619
                                        }
414
626
                        }
415
627
                        catch (Exception ex) {
416
628
                                Gtk.Application.Invoke (delegate {
417
 
                                        Statusbar1.Push(0, "Unable to get user image");
 
629
                                        Statusbar1.Push(0, Catalog.GetString("Unable to get user image"));
418
630
                                        UserImage.Stock = "gtk-missing-image";
419
631
                                        UserImage.IconSize = 6;
420
632
                                });
430
642
                //populate treeview
431
643
                public void PopulateTreeviewThreadRoutine()
432
644
                {
433
 
                        Gtk.Application.Invoke (delegate {
434
 
                                
435
 
                                liststore.Clear();
436
 
                        
437
 
                                try {
438
 
                                        
439
 
                                        string si, name, time;
440
 
                                        for (int i = 0; i < readInfo.statusCount; i++) {
441
 
                                                
442
 
                                                si = (i+1).ToString();
443
 
                                                name = String.Format("<span size='small'>{0}</span>", readInfo.name[i]);
444
 
                                                time = String.Format("<span size='small'>{0}</span>", readInfo.relative_time[i]);
445
 
                                                
446
 
                                                //Console.WriteLine(si + name + time);
447
 
                                                liststore.AppendValues (si, name, time);
448
 
                                        }
449
 
 
450
 
                                        Treeview1.Model = liststore;
451
 
                                        
452
 
                                        if (liststore != null)
453
 
                                                Treeview1.SetCursor(TreePath.NewFirst(), null, false);
454
 
                                        
455
 
                                }
456
 
                                catch (NullReferenceException ex) {
457
 
                                        if (MainClass.debug) {
458
 
                                                Console.WriteLine("Treeview exception: PopulateTreeview()");
459
 
                                                Console.WriteLine(ex.StackTrace);
460
 
                                        }
461
 
                                }
462
 
                                
463
 
                                RefreshButton.Sensitive = true;
464
 
                                PostEntry.Sensitive = true;
465
 
                        });
466
 
                }
 
645
                        //TweetView not activated
 
646
                        if (!TweetView.Active) {
 
647
                                
 
648
                                Gtk.Application.Invoke (delegate {
 
649
                                        
 
650
                                        liststore.Clear();
 
651
                                        timeColumn.Visible = true;
 
652
                                        imageColumn.Visible = false;
 
653
                                
 
654
                                        try {
 
655
                                                
 
656
                                                if ( (int) client.Get (SOURCE_KEY) != 2 ) {
 
657
                                                        string si, name, time;
 
658
                                                        for (int i = 0; i < readInfo.statusCount; i++) {
 
659
                                                                
 
660
                                                                si = (i+1).ToString();
 
661
                                                                name = String.Format("<span size='small'>{0}</span>", readInfo.name[i]);
 
662
                                                                time = String.Format("<span size='small'>{0}</span>", readInfo.relative_time[i]);
 
663
                                                                
 
664
                                                                //Console.WriteLine(si + name + time);
 
665
                                                                liststore.AppendValues (si,
 
666
                                                                                        null,
 
667
                                                                                        name,
 
668
                                                                                        time);
 
669
                                                        }
 
670
                                                }
 
671
                                                else {
 
672
                                                        
 
673
                                                        string si, screen_name, time;
 
674
                                                        for (int i = 0; i < readInfo.direct_statusCount; i++) {
 
675
                                                                
 
676
                                                                si = (i+1).ToString();
 
677
                                                                screen_name = String.Format("<span size='small'>{0}</span>", readInfo.direct_screenName[i]);
 
678
                                                                time = String.Format("<span size='small'>{0}</span>", readInfo.direct_relative_time[i]);
 
679
                                                                
 
680
                                                                liststore.AppendValues (si,
 
681
                                                                                        null,
 
682
                                                                                        screen_name,
 
683
                                                                                        time);
 
684
                                                        }
 
685
                                                }
 
686
                                                
 
687
                                                Treeview1.Model = liststore;
 
688
                                                
 
689
                                                if (liststore != null)
 
690
                                                        Treeview1.SetCursor(TreePath.NewFirst(), null, false);
 
691
                                                
 
692
                                        }
 
693
                                        catch (NullReferenceException ex) {
 
694
                                                if (MainClass.debug) {
 
695
                                                        Console.WriteLine("Treeview exception: PopulateTreeview()");
 
696
                                                        Console.WriteLine(ex.StackTrace);
 
697
                                                }
 
698
                                        }
 
699
                                        
 
700
                                        RefreshButton.Sensitive = true;
 
701
                                        PostEntry.Sensitive = true;
 
702
                                        menubar1.Sensitive = true;
 
703
                                });
 
704
                        }
 
705
                        //TweetView activated
 
706
                        else {
 
707
                        
 
708
                                Gtk.Application.Invoke (delegate {
 
709
                                
 
710
                                        liststore.Clear();
 
711
                                        imageColumn.Visible = true;
 
712
                                        timeColumn.Visible = false;
 
713
                                
 
714
                                        try {
 
715
                                                
 
716
                                                if ( (int) client.Get (SOURCE_KEY) != 2 ) {
 
717
                                                        string si, text;
 
718
                                                        for (int i = 0; i < readInfo.statusCount; i++) {
 
719
                                                                
 
720
                                                                si = (i+1).ToString();
 
721
                                                                
 
722
                                                                text = String.Format("<b>{1}</b> <span size='small' foreground='gray'>({2})</span>\n<span size='small' foreground='darkblue'>{0}</span>", 
 
723
                                                                                     readInfo.text[i], readInfo.name[i], readInfo.relative_time[i]);
 
724
                                                                
 
725
                                                                String imageFile = (configDir+"images/"+readInfo.screenName[i]+".png");
 
726
                                                                
 
727
                                                                Gdk.Pixbuf uPixbuf;
 
728
                                                                try {
 
729
                                                                        
 
730
                                                                        uPixbuf = new Gdk.Pixbuf(imageFile);
 
731
                                                                }
 
732
                                                                catch (GLib.GException) {
 
733
                        
 
734
                                                                        imageUrl = readInfo.image[i];
 
735
                                                                        
 
736
                                                                        uPixbuf = getTwitterData.GetUserImage(imageUrl);
 
737
                                                                        
 
738
                                                                        //save friends image if it doesn't exist
 
739
                                                                        if ((int) client.Get (SOURCE_KEY) == 0 && !System.IO.File.Exists(configDir + "images/" + readInfo.screenName[i] + ".png"))
 
740
                                                                                uPixbuf.Save(configDir + "images/" + readInfo.screenName[i] + ".png", "png");
 
741
                                                                        
 
742
                                                                        //uPixbuf = new Gdk.Pixbuf(null, "gtwitter-22.png");
 
743
                                                                        //Queue(imageUrl);
 
744
                                                                }
 
745
                                                                
 
746
                                                                liststore.AppendValues (si,
 
747
                                                                                        uPixbuf,
 
748
                                                                                        text,
 
749
                                                                                        null);
 
750
                                                        }
 
751
                                                }
 
752
                                                else {
 
753
                                                        
 
754
                                                        string si, text;
 
755
                                                        for (int i = 0; i < readInfo.direct_statusCount; i++) {
 
756
                                                                
 
757
                                                                si = (i+1).ToString();
 
758
                                                                text = String.Format("<b>{1}</b> <span size='small' foreground='gray'>({2})</span>\n<span size='small' foreground='darkblue'>{0}</span>",
 
759
                                                                                     readInfo.direct_text[i], readInfo.direct_screenName[i], readInfo.direct_relative_time[i]);
 
760
                                                                
 
761
                                                                liststore.AppendValues (si,
 
762
                                                                                        new Gdk.Pixbuf(null, "gtwitter-48.png"),
 
763
                                                                                        text,
 
764
                                                                                        null);
 
765
                                                        }
 
766
                                                }
 
767
                                                
 
768
                                                Treeview1.Model = liststore;
 
769
                                                
 
770
                                                if (liststore != null)
 
771
                                                        Treeview1.SetCursor(TreePath.NewFirst(), null, false);
 
772
                                                
 
773
                                        }
 
774
                                        catch (NullReferenceException ex) {
 
775
                                                if (MainClass.debug) {
 
776
                                                        Console.WriteLine("Treeview exception: PopulateTreeview()");
 
777
                                                        Console.WriteLine(ex.StackTrace);
 
778
                                                }
 
779
                                        }
 
780
                                        
 
781
                                        RefreshButton.Sensitive = true;
 
782
                                        PostEntry.Sensitive = true;
 
783
                                        menubar1.Sensitive = true;
 
784
                                });
 
785
                        }
467
786
                
 
787
                }
 
788
                /*
 
789
                HttpWebRequest req;
 
790
                void Queue (string url)
 
791
                {
 
792
                        Gdk.Pixbuf pix1;
 
793
                        
 
794
                        req = (HttpWebRequest) WebRequest.Create (url);
 
795
                        req.KeepAlive = false;
 
796
                        
 
797
                        WebResponse resp = null;
 
798
                        
 
799
                        resp = req.GetResponse ();
 
800
                        req.BeginGetRequestStream (mycallback, this);
 
801
                        
 
802
                        
 
803
                        Stream s = resp.GetResponseStream ();
 
804
                        pix1 = new Gdk.Pixbuf (s);
 
805
 
 
806
                        
 
807
                        resp.Close ();
 
808
                        
 
809
                }
 
810
 
 
811
                void mycallback (IAsyncResult r)
 
812
                {
 
813
                    req.EndGetRequestStream (r);
 
814
                        
 
815
                    Gtk.Application.Invoke (delegate {
 
816
                        Console.WriteLine("sdddddddd");
 
817
                    });
 
818
 
 
819
                } 
 
820
                */
468
821
                
469
822
                
470
823
                //thread function to call GetTwitterData
487
840
                                        if ( getTwitterData.GetTwitterFriendsData(TwitterFriendsUrl, usernameKey, passKey, configDir) ) {
488
841
                                                
489
842
                                                Gtk.Application.Invoke (delegate {
490
 
                                                        Statusbar1.Push(0, "Connection complete! Populating with friends data.");
491
 
                                                        UserText.Selectable = true;
 
843
                                                        Statusbar1.Push(0, Catalog.GetString("Connection ok, populating with data."));
 
844
                                                        urlLabel1.Selectable = true;
492
845
                                                });
493
846
                                                
494
847
                                                //start thread
496
849
                                        }
497
850
                                        else {
498
851
                                                Gtk.Application.Invoke (delegate {
499
 
                                                        Statusbar1.Push(0, "Connection failed! No connection or wrong username/password.");
500
 
                                                        UserName.Markup = "<span size='large' weight='bold'>Connection failed!</span>";
 
852
                                                        Statusbar1.Push(0, Catalog.GetString ("Connection failed!"));
 
853
                                                        UserName.Markup = String.Format("<span size='large' weight='bold'>{0}</span>",
 
854
                                                                Catalog.GetString("Connection failed!"));
501
855
                                                        RefreshButton.Sensitive = true;
502
 
                                                        PostEntry.Sensitive = true;
 
856
                                                        //PostEntry.Sensitive = true;
 
857
                                                        menubar1.Sensitive = true;
503
858
                                                });
504
859
                                        }
505
860
 
512
867
                                        if ( getTwitterData.GetTwitterPublicData(TwitterPublicUrl, configDir) ) {
513
868
 
514
869
                                                Gtk.Application.Invoke (delegate {
515
 
                                                        Statusbar1.Push(0, "Connection complete! Populating with public data.");
516
 
                                                        UserText.Selectable = true;
 
870
                                                        Statusbar1.Push(0, Catalog.GetString("Connection ok, populating with data."));
 
871
                                                        urlLabel1.Selectable = true;
517
872
                                                });
518
873
                                                
519
874
                                                //start thread
521
876
                                        }
522
877
                                        else {
523
878
                                                Gtk.Application.Invoke (delegate {
524
 
                                                        Statusbar1.Push(0, "Connection failed! No internet connection.");
525
 
                                                        UserName.Markup = "<span size='large' weight='bold'>Connection failed!</span>";
 
879
                                                        Statusbar1.Push(0, Catalog.GetString ("Connection failed!"));
 
880
                                                        UserName.Markup = String.Format("<span size='large' weight='bold'>{0}</span>",
 
881
                                                                Catalog.GetString ("Connection failed!"));
526
882
                                                        RefreshButton.Sensitive = true;
527
 
                                                        PostEntry.Sensitive = true;
 
883
                                                        //PostEntry.Sensitive = true;
 
884
                                                        menubar1.Sensitive = true;
528
885
                                                });
529
886
                                        }
530
887
                                        
531
888
                                        GLib.Timeout.Add (3000, new GLib.TimeoutHandler (ClearStatusbar));
532
889
                                }
 
890
                                
 
891
                                if (sourceKey == 2) {
 
892
 
 
893
                                        if ( getTwitterData.GetTwitterDirectData(TwitterDirectUrl, usernameKey, passKey, configDir) ) {
 
894
                                                
 
895
                                                Gtk.Application.Invoke (delegate {
 
896
                                                        Statusbar1.Push(0, Catalog.GetString("Connection ok, populating with data."));
 
897
                                                        urlLabel1.Selectable = true;
 
898
                                                });
 
899
                                                
 
900
                                                //start thread
 
901
                                                readStoredData.Start();
 
902
                                        }
 
903
                                        else {
 
904
                                                Gtk.Application.Invoke (delegate {
 
905
                                                        Statusbar1.Push(0, Catalog.GetString("Connection failed!"));
 
906
                                                        UserName.Markup = String.Format("<span size='large' weight='bold'>{0}</span>",
 
907
                                                                Catalog.GetString("Connection failed!"));
 
908
                                                        RefreshButton.Sensitive = true;
 
909
                                                        //PostEntry.Sensitive = true;
 
910
                                                        menubar1.Sensitive = true;
 
911
                                                });
 
912
                                        }
 
913
 
 
914
                                        GLib.Timeout.Add (3000, new GLib.TimeoutHandler (ClearStatusbar));
 
915
                                }
533
916
                        }
534
917
                        catch (NoSuchKeyException) {
535
918
                                
536
919
                                Gtk.Application.Invoke (delegate {
537
 
                                        Statusbar1.Push(0, "Connection failed! No connection or wrong username/password.");
538
 
                                        UserName.Markup = "<span size='large' weight='bold'>Connection failed!</span>";
 
920
                                        Statusbar1.Push(0, Catalog.GetString("Connection failed!"));
 
921
                                        UserName.Markup = String.Format("<span size='large' weight='bold'>{0}</span>",
 
922
                                                Catalog.GetString("Connection failed!"));
539
923
                                        RefreshButton.Sensitive = true;
540
924
                                        //PostEntry.Sensitive = true;
541
925
                                });
542
926
                        }
543
 
                        
544
 
                        
545
927
                }
546
928
                
547
929
                //clear statusbar timeout
558
940
                }
559
941
                
560
942
                //expose event, cairo/composite
 
943
                // FIXME: IMPORTANT! Fix this event so it compiles under Runtime 2.0 (gmcs)
 
944
                /*
561
945
                protected virtual void OnExposeEvent(object o, Gtk.ExposeEventArgs e)
562
946
                {
563
947
                        
573
957
                                
574
958
                                compositeInterface.DrawComposite(cr, width, height);
575
959
                        }
576
 
                }
 
960
                }*/
577
961
                
578
962
                //window delete event - hides window
579
963
                protected void OnDeleteEvent (object sender, DeleteEventArgs a)
580
964
                {
581
 
                        window1.GetPosition(out x, out y);
582
 
                        window1.Hide();
 
965
                        mainWindow.GetPosition(out x, out y);
 
966
                        mainWindow.Hide();
583
967
 
584
968
                        a.RetVal = true;
585
969
                }
593
977
                        try {
594
978
                                
595
979
                                //store window position
596
 
                                window1.GetPosition(out x, out y);
 
980
                                mainWindow.GetPosition(out x, out y);
597
981
                                client.Set(WINDOW_X_KEY, x);
598
982
                                client.Set(WINDOW_Y_KEY, y);
599
 
                                client.Set(WINDOW_WIDTH_KEY, window1.Allocation.Width);
600
 
                                client.Set(WINDOW_HEIGHT_KEY, window1.Allocation.Height);
 
983
                                client.Set(WINDOW_WIDTH_KEY, mainWindow.Allocation.Width);
 
984
                                client.Set(WINDOW_HEIGHT_KEY, mainWindow.Allocation.Height);
601
985
                                
602
986
                                if (imageThread != null) {
603
987
                                        imageThread.Abort();
619
1003
                {
620
1004
                        PostEntry.Sensitive = false;
621
1005
                        RefreshButton.Sensitive = false;
 
1006
                        menubar1.Sensitive = false;
 
1007
                        
622
1008
                        try {
623
1009
                                getDataThread.Abort();
624
1010
                                refreshThread.Abort();
636
1022
                {
637
1023
                        string post = PostEntry.Text;
638
1024
                        
 
1025
                        //trying to fix & character escaping
 
1026
                        //post = post.Replace("&amp;", "&");
 
1027
                        //Console.WriteLine("A " + post);
 
1028
                        
639
1029
                        string usernameKey = "";
640
1030
                        string passKey = "";
641
1031
                                                
643
1033
                                usernameKey = (string) client.Get (USERNAME_KEY);
644
1034
                                passKey = (string) client.Get (PASSWORD_KEY);
645
1035
                                
646
 
                                if (post.Length > 3) {
 
1036
                                if (post.Length > 2) {
647
1037
                                        
648
1038
                                        Gtk.Application.Invoke (delegate {
649
 
                                                Statusbar1.Push(0, "Posting to Twitter...");
 
1039
                                                Statusbar1.Push(0, Catalog.GetString("Posting to Twitter..."));
650
1040
                                        });
651
1041
                                        
652
1042
                                        //post to twitter
653
1043
                                        if (!postToTwitter.PostDataToTwitter(TwitterPostUrl, usernameKey, passKey, post))
654
1044
                                        {
655
1045
                                                Gtk.Application.Invoke (delegate {
656
 
                                                        Statusbar1.Push(0, "Posting failed! No connection or wrong username/password.");
 
1046
                                                        Statusbar1.Push(0, Catalog.GetString("Posting failed!"));
657
1047
                                                });
658
1048
                                        }
659
1049
                                        else {
660
1050
                                                Gtk.Application.Invoke (delegate {
661
 
                                                        Statusbar1.Push(0, "Successfully Posted!");
 
1051
                                                        Statusbar1.Push(0, Catalog.GetString("Successfully Posted!"));
662
1052
                                                });
663
1053
                                                GLib.Timeout.Add (2000, new GLib.TimeoutHandler (ClearStatusbar));
664
1054
                                                
669
1059
                                }
670
1060
                                else {
671
1061
                                        Gtk.Application.Invoke (delegate {
672
 
                                                Statusbar1.Push(0, "At least write something :)");
 
1062
                                                Statusbar1.Push(0, Catalog.GetString("At least write something :)"));
673
1063
                                        });
674
1064
                                        GLib.Timeout.Add (3000, new GLib.TimeoutHandler (ClearStatusbar));
675
1065
                                }
676
1066
                                
677
 
                                PostEntry.Text = "";
 
1067
                                PostEntry.Text = Catalog.GetString("What are you doing?");
678
1068
                                PostEntry.Sensitive = true;
 
1069
                                RefreshButton.Sensitive = true;
 
1070
                                menubar1.Sensitive = true;
679
1071
                        }
680
1072
                        catch (NoSuchKeyException) {
681
1073
                                
682
1074
                                Gtk.Application.Invoke (delegate {
683
 
                                        Statusbar1.Push(0, "Posting failed! No connection or wrong username/password.");
 
1075
                                        Statusbar1.Push(0, Catalog.GetString("Posting failed!"));
684
1076
                                });
685
1077
                        }
686
1078
                }
687
1079
                bool RefreshAfterPost()
688
1080
                {
689
 
                        Statusbar1.Push(0, "Connecting...");
 
1081
                        Statusbar1.Push(0, Catalog.GetString("Connecting..."));
690
1082
                        refreshThread = new Thread(new ThreadStart(DataThreadRoutine));
691
1083
        
692
1084
                        refreshThread.Start();
710
1102
                protected virtual void OnPostEntryFocusOutEvent(object o, Gtk.FocusOutEventArgs args)
711
1103
                {
712
1104
                        if (PostEntry.Text.Length < 1)
713
 
                                PostEntry.Text = "What are you doing?";
 
1105
                                PostEntry.Text = Catalog.GetString("What are you doing?");
714
1106
                }
715
1107
 
716
1108
                protected virtual void OnPostEntryFocusInEvent(object o, Gtk.FocusInEventArgs args)
722
1114
                //140 characters counter
723
1115
                protected virtual void OnPostEntryChanged(object sender, System.EventArgs e)
724
1116
                {
725
 
                        StatusLabel.Markup = String.Format("<span foreground='gray'>{0}</span>", (140 - PostEntry.Text.Length).ToString());
726
 
                }
727
 
 
728
 
 
 
1117
                        // don't know if I should add a Catalog.GetString here
 
1118
                        if (PostEntry.Text == "What are you doing?")
 
1119
                                StatusLabel.Markup = "<span foreground='gray'>140</span>";
 
1120
                        else
 
1121
                                StatusLabel.Markup = String.Format("<span foreground='gray'>{0}</span>", (140 - PostEntry.Text.Length).ToString());
 
1122
                }
 
1123
 
 
1124
                //user details show when clicking on user image
 
1125
                bool onceud = true;
 
1126
                private UrlLabel urlLabel2 = new UrlLabel();
 
1127
                protected virtual void OnEventbox1ButtonPressEvent(object o, Gtk.ButtonPressEventArgs args)
 
1128
                {
 
1129
                        if (onceud) {
 
1130
 
 
1131
                                table1.Attach(urlLabel2, 1, 2, 4, 5, AttachOptions.Fill, AttachOptions.Shrink, 0, 0);
 
1132
                                urlLabel2.Xalign = 0.0f;
 
1133
                                urlLabel2.Show();
 
1134
                                
 
1135
                                urlLabel2.UrlActivated += delegate(object obj, UrlActivatedArgs args2) {
 
1136
                                        Process.Start("gnome-open", args2.Url);
 
1137
                                };
 
1138
                                
 
1139
                                onceud = false;
 
1140
                        }
 
1141
                        
 
1142
                        if (TopNotebook.Page == 0 && !Direct.Active) {
 
1143
                                
 
1144
                                TopNotebook.Page = 1;
 
1145
                                SetLabels();
 
1146
                        }
 
1147
                        else {
 
1148
                                
 
1149
                                TopNotebook.Page = 0;
 
1150
                                
 
1151
                                NameLabel.Text = "";
 
1152
                                ScreenNameLabel.Text = "";
 
1153
                                LocationLabel.Text = "";
 
1154
                                DescriptionLabel.Text = "";
 
1155
                                urlLabel2.Text = "";
 
1156
                        }
 
1157
                }
 
1158
                public void SetLabels() //set user detail labels
 
1159
                {
 
1160
                        NameLabel.Markup = readInfo.name[navigation];
 
1161
                        ScreenNameLabel.Markup = readInfo.screenName[navigation];
 
1162
                        LocationLabel.Markup = readInfo.location[navigation];
 
1163
                        DescriptionLabel.Markup = readInfo.description[navigation];
 
1164
                        string urlString = readInfo.url[navigation];
 
1165
                        urlLabel2.Markup = String.Format("<a href=\"{0}\">{1}</a>", urlString, urlString);
 
1166
                        
 
1167
                        if (NameLabel.Text.Length < 2) {
 
1168
                                label1.Visible = false;
 
1169
                                NameLabel.Visible = false;
 
1170
                        }
 
1171
                        else {
 
1172
                                label1.Visible = true;
 
1173
                                NameLabel.Visible = true;
 
1174
                        }
 
1175
                        
 
1176
                        if (ScreenNameLabel.Text.Length < 2) {
 
1177
                                label2.Visible = false;
 
1178
                                ScreenNameLabel.Visible = false;
 
1179
                        }
 
1180
                        else {
 
1181
                                label2.Visible = true;
 
1182
                                ScreenNameLabel.Visible = true;
 
1183
                        }
 
1184
                        
 
1185
                        if (LocationLabel.Text.Length < 2) {
 
1186
                                label3.Visible = false;
 
1187
                                LocationLabel.Visible = false;
 
1188
                        }
 
1189
                        else {
 
1190
                                LocationLabel.Visible = true;
 
1191
                                label3.Visible = true;
 
1192
                        }
 
1193
                        
 
1194
                        if (DescriptionLabel.Text.Length < 2) {
 
1195
                                label4.Visible = false;
 
1196
                                DescriptionLabel.Visible = false;
 
1197
                        }
 
1198
                        else {
 
1199
                                label4.Visible = true;
 
1200
                                DescriptionLabel.Visible = true;
 
1201
                        }
 
1202
                        
 
1203
                        if (urlLabel2.Text.Length < 2) {
 
1204
                                label5.Visible = false;
 
1205
                                urlLabel2.Visible = false;
 
1206
                        }
 
1207
                        else {
 
1208
                                label5.Visible = true;
 
1209
                                urlLabel2.Visible = true;
 
1210
                        }
 
1211
                }
 
1212
                
 
1213
                //screen name event
 
1214
                protected virtual void OnUserNEventboxButtonPressEvent(object o, Gtk.ButtonPressEventArgs args)
 
1215
                {
 
1216
                        if (!directM) {
 
1217
                                UserNLabel.Markup = screenName;
 
1218
                                directM = true;
 
1219
                        }
 
1220
                        else {
 
1221
                                UserNLabel.Markup = "<span foreground='gray'>" + screenName + "</span>";
 
1222
                                directM = true;
 
1223
                        }
 
1224
                                
 
1225
                }
 
1226
 
 
1227
 
 
1228
                //source radio buttons
 
1229
                protected virtual void OnFriendsActivated(object sender, System.EventArgs e)
 
1230
                {
 
1231
                        if (Friends.Active) {
 
1232
                                client.Set (SOURCE_KEY, 0);
 
1233
                                
 
1234
                                Source.Label = Friends.Label;
 
1235
                                
 
1236
                                readStoredData = new Thread(new ThreadStart(ReadStoredData));
 
1237
                                readStoredData.Start();
 
1238
                        }
 
1239
                }
 
1240
                protected virtual void OnPublicActivated(object sender, System.EventArgs e)
 
1241
                {
 
1242
                        if (Public.Active) {
 
1243
                                client.Set (SOURCE_KEY, 1);
 
1244
                                
 
1245
                                Source.Label = Public.Label;
 
1246
                                
 
1247
                                readStoredData = new Thread(new ThreadStart(ReadStoredData));
 
1248
                                readStoredData.Start();
 
1249
                        }
 
1250
                }
 
1251
                protected virtual void OnDirectActivated(object sender, System.EventArgs e)
 
1252
                {
 
1253
                        if (Direct.Active) {
 
1254
                                client.Set (SOURCE_KEY, 2);
 
1255
                                
 
1256
                                Source.Label = Direct.Label;
 
1257
                                
 
1258
                                readStoredData = new Thread(new ThreadStart(ReadStoredData));
 
1259
                                readStoredData.Start();
 
1260
                        }
 
1261
                }
 
1262
                
 
1263
                protected virtual void OnTweetViewActivated(object sender, System.EventArgs e)
 
1264
                {
 
1265
                        if (TweetView.Active) {
 
1266
                        
 
1267
                                client.Set(FANCY_UI_KEY, true);
 
1268
                                
 
1269
                                vpaned1.Child1.Visible = false;
 
1270
                                alignment1.TopPadding = 6;
 
1271
                                
 
1272
                                populateTreeview = new Thread(new ThreadStart(PopulateTreeviewThreadRoutine));
 
1273
                                //start thread
 
1274
                                populateTreeview.Start();
 
1275
                        }
 
1276
                        else {
 
1277
                        
 
1278
                                client.Set(FANCY_UI_KEY, false);
 
1279
 
 
1280
                                vpaned1.Child1.Visible = true;
 
1281
                                alignment1.TopPadding = 0;
 
1282
                                
 
1283
                                populateTreeview = new Thread(new ThreadStart(PopulateTreeviewThreadRoutine));
 
1284
                                //start thread
 
1285
                                populateTreeview.Start();
 
1286
                        }
 
1287
                }
 
1288
 
 
1289
                //focus post entry on window focus
 
1290
                protected virtual void OnFocusInEvent(object o, Gtk.FocusInEventArgs args)
 
1291
                {
 
1292
                        PostEntry.GrabFocus();
 
1293
                }
 
1294
 
 
1295
                
 
1296
                
729
1297
        }
730
1298
}
731
1299