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     bool paused = false;
41     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 = "vgitlive";
51         
52         this.set_name("vgitlive");
53         this.set_visible(true);      
54         
55         var menu = new MenuA();
56                  
57          
58         this.activate.connect( () =>{
59             
60             //print(Array.prototype.slice.call(arguments).join(','));
61             
62             //var menu = this.get('menu');
63             
64             menu.show_all();
65             
66             if (this.paused) {
67                 menu.resume.show();
68                 menu.pause.hide();
69             } else {
70                 menu.resume.hide();
71                 menu.pause.show();
72             }
73               
74             //Gtk.get_current_event_device ()
75             menu.popup(
76                     
77                         null, null,
78                         this.position_menu, 0,
79                          Gtk.get_current_event_time()
80             );
81                         
82             
83             
84             //var g = { };
85             //var a = new Gdk.Rectangle();
86             //  needs direction=inout setting in gir to work (in bugzilla @present)
87             //this.el.get_geometry(g,a,null);
88              
89             // should check to see if @ top or bottom I guess..
90             //menu.el.get_toplevel().move(a.x, a.y +a.height);
91             //menu.el.get_toplevel().move(10,10);
92               
93         }); 
94         
95     }
96     
97     class MenuA : Gtk.Menu
98     {
99         public ImageMenuItem pause;
100         public ImageMenuItem resume;
101         
102         public MenuA()
103         {
104             this.pause = new ImageMenuItemA();
105             this.append(this.pause);
106             this.resume = new ImageMenuItemB();
107             this.append(this.resume);
108             this.append(new ImageMenuItemC());
109             this.append(new ImageMenuItemD());
110             this.append(new ImageMenuItemE());
111             this.append(new ImageMenuItemF());
112             this.append(new ImageMenuItemG());
113             
114             
115             
116         }
117         
118         
119         class ImageMenuItemA : ImageMenuItem {
120             
121             public ImageMenuItemA()
122             {
123                 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
124                 
125                 var  image = new Gtk.Image();
126                 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
127                 this.set_image (image);
128                 
129                 this.label= "Pause Commits";
130                 this.always_show_image = true;
131                 this.accel_group = null;
132                 
133                 this.activate.connect( () => {
134                     statusicon.paused = true;
135                     
136                     //GitMonitor.GitMonitor.stop();
137                    // this.el.label  = status ? 'Resume' : 'Pause';
138                     statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
139                     
140                     
141                 });
142                 //    id : 'pause',
143             }
144             
145             
146         }
147         class ImageMenuItemB : ImageMenuItem {
148             
149             public ImageMenuItemB()
150             {
151                 
152                 var  image = new Gtk.Image();
153                 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
154                 this.set_image (image);
155                 this.label= "Start Commits";
156                 this.always_show_image = true;
157                 this.accel_group = null;
158                 
159                 this.activate.connect( () => {
160                     //GitMonitor.GitMonitor.start();
161                     statusicon.paused = false;
162                     
163                     //
164                    // this.el.label  = status ? 'Resume' : 'Pause';
165                     statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
166                     
167                     
168                 });
169             }
170             
171             
172         }
173         
174         class ImageMenuItemC : ImageMenuItem {
175             
176             public ImageMenuItemC()
177             {
178                 
179                 var  image = new Gtk.Image();
180                 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
181                 this.set_image (image);
182                 this.label= "Pull (Refresh) All";
183                 this.always_show_image = true;
184                 this.accel_group = null;
185                 
186                 this.activate.connect( () => {
187                     /*
188                    imports.GitMonitor.GitMonitor.stop();
189                            
190                             
191                             var tr = imports.Scm.Repo.Repo.list();
192                             for (var i= 0; i< tr.length;i++) {
193                                 this.parent.parent.el.set_from_stock( i%2 ?  Gtk.STOCK_FULLSCREEN : Gtk.STOCK_LEAVE_FULLSCREEN );
194                                 
195                                 var repo = tr[i];
196                                 if (!repo.autocommit()) {
197                                     //??? should we ignore ones not on autocommit..
198                                     continue;
199                                 }
200                                 try {
201                                     this.parent.parent.el.set_tooltip_text("pull: " + repo.name);
202                                
203                                     var str = repo.pull();
204                                     // do not care if it's already in sycn..
205                                     if (str.match(/Already up-to-date/)) {
206                                         continue;
207                                     }
208                                     var notification = new Notify.Notification({
209                                        summary: "Updated " + repo.name,
210                                        body : str
211                                    });
212                                    notification.set_timeout(20);
213                                    notification.show();
214                                    
215                                 } catch(e) {
216                                     this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_RECORD );
217                                     print(JSON.stringify(e));
218                                     print("notification or push errror- probably to many in queue..");
219                                     imports.gitlive.errorDialog(e.message);
220
221                                 }
222                             }
223                             this.parent.parent.el.set_tooltip_text(this.parent.parent.tooltip_text);
224                                
225                             
226                              
227                           
228                             imports.GitMonitor.GitMonitor.start();
229                     
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