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 mi = new MergeMenuItem(r,t);
202 this.insert (mi,4); //backwards..
209 class MergeMenuItem : MenuItem {
214 public MergeMenuItem(GitRep r, Roo.Ticket t)
219 this.label = ("Merge [%s] #%s %s".printf(r.name, t.id , t.summary));
221 this.activate.connect(() => {
222 // show merge dialog..
230 class MenuItemPause : ImageMenuItem {
232 public MenuItemPause()
234 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
236 var image = new Gtk.Image();
237 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
238 this.set_image (image);
240 this.label= "Pause Commits";
241 this.always_show_image = true;
242 this.accel_group = null;
244 this.activate.connect( () => {
245 statusicon.paused = true;
246 GitMonitor.gitmonitor.stop();
248 // this.el.label = status ? 'Resume' : 'Pause';
249 statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
258 class MenuItemStartCommits : ImageMenuItem {
260 public MenuItemStartCommits()
263 var image = new Gtk.Image();
264 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
265 this.set_image (image);
266 this.label= "Start Commits";
267 this.always_show_image = true;
268 this.accel_group = null;
270 this.activate.connect( () => {
271 GitMonitor.gitmonitor.start();
272 statusicon.paused = false;
275 // this.el.label = status ? 'Resume' : 'Pause';
276 statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
286 class MenuItemPullAll : ImageMenuItem {
288 public MenuItemPullAll()
291 var image = new Gtk.Image();
292 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
293 this.set_image (image);
294 this.label= "Pull (Refresh) All";
295 this.always_show_image = true;
296 this.accel_group = null;
298 this.activate.connect( () => {
302 GitMonitor.gitmonitor.stop();
303 var tr = GitRepo.list();
307 for (var i= 0; i< tr.length;i++) {
308 statusicon.set_from_stock(
309 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
311 var repo = tr.index(i);
312 //if (!repo.autocommit()) {
313 //??? should we ignore ones not on autocommit..
317 statusicon.set_tooltip_text("pull: " + repo.name);
318 var str = repo.pull();
319 // do not care if it's already in sycn..
320 if (Regex.match_simple ("Already up-to-date", str) ) {
323 var notification = new Notify.Notification(
324 "Updated " + repo.name,
330 notification.set_timeout(20);
334 print("notification or push errror- probably to many in queue..");
335 statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
348 var tr = GitRepo.list();
350 GitMonitor.gitmonitor.stop();
353 this.total = tr.length;
355 this.pull_all_error_message = "";
356 for (var i= 0; i< tr.length;i++) {
357 statusicon.set_from_stock(
358 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
360 var repo = tr.index(i);
364 statusicon.set_tooltip_text("pull: " + repo.name);
366 repo.pull_async(this.pullAllCallback);
367 // do not care if it's already in sycn..
379 string pull_all_error_message = "";
381 void pullAllCallback(GitRepo repo, int err, string res)
387 this.pull_all_error_message += this.pull_all_error_message.length > 0 ? "\n" : "";
388 this.pull_all_error_message += "Error Pulling " + repo.name +"\n" + res;
391 if (!Regex.match_simple ("Already up-to-date", res) ) {
392 var notification = new Notify.Notification(
394 "Updated: " +repo.name + "\n" + res +"\n",
397 notification.set_timeout(20);
403 if (this.total < 1) {
404 if (this.has_error > 0) {
405 GitMonitor.gitmonitor.pauseError(this.pull_all_error_message);
409 statusicon.set_tooltip_text("Gitlive");
411 GitMonitor.gitmonitor.start();
422 class MenuItemUpdateTimesheet : ImageMenuItem {
424 public MenuItemUpdateTimesheet()
427 var image = new Gtk.Image();
428 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
429 this.set_image (image);
430 this.label= "Update Timesheet";
431 this.always_show_image = true;
432 this.accel_group = null;
434 this.activate.connect( () => {
435 //var ret = imports.FixBug.FixBug.show();
442 class MenuItemManageClones : ImageMenuItem {
444 public MenuItemManageClones()
447 var image = new Gtk.Image();
448 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
449 this.set_image (image);
450 this.label= "Manage Clones";
451 this.always_show_image = true;
452 this.accel_group = null;
454 this.activate.connect( () => {
455 Clones.singleton().show();
462 class MenuItemAbout : ImageMenuItem {
464 public MenuItemAbout()
467 var image = new Gtk.Image();
468 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
469 this.set_image (image);
470 this.label= "About Gitlive";
471 this.always_show_image = true;
472 this.accel_group = null;
474 this.activate.connect( () => {
475 //var ret = imports.Clones.Clones.show();
477 var msg = new Gtk.AboutDialog();
478 msg.program_name = "Git Live";
480 msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
481 msg.website_label= "Roo J Solutions Ltd.";
482 msg.license = "LGPL";
483 msg.authors = { "Alan Knowles <alan@roojs.com>" };
492 class MenuItemQuit : ImageMenuItem {
494 public MenuItemQuit()
497 var image = new Gtk.Image();
498 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
499 this.set_image (image);
501 this.always_show_image = true;
502 this.accel_group = null;
504 this.activate.connect( () => {
507 //var ret = imports.Clones.Clones.show();