Kill button as back button when on zavai
[gregoa/zavai.git] / src / app.vala
index 2b2c8d79e1e426e5ba43e7989f71563f59f05c39..2478d2bac4e5d1b576eb03c06d3423e98162d8eb 100644 (file)
@@ -38,6 +38,9 @@ public class Zavai : Gtk.Window, zavai.Resource
                destroy += Gtk.main_quit;
                set_events(get_events() | Gdk.EventMask.VISIBILITY_NOTIFY_MASK);
                visibility_notify_event += on_visibility;
                destroy += Gtk.main_quit;
                set_events(get_events() | Gdk.EventMask.VISIBILITY_NOTIFY_MASK);
                visibility_notify_event += on_visibility;
+               set_skip_pager_hint(true);
+               set_skip_taskbar_hint(true);
+               //set_type_hint(Gdk.WindowTypeHint.DESKTOP);
        }
 
        private bool on_visibility(Gdk.Event event)
        }
 
        private bool on_visibility(Gdk.Event event)
@@ -58,6 +61,19 @@ public class Zavai : Gtk.Window, zavai.Resource
                } else {
                        visible = true;
                        present();
                } else {
                        visible = true;
                        present();
+                       set_skip_pager_hint(true);
+                       set_skip_taskbar_hint(true);
+               }
+       }
+
+       public void ensure_visible()
+       {
+               if (!visibility)
+               {
+                       visible = true;
+                       present();
+                       set_skip_pager_hint(true);
+                       set_skip_taskbar_hint(true);
                }
        }
 
                }
        }
 
@@ -84,13 +100,17 @@ public class Zavai : Gtk.Window, zavai.Resource
 
        public void push_applet(string name)
        {
 
        public void push_applet(string name)
        {
-stderr.printf("push applet %s -> %s\n", current_name, name);
+               // Make the function idempotent
+               if (current_name == name)
+                       return;
+
+//stderr.printf("push applet %s -> %s\n", current_name, name);
                zavai.Applet applet = zavai.registry.geta(name);
 
                // Remove the current applet
                if (current != null)
                {
                zavai.Applet applet = zavai.registry.geta(name);
 
                // Remove the current applet
                if (current != null)
                {
-stderr.printf("push applet remove %s\n", current_name);
+//stderr.printf("push applet remove %s\n", current_name);
                        applet.back_link = current_name;
                        current.stop();
                        remove(current);
                        applet.back_link = current_name;
                        current.stop();
                        remove(current);
@@ -98,7 +118,7 @@ stderr.printf("push applet remove %s\n", current_name);
                        current_name = null;
                }
 
                        current_name = null;
                }
 
-stderr.printf("push applet add %s\n", name);
+//stderr.printf("push applet add %s\n", name);
                // Add the new applet
                current = applet;
                current_name = name;
                // Add the new applet
                current = applet;
                current_name = name;
@@ -107,6 +127,12 @@ stderr.printf("push applet add %s\n", name);
                current.show_all();
        }
 
                current.show_all();
        }
 
+       public void back()
+       {
+               if (current != null)
+                       current.back();
+       }
+
        public void shutdown()
        {
        }
        public void shutdown()
        {
        }
@@ -152,22 +178,24 @@ public abstract class Applet : Gtk.VBox, Resource
        }
        public signal void label_changed();
 
        }
        public signal void label_changed();
 
