Add Cristian Greco as uploader
[debian/pino.git] / src / main_window.vala
1 /* main_window.vala
2  *
3  * Copyright (C) 2009-2010  troorl
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Author:
19  *      troorl <troorl@gmail.com>
20  */
21
22 using Gtk;
23 using WebKit;
24 using RestAPI;
25 using Auth;
26 //using OAuth;
27 using Soup;
28
29 #if(LIBINDICATE)
30         using Indicate;
31 #endif
32
33 public class MainWindow : Window {
34         
35         unowned SList<RadioAction> list_group;
36         
37         private Action updateAct;
38         private ToggleAction menuAct;
39         private ToggleAction toolbarAct;
40         private AccountAction accountAct;
41         
42         private TrayIcon tray;
43         
44         private Gdk.Pixbuf logo;
45         private Gdk.Pixbuf logo_fresh;
46         
47         private Widget menubar;
48         private Widget toolbar;
49         private Menu popup;
50         //private IconEntry searchEntry;
51         private HBox sbox;
52         
53         private SystemStyle gtk_style;
54         
55         public TimelineList home;
56         public TimelineList mentions;
57         public TimelineDirectList direct;
58         public UserInfoList user_info;
59         
60         public ReTweet re_tweet;
61         public StatusbarSmart statusbar;
62         
63         //private TwitterInterface twee;
64         private Cache cache;
65         private Template template;
66         
67         private Prefs prefs;
68         private Accounts accounts;
69         private SmartTimer timer;
70         
71         private AuthData auth_data;
72         
73         private Popups notify;
74         
75         public bool first_show = true;
76         private bool updating = false;
77         
78         public MainWindow() {
79                 logo = new Gdk.Pixbuf.from_file(Config.LOGO_PATH);
80                 logo_fresh = new Gdk.Pixbuf.from_file(Config.LOGO_FRESH_PATH);
81                 
82                 /** testing oauth
83                 string cons_key = "k6R1A0PPkmpRcThEdPF1Q";
84                 string cons_sec = "TKneXwqslxkbaR3RQGcvvvGU4Qk01qh8HAhRIMN74";
85                 string request_token_url = "https://api.twitter.com/oauth/request_token";
86                 string access_token_url = "https://twitter.com/oauth/access_token";
87                 string auth_url = "http://api.twitter.com/oauth/authorize?oauth_token=%s";
88                 
89                 Soup.SessionSync session = new Soup.SessionSync();
90                 Client client = new Client(Config.CONS_KEY, Config.CONS_SEC,
91                 SignatureMethod.HMAC_SHA1, session);
92                 
93                 /*
94                 client.fetch_request_token ("POST", request_token_url);
95                 debug(auth_url, client.request_token.lookup("oauth_token"));
96                 debug("input PIN");
97                 string? pin = stdin.read_line();
98                 debug(pin);
99                 client.fetch_access_token("POST", access_token_url, pin);
100                 debug("%s, %s", client.request_token.lookup("oauth_token"),
101                         client.request_token.lookup("oauth_token_secret"));
102                 
103                 string oauth_token = "18604056-PlBJS2DNHgixESyaW2bo99qD3iwIysec1ANB8QpBr";
104                 string oauth_token_secret = "9LGC6VqPrEfYqu5WByANcyr391oBaWcM2ubiKeSPjM";
105                 
106                 client.request_token.replace("oauth_token", oauth_token);
107                 client.request_token.replace("oauth_token_secret", oauth_token_secret);
108                 
109                 var table = new HashTable<string, string>(str_hash, str_equal);
110                 string signature = client.generate_signature("GET", "http://api.twitter.com/statuses/home_timeline.xml",
111                         oauth_token_secret, table);
112                 //signature = signature.substring(0, signature.length - 1);
113                 
114                 debug(signature);
115                 
116                 string auth_header = """OAuth realm="%s",oauth_consumer_key="%s",oauth_token="%s",oauth_signature_method="HMAC-SHA1",oauth_signature="%s",oauth_timestamp="%s",oauth_nonce="%s",oauth_version="1.0"""".printf("http://api.twitter.com/",
117                 Config.CONS_KEY, oauth_token, signature, client.timestamp,
118                 client.nonce);
119         
120         debug(auth_header);
121         
122         string h = client.generate_authorization("GET", "http://api.twitter.com/statuses/home_timeline.xml", "http://api.twitter.com");
123         debug(h);
124         
125         Message message = new Message("GET", "http://api.twitter.com/statuses/home_timeline.xml");
126         message.set_http_version (HTTPVersion.1_1);
127         MessageHeaders headers = new MessageHeaders(MessageHeadersType.MULTIPART);
128         headers.append("Authorization", h);
129         
130         message.request_headers = headers;
131         
132         session.send_message(message);
133         debug((string)message.response_body.flatten().data);
134                  end of testing */
135                 
136                 //getting settings
137                 prefs = new Prefs();
138                 
139                 accounts = new Accounts();
140                 accounts.active_changed.connect(() => {
141                         refresh_auth();
142                 });
143                 
144                 accounts.changed.connect((hash) => {
145                         var acc = accounts.get_current_account();
146                         string cur_hash = acc.login + acc.password + acc.proxy;
147                         
148                         if(cur_hash == hash)
149                                 refresh_auth();
150                 });
151                 
152                 set_default_size (prefs.width, prefs.height);
153                 set_size_request(350, 300);
154                 
155                 //set window position
156                 if(prefs.left >= 0 && prefs.top >= 0)
157                         move(prefs.left, prefs.top);
158                 
159                 configure_event.connect((widget, event) => {
160                         //saving window size and position
161                         int x;
162                         int y;
163                         get_position(out x, out y);
164                         
165                         prefs.width = event.width;
166                         prefs.height = event.height;
167                         prefs.left = x;
168                         prefs.top = y;
169                         
170                         return false;
171                 });
172                 
173                 set_title(Config.APPNAME);
174                 
175                 destroy.connect(() => before_close());
176                 
177                 gtk_style = new SystemStyle(rc_get_style(this));
178                 this.map_event.connect((event) => {
179                         gtk_style = new SystemStyle(rc_get_style(this));
180                         return true;
181                 });
182                 
183                 cache = new Cache();
184                 //template setup
185                 template = new Template(prefs, accounts, gtk_style, cache);
186                 
187                 //home timeline
188                 home = new TimelineList(this, accounts, TimelineType.HOME,
189                         template, prefs.numberStatuses,
190                         Icon.new_for_string(Config.TIMELINE_PATH),
191                         Icon.new_for_string(Config.TIMELINE_FRESH_PATH), "HomeAct", _("Home timeline"),
192                         _("Show your home timeline"), true);
193                 
194                 //mentions
195                 mentions = new TimelineList(this, accounts, TimelineType.MENTIONS,
196                         template, prefs.numberStatuses,
197                         Icon.new_for_string(Config.MENTIONS_PATH),
198                         Icon.new_for_string(Config.MENTIONS_FRESH_PATH), "MentionsAct", _("Mentions"),
199                         _("Show mentions"));
200                 
201                 //direct messages
202                 direct = new TimelineDirectList(this, accounts,
203                         template, prefs.numberStatuses,
204                         Icon.new_for_string(Config.DIRECT_PATH),
205                         Icon.new_for_string(Config.DIRECT_FRESH_PATH), "DirectAct", _("Direct messages"),
206                         _("Show direct messages"));
207                 
208                 //user info
209                 user_info = new UserInfoList(this, accounts, template, prefs.numberStatuses,
210                         Icon.new_for_string(Config.USERPIC_PATH), prefs.nativeLinkColor,
211                         "UserInfoAct", _("User info"), _("Show information about user"));
212                 
213                 home.fresh.connect(() => tray.new_tweets(true));
214                 mentions.fresh.connect(() => tray.new_tweets(true));
215                 direct.fresh.connect(() => tray.new_tweets(true));
216                 home.no_fresh.connect(() => check_fresh());
217                 mentions.no_fresh.connect(() => check_fresh());
218                 direct.no_fresh.connect(() => check_fresh());
219                 
220                 //group for lists
221                 list_group = home.act.get_group();
222                 mentions.act.set_group(home.act.get_group());
223                 direct.act.set_group(home.act.get_group());
224                 user_info.act.set_group(home.act.get_group());
225                 
226                 //retweet widget
227                 re_tweet = new ReTweet(this, prefs, accounts, cache, gtk_style);
228                 re_tweet.status_updated.connect((status) => {
229                         home.insert_status(status);
230                 });
231                 
232                 menu_init();
233                 
234                 //set popup menu to the views
235                 home.popup = popup;
236                 mentions.popup = popup;
237                 direct.popup = popup;
238                 user_info.popup = popup;
239                 
240                 //tray setup
241                 tray = new TrayIcon(this, prefs, logo, logo_fresh);
242                 tray.set_visible(prefs.showTray);
243                 
244                 tray.popup = popup;
245                 prefs.showTrayChanged.connect(() => {
246                         tray.set_visible(prefs.showTray);
247                 });
248                 
249                 //hiding on closing main window
250                 delete_event.connect((event) => {
251                         bool use_indicate = false;
252
253                         #if(LIBINDICATE)
254                                 use_indicate = true;
255                         #endif
256
257                         if(!tray.visible && !use_indicate) { //close pino, if tray and indicator are not used
258                                 before_close();
259                                 return true;
260                         }
261                         
262                         this.hide_on_delete();
263                         visible = false;
264                         return true;
265                 });
266                 
267                 re_tweet.sending_data.connect((msg) => {
268                         statusbar.set_status(StatusbarSmart.StatusType.SENDING_DATA, msg);
269                 });
270                 
271                 re_tweet.data_sent.connect((msg) => {
272                         statusbar.set_status(StatusbarSmart.StatusType.DATA_SENT, msg);
273                 });
274                 
275                 re_tweet.data_error_sent.connect((msg) => {
276                         statusbar.set_status(StatusbarSmart.StatusType.FINISH_ERROR, msg);
277                 });
278                 
279                 home.nickto.connect((screen_name) => {
280                         re_tweet.set_nickto(screen_name);
281                 });
282                 mentions.nickto.connect((screen_name) => {
283                         re_tweet.set_nickto(screen_name);
284                 });
285                 direct.nickto.connect((screen_name) => {
286                         re_tweet.set_nickto(screen_name);
287                 });
288                 home.user_info.connect((screen_name) => {
289                         user_info.show_user(screen_name);
290                 });
291                 mentions.user_info.connect((screen_name) => {
292                         user_info.show_user(screen_name);
293                 });
294                 direct.user_info.connect((screen_name) => {
295                         user_info.show_user(screen_name);
296                 });
297                 user_info.user_info.connect((screen_name) => {
298                         user_info.show_user(screen_name);
299                 });
300                 home.retweet.connect((status) => {
301                         re_tweet.set_state_retweet(status);
302                 });
303                 mentions.retweet.connect((status) => {
304                         re_tweet.set_state_retweet(status);
305                 });
306                 user_info.retweet.connect((status) => {
307                         re_tweet.set_state_retweet(status);
308                 });
309                 home.directreply.connect((screen_name) => {
310                         re_tweet.set_state_directreply(screen_name);
311                 });
312                 mentions.directreply.connect((screen_name) => {
313                         re_tweet.set_state_directreply(screen_name);
314                 });
315                 direct.directreply.connect((screen_name) => {
316                         re_tweet.set_state_directreply(screen_name);
317                 });
318                 user_info.directreply.connect((screen_name) => {
319                         re_tweet.set_state_directreply(screen_name);
320                 });
321                 home.replyto.connect((status) => {
322                         re_tweet.set_state_reply(status);
323                 });
324                 mentions.replyto.connect((status) => {
325                         re_tweet.set_state_reply(status);
326                 });
327                 user_info.replyto.connect((status) => {
328                         re_tweet.set_state_reply(status);
329                 });
330                 home.deleted.connect((msg) => {
331                         statusbar.set_status(StatusbarSmart.StatusType.DATA_SENT, msg);
332                 });
333                 mentions.deleted.connect((msg) => {
334                         statusbar.set_status(StatusbarSmart.StatusType.DATA_SENT, msg);
335                 });
336                 direct.deleted.connect((msg) => {
337                         statusbar.set_status(StatusbarSmart.StatusType.DATA_SENT, msg);
338                 });
339                 user_info.start_fetch.connect(() => {
340                         statusbar.set_status(StatusbarSmart.StatusType.UPDATING);
341                 });
342                 user_info.end_fetch.connect(() => {
343                         statusbar.set_status(StatusbarSmart.StatusType.FINISH_OK);
344                 });
345                 user_info.follow_event.connect((msg) => {
346                         statusbar.set_status(StatusbarSmart.StatusType.DATA_SENT, msg);
347                 });
348                 
349                 //setup logging
350                 statusbar = new StatusbarSmart();
351                 home.start_update.connect((req) => statusbar.logging(req));
352                 mentions.start_update.connect((req) => statusbar.logging(req));
353                 direct.start_update.connect((req) => statusbar.logging(req));
354                 re_tweet.start_update.connect((req) => statusbar.logging(req));
355                 
356                 home.finish_update.connect(() => statusbar.logging(_("updated ")));
357                 mentions.finish_update.connect(() => statusbar.logging(_("updated ")));
358                 direct.finish_update.connect(() => statusbar.logging(_("updated ")));
359                 home.updating_error.connect((msg) => {
360                         statusbar.set_status(StatusbarSmart.StatusType.FINISH_ERROR, msg);
361                 });
362                 mentions.updating_error.connect((msg) => {
363                         statusbar.set_status(StatusbarSmart.StatusType.FINISH_ERROR, msg);
364                 });
365                 direct.updating_error.connect((msg) => {
366                         statusbar.set_status(StatusbarSmart.StatusType.FINISH_ERROR, msg);
367                 });
368                 user_info.updating_error.connect((msg) => {
369                         statusbar.set_status(StatusbarSmart.StatusType.FINISH_ERROR, msg);
370                 });
371                 
372                 VBox vbox = new VBox(false, 0);
373                 vbox.pack_start(menubar, false, false, 0);
374                 vbox.pack_start(toolbar, false, false, 0);
375                 //vbox.pack_start(sbox, false, false, 0);
376                 vbox.pack_start(home, true, true, 0);
377                 vbox.pack_start(mentions, true, true, 0);
378                 vbox.pack_start(direct, true, true, 0);
379                 vbox.pack_start(user_info, true, true, 0);
380                 vbox.pack_end(statusbar, false, false, 0);
381                 vbox.pack_end(re_tweet, false, false, 0);
382                 
383                 this.add(vbox);
384                 
385                 //show window
386                 if(!prefs.startMin || !prefs.showTray) {
387                         first_show = false;
388                         show_all();
389                         first_hide();
390                 }
391                 
392                 //hide menubar and toolbar if needed
393                 if(!prefs.menuShow)
394                         menuAct.set_active(false);
395                 if(!prefs.toolbarShow)
396                         toolbarAct.set_active(false);
397                 
398                 if(accounts.is_new)
399                         run_prefs();
400                 
401                 //notification popups
402                 notify = new Popups(prefs, accounts, cache, logo);
403                 
404                 //first_hide();
405                 
406                 //getting updates
407                 if(accounts.accounts.size > 0) {
408                         refresh_action();
409                 }
410                 
411                 style_set.connect((prev_style) => { //when gtk style is changing
412                         gtk_style.updateStyle(rc_get_style(this));
413                         template.refresh_gtk_style(gtk_style);
414                 });
415                 
416                 //start timer
417                 timer = new SmartTimer(prefs.updateInterval * 60);
418                 timer.timeout.connect(refresh_action);
419         }
420         
421         public void first_hide() { //when starts minimized
422                 re_tweet.hide();
423                 mentions.hide();
424                 direct.hide();
425                 user_info.hide();
426                 user_info.set_empty();
427                 
428                 if(!prefs.menuShow)
429                         menubar.hide();
430                 if(!prefs.toolbarShow)
431                         toolbar.hide();
432         }
433         
434         private void refresh_auth() {
435                 updateAct.set_sensitive(false);
436                 statusbar.set_status(StatusbarSmart.StatusType.UPDATING);
437                 
438                 re_tweet.update_auth();
439                 home.update_auth();
440                 mentions.update_auth();
441                 direct.update_auth();
442                 user_info.update_auth();
443                 
444                 statusbar.set_status(StatusbarSmart.StatusType.FINISH_OK);
445                 updateAct.set_sensitive(true);
446         }
447         
448         private void menu_init() {      
449                 var actGroup = new ActionGroup("main");
450                 
451                 //file menu
452                 var fileMenu = new Action("FileMenu", "Pino", null, null);
453                 
454                 var createAct = new Action("FileCreate", _("New status"),
455                         _("Create new status"), STOCK_EDIT);
456                 createAct.activate.connect(() => { re_tweet.set_state_new(); });
457                 
458                 var createDirectAct = new Action("FileCreateDirect", _("New direct message"),
459                         _("Create new direct message"), null);
460                 createDirectAct.set_gicon(Icon.new_for_string(Config.DIRECT_REPLY_PATH));
461                 createDirectAct.activate.connect(() => {
462                         re_tweet.set_state_directreply("");
463                 });
464                 
465                 var showUserAct = new Action("ShowUser", _("Show user"),
466                         _("Show information about specified user"), null);
467                 showUserAct.activate.connect(() => {
468                         user_info.set_empty();
469                         user_info.act.activate();
470                 });
471                 
472                 var showFavoritesAct = new Action("ShowFavorites", _("Show favorites..."),
473                         null, null);
474                 showFavoritesAct.set_gicon(Icon.new_for_string(Config.FAVORITE_PATH));
475                 showFavoritesAct.activate.connect(() => {
476                         new FavoritesViewDialog(this, accounts, template);
477                 });
478                 
479                 updateAct = new Action("FileUpdate", _("Update timeline"),
480                         null, STOCK_REFRESH);
481                 updateAct.activate.connect(refresh_action);
482                 var quitAct = new Action("FileQuit", _("Quit"),
483                         null, STOCK_QUIT);
484                 quitAct.activate.connect(before_close);
485                 
486                 //edit menu
487                 var editMenu = new Action("EditMenu", _("Edit"), null, null);
488                 accountAct = new AccountAction();
489                 accountAct.set_accounts(accounts);
490                 var prefAct = new Action("EditPref", _("Preferences"),
491                         null, STOCK_PREFERENCES);
492                 prefAct.activate.connect(run_prefs);
493                 
494                 //view menu
495                 var viewMenu = new Action("ViewMenu", _("View"), null, null);
496                 
497                 menuAct = new ToggleAction("ViewMenuAct", _("Show menu"), null, null);
498                 menuAct.set_active(true);
499                 
500                 menuAct.toggled.connect(() => {
501                         if(menuAct.active)
502                                 menubar.show();
503                         else
504                                 menubar.hide();
505                 });
506                 
507                 toolbarAct = new ToggleAction("ViewToolbar", _("Show toolbar"),
508                         null, null);
509                 toolbarAct.set_active(true);
510                 
511                 toolbarAct.toggled.connect(() => {
512                         if(toolbarAct.active)
513                                 toolbar.show();
514                         else
515                                 toolbar.hide();
516                 });
517                 
518                 //help menu
519                 var helpMenu = new Action("HelpMenu", _("Help"), null, null);
520                 var aboutAct = new Action("HelpAbout", _("About %s").printf(Config.APPNAME),
521                         null, STOCK_ABOUT);
522                 
523                 aboutAct.activate.connect(() => {
524                         var about_dlg = new AboutDialog();
525                         about_dlg.set_logo(logo);
526                         about_dlg.set_program_name(Config.APPNAME);
527                         about_dlg.set_version(Config.APP_VERSION);
528                         about_dlg.set_website("http://pino-app.appspot.com/");
529                         about_dlg.set_authors({Config.AUTHORS});
530                         about_dlg.set_translator_credits("http://www.transifex.net/projects/p/pino/c/ui/");
531                         about_dlg.set_copyright("© 2009-2010 troorl");
532                         
533                         about_dlg.set_transient_for(this);
534                         about_dlg.run();
535                         about_dlg.hide();
536                 });
537                 
538                 actGroup.add_action(fileMenu);
539                 actGroup.add_action_with_accel(createAct, "<Ctrl>N");
540                 actGroup.add_action_with_accel(createDirectAct, "<Ctrl>D");
541                 actGroup.add_action(showUserAct);
542                 actGroup.add_action(showFavoritesAct);
543                 actGroup.add_action_with_accel(updateAct, "<Ctrl>R");
544                 actGroup.add_action_with_accel(quitAct, "<Ctrl>Q");
545                 actGroup.add_action(editMenu);
546                 actGroup.add_action_with_accel(re_tweet.shortAct, "<Ctrl>U");
547                 actGroup.add_action(accountAct);
548                 actGroup.add_action_with_accel(prefAct, "<Ctrl>P");
549                 actGroup.add_action(viewMenu);
550                 actGroup.add_action_with_accel(home.act, "<Ctrl>1");
551                 actGroup.add_action_with_accel(mentions.act, "<Ctrl>2");
552                 actGroup.add_action_with_accel(direct.act, "<Ctrl>3");
553                 actGroup.add_action_with_accel(user_info.act, "<Ctrl>4");
554                 actGroup.add_action_with_accel(menuAct, "<Ctrl>M");
555                 actGroup.add_action(toolbarAct);
556                 actGroup.add_action(helpMenu);
557                 actGroup.add_action(aboutAct);
558                 
559                 var ui = new UIManager();
560                 ui.insert_action_group(actGroup, 0);
561                 this.add_accel_group(ui.get_accel_group());
562                 
563                 var uiString = """
564                 <ui>
565                         <menubar name="MenuBar">
566                                 <menu action="FileMenu">
567                                         <menuitem action="FileCreate" />
568                                         <menuitem action="FileCreateDirect" />
569                                         <separator />
570                                         <menuitem action="ShowUser" />
571                                         <menuitem action="ShowFavorites" />
572                                         <separator />
573                                         <menuitem action="FileUpdate" />
574                                         <separator />
575                                         <menuitem action="FileQuit" />
576                                 </menu>
577                                 <menu action="EditMenu">
578                                         <menuitem action="UrlShort" />
579                                         <menu action="AccountAct">
580                                         </menu>
581                                         <separator />
582                                         <menuitem action="EditPref" />
583                                 </menu>
584                                 <menu action="ViewMenu">
585                                         <menuitem action="HomeAct" />
586                                         <menuitem action="MentionsAct" />
587                                         <menuitem action="DirectAct" />
588                                         <separator />
589                                         <menuitem action="UserInfoAct" />
590                                         <separator />
591                                         <menuitem action="ViewMenuAct" />
592                                         <menuitem action="ViewToolbar" />
593                                 </menu>
594                                 <menu action="HelpMenu">
595                                         <menuitem action="HelpAbout" />
596                                 </menu>
597                         </menubar>
598                         <popup name="MenuPopup">
599                                 <menuitem action="FileCreate" />
600                                 <menuitem action="FileCreateDirect" />
601                                 <menuitem action="FileUpdate" />
602                                 <separator />
603                                 <menuitem action="EditPref" />
604                                 <separator />
605                                 <menuitem action="ViewMenuAct" />
606                                 <menuitem action="ViewToolbar" />
607                                 <separator />
608                                 <menuitem action="HelpAbout" />
609                                 <menuitem action="FileQuit" />
610                         </popup>
611                         <toolbar name="ToolBar">
612                                 <toolitem action="FileCreate" />
613                                 <toolitem action="FileUpdate" />
614                                 <separator />
615                                 <toolitem action="HomeAct" />
616                                 <toolitem action="MentionsAct" />
617                                 <toolitem action="DirectAct" />
618                                 <separator />
619                                 <toolitem action="UserInfoAct" />
620                                 <separator expand="true" draw="false" />
621                                 <toolitem action="AccountAct" />
622                         </toolbar>
623                 </ui>
624                 """;
625                 
626                 ui.add_ui_from_string(uiString, uiString.length);
627                 
628                 menubar = ui.get_widget("/MenuBar");
629                 popup = (Menu)ui.get_widget("/MenuPopup");
630                 toolbar = ui.get_widget("/ToolBar");
631                 
632                 accountAct.set_ui(ui, cache);
633                 //var toolitem = new AccountAction(accounts);
634                 //((Toolbar)toolbar).insert(toolitem, 9);
635         }
636         
637         public void refresh_action() {
638                 updateAct.set_sensitive(false);
639                 
640                 statusbar.set_status(StatusbarSmart.StatusType.UPDATING);
641                 
642                 debug("start home");
643                 var home_list = home.update();
644                 debug("start mentions");
645                 var mentions_list = mentions.update();
646                 debug("start direct");
647                 var direct_list = direct.update();
648                 statusbar.set_status(StatusbarSmart.StatusType.FINISH_OK);
649                 debug("end of update, starting notification");
650                 notify.start(home_list, mentions_list, direct_list);
651                 debug("notification is ok");
652                 updateAct.set_sensitive(true);
653                 debug("refresh complete");
654         }
655         
656         private void run_prefs() {
657                 var pref_dialog = new PrefDialog(prefs, this, accounts);
658                 
659                 pref_dialog.delete_cache.connect(() => {
660                         cache.delete_cache();
661                 });
662                 
663                 pref_dialog.destroy.connect(() => {
664                         //timer interval update
665                         timer.set_interval(prefs.updateInterval * 60);
666                         prefs.write();
667                 });
668         }
669         
670         /* saving settings */
671         private void before_close() {
672                 prefs.menuShow = menubar.visible;
673                 prefs.toolbarShow = toolbar.visible;
674                 
675                 prefs.write();
676                 main_quit();
677         }
678         
679         private void check_fresh() {
680                 if(!(home.have_fresh || mentions.have_fresh || direct.have_fresh))
681                         tray.new_tweets(false);
682         }
683 }