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 MenuItemAbout());
184 this.append(new MenuItemQuit());
185 this.merge_items = new Gee.ArrayList<Gtk.MenuItem>();
187 public Gee.ArrayList<Gtk.MenuItem> merge_items;
190 public void updateMerges()
192 // show a list of possible merges on the menu.
193 foreach (var m in this.merge_items) {
196 foreach(var r in GitRepo.singleton().cache.values ) {
197 GLib.debug("checking %s for branch = %s", r.name, r.currentBranch.name);
198 if (!r.is_wip_branch()) {
201 GLib.debug("checking for activeTicket");
202 var t = r.activeTicket;
206 var mi = new MergeMenuItem(r,t);
207 this.insert (mi,4); //backwards.
208 this.merge_items.add(mi);
215 class MergeMenuItem : Gtk.MenuItem {
220 public MergeMenuItem(GitRepo r, RooTicket t)
225 this.label = ("Merge [%s] #%s %s".printf(r.name, t.id , t.summary));
227 this.activate.connect(() => {
228 MergeBranch.singleton().show(this.ticket);
229 // show merge dialog..
237 class MenuItemPause : ImageMenuItem {
239 public MenuItemPause()
241 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
243 var image = new Gtk.Image();
244 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
245 this.set_image (image);
247 this.label= "Pause Commits";
248 this.always_show_image = true;
249 this.accel_group = null;
251 this.activate.connect( () => {
252 statusicon.paused = true;
253 GitMonitor.gitmonitor.stop();
255 // this.el.label = status ? 'Resume' : 'Pause';
256 statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
265 class MenuItemStartCommits : ImageMenuItem {
267 public MenuItemStartCommits()
270 var image = new Gtk.Image();
271 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
272 this.set_image (image);
273 this.label= "Start Commits";
274 this.always_show_image = true;
275 this.accel_group = null;
277 this.activate.connect( () => {
278 GitMonitor.gitmonitor.start();
279 statusicon.paused = false;
282 // this.el.label = status ? 'Resume' : 'Pause';
283 statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
293 class MenuItemPullAll : ImageMenuItem {
295 public MenuItemPullAll()
298 var image = new Gtk.Image();
299 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
300 this.set_image (image);
301 this.label= "Pull (Refresh) All";
302 this.always_show_image = true;
303 this.accel_group = null;
305 this.activate.connect( () => {
309 GitMonitor.gitmonitor.stop();
310 var tr = GitRepo.list();
314 for (var i= 0; i< tr.length;i++) {
315 statusicon.set_from_stock(
316 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
318 var repo = tr.index(i);
319 //if (!repo.autocommit()) {
320 //??? should we ignore ones not on autocommit..
324 statusicon.set_tooltip_text("pull: " + repo.name);
325 var str = repo.pull();
326 // do not care if it's already in sycn..
327 if (Regex.match_simple ("Already up-to-date", str) ) {
330 var notification = new Notify.Notification(
331 "Updated " + repo.name,
337 notification.set_timeout(20);
341 print("notification or push errror- probably to many in queue..");
342 statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
355 var tr = GitRepo.list();
357 GitMonitor.gitmonitor.stop();
360 this.total = tr.length;
362 this.pull_all_error_message = "";
363 for (var i= 0; i< tr.length;i++) {
364 statusicon.set_from_stock(
365 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
367 var repo = tr.index(i);
371 statusicon.set_tooltip_text("pull: " + repo.name);
373 repo.pull_async(this.pullAllCallback);
374 // do not care if it's already in sycn..
386 string pull_all_error_message = "";
388 void pullAllCallback(GitRepo repo, int err, string res)
394 this.pull_all_error_message += this.pull_all_error_message.length > 0 ? "\n" : "";
395 this.pull_all_error_message += "Error Pulling " + repo.name +"\n" + res;
398 if (!Regex.match_simple ("Already up-to-date", res) ) {
399 var notification = new Notify.Notification(
401 "Updated: " +repo.name + "\n" + res +"\n",
404 notification.set_timeout(20);
410 if (this.total < 1) {
411 if (this.has_error > 0) {
412 GitMonitor.gitmonitor.pauseError(this.pull_all_error_message);
416 statusicon.set_tooltip_text("Gitlive");
418 GitMonitor.gitmonitor.start();
429 class MenuItemUpdateTimesheet : ImageMenuItem {
431 public MenuItemUpdateTimesheet()
434 var image = new Gtk.Image();
435 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
436 this.set_image (image);
437 this.label= "Update Timesheet";
438 this.always_show_image = true;
439 this.accel_group = null;
441 this.activate.connect( () => {
442 //var ret = imports.FixBug.FixBug.show();
449 class MenuItemManageClones : ImageMenuItem {
451 public MenuItemManageClones()
454 var image = new Gtk.Image();
455 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
456 this.set_image (image);
457 this.label= "Manage Clones";
458 this.always_show_image = true;
459 this.accel_group = null;
461 this.activate.connect( () => {
462 Clones.singleton().show();
469 class MenuItemAbout : ImageMenuItem {
471 public MenuItemAbout()
474 var image = new Gtk.Image();
475 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
476 this.set_image (image);
477 this.label= "About Gitlive";
478 this.always_show_image = true;
479 this.accel_group = null;
481 this.activate.connect( () => {
482 //var ret = imports.Clones.Clones.show();
484 var msg = new Gtk.AboutDialog();
485 msg.program_name = "Git Live";
487 msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
488 msg.website_label= "Roo J Solutions Ltd.";
489 msg.license = "LGPL";
490 msg.authors = { "Alan Knowles <alan@roojs.com>" };
499 class MenuItemQuit : ImageMenuItem {
501 public MenuItemQuit()
504 var image = new Gtk.Image();
505 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
506 this.set_image (image);
508 this.always_show_image = true;
509 this.accel_group = null;
511 this.activate.connect( () => {
514 //var ret = imports.Clones.Clones.show();