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