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