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