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