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);
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 stderr.printf("push applet %s -> %s\n", current_name, name);
93 zavai.Applet applet = zavai.registry.geta(name);
95 // Remove the current applet
98 stderr.printf("push applet remove %s\n", current_name);
99 applet.back_link = current_name;
106 stderr.printf("push applet add %s\n", name);
107 // Add the new applet
115 public void shutdown()
121 set_size_request(300, 500);
127 class Zavai(gtk.Window, zavai.Resource):
128 def __init__(self, registry, name):
129 super(Zavai, self).__init__()
130 self.registry = registry
132 self.activate_resource("menu.main")
134 def activate_resource(self, name):
135 widget = self.registry.resource(name)
137 widget = self.registry.resource("menu.main")
138 if isinstance(widget, gtk.Action):
141 self.show_widget(name, widget)
144 public abstract class Applet : Gtk.VBox, Resource
146 // 'label' property: label to show in window title or button names
147 protected string _label;
148 public string label {
149 get { return this._label; }
158 public signal void label_changed();
160 // 'back_link' property: link to use to "go back". If null, do not show
162 protected AppletLink _back_link = null;
163 public string back_link {
164 get { return _back_link.target; }
166 stderr.printf("Set back link of %s to %s\n", _label, value);
167 if (value == null && _back_link != null)
169 _back_link.target = value;
171 } else if (value != null) {
172 if (_back_link.target == null)
174 _back_link.target = value;
175 pack_end(_back_link, false, false, 0);
178 _back_link.target = value;
185 this.homogeneous = false;
187 _back_link = new AppletStraightLink();
190 name = gobject.property(type=str)
191 label = gobject.property(type=str)
193 def __init__(self, registry, name, label = None):
194 super(Applet, self).__init__()
196 self.zavai_registry = registry
198 self.props.name = name
200 self.props.label = zavai.default_label(name)
202 self.props.label = label
204 self.back_link = zavai.LinkButton(registry, zavai.get_parent(name), _("Back"))
205 self.pack_end(self.back_link, False, False)
207 def add(self, widget):
208 self.pack_start(widget, True, True)
211 public void shutdown()
216 public virtual void start() {}
217 public virtual void stop() {}
220 public class Menu : Applet
222 public Menu(string label)
227 public void add_applet(string target)
229 stderr.printf("menu.add_applet.packpre me %s them %s\n", _label, target);
230 pack_start(new AppletPushLink(target), false, false, 0);
231 stderr.printf("menu.add_applet.packpost me %s them %s\n", _label, target);
234 public void add_service_toggle(string service_name, string label_start, string label_stop)
236 pack_start(new ServiceRequestLink(service_name, label_start, label_stop), false, false, 0);
239 public void add_widget(Gtk.Widget w)
241 pack_start(w, false, false, 0);
245 public class BigButton : Gtk.Button
249 set_size_request(0, zavai.config.min_button_height);
253 public abstract class AppletLink : BigButton
255 protected string _target;
256 public string target {
257 get { return _target; }
262 Applet a = zavai.registry.geta(_target);
263 a.label_changed -= on_label_changed;
265 bool was_shown = _target != null;
269 Applet a = zavai.registry.geta(_target);
271 a.label_changed += on_label_changed;
272 if (!was_shown) show();
274 if (was_shown) hide();
279 private void on_label_changed(Applet a)
284 private abstract void on_clicked(Gtk.Button src);
286 public AppletLink(string? name = null)
291 clicked += on_clicked;
295 public class AppletStraightLink : AppletLink
297 private override void on_clicked(Gtk.Button src)
299 stderr.printf("straight link: %s\n", _target);
301 zavai.app.show_applet(_target);
304 public AppletStraightLink(string? name = null)
310 public class AppletPushLink : AppletLink
312 private override void on_clicked(Gtk.Button src)
314 stderr.printf("push link: %s\n", _target);
316 zavai.app.push_applet(_target);
319 public AppletPushLink(string? name = null)
325 public class ServiceRequestLink : Gtk.ToggleButton
327 protected string service_name;
328 protected string label_start;
329 protected string label_stop;
331 private void on_toggled(Gtk.Button src)
333 Service s = zavai.registry.gets(service_name);
335 s.request("servicerequestlink");
337 s.release("servicerequestlink");
338 set_label(get_active() ? label_stop : label_start);
341 public ServiceRequestLink(string service_name, string label_start, string label_stop)
343 this.service_name = service_name;
344 this.label_start = label_start;
345 this.label_stop = label_stop;
346 set_size_request(0, zavai.config.min_button_height);
347 toggled += on_toggled;
349 set_label(get_active() ? label_stop : label_start);