summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Alan Fitton <ajf@eth0.org.uk>2011-10-19 17:32:46 +0000
committerGravatar Alan Fitton <ajf@eth0.org.uk>2011-10-19 17:32:46 +0000
commita04430bff79030690add518548677251816e3e71 (patch)
treecbc567bf9c2e6b44df87ab0b8f7c2889c5b5e0f3 /src
parentee516bb3b42f42a1880de7b943c0e17a97da48ae (diff)
issue 155
Diffstat (limited to 'src')
-rw-r--r--src/remote-exec.c12
-rw-r--r--src/remote-exec.h3
-rw-r--r--src/trg-client.c28
-rw-r--r--src/trg-client.h2
-rw-r--r--src/trg-main-window.c7
-rw-r--r--src/trg-preferences-dialog.c2
6 files changed, 44 insertions, 10 deletions
diff --git a/src/remote-exec.c b/src/remote-exec.c
index 75c1d10..d8041c7 100644
--- a/src/remote-exec.c
+++ b/src/remote-exec.c
@@ -22,6 +22,8 @@
#include <json-glib/json-glib.h>
#include "trg-torrent-model.h"
+#include "trg-client.h"
+#include "trg-prefs.h"
#include "protocol-constants.h"
#include "torrent.h"
@@ -81,15 +83,19 @@ static gchar *dump_json_value(JsonNode * node) {
return g_string_free(buffer, FALSE);
}
-gchar *build_remote_exec_cmd(TrgPrefs *prefs, GtkTreeModel *model, GList *selection,
+gchar *build_remote_exec_cmd(TrgClient *tc, GtkTreeModel *model, GList *selection,
const gchar * input) {
- JsonObject *profile = trg_prefs_get_profile(prefs);
- gchar *work = g_strdup(input);
+ JsonObject *profile = trg_client_get_current_profile(tc);
+ gchar *work;
GRegex *regex, *replacerx;
GMatchInfo *match_info;
gchar *whole, *wholeEscaped, *id, *tmp, *valuestr, *repeater;
JsonNode *replacement;
+ if (!profile)
+ return NULL;
+
+ work = g_strdup(input);
regex = g_regex_new("%{([A-Za-z\\-]+)}(?:\\[(.*)\\])?", 0, 0, NULL);
g_regex_match_full(regex, input, -1, 0, 0, &match_info, NULL);
diff --git a/src/remote-exec.h b/src/remote-exec.h
index 864f8b5..4f8c52e 100644
--- a/src/remote-exec.h
+++ b/src/remote-exec.h
@@ -20,6 +20,7 @@
#ifndef REMOTE_EXEC_H_
#define REMOTE_EXEC_H_
-gchar *build_remote_exec_cmd(TrgPrefs *prefs, GtkTreeModel *model, GList *selection, const gchar * input);
+gchar *build_remote_exec_cmd(TrgClient *tc, GtkTreeModel *model, GList *selection,
+ const gchar * input);
#endif /* REMOTE_EXEC_H_ */
diff --git a/src/trg-client.c b/src/trg-client.c
index 7e06189..481156c 100644
--- a/src/trg-client.c
+++ b/src/trg-client.c
@@ -60,6 +60,7 @@ struct _TrgClientPrivate {
guint min_interval;
gint64 updateSerial;
JsonObject *session;
+ JsonObject *currentProfile;
gboolean ssl;
float version;
char *url;
@@ -196,6 +197,12 @@ TrgPrefs *trg_client_get_prefs(TrgClient *tc)
return priv->prefs;
}
+JsonObject *trg_client_get_current_profile(TrgClient *tc)
+{
+ TrgClientPrivate *priv = TRG_CLIENT_GET_PRIVATE(tc);
+ return priv->currentProfile;
+}
+
int trg_client_populate_with_settings(TrgClient * tc)
{
TrgClientPrivate *priv = TRG_CLIENT_GET_PRIVATE(tc);
@@ -262,6 +269,8 @@ int trg_client_populate_with_settings(TrgClient * tc)
trg_prefs_get_bool(prefs,
TRG_PREFS_KEY_UPDATE_ACTIVE_ONLY, TRG_PREFS_PROFILE);
+ priv->currentProfile = trg_prefs_get_profile(prefs);
+
#ifdef HAVE_LIBPROXY
if ((pf = px_proxy_factory_new())) {
char **proxies = px_proxy_factory_get_proxies(pf, priv->url);
@@ -328,9 +337,12 @@ void trg_client_status_change(TrgClient *tc, gboolean connected)
{
TrgClientPrivate *priv = TRG_CLIENT_GET_PRIVATE(tc);
- if (!connected && priv->session) {
- json_object_unref(priv->session);
- priv->session = NULL;
+ if (!connected) {
+ if (priv->session) {
+ json_object_unref(priv->session);
+ priv->session = NULL;
+ }
+ priv->currentProfile = NULL;
}
}
@@ -340,6 +352,16 @@ JsonObject* trg_client_get_session(TrgClient *tc)
return priv->session;
}
+void trg_client_del_profile(TrgClient *tc, JsonObject *profile)
+{
+ TrgClientPrivate *priv = TRG_CLIENT_GET_PRIVATE(tc);
+
+ if (profile == priv->currentProfile)
+ priv->currentProfile = NULL;
+
+ trg_prefs_del_profile(priv->prefs, profile);
+}
+
void trg_client_thread_pool_push(TrgClient *tc, gpointer data, GError **err)
{
TrgClientPrivate *priv = TRG_CLIENT_GET_PRIVATE(tc);
diff --git a/src/trg-client.h b/src/trg-client.h
index 4ef93f9..f89d695 100644
--- a/src/trg-client.h
+++ b/src/trg-client.h
@@ -170,6 +170,8 @@ void trg_client_set_interval(TrgClient *tc, guint interval);
void trg_client_set_minimised_interval(TrgClient *tc, guint interval);
void trg_client_set_activeonlyupdate(TrgClient *tc, gboolean activeOnlyUpdate);
void trg_client_inc_connid(TrgClient *tc);
+JsonObject *trg_client_get_current_profile(TrgClient *tc);
+void trg_client_del_profile(TrgClient *tc, JsonObject *profile);
G_END_DECLS
diff --git a/src/trg-main-window.c b/src/trg-main-window.c
index 124f915..20a9df7 100644
--- a/src/trg-main-window.c
+++ b/src/trg-main-window.c
@@ -1501,7 +1501,6 @@ static GtkWidget *limit_menu_new(TrgMainWindow * win, gchar * title,
static void exec_cmd_cb(GtkWidget *w, gpointer data) {
TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data);
- TrgPrefs *prefs = trg_client_get_prefs(priv->client);
JsonObject *cmd_obj = (JsonObject*) g_object_get_data(G_OBJECT(w),
"cmd-object");
GtkTreeSelection *selection = gtk_tree_view_get_selection(
@@ -1512,13 +1511,17 @@ static void exec_cmd_cb(GtkWidget *w, gpointer data) {
gchar *cmd_line, **argv;
cmd_line = build_remote_exec_cmd(
- prefs,
+ priv->client,
model,
selectedRows,
json_object_get_string_member(cmd_obj,
TRG_PREFS_KEY_EXEC_COMMANDS_SUBKEY_CMD));
+
g_debug("Exec: %s",cmd_line);
+ if (!cmd_line)
+ return;
+
//GTK has bug, won't let you pass a string here containing a quoted param, so use parse and then spawn
// rather than g_spawn_command_line_async(cmd_line,&cmd_error);
diff --git a/src/trg-preferences-dialog.c b/src/trg-preferences-dialog.c
index 4b0cd57..e72febe 100644
--- a/src/trg-preferences-dialog.c
+++ b/src/trg-preferences-dialog.c
@@ -529,7 +529,7 @@ static void del_profile_cb(GtkWidget *w, gpointer data) {
if (gtk_combo_box_get_active_iter(combo, &iter)) {
gtk_tree_model_get(profileModel, &iter, 0, &profile, -1);
- trg_prefs_del_profile(prefs, profile);
+ trg_client_del_profile(priv->client, profile);
trg_prefs_set_profile(prefs, NULL);
gtk_list_store_remove(GTK_LIST_STORE(profileModel), &iter);
gtk_combo_box_set_active(combo, 0);