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 GLib.log("checking r.name for branches");
197 if (!r.is_wip_branch()) {
200 GLib.log("checking for activeTicket");
201 var t = r.activeTicket;
205 var mi = new MergeMenuItem(r,t);
206 this.insert (mi,4); //backwards..
213 class MergeMenuItem : Gtk.MenuItem {
218 public MergeMenuItem(GitRepo r, RooTicket t)
223 this.label = ("Merge [%s] #%s %s".printf(r.name, t.id , t.summary));
225 this.activate.connect(() => {
226 // show merge dialog..
234 class MenuItemPause : ImageMenuItem {
236 public MenuItemPause()
238 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
240 var image = new Gtk.Image();
241 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
242 this.set_image (image);
244 this.label= "Pause Commits";
245 this.always_show_image = true;
246 this.accel_group = null;
248 this.activate.connect( () => {
249 statusicon.paused = true;
250 GitMonitor.gitmonitor.stop();
252 // this.el.label = status ? 'Resume' : 'Pause';
253 statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
262 class MenuItemStartCommits : ImageMenuItem {
264 public MenuItemStartCommits()
267 var image = new Gtk.Image();
268 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
269 this.set_image (image);
270 this.label= "Start Commits";
271 this.always_show_image = true;
272 this.accel_group = null;
274 this.activate.connect( () => {
275 GitMonitor.gitmonitor.start();
276 statusicon.paused = false;
279 // this.el.label = status ? 'Resume' : 'Pause';
280 statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
290 class MenuItemPullAll : ImageMenuItem {
292 public MenuItemPullAll()
295 var image = new Gtk.Image();
296 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
297 this.set_image (image);
298 this.label= "Pull (Refresh) All";
299 this.always_show_image = true;
300 this.accel_group = null;
302 this.activate.connect( () => {
306 GitMonitor.gitmonitor.stop();
307 var tr = GitRepo.list();
311 for (var i= 0; i< tr.length;i++) {
312 statusicon.set_from_stock(
313 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
315 var repo = tr.index(i);
316 //if (!repo.autocommit()) {
317 //??? should we ignore ones not on autocommit..
321 statusicon.set_tooltip_text("pull: " + repo.name);
322 var str = repo.pull();
323 // do not care if it's already in sycn..
324 if (Regex.match_simple ("Already up-to-date", str) ) {
327 var notification = new Notify.Notification(
328 "Updated " + repo.name,
334 notification.set_timeout(20);
338 print("notification or push errror- probably to many in queue..");
339 statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
352 var tr = GitRepo.list();
354 GitMonitor.gitmonitor.stop();
357 this.total = tr.length;
359 this.pull_all_error_message = "";
360 for (var i= 0; i< tr.length;i++) {
361 statusicon.set_from_stock(
362 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
364 var repo = tr.index(i);
368 statusicon.set_tooltip_text("pull: " + repo.name);
370 repo.pull_async(this.pullAllCallback);
371 // do not care if it's already in sycn..
383 string pull_all_error_message = "";
385 void pullAllCallback(GitRepo repo, int err, string res)
391 this.pull_all_error_message += this.pull_all_error_message.length > 0 ? "\n" : "";
392 this.pull_all_error_message += "Error Pulling " + repo.name +"\n" + res;
395 if (!Regex.match_simple ("Already up-to-date", res) ) {
396 var notification = new Notify.Notification(
398 "Updated: " +repo.name + "\n" + res +"\n",
401 notification.set_timeout(20);
407 if (this.total < 1) {
408 if (this.has_error > 0) {
409 GitMonitor.gitmonitor.pauseError(this.pull_all_error_message);
413 statusicon.set_tooltip_text("Gitlive");
415 GitMonitor.gitmonitor.start();
426 class MenuItemUpdateTimesheet : ImageMenuItem {
428 public MenuItemUpdateTimesheet()
431 var image = new Gtk.Image();
432 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
433 this.set_image (image);
434 this.label= "Update Timesheet";
435 this.always_show_image = true;
436 this.accel_group = null;
438 this.activate.connect( () => {
439 //var ret = imports.FixBug.FixBug.show();
446 class MenuItemManageClones : ImageMenuItem {
448 public MenuItemManageClones()
451 var image = new Gtk.Image();
452 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
453 this.set_image (image);
454 this.label= "Manage Clones";
455 this.always_show_image = true;
456 this.accel_group = null;
458 this.activate.connect( () => {
459 Clones.singleton().show();
466 class MenuItemAbout : ImageMenuItem {
468 public MenuItemAbout()
471 var image = new Gtk.Image();
472 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
473 this.set_image (image);
474 this.label= "About Gitlive";
475 this.always_show_image = true;
476 this.accel_group = null;
478 this.activate.connect( () => {
479 //var ret = imports.Clones.Clones.show();
481 var msg = new Gtk.AboutDialog();
482 msg.program_name = "Git Live";
484 msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
485 msg.website_label= "Roo J Solutions Ltd.";
486 msg.license = "LGPL";
487 msg.authors = { "Alan Knowles <alan@roojs.com>" };
496 class MenuItemQuit : ImageMenuItem {
498 public MenuItemQuit()
501 var image = new Gtk.Image();
502 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
503 this.set_image (image);
505 this.always_show_image = true;
506 this.accel_group = null;
508 this.activate.connect( () => {
511 //var ret = imports.Clones.Clones.show();