summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alan Fitton <ajf@eth0.org.uk>2011-02-12 11:51:23 +0000
committerGravatar Alan Fitton <ajf@eth0.org.uk>2011-02-12 11:51:23 +0000
commit2d989e3e693f41f654f56972bc3c742828f409b6 (patch)
tree2c2124594342c47cf113e2bb40dfda5b85469516
parent78b168dbc30d9540b96254b77cfeaef3619b540c (diff)
torrent added notifications, make notifications configurable. unref id arrays if the user cancels an action.
-rw-r--r--src/transmission-remote-gtk.schemas26
-rw-r--r--src/trg-about-window.c2
-rw-r--r--src/trg-main-window.c43
-rw-r--r--src/trg-preferences-dialog.c28
-rw-r--r--src/trg-preferences.h2
-rw-r--r--src/trg-torrent-model.c19
-rw-r--r--src/trg-torrent-model.h3
7 files changed, 104 insertions, 19 deletions
diff --git a/src/transmission-remote-gtk.schemas b/src/transmission-remote-gtk.schemas
index a4df4e0..81b6fc6 100644
--- a/src/transmission-remote-gtk.schemas
+++ b/src/transmission-remote-gtk.schemas
@@ -41,6 +41,32 @@
</schema>
<schema>
+ <key>/schemas/apps/transmission-remote-gtk/add-notify</key>
+ <applyto>/apps/transmission-remote-gtk/add-notify</applyto>
+ <owner>transmission-remote-gtk</owner>
+ <type>bool</type>
+ <default>0</default>
+
+ <locale name="C">
+ <short>Added notifications</short>
+ <long>Added notifications</long>
+ </locale>
+ </schema>
+
+ <schema>
+ <key>/schemas/apps/transmission-remote-gtk/complete-notify</key>
+ <applyto>/apps/transmission-remote-gtk/complete-notify</applyto>
+ <owner>transmission-remote-gtk</owner>
+ <type>bool</type>
+ <default>0</default>
+
+ <locale name="C">
+ <short>Complete notifications</short>
+ <long>Complete notifications</long>
+ </locale>
+ </schema>
+
+ <schema>
<key>/schemas/apps/transmission-remote-gtk/system-tray</key>
<applyto>/apps/transmission-remote-gtk/system-tray</applyto>
<owner>transmission-remote-gtk</owner>
diff --git a/src/trg-about-window.c b/src/trg-about-window.c
index d869cea..49eaca3 100644
--- a/src/trg-about-window.c
+++ b/src/trg-about-window.c
@@ -62,7 +62,7 @@ GtkWidget *trg_about_window_new(GtkWindow * parent)
gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(dialog),
PACKAGE_VERSION);
gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(dialog),
- "(C) 2011 Alan F");
+ "(C) 2011 Alan Fitton");
gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(dialog),
"A remote client to transmission-daemon.");
/* Set the license text, which is usually loaded from a file. Also, set the
diff --git a/src/trg-main-window.c b/src/trg-main-window.c
index 547fd39..1c8adc2 100644
--- a/src/trg-main-window.c
+++ b/src/trg-main-window.c
@@ -196,8 +196,9 @@ static void response_unref(JsonObject * response)
json_object_unref(response);
}
-static void on_torrent_completed(TrgTorrentModel * model,
- GtkTreeIter * iter, gpointer * data)
+static void torrent_event_notification(TrgTorrentModel * model,
+ gchar *icon, gchar *desc, gint tmout,
+ gchar *prefKey, GtkTreeIter * iter, gpointer * data)
{
TrgMainWindowPrivate *priv;
gchar *name;
@@ -209,14 +210,16 @@ static void on_torrent_completed(TrgTorrentModel * model,
|| !gtk_status_icon_is_embedded(priv->statusIcon))
return;
+ if (!gconf_client_get_bool(priv->client->gconf, prefKey, NULL))
+ return;
+
gtk_tree_model_get(GTK_TREE_MODEL(model), iter,
TORRENT_COLUMN_NAME, &name, -1);
notify =
notify_notification_new(name,
- "This torrent has finished downloading",
- GTK_STOCK_APPLY
-/* the fourth argument was removed in libnotify 0.7.0 */
+ desc,
+ icon
#if !defined(NOTIFY_VERSION_MINOR) || (NOTIFY_VERSION_MAJOR == 0 && NOTIFY_VERSION_MINOR < 7)
, NULL
#endif
@@ -227,13 +230,27 @@ static void on_torrent_completed(TrgTorrentModel * model,
#endif
notify_notification_set_urgency(notify, NOTIFY_URGENCY_LOW);
- notify_notification_set_timeout(notify, 8000);
+ notify_notification_set_timeout(notify, tmout);
g_free(name);
notify_notification_show(notify, NULL);
}
+static void on_torrent_completed(TrgTorrentModel * model,
+ GtkTreeIter * iter, gpointer * data)
+{
+ torrent_event_notification(model, GTK_STOCK_APPLY, "This torrent has completed.",
+ 8000, TRG_GCONF_KEY_COMPLETE_NOTIFY, iter, data);
+}
+
+static void on_torrent_added(TrgTorrentModel * model,
+ GtkTreeIter * iter, gpointer * data)
+{
+ torrent_event_notification(model, GTK_STOCK_ADD, "This torrent has been added.",
+ 3000, TRG_GCONF_KEY_ADD_NOTIFY, iter, data);
+}
+
static gboolean delete_event(GtkWidget * w,
GdkEvent * event G_GNUC_UNUSED,
gpointer * data G_GNUC_UNUSED)
@@ -616,6 +633,8 @@ static void remove_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data)
torrent_remove(ids,
FALSE),
on_generic_interactive_action, data);
+ else
+ json_array_unref(ids);
}
static void delete_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data)
@@ -639,6 +658,8 @@ static void delete_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data)
torrent_remove(ids,
TRUE),
on_generic_interactive_action, data);
+ else
+ json_array_unref(ids);
}
static
@@ -710,14 +731,14 @@ void on_session_set(JsonObject * response, int status, gpointer data)
{
TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data);
+ if (status == CURLE_OK || status == FAIL_RESPONSE_UNSUCCESSFUL)
+ dispatch_async(priv->client, session_get(), on_session_get, data);
+
gdk_threads_enter();
trg_dialog_error_handler(TRG_MAIN_WINDOW(data), response, status);
gdk_threads_leave();
response_unref(response);
-
- if (status == CURLE_OK || status == FAIL_RESPONSE_UNSUCCESSFUL)
- dispatch_async(priv->client, session_get(), on_session_get, data);
}
static void on_session_get(JsonObject * response, int status,
@@ -1256,7 +1277,7 @@ static GtkWidget *limit_menu_new(TrgMainWindow *win, gchar *title, gchar *enable
g_strdup(speedKey), g_free);
g_object_set_data_full(G_OBJECT(menu), "enabledKey",
g_strdup(enabledKey), g_free);
- g_object_set_data(G_OBJECT(menu), "limit-ids", ids);
+ g_object_set_data_full(G_OBJECT(menu), "limit-ids", ids, (GDestroyNotify)json_array_unref);
item = gtk_check_menu_item_new_with_label("No Limit");
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), limit < 0);
@@ -1500,6 +1521,8 @@ static GObject *trg_main_window_constructor(GType type,
priv->torrentModel = trg_torrent_model_new();
g_signal_connect(priv->torrentModel, "torrent-completed",
G_CALLBACK(on_torrent_completed), self);
+ g_signal_connect(priv->torrentModel, "torrent-added",
+ G_CALLBACK(on_torrent_added), self);
priv->filteredTorrentModel =
gtk_tree_model_filter_new(GTK_TREE_MODEL(priv->torrentModel),
diff --git a/src/trg-preferences-dialog.c b/src/trg-preferences-dialog.c
index e94f5c8..a597f38 100644
--- a/src/trg-preferences-dialog.c
+++ b/src/trg-preferences-dialog.c
@@ -196,7 +196,7 @@ static GtkWidget *new_entry(GConfClient * gconf, const char *key)
static GtkWidget *trg_prefs_desktopPage(GConfClient * gconf)
{
- GtkWidget *tray, *tray_min, *t;
+ GtkWidget *tray, *w, *t;
gint row = 0;
t = hig_workarea_create();
@@ -207,14 +207,32 @@ static GtkWidget *trg_prefs_desktopPage(GConfClient * gconf)
TRG_GCONF_KEY_SYSTEM_TRAY);
hig_workarea_add_wide_control(t, &row, tray);
- tray_min = new_check_button(gconf, "Minimise to system tray",
+ w = new_check_button(gconf, "Minimise to system tray",
TRG_GCONF_KEY_SYSTEM_TRAY_MINIMISE);
- gtk_widget_set_sensitive(tray_min,
+ gtk_widget_set_sensitive(w,
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
(tray)));
g_signal_connect(G_OBJECT(tray), "toggled",
- G_CALLBACK(toggle_active_arg_is_sensitive), tray_min);
- hig_workarea_add_wide_control(t, &row, tray_min);
+ G_CALLBACK(toggle_active_arg_is_sensitive), w);
+ hig_workarea_add_wide_control(t, &row, w);
+
+ w = new_check_button(gconf, "Torrent added notifications",
+ TRG_GCONF_KEY_ADD_NOTIFY);
+ gtk_widget_set_sensitive(w,
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
+ (tray)));
+ g_signal_connect(G_OBJECT(tray), "toggled",
+ G_CALLBACK(toggle_active_arg_is_sensitive), w);
+ hig_workarea_add_wide_control(t, &row, w);
+
+ w = new_check_button(gconf, "Torrent complete notifications",
+ TRG_GCONF_KEY_COMPLETE_NOTIFY);
+ gtk_widget_set_sensitive(w,
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
+ (tray)));
+ g_signal_connect(G_OBJECT(tray), "toggled",
+ G_CALLBACK(toggle_active_arg_is_sensitive), w);
+ hig_workarea_add_wide_control(t, &row, w);
return t;
}
diff --git a/src/trg-preferences.h b/src/trg-preferences.h
index bb52bca..d2a53a4 100644
--- a/src/trg-preferences.h
+++ b/src/trg-preferences.h
@@ -26,6 +26,8 @@
#define TRG_GCONF_KEY_PASSWORD "/apps/transmission-remote-gtk/password"
#define TRG_GCONF_KEY_AUTO_CONNECT "/apps/transmission-remote-gtk/auto-connect"
#define TRG_GCONF_KEY_SSL "/apps/transmission-remote-gtk/ssl"
+#define TRG_GCONF_KEY_COMPLETE_NOTIFY "/apps/transmission-remote-gtk/complete-notify"
+#define TRG_GCONF_KEY_ADD_NOTIFY "/apps/transmission-remote-gtk/add-notify"
#define TRG_GCONF_KEY_WINDOW_WIDTH "/apps/transmission-remote-gtk/window-width"
#define TRG_GCONF_KEY_WINDOW_HEIGHT "/apps/transmission-remote-gtk/window-height"
#define TRG_GCONF_KEY_SYSTEM_TRAY "/apps/transmission-remote-gtk/system-tray"
diff --git a/src/trg-torrent-model.c b/src/trg-torrent-model.c
index cc58750..a3c9398 100644
--- a/src/trg-torrent-model.c
+++ b/src/trg-torrent-model.c
@@ -32,6 +32,7 @@
enum {
TMODEL_TORRENT_COMPLETED,
+ TMODEL_TORRENT_ADDED,
TMODEL_SIGNAL_COUNT
};
@@ -69,6 +70,14 @@ static void trg_torrent_model_class_init(TrgTorrentModelClass * klass)
NULL, g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER);
+ signals[TMODEL_TORRENT_ADDED] =
+ g_signal_new("torrent-added",
+ G_TYPE_FROM_CLASS(object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET(TrgTorrentModelClass,
+ torrent_added), NULL,
+ NULL, g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
}
static void trg_torrent_model_count_peers(TrgTorrentModel * model,
@@ -316,10 +325,14 @@ void trg_torrent_model_update(TrgTorrentModel * model, trg_client * tc,
t = json_array_get_object_element(newTorrents, i);
if (first == TRUE
- || find_existing_torrent_item(model, t, &iter) == FALSE)
+ || find_existing_torrent_item(model, t, &iter) == FALSE) {
gtk_list_store_append(GTK_LIST_STORE(model), &iter);
-
- update_torrent_iter(tc->updateSerial, model, &iter, t, stats);
+ update_torrent_iter(tc->updateSerial, model, &iter, t, stats);
+ if (!first)
+ g_signal_emit(model, signals[TMODEL_TORRENT_ADDED], 0, &iter);
+ } else {
+ update_torrent_iter(tc->updateSerial, model, &iter, t, stats);
+ }
}
json_array_ref(newTorrents);
diff --git a/src/trg-torrent-model.h b/src/trg-torrent-model.h
index dd08588..962a2f0 100644
--- a/src/trg-torrent-model.h
+++ b/src/trg-torrent-model.h
@@ -47,6 +47,9 @@ typedef struct {
void (*torrent_completed) (TrgTorrentModel * model,
GtkTreeIter * iter, JsonObject * t,
gpointer data);
+ void (*torrent_added) (TrgTorrentModel * model,
+ GtkTreeIter * iter, JsonObject * t,
+ gpointer data);
} TrgTorrentModelClass;
typedef struct {