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