2009-07-07 15:57:45 +04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* ede-launch, launch external application
|
|
|
|
* Part of Equinox Desktop Environment (EDE).
|
|
|
|
* Copyright (c) 2008-2009 EDE Authors.
|
|
|
|
*
|
|
|
|
* This program is licensed under terms of the
|
|
|
|
* GNU General Public License version 2 or newer.
|
|
|
|
* See COPYING for details.
|
|
|
|
*/
|
|
|
|
|
2009-02-25 16:15:16 +03:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <errno.h>
|
2009-10-03 13:06:05 +04:00
|
|
|
#include <ctype.h>
|
2009-02-25 16:15:16 +03:00
|
|
|
|
2009-03-06 15:12:27 +03:00
|
|
|
#include <FL/x.H>
|
2009-02-25 17:03:00 +03:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Box.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
2009-02-25 17:42:40 +03:00
|
|
|
#include <FL/Fl_Check_Button.H>
|
2009-02-25 17:03:00 +03:00
|
|
|
#include <FL/Fl_Input.H>
|
|
|
|
#include <FL/Fl_Pixmap.H>
|
2009-07-07 15:57:45 +04:00
|
|
|
|
2009-02-25 16:15:16 +03:00
|
|
|
#include <edelib/Run.h>
|
2009-07-07 15:57:45 +04:00
|
|
|
#include <edelib/Resource.h>
|
2009-02-25 17:03:00 +03:00
|
|
|
#include <edelib/Window.h>
|
2009-02-27 17:37:09 +03:00
|
|
|
#include <edelib/Debug.h>
|
2009-03-06 15:12:27 +03:00
|
|
|
#include <edelib/Missing.h>
|
2009-02-27 17:37:09 +03:00
|
|
|
#include <edelib/MessageBox.h>
|
2009-10-03 13:06:05 +04:00
|
|
|
#include <edelib/String.h>
|
2011-10-22 00:26:19 +04:00
|
|
|
#include <edelib/File.h>
|
2011-10-23 04:10:40 +04:00
|
|
|
#include <edelib/WindowUtils.h>
|
2011-10-24 13:02:36 +04:00
|
|
|
#include <edelib/DesktopFile.h>
|
|
|
|
#include <edelib/StrUtil.h>
|
2011-10-25 17:48:56 +04:00
|
|
|
#include <edelib/Debug.h>
|
2010-03-28 16:54:45 +04:00
|
|
|
#include <edelib/Ede.h>
|
2011-10-24 16:21:05 +04:00
|
|
|
#include "StartupNotify.h"
|
2009-03-06 15:12:27 +03:00
|
|
|
|
2009-02-25 17:03:00 +03:00
|
|
|
#include "icons/run.xpm"
|
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
/* so value could be directed returned to shell */
|
|
|
|
#define RETURN_FROM_BOOL(v) (v != false)
|
|
|
|
|
|
|
|
/* config name where all things are stored and read from */
|
|
|
|
#define EDE_LAUNCH_CONFIG "ede-launch"
|
|
|
|
|
|
|
|
EDELIB_NS_USING_LIST(11, (Resource, String, DesktopFile, RES_USER_ONLY, DESK_FILE_TYPE_APPLICATION, run_sync, run_async, alert, file_path, window_center_on_screen, str_ends))
|
|
|
|
EDELIB_NS_USING_AS(Window, LaunchWindow)
|
2009-02-25 16:15:16 +03:00
|
|
|
|
2009-03-30 19:17:00 +04:00
|
|
|
static Fl_Pixmap image_run((const char**)run_xpm);
|
2009-02-25 17:42:40 +03:00
|
|
|
static Fl_Input* dialog_input;
|
|
|
|
static Fl_Check_Button* in_term;
|
|
|
|
|
2009-07-07 15:57:45 +04:00
|
|
|
static void help(void) {
|
2011-10-25 17:48:56 +04:00
|
|
|
puts("Usage: ede-launch [OPTIONS] [PROGRAM]");
|
2009-02-25 16:15:16 +03:00
|
|
|
puts("EDE program launcher");
|
2011-10-24 16:21:05 +04:00
|
|
|
puts("Options:");
|
2011-10-25 17:48:56 +04:00
|
|
|
puts(" -h, --help show this help");
|
|
|
|
puts(" -l, --launch [TYPE] [PARAMETERS] launch preferred application of TYPE with");
|
|
|
|
puts(" given PARAMETERS; see Types below");
|
|
|
|
puts(" -w, --working-dir [DIR] run programs with DIR as working directory\n");
|
2011-10-24 16:21:05 +04:00
|
|
|
puts("Types:");
|
2011-10-25 17:48:56 +04:00
|
|
|
puts(" browser preferred web browser");
|
|
|
|
puts(" mail preferred mail reader");
|
|
|
|
puts(" terminal preferred terminal");
|
|
|
|
puts(" file_manager preferred file manager\n");
|
2011-10-24 16:21:05 +04:00
|
|
|
puts("Example:");
|
|
|
|
puts(" ede-launch --launch browser http://www.foo.com");
|
2011-10-26 13:04:04 +04:00
|
|
|
puts(" ede-launch --launch mail mailto:foo@foo.com");
|
2011-10-24 16:21:05 +04:00
|
|
|
puts(" ede-launch gvim");
|
2011-10-25 17:48:56 +04:00
|
|
|
puts(" ede-launch ~/Desktop/foo.desktop");
|
2009-02-25 16:15:16 +03:00
|
|
|
}
|
|
|
|
|
2009-07-07 15:57:45 +04:00
|
|
|
static char* get_basename(const char* path) {
|
2009-11-20 20:08:29 +03:00
|
|
|
char *p = (char*)strrchr(path, '/');
|
2009-07-07 15:57:45 +04:00
|
|
|
if(p)
|
|
|
|
return (p + 1);
|
|
|
|
|
|
|
|
return (char*)p;
|
|
|
|
}
|
|
|
|
|
2009-02-25 16:15:16 +03:00
|
|
|
static char** cmd_split(const char* cmd) {
|
|
|
|
int sz = 10;
|
|
|
|
int i = 0;
|
|
|
|
char* c = strdup(cmd);
|
|
|
|
|
|
|
|
char** arr = (char**)malloc(sizeof(char*) * sz);
|
|
|
|
|
|
|
|
for(char* p = strtok(c, " "); p; p = strtok(NULL, " ")) {
|
|
|
|
if(i >= sz) {
|
|
|
|
sz *= 2;
|
|
|
|
arr = (char**)realloc(arr, sizeof(char*) * sz);
|
|
|
|
}
|
|
|
|
arr[i++] = strdup(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
arr[i] = NULL;
|
|
|
|
free(c);
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
static bool allowed_launch_type(const char *t) {
|
|
|
|
E_RETURN_VAL_IF_FAIL(t != 0, false);
|
|
|
|
|
|
|
|
/* should be synced with keys from ede-preferred-applications */
|
|
|
|
static const char *launch_types[] = {
|
|
|
|
"browser",
|
|
|
|
"mail",
|
|
|
|
"terminal",
|
|
|
|
"file_manager",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
for(int i = 0; launch_types[i]; i++) {
|
|
|
|
/* we do not allow >= 64 chars from user input */
|
|
|
|
if(strncmp(t, launch_types[i], 64) == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-25 16:15:16 +03:00
|
|
|
static void start_crasher(const char* cmd, int sig) {
|
2009-07-07 15:57:45 +04:00
|
|
|
const char* base = get_basename(cmd);
|
|
|
|
const char* ede_app_flag = "";
|
|
|
|
|
|
|
|
/* this means the app was called without full path */
|
2011-10-25 17:48:56 +04:00
|
|
|
if(!base) base = cmd;
|
2009-07-07 15:57:45 +04:00
|
|
|
|
2009-02-25 16:15:16 +03:00
|
|
|
/*
|
2009-07-07 15:57:45 +04:00
|
|
|
* determine is our app by checking the prefix; we don't want user to send bug reports about crashes
|
|
|
|
* of foreign applications
|
2009-02-25 16:15:16 +03:00
|
|
|
*/
|
2009-07-07 15:57:45 +04:00
|
|
|
if(strncmp(base, "ede-", 4) == 0)
|
|
|
|
ede_app_flag = "--edeapp";
|
|
|
|
|
|
|
|
/* call edelib implementation instead start_child_process() to prevents loops if 'ede-crasher' crashes */
|
2011-10-25 17:48:56 +04:00
|
|
|
run_sync(PREFIX "/bin/ede-crasher %s --appname %s --apppath %s --signal %i", ede_app_flag, base, cmd, sig);
|
2009-02-25 16:15:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int start_child_process(const char* cmd) {
|
|
|
|
int pid, in[2], out[2], err[2];
|
|
|
|
char** params = cmd_split(cmd);
|
|
|
|
|
|
|
|
pipe(in);
|
|
|
|
pipe(out);
|
|
|
|
pipe(err);
|
|
|
|
|
|
|
|
signal(SIGCHLD, SIG_DFL);
|
|
|
|
|
|
|
|
pid = fork();
|
|
|
|
switch(pid) {
|
|
|
|
case 0:
|
|
|
|
/* child process */
|
|
|
|
close(0);
|
|
|
|
dup(in[0]);
|
|
|
|
close(in[0]);
|
|
|
|
close(in[1]);
|
|
|
|
|
|
|
|
close(1);
|
|
|
|
dup(out[1]);
|
|
|
|
close(out[0]);
|
|
|
|
close(out[1]);
|
|
|
|
|
|
|
|
close(2);
|
|
|
|
dup(err[1]);
|
|
|
|
close(err[0]);
|
|
|
|
close(err[1]);
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
/* start it */
|
|
|
|
execvp(params[0], params);
|
|
|
|
|
2009-02-27 17:37:09 +03:00
|
|
|
/* some programs use value 2 (tar) */
|
2009-02-25 16:15:16 +03:00
|
|
|
if(errno == 2)
|
|
|
|
_exit(199);
|
|
|
|
else
|
|
|
|
_exit(errno);
|
|
|
|
break;
|
|
|
|
case -1:
|
2009-02-27 17:37:09 +03:00
|
|
|
E_WARNING(E_STRLOC ": fork() failed\n");
|
2009-02-25 16:15:16 +03:00
|
|
|
/* close the pipes */
|
|
|
|
close(in[0]);
|
|
|
|
close(in[1]);
|
|
|
|
|
|
|
|
close(out[0]);
|
|
|
|
close(out[1]);
|
|
|
|
|
|
|
|
close(err[0]);
|
|
|
|
close(err[1]);
|
|
|
|
break;
|
|
|
|
default:
|
2009-10-03 16:28:41 +04:00
|
|
|
/* parent */
|
2009-02-25 16:15:16 +03:00
|
|
|
close(in[0]);
|
|
|
|
close(out[1]);
|
|
|
|
close(err[1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-03 16:28:41 +04:00
|
|
|
/* cleanup when returns from the child */
|
|
|
|
for(int i = 0; params[i]; i++)
|
|
|
|
free(params[i]);
|
|
|
|
free(params);
|
|
|
|
|
2009-10-07 13:25:21 +04:00
|
|
|
int status = 0, ret = 1;
|
2009-02-27 17:37:09 +03:00
|
|
|
errno = 0;
|
2009-02-25 16:15:16 +03:00
|
|
|
if(waitpid(pid, &status, 0) < 0) {
|
2009-02-27 17:37:09 +03:00
|
|
|
E_WARNING(E_STRLOC ": waitpid() failed with '%s'\n", strerror(errno));
|
2009-02-25 16:15:16 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(WIFEXITED(status)) {
|
2009-02-27 17:37:09 +03:00
|
|
|
ret = WEXITSTATUS(status);
|
2009-02-25 16:15:16 +03:00
|
|
|
} else if(WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
|
|
|
|
start_crasher(cmd, SIGSEGV);
|
|
|
|
} else {
|
2009-02-27 17:37:09 +03:00
|
|
|
E_WARNING(E_STRLOC ": child '%s' killed\n", cmd);
|
2009-02-25 16:15:16 +03:00
|
|
|
}
|
|
|
|
|
2009-02-27 17:37:09 +03:00
|
|
|
return ret;
|
2009-02-25 16:15:16 +03:00
|
|
|
}
|
|
|
|
|
2009-02-27 17:37:09 +03:00
|
|
|
static int start_child_process_with_core(const char* cmd) {
|
2009-02-25 16:15:16 +03:00
|
|
|
struct rlimit r;
|
2009-02-27 17:37:09 +03:00
|
|
|
errno = 0;
|
|
|
|
|
2009-02-25 17:03:00 +03:00
|
|
|
if(getrlimit(RLIMIT_CORE, &r) == -1) {
|
2009-02-27 17:37:09 +03:00
|
|
|
E_WARNING(E_STRLOC ": gerlimit() failed with '%s'\n", strerror(errno));
|
|
|
|
return -1;
|
2009-02-25 17:03:00 +03:00
|
|
|
}
|
2009-02-25 16:15:16 +03:00
|
|
|
|
|
|
|
rlim_t old = r.rlim_cur;
|
|
|
|
r.rlim_cur = RLIM_INFINITY;
|
|
|
|
|
2009-02-25 17:03:00 +03:00
|
|
|
if(setrlimit(RLIMIT_CORE, &r) == -1) {
|
2009-02-27 17:37:09 +03:00
|
|
|
E_WARNING(E_STRLOC ": setrlimit() failed with '%s'\n", strerror(errno));
|
|
|
|
return -1;
|
2009-02-25 17:03:00 +03:00
|
|
|
}
|
2009-02-25 16:15:16 +03:00
|
|
|
|
2009-02-27 17:37:09 +03:00
|
|
|
int ret = start_child_process(cmd);
|
2009-02-25 16:15:16 +03:00
|
|
|
|
|
|
|
r.rlim_cur = old;
|
2009-02-25 17:03:00 +03:00
|
|
|
if(setrlimit(RLIMIT_CORE, &r) == -1) {
|
2009-02-27 17:37:09 +03:00
|
|
|
E_WARNING(E_STRLOC ": setrlimit() failed with '%s'\n", strerror(errno));
|
|
|
|
return -1;
|
2009-02-25 17:03:00 +03:00
|
|
|
}
|
2009-02-27 17:37:09 +03:00
|
|
|
|
|
|
|
return ret;
|
2009-02-25 17:03:00 +03:00
|
|
|
}
|
2009-02-25 16:15:16 +03:00
|
|
|
|
2009-03-05 21:21:37 +03:00
|
|
|
static bool start_child(const char* cmd) {
|
2011-10-24 13:02:36 +04:00
|
|
|
E_DEBUG(E_STRLOC ": Starting '%s'\n", cmd);
|
2011-10-24 16:21:05 +04:00
|
|
|
|
|
|
|
StartupNotify *n = startup_notify_start(cmd, "applications-order");
|
2009-03-05 21:21:37 +03:00
|
|
|
int ret = start_child_process_with_core(cmd);
|
|
|
|
|
2011-10-24 16:21:05 +04:00
|
|
|
startup_notify_end(n);
|
|
|
|
|
2009-03-05 21:21:37 +03:00
|
|
|
if(ret == 199) {
|
2009-07-07 15:57:45 +04:00
|
|
|
alert(_("Program '%s' not found.\n\nPlease check if given path to the "
|
|
|
|
"executable was correct or adjust $PATH environment variable to "
|
|
|
|
"point to the directory where target executable exists"), cmd);
|
|
|
|
|
2009-03-05 21:21:37 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret == EACCES) {
|
2009-03-06 15:12:27 +03:00
|
|
|
/* now check the if file is executable since EACCES is common error if not so */
|
|
|
|
if(access(cmd, X_OK) != 0)
|
|
|
|
alert(_("You are trying to execute '%s', but it is not executable file"), cmd);
|
|
|
|
else
|
|
|
|
alert(_("You do not have enough permissions to execute '%s'"), cmd);
|
|
|
|
|
2009-03-05 21:21:37 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-24 13:02:36 +04:00
|
|
|
static bool start_desktop_file(const char *cmd) {
|
|
|
|
DesktopFile d;
|
|
|
|
|
|
|
|
if(!d.load(cmd)) {
|
2011-10-25 17:48:56 +04:00
|
|
|
alert(_("Unable to load .desktop file '%s'. Got: %s"), cmd, d.strerror());
|
2011-10-24 13:02:36 +04:00
|
|
|
goto FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(d.type() != DESK_FILE_TYPE_APPLICATION) {
|
|
|
|
alert(_("Starting other types of .desktop files except 'Application' is not supported now"));
|
|
|
|
goto FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char buf[PATH_MAX];
|
2011-10-25 18:30:29 +04:00
|
|
|
if(!d.exec(buf, PATH_MAX)) {
|
2011-10-24 13:02:36 +04:00
|
|
|
alert(_("Unable to run '%s'.\nProbably this file is malformed or 'Exec' key has non-installed program"), cmd);
|
2011-10-25 17:48:56 +04:00
|
|
|
goto FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return start_child(buf);
|
2011-10-24 13:02:36 +04:00
|
|
|
|
|
|
|
FAIL:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
/* concat all arguments preparing it for start_child() */
|
|
|
|
static void join_args(int start, int argc, char **argv, const char *program, String &ret) {
|
|
|
|
String args;
|
|
|
|
unsigned int alen;
|
|
|
|
|
|
|
|
/* append program if given */
|
|
|
|
if(program) {
|
|
|
|
args = program;
|
|
|
|
args += ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = start; i < argc; i++) {
|
|
|
|
args += argv[i];
|
|
|
|
args += ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
alen = args.length();
|
|
|
|
|
|
|
|
/* remove start/ending quotes and spaces */
|
|
|
|
if((args[0] == '"') || isspace(args[0]) || (args[alen - 1] == '"') || isspace(args[alen - 1])) {
|
|
|
|
int i;
|
|
|
|
char *copy = strdup(args.c_str());
|
|
|
|
char *ptr = copy;
|
|
|
|
|
|
|
|
/* remove ending first */
|
|
|
|
for(i = (int)alen - 1; i > 0 && (ptr[i] == '"' || isspace(ptr[i])); i--)
|
|
|
|
;
|
|
|
|
|
|
|
|
ptr[i + 1] = 0;
|
|
|
|
|
|
|
|
/* remove then starting */
|
|
|
|
for(; *ptr && (*ptr == '"' || isspace(*ptr)); ptr++)
|
|
|
|
;
|
|
|
|
|
|
|
|
ret = copy;
|
|
|
|
free(copy);
|
|
|
|
} else {
|
|
|
|
ret = args;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-25 17:03:00 +03:00
|
|
|
static void cancel_cb(Fl_Widget*, void* w) {
|
|
|
|
LaunchWindow* win = (LaunchWindow*)w;
|
|
|
|
win->hide();
|
|
|
|
}
|
|
|
|
|
2011-10-22 00:26:19 +04:00
|
|
|
#define RETURN_IF_VALID_TERM(t, r) \
|
|
|
|
do { \
|
|
|
|
if(t && ((strcmp(t, "linux") != 0) || (strcmp(t, "dumb") != 0))) { \
|
|
|
|
r = file_path(t, false); \
|
|
|
|
if(E_UNLIKELY(r.empty())) return true; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
static bool find_terminal(String &ret) {
|
2011-10-25 17:48:56 +04:00
|
|
|
/* before goint to list, try to read it from config file */
|
|
|
|
Resource rc;
|
|
|
|
if(rc.load(EDE_LAUNCH_CONFIG)) {
|
|
|
|
char buf[64];
|
|
|
|
if(rc.get("Preferred", "terminal", buf, sizeof(buf))) {
|
|
|
|
ret = buf;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-22 00:26:19 +04:00
|
|
|
/* list of known terminals */
|
|
|
|
static const char *terms[] = {
|
|
|
|
"xterm",
|
|
|
|
"rxvt",
|
|
|
|
"Terminal",
|
|
|
|
"gnome-terminal",
|
|
|
|
"konsole",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* term = getenv("TERM");
|
|
|
|
|
|
|
|
RETURN_IF_VALID_TERM(term, ret);
|
|
|
|
|
|
|
|
term = getenv("COLORTERM");
|
|
|
|
RETURN_IF_VALID_TERM(term, ret);
|
|
|
|
|
|
|
|
for(int i = 0; terms[i]; i++) {
|
|
|
|
term = terms[i];
|
|
|
|
RETURN_IF_VALID_TERM(term, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-25 17:03:00 +03:00
|
|
|
static void ok_cb(Fl_Widget*, void* w) {
|
|
|
|
LaunchWindow* win = (LaunchWindow*)w;
|
|
|
|
const char* cmd = dialog_input->value();
|
2009-03-05 21:21:37 +03:00
|
|
|
bool started = false;
|
2009-02-27 17:37:09 +03:00
|
|
|
|
2009-02-25 17:03:00 +03:00
|
|
|
win->hide();
|
|
|
|
|
|
|
|
/* do not block dialog when program is starting */
|
|
|
|
Fl::check();
|
|
|
|
|
2009-02-25 17:42:40 +03:00
|
|
|
/* TODO: is 'cmd' safe after hide? */
|
|
|
|
if(in_term->value()) {
|
2009-03-06 15:12:27 +03:00
|
|
|
char buf[128];
|
2011-10-22 00:26:19 +04:00
|
|
|
String term;
|
2009-02-25 17:42:40 +03:00
|
|
|
|
2011-10-22 00:26:19 +04:00
|
|
|
if(find_terminal(term)) {
|
|
|
|
snprintf(buf, sizeof(buf), "%s -e %s", term.c_str(), cmd);
|
|
|
|
started = start_child(buf);
|
|
|
|
} else {
|
|
|
|
E_WARNING(E_STRLOC ": unable to find any suitable terminal\n");
|
|
|
|
}
|
2009-02-25 17:42:40 +03:00
|
|
|
} else {
|
2009-03-05 21:21:37 +03:00
|
|
|
started = start_child(cmd);
|
2009-02-27 17:37:09 +03:00
|
|
|
}
|
|
|
|
|
2009-03-05 21:21:37 +03:00
|
|
|
if(!started) {
|
2009-02-27 17:37:09 +03:00
|
|
|
/* show dialog again */
|
|
|
|
win->show();
|
2009-07-07 15:57:45 +04:00
|
|
|
|
|
|
|
if(cmd)
|
|
|
|
dialog_input->position(0, dialog_input->size());
|
|
|
|
} else {
|
|
|
|
Resource rc;
|
2011-10-25 17:48:56 +04:00
|
|
|
/* so could load previous content */
|
|
|
|
rc.load(EDE_LAUNCH_CONFIG);
|
2009-07-07 15:57:45 +04:00
|
|
|
rc.set("History", "open", cmd);
|
2011-10-25 17:48:56 +04:00
|
|
|
rc.save(EDE_LAUNCH_CONFIG);
|
2009-02-25 17:42:40 +03:00
|
|
|
}
|
2009-02-25 17:03:00 +03:00
|
|
|
}
|
|
|
|
|
2009-07-07 15:57:45 +04:00
|
|
|
static int start_dialog(int argc, char** argv) {
|
2009-02-25 17:42:40 +03:00
|
|
|
LaunchWindow* win = new LaunchWindow(370, 195, _("Run Command"));
|
2009-02-25 17:03:00 +03:00
|
|
|
win->begin();
|
|
|
|
Fl_Box* icon = new Fl_Box(10, 10, 55, 55);
|
|
|
|
icon->image(image_run);
|
|
|
|
|
2010-03-07 17:03:30 +03:00
|
|
|
Fl_Box* txt = new Fl_Box(70, 10, 290, 69, _("Enter the name of the application you would like to run"));
|
2009-02-25 17:03:00 +03:00
|
|
|
txt->align(132|FL_ALIGN_INSIDE);
|
|
|
|
|
|
|
|
dialog_input = new Fl_Input(70, 90, 290, 25, _("Open:"));
|
|
|
|
|
2009-07-07 15:57:45 +04:00
|
|
|
Resource rc;
|
|
|
|
char buf[128];
|
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
if(rc.load(EDE_LAUNCH_CONFIG) && rc.get("History", "open", buf, sizeof(buf))) {
|
2009-07-07 15:57:45 +04:00
|
|
|
dialog_input->value(buf);
|
|
|
|
|
|
|
|
/* make text appear selected */
|
|
|
|
dialog_input->position(0, dialog_input->size());
|
|
|
|
}
|
|
|
|
|
2009-02-25 17:42:40 +03:00
|
|
|
in_term = new Fl_Check_Button(70, 125, 290, 25, _("Run in terminal"));
|
|
|
|
in_term->down_box(FL_DOWN_BOX);
|
|
|
|
|
|
|
|
Fl_Button* ok = new Fl_Button(175, 160, 90, 25, _("&OK"));
|
2009-02-25 17:03:00 +03:00
|
|
|
ok->callback(ok_cb, win);
|
2009-02-25 17:42:40 +03:00
|
|
|
Fl_Button* cancel = new Fl_Button(270, 160, 90, 25, _("&Cancel"));
|
2009-02-25 17:03:00 +03:00
|
|
|
cancel->callback(cancel_cb, win);
|
|
|
|
win->end();
|
2009-07-07 15:57:45 +04:00
|
|
|
win->window_icon(run_xpm);
|
2011-10-25 17:48:56 +04:00
|
|
|
|
2011-10-23 04:10:40 +04:00
|
|
|
window_center_on_screen(win);
|
2009-02-25 17:03:00 +03:00
|
|
|
win->show(argc, argv);
|
|
|
|
|
2009-07-07 15:57:45 +04:00
|
|
|
return Fl::run();
|
2009-02-25 16:15:16 +03:00
|
|
|
}
|
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
#define CHECK_ARGV(argv, pshort, plong) ((strcmp(argv, pshort) == 0) || (strcmp(argv, plong) == 0))
|
|
|
|
|
|
|
|
static const char* next_param(int curr, char **argv, int argc) {
|
|
|
|
int j = curr + 1;
|
|
|
|
if(j >= argc)
|
|
|
|
return NULL;
|
|
|
|
if(argv[j][0] == '-')
|
|
|
|
return NULL;
|
|
|
|
return argv[j];
|
|
|
|
}
|
|
|
|
|
2009-02-25 16:15:16 +03:00
|
|
|
int main(int argc, char** argv) {
|
2010-03-28 16:54:45 +04:00
|
|
|
EDE_APPLICATION("ede-launch");
|
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
/* start dialog if we have nothing */
|
2009-10-03 16:28:41 +04:00
|
|
|
if(argc <= 1)
|
2009-07-07 15:57:45 +04:00
|
|
|
return start_dialog(argc, argv);
|
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
int ca = 1; /* current argument index */
|
|
|
|
const char *cwd, *launch_type;
|
|
|
|
cwd = launch_type = 0;
|
2009-10-03 13:06:05 +04:00
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
/* parse args and stop as soon as detected first non-parameter value (not counting parameter values) */
|
|
|
|
for(; ca < argc; ca++) {
|
|
|
|
if(argv[ca][0] != '-') break;
|
2011-10-24 13:02:36 +04:00
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
if(CHECK_ARGV(argv[ca], "-h", "--help")) {
|
|
|
|
help();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(CHECK_ARGV(argv[ca], "-l", "--launch")) {
|
|
|
|
launch_type = next_param(ca, argv, argc);
|
|
|
|
if(!launch_type) {
|
|
|
|
puts("Missing lauch type. Run program with '-h' to see options");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!allowed_launch_type(launch_type)) {
|
|
|
|
puts("This is not allowed launch type. Run program with '-h' to see options");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ca++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(CHECK_ARGV(argv[ca], "-w", "--working-dir")) {
|
|
|
|
cwd = next_param(ca, argv, argc);
|
|
|
|
if(!cwd) {
|
|
|
|
puts("Missing working directory parameter. Run program with '-h' to see options");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ca++;
|
|
|
|
continue;
|
|
|
|
}
|
2009-10-03 13:06:05 +04:00
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
printf("Bad parameter '%s'. Run program with '-h' to see options\n", argv[ca]);
|
|
|
|
return 1;
|
2009-10-03 16:28:41 +04:00
|
|
|
}
|
2009-10-03 13:06:05 +04:00
|
|
|
|
2011-10-25 18:30:29 +04:00
|
|
|
/* make sure we have something to run but only if --launch isn't used */
|
|
|
|
if(!argv[ca] && !launch_type) {
|
2011-10-25 17:48:56 +04:00
|
|
|
puts("Missing execution parameter(s). Run program with '-h' to see options");
|
|
|
|
return 1;
|
|
|
|
}
|
2009-10-03 13:06:05 +04:00
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
/* setup working dir */
|
|
|
|
if(cwd) {
|
|
|
|
errno = 0;
|
|
|
|
if(chdir(cwd) != 0) {
|
|
|
|
alert(_("Unable to change directory to '%s'. Got '%s' (%i)"), cwd, strerror(errno), errno);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2009-10-03 13:06:05 +04:00
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
/* check if we have .desktop file */
|
2011-10-25 18:30:29 +04:00
|
|
|
if(argv[ca] && str_ends(argv[ca], ".desktop"))
|
2011-10-25 17:48:56 +04:00
|
|
|
return RETURN_FROM_BOOL(start_desktop_file(argv[ca]));
|
2009-10-03 13:06:05 +04:00
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
/* make arguments and exec program */
|
|
|
|
String args;
|
|
|
|
if(launch_type) {
|
|
|
|
Resource rc;
|
|
|
|
char buf[64];
|
2009-10-03 13:06:05 +04:00
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
if(!rc.load(EDE_LAUNCH_CONFIG) || !rc.get("Preferred", launch_type, buf, sizeof(buf))) {
|
|
|
|
E_WARNING("Unable to find out launch type. Balling out...\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2009-10-03 13:06:05 +04:00
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
join_args(ca, argc, argv, buf, args);
|
2009-10-03 16:28:41 +04:00
|
|
|
} else {
|
2011-10-25 17:48:56 +04:00
|
|
|
join_args(ca, argc, argv, 0, args);
|
2009-10-03 13:06:05 +04:00
|
|
|
}
|
2009-02-25 16:15:16 +03:00
|
|
|
|
2011-10-25 17:48:56 +04:00
|
|
|
return RETURN_FROM_BOOL(start_child(args.c_str()));
|
2009-02-25 16:15:16 +03:00
|
|
|
}
|