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 MenuA();
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 MenuA : Gtk.Menu
162 public ImageMenuItem pause;
163 public ImageMenuItem resume;
167 this.pause = new MenuItemPause();
168 this.append(this.pause);
169 this.resume = new MenuItemStartCommits();
170 this.append(this.resume);
171 this.append(new MenuItemPullAll());
172 this.append(new Gtk.SeparatorMenuItem());
173 //this.append(new MenuItemUpdateTimesheet());
174 this.append(new MenuItemManageClones());
175 this.append(new ImageMenuItemF());
176 this.append(new ImageMenuItemG());
183 class MenuItemPause : ImageMenuItem {
185 public MenuItemPause()
187 //this.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
189 var image = new Gtk.Image();
190 image.set_from_stock(Gtk.Stock.MEDIA_PAUSE,Gtk.IconSize.MENU );
191 this.set_image (image);
193 this.label= "Pause Commits";
194 this.always_show_image = true;
195 this.accel_group = null;
197 this.activate.connect( () => {
198 statusicon.paused = true;
199 GitMonitor.gitmonitor.stop();
201 // this.el.label = status ? 'Resume' : 'Pause';
202 statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE );
211 class MenuItemStartCommits : ImageMenuItem {
213 public MenuItemStartCommits()
216 var image = new Gtk.Image();
217 image.set_from_stock(Gtk.Stock.MEDIA_PLAY,Gtk.IconSize.MENU );
218 this.set_image (image);
219 this.label= "Start Commits";
220 this.always_show_image = true;
221 this.accel_group = null;
223 this.activate.connect( () => {
224 GitMonitor.gitmonitor.start();
225 statusicon.paused = false;
228 // this.el.label = status ? 'Resume' : 'Pause';
229 statusicon.set_from_stock( Gtk.Stock.MEDIA_PLAY );
239 class MenuItemPullAll : ImageMenuItem {
241 public MenuItemPullAll()
244 var image = new Gtk.Image();
245 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
246 this.set_image (image);
247 this.label= "Pull (Refresh) All";
248 this.always_show_image = true;
249 this.accel_group = null;
251 this.activate.connect( () => {
255 GitMonitor.gitmonitor.stop();
256 var tr = GitRepo.list();
260 for (var i= 0; i< tr.length;i++) {
261 statusicon.set_from_stock(
262 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
264 var repo = tr.index(i);
265 //if (!repo.autocommit()) {
266 //??? should we ignore ones not on autocommit..
270 statusicon.set_tooltip_text("pull: " + repo.name);
271 var str = repo.pull();
272 // do not care if it's already in sycn..
273 if (Regex.match_simple ("Already up-to-date", str) ) {
276 var notification = new Notify.Notification(
277 "Updated " + repo.name,
283 notification.set_timeout(20);
287 print("notification or push errror- probably to many in queue..");
288 statusicon.set_from_stock( Gtk.Stock.MEDIA_RECORD );
301 var tr = GitRepo.list();
303 GitMonitor.gitmonitor.stop();
306 this.total = tr.length;
308 this.pull_all_error_message = "";
309 for (var i= 0; i< tr.length;i++) {
310 statusicon.set_from_stock(
311 i%2 == 0 ? Gtk.Stock.FULLSCREEN : Gtk.Stock.LEAVE_FULLSCREEN );
313 var repo = tr.index(i);
317 statusicon.set_tooltip_text("pull: " + repo.name);
319 repo.pull_async(this.pullAllCallback);
320 // do not care if it's already in sycn..
332 string pull_all_error_message = "";
334 void pullAllCallback(GitRepo repo, int err, string res)
340 this.pull_all_error_message += this.pull_all_error_message.length > 0 ? "\n" : "";
341 this.pull_all_error_message += "Error Pulling " + repo.name +"\n" + res;
344 if (!Regex.match_simple ("Already up-to-date", res) ) {
345 var notification = new Notify.Notification(
347 "Updated: " +repo.name + "\n" + res +"\n",
350 notification.set_timeout(20);
356 if (this.total < 1) {
357 if (this.has_error > 0) {
358 GitMonitor.gitmonitor.pauseError(this.pull_all_error_message);
362 statusicon.set_tooltip_text("Gitlive");
364 GitMonitor.gitmonitor.start();
375 class MenuItemUpdateTimesheet : ImageMenuItem {
377 public MenuItemUpdateTimesheet()
380 var image = new Gtk.Image();
381 image.set_from_stock(Gtk.Stock.SAVE,Gtk.IconSize.MENU );
382 this.set_image (image);
383 this.label= "Update Timesheet";
384 this.always_show_image = true;
385 this.accel_group = null;
387 this.activate.connect( () => {
388 //var ret = imports.FixBug.FixBug.show();
395 class MenuItemManageClones : ImageMenuItem {
397 public MenuItemManageClones()
400 var image = new Gtk.Image();
401 image.set_from_stock(Gtk.Stock.FULLSCREEN,Gtk.IconSize.MENU );
402 this.set_image (image);
403 this.label= "Manage Clones";
404 this.always_show_image = true;
405 this.accel_group = null;
407 this.activate.connect( () => {
408 Clones.singleton().show();
415 class ImageMenuItemF : ImageMenuItem {
417 public ImageMenuItemF()
420 var image = new Gtk.Image();
421 image.set_from_stock(Gtk.Stock.ABOUT,Gtk.IconSize.MENU );
422 this.set_image (image);
423 this.label= "About Gitlive";
424 this.always_show_image = true;
425 this.accel_group = null;
427 this.activate.connect( () => {
428 //var ret = imports.Clones.Clones.show();
430 var msg = new Gtk.AboutDialog();
431 msg.program_name = "Git Live";
433 msg.website= "http://www.roojs.org/index.php/projects/gitlive.html";
434 msg.website_label= "Roo J Solutions Ltd.";
435 msg.license = "LGPL";
436 msg.authors = { "Alan Knowles <alan@roojs.com>" };
445 class ImageMenuItemG : ImageMenuItem {
447 public ImageMenuItemG()
450 var image = new Gtk.Image();
451 image.set_from_stock(Gtk.Stock.QUIT,Gtk.IconSize.MENU );
452 this.set_image (image);
454 this.always_show_image = true;
455 this.accel_group = null;
457 this.activate.connect( () => {
460 //var ret = imports.Clones.Clones.show();