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