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