WindowLog.js
[gitlive] / StatusIcon.js
1 /**
2  * Status icon and menu for component of gitlive.
3  * 
4  * Implements XObject - however we want to control initialization.
5  * 
6  * 
7  * 
8  * Currently only does a few things
9  * a) Quit
10  * 
11  * b) Pause!??!
12  */
13  
14 var Gtk      = imports.gi.Gtk;
15 var Gdk      = imports.gi.Gdk;
16 var Gio      = imports.gi.Gio;
17 var GLib     = imports.gi.GLib;
18 var Notify   = imports.gi.Notify;
19
20 var XObject = imports.XObject.XObject;
21
22 //var gitlive = imports.gitlive;
23
24  
25 var StatusIcon  = new XObject({
26     
27     paused : false, // on!
28     xtype : Gtk.StatusIcon,
29     title : 'gitlive',
30     stock : Gtk.STOCK_REFRESH,
31     tooltip_text : 'GitLive',
32         init : function() {
33         XObject.prototype.init.call(this);
34         this.el.set_name('gitlive');
35     },
36     listeners : {
37         //'popup-menu' : function( w, event, event_time) {
38         'activate' : function( w, event, event_time) {
39             print(Array.prototype.slice.call(arguments).join(','));
40             
41             var menu = this.get('menu');
42             
43             menu.el.show_all();
44             
45             this.get(!this.paused ? 'resume' : 'pause' ).el.hide();
46             print("MENU EL: "  + menu.el);
47             print("POPUP: " + typeof(menu.el.popup));
48             
49             
50             menu.el.popup(null, null,Gtk.StatusIcon.position_menu , this.el , 1, Gtk.get_current_event_time());
51             //menu.el.popup(null, null,null, null, 1, Gtk.get_current_event_time());
52             
53             return;
54             
55             var g = { };
56             var a = new Gdk.Rectangle();
57             //  needs direction=inout setting in gir to work (in bugzilla @present)
58             this.el.get_geometry(g,a,null);
59              
60             // should check to see if @ top or bottom I guess..
61             menu.el.get_toplevel().move(a.x, a.y +a.height);
62              
63         }
64     },
65     items : [
66        {
67             xtype: Gtk.Menu,
68             id : 'menu',
69             pack: false,
70             items : [
71                 {
72                     init : function() {
73                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_MEDIA_PAUSE);
74                         XObject.prototype.init.call(this);
75                     },
76                     label: 'Pause Commits',
77                    
78                     always_show_image : true,
79                     accel_group : null,
80                     id : 'pause',
81                     //label: 'Pause',
82                     pack:  'append',
83                     listeners : {
84                         activate : function () {
85                             this.parent.parent.paused = true;
86                             imports.GitMonitor.GitMonitor.stop();
87                            // this.el.label  = status ? 'Resume' : 'Pause';
88                             this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
89                             
90                         }
91                     }
92                 },
93                 
94                 {
95                     init : function() {
96                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_MEDIA_PLAY);
97                         XObject.prototype.init.call(this);
98                     },
99                     label: 'Resume Commits',
100                     always_show_image : true,
101                     accel_group : null,
102                     id : 'resume',
103                     //label: 'Pause',
104                     pack:  'append',
105                     listeners : {
106                         activate : function () {
107                             this.parent.parent.paused = false;
108                              imports.GitMonitor.GitMonitor.start();
109                             //var status = this.el.label == 'Pause' ? 1 : 0
110                            // this.el.label  = status ? 'Resume' : 'Pause';
111                                
112                             
113                         }
114                     }
115                 },
116                 
117                 {
118                     init : function() {
119                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_RELOAD);
120                         XObject.prototype.init.call(this);
121                     },
122                     label: 'Pull (Refresh) All',
123                     always_show_image : true,
124                     accel_group : null,
125                     //label: 'Pause',
126                     pack:  'append',
127                     listeners : {
128                         activate : function () {
129                             imports.GitMonitor.GitMonitor.stop();
130                            
131                             
132                             var tr = imports.Scm.Repo.Repo.list();
133                             for (var i= 0; i< tr.length;i++) {
134                                 this.parent.parent.el.set_from_stock( i%2 ?  Gtk.STOCK_FULLSCREEN : Gtk.STOCK_LEAVE_FULLSCREEN );
135                                 
136                                 var repo = tr[i];
137                                 if (!repo.autocommit()) {
138                                     //??? should we ignore ones not on autocommit..
139                                     continue;
140                                 }
141                                 try {
142                                     this.parent.parent.el.set_tooltip_text("pull: " + repo.name);
143                                
144                                     var str = repo.pull();
145                                     // do not care if it's already in sycn..
146                                     if (str.match(/Already up-to-date/)) {
147                                         continue;
148                                     }
149                                     var notification = new Notify.Notification({
150                                        summary: "Updated " + repo.name,
151                                        body : str
152                                    });
153                                    notification.set_timeout(20);
154                                    notification.show();
155                                    
156                                 } catch(e) {
157                                     this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_RECORD );
158                                     print(JSON.stringify(e));
159                                     print("notification or push errror- probably to many in queue..");
160                                     imports.gitlive.errorDialog(e.message);
161
162                                 }
163                             }
164                             this.parent.parent.el.set_tooltip_text(this.parent.parent.tooltip_text);
165                                
166                             
167                              
168                           
169                             imports.GitMonitor.GitMonitor.start();
170                         }   
171                     }
172                 },
173                 {
174                     init : function() {
175                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_RELOAD);
176                         XObject.prototype.init.call(this);
177                     },
178                     label: 'Manage Clones',
179                     always_show_image : true,
180                     accel_group : null,
181                     
182                     //label: 'Pause',
183                     pack:  'append',
184                     listeners : {
185                         activate : function () {
186                              var ret = imports.Clones.Clones.show();
187                             
188                         }
189                     }
190                 },
191                 
192                 
193                 
194             
195                 {
196                     init : function() {
197                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_ABOUT);
198                         XObject.prototype.init.call(this);
199                     },
200                     label: 'About GitLive',
201                     pack:  'append',
202                     listeners : {
203                         activate : function () {
204                             var msg = new Gtk.AboutDialog({
205                                 program_name : "Git Live",
206                                 version: '0.3',
207                                 website: 'http://www.roojs.org/index.php/projects/gitlive.html',
208                                 website_label: 'RooJS Consulting',
209                                 license : 'LGPL'
210                             });
211                             msg.set_authors([ "Alan Knowles <alan@roojs.com>" ]);
212                             msg.run();
213                             msg.destroy();
214                         }
215                     }
216                 },
217                 
218                 {
219                     init : function() {
220                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_QUIT);
221                         XObject.prototype.init.call(this);
222                     },
223                     label: 'Quit',
224                     pack:  'append',
225                     listeners : {
226                         activate : function () {
227                             Seed.quit();
228                         }
229                     }
230                 }
231                 
232                 
233             ]
234         }
235     ]
236     
237 });
238
239