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 GitRepo.singleton().cache.values as r) {
208 class MenuItemPause : ImageMenuItem {
210 public MenuItemPause()
212 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
214 var image = new Gtk.Image();
215 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
216 this.set_image (image);
218 this.label= "Pause Commits";
219 this.always_show_image = true;
220 this.accel_group = null;
222 this.activate.connect( () => {
223 statusicon.paused = true;
224 GitMonitor.gitmonitor.stop();
226 // this.el.label = status ? 'Resume' : 'Pause';
227 statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
236 class MenuItemStartCommits : ImageMenuItem {
238 public MenuItemStartCommits()
241 var image = new Gtk.Image();
242 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
243 this.set_image (image);
244 this.label= "Start Commits";
245 this.always_show_image = true;
246 this.accel_group = null;
248 this.activate.connect( () => {
249 GitMonitor.gitmonitor.start();
250 statusicon.paused = false;
253 // this.el.label = status ? 'Resume' : 'Pause';
254 statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
264 class MenuItemPullAll : ImageMenuItem {
266 public MenuItemPullAll()
269 var image = new Gtk.Image();
270 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
271 this.set_image (image);
272 this.label= "Pull (Refresh) All";
273 this.always_show_image = true;
274 this.accel_group = null;
276 this.activate.connect( () => {
280 GitMonitor.gitmonitor.stop();
281 var tr = GitRepo.list();
285 for (var i= 0; i< tr.length;i++) {
286 statusicon.set_from_stock(
287 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
289 var repo = tr.index(i);
290 //if (!repo.autocommit()) {
291 //??? should we ignore ones not on autocommit..
295 statusicon.set_tooltip_text("pull: " + repo.name);
296 var str = repo.pull();
297 // do not care if it's already in sycn..
298 if (Regex.match_simple ("Already up-to-date", str) ) {
301 var notification = new Notify.Notification(
302 "Updated " + repo.name,
308 notification.set_timeout(20);
312 print("notification or push errror- probably to many in queue..");
313 statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
326 var tr = GitRepo.list();
328 GitMonitor.gitmonitor.stop();
331 this.total = tr.length;
333 this.pull_all_error_message = "";
334 for (var i= 0; i< tr.length;i++) {
335 statusicon.set_from_stock(
336 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
338 var repo = tr.index(i);
342 statusicon.set_tooltip_text("pull: " + repo.name);
344 repo.pull_async(this.pullAllCallback);
345 // do not care if it's already in sycn..
357 string pull_all_error_message = "";
359 void pullAllCallback(GitRepo repo, int err, string res)
365 this.pull_all_error_message += this.pull_all_error_message.length > 0 ? "\n" : "";
366 this.pull_all_error_message += "Error Pulling " + repo.name +"\n" + res;
369 if (!Regex.match_simple ("Already up-to-date", res) ) {
370 var notification = new Notify.Notification(
372 "Updated: " +repo.name + "\n" + res +"\n",
375 notification.set_timeout(20);
381 if (this.total < 1) {
382 if (this.has_error > 0) {
383 GitMonitor.gitmonitor.pauseError(this.pull_all_error_message);
387 statusicon.set_tooltip_text("Gitlive");
389 GitMonitor.gitmonitor.start();
400 class MenuItemUpdateTimesheet : ImageMenuItem {
402 public MenuItemUpdateTimesheet()
405 var image = new Gtk.Image();
406 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
407 this.set_image (image);
408 this.label= "Update Timesheet";
409 this.always_show_image = true;
410 this.accel_group = null;
412 this.activate.connect( () => {
413 //var ret = imports.FixBug.FixBug.show();
420 class MenuItemManageClones : ImageMenuItem {
422 public MenuItemManageClones()
425 var image = new Gtk.Image();
426 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
427 this.set_image (image);
428 this.label= "Manage Clones";
429 this.always_show_image = true;
430 this.accel_group = null;
432 this.activate.connect( () => {
433 Clones.singleton().show();
440 class MenuItemAbout : ImageMenuItem {
442 public MenuItemAbout()
445 var image = new Gtk.Image();
446 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
447 this.set_image (image);
448 this.label= "About Gitlive";
449 this.always_show_image = true;
450 this.accel_group = null;
452 this.activate.connect( () => {
453 //var ret = imports.Clones.Clones.show();
455 var msg = new Gtk.AboutDialog();
456 msg.program_name = "Git Live";
458 msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
459 msg.website_label= "Roo J Solutions Ltd.";
460 msg.license = "LGPL";
461 msg.authors = { "Alan Knowles <alan@roojs.com>" };
470 class MenuItemQuit : ImageMenuItem {
472 public MenuItemQuit()
475 var image = new Gtk.Image();
476 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
477 this.set_image (image);
479 this.always_show_image = true;
480 this.accel_group = null;
482 this.activate.connect( () => {
485 //var ret = imports.Clones.Clones.show();