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");
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 GitliveMenu : Gtk.Menu
162 public ImageMenuItem pause;
163 public ImageMenuItem resume;
164 public Gtk.MenuItem before_seperator;
165 public Gtk.MenuItem after_seperator;
170 this.pause = new MenuItemPause();
171 this.append(this.pause);
172 this.resume = new MenuItemStartCommits();
173 this.append(this.resume);
174 this.append(new MenuItemPullAll());
175 this.before_seperator = new Gtk.SeparatorMenuItem();
176 this.append(this.before_seperator);
178 this.after_seperator = new Gtk.SeparatorMenuItem();
179 this.append(this.after_seperator);
180 //this.append(new MenuItemUpdateTimesheet());
181 this.append(new MenuItemManageClones());
182 this.append(new MenuItemAbout());
183 this.append(new MenuItemQuit());
184 this.merge_items = new Gee.ArrayList<Gtk.MenuItem>();
186 public Gee.ArrayList<Gtk.MenuItem> merge_items;
187 public void updateMerges()
189 // show a list of possible merges on the menu.
190 foreach (var m in this.merge_items) {
193 foreach(var r in GitRepo.singleton().cache.values ) {
194 if (!r.is_wip_branch()) {
197 var t = r.activeTicket;
201 var mi = new Gtk.MenuItem.with_label ("Merge [%s] #%s %s".printf(r.name, t.id , t.summary));
217 class MenuItemPause : ImageMenuItem {
219 public MenuItemPause()
221 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
223 var image = new Gtk.Image();
224 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
225 this.set_image (image);
227 this.label= "Pause Commits";
228 this.always_show_image = true;
229 this.accel_group = null;
231 this.activate.connect( () => {
232 statusicon.paused = true;
233 GitMonitor.gitmonitor.stop();
235 // this.el.label = status ? 'Resume' : 'Pause';
236 statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
245 class MenuItemStartCommits : ImageMenuItem {
247 public MenuItemStartCommits()
250 var image = new Gtk.Image();
251 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
252 this.set_image (image);
253 this.label= "Start Commits";
254 this.always_show_image = true;
255 this.accel_group = null;
257 this.activate.connect( () => {
258 GitMonitor.gitmonitor.start();
259 statusicon.paused = false;
262 // this.el.label = status ? 'Resume' : 'Pause';
263 statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
273 class MenuItemPullAll : ImageMenuItem {
275 public MenuItemPullAll()
278 var image = new Gtk.Image();
279 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
280 this.set_image (image);
281 this.label= "Pull (Refresh) All";
282 this.always_show_image = true;
283 this.accel_group = null;
285 this.activate.connect( () => {
289 GitMonitor.gitmonitor.stop();
290 var tr = GitRepo.list();
294 for (var i= 0; i< tr.length;i++) {
295 statusicon.set_from_stock(
296 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
298 var repo = tr.index(i);
299 //if (!repo.autocommit()) {
300 //??? should we ignore ones not on autocommit..
304 statusicon.set_tooltip_text("pull: " + repo.name);
305 var str = repo.pull();
306 // do not care if it's already in sycn..
307 if (Regex.match_simple ("Already up-to-date", str) ) {
310 var notification = new Notify.Notification(
311 "Updated " + repo.name,
317 notification.set_timeout(20);
321 print("notification or push errror- probably to many in queue..");
322 statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
335 var tr = GitRepo.list();
337 GitMonitor.gitmonitor.stop();
340 this.total = tr.length;
342 this.pull_all_error_message = "";
343 for (var i= 0; i< tr.length;i++) {
344 statusicon.set_from_stock(
345 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
347 var repo = tr.index(i);
351 statusicon.set_tooltip_text("pull: " + repo.name);
353 repo.pull_async(this.pullAllCallback);
354 // do not care if it's already in sycn..
366 string pull_all_error_message = "";
368 void pullAllCallback(GitRepo repo, int err, string res)
374 this.pull_all_error_message += this.pull_all_error_message.length > 0 ? "\n" : "";
375 this.pull_all_error_message += "Error Pulling " + repo.name +"\n" + res;
378 if (!Regex.match_simple ("Already up-to-date", res) ) {
379 var notification = new Notify.Notification(
381 "Updated: " +repo.name + "\n" + res +"\n",
384 notification.set_timeout(20);
390 if (this.total < 1) {
391 if (this.has_error > 0) {
392 GitMonitor.gitmonitor.pauseError(this.pull_all_error_message);
396 statusicon.set_tooltip_text("Gitlive");
398 GitMonitor.gitmonitor.start();
409 class MenuItemUpdateTimesheet : ImageMenuItem {
411 public MenuItemUpdateTimesheet()
414 var image = new Gtk.Image();
415 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
416 this.set_image (image);
417 this.label= "Update Timesheet";
418 this.always_show_image = true;
419 this.accel_group = null;
421 this.activate.connect( () => {
422 //var ret = imports.FixBug.FixBug.show();
429 class MenuItemManageClones : ImageMenuItem {
431 public MenuItemManageClones()
434 var image = new Gtk.Image();
435 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
436 this.set_image (image);
437 this.label= "Manage Clones";
438 this.always_show_image = true;
439 this.accel_group = null;
441 this.activate.connect( () => {
442 Clones.singleton().show();
449 class MenuItemAbout : ImageMenuItem {
451 public MenuItemAbout()
454 var image = new Gtk.Image();
455 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
456 this.set_image (image);
457 this.label= "About Gitlive";
458 this.always_show_image = true;
459 this.accel_group = null;
461 this.activate.connect( () => {
462 //var ret = imports.Clones.Clones.show();
464 var msg = new Gtk.AboutDialog();
465 msg.program_name = "Git Live";
467 msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
468 msg.website_label= "Roo J Solutions Ltd.";
469 msg.license = "LGPL";
470 msg.authors = { "Alan Knowles <alan@roojs.com>" };
479 class MenuItemQuit : ImageMenuItem {
481 public MenuItemQuit()
484 var image = new Gtk.Image();
485 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
486 this.set_image (image);
488 this.always_show_image = true;
489 this.accel_group = null;
491 this.activate.connect( () => {
494 //var ret = imports.Clones.Clones.show();