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