2 * Status icon and menu for component of gitlive.
4 * Implements XObject - however we want to control initialization.
8 * Currently only does a few things
15 // valac --pkg gtk+-3.0 StatusIcon.vala -o /tmp/StatusIcon
17 //var gitlive = imports.gitlive;
23 static int main (string[] args) {
24 // A reference to our file
36 //public StatusIconA statusicon;
38 public class StatusIconA : StatusIcon {
40 public bool paused = false;
41 public static StatusIconA statusicon;
44 public StatusIconA() {
49 this.stock = Gtk.Stock.REFRESH;
50 this.tooltip_text = "GitLive";
51 this.title = "gitlive";
53 this.set_name("gitlive");
54 this.set_visible(true);
56 var menu = new MenuA();
58 this.button_press_event.connect( ( ev ) =>{
59 print("button press event called\n");
70 // public void popup (Gtk.Widget? parent_menu_shell, Gtk.Widget? parent_menu_item,
71 // [CCode (scope = "async")] Gtk.MenuPositionFunc? func, uint button, uint32 activate_time);
72 //Gtk.get_current_event_device ()
78 ev.button, ev.time // time
84 this.popup_menu.connect( ( button, time) =>{
85 //this.button_press_event.connect( ( ) =>{
87 //print(Array.prototype.slice.call(arguments).join(','));
88 print("menu activiate called\n");
89 //var menu = this.get('menu');
100 // public void popup (Gtk.Widget? parent_menu_shell, Gtk.Widget? parent_menu_item,
101 // [CCode (scope = "async")] Gtk.MenuPositionFunc? func, uint button, uint32 activate_time);
102 //Gtk.get_current_event_device ()
113 //var a = new Gdk.Rectangle();
114 // needs direction=inout setting in gir to work (in bugzilla @present)
115 //this.el.get_geometry(g,a,null);
117 // should check to see if @ top or bottom I guess..
118 //menu.el.get_toplevel().move(a.x, a.y +a.height);
119 //menu.el.get_toplevel().move(10,10);
128 this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
134 this.set_from_stock( Gtk.Stock.MEDIA_PLAY );
138 public void refreshing()
140 this.set_from_stock( Gtk.Stock.REFRESH );
143 public void pauseError()
147 Timeout.add_full(Priority.LOW, 500, () => {
152 this.set_from_stock( flag == true ? Gtk.Stock.MEDIA_RECORD
153 : Gtk.Stock.MEDIA_PAUSE);
160 class MenuA : Gtk.Menu
162 public ImageMenuItem pause;
163 public ImageMenuItem resume;
167 this.pause = new ImageMenuItemA();
168 this.append(this.pause);
169 this.resume = new ImageMenuItemB();
170 this.append(this.resume);
171 this.append(new ImageMenuItemC());
172 this.append(new ImageMenuItemD());
173 this.append(new ImageMenuItemE());
174 this.append(new ImageMenuItemF());
175 this.append(new ImageMenuItemG());
182 class ImageMenuItemA : ImageMenuItem {
184 public ImageMenuItemA()
186 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
188 var image = new Gtk.Image();
189 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
190 this.set_image (image);
192 this.label= "Pause Commits";
193 this.always_show_image = true;
194 this.accel_group = null;
196 this.activate.connect( () => {
197 statusicon.paused = true;
198 GitMonitor.gitmonitor.stop();
200 // this.el.label = status ? 'Resume' : 'Pause';
201 statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
210 class ImageMenuItemB : ImageMenuItem {
212 public ImageMenuItemB()
215 var image = new Gtk.Image();
216 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
217 this.set_image (image);
218 this.label= "Start Commits";
219 this.always_show_image = true;
220 this.accel_group = null;
222 this.activate.connect( () => {
223 GitMonitor.gitmonitor.start();
224 statusicon.paused = false;
227 // this.el.label = status ? 'Resume' : 'Pause';
228 statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
238 class ImageMenuItemC : ImageMenuItem {
240 public ImageMenuItemC()
243 var image = new Gtk.Image();
244 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
245 this.set_image (image);
246 this.label= "Pull (Refresh) All";
247 this.always_show_image = true;
248 this.accel_group = null;
250 this.activate.connect( () => {
254 GitMonitor.gitmonitor.stop();
255 var tr = GitRepo.list();
259 for (var i= 0; i< tr.length;i++) {
260 statusicon.set_from_stock(
261 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
263 var repo = tr.index(i);
264 //if (!repo.autocommit()) {
265 //??? should we ignore ones not on autocommit..
269 statusicon.set_tooltip_text("pull: " + repo.name);
270 var str = repo.pull();
271 // do not care if it's already in sycn..
272 if (Regex.match_simple ("Already up-to-date", str) ) {
275 var notification = new Notify.Notification(
276 "Updated " + repo.name,
282 notification.set_timeout(20);
286 print("notification or push errror- probably to many in queue..");
287 statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
300 var tr = GitRepo.list();
302 GitMonitor.gitmonitor.stop();
305 this.total = tr.length;
307 this.pull_all_error_message = "";
308 for (var i= 0; i< tr.length;i++) {
309 statusicon.set_from_stock(
310 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
312 var repo = tr.index(i);
316 statusicon.set_tooltip_text("pull: " + repo.name);
318 repo.pull_async(this.pullAllCallback);
319 // do not care if it's already in sycn..
331 string pull_all_error_message = "";
333 void pullAllCallback(GitRepo repo, int err, string res)
339 this.pull_all_error_message += this.pull_all_error_message.length > 0 ? "\n" : "";
340 this.pull_all_error_message += "Error Pulling " + repo.name +"\n" + res;
343 if (!Regex.match_simple ("Already up-to-date", res) ) {
344 var notification = new Notify.Notification(
346 "Updated: " +repo.name + "\n" + res +"\n",
349 notification.set_timeout(20);
355 if (this.total < 1) {
356 if (this.has_error > 0) {
357 GitMonitor.gitmonitor.pauseError(this.pull_all_error_message);
361 statusicon.set_tooltip_text("Gitlive");
363 GitMonitor.gitmonitor.start();
374 class ImageMenuItemD : ImageMenuItem {
376 public ImageMenuItemD()
379 var image = new Gtk.Image();
380 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
381 this.set_image (image);
382 this.label= "Update Timesheet";
383 this.always_show_image = true;
384 this.accel_group = null;
386 this.activate.connect( () => {
387 //var ret = imports.FixBug.FixBug.show();
394 class ImageMenuItemE : ImageMenuItem {
396 public ImageMenuItemE()
399 var image = new Gtk.Image();
400 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
401 this.set_image (image);
402 this.label= "Manage Clones";
403 this.always_show_image = true;
404 this.accel_group = null;
406 this.activate.connect( () => {
407 Clones.singleton().show(statusicon);
414 class ImageMenuItemF : ImageMenuItem {
416 public ImageMenuItemF()
419 var image = new Gtk.Image();
420 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
421 this.set_image (image);
422 this.label= "About Gitlive";
423 this.always_show_image = true;
424 this.accel_group = null;
426 this.activate.connect( () => {
427 //var ret = imports.Clones.Clones.show();
429 var msg = new Gtk.AboutDialog();
430 msg.program_name = "Git Live";
432 msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
433 msg.website_label= "Roo J Solutions Ltd.";
434 msg.license = "LGPL";
435 msg.authors = { "Alan Knowles <alan@roojs.com>" };
444 class ImageMenuItemG : ImageMenuItem {
446 public ImageMenuItemG()
449 var image = new Gtk.Image();
450 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
451 this.set_image (image);
453 this.always_show_image = true;
454 this.accel_group = null;
456 this.activate.connect( () => {
459 //var ret = imports.Clones.Clones.show();