Imported Upstream version 0.2.7
[debian/pino.git] / src / tray_icon.vala
1 /* tray_icon.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
24 public class TrayIcon : StatusIcon {
25         
26         private MainWindow parent;
27         private Prefs prefs;
28         private Gdk.Pixbuf logo;
29         private Gdk.Pixbuf logo_fresh;
30         
31         private Menu _popup;
32         public Menu popup {
33                 get{ return popup; }
34                 set{ _popup = value; }
35         }
36         
37         public TrayIcon(MainWindow _parent, Prefs _prefs, Gdk.Pixbuf _logo,
38                 Gdk.Pixbuf _logo_fresh) {
39                 
40                 base;
41                 
42                 parent = _parent;
43                 prefs = _prefs;
44
45                 var theme = IconTheme.get_default();
46                 
47                 if(!theme.has_icon("pino-tray-icon")) {
48                         debug("no!!!!!!!!");
49                         logo = _logo;
50                 } else {
51                         var info = theme.lookup_icon("pino-tray-icon", 22, IconLookupFlags.USE_BUILTIN);
52                         logo = info.load_icon();
53                 }
54                 
55                 if(!theme.has_icon("pino-tray-icon")) {
56                         debug("no!!!!!!!!");
57                         logo_fresh = _logo_fresh;
58                 } else {
59                         var info = theme.lookup_icon("pino-tray-icon-fresh", 22, IconLookupFlags.USE_BUILTIN);
60                         logo_fresh = info.load_icon();
61                 }
62                 
63                 
64                 set_from_pixbuf(logo);
65                 parent.set_icon(logo);
66                 
67                 set_tooltip_text(_("%s - not only a twitter client").printf(Config.APPNAME));
68                 
69                 popup_menu.connect((button, activate_time) => {
70                         _popup.popup(null, null, null, button, activate_time);
71                 });
72                 
73                 activate.connect(() => {
74                         if(parent.visible) {
75                                 parent.hide();
76                         } else {
77                                 if(parent.first_show) {
78                                         parent.show_all();
79                                         parent.first_hide();
80                                         parent.first_show = false;
81                                         return;
82                                 }
83                                 
84                                 parent.show();
85                                 parent.move(prefs.left, prefs.top);
86                         }
87                 });
88                 
89                 #if(LIBINDICATE)
90                         var server = Indicate.Server.ref_default();
91                         
92                         server.set_type("message.pino");
93                         server.set_desktop_file(Config.DESKTOP_FILE_PATH);
94                         server.server_display.connect(dirty_activate);
95                         server.show();
96                         
97                         /*
98                         indicator = new Indicate.Indicator();
99                         indicator.set_property("subtype", "pino");
100                         indicator.set_property("sender", "troorl");
101                         indicator.set_property("body", "bla bla bla");
102                         indicator.user_display.connect(dirty_activate);
103                         indicator.show();
104                         */
105                 #endif
106                 
107         }
108
109         private void dirty_activate() {
110                 try {
111                         Process.spawn_async(null, {Config.APP_PATH, "/"}, null,
112                                 GLib.SpawnFlags.STDERR_TO_DEV_NULL, null, null);
113                 } catch(GLib.SpawnError e) {
114                         warning(e.message);
115                 }
116         }
117         
118         public void new_tweets(bool y) {
119                 if(y) {
120                         set_from_pixbuf(logo_fresh);
121                         parent.set_icon(logo_fresh);
122                 }
123                 else {
124                         set_from_pixbuf(logo);
125                         parent.set_icon(logo);
126                 }
127         }
128 }