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