+       protected Gtk.HBox button_box;
+
        // 'back_link' property: link to use to "go back". If null, do not show
        // a way to go back.
        protected AppletLink _back_link = null;
        public string back_link {
                get { return _back_link.target; }
                set {
        // 'back_link' property: link to use to "go back". If null, do not show
        // a way to go back.
        protected AppletLink _back_link = null;
        public string back_link {
                get { return _back_link.target; }
                set {
-stderr.printf("Set back link of %s to %s\n", _label, value);
+//stderr.printf("Set back link of %s to %s\n", _label, value);
                        if (value == null && _back_link != null)
                        {
                                _back_link.target = value;
                        if (value == null && _back_link != null)
                        {
                                _back_link.target = value;
-                               remove(_back_link);
+                               button_box.remove(_back_link);
                        } else if (value != null) {
                                if (_back_link.target == null)
                                {
                                        _back_link.target = value;
                        } else if (value != null) {
                                if (_back_link.target == null)
                                {
                                        _back_link.target = value;
-                                       pack_end(_back_link, false, false, 0);
+                                       button_box.pack_end(_back_link, true, true, 0);
                                        _back_link.show();
                                } else
                                        _back_link.target = value;
                                        _back_link.show();
                                } else
                                        _back_link.target = value;
@@ -177,8 +205,10 @@ stderr.printf("Set back link of %s to %s\n", _label, value);
 
        public Applet()
        {
 
        public Applet()
        {
+               button_box = new Gtk.HBox(true, 0);
                this.homogeneous = false;
                this.spacing = 0;
                this.homogeneous = false;
                this.spacing = 0;
+               pack_end(button_box, false, true, 0);
                _back_link = new AppletStraightLink();
        }
 /*
                _back_link = new AppletStraightLink();
        }
 /*
@@ -203,6 +233,11 @@ stderr.printf("Set back link of %s to %s\n", _label, value);
         self.pack_start(widget, True, True)
 */
 
         self.pack_start(widget, True, True)
 */
 
+       public virtual void back()
+       {
+               _back_link.activate();
+       }
+
        public void shutdown()
        {
                stop();
        public void shutdown()
        {
                stop();
@@ -221,9 +256,7 @@ public class Menu : Applet
 
        public void add_applet(string target)
        {
 
        public void add_applet(string target)
        {
-stderr.printf("menu.add_applet.packpre me %s them %s\n", _label, target);
                pack_start(new AppletPushLink(target), false, false, 0);
                pack_start(new AppletPushLink(target), false, false, 0);
-stderr.printf("menu.add_applet.packpost me %s them %s\n", _label, target);
        }
 
        public void add_service_toggle(string service_name, string label_start, string label_stop)
        }
 
        public void add_service_toggle(string service_name, string label_start, string label_stop)
@@ -285,13 +318,18 @@ public abstract class AppletLink : BigButton
 
                clicked += on_clicked;
        }
 
                clicked += on_clicked;
        }
+
+       public virtual void activate()
+       {
+               on_clicked(this);
+       }
 }
 
 public class AppletStraightLink : AppletLink
 {
        private override void on_clicked(Gtk.Button src)
        {
 }
 
 public class AppletStraightLink : AppletLink
 {
        private override void on_clicked(Gtk.Button src)
        {
-stderr.printf("straight link: %s\n", _target);
+//stderr.printf("straight link: %s\n", _target);
                if (_target != null)
                        zavai.app.show_applet(_target);
        }
                if (_target != null)
                        zavai.app.show_applet(_target);
        }
@@ -306,7 +344,7 @@ public class AppletPushLink : AppletLink
 {
        private override void on_clicked(Gtk.Button src)
        {
 {
        private override void on_clicked(Gtk.Button src)
        {
-stderr.printf("push link: %s\n", _target);
+//stderr.printf("push link: %s\n", _target);
                if (_target != null)
                        zavai.app.push_applet(_target);
        }
                if (_target != null)
                        zavai.app.push_applet(_target);
        }
@@ -345,6 +383,34 @@ public class ServiceRequestLink : Gtk.ToggleButton
        }
 }
 
        }
 }
 
+public class CommandButton : Gtk.Button
+{
+       private string command;
+
+       public CommandButton(string name, string command)
+       {
+               label = name;
+               this.command = command;
+               clicked += on_clicked;
+               set_size_request(0, zavai.config.min_button_height);
+       }
+
+       public void on_clicked()
+       {
+               zavai.log.info("Run program: " + command);
+               string[] args = command.split(" ");
+               Pid pid;
+               Process.spawn_async(
+                       Environment.get_home_dir(),
+                       args,
+                       null,
+                       SpawnFlags.SEARCH_PATH,
+                       null,
+                       out pid);
+       }
+}
+
+
 zavai.Zavai app;
 
 }
 zavai.Zavai app;
 
 }