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.activeBranch.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..
214 class MergeMenuItem : Gtk.MenuItem {
219 public MergeMenuItem(GitRepo r, RooTicket t)
224 this.label = ("Merge [%s] #%s %s".printf(r.name, t.id , t.summary));
226 this.activate.connect(() => {
227 // show merge dialog..
235 class MenuItemPause : ImageMenuItem {
237 public MenuItemPause()
239 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
241 var image = new Gtk.Image();
242 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
243 this.set_image (image);
245 this.label= "Pause Commits";
246 this.always_show_image = true;
247 this.accel_group = null;
249 this.activate.connect( () => {
250 statusicon.paused = true;
251 GitMonitor.gitmonitor.stop();
253 // this.el.label = status ? 'Resume' : 'Pause';
254 statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
263 class MenuItemStartCommits : ImageMenuItem {
265 public MenuItemStartCommits()
268 var image = new Gtk.Image();
269 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
270 this.set_image (image);
271 this.label= "Start Commits";
272 this.always_show_image = true;
273 this.accel_group = null;
275 this.activate.connect( () => {
276 GitMonitor.gitmonitor.start();
277 statusicon.paused = false;
280 // this.el.label = status ? 'Resume' : 'Pause';
281 statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
291 class MenuItemPullAll : ImageMenuItem {
293 public MenuItemPullAll()
296 var image = new Gtk.Image();
297 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
298 this.set_image (image);
299 this.label= "Pull (Refresh) All";
300 this.always_show_image = true;
301 this.accel_group = null;
303 this.activate.connect( () => {
307 GitMonitor.gitmonitor.stop();
308 var tr = GitRepo.list();
312 for (var i= 0; i< tr.length;i++) {
313 statusicon.set_from_stock(
314 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
316 var repo = tr.index(i);
317 //if (!repo.autocommit()) {
318 //??? should we ignore ones not on autocommit..
322 statusicon.set_tooltip_text("pull: " + repo.name);
323 var str = repo.pull();
324 // do not care if it's already in sycn..
325 if (Regex.match_simple ("Already up-to-date", str) ) {
328 var notification = new Notify.Notification(
329 "Updated " + repo.name,
335 notification.set_timeout(20);
339 print("notification or push errror- probably to many in queue..");
340 statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
353 var tr = GitRepo.list();
355 GitMonitor.gitmonitor.stop();
358 this.total = tr.length;
360 this.pull_all_error_message = "";
361 for (var i= 0; i< tr.length;i++) {
362 statusicon.set_from_stock(
363 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
365 var repo = tr.index(i);
369 statusicon.set_tooltip_text("pull: " + repo.name);
371 repo.pull_async(this.pullAllCallback);
372 // do not care if it's already in sycn..
384 string pull_all_error_message = "";
386 void pullAllCallback(GitRepo repo, int err, string res)
392 this.pull_all_error_message += this.pull_all_error_message.length > 0 ? "\n" : "";
393 this.pull_all_error_message += "Error Pulling " + repo.name +"\n" + res;
396 if (!Regex.match_simple ("Already up-to-date", res) ) {
397 var notification = new Notify.Notification(
399 "Updated: " +repo.name + "\n" + res +"\n",
402 notification.set_timeout(20);
408 if (this.total < 1) {
409 if (this.has_error > 0) {
410 GitMonitor.gitmonitor.pauseError(this.pull_all_error_message);
414 statusicon.set_tooltip_text("Gitlive");
416 GitMonitor.gitmonitor.start();
427 class MenuItemUpdateTimesheet : ImageMenuItem {
429 public MenuItemUpdateTimesheet()
432 var image = new Gtk.Image();
433 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
434 this.set_image (image);
435 this.label= "Update Timesheet";
436 this.always_show_image = true;
437 this.accel_group = null;
439 this.activate.connect( () => {
440 //var ret = imports.FixBug.FixBug.show();
447 class MenuItemManageClones : ImageMenuItem {
449 public MenuItemManageClones()
452 var image = new Gtk.Image();
453 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
454 this.set_image (image);
455 this.label= "Manage Clones";
456 this.always_show_image = true;
457 this.accel_group = null;
459 this.activate.connect( () => {
460 Clones.singleton().show();
467 class MenuItemAbout : ImageMenuItem {
469 public MenuItemAbout()
472 var image = new Gtk.Image();
473 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
474 this.set_image (image);
475 this.label= "About Gitlive";
476 this.always_show_image = true;
477 this.accel_group = null;
479 this.activate.connect( () => {
480 //var ret = imports.Clones.Clones.show();
482 var msg = new Gtk.AboutDialog();
483 msg.program_name = "Git Live";
485 msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
486 msg.website_label= "Roo J Solutions Ltd.";
487 msg.license = "LGPL";
488 msg.authors = { "Alan Knowles <alan@roojs.com>" };
497 class MenuItemQuit : ImageMenuItem {
499 public MenuItemQuit()
502 var image = new Gtk.Image();
503 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
504 this.set_image (image);
506 this.always_show_image = true;
507 this.accel_group = null;
509 this.activate.connect( () => {
512 //var ret = imports.Clones.Clones.show();