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