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;
189 public void updateMerges()
191 // show a list of possible merges on the menu.
192 foreach (var m in this.merge_items) {
195 foreach(var r in GitRepo.singleton().cache.values ) {
196 if (!r.is_wip_branch()) {
199 var t = r.activeTicket;
203 var mi = new MergeMenuItem(r,t);
204 this.insert (mi,4); //backwards..
211 class MergeMenuItem : Gtk.MenuItem {
216 public MergeMenuItem(GitRepo r, RooTicket t)
221 this.label = ("Merge [%s] #%s %s".printf(r.name, t.id , t.summary));
223 this.activate.connect(() => {
224 // show merge dialog..
232 class MenuItemPause : ImageMenuItem {
234 public MenuItemPause()
236 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
238 var image = new Gtk.Image();
239 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
240 this.set_image (image);
242 this.label= "Pause Commits";
243 this.always_show_image = true;
244 this.accel_group = null;
246 this.activate.connect( () => {
247 statusicon.paused = true;
248 GitMonitor.gitmonitor.stop();
250 // this.el.label = status ? 'Resume' : 'Pause';
251 statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
260 class MenuItemStartCommits : ImageMenuItem {
262 public MenuItemStartCommits()
265 var image = new Gtk.Image();
266 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
267 this.set_image (image);
268 this.label= "Start Commits";
269 this.always_show_image = true;
270 this.accel_group = null;
272 this.activate.connect( () => {
273 GitMonitor.gitmonitor.start();
274 statusicon.paused = false;
277 // this.el.label = status ? 'Resume' : 'Pause';
278 statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
288 class MenuItemPullAll : ImageMenuItem {
290 public MenuItemPullAll()
293 var image = new Gtk.Image();
294 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
295 this.set_image (image);
296 this.label= "Pull (Refresh) All";
297 this.always_show_image = true;
298 this.accel_group = null;
300 this.activate.connect( () => {
304 GitMonitor.gitmonitor.stop();
305 var tr = GitRepo.list();
309 for (var i= 0; i< tr.length;i++) {
310 statusicon.set_from_stock(
311 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
313 var repo = tr.index(i);
314 //if (!repo.autocommit()) {
315 //??? should we ignore ones not on autocommit..
319 statusicon.set_tooltip_text("pull: " + repo.name);
320 var str = repo.pull();
321 // do not care if it's already in sycn..
322 if (Regex.match_simple ("Already up-to-date", str) ) {
325 var notification = new Notify.Notification(
326 "Updated " + repo.name,
332 notification.set_timeout(20);
336 print("notification or push errror- probably to many in queue..");
337 statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
350 var tr = GitRepo.list();
352 GitMonitor.gitmonitor.stop();
355 this.total = tr.length;
357 this.pull_all_error_message = "";
358 for (var i= 0; i< tr.length;i++) {
359 statusicon.set_from_stock(
360 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
362 var repo = tr.index(i);
366 statusicon.set_tooltip_text("pull: " + repo.name);
368 repo.pull_async(this.pullAllCallback);
369 // do not care if it's already in sycn..
381 string pull_all_error_message = "";
383 void pullAllCallback(GitRepo repo, int err, string res)
389 this.pull_all_error_message += this.pull_all_error_message.length > 0 ? "\n" : "";
390 this.pull_all_error_message += "Error Pulling " + repo.name +"\n" + res;
393 if (!Regex.match_simple ("Already up-to-date", res) ) {
394 var notification = new Notify.Notification(
396 "Updated: " +repo.name + "\n" + res +"\n",
399 notification.set_timeout(20);
405 if (this.total < 1) {
406 if (this.has_error > 0) {
407 GitMonitor.gitmonitor.pauseError(this.pull_all_error_message);
411 statusicon.set_tooltip_text("Gitlive");
413 GitMonitor.gitmonitor.start();
424 class MenuItemUpdateTimesheet : ImageMenuItem {
426 public MenuItemUpdateTimesheet()
429 var image = new Gtk.Image();
430 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
431 this.set_image (image);
432 this.label= "Update Timesheet";
433 this.always_show_image = true;
434 this.accel_group = null;
436 this.activate.connect( () => {
437 //var ret = imports.FixBug.FixBug.show();
444 class MenuItemManageClones : ImageMenuItem {
446 public MenuItemManageClones()
449 var image = new Gtk.Image();
450 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
451 this.set_image (image);
452 this.label= "Manage Clones";
453 this.always_show_image = true;
454 this.accel_group = null;
456 this.activate.connect( () => {
457 Clones.singleton().show();
464 class MenuItemAbout : ImageMenuItem {
466 public MenuItemAbout()
469 var image = new Gtk.Image();
470 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
471 this.set_image (image);
472 this.label= "About Gitlive";
473 this.always_show_image = true;
474 this.accel_group = null;
476 this.activate.connect( () => {
477 //var ret = imports.Clones.Clones.show();
479 var msg = new Gtk.AboutDialog();
480 msg.program_name = "Git Live";
482 msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
483 msg.website_label= "Roo J Solutions Ltd.";
484 msg.license = "LGPL";
485 msg.authors = { "Alan Knowles <alan@roojs.com>" };
494 class MenuItemQuit : ImageMenuItem {
496 public MenuItemQuit()
499 var image = new Gtk.Image();
500 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
501 this.set_image (image);
503 this.always_show_image = true;
504 this.accel_group = null;
506 this.activate.connect( () => {
509 //var ret = imports.Clones.Clones.show();