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 | |
parent | 9d7104735ae1d56d5ef7b7bd82c2ab41c509b569 (diff) |
issue 84
-rw-r--r-- | src/main.c | 41 | ||||
-rw-r--r-- | src/trg-main-window.c | 33 | ||||
-rw-r--r-- | src/trg-main-window.h | 2 | ||||
-rw-r--r-- | src/trg-torrent-add-dialog.c | 2 |
4 files changed, 60 insertions, 18 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(); diff --git a/src/trg-main-window.c b/src/trg-main-window.c index f92b4e7..e143f65 100644 --- a/src/trg-main-window.c +++ b/src/trg-main-window.c @@ -207,12 +207,23 @@ struct _TrgMainWindowPrivate { guint timerId; gboolean min_on_start; gboolean queuesEnabled; + + gchar **args; }; enum { PROP_0, PROP_CLIENT, PROP_MINIMISE_ON_START }; +static void reset_connect_args(TrgMainWindow * win) +{ + TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); + if (priv->args) { + g_strfreev(priv->args); + priv->args = NULL; + } +} + static void trg_main_window_init(TrgMainWindow * self G_GNUC_UNUSED) { } @@ -411,6 +422,8 @@ gboolean trg_add_from_filename(TrgMainWindow * win, gchar ** uris) { g_free(uris); // launch_add_thread() or trg_torrent_add_dialog() will free the filenames and fileList; + priv->args = NULL; + return TRUE; } @@ -786,6 +799,7 @@ static gboolean on_session_get(gpointer data) { if (trg_dialog_error_handler(win, response) == TRUE) { trg_response_free(response); + reset_connect_args(win); return FALSE; } @@ -805,6 +819,7 @@ static gboolean on_session_get(gpointer data) { gtk_widget_destroy(dialog); g_free(msg); trg_response_free(response); + reset_connect_args(win); return FALSE; } @@ -819,8 +834,11 @@ static gboolean on_session_get(gpointer data) { json_object_ref(newSession); - if (!isConnected) + if (!isConnected) { dispatch_async(client, torrent_get(-1), on_torrent_get_first, win); + if (priv->args) + trg_add_from_filename(win, priv->args); + } trg_response_free(response); @@ -2058,8 +2076,9 @@ static void trg_main_window_class_init(TrgMainWindowClass * klass) { | G_PARAM_STATIC_BLURB)); } -void auto_connect_if_required(TrgMainWindow * win, TrgClient * tc) { - TrgPrefs *prefs = trg_client_get_prefs(tc); +void auto_connect_if_required(TrgMainWindow * win, gchar **args) { + TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); + TrgPrefs *prefs = trg_client_get_prefs(priv->client); gchar *host = trg_prefs_get_string(prefs, TRG_PREFS_KEY_HOSTNAME, TRG_PREFS_PROFILE); @@ -2067,9 +2086,15 @@ void auto_connect_if_required(TrgMainWindow * win, TrgClient * tc) { gint len = strlen(host); g_free(host); if (len > 0 && trg_prefs_get_bool(prefs, TRG_PREFS_KEY_AUTO_CONNECT, - TRG_PREFS_PROFILE)) + TRG_PREFS_PROFILE)) { + priv->args = args; connect_cb(NULL, win); + return; + } } + + if (args) + g_strfreev(args); } TrgMainWindow *trg_main_window_new(TrgClient * tc, gboolean minonstart) { diff --git a/src/trg-main-window.h b/src/trg-main-window.h index ac19fba..4a1fd5d 100644 --- a/src/trg-main-window.h +++ b/src/trg-main-window.h @@ -60,7 +60,7 @@ GType trg_main_window_get_type(void); gboolean trg_add_from_filename(TrgMainWindow * win, gchar ** uris); gboolean on_session_set(gpointer data); gboolean on_generic_interactive_action(gpointer data); -void auto_connect_if_required(TrgMainWindow * win, TrgClient * tc); +void auto_connect_if_required(TrgMainWindow * win, gchar **args); TrgMainWindow *trg_main_window_new(TrgClient * tc, gboolean minonstart); void trg_main_window_add_status_icon(TrgMainWindow * win); void trg_main_window_remove_status_icon(TrgMainWindow * win); diff --git a/src/trg-torrent-add-dialog.c b/src/trg-torrent-add-dialog.c index 522d8ee..2e8ccf9 100644 --- a/src/trg-torrent-add-dialog.c +++ b/src/trg-torrent-add-dialog.c @@ -706,7 +706,7 @@ static void torrent_not_found_error(GtkWindow * parent, gchar *file) gtk_message_dialog_new(parent, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _ - ("Unable to find torrent file: %s"), file); + ("Unable to open torrent file: %s"), file); gtk_window_set_transient_for(GTK_WINDOW(dialog), parent); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); |