removed factory registration code from ApplicationItemFactory (it was moved to BasicI...
[simple-launcher] / utils.cc
1 // This file is a part of Simple Launcher
2 //
3 // Copyright (C) 2006, 2007, Mikhail Sobolev
4 //
5 // Simple Launcher is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License version 2 as published by
7 // the Free Software Foundation.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12 // more details.
13 //
14 // You should have received a copy of the GNU General Public License along with
15 // this program; if not, write to the Free Software Foundation, Inc., 51
16 // Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 #include <glib/gerror.h>
19 #include <glib/gutils.h>
20 #include <glib/gshell.h>
21 #include <glib/gspawn.h>
22 #include <glib/gmem.h>
23
24 #include "utils.h"
25
26 void runApplication(const std::string& whatToRun) {
27   if (!whatToRun.empty()) {
28     GError *error = NULL;
29     std::string::size_type pos;
30     std::string app, args;
31
32     if ((pos = whatToRun.find(' ')) != std::string::npos) {
33       app = whatToRun.substr(0, pos);
34       args = whatToRun.substr(pos);
35     } else {
36       app = whatToRun;
37     }
38
39     {
40       gchar *fullPath = g_find_program_in_path(app.c_str());
41
42       app.assign(fullPath);
43
44       g_free(fullPath);
45     }
46
47     if (!args.empty()) {
48       app += args;
49     }
50
51     if (!app.empty()) {
52       gint argc;
53       gchar **argv;
54       GPid pid;
55
56       if (g_shell_parse_argv (app.c_str(), &argc, &argv, &error)) {
57         g_spawn_async(NULL, argv, NULL, (GSpawnFlags)0, NULL, NULL, &pid, &error);
58       }
59
60       if (error != NULL) {
61         g_error_free(error);
62       }
63     }
64   }
65 }