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 GitliveMenu();
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");
90 //var menu = this.get('menu');
101 // public void popup (Gtk.Widget? parent_menu_shell, Gtk.Widget? parent_menu_item,
102 // [CCode (scope = "async")] Gtk.MenuPositionFunc? func, uint button, uint32 activate_time);
103 //Gtk.get_current_event_device ()
114 //var a = new Gdk.Rectangle();
115 // needs direction=inout setting in gir to work (in bugzilla @present)
116 //this.el.get_geometry(g,a,null);
118 // should check to see if @ top or bottom I guess..
119 //menu.el.get_toplevel().move(a.x, a.y +a.height);
120 //menu.el.get_toplevel().move(10,10);
129 this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
135 this.set_from_stock( Gtk.Stock.MEDIA_PLAY );
139 public void refreshing()
141 this.set_from_stock( Gtk.Stock.REFRESH );
144 public void pauseError()
148 Timeout.add_full(Priority.LOW, 500, () => {
153 this.set_from_stock( flag == true ? Gtk.Stock.MEDIA_RECORD
154 : Gtk.Stock.MEDIA_PAUSE);
161 class GitliveMenu : Gtk.Menu
163 public ImageMenuItem pause;
164 public ImageMenuItem resume;
165 public Gtk.MenuItem before_seperator;
166 public Gtk.MenuItem after_seperator;
171 this.pause = new MenuItemPause();
172 this.append(this.pause);
173 this.resume = new MenuItemStartCommits();
174 this.append(this.resume);
175 this.append(new MenuItemPullAll());
176 this.before_seperator = new Gtk.SeparatorMenuItem();
177 this.append(this.before_seperator);
179 this.after_seperator = new Gtk.SeparatorMenuItem();
180 this.append(this.after_seperator);
181 //this.append(new MenuItemUpdateTimesheet());
182 this.append(new MenuItemManageClones());
183 this.append(new MenuItemNewTicket());
184 this.append(new MenuItemAbout());
185 this.append(new MenuItemQuit());
186 this.merge_items = new Gee.ArrayList<Gtk.MenuItem>();
188 public Gee.ArrayList<Gtk.MenuItem> merge_items;
191 public void updateMerges()
193 // show a list of possible merges on the menu.
194 foreach (var m in this.merge_items) {
197 foreach(var r in GitRepo.singleton().cache.values ) {
198 GLib.debug("checking %s for branch = %s", r.name, r.currentBranch.name);
199 if (r.is_master_branch()) {
202 GLib.debug("checking for activeTicket");
203 var t = r.activeTicket;
207 var mi = new MergeMenuItem(r,t);
208 this.insert (mi,4); //backwards.
209 this.merge_items.add(mi);
216 class MergeMenuItem : Gtk.MenuItem {
221 public MergeMenuItem(GitRepo r, RooTicket t)
226 this.label = ("Merge [%s] #%s %s".printf(r.name, t.id , t.summary));
228 this.activate.connect(() => {
229 MergeBranch.singleton().show(this.ticket, null);
230 // show merge dialog..
238 class MenuItemPause : ImageMenuItem {
240 public MenuItemPause()
242 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
244 var image = new Gtk.Image();
245 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
246 this.set_image (image);
248 this.label= "Pause Commits";
249 this.always_show_image = true;
250 this.accel_group = null;
252 this.activate.connect( () => {
253 statusicon.paused = true;
254 GitMonitor.gitmonitor.stop();
256 // this.el.label = status ? 'Resume' : 'Pause';
257 statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
266 class MenuItemStartCommits : ImageMenuItem {
268 public MenuItemStartCommits()
271 var image = new Gtk.Image();
272 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
273 this.set_image (image);
274 this.label= "Start Commits";
275 this.always_show_image = true;
276 this.accel_group = null;
278 this.activate.connect( () => {
279 GitMonitor.gitmonitor.start();
280 statusicon.paused = false;
283 // this.el.label = status ? 'Resume' : 'Pause';
284 statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
294 class MenuItemPullAll : ImageMenuItem {
296 public MenuItemPullAll()
299 var image = new Gtk.Image();
300 image.set_from_stock(Gtk.Stock.GOTO_BOTTOM,Gtk.IconSize.MENU );
301 this.set_image (image);
302 this.label= "Pull (Refresh) All";
303 this.always_show_image = true;
304 this.accel_group = null;
306 this.activate.connect( () => {
310 GitMonitor.gitmonitor.stop();
311 var tr = GitRepo.list();
315 for (var i= 0; i< tr.length;i++) {
316 statusicon.set_from_stock(
317 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
319 var repo = tr.index(i);
320 //if (!repo.autocommit()) {
321 //??? should we ignore ones not on autocommit..
325 statusicon.set_tooltip_text("pull: " + repo.name);
326 var str = repo.pull();
327 // do not care if it's already in sycn..
328 if (Regex.match_simple ("Already up-to-date", str) ) {
331 var notification = new Notify.Notification(
332 "Updated " + repo.name,
338 notification.set_timeout(20);
342 print("notification or push errror- probably to many in queue..");
343 statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
356 var tr = GitRepo.list();
358 GitMonitor.gitmonitor.stop();
361 this.total = tr.length;
363 this.pull_all_error_message = "";
364 for (var i= 0; i< tr.length;i++) {
365 statusicon.set_from_stock(
366 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
368 var repo = tr.index(i);
372 statusicon.set_tooltip_text("pull: " + repo.name);
374 repo.pull_async(this.pullAllCallback);
375 // do not care if it's already in sycn..
387 string pull_all_error_message = "";
389 void pullAllCallback(GitRepo repo, int err, string res)
395 this.pull_all_error_message += this.pull_all_error_message.length > 0 ? "\n" : "";
396 this.pull_all_error_message += "Error Pulling " + repo.name +"\n" + res;
399 if (!Regex.match_simple ("Already up-to-date", res) ) {
400 var notification = new Notify.Notification(
402 "Updated: " +repo.name + "\n" + res +"\n",
405 notification.set_timeout(20);
411 if (this.total < 1) {
412 if (this.has_error > 0) {
413 GitMonitor.gitmonitor.pauseError(this.pull_all_error_message);
417 statusicon.set_tooltip_text("Gitlive");
419 GitMonitor.gitmonitor.start();
430 class MenuItemUpdateTimesheet : ImageMenuItem {
432 public MenuItemUpdateTimesheet()
435 var image = new Gtk.Image();
436 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
437 this.set_image (image);
438 this.label= "Update Timesheet";
439 this.always_show_image = true;
440 this.accel_group = null;
442 this.activate.connect( () => {
443 //var ret = imports.FixBug.FixBug.show();
450 class MenuItemManageClones : ImageMenuItem {
452 public MenuItemManageClones()
455 var image = new Gtk.Image();
456 image.set_from_stock(Gtk.Stock.JUSTIFY_FILL,Gtk.IconSize.MENU );
457 this.set_image (image);
458 this.label= "Manage Clones";
459 this.always_show_image = true;
460 this.accel_group = null;
462 this.activate.connect( () => {
463 //GitRepo.updateAll("show_clones");
464 Clones.singleton().loadAndShow();
466 // Clones.singleton().show();
473 class MenuItemNewTicket : ImageMenuItem {
475 public MenuItemNewTicket()
478 var image = new Gtk.Image();
479 image.set_from_stock(Gtk.Stock.NEW,Gtk.IconSize.MENU );
480 this.set_image (image);
481 this.label= "New Ticket";
482 this.always_show_image = true;
483 this.accel_group = null;
485 this.activate.connect( () => {
486 Ticket.singleton().show(null);
489 // Clones.singleton().show();
497 class MenuItemAbout : ImageMenuItem {
499 public MenuItemAbout()
502 var image = new Gtk.Image();
503 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
504 this.set_image (image);
505 this.label= "About Gitlive";
506 this.always_show_image = true;
507 this.accel_group = null;
509 this.activate.connect( () => {
510 //var ret = imports.Clones.Clones.show();
512 var msg = new Gtk.AboutDialog();
513 msg.program_name = "Git Live";
515 msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
516 msg.website_label= "Roo J Solutions Ltd.";
517 msg.license = "LGPL";
518 msg.authors = { "Alan Knowles <alan@roojs.com>" };
527 class MenuItemQuit : ImageMenuItem {
529 public MenuItemQuit()
532 var image = new Gtk.Image();
533 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
534 this.set_image (image);
536 this.always_show_image = true;
537 this.accel_group = null;
539 this.activate.connect( () => {
542 //var ret = imports.Clones.Clones.show();