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