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 MenuItemNewTicket());
184 this.append(new MenuItemAbout());
185 this.append(new MenuItemQuit());
186 this.merge_items = new Gee.ArrayList<Gtk.MenuItem>();
188 public Gee.ArrayList<Gtk.MenuItem> merge_items;
191 public void updateMerges()
193 // show a list of possible merges on the menu.
194 foreach (var m in this.merge_items) {
197 foreach(var r in GitRepo.singleton().cache.values ) {
198 GLib.debug("checking %s for branch = %s", r.name, r.getCurrentBranch().name);
199 if (r.is_master_branch()) {
202 GLib.debug("checking for activeTicket");
203 var t = r.activeTicket;
207 var mi = new MergeMenuItem(r,t);
208 this.insert (mi,4); //backwards.
209 this.merge_items.add(mi);
216 class MergeMenuItem : Gtk.MenuItem {
221 public MergeMenuItem(GitRepo r, RooTicket t)
226 this.label = ("Merge [%s] #%s %s".printf(r.name, t.id , t.summary));
228 this.activate.connect(() => {
229 MergeBranch.singleton().show(this.ticket, null);
230 // show merge dialog..
238 class MenuItemPause : ImageMenuItem {
240 public MenuItemPause()
242 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
244 var image = new Gtk.Image();
245 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
246 this.set_image (image);
248 this.label= "Pause Commits";
249 this.always_show_image = true;
250 this.accel_group = null;
252 this.activate.connect( () => {
253 statusicon.paused = true;
254 GitMonitor.gitmonitor.stop();
256 // this.el.label = status ? 'Resume' : 'Pause';
257 statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
266 class MenuItemStartCommits : ImageMenuItem {
268 public MenuItemStartCommits()
271 var image = new Gtk.Image();
272 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
273 this.set_image (image);
274 this.label= "Start Commits";
275 this.always_show_image = true;
276 this.accel_group = null;
278 this.activate.connect( () => {
279 GitMonitor.gitmonitor.start();
280 statusicon.paused = false;
283 // this.el.label = status ? 'Resume' : 'Pause';
284 statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
294 class MenuItemPullAll : ImageMenuItem {
296 public MenuItemPullAll()
299 var image = new Gtk.Image();
300 image.set_from_stock(Gtk.Stock.GOTO_BOTTOM,Gtk.IconSize.MENU );
301 this.set_image (image);
302 this.label= "Pull (Refresh) All";
303 this.always_show_image = true;
304 this.accel_group = null;
306 this.activate.connect( () => {
316 var tr = GitRepo.list();
318 GitMonitor.gitmonitor.stop();
321 this.total = tr.length;
323 this.pull_all_error_message = "";
324 for (var i= 0; i< tr.length;i++) {
325 statusicon.set_from_stock(
326 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
328 var repo = tr.index(i);
332 statusicon.set_tooltip_text("pull: " + repo.name);
334 repo.pull_async(this.pullAllCallback);
335 // do not care if it's already in sycn..
347 string pull_all_error_message = "";
349 void pullAllCallback(GitRepo repo, int err, string res)
355 this.pull_all_error_message += this.pull_all_error_message.length > 0 ? "\n" : "";
356 this.pull_all_error_message += "Error Pulling " + repo.name +"\n" + res;
359 if (!Regex.match_simple ("Already up-to-date", res) ) {
360 var notification = new Notify.Notification(
362 "Updated: " +repo.name + "\n" + res +"\n",
365 notification.set_timeout(20);
371 if (this.total < 1) {
372 if (this.has_error > 0) {
373 GitMonitor.gitmonitor.pauseError(this.pull_all_error_message);
377 statusicon.set_tooltip_text("Gitlive");
379 GitMonitor.gitmonitor.start();
390 class MenuItemUpdateTimesheet : ImageMenuItem {
392 public MenuItemUpdateTimesheet()
395 var image = new Gtk.Image();
396 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
397 this.set_image (image);
398 this.label= "Update Timesheet";
399 this.always_show_image = true;
400 this.accel_group = null;
402 this.activate.connect( () => {
403 //var ret = imports.FixBug.FixBug.show();
410 class MenuItemManageClones : ImageMenuItem {
412 public MenuItemManageClones()
415 var image = new Gtk.Image();
416 image.set_from_stock(Gtk.Stock.JUSTIFY_FILL,Gtk.IconSize.MENU );
417 this.set_image (image);
418 this.label= "Manage Clones";
419 this.always_show_image = true;
420 this.accel_group = null;
422 this.activate.connect( () => {
423 //GitRepo.updateAll("show_clones");
424 Clones.singleton().loadAndShow();
426 // Clones.singleton().show();
433 class MenuItemNewTicket : ImageMenuItem {
435 public MenuItemNewTicket()
438 var image = new Gtk.Image();
439 image.set_from_stock(Gtk.Stock.NEW,Gtk.IconSize.MENU );
440 this.set_image (image);
441 this.label= "New Ticket";
442 this.always_show_image = true;
443 this.accel_group = null;
445 this.activate.connect( () => {
446 Ticket.singleton().show(null);
449 // Clones.singleton().show();
457 class MenuItemAbout : ImageMenuItem {
459 public MenuItemAbout()
462 var image = new Gtk.Image();
463 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
464 this.set_image (image);
465 this.label= "About Gitlive";
466 this.always_show_image = true;
467 this.accel_group = null;
469 this.activate.connect( () => {
470 //var ret = imports.Clones.Clones.show();
472 var msg = new Gtk.AboutDialog();
473 msg.program_name = "Git Live";
475 msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
476 msg.website_label= "Roo J Solutions Ltd.";
477 msg.license = "LGPL";
478 msg.authors = { "Alan Knowles <alan@roojs.com>" };
487 class MenuItemQuit : ImageMenuItem {
489 public MenuItemQuit()
492 var image = new Gtk.Image();
493 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
494 this.set_image (image);
496 this.always_show_image = true;
497 this.accel_group = null;
499 this.activate.connect( () => {
502 //var ret = imports.Clones.Clones.show();