diff options
author | Alan Fitton <ajf@eth0.org.uk> | 2011-10-04 10:55:17 +0000 |
---|---|---|
committer | Alan Fitton <ajf@eth0.org.uk> | 2011-10-04 10:55:17 +0000 |
commit | c3bd3ac55162a88b308a6f700aad88d26cbd5f29 (patch) | |
tree | 9558525a985af6c3e2b2d390de05e6a4a5ca7f98 /src/main.c | |
parent | 9d7104735ae1d56d5ef7b7bd82c2ab41c509b569 (diff) |
issue 84
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 41 |
1 files changed, 29 insertions, 12 deletions
@@ -36,6 +36,7 @@ #include "trg-main-window.h" #include "trg-client.h" +#include "util.h" #ifdef HAVE_LIBUNIQUE @@ -91,11 +92,35 @@ static gboolean should_be_minimised(int argc, char *argv[]) return FALSE; } +static gchar **convert_args(int argc, char *argv[]) +{ + gchar *cwd = g_get_current_dir (); + gchar **files = NULL; + int i; + if (argc > 1) { + files = g_new0(gchar *, argc); + for (i = 1; i < argc; i++) { + if (!is_url(argv[i]) && !is_magnet(argv[i]) + && g_file_test(argv[i], G_FILE_TEST_IS_REGULAR) + && !g_path_is_absolute(argv[i])) { + files[i - 1] = g_build_path(G_DIR_SEPARATOR_S, cwd, argv[i], NULL); + } else { + files[i - 1] = g_strdup(argv[i]); + } + } + } + + g_free(cwd); + + return files; +} + int main(int argc, char *argv[]) { int returnValue = EXIT_SUCCESS; TrgMainWindow *window; TrgClient *client; + gchar **args = convert_args(argc, argv); #ifdef HAVE_LIBUNIQUE UniqueApp *app = NULL; gboolean withUnique; @@ -127,19 +152,11 @@ int main(int argc, char *argv[]) UniqueResponse response; UniqueMessageData *message; - if (argc > 1) { - /* Turn the arguments into a null terminated array for libunique - * exclude the first (executable name). - */ - gchar **files = g_new0(gchar *, argc); - int i; - for (i = 1; i < argc; i++) - files[i - 1] = argv[i]; - + if (args) { command = COMMAND_ADD; message = unique_message_data_new(); - unique_message_data_set_uris(message, files); - g_free(files); + unique_message_data_set_uris(message, args); + g_strfreev(args); } else { command = UNIQUE_ACTIVATE; message = NULL; @@ -166,7 +183,7 @@ int main(int argc, char *argv[]) } #endif - auto_connect_if_required(window, client); + auto_connect_if_required(window, args); gtk_main(); curl_global_cleanup(); |