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