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   new StatusIcon();
27     
28     window.show_all ();
29
30     Gtk.main ();
31     return 0;
32      
33
34 }
35  
36
37
38 pubic StatusIconA statusicon;
39  
40 class StatusIconA : StatusIcon {
41
42     bool paused = false;
43      
44     public StatusIconA() {
45         
46         statusicon = this;
47         
48         
49          //title : 'gitlive',
50         this.stock = Gtk.STOCK_REFRESH;
51         this.tooltip_text = "GitLive";
52         this.title = "gitlive";
53         
54         this.set_name("gitlive");
55        
56         
57         var menu = new MenuA();
58                  
59          
60         this.popup_menu.connect( (button,event_time) =>{
61             
62             //print(Array.prototype.slice.call(arguments).join(','));
63             
64             //var menu = this.get('menu');
65             
66             this.menu.show_all();
67             
68             if (this.paused) {
69                 menu.resume.show();
70                 menu.pause.hide();
71             } else {
72                 menu.resume.hide();
73                 menu.pause.show();
74             }
75              
76             //Gtk.get_current_event_device ()
77             menu.popup(
78                     
79                         null, null,
80                         null, button,
81                         event_time, null
82             );
83                         
84             
85             
86             //var g = { };
87             //var a = new Gdk.Rectangle();
88             //  needs direction=inout setting in gir to work (in bugzilla @present)
89             //this.el.get_geometry(g,a,null);
90              
91             // should check to see if @ top or bottom I guess..
92             //menu.el.get_toplevel().move(a.x, a.y +a.height);
93             //menu.el.get_toplevel().move(10,10);
94               
95         }); 
96         
97     }
98     
99     class MenuA : Menu
100     {
101         public ImageMenuItem pause;
102         public ImageMenuItem resume;
103         
104         public MenuA()
105         {
106             this.pause = new ImageMenuItemA();
107             this.append(this.pause);
108             this.resume = new ImageMenuItemB();
109             this.append(this.resume);
110         }
111         
112         
113         class ImageMenuItemA : ImageMenuItem {
114             
115             public ImageMenuItemA()
116             {
117                 this.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
118                 this.label= "Pause Commits";
119                 this.always_show_image = true;
120                 this.accel_group = null;
121                 
122                 this.activate.connect( () => {
123                     statusicon.paused = true;
124                     
125                     //GitMonitor.GitMonitor.stop();
126                    // this.el.label  = status ? 'Resume' : 'Pause';
127                     statusicon.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
128                     
129                     
130                 })
131                 //    id : 'pause',
132             }
133             
134             
135         }
136          class ImageMenuItemB : ImageMenuItem {
137             
138             public ImageMenuItemB()
139             {
140                 this.set_from_stock( Gtk.STOCK_MEDIA_PLAY );
141                 this.label= "Start Commits";
142                 this.always_show_image = true;
143                 this.accel_group = null;
144                 
145                 this.activate.connect( () => {
146                     //GitMonitor.GitMonitor.start();
147                     statusicon.paused = false;
148                     
149                     //
150                    // this.el.label  = status ? 'Resume' : 'Pause';
151                     statusicon.set_from_stock( Gtk.STOCK_MEDIA_PLAY );
152                     
153                     
154                 })
155                 //    id : 'pause',
156             }
157             
158             
159         }
160     }
161 }
162     
163     /*
164                 
165                 {
166                     init : function() {
167                         this.el = XObject.isSeed ?
168                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_FULLSCREEN)
169                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_FULLSCREEN, null);
170                       
171                         XObject.prototype.init.call(this);
172                     },
173                     label: 'Pull (Refresh) All',
174                     always_show_image : true,
175                     accel_group : null,
176                     //label: 'Pause',
177                     pack:  'append',
178                     listeners : {
179                         activate : function () {
180                             imports.GitMonitor.GitMonitor.stop();
181                            
182                             
183                             var tr = imports.Scm.Repo.Repo.list();
184                             for (var i= 0; i< tr.length;i++) {
185                                 this.parent.parent.el.set_from_stock( i%2 ?  Gtk.STOCK_FULLSCREEN : Gtk.STOCK_LEAVE_FULLSCREEN );
186                                 
187                                 var repo = tr[i];
188                                 if (!repo.autocommit()) {
189                                     //??? should we ignore ones not on autocommit..
190                                     continue;
191                                 }
192                                 try {
193                                     this.parent.parent.el.set_tooltip_text("pull: " + repo.name);
194                                
195                                     var str = repo.pull();
196                                     // do not care if it's already in sycn..
197                                     if (str.match(/Already up-to-date/)) {
198                                         continue;
199                                     }
200                                     var notification = new Notify.Notification({
201                                        summary: "Updated " + repo.name,
202                                        body : str
203                                    });
204                                    notification.set_timeout(20);
205                                    notification.show();
206                                    
207                                 } catch(e) {
208                                     this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_RECORD );
209                                     print(JSON.stringify(e));
210                                     print("notification or push errror- probably to many in queue..");
211                                     imports.gitlive.errorDialog(e.message);
212
213                                 }
214                             }
215                             this.parent.parent.el.set_tooltip_text(this.parent.parent.tooltip_text);
216                                
217                             
218                              
219                           
220                             imports.GitMonitor.GitMonitor.start();
221                         }   
222                     }
223                 },
224                 {
225                     init : function() {
226                         this.el = XObject.isSeed ?
227                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_SAVE)
228                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_SAVE, null);
229                          
230                         XObject.prototype.init.call(this);
231                     },
232                     label: 'Update Timesheet',
233                     always_show_image : true,
234                     accel_group : null,
235                     
236                     //label: 'Pause',
237                     pack:  'append',
238                     listeners : {
239                         activate : function () {
240                             var ret = imports.FixBug.FixBug.show();
241                             
242                         }
243                     }
244                 },
245                 
246                 
247                 {
248                     init : function() {
249                         this.el = XObject.isSeed ?
250                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_FULLSCREEN)
251                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_FULLSCREEN, null);
252                          XObject.prototype.init.call(this);
253                     },
254                     label: 'Manage Clones',
255                     always_show_image : true,
256                     accel_group : null,
257                     
258                     //label: 'Pause',
259                     pack:  'append',
260                     listeners : {
261                         activate : function () {
262                              var ret = imports.Clones.Clones.show();
263                             
264                         }
265                     }
266                 },
267                 
268                 
269                 
270             
271                 {
272                     init : function() {
273                         this.el = XObject.isSeed ?
274                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_ABOUT)
275                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_ABOUT, null);
276                    
277                         XObject.prototype.init.call(this);
278                     },
279                     label: 'About GitLive',
280                     pack:  'append',
281                     listeners : {
282                         activate : function () {
283                             var msg = new Gtk.AboutDialog({
284                                 program_name : "Git Live",
285                                 version: '0.3',
286                                 website: 'http://www.roojs.org/index.php/projects/gitlive.html',
287                                 website_label: 'RooJS Consulting',
288                                 license : 'LGPL'
289                             });
290                             msg.set_authors([ "Alan Knowles <alan@roojs.com>" ]);
291                             msg.run();
292                             msg.destroy();
293                         }
294                     }
295                 },
296                 
297                 {
298                     init : function() {
299                         
300                         this.el = XObject.isSeed ?
301                             new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_QUIT)
302                             : new Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_QUIT, null);
303                      
304                         XObject.prototype.init.call(this);
305                     },
306                     label: 'Quit',
307                     pack:  'append',
308                     listeners : {
309                         activate : function () {
310                             Seed.quit();
311                         }
312                     }
313                 }
314                 
315                 
316             ]
317         }
318     ]
319     
320 });
321 */
322
323