enable activation of applications that do not have d-bus service
authormishas <mikhail.sobolev@gmail.com>
Sat, 24 Mar 2007 19:38:47 +0000 (19:38 +0000)
committermishas <mikhail.sobolev@gmail.com>
Sat, 24 Mar 2007 19:38:47 +0000 (19:38 +0000)
git-svn-id: file:///svnroot/simple-launcher/trunk@126 3ba93dab-e023-0410-b42a-de7732cf370a

Makefile
debian/changelog
launchable-item.cc
launcher-item.cc
launcher-item.h
utils.cc [new file with mode: 0644]
utils.h [new file with mode: 0644]

index dfe440d..46a4255 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,7 @@ all: $(TARGET)
 
 tests: test test1
 
-$(TARGET): simple-launcher.o launchable-item.o launcher-item.o sla-list.o
+$(TARGET): simple-launcher.o launchable-item.o launcher-item.o sla-list.o utils.o
        $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
 
 test: test.o launcher-item.o
index 1d3aa54..4db0c32 100644 (file)
@@ -1,8 +1,9 @@
 simple-launcher (0.9.3) unstable; urgency=low
 
   * the config file can now be backed up
+  * enable activation of applications that do not have d-bus service
 
- -- Mikhail Sobolev <mss@mawhrin.net>  Sat, 24 Mar 2007 12:32:51 +0200
+ -- Mikhail Sobolev <mss@mawhrin.net>  Sat, 24 Mar 2007 21:11:54 +0200
 
 simple-launcher (0.9.2) unstable; urgency=low
 
index cf17f2c..53edc67 100644 (file)
 // Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include "launchable-item.h"
+#include "utils.h"
 
 bool LaunchableItem::activate(osso_context_t *context) {
-  return osso_application_top(context, getService().c_str(), NULL) == OSSO_OK;
+  bool result = false;
+
+  if (getService().empty() || !(result = osso_application_top(context, getService().c_str(), NULL) == OSSO_OK)) {
+    runApplication(getExec());
+    return true;
+  } else {
+    return result;
+  }
 }
 
 // vim:ts=2:sw=2:et
index 67e984d..6487f28 100644 (file)
@@ -31,6 +31,7 @@ static const char *DESKTOP_ENTRY_GROUP = "Desktop Entry",
                   *DESKTOP_ENTRY_ICON_FIELD = "Icon",
                   *DESKTOP_ENTRY_NAME_FIELD = "Name",
                   *DESKTOP_ENTRY_COMMENT_FIELD = "Comment",
+                  *DESKTOP_ENTRY_EXEC_FIELD = "Exec",
                   *DESKTOP_ENTRY_SERVICE_FIELD = "X-Osso-Service",
                   *DESKTOP_ENTRY_TEXT_DOMAIN = "X-Text-Domain";
 
@@ -122,6 +123,7 @@ bool LauncherItem::load(const std::string& filename) {
     myComment = key_file.getLocaleString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_COMMENT_FIELD);
     myIcon = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_ICON_FIELD);
     myService = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_SERVICE_FIELD);
+    myExec = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_EXEC_FIELD);
     myTextDomain = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_TEXT_DOMAIN);
 
     break;
index 03b78be..220c20a 100644 (file)
@@ -39,6 +39,7 @@ public:
   std::string getName(bool translate = true) const { return translate ? translateString(myName) : myName; }
   std::string getComment(bool translate = true) const { return translate ? translateString(myComment) : myComment; }
   const std::string& getService() const { return myService; }
+  const std::string& getExec() const { return myExec; }
 
   bool isEnabled(void) const { return myEnabled; }
 
@@ -55,10 +56,10 @@ public:
 private:
   std::string translateString(const std::string& what) const;
 
-  bool checkSanity(void) { return !(myName.empty() || myService.empty()); }
+  bool checkSanity(void) { return !myName.empty() && (!myService.empty() || !myExec.empty()); }
 
 private:
-  std::string myFileName, myName, myComment, myIcon, myService, myTextDomain;
+  std::string myFileName, myName, myComment, myIcon, myService, myExec, myTextDomain;
   bool myEnabled;
 
   static GtkIconTheme *ourTheme;
diff --git a/utils.cc b/utils.cc
new file mode 100644 (file)
index 0000000..5393af2
--- /dev/null
+++ b/utils.cc
@@ -0,0 +1,65 @@
+// This file is a part of Simple Launcher
+//
+// Copyright (C) 2006, 2007, Mikhail Sobolev
+//
+// Simple Launcher is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#include <glib/gerror.h>
+#include <glib/gutils.h>
+#include <glib/gshell.h>
+#include <glib/gspawn.h>
+#include <glib/gmem.h>
+
+#include "utils.h"
+
+void runApplication(const std::string& whatToRun) {
+  if (!whatToRun.empty()) {
+    GError *error = NULL;
+    std::string::size_type pos;
+    std::string app, args;
+
+    if ((pos = whatToRun.find(' ')) != std::string::npos) {
+      app = whatToRun.substr(0, pos);
+      args = whatToRun.substr(pos);
+    } else {
+      app = whatToRun;
+    }
+
+    {
+      gchar *fullPath = g_find_program_in_path(app.c_str());
+
+      app = std::string(fullPath);
+
+      g_free(fullPath);
+    }
+
+    if (!args.empty()) {
+      app += args;
+    }
+
+    if (!app.empty()) {
+      gint argc;
+      gchar **argv;
+      GPid pid;
+
+      if (g_shell_parse_argv (app.c_str(), &argc, &argv, &error)) {
+        g_spawn_async(NULL, argv, NULL, (GSpawnFlags)0, NULL, NULL, &pid, &error);
+      }
+
+      if (error != NULL) {
+        g_error_free(error);
+      }
+    }
+  }
+}
diff --git a/utils.h b/utils.h
new file mode 100644 (file)
index 0000000..a993618
--- /dev/null
+++ b/utils.h
@@ -0,0 +1,25 @@
+// This file is a part of Simple Launcher
+//
+// Copyright (C) 2006, 2007, Mikhail Sobolev
+//
+// Simple Launcher is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#ifndef __UTILS_H__
+#define __UTILS_H__
+
+#include <string>
+
+  void runApplication(const std::string& whatToRun);
+
+#endif