more test on spawn
[gitlive] / StatusIcon.js
1 //<script type="text/javascript">
2
3
4 /**
5  * Status icon and menu for component of gitlive.
6  * 
7  * Implements XObject - however we want to control initialization.
8  * 
9  * 
10  * 
11  * Currently only does a few things
12  * a) Quit
13  * 
14  * b) Pause!??!
15  */
16  
17 var Gtk      = imports.gi.Gtk;
18 var Gdk      = imports.gi.Gdk;
19 var Gio      = imports.gi.Gio;
20 var GLib     = imports.gi.GLib;
21 var Notify   = imports.gi.Notify;
22
23 var Git = imports.Git;
24 var XObject = imports.XObject.XObject;
25
26 //var gitlive = imports.gitlive;
27
28  
29 var StatusIcon  = new XObject({
30     
31     paused : false, // on!
32     xtype : Gtk.StatusIcon,
33     title : 'gitlive',
34     stock : Gtk.STOCK_MEDIA_PLAY,
35     tooltip_text : 'GitLive',
36         init : function() {
37         XObject.prototype.init.call(this);
38         this.el.set_name('gitlive');
39     },
40     listeners : {
41         //'popup-menu' : function( w, event, event_time) {
42         'activate' : function( w, event, event_time) {
43             print(Array.prototype.slice.call(arguments).join(','));
44             
45             var menu = this.get('menu');
46             
47             menu.el.show_all();
48             
49             this.get(!this.paused ? 'resume' : 'pause' ).el.hide();
50             
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             var g = { };
57             var a = new Gdk.Rectangle();
58             //  needs direction=inout setting in gir to work (in bugzilla @present)
59             this.el.get_geometry(g,a,null);
60              
61             // should check to see if @ top or bottom I guess..
62             menu.el.get_toplevel().move(a.x, a.y +a.height);
63              
64         }
65     },
66     items : [
67        {
68             xtype: Gtk.Menu,
69             id : 'menu',
70             pack: false,
71             items : [
72                 {
73                     init : function() {
74                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_MEDIA_PAUSE);
75                         XObject.prototype.init.call(this);
76                     },
77                     label: 'Pause Commits',
78                    
79                     always_show_image : true,
80                     accel_group : null,
81                     id : 'pause',
82                     //label: 'Pause',
83                     pack:  'append',
84                     listeners : {
85                         activate : function () {
86                             this.parent.parent.paused = true;
87                             imports.gitlive.monitor.stop();
88                            // this.el.label  = status ? 'Resume' : 'Pause';
89                             this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
90                             
91                         }
92                     }
93                 },
94                 
95                 {
96                     init : function() {
97                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_MEDIA_PLAY);
98                         XObject.prototype.init.call(this);
99                     },
100                     label: 'Resume Commits',
101                     always_show_image : true,
102                     accel_group : null,
103                     id : 'resume',
104                     //label: 'Pause',
105                     pack:  'append',
106                     listeners : {
107                         activate : function () {
108                             this.parent.parent.paused = false;
109                             imports.gitlive.monitor.start();
110                             //var status = this.el.label == 'Pause' ? 1 : 0
111                            // this.el.label  = status ? 'Resume' : 'Pause';
112                             this.parent.parent.el.set_from_stock(   Gtk.STOCK_MEDIA_PLAY);
113                             
114                         }
115                     }
116                 },
117                 
118                 {
119                     init : function() {
120                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_RELOAD);
121                         XObject.prototype.init.call(this);
122                     },
123                     label: 'Pull (Refresh) All',
124                     always_show_image : true,
125                     accel_group : null,
126                     //label: 'Pause',
127                     pack:  'append',
128                     listeners : {
129                         activate : function () {
130                             imports.gitlive.monitor.stop();
131                             
132                             var f = Gio.file_new_for_path(imports.gitlive.gitlive);
133                             var file_enum = f.enumerate_children(
134                                 Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, Gio.FileQueryInfoFlags.NONE, null);
135
136                             var next_file = null;
137                             
138                             while ((next_file = file_enum.next_file(null)) != null) {
139                                 
140                                 var fn = imports.gitlive.gitlive + '/' + next_file.get_display_name();
141                                 if (! GLib.file_test(fn + '/.git', GLib.FileTest.IS_DIR)) {
142                                     continue;
143                                 }
144                                 
145                                 
146                                 var res = Git.run(fn,  'pull' );
147                                 if (res.result * 1  == 0) {
148                                     try {
149                                         var notification = new Notify.Notification({
150                                             summary: "Updated " + fn,
151                                             body : res.output
152                                         });
153                                         notification.set_timeout(20);
154                                         notification.show();
155                                     } catch(e) {
156                                         print("notification - probably to many in queue..");
157                                     }
158                                     continue;
159                                 }
160                                 imports.gitlive.errorDialog(res.stderr);
161                                     // should also update modules ideally.
162                                 
163                             }
164                             
165                                 
166                             file_enum.close(null);
167
168                             
169                             imports.gitlive.monitor.start();
170                             
171                         }
172                     }
173                 },
174                 {
175                     init : function() {
176                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_RELOAD);
177                         XObject.prototype.init.call(this);
178                     },
179                     label: 'Manage Clones',
180                     always_show_image : true,
181                     accel_group : null,
182                     
183                     //label: 'Pause',
184                     pack:  'append',
185                     listeners : {
186                         activate : function () {
187                              
188                             
189                         }
190                     }
191                 },
192                 
193                 
194                 
195             
196                 {
197                     init : function() {
198                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_ABOUT);
199                         XObject.prototype.init.call(this);
200                     },
201                     label: 'About GitLive',
202                     pack:  'append',
203                     listeners : {
204                         activate : function () {
205                             var msg = new Gtk.AboutDialog({
206                                 program_name : "Git Live",
207                                 version: '0.1',
208                                 website: 'http://git.akbkhome.com',
209                                 website_label: 'AK BK Consulting (git repo)',
210                                 license : 'LGPL'
211                             });
212                             msg.set_authors([ "Alan Knowles <alan@akbkhome.com>" ]);
213                             msg.run();
214                             msg.destroy();
215                         }
216                     }
217                 },
218                 
219                 {
220                     init : function() {
221                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_QUIT);
222                         XObject.prototype.init.call(this);
223                     },
224                     label: 'Quit',
225                     pack:  'append',
226                     listeners : {
227                         activate : function () {
228                             Seed.quit();
229                         }
230                     }
231                 }
232                 
233                 
234             ]
235         }
236     ]
237     
238 });
239
240