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        //this.button_press_event.connect( (  ) =>{
61                
62             //print(Array.prototype.slice.call(arguments).join(','));
63             print("menu activiate called\n");
64             //var menu = this.get('menu');
65             
66             menu.show_all();
67             
68             if (this.paused) {
69                 menu.resume.show();
70                 menu.pause.hide();
71             } else {
72                 menu.resume.hide();
73                 menu.pause.show();
74             }
75               //                public void popup (Gtk.Widget? parent_menu_shell, Gtk.Widget? parent_menu_item,
76                     // [CCode (scope = "async")] Gtk.MenuPositionFunc? func, uint button, uint32 activate_time);
77             //Gtk.get_current_event_device ()
78             menu.popup(
79
80                         null, null,
81                        this.position_menu,
82                        
83                     button,  time //   time
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             //return false;
96               
97         }); 
98         
99     }
100     
101     class MenuA : Gtk.Menu
102     {
103         public ImageMenuItem pause;
104         public ImageMenuItem resume;
105         
106         public MenuA()
107         {
108             this.pause = new ImageMenuItemA();
109             this.append(this.pause);
110             this.resume = new ImageMenuItemB();
111             this.append(this.resume);
112             this.append(new ImageMenuItemC());
113             this.append(new ImageMenuItemD());
114             this.append(new ImageMenuItemE());
115             this.append(new ImageMenuItemF());
116             this.append(new ImageMenuItemG());
117             
118             
119             
120         }
121         
122         
123         class ImageMenuItemA : ImageMenuItem {
124             
125             public ImageMenuItemA()
126             {
127                 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
128                 
129                 var  image = new Gtk.Image();
130                 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
131                 this.set_image (image);
132                 
133                 this.label= "Pause Commits";
134                 this.always_show_image = true;
135                 this.accel_group = null;
136                 
137                 this.activate.connect( () => {
138                     statusicon.paused = true;
139                     GitMonitor.gitmonitor.stop();
140
141                    // this.el.label  = status ? 'Resume' : 'Pause';
142                     statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
143                     
144                     
145                 });
146                 //    id : 'pause',
147             }
148             
149             
150         }
151         class ImageMenuItemB : ImageMenuItem {
152             
153             public ImageMenuItemB()
154             {
155                 
156                 var  image = new Gtk.Image();
157                 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
158                 this.set_image (image);
159                 this.label= "Start Commits";
160                 this.always_show_image = true;
161                 this.accel_group = null;
162                 
163                 this.activate.connect( () => {
164                     GitMonitor.gitmonitor.start();
165                     statusicon.paused = false;
166                     
167                     //
168                    // this.el.label  = status ? 'Resume' : 'Pause';
169                     statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
170                     
171                     
172                 });
173             }
174             
175             
176         }
177         
178         
179         class ImageMenuItemC : ImageMenuItem {
180             
181             public ImageMenuItemC()
182             {
183                 
184                 var  image = new Gtk.Image();
185                 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
186                 this.set_image (image);
187                 this.label= "Pull (Refresh) All";
188                 this.always_show_image = true;
189                 this.accel_group = null;
190                 
191                 this.activate.connect( () => {
192                     GitMonitor.gitmonitor.stop();
193                     var tr = GitRepo.list();
194                     for (var i= 0; i< tr.length;i++) {
195                         statusicon.set_from_stock( i%2 == 0 ?  Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
196                                 
197                         var repo = tr.index(i);
198                         //if (!repo.autocommit()) {
199                             //??? should we ignore ones not on autocommit..
200                         //    continue;
201                         //}
202                         try {
203                             statusicon.set_tooltip_text("pull: " + repo.name);
204                             var str = repo.pull();
205                                     // do not care if it's already in sycn..
206                             if (Regex.match_simple ("Already up-to-date", str) ) {
207                                 continue;
208                             }
209                             var notification = new Notify.Notification( 
210                                      "Updated " + repo.name,
211                                      str,
212                                        "dialog-information"
213                                    
214                             );
215                         
216                             notification.set_timeout(20);
217                             notification.show();
218                                      
219                         } catch(Error e) {
220                             print("notification or push errror- probably to many in queue..");
221                             statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
222                             print(e.message);
223                             
224                         }        
225
226                     } 
227                     statusicon.set_tooltip_text("Gitlive");
228                              
229                             
230                     GitMonitor.gitmonitor.start();         
231                            
232                 });
233             }
234             
235             
236         }
237         
238         
239         class ImageMenuItemD : ImageMenuItem {
240             
241             public ImageMenuItemD()
242             {
243                 
244                 var  image = new Gtk.Image();
245                 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
246                 this.set_image (image);
247                 this.label= "Update Timesheet";
248                 this.always_show_image = true;
249                 this.accel_group = null;
250                 
251                 this.activate.connect( () => {
252                  //var ret = imports.FixBug.FixBug.show();
253                 });
254             }
255             
256             
257         }
258         
259         class ImageMenuItemE : ImageMenuItem {
260             
261             public ImageMenuItemE()
262             {
263                 
264                 var  image = new Gtk.Image();
265                 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
266                 this.set_image (image);
267                 this.label= "Manage Clones";
268                 this.always_show_image = true;
269                 this.accel_group = null;
270                 
271                 this.activate.connect( () => {
272                  //var ret = imports.Clones.Clones.show();
273                 });
274             }
275             
276             
277         }
278         
279         class ImageMenuItemF : ImageMenuItem {
280             
281             public ImageMenuItemF()
282             {
283                 
284                 var  image = new Gtk.Image();
285                 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
286                 this.set_image (image);
287                 this.label= "About Gitlive";
288                 this.always_show_image = true;
289                 this.accel_group = null;
290                 
291                 this.activate.connect( () => {
292                  //var ret = imports.Clones.Clones.show();
293                  
294                     var msg = new Gtk.AboutDialog();
295                     msg.program_name = "Git Live";
296                     msg.version= "0.3";
297                     msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
298                     msg.website_label= "Roo J Solutions Ltd.";
299                     msg.license = "LGPL";
300                     msg.authors = { "Alan Knowles <alan@roojs.com>" };
301                     msg.run();
302                     msg.destroy();
303                 });
304             }
305             
306             
307         }
308         
309          class ImageMenuItemG : ImageMenuItem {
310             
311             public ImageMenuItemG()
312             {
313                 
314                 var  image = new Gtk.Image();
315                 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
316                 this.set_image (image);
317                 this.label= "Quit";
318                 this.always_show_image = true;
319                 this.accel_group = null;
320                 
321                 this.activate.connect( () => {
322                     // confirm?
323                     Gtk.main_quit();
324                  //var ret = imports.Clones.Clones.show();
325                  });
326             }
327             
328             
329         }
330         
331     }
332 }
333       
334                 
335