/* ------------------------- member functions (launcher_application) */
gboolean launcher_application_execute(struct launcher *launcher,
                                      const char *name,
                                      const char *long_name,
                                      const char *uri,
                                      GError **err)
{
        char *exec = NULL;
        gboolean retval = FALSE;
        gboolean terminal = FALSE;

        g_return_val_if_fail(launcher!=NULL, FALSE);
        g_return_val_if_fail(launcher==&launcher_application, FALSE);
        g_return_val_if_fail(name!=NULL, FALSE);
        g_return_val_if_fail(long_name!=NULL, FALSE);
        g_return_val_if_fail(uri!=NULL, FALSE);
        g_return_val_if_fail(err==NULL || *err==NULL, FALSE);


        printf("%s:%d: launching application %s using %s...\n", __FILE__, __LINE__, name, uri);

        if(get_application(uri, &exec, &terminal, err)) {
                int pid;

                printf("%s:%d: execute: '%s' (in terminal=%c)\n",
                       __FILE__,
                       __LINE__,
                       exec,
                       terminal ? 'y':'n');
                errno=0;
                if(terminal)
                        pid=gnome_execute_terminal_shell(NULL, exec);
                else
                        pid=gnome_execute_shell(NULL, exec);
                if(pid==-1) {
                        g_set_error(err,
                                    LAUNCHER_ERROR,
                                    LAUNCHER_EXTERNAL_ERROR,
                                    "launching '%s' failed: %s",
                                    exec,
                                    errno!=0 ? strerror(errno):"unknown error");
                } else {
                        printf("%s:%d: executed '%s' with PID %d\n",
                               __FILE__,
                               __LINE__,
                               exec,
                               pid);
                        retval=TRUE;
                }
        }

        if(exec) {
                g_free(exec);
        }
        g_assert(retval || err==NULL || *err!=NULL);
        return retval;
}
Esempio n. 2
0
/**
 * Either displays a URL or invokes an command line with the supplied
 * terms appropriately embedded.
 */
void
lk_launcher_launch (const LkBinding* binding, const gchar* terms)
{
    char cwdbuf[1024];
    GString* cmd;
    gchar* uterms, *command;
    LkBindingType type;

    /* figure out what we're supposed to do */
    if (binding == NULL) {
	command = DEFAULT_COMMAND;
	type = DEFAULT_TYPE;

    } else {
	command = binding->argument;
	type = binding->type;
    }

    /* construct the actual command from it by replacing instances of %T
     * with the terms and %U with the URL encoded terms. */
    cmd = g_string_new(command);
    /* first replace %U because we know that won't result in any '%T's
     * being inserted into the string because the url encoded terms
     * encode all %s */
    uterms = url_encode(terms);
    g_string_replace(cmd, "%U", uterms);
    g_free(uterms);
    g_string_replace(cmd, "%T", terms);

    /* now we either invoke a program or launch a URL */
    switch (type) {
    case EXEC:
	gnome_execute_shell(getcwd(cwdbuf, 1024), cmd->str);
	break;

    default:
    case URL:
	gnome_url_show(cmd->str);
	break;
    }

    g_string_free(cmd, TRUE);
}