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 StatusIcon();
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         
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        
54         
55         var menu = new MenuA();
56                  
57          
58         this.popup_menu.connect( (button,event_time) =>{
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, button,
79                         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         }
109         
110         
111         class ImageMenuItemA : ImageMenuItem {
112             
113             public ImageMenuItemA()
114             {
115                 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
116                 
117                 var  image = new Gtk.Image();
118                 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
119                 this.set_image (image);
120                 
121                 this.label= "Pause Commits";
122                 this.always_show_image = true;
123                 this.accel_group = null;
124                 
125                 this.activate.connect( () => {
126                     statusicon.paused = true;
127                     
128                     //GitMonitor.GitMonitor.stop();
129                    // this.el.label  = status ? 'Resume' : 'Pause';
130                     statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
131                     
132                     
133                 });
134                 //    id : 'pause',
135             }
136             
137             
138         }
139          class ImageMenuItemB : ImageMenuItem {
140             
141             public ImageMenuItemB()
142             {
143                 
144                 var  image = new Gtk.Image();
145                 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
146                 this.set_image (image);
147                 this.label= "Start Commits";
148                 this.always_show_image = true;
149                 this.accel_group = null;
150                 
151                 this.activate.connect( () => {
152                     //GitMonitor.GitMonitor.start();
153                     statusicon.paused = false;
154                     
155                     //
156                    // this.el.label  = status ? 'Resume' : 'Pause';
157                     statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
158                     
159                     
160                 });
161                 //    id : 'pause',
162             }
163             
164             
165         }
166     }
167 }
168     
169     /*
170                 
171                 {
172                     init : function() {
173                         this.el = XObject.isSeed ?
174                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_FULLSCREEN)
175                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_FULLSCREEN, null);
176                       
177                         XObject.prototype.init.call(this);
178                     },
179                     label: 'Pull (Refresh) All',
180                     always_show_image : true,
181                     accel_group : null,
182                     //label: 'Pause',
183                     pack:  'append',
184                     listeners : {
185                         activate : function () {
186                             imports.GitMonitor.GitMonitor.stop();
187                            
188                             
189                             var tr = imports.Scm.Repo.Repo.list();
190                             for (var i= 0; i< tr.length;i++) {
191                                 this.parent.parent.el.set_from_stock( i%2 ?  Gtk.STOCK_FULLSCREEN : Gtk.STOCK_LEAVE_FULLSCREEN );
192                                 
193                                 var repo = tr[i];
194                                 if (!repo.autocommit()) {
195                                     //??? should we ignore ones not on autocommit..
196                                     continue;
197                                 }
198                                 try {
199                                     this.parent.parent.el.set_tooltip_text("pull: " + repo.name);
200                                
201                                     var str = repo.pull();
202                                     // do not care if it's already in sycn..
203                                     if (str.match(/Already up-to-date/)) {
204                                         continue;
205                                     }
206                                     var notification = new Notify.Notification({
207                                        summary: "Updated " + repo.name,
208                                        body : str
209                                    });
210                                    notification.set_timeout(20);
211                                    notification.show();
212                                    
213                                 } catch(e) {
214                                     this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_RECORD );
215                                     print(JSON.stringify(e));
216                                     print("notification or push errror- probably to many in queue..");
217                                     imports.gitlive.errorDialog(e.message);
218
219                                 }
220                             }
221                             this.parent.parent.el.set_tooltip_text(this.parent.parent.tooltip_text);
222                                
223                             
224                              
225                           
226                             imports.GitMonitor.GitMonitor.start();
227                         }   
228                     }
229                 },
230                 {
231                     init : function() {
232                         this.el = XObject.isSeed ?
233                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_SAVE)
234                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_SAVE, null);
235                          
236                         XObject.prototype.init.call(this);
237                     },
238                     label: 'Update Timesheet',
239                     always_show_image : true,
240                     accel_group : null,
241                     
242                     //label: 'Pause',
243                     pack:  'append',
244                     listeners : {
245                         activate : function () {
246                             var ret = imports.FixBug.FixBug.show();
247                             
248                         }
249                     }
250                 },
251                 
252                 
253                 {
254                     init : function() {
255                         this.el = XObject.isSeed ?
256                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_FULLSCREEN)
257                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_FULLSCREEN, null);
258                          XObject.prototype.init.call(this);
259                     },
260                     label: 'Manage Clones',
261                     always_show_image : true,
262                     accel_group : null,
263                     
264                     //label: 'Pause',
265                     pack:  'append',
266                     listeners : {
267                         activate : function () {
268                              var ret = imports.Clones.Clones.show();
269                             
270                         }
271                     }
272                 },
273                 
274                 
275                 
276             
277                 {
278                     init : function() {
279                         this.el = XObject.isSeed ?
280                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_ABOUT)
281                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_ABOUT, null);
282                    
283                         XObject.prototype.init.call(this);
284                     },
285                     label: 'About GitLive',
286                     pack:  'append',
287                     listeners : {
288                         activate : function () {
289                             var msg = new Gtk.AboutDialog({
290                                 program_name : "Git Live",
291                                 version: '0.3',
292                                 website: 'http://www.roojs.org/index.php/projects/gitlive.html',
293                                 website_label: 'RooJS Consulting',
294                                 license : 'LGPL'
295                             });
296                             msg.set_authors([ "Alan Knowles <alan@roojs.com>" ]);
297                             msg.run();
298                             msg.destroy();
299                         }
300                     }
301                 },
302                 
303                 {
304                     init : function() {
305                         
306                         this.el = XObject.isSeed ?
307                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_QUIT)
308                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_QUIT, null);
309                      
310                         XObject.prototype.init.call(this);
311                     },
312                     label: 'Quit',
313                     pack:  'append',
314                     listeners : {
315                         activate : function () {
316                             Seed.quit();
317                         }
318                     }
319                 }
320                 
321                 
322             ]
323         }
324     ]
325     
326 });
327 */
328
329