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);
73 visibility_changed(visibility);
76 public void ensure_visible()
82 set_skip_pager_hint(true);
83 set_skip_taskbar_hint(true);
87 public void show_applet(string name)
89 zavai.Applet applet = zavai.registry.geta(name);
91 // Remove the current applet
100 // Add the new applet
108 public void push_applet(string name)
110 // Make the function idempotent
111 if (current_name == name)
114 //stderr.printf("push applet %s -> %s\n", current_name, name);
115 zavai.Applet applet = zavai.registry.geta(name);
117 // Remove the current applet
120 //stderr.printf("push applet remove %s\n", current_name);
121 applet.back_link = current_name;
128 //stderr.printf("push applet add %s\n", name);
129 // Add the new applet
143 public void shutdown()
149 set_size_request(300, 500);
155 class Zavai(gtk.Window, zavai.Resource):
156 def __init__(self, registry, name):
157 super(Zavai, self).__init__()
158 self.registry = registry
160 self.activate_resource("menu.main")
162 def activate_resource(self, name):
163 widget = self.registry.resource(name)
165 widget = self.registry.resource("menu.main")
166 if isinstance(widget, gtk.Action):
169 self.show_widget(name, widget)
172 public abstract class Applet : Gtk.VBox, Resource
174 // 'label' property: label to show in window title or button names
175 protected string _label;
176 public string label {
177 get { return this._label; }
186 public signal void label_changed();
188 protected Gtk.HBox button_box;
190 // 'back_link' property: link to use to "go back". If null, do not show
192 protected AppletLink _back_link = null;
193 public string back_link {
194 get { return _back_link.target; }
196 //stderr.printf("Set back link of %s to %s\n", _label, value);
197 if (value == null && _back_link != null)
199 _back_link.target = value;
200 button_box.remove(_back_link);
201 } else if (value != null) {
202 if (_back_link.target == null)
204 _back_link.target = value;
205 button_box.pack_end(_back_link, true, true, 0);
208 _back_link.target = value;
215 button_box = new Gtk.HBox(true, 0);
216 this.homogeneous = false;
218 pack_end(button_box, false, true, 0);
219 _back_link = new AppletStraightLink();
222 name = gobject.property(type=str)
223 label = gobject.property(type=str)
225 def __init__(self, registry, name, label = None):
226 super(Applet, self).__init__()
228 self.zavai_registry = registry
230 self.props.name = name
232 self.props.label = zavai.default_label(name)
234 self.props.label = label
236 self.back_link = zavai.LinkButton(registry, zavai.get_parent(name), _("Back"))
237 self.pack_end(self.back_link, False, False)
239 def add(self, widget):
240 self.pack_start(widget, True, True)
243 public virtual void back()
245 _back_link.activate();
248 public void shutdown()
253 public virtual void start() {}
254 public virtual void stop() {}
257 public class Menu : Applet
259 public Menu(string label)
264 public void add_applet(string target)
266 pack_start(new AppletPushLink(target), false, false, 0);
269 public void add_service_toggle(string service_name, string label_start, string label_stop)
271 pack_start(new ServiceRequestLink(service_name, label_start, label_stop), false, false, 0);
274 public void add_widget(Gtk.Widget w)
276 pack_start(w, false, false, 0);
280 public class BigButton : Gtk.Button
284 set_size_request(0, zavai.config.min_button_height);
288 public abstract class AppletLink : BigButton
290 protected string _target;
291 public string target {
292 get { return _target; }
297 Applet a = zavai.registry.geta(_target);
298 a.label_changed -= on_label_changed;
300 bool was_shown = _target != null;
304 Applet a = zavai.registry.geta(_target);
306 a.label_changed += on_label_changed;
307 if (!was_shown) show();
309 if (was_shown) hide();
314 private void on_label_changed(Applet a)
319 private abstract void on_clicked(Gtk.Button src);
321 public AppletLink(string? name = null)
326 clicked += on_clicked;
329 public virtual void activate()
335 public class AppletStraightLink : AppletLink
337 private override void on_clicked(Gtk.Button src)
339 //stderr.printf("straight link: %s\n", _target);
341 zavai.app.show_applet(_target);
344 public AppletStraightLink(string? name = null)
350 public class AppletPushLink : AppletLink
352 private override void on_clicked(Gtk.Button src)
354 //stderr.printf("push link: %s\n", _target);
356 zavai.app.push_applet(_target);
359 public AppletPushLink(string? name = null)
365 public class ServiceRequestLink : Gtk.ToggleButton
367 protected string service_name;
368 protected string label_start;
369 protected string label_stop;
371 private void on_toggled(Gtk.Button src)
373 Service s = zavai.registry.gets(service_name);
375 s.request("servicerequestlink");
377 s.release("servicerequestlink");
378 set_label(get_active() ? label_stop : label_start);
381 public ServiceRequestLink(string service_name, string label_start, string label_stop)
383 this.service_name = service_name;
384 this.label_start = label_start;
385 this.label_stop = label_stop;
386 set_size_request(0, zavai.config.min_button_height);
387 toggled += on_toggled;
389 set_label(get_active() ? label_stop : label_start);
393 public class StatusIcon : Gtk.Button
395 private Gtk.Image image_widget;
397 public signal void activate();
401 relief = Gtk.ReliefStyle.NONE;
402 image_widget = new Gtk.Image();
403 image = image_widget;
404 clicked += on_clicked;
407 public void set_from_file(string file)
409 image_widget.set_from_file(file);
412 public void install()
414 zavai.ui.main.status.status_icons.pack_start(this, false, false, 0);
417 private void on_clicked(Gtk.Button b)
423 public class CommandButton : Gtk.Button
425 private string command;
427 public CommandButton(string name, string command)
430 this.command = command;
431 clicked += on_clicked;
432 set_size_request(0, zavai.config.min_button_height);
435 public void on_clicked()
437 zavai.log.info("Run program: " + command);
438 string[] args = command.split(" ");
441 Environment.get_home_dir(),
444 SpawnFlags.SEARCH_PATH,