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