Started work on app launcher
authorEnrico Zini <enrico@enricozini.org>
Mon, 3 Aug 2009 22:03:24 +0000 (23:03 +0100)
committerEnrico Zini <enrico@enricozini.org>
Mon, 3 Aug 2009 22:03:24 +0000 (23:03 +0100)
src/app_wm.vala

index 2100b0d32bb92a41d78044a6906fbadbf134e399..e2b8b283c7d4b25278cd210a5a420cba5adea2ce 100644 (file)
@@ -133,10 +133,88 @@ public class WindowList : Applet
        }
 }
 
        }
 }
 
+public class LauncherButton : Gtk.Button
+{
+       private string exec;
+
+       public LauncherButton(string name, string exec)
+       {
+               label = name;
+               this.exec = exec;
+               clicked += on_clicked;
+               set_size_request(0, zavai.config.min_button_height);
+       }
+
+       public void on_clicked()
+       {
+               stderr.printf("COMMAND: %s\n", exec);
+       }
+}
+
+public class Launcher: Applet
+{
+       static const string DENTRY_GROUP = "Desktop Entry";
+
+       public Launcher(string label)
+       {
+               _label = label;
+
+               var dir = File.new_for_path(zavai.config.homedir);
+               var enumerator = dir.enumerate_children(FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
+
+               FileInfo file_info;
+               var icon_theme = Gtk.IconTheme.get_default();
+               while ((file_info = enumerator.next_file(null)) != null)
+               {
+                       string pathname = zavai.config.homedir + "/" + file_info.get_name();
+                       //stdout.printf("Load %s\n", pathname);
+
+                       string icon = null;
+                       var kf = new KeyFile();
+                       try {
+                               kf.load_from_file(pathname, KeyFileFlags.NONE);
+                               if (! kf.has_group(DENTRY_GROUP)) continue;
+                               if (! kf.has_key(DENTRY_GROUP, "Name")) continue;
+                               if (! kf.has_key(DENTRY_GROUP, "Exec")) continue;
+                               if (kf.has_key(DENTRY_GROUP, "Icon"))
+                                       icon = kf.get_string(DENTRY_GROUP, "Icon");
+                       } catch (Error e) {
+                               zavai.log.error("Skipping file " + pathname + ": " + e.message);
+                               continue;
+                       }
+                       var name = kf.get_string(DENTRY_GROUP, "Name");
+                       var exec = kf.get_string(DENTRY_GROUP, "Exec");
+                       var button = new LauncherButton(name, exec);
+                       if (icon != null && icon_theme.has_icon(icon))
+                       {
+                               try {
+                                       var pb = icon_theme.load_icon(icon, zavai.config.min_button_height * 2 / 3, 0);
+                                       button.image = new Gtk.Image.from_pixbuf(pb);
+                               } catch (Error e) {
+                                       zavai.log.error("Skipping icon " + icon + ": " + e.message);
+                               }
+                       }
+                       pack_start(button, false, false, 0);
+               }
+
+/*
+    try {
+    } catch (Error e) {
+        stderr.printf ("Error: %s\n", e.message);
+        return 1;
+    }
+
+               for (string file in confdir)
+               {
+               }
+*/
+       }
+}
 
 RaiseIcon raise_icon;
 CloseOrBack close_or_back;
 WindowList window_list;
 
 RaiseIcon raise_icon;
 CloseOrBack close_or_back;
 WindowList window_list;
+Launcher launcher;
 
 public void init()
 {
 
 public void init()
 {
@@ -149,6 +227,19 @@ public void init()
        window_list = new WindowList("Current apps");
        zavai.registry.register_applet("wm.list", window_list);
        zavai.registry.getmenu("menu.main").add_applet("wm.list");
        window_list = new WindowList("Current apps");
        zavai.registry.register_applet("wm.list", window_list);
        zavai.registry.getmenu("menu.main").add_applet("wm.list");
+
+       try {
+               launcher = new Launcher("Run program");
+       } catch (Error e) {
+               zavai.log.error("Not running launcher: " + e.message);
+               launcher = null;
+       }
+       
+       if (launcher != null)
+       {
+               zavai.registry.register_applet("wm.launcher", launcher);
+               zavai.registry.getmenu("menu.main").add_applet("wm.launcher");
+       }
 }
 
 }
 }
 
 }