StatusIcon.vala
[gitlive] / StatusIcon.vala
1 /**
2  * Status icon and menu for component of gitlive.
3  * 
4  * Implements XObject - however we want to control initialization.
5  * 
6  * 
7  * 
8  * Currently only does a few things
9  * a) Quit
10  * 
11  * b) Pause!??!
12  */
13    
14 // Compile::
15 // valac --pkg gtk+-3.0 StatusIcon.vala -o /tmp/StatusIcon
16    
17 //var gitlive = imports.gitlive;
18
19
20 using Gtk;
21 /*
22
23 static int main (string[] args) {
24     // A reference to our file
25     Gtk.init (ref args);
26     new StatusIconA();
27  
28     Gtk.main ();
29     return 0;
30      
31
32 }
33  */
34
35
36 //public StatusIconA statusicon;
37  
38 public class StatusIconA : StatusIcon {
39
40     public bool paused = false;
41     public static StatusIconA statusicon;
42      
43     public StatusIconA() {
44         
45         statusicon = this;
46         
47          //title : 'gitlive',
48         this.stock = Gtk.Stock.REFRESH;
49         this.tooltip_text = "GitLive";
50         this.title = "gitlive";
51         
52         this.set_name("gitlive");
53         this.set_visible(true);      
54         
55         var menu = new MenuA();
56         menu.ref();       
57
58             
59         this.popup_menu.connect( (  button,   time) =>{
60             
61             //print(Array.prototype.slice.call(arguments).join(','));
62             print("menu activiate called\n");
63             //var menu = this.get('menu');
64             
65             menu.show_all();
66             
67             if (this.paused) {
68                 menu.resume.show();
69                 menu.pause.hide();
70             } else {
71                 menu.resume.hide();
72                 menu.pause.show();
73             }
74               
75             //Gtk.get_current_event_device ()
76             menu.popup(
77                     
78                         null, null,
79                         //this.position_menu,
80                        null,
81                         button,
82                          time
83             );
84                         
85             
86             
87             //var g = { };
88             //var a = new Gdk.Rectangle();
89             //  needs direction=inout setting in gir to work (in bugzilla @present)
90             //this.el.get_geometry(g,a,null);
91              
92             // should check to see if @ top or bottom I guess..
93             //menu.el.get_toplevel().move(a.x, a.y +a.height);
94             //menu.el.get_toplevel().move(10,10);
95               
96         }); 
97         
98     }
99     
100     class MenuA : Gtk.Menu
101     {
102         public ImageMenuItem pause;
103         public ImageMenuItem resume;
104         
105         public MenuA()
106         {
107             this.pause = new ImageMenuItemA();
108             this.append(this.pause);
109             this.resume = new ImageMenuItemB();
110             this.append(this.resume);
111             this.append(new ImageMenuItemC());
112             this.append(new ImageMenuItemD());
113             this.append(new ImageMenuItemE());
114             this.append(new ImageMenuItemF());
115             this.append(new ImageMenuItemG());
116             
117             
118             
119         }
120         
121         
122         class ImageMenuItemA : ImageMenuItem {
123             
124             public ImageMenuItemA()
125             {
126                 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
127                 
128                 var  image = new Gtk.Image();
129                 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
130                 this.set_image (image);
131                 
132                 this.label= "Pause Commits";
133                 this.always_show_image = true;
134                 this.accel_group = null;
135                 
136                 this.activate.connect( () => {
137                     statusicon.paused = true;
138                     GitMonitor.gitmonitor.stop();
139
140                    // this.el.label  = status ? 'Resume' : 'Pause';
141                     statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
142                     
143                     
144                 });
145                 //    id : 'pause',
146             }
147             
148             
149         }
150         class ImageMenuItemB : ImageMenuItem {
151             
152             public ImageMenuItemB()
153             {
154                 
155                 var  image = new Gtk.Image();
156                 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
157                 this.set_image (image);
158                 this.label= "Start Commits";
159                 this.always_show_image = true;
160                 this.accel_group = null;
161                 
162                 this.activate.connect( () => {
163                     GitMonitor.gitmonitor.start();
164                     statusicon.paused = false;
165                     
166                     //
167                    // this.el.label  = status ? 'Resume' : 'Pause';
168                     statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
169                     
170                     
171                 });
172             }
173             
174             
175         }
176         
177         
178         class ImageMenuItemC : ImageMenuItem {
179             
180             public ImageMenuItemC()
181             {
182                 
183                 var  image = new Gtk.Image();
184                 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
185                 this.set_image (image);
186                 this.label= "Pull (Refresh) All";
187                 this.always_show_image = true;
188                 this.accel_group = null;
189                 
190                 this.activate.connect( () => {
191                     GitMonitor.gitmonitor.stop();
192                     var tr = GitRepo.list();
193                     for (var i= 0; i< tr.length;i++) {
194                         statusicon.set_from_stock( i%2 == 0 ?  Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
195                                 
196                         var repo = tr.index(i);
197                         //if (!repo.autocommit()) {
198                             //??? should we ignore ones not on autocommit..
199                         //    continue;
200                         //}
201                         try {
202                             statusicon.set_tooltip_text("pull: " + repo.name);
203                             var str = repo.pull();
204                                     // do not care if it's already in sycn..
205                             if (Regex.match_simple ("Already up-to-date", str) ) {
206                                 continue;
207                             }
208                             var notification = new Notify.Notification( 
209                                      "Updated " + repo.name,
210                                      str,
211                                        "dialog-information"
212                                    
213                             );
214                         
215                             notification.set_timeout(20);
216                             notification.show();
217                                      
218                         } catch(Error e) {
219                             print("notification or push errror- probably to many in queue..");
220                             statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
221                             print(e.message);
222                             
223                         }        
224
225                     } 
226                     statusicon.set_tooltip_text("Gitlive");
227                              
228                             
229                     GitMonitor.gitmonitor.start();         
230                            
231                 });
232             }
233             
234             
235         }
236         
237         
238         class ImageMenuItemD : ImageMenuItem {
239             
240             public ImageMenuItemD()
241             {
242                 
243                 var  image = new Gtk.Image();
244                 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
245                 this.set_image (image);
246                 this.label= "Update Timesheet";
247                 this.always_show_image = true;
248                 this.accel_group = null;
249                 
250                 this.activate.connect( () => {
251                  //var ret = imports.FixBug.FixBug.show();
252                 });
253             }
254             
255             
256         }
257         
258         class ImageMenuItemE : ImageMenuItem {
259             
260             public ImageMenuItemE()
261             {
262                 
263                 var  image = new Gtk.Image();
264                 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
265                 this.set_image (image);
266                 this.label= "Manage Clones";
267                 this.always_show_image = true;
268                 this.accel_group = null;
269                 
270                 this.activate.connect( () => {
271                  //var ret = imports.Clones.Clones.show();
272                 });
273             }
274             
275             
276         }
277         
278         class ImageMenuItemF : ImageMenuItem {
279             
280             public ImageMenuItemF()
281             {
282                 
283                 var  image = new Gtk.Image();
284                 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
285                 this.set_image (image);
286                 this.label= "About Gitlive";
287                 this.always_show_image = true;
288                 this.accel_group = null;
289                 
290                 this.activate.connect( () => {
291                  //var ret = imports.Clones.Clones.show();
292                  
293                     var msg = new Gtk.AboutDialog();
294                     msg.program_name = "Git Live";
295                     msg.version= "0.3";
296                     msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
297                     msg.website_label= "Roo J Solutions Ltd.";
298                     msg.license = "LGPL";
299                     msg.authors = { "Alan Knowles <alan@roojs.com>" };
300                     msg.run();
301                     msg.destroy();
302                 });
303             }
304             
305             
306         }
307         
308          class ImageMenuItemG : ImageMenuItem {
309             
310             public ImageMenuItemG()
311             {
312                 
313                 var  image = new Gtk.Image();
314                 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
315                 this.set_image (image);
316                 this.label= "Quit";
317                 this.always_show_image = true;
318                 this.accel_group = null;
319                 
320                 this.activate.connect( () => {
321                     // confirm?
322                     Gtk.main_quit();
323                  //var ret = imports.Clones.Clones.show();
324                  });
325             }
326             
327             
328         }
329         
330     }
331 }
332       
333                 
334