20
20
namespace Imendio.Blam {
22
22
public class Application : Program {
23
public static Application TheApp;
25
[Widget] Gtk.Window mainWindow = null;
26
[Widget] Gtk.ScrolledWindow channelListSw = null;
27
[Widget] Gtk.ScrolledWindow itemListSw = null;
28
[Widget] Gtk.Paned channelPaned = null;
29
[Widget] Gtk.Paned itemPaned = null;
30
[Widget] Gtk.Label blogNameLabel = null;
31
[Widget] Gtk.Statusbar statusbar = null;
32
[Widget] Gtk.Label channelsLabel = null;
33
private string channelsLabelText;
35
[Widget] Gtk.MenuItem refreshChannelMenuItem = null;
36
[Widget] Gtk.MenuItem markChannelAsReadMenuItem = null;
37
[Widget] Gtk.MenuItem removeChannelMenuItem = null;
38
[Widget] Gtk.MenuItem editChannelMenuItem = null;
40
[Widget] Gtk.MenuItem markEntryAsUnreadMenuItem = null;
41
[Widget] Gtk.MenuItem nextUnreadMenuItem = null;
23
public static Application TheApp;
25
[Widget] Gtk.Window mainWindow = null;
26
[Widget] Gtk.ScrolledWindow channelListSw = null;
27
[Widget] Gtk.ScrolledWindow itemListSw = null;
28
[Widget] Gtk.Paned channelPaned = null;
29
[Widget] Gtk.Paned itemPaned = null;
30
[Widget] Gtk.Label blogNameLabel = null;
31
[Widget] Gtk.Statusbar statusbar = null;
32
[Widget] Gtk.Label channelsLabel = null;
33
private string channelsLabelText;
35
[Widget] Gtk.MenuItem refreshChannelMenuItem = null;
36
[Widget] Gtk.MenuItem markChannelAsReadMenuItem = null;
37
[Widget] Gtk.MenuItem removeChannelMenuItem = null;
38
[Widget] Gtk.MenuItem editChannelMenuItem = null;
40
[Widget] Gtk.MenuItem markEntryAsUnreadMenuItem = null;
41
[Widget] Gtk.MenuItem editEntryKeywordsMenuItem = null;
42
[Widget] Gtk.MenuItem nextUnreadMenuItem = null;
43
44
//[Widget] Gtk.MenuItem printMenuItem;
45
private Gtk.FileSelection exportFileDialog;
47
private ChannelList channelList;
48
private ItemList itemList;
49
private ItemView itemView;
51
private TrayIcon trayIcon;
53
public static string BaseDir;
55
private MessageConnection messageConn;
57
private AddChannelDialog addChannelDialog;
58
private ChannelDialog channelDialog;
59
private PreferencesDialog preferencesDialog;
60
private OpmlDialog opmlDialog;
62
private ChannelCollection mCollection;
64
private uint mAutoRefreshId;
66
private MessageConnection.MessageReceivedHandler mIpcHandler;
73
public static TargetEntry[] DragEntries = new TargetEntry[] {
74
new TargetEntry("STRING", 0, (uint)TargetType.String),
75
new TargetEntry("text/plain", 0, (uint)TargetType.String),
76
new TargetEntry("text/uri-list", 0, (uint)TargetType.UriList)
79
public Gtk.Window Window {
81
return (Gtk.Window) mainWindow;
85
public ChannelCollection CCollection {
91
public ItemList ItemList {
46
private Gtk.FileSelection exportFileDialog;
48
private ChannelList channelList;
49
private ItemList itemList;
50
private ItemView itemView;
52
private ThemeManager mThemeManager;
54
private TrayIcon trayIcon;
56
public static string BaseDir;
58
private MessageConnection messageConn;
60
private AddChannelDialog addChannelDialog;
61
private ChannelDialog channelDialog;
62
private PreferencesDialog preferencesDialog;
63
private OpmlDialog opmlDialog;
65
private ChannelCollection mCollection;
67
private uint mAutoRefreshId;
70
private MessageConnection.MessageReceivedHandler mIpcHandler;
77
public static TargetEntry[] DragEntries = new TargetEntry[] {
78
new TargetEntry("STRING", 0, (uint)TargetType.String),
79
new TargetEntry("text/plain", 0, (uint)TargetType.String),
80
new TargetEntry("text/uri-list", 0, (uint)TargetType.UriList)
83
public Gtk.Window Window {
85
return(Gtk.Window) mainWindow;
89
public ChannelCollection CCollection {
95
public ItemList ItemList {
101
public ThemeManager ThemeManager {
103
return mThemeManager;
97
107
public Application (string[] args, params object[] props) : base ("Blam", Defines.VERSION, Modules.UI, args, props)
99
messageConn = new MessageConnection ("Blam");
100
if (!messageConn.IsServer) {
101
messageConn.Send ("ShowWindow");
102
messageConn.Close ();
103
Gdk.Global.NotifyStartupComplete ();
104
Environment.Exit (0);
107
mIpcHandler = new MessageConnection.MessageReceivedHandler (MessageReceivedCb) ;
108
messageConn.SetCallback (mIpcHandler);
109
messageConn = new MessageConnection ("Blam");
110
if (!messageConn.IsServer) {
111
messageConn.Send ("ShowWindow");
112
messageConn.Close ();
113
Gdk.Global.NotifyStartupComplete ();
114
Environment.Exit (0);
117
mIpcHandler = new MessageConnection.MessageReceivedHandler (MessageReceivedCb) ;
118
messageConn.SetCallback (mIpcHandler);
111
121
Utils.GeckoInit ();
113
string homeDirectory = Environment.GetEnvironmentVariable("HOME");
115
Mono.Posix.Catalog.Init ("blam", Defines.GNOME_LOCALE_DIR);
117
BaseDir = homeDirectory + "/.gnome2/blam";
118
if (!File.Exists(BaseDir)) {
119
Directory.CreateDirectory(BaseDir);
122
mCollection = ChannelCollection.LoadFromFile (BaseDir + "/collection.xml");
124
mCollection.ChannelUpdated += ChannelUpdatedCb;
125
mCollection.ChannelAdded += ChannelAddedCb;
126
mCollection.ChannelRemoved += ChannelRemovedCb;
127
mCollection.ChannelRefreshStarted += ChannelRefreshStartedCb;
128
mCollection.ChannelRefreshFinished += ChannelRefreshFinishedCb;
123
Catalog.Init ("blam", Defines.GNOME_LOCALE_DIR);
125
if (!File.Exists(BaseDir)) {
126
Directory.CreateDirectory(Defines.APP_HOMEDIR);
129
mCollection = ChannelCollection.LoadFromFile (Defines.APP_HOMEDIR + "/collection.xml");
131
mCollection.ChannelUpdated += ChannelUpdatedCb;
132
mCollection.ChannelAdded += ChannelAddedCb;
133
mCollection.ChannelRemoved += ChannelRemovedCb;
134
mCollection.ChannelRefreshStarted += ChannelRefreshStartedCb;
135
mCollection.ChannelRefreshFinished += ChannelRefreshFinishedCb;
137
mThemeManager = new ThemeManager ();
132
Conf.AddNotify (new NotifyEventHandler (ConfNotifyHandler));
133
// Uncommented until support for checking whether a channels should
134
// be refreshed on startup.
135
//GLib.Idle.Add (new GLib.IdleHandler (IdleRefreshAll));
138
private void PrepareGUI()
140
Glade.XML gladeXML = Glade.XML.FromAssembly("blam.glade",
142
gladeXML.Autoconnect(this);
144
channelList = new ChannelList(mCollection.Channels);
145
((Container)channelListSw).Child = channelList;
147
channelList.ChannelSelectedEvent += ChannelSelected;
148
channelList.EditChannelEvent += EditChannelActivated;
149
channelList.MarkChannelAsReadEvent += MarkChannelAsReadActivated;
150
channelList.RemoveChannelEvent += RemoveChannelActivated;
151
channelList.RefreshChannelEvent += RefreshChannelActivated;
153
itemView = new ItemView ();
141
Conf.AddNotify (new NotifyEventHandler (ConfNotifyHandler));
143
GLib.Idle.Add (new GLib.IdleHandler (IdleRefreshAll));
148
private void PrepareGUI()
150
Glade.XML gladeXML = Glade.XML.FromAssembly("blam.glade",
152
gladeXML.Autoconnect(this);
154
channelList = new ChannelList(mCollection.Channels);
155
((Container)channelListSw).Child = channelList;
157
channelList.ChannelSelectedEvent += ChannelSelected;
158
channelList.EditChannelEvent += EditChannelActivated;
159
channelList.MarkChannelAsReadEvent += MarkChannelAsReadActivated;
160
channelList.RemoveChannelEvent += RemoveChannelActivated;
161
channelList.RefreshChannelEvent += RefreshChannelActivated;
163
itemView = new ItemView ();
155
165
Frame f = new Frame ();
156
166
f.Shadow = ShadowType.In;
160
170
itemView.OnUrl += OnUrl;
162
itemList = new ItemList(itemView);
172
itemList = new ItemList(itemView);
163
173
((Container)itemListSw).Child = itemList;
165
itemList.ItemSelected += ItemSelected;
167
trayIcon = new TrayIcon (Catalog.GetString ("Imendio Blam News Reader"));
168
trayIcon.Image.Pixbuf = Gdk.Pixbuf.LoadFromResource ("blam-tray-icon.png");
169
trayIcon.ButtonPressEvent += TrayIconButtonPressCb;
170
channelsLabelText = channelsLabel.Text;
171
UpdateTotalNumberOfUnread ();
173
//printMenuItem.Sensitive = false;
174
SensitizeChannelMenuItems(false);
177
Gtk.Drag.DestSet(mainWindow, DestDefaults.All,
178
DragEntries, DragAction.Copy | DragAction.Move);
179
mainWindow.DragDataReceived += DragDataReceivedCb;
181
RestoreWindowState();
183
mainWindow.Icon = Gdk.Pixbuf.LoadFromResource("blam.png");
175
itemList.ItemSelected += ItemSelected;
177
trayIcon = new TrayIcon (Catalog.GetString ("Imendio Blam News Reader"));
178
trayIcon.Image.Pixbuf = Gdk.Pixbuf.LoadFromResource ("blam-tray-icon.png");
179
trayIcon.ButtonPressEvent += TrayIconButtonPressCb;
180
channelsLabelText = channelsLabel.Text;
181
UpdateTotalNumberOfUnread ();
183
//printMenuItem.Sensitive = false;
184
SensitizeChannelMenuItems(false);
187
Gtk.Drag.DestSet(mainWindow, DestDefaults.All,
188
DragEntries, DragAction.Copy | DragAction.Move);
189
mainWindow.DragDataReceived += DragDataReceivedCb;
191
RestoreWindowState();
193
mainWindow.Icon = Gdk.Pixbuf.LoadFromResource("blam.png");
185
195
mainWindow.ShowAll ();
187
channelDialog = new ChannelDialog (this);
188
addChannelDialog = new AddChannelDialog (this);
189
preferencesDialog = new PreferencesDialog (this.Window);
190
opmlDialog = new OpmlDialog (this.Window);
191
opmlDialog.ChannelAdded += mCollection.Add;
192
opmlDialog.ImportFinished += OpmlImportFinished;
196
private void ChannelSelected(Channel channel)
198
if (channel == null) {
199
SensitizeChannelMenuItems(false);
203
itemList.CurrentChannel = channel;
205
blogNameLabel.Markup = "<b>" + channel.Name + "</b>";
206
mainWindow.Title = "Blam - " + channel.Name;
208
SensitizeChannelMenuItems(true);
211
private void SensitizeChannelMenuItems (bool sensitive)
213
refreshChannelMenuItem.Sensitive = sensitive;
214
removeChannelMenuItem.Sensitive = sensitive;
215
editChannelMenuItem.Sensitive = sensitive;
216
markChannelAsReadMenuItem.Sensitive = sensitive;
219
private void ItemSelected(Imendio.Blam.Item item)
221
itemView.CurrentItem = item;
222
//printMenuItem.Sensitive = true;
225
public void MarkEntryAsUnreadActivated (object obj, EventArgs args)
227
Item item = itemList.GetSelected ();
232
// Toggle unread status
233
item.SetUnread (!item.Unread, false);
236
public void MenuChannelActivated (object obj, EventArgs args)
238
Channel channel = channelList.GetSelected ();
240
bool sensitive = true;
241
if (channel == null) {
245
SensitizeChannelMenuItems (sensitive);
248
public void MenuEntryActivated (object obj, EventArgs args)
250
Item item = itemList.GetSelected ();
253
markEntryAsUnreadMenuItem.Sensitive = false;
257
markEntryAsUnreadMenuItem.Sensitive = true;
261
str = Catalog.GetString ("_Mark as unread");
263
str = Catalog.GetString ("_Mark as read");
266
((Label) markEntryAsUnreadMenuItem.Child).TextWithMnemonic = str;
269
public void NextUnreadActivated(object obj, EventArgs args)
271
if (channelList.NextUnread()) {
272
itemList.NextUnread();
276
public void MainWindowKeyPressed (object obj, KeyPressEventArgs args)
278
switch (args.Event.Key) {
279
case (Gdk.Key.period):
280
case (Gdk.Key.bracketright):
281
// Couldn't figure out how to get this to the menu item itself.
282
nextUnreadMenuItem.Activate ();
197
channelDialog = new ChannelDialog (this);
198
addChannelDialog = new AddChannelDialog (this);
199
preferencesDialog = new PreferencesDialog (this.Window);
200
opmlDialog = new OpmlDialog (this.Window);
201
opmlDialog.ChannelAdded += mCollection.Add;
202
opmlDialog.ImportFinished += OpmlImportFinished;
207
private DBus.Connection dbusConnection;
208
private void SetupDBus ()
211
this.dbusConnection = DBus.Bus.GetSessionBus ();
212
DBus.Service service = new DBus.Service (this.dbusConnection, DBusFeedReaderProxy.Service);
214
DBusFeedReader feedReader = new DBusFeedReader (this);
215
service.RegisterObject(feedReader, DBusFeedReaderProxy.ObjectPath);
216
} catch (Exception e) {
217
Console.WriteLine("Failed to init dbus interface, I won't receive any dbus message, be warned !");
221
private void SetupDBus ()
227
private void ChannelSelected(Channel channel)
229
if (channel == null) {
230
SensitizeChannelMenuItems(false);
234
itemList.CurrentChannel = channel;
236
blogNameLabel.Markup = "<b>" + channel.Name + "</b>";
237
mainWindow.Title = "Blam - " + channel.Name;
239
SensitizeChannelMenuItems(true);
242
private void SensitizeChannelMenuItems (bool sensitive)
244
refreshChannelMenuItem.Sensitive = sensitive;
245
removeChannelMenuItem.Sensitive = sensitive;
246
editChannelMenuItem.Sensitive = sensitive;
247
markChannelAsReadMenuItem.Sensitive = sensitive;
248
editEntryKeywordsMenuItem.Sensitive = sensitive;
251
private void ItemSelected(Imendio.Blam.Item item)
253
itemView.CurrentItem = item;
254
//printMenuItem.Sensitive = true;
257
public void MarkEntryAsUnreadActivated (object obj, EventArgs args)
259
Item item = itemList.GetSelected ();
264
// Toggle unread status
265
item.SetUnread (!item.Unread, false);
268
public void EditEntryKeywordsActivated (object obj, EventArgs args)
270
Item item = itemList.GetSelected ();
275
// FIXME: Show edit keywords dialog
278
public void MenuChannelActivated (object obj, EventArgs args)
280
Channel channel = channelList.GetSelected ();
282
bool sensitive = true;
283
if (channel == null) {
287
SensitizeChannelMenuItems (sensitive);
290
public void MenuEntryActivated (object obj, EventArgs args)
292
Item item = itemList.GetSelected ();
295
markEntryAsUnreadMenuItem.Sensitive = false;
299
markEntryAsUnreadMenuItem.Sensitive = true;
303
str = Catalog.GetString ("_Mark as unread");
305
str = Catalog.GetString ("_Mark as read");
308
((Label) markEntryAsUnreadMenuItem.Child).TextWithMnemonic = str;
311
public void NextUnreadActivated(object obj, EventArgs args)
313
if (channelList.NextUnread()) {
314
itemList.NextUnread();
318
public void MainWindowKeyPressed (object obj, KeyPressEventArgs args)
320
switch (args.Event.Key) {
321
case (Gdk.Key.period):
322
case (Gdk.Key.bracketright):
323
// Couldn't figure out how to get this to the menu item itself.
324
nextUnreadMenuItem.Activate ();
284
326
case (Gdk.Key.Escape):
285
327
mainWindow.Iconify ();
290
332
/*private void PrintActivated(object obj, EventArgs args)
292
Blam.PrintDialog dialog = new Blam.PrintDialog(itemView);
296
public void ImportOpmlActivated (object obj, EventArgs args)
301
private bool ShowFileExistsDialog (Gtk.Window parentWindow, string fileName)
303
string str = String.Format (Catalog.GetString ("File {0} already exists"), fileName);
305
string msg = Catalog.GetString ("Do you want to overwrite the file?");
307
Gtk.Dialog dialog = ConfirmationDialog.Create (parentWindow,
308
Catalog.GetString ("_Overwrite"),
311
int result = dialog.Run ();
315
case (int)ResponseType.Ok:
322
public void ExportOpmlActivated (object obj, EventArgs args)
324
if (exportFileDialog == null) {
325
exportFileDialog = new Gtk.FileSelection (Catalog.GetString ("Export to..."));
326
exportFileDialog.Modal = true;
327
exportFileDialog.ShowFileops = true;
328
exportFileDialog.TransientFor = mainWindow;
331
bool finished = false;
333
string fileName = "";
336
int result = exportFileDialog.Run ();
339
case (int)ResponseType.Ok:
340
fileName = exportFileDialog.Filename;
342
if (!File.Exists (fileName)) {
346
write = ShowFileExistsDialog (exportFileDialog, fileName);
352
case (int)ResponseType.Cancel:
358
exportFileDialog.Hide ();
361
OpmlWriter.Write (mCollection, fileName);
365
private void OpmlImportFinished (string status)
367
uint contextId = statusbar.GetContextId("status");
369
if (status != null) {
370
statusbar.Push(contextId, status);
374
public void QuitActivated(object obj, EventArgs args)
379
mCollection.SaveToFile ();
384
public void CopyActivated (object obj, EventArgs args)
334
Blam.PrintDialog dialog = new Blam.PrintDialog(itemView);
338
public void ImportOpmlActivated (object obj, EventArgs args)
343
private bool ShowFileExistsDialog (Gtk.Window parentWindow, string fileName)
345
string str = String.Format (Catalog.GetString ("File {0} already exists"), fileName);
347
string msg = Catalog.GetString ("Do you want to overwrite the file?");
349
Gtk.Dialog dialog = ConfirmationDialog.Create (parentWindow,
350
Catalog.GetString ("_Overwrite"),
353
int result = dialog.Run ();
357
case (int)ResponseType.Ok:
364
public void ExportOpmlActivated (object obj, EventArgs args)
366
if (exportFileDialog == null) {
367
exportFileDialog = new Gtk.FileSelection (Catalog.GetString ("Export to..."));
368
exportFileDialog.Modal = true;
369
exportFileDialog.ShowFileops = true;
370
exportFileDialog.TransientFor = mainWindow;
373
bool finished = false;
375
string fileName = "";
378
int result = exportFileDialog.Run ();
381
case (int)ResponseType.Ok:
382
fileName = exportFileDialog.Filename;
384
if (!File.Exists (fileName)) {
388
write = ShowFileExistsDialog (exportFileDialog, fileName);
394
case (int)ResponseType.Cancel:
400
exportFileDialog.Hide ();
403
OpmlWriter.Write (mCollection, fileName);
407
private void OpmlImportFinished (string status)
409
uint contextId = statusbar.GetContextId("status");
411
if (status != null) {
412
statusbar.Push(contextId, status);
416
public void QuitActivated(object obj, EventArgs args)
421
mCollection.SaveToFile ();
426
public void CopyActivated (object obj, EventArgs args)
386
428
// FIXME: Check how to do this
387
429
//itemView.Copy ();
390
public void PreferencesActivated (object obj, EventArgs args)
392
preferencesDialog.Show ();
395
public void AboutActivated (object obj, EventArgs args)
397
About.Show (mainWindow);
400
public void AddChannelActivated (object obj, EventArgs args)
402
addChannelDialog.Show ();
405
public void EditChannelActivated (Channel channel)
407
if (channel != null) {
408
channelDialog.Show (channel);
412
public void EditChannelActivated(object obj, EventArgs args)
414
EditChannelActivated (channelList.GetSelected ());
417
public void MarkChannelAsReadActivated (Channel channel)
419
if (channel.MarkAsRead ()) {
420
CCollection.Update (channel);
424
public void MarkChannelAsReadActivated (object obj, EventArgs args)
426
MarkChannelAsReadActivated (channelList.GetSelected ());
429
public void RemoveChannelActivated(Channel channel)
431
if (channel != null) {
432
RemoveChannelDialog.Show (mainWindow, mCollection, channel);
436
public void RemoveChannelActivated(object obj, EventArgs args)
438
Channel channel = channelList.GetSelected ();
440
RemoveChannelActivated(channel);
443
public void RefreshChannelActivated(Channel channel)
445
if (channel != null) {
446
mCollection.Refresh (channel);
450
public void RefreshChannelActivated(object obj, EventArgs args)
452
Channel channel = channelList.GetSelected ();
454
RefreshChannelActivated(channel);
457
public void RefreshAllActivated(object obj, EventArgs args)
459
mCollection.RefreshAll ();
461
StartStopAutoRefresh ();
464
private void DragDataReceivedCb(object o, DragDataReceivedArgs args)
466
SelectionData d = args.SelectionData;
468
if (d.Length < 0 && d.Format != 8){
469
Gtk.Drag.Finish(args.Context, false, false, args.Time);
473
Gtk.Drag.Finish(args.Context, true, true, args.Time);
475
UTF8Encoding encoding = new UTF8Encoding( );
476
string text = encoding.GetString(d.Data);
478
addChannelDialog.Show (text);
432
public void PreferencesActivated (object obj, EventArgs args)
434
preferencesDialog.Show ();
437
public void AboutActivated (object obj, EventArgs args)
439
About.Show (mainWindow);
442
public void AddChannelActivated (object obj, EventArgs args)
444
addChannelDialog.Show ();
447
public void EditChannelActivated (Channel channel)
449
if (channel != null) {
450
channelDialog.Show (channel);
454
public void EditChannelActivated(object obj, EventArgs args)
456
EditChannelActivated (channelList.GetSelected ());
459
public void MarkChannelAsReadActivated (Channel channel)
461
if (channel.MarkAsRead ()) {
462
CCollection.Update (channel);
466
public void MarkChannelAsReadActivated (object obj, EventArgs args)
468
MarkChannelAsReadActivated (channelList.GetSelected ());
471
public void RemoveChannelActivated(Channel channel)
473
if (channel != null) {
474
RemoveChannelDialog.Show (mainWindow, mCollection, channel);
478
public void RemoveChannelActivated(object obj, EventArgs args)
480
Channel channel = channelList.GetSelected ();
482
RemoveChannelActivated(channel);
485
public void RefreshChannelActivated(Channel channel)
487
if (channel != null) {
488
mCollection.Refresh (channel);
492
public void RefreshChannelActivated(object obj, EventArgs args)
494
Channel channel = channelList.GetSelected ();
496
RefreshChannelActivated(channel);
499
public void RefreshAllActivated(object obj, EventArgs args)
501
mCollection.RefreshAll ();
504
private void DragDataReceivedCb(object o, DragDataReceivedArgs args)
506
SelectionData d = args.SelectionData;
508
if (d.Length < 0 && d.Format != 8){
509
Gtk.Drag.Finish(args.Context, false, false, args.Time);
513
Gtk.Drag.Finish(args.Context, true, true, args.Time);
515
UTF8Encoding encoding = new UTF8Encoding( );
516
string text = encoding.GetString(d.Data);
518
addChannelDialog.Show (text);
481
521
private void OnUrl (string url)
483
523
uint contextId = statusbar.GetContextId("on_url");
485
525
statusbar.Pop(contextId);
486
526
if (url != null) {
487
527
statusbar.Push(contextId, url);
491
private void ChannelAddedCb (Channel channel)
493
channelList.Add (channel);
496
private void ChannelUpdatedCb (Channel channel)
498
channelList.Updated (channel);
499
UpdateTotalNumberOfUnread ();
502
private void ChannelRemovedCb (Channel channel)
504
channelList.Remove (channel);
505
UpdateTotalNumberOfUnread ();
508
private void ChannelRefreshStartedCb (Channel channel)
510
uint contextId = statusbar.GetContextId("update-status");
513
statusString = String.Format (Catalog.GetString ("Refreshing: {0}"), channel.Name);
515
statusbar.Push (contextId, statusString);
518
private void ChannelRefreshFinishedCb (Channel channel)
520
uint contextId = statusbar.GetContextId("update-status");
522
statusbar.Pop (contextId);
523
channelList.Updated (channel);
524
UpdateTotalNumberOfUnread ();
526
if (channelList.GetSelected () == channel) {
527
itemList.UpdateList ();
531
//public bool IdleRefreshAll ()
533
// mCollection.RefreshAll ();
535
//StartStopAutoRefresh ();
539
private bool TimeoutRefreshAll ()
541
mCollection.RefreshAll ();
543
/* Continue until source is removed */
547
private void StartStopAutoRefresh ()
552
if (mAutoRefreshId != 0) {
553
GLib.Source.Remove (mAutoRefreshId);
557
doAutoRefresh = Conf.Get (Preference.AUTO_REFRESH, false);
558
if (!doAutoRefresh) {
562
refreshRate = Conf.Get (Preference.AUTO_REFRESH_RATE, 15);
563
if (refreshRate >= 1) {
564
mAutoRefreshId = GLib.Timeout.Add ((uint) (refreshRate * 60 * 1000),
565
new GLib.TimeoutHandler (TimeoutRefreshAll));
569
private void ConfNotifyHandler (object sender, NotifyEventArgs args)
571
if (args.Key == Conf.GetFullKey (Preference.AUTO_REFRESH) ||
572
args.Key == Conf.GetFullKey (Preference.AUTO_REFRESH_RATE)) {
573
StartStopAutoRefresh ();
577
private void TrayIconButtonPressCb (object o, ButtonPressEventArgs args)
579
mainWindow.Present ();
582
private void RestoreWindowState()
585
int position_x, position_y;
588
state = Conf.Get ("ui/main_window_state", "normal");
590
width = Conf.Get ("ui/main_window_width", 600);
591
height = Conf.Get ("ui/main_window_height", 400);
593
mainWindow.Resize(width, height);
595
position_x = Conf.Get("ui/main_window_position_x", -1);
596
position_y = Conf.Get("ui/main_window_position_y", -1);
597
if (position_x >= 0 && position_y >= 0) {
598
mainWindow.Move(position_x, position_y);
601
width = Conf.Get("ui/channel_list_width", 180);
602
channelPaned.Position = width;
604
height = Conf.Get("ui/item_list_height", 100);
605
itemPaned.Position = height;
607
if (state == "maximized") {
608
mainWindow.Maximize ();
612
private void SaveWindowState()
615
int position_x, position_y;
617
if (mainWindow.GdkWindow.State != Gdk.WindowState.Maximized) {
618
Conf.Set ("ui/main_window_state", "normal");
620
mainWindow.GetSize (out width, out height);
622
Conf.Set ("ui/main_window_width", width);
623
Conf.Set ("ui/main_window_height", height);
625
Conf.Set ("ui/channel_list_width", channelPaned.Position);
626
Conf.Set ("ui/item_list_height", itemPaned.Position);
628
mainWindow.GetPosition (out position_x, out position_y);
630
Conf.Set ("ui/main_window_position_x", position_x);
631
Conf.Set ("ui/main_window_position_y", position_y);
633
Conf.Set ("ui/main_window_state", "maximized");
639
private void UpdateTotalNumberOfUnread ()
643
nrOfUnread = mCollection.NrOfUnreadItems;
645
channelsLabel.Markup = string.Format("<b>" +
649
if (nrOfUnread > 0) {
651
trayIcon.Tooltip = string.Format (Catalog.GetPluralString ("{0} unread item", "{0} unread items", nrOfUnread),
658
private void MessageReceivedCb (string message, IntPtr userData)
660
if (!message.Equals ("ShowWindow")) {
664
mainWindow.Present ();
665
//mCollection.RefreshAll ();
531
private void ChannelAddedCb (Channel channel)
533
channelList.Add (channel);
536
private void ChannelUpdatedCb (Channel channel)
538
channelList.Updated (channel);
539
UpdateTotalNumberOfUnread ();
542
private void ChannelRemovedCb (Channel channel)
544
channelList.Remove (channel);
545
UpdateTotalNumberOfUnread ();
548
private void ChannelRefreshStartedCb (Channel channel)
550
uint contextId = statusbar.GetContextId("update-status");
553
statusString = String.Format (Catalog.GetString ("Refreshing: {0}"), channel.Name);
555
statusbar.Push (contextId, statusString);
558
private void ChannelRefreshFinishedCb (Channel channel)
560
uint contextId = statusbar.GetContextId("update-status");
562
statusbar.Pop (contextId);
563
channelList.Updated (channel);
564
UpdateTotalNumberOfUnread ();
566
if (channelList.GetSelected () == channel) {
567
itemList.UpdateList ();
571
public bool IdleRefreshAll ()
573
TimeoutRefreshAll ();
575
StartStopAutoRefresh ();
579
private bool TimeoutRefreshAll ()
583
if (Conf.Get (Preference.AUTO_REFRESH, false) == false) {
584
// User don't want auto refresh.
588
refreshRate = Conf.Get (Preference.AUTO_REFRESH_RATE, 15);
590
mCollection.RefreshAll (refreshRate);
592
/* Continue until source is removed */
596
private void StartStopAutoRefresh ()
600
if (mAutoRefreshId != 0) {
601
GLib.Source.Remove (mAutoRefreshId);
605
doAutoRefresh = Conf.Get (Preference.AUTO_REFRESH, false);
606
if (!doAutoRefresh) {
610
// Check if any feeds require refresh every ten seconds
611
mAutoRefreshId = GLib.Timeout.Add ((uint) (10 * 1000),
612
new GLib.TimeoutHandler (TimeoutRefreshAll));
615
private void ConfNotifyHandler (object sender, NotifyEventArgs args)
617
if (args.Key == Conf.GetFullKey (Preference.AUTO_REFRESH)) {
618
StartStopAutoRefresh ();
622
private void TrayIconButtonPressCb (object o, ButtonPressEventArgs args)
624
mainWindow.Present ();
627
private void RestoreWindowState()
630
int position_x, position_y;
633
state = Conf.Get ("ui/main_window_state", "normal");
635
width = Conf.Get ("ui/main_window_width", 600);
636
height = Conf.Get ("ui/main_window_height", 400);
638
mainWindow.Resize(width, height);
640
position_x = Conf.Get("ui/main_window_position_x", -1);
641
position_y = Conf.Get( "ui/main_window_position_y", -1);
642
if (position_x >= 0 && position_y >= 0) {
643
mainWindow.Move(position_x, position_y);
646
width = Conf.Get("ui/channel_list_width", 180);
647
channelPaned.Position = width;
649
height = Conf.Get("ui/item_list_height", 100);
650
itemPaned.Position = height;
652
if (state == "maximized") {
653
mainWindow.Maximize ();
657
private void SaveWindowState()
660
int position_x, position_y;
662
if (mainWindow.GdkWindow.State != Gdk.WindowState.Maximized) {
663
Conf.Set ("ui/main_window_state", "normal");
665
mainWindow.GetSize (out width, out height);
667
Conf.Set ("ui/main_window_width", width);
668
Conf.Set ("ui/main_window_height", height);
670
Conf.Set ("ui/channel_list_width", channelPaned.Position);
671
Conf.Set ("ui/item_list_height", itemPaned.Position);
673
mainWindow.GetPosition (out position_x, out position_y);
675
Conf.Set ("ui/main_window_position_x", position_x);
676
Conf.Set ("ui/main_window_position_y", position_y);
678
Conf.Set ("ui/main_window_state", "maximized");
684
private void UpdateTotalNumberOfUnread ()
688
nrOfUnread = mCollection.NrOfUnreadItems;
690
channelsLabel.Markup = string.Format("<b>" +
694
if (nrOfUnread > 0) {
696
trayIcon.Tooltip = string.Format (Catalog.GetPluralString ("{0} unread item", "{0} unread items", nrOfUnread),
703
private void MessageReceivedCb (string message, IntPtr userData)
705
if (!message.Equals ("ShowWindow")) {
709
mainWindow.Present ();
710
//mCollection.RefreshAll ();
668
713
public static void Main(string[] args)
670
715
TheApp = new Application (args);
672
// new Application(args).Run();
717
// new Application(args).Run();