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