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
27     var window = new TestWindow();
28     
29     window.show_all ();
30
31     Gtk.main ();
32     return 0;
33      
34
35 }
36
37 public class TestButton : Button {
38     public TestButton()
39     {
40         this.set_label("Click me");
41         
42         
43         this.clicked.connect (() => {
44             this.label = "Thank you";
45         });
46         
47     }
48     
49     
50 }
51
52 public class TestWindow : Window {
53
54     public TestWindow() {
55          this.title = "First GTK+ Program";
56         this.border_width = 10;
57         this.window_position = WindowPosition.CENTER;
58         this.set_default_size (350, 70);
59         
60         // -- connect all
61         this.destroy.connect (Gtk.main_quit);        
62         
63         // add children..
64         this.add(new TestButton());
65
66     }
67    
68     
69  
70    
71 }
72
73
74
75  
76 class StatusIconA : StatusIcon {
77
78     bool paused = false;
79     
80     MenuA menu = null;
81     
82     public StatusIconA() {
83          //title : 'gitlive',
84         this.stock = Gtk.STOCK_REFRESH;
85         this.tooltip_text = "GitLive";
86         this.title = "gitlive";
87         
88         this.set_name("gitlive");
89        
90         
91         var menu = new MenuA();
92                  
93          
94         this.popup_menu.connect( (button,event_time) =>{
95             
96             //print(Array.prototype.slice.call(arguments).join(','));
97             
98             //var menu = this.get('menu');
99             
100             this.menu.show_all();
101             
102             if (this.paused) {
103                 menu.resume.show();
104                 menu.pause.hide();
105             } else {
106                 menu.resume.hide();
107                 menu.pause.show();
108             }
109              
110             //Gtk.get_current_event_device ()
111             menu.popup(
112                     
113                         null, null,
114                         null, button,
115                         event_time, null
116             );
117                         
118             
119             
120             //var g = { };
121             //var a = new Gdk.Rectangle();
122             //  needs direction=inout setting in gir to work (in bugzilla @present)
123             //this.el.get_geometry(g,a,null);
124              
125             // should check to see if @ top or bottom I guess..
126             //menu.el.get_toplevel().move(a.x, a.y +a.height);
127             //menu.el.get_toplevel().move(10,10);
128               
129         }); 
130         
131     }
132     
133     class MenuA : Menu
134     {
135         public ImageMenuItem pause;
136         public ImageMenuItem resume;
137         
138         public MenuA()
139         {
140             this.pause = new ImageMenuItemA();
141             this.append(this.pause);
142             this.resume = new ImageMenuItemB();
143             this.append(this.resume);
144         }
145         
146         
147         class ImageMenuItemA : ImageMenuItem {
148             
149             public ImageMenuItemA()
150             {
151                 this.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
152                 this.label= "Pause Commits";
153                 this.always_show_image = true;
154                 this.accel_group = null;
155                 
156                 this.activate.connect( () => {
157                     this.parent.parent.paused = true;
158                     imports.GitMonitor.GitMonitor.stop();
159                    // this.el.label  = status ? 'Resume' : 'Pause';
160                     this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
161                     
162                     
163                 })
164                 //    id : 'pause',
165             }
166             
167             
168         }
169         
170     }
171     
172          
173     items : [
174        {
175             xtype: Gtk.Menu,
176             id : 'menu',
177             pack: false,
178             items : [
179                 {
180                     
181                     //label: 'Pause',
182                     pack:  'append',
183                     listeners : {
184                         activate : function () {
185                             this.parent.parent.paused = true;
186                             imports.GitMonitor.GitMonitor.stop();
187                            // this.el.label  = status ? 'Resume' : 'Pause';
188                             this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
189                             
190                         }
191                     }
192                 },
193                 
194                 {
195                     init : function() {
196                         this.el = XObject.isSeed ?
197                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_MEDIA_PLAY)
198                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_MEDIA_PLAY, null);
199                         XObject.prototype.init.call(this);
200                     },
201                     label: 'Resume Commits',
202                     always_show_image : true,
203                     accel_group : null,
204                     id : 'resume',
205                     //label: 'Pause',
206                     pack:  'append',
207                     listeners : {
208                         activate : function () {
209                             this.parent.parent.paused = false;
210                              imports.GitMonitor.GitMonitor.start();
211                             //var status = this.el.label == 'Pause' ? 1 : 0
212                            // this.el.label  = status ? 'Resume' : 'Pause';
213                                
214                             
215                         }
216                     }
217                 },
218                 
219                 {
220                     init : function() {
221                         this.el = XObject.isSeed ?
222                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_FULLSCREEN)
223                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_FULLSCREEN, null);
224                       
225                         XObject.prototype.init.call(this);
226                     },
227                     label: 'Pull (Refresh) All',
228                     always_show_image : true,
229                     accel_group : null,
230                     //label: 'Pause',
231                     pack:  'append',
232                     listeners : {
233                         activate : function () {
234                             imports.GitMonitor.GitMonitor.stop();
235                            
236                             
237                             var tr = imports.Scm.Repo.Repo.list();
238                             for (var i= 0; i< tr.length;i++) {
239                                 this.parent.parent.el.set_from_stock( i%2 ?  Gtk.STOCK_FULLSCREEN : Gtk.STOCK_LEAVE_FULLSCREEN );
240                                 
241                                 var repo = tr[i];
242                                 if (!repo.autocommit()) {
243                                     //??? should we ignore ones not on autocommit..
244                                     continue;
245                                 }
246                                 try {
247                                     this.parent.parent.el.set_tooltip_text("pull: " + repo.name);
248                                
249                                     var str = repo.pull();
250                                     // do not care if it's already in sycn..
251                                     if (str.match(/Already up-to-date/)) {
252                                         continue;
253                                     }
254                                     var notification = new Notify.Notification({
255                                        summary: "Updated " + repo.name,
256                                        body : str
257                                    });
258                                    notification.set_timeout(20);
259                                    notification.show();
260                                    
261                                 } catch(e) {
262                                     this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_RECORD );
263                                     print(JSON.stringify(e));
264                                     print("notification or push errror- probably to many in queue..");
265                                     imports.gitlive.errorDialog(e.message);
266
267                                 }
268                             }
269                             this.parent.parent.el.set_tooltip_text(this.parent.parent.tooltip_text);
270                                
271                             
272                              
273                           
274                             imports.GitMonitor.GitMonitor.start();
275                         }   
276                     }
277                 },
278                 {
279                     init : function() {
280                         this.el = XObject.isSeed ?
281                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_SAVE)
282                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_SAVE, null);
283                          
284                         XObject.prototype.init.call(this);
285                     },
286                     label: 'Update Timesheet',
287                     always_show_image : true,
288                     accel_group : null,
289                     
290                     //label: 'Pause',
291                     pack:  'append',
292                     listeners : {
293                         activate : function () {
294                             var ret = imports.FixBug.FixBug.show();
295                             
296                         }
297                     }
298                 },
299                 
300                 
301                 {
302                     init : function() {
303                         this.el = XObject.isSeed ?
304                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_FULLSCREEN)
305                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_FULLSCREEN, null);
306                          XObject.prototype.init.call(this);
307                     },
308                     label: 'Manage Clones',
309                     always_show_image : true,
310                     accel_group : null,
311                     
312                     //label: 'Pause',
313                     pack:  'append',
314                     listeners : {
315                         activate : function () {
316                              var ret = imports.Clones.Clones.show();
317                             
318                         }
319                     }
320                 },
321                 
322                 
323                 
324             
325                 {
326                     init : function() {
327                         this.el = XObject.isSeed ?
328                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_ABOUT)
329                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_ABOUT, null);
330                    
331                         XObject.prototype.init.call(this);
332                     },
333                     label: 'About GitLive',
334                     pack:  'append',
335                     listeners : {
336                         activate : function () {
337                             var msg = new Gtk.AboutDialog({
338                                 program_name : "Git Live",
339                                 version: '0.3',
340                                 website: 'http://www.roojs.org/index.php/projects/gitlive.html',
341                                 website_label: 'RooJS Consulting',
342                                 license : 'LGPL'
343                             });
344                             msg.set_authors([ "Alan Knowles <alan@roojs.com>" ]);
345                             msg.run();
346                             msg.destroy();
347                         }
348                     }
349                 },
350                 
351                 {
352                     init : function() {
353                         
354                         this.el = XObject.isSeed ?
355                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_QUIT)
356                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_QUIT, null);
357                      
358                         XObject.prototype.init.call(this);
359                     },
360                     label: 'Quit',
361                     pack:  'append',
362                     listeners : {
363                         activate : function () {
364                             Seed.quit();
365                         }
366                     }
367                 }
368                 
369                 
370             ]
371         }
372     ]
373     
374 });
375 */
376
377