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