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