2 * app - zavai main window
4 * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 public class Zavai : Gtk.Window, zavai.Resource
27 public bool visibility = true;
28 public signal void visibility_changed(bool visible);
38 destroy += Gtk.main_quit;
39 set_events(get_events() | Gdk.EventMask.VISIBILITY_NOTIFY_MASK);
40 visibility_notify_event += on_visibility;
43 private bool on_visibility(Gdk.Event event)
45 visibility = (event.visibility.state == Gdk.VisibilityState.UNOBSCURED);
46 visibility_changed(visibility);
50 public void toggle_visibility()
56 visibility_changed(visibility);
57 //zavai.app.iconify();
64 public void show_applet(string name)
66 zavai.Applet applet = zavai.registry.geta(name);
68 // Remove the current applet
85 public void push_applet(string name)
87 stderr.printf("push applet %s -> %s\n", current_name, name);
88 zavai.Applet applet = zavai.registry.geta(name);
90 // Remove the current applet
93 stderr.printf("push applet remove %s\n", current_name);
94 applet.back_link = current_name;
101 stderr.printf("push applet add %s\n", name);
102 // Add the new applet
110 public void shutdown()
116 set_size_request(300, 500);
122 class Zavai(gtk.Window, zavai.Resource):
123 def __init__(self, registry, name):
124 super(Zavai, self).__init__()
125 self.registry = registry
127 self.activate_resource("menu.main")
129 def activate_resource(self, name):
130 widget = self.registry.resource(name)
132 widget = self.registry.resource("menu.main")
133 if isinstance(widget, gtk.Action):
136 self.show_widget(name, widget)
139 public abstract class Applet : Gtk.VBox, Resource
141 // 'label' property: label to show in window title or button names
142 protected string _label;
143 public string label {
144 get { return this._label; }
153 public signal void label_changed();
155 // 'back_link' property: link to use to "go back". If null, do not show
157 protected AppletLink _back_link = null;
158 public string back_link {
159 get { return _back_link.target; }
161 stderr.printf("Set back link of %s to %s\n", _label, value);
162 if (value == null && _back_link != null)
164 _back_link.target = value;
166 } else if (value != null) {
167 if (_back_link.target == null)
169 _back_link.target = value;
170 pack_end(_back_link, false, false, 0);
173 _back_link.target = value;
180 this.homogeneous = false;
182 _back_link = new AppletStraightLink();
185 name = gobject.property(type=str)
186 label = gobject.property(type=str)
188 def __init__(self, registry, name, label = None):
189 super(Applet, self).__init__()
191 self.zavai_registry = registry
193 self.props.name = name
195 self.props.label = zavai.default_label(name)
197 self.props.label = label
199 self.back_link = zavai.LinkButton(registry, zavai.get_parent(name), _("Back"))
200 self.pack_end(self.back_link, False, False)
202 def add(self, widget):
203 self.pack_start(widget, True, True)
206 public void shutdown()
211 public virtual void start() {}
212 public virtual void stop() {}
215 public class Menu : Applet
217 public Menu(string label)
222 public void add_applet(string target)
224 stderr.printf("menu.add_applet.packpre me %s them %s\n", _label, target);
225 pack_start(new AppletPushLink(target), false, false, 0);
226 stderr.printf("menu.add_applet.packpost me %s them %s\n", _label, target);
229 public void add_service_toggle(string service_name, string label_start, string label_stop)
231 pack_start(new ServiceRequestLink(service_name, label_start, label_stop), false, false, 0);
234 public void add_widget(Gtk.Widget w)
236 pack_start(w, false, false, 0);
240 public class BigButton : Gtk.Button
244 set_size_request(0, zavai.config.min_button_height);
248 public abstract class AppletLink : BigButton
250 protected string _target;
251 public string target {
252 get { return _target; }
257 Applet a = zavai.registry.geta(_target);
258 a.label_changed -= on_label_changed;
260 bool was_shown = _target != null;
264 Applet a = zavai.registry.geta(_target);
266 a.label_changed += on_label_changed;
267 if (!was_shown) show();
269 if (was_shown) hide();
274 private void on_label_changed(Applet a)
279 private abstract void on_clicked(Gtk.Button src);
281 public AppletLink(string? name = null)
286 clicked += on_clicked;
290 public class AppletStraightLink : AppletLink
292 private override void on_clicked(Gtk.Button src)
294 stderr.printf("straight link: %s\n", _target);
296 zavai.app.show_applet(_target);
299 public AppletStraightLink(string? name = null)
305 public class AppletPushLink : AppletLink
307 private override void on_clicked(Gtk.Button src)
309 stderr.printf("push link: %s\n", _target);
311 zavai.app.push_applet(_target);
314 public AppletPushLink(string? name = null)
320 public class ServiceRequestLink : Gtk.ToggleButton
322 protected string service_name;
323 protected string label_start;
324 protected string label_stop;
326 private void on_toggled(Gtk.Button src)
328 Service s = zavai.registry.gets(service_name);
330 s.request("servicerequestlink");
332 s.release("servicerequestlink");
333 set_label(get_active() ? label_stop : label_start);
336 public ServiceRequestLink(string service_name, string label_start, string label_stop)
338 this.service_name = service_name;
339 this.label_start = label_start;
340 this.label_stop = label_stop;
341 set_size_request(0, zavai.config.min_button_height);
342 toggled += on_toggled;
344 set_label(get_active() ? label_stop : label_start);