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