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;
41 set_skip_pager_hint(true);
42 set_skip_taskbar_hint(true);
43 //set_type_hint(Gdk.WindowTypeHint.DESKTOP);
46 private bool on_visibility(Gdk.Event event)
48 visibility = (event.visibility.state == Gdk.VisibilityState.UNOBSCURED);
49 visibility_changed(visibility);
53 public void toggle_visibility()
59 visibility_changed(visibility);
60 //zavai.app.iconify();
64 set_skip_pager_hint(true);
65 set_skip_taskbar_hint(true);
69 public void show_applet(string name)
71 zavai.Applet applet = zavai.registry.geta(name);
73 // Remove the current applet
90 public void push_applet(string name)
92 // Make the function idempotent
93 if (current_name == name)
96 stderr.printf("push applet %s -> %s\n", current_name, name);
97 zavai.Applet applet = zavai.registry.geta(name);
99 // Remove the current applet
102 stderr.printf("push applet remove %s\n", current_name);
103 applet.back_link = current_name;
110 stderr.printf("push applet add %s\n", name);
111 // Add the new applet
119 public void shutdown()
125 set_size_request(300, 500);
131 class Zavai(gtk.Window, zavai.Resource):
132 def __init__(self, registry, name):
133 super(Zavai, self).__init__()
134 self.registry = registry
136 self.activate_resource("menu.main")
138 def activate_resource(self, name):
139 widget = self.registry.resource(name)
141 widget = self.registry.resource("menu.main")
142 if isinstance(widget, gtk.Action):
145 self.show_widget(name, widget)
148 public abstract class Applet : Gtk.VBox, Resource
150 // 'label' property: label to show in window title or button names
151 protected string _label;
152 public string label {
153 get { return this._label; }
162 public signal void label_changed();
164 // 'back_link' property: link to use to "go back". If null, do not show
166 protected AppletLink _back_link = null;
167 public string back_link {
168 get { return _back_link.target; }
170 stderr.printf("Set back link of %s to %s\n", _label, value);
171 if (value == null && _back_link != null)
173 _back_link.target = value;
175 } else if (value != null) {
176 if (_back_link.target == null)
178 _back_link.target = value;
179 pack_end(_back_link, false, false, 0);
182 _back_link.target = value;
189 this.homogeneous = false;
191 _back_link = new AppletStraightLink();
194 name = gobject.property(type=str)
195 label = gobject.property(type=str)
197 def __init__(self, registry, name, label = None):
198 super(Applet, self).__init__()
200 self.zavai_registry = registry
202 self.props.name = name
204 self.props.label = zavai.default_label(name)
206 self.props.label = label
208 self.back_link = zavai.LinkButton(registry, zavai.get_parent(name), _("Back"))
209 self.pack_end(self.back_link, False, False)
211 def add(self, widget):
212 self.pack_start(widget, True, True)
215 public void shutdown()
220 public virtual void start() {}
221 public virtual void stop() {}
224 public class Menu : Applet
226 public Menu(string label)
231 public void add_applet(string target)
233 stderr.printf("menu.add_applet.packpre me %s them %s\n", _label, target);
234 pack_start(new AppletPushLink(target), false, false, 0);
235 stderr.printf("menu.add_applet.packpost me %s them %s\n", _label, target);
238 public void add_service_toggle(string service_name, string label_start, string label_stop)
240 pack_start(new ServiceRequestLink(service_name, label_start, label_stop), false, false, 0);
243 public void add_widget(Gtk.Widget w)
245 pack_start(w, false, false, 0);
249 public class BigButton : Gtk.Button
253 set_size_request(0, zavai.config.min_button_height);
257 public abstract class AppletLink : BigButton
259 protected string _target;
260 public string target {
261 get { return _target; }
266 Applet a = zavai.registry.geta(_target);
267 a.label_changed -= on_label_changed;
269 bool was_shown = _target != null;
273 Applet a = zavai.registry.geta(_target);
275 a.label_changed += on_label_changed;
276 if (!was_shown) show();
278 if (was_shown) hide();
283 private void on_label_changed(Applet a)
288 private abstract void on_clicked(Gtk.Button src);
290 public AppletLink(string? name = null)
295 clicked += on_clicked;
299 public class AppletStraightLink : AppletLink
301 private override void on_clicked(Gtk.Button src)
303 stderr.printf("straight link: %s\n", _target);
305 zavai.app.show_applet(_target);
308 public AppletStraightLink(string? name = null)
314 public class AppletPushLink : AppletLink
316 private override void on_clicked(Gtk.Button src)
318 stderr.printf("push link: %s\n", _target);
320 zavai.app.push_applet(_target);
323 public AppletPushLink(string? name = null)
329 public class ServiceRequestLink : Gtk.ToggleButton
331 protected string service_name;
332 protected string label_start;
333 protected string label_stop;
335 private void on_toggled(Gtk.Button src)
337 Service s = zavai.registry.gets(service_name);
339 s.request("servicerequestlink");
341 s.release("servicerequestlink");
342 set_label(get_active() ? label_stop : label_start);
345 public ServiceRequestLink(string service_name, string label_start, string label_stop)
347 this.service_name = service_name;
348 this.label_start = label_start;
349 this.label_stop = label_stop;
350 set_size_request(0, zavai.config.min_button_height);
351 toggled += on_toggled;
353 set_label(get_active() ? label_stop : label_start);