try fix
[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             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                                         
149                                     var notification = new Notify.Notification({
150                                         summary: "Updated " + fn,
151                                         body : res.output
152                                     });
153                                     notification.set_timeout(1000);
154                                     notification.show();
155                                     continue;
156                                 }
157                                 imports.gitlive.errorDialog(res.stderr);
158                                     // should also update modules ideally.
159                                 
160                             }
161                             
162                                 
163                             file_enum.close(null);
164
165                             
166                             imports.gitlive.monitor.start();
167                             
168                         }
169                     }
170                 },
171                 {
172                     init : function() {
173                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_RELOAD);
174                         XObject.prototype.init.call(this);
175                     },
176                     label: 'Manage Clones',
177                     always_show_image : true,
178                     accel_group : null,
179                     
180                     //label: 'Pause',
181                     pack:  'append',
182                     listeners : {
183                         activate : function () {
184                              
185                             
186                         }
187                     }
188                 },
189                 
190                 
191                 
192             
193                 {
194                     init : function() {
195                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_ABOUT);
196                         XObject.prototype.init.call(this);
197                     },
198                     label: 'About GitLive',
199                     pack:  'append',
200                     listeners : {
201                         activate : function () {
202                             var msg = new Gtk.AboutDialog({
203                                 program_name : "Git Live",
204                                 version: '0.1',
205                                 website: 'http://git.akbkhome.com',
206                                 website_label: 'AK BK Consulting (git repo)',
207                                 license : 'LGPL'
208                             });
209                             msg.set_authors([ "Alan Knowles <alan@akbkhome.com>" ]);
210                             msg.run();
211                             msg.destroy();
212                         }
213                     }
214                 },
215                 
216                 {
217                     init : function() {
218                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_QUIT);
219                         XObject.prototype.init.call(this);
220                     },
221                     label: 'Quit',
222                     pack:  'append',
223                     listeners : {
224                         activate : function () {
225                             Seed.quit();
226                         }
227                     }
228                 }
229                 
230                 
231             ]
232         }
233     ]
234     
235 });
236
237