StatusIcon.js
[gitlive] / StatusIcon.js
1 //<script type="text/javascript">
2
3
4 /**
5  * Status icon and menu for component of gitlive.
6  * 
7  * Implements XObject - however we want to control initialization.
8  * 
9  * 
10  * 
11  * Currently only does a few things
12  * a) Quit
13  * 
14  * b) Pause!??!
15  */
16  
17 Gtk      = imports.gi.Gtk;
18 Gdk      = imports.gi.Gdk;
19 XObject = imports['XObject.js'].XObject
20
21
22  
23 StatusIcon  = new XObject({
24     
25     paused : false, // on!
26     xtype : Gtk.StatusIcon,
27     stock : Gtk.STOCK_MEDIA_PLAY,
28     tooltip_text : 'GitLive',
29     listeners : {
30         //'popup-menu' : function( w, event, event_time) {
31         'activate' : function( w, event, event_time) {
32             print(Array.prototype.slice.call(arguments).join(','));
33             
34             menu = this.get('menu');
35             
36             menu.el.show_all();
37             
38             this.get(!this.paused ? 'resume' : 'pause' ).el.hide();
39             
40             menu.el.popup(null, null,null, null, 1, Gtk.get_current_event_time());
41             var g = { };
42             var a = new Gdk.Rectangle();
43             //  needs direction=inout setting in gir to work (in bugzilla @present)
44             this.el.get_geometry(g,a,null);
45              
46             // should check to see if @ top or bottom I guess..
47             menu.el.get_toplevel().move(a.x, a.y +a.height);
48              
49         }
50     },
51     items : [
52        {
53             xtype: Gtk.Menu,
54             xid : 'menu',
55             pack: false,
56             items : [
57                 {
58                     init : function() {
59                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_MEDIA_PAUSE);
60                         XObject.prototype.init.call(this);
61                     },
62                     label: 'Pause Commits',
63                    
64                     always_show_image : true,
65                     accel_group : null,
66                     xid : 'pause',
67                     //label: 'Pause',
68                     pack:  'append',
69                     listeners : {
70                         activate : function () {
71                             this.parent.parent.paused = true;
72                            // this.el.label  = status ? 'Resume' : 'Pause';
73                             this.parent.parent.el.set_from_stock( Gtk.STOCK_MEDIA_PAUSE );
74                             
75                         }
76                     }
77                 },
78                 
79                 {
80                     init : function() {
81                         this.el = new Gtk.ImageMenuItem.from_stock(Gtk.STOCK_MEDIA_PLAY);
82                         XObject.prototype.init.call(this);
83                     },
84                     label: 'Resume Commits',
85                     always_show_image : true,
86                     accel_group : null,
87                     xid : 'resume',
88                     //label: 'Pause',
89                     pack:  'append',
90                     listeners : {
91                         activate : function () {
92                             this.parent.parent.paused = false;
93                             //var status = this.el.label == 'Pause' ? 1 : 0
94                            // this.el.label  = status ? 'Resume' : 'Pause';
95                             this.parent.parent.el.set_from_stock(   Gtk.STOCK_MEDIA_PLAY);
96                             
97                         }
98                     }
99                 },
100             
101                 {
102                     xtype: Gtk.MenuItem,
103                     label: 'About',
104                     pack:  'append',
105                     listeners : {
106                         activate : function () {
107                             var msg = new Gtk.MessageDialog({message_type:
108                                 Gtk.MessageType.INFO, buttons : Gtk.ButtonsType.OK, text: "GIT Live - auto commits and pushes everything in ~/gitlive"});
109                             msg.run();
110                             msg.destroy();
111                         }
112                     }
113                 },
114                 
115                 {
116                     xtype: Gtk.MenuItem,
117                     label: 'Close',
118                     pack:  'append',
119                     listeners : {
120                         activate : function () {
121                             Seed.quit();
122                         }
123                     }
124                 }
125                 
126                 
127             ]
128         }
129     ]
130     
131 });
132
133