Changeset 13626
- Timestamp:
- Dec 5, 2012, 9:26:40 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gtk/notify.c
r13625 r13626 31 31 typedef struct _TrNotification 32 32 { 33 guint id; 34 TrCore * core; 35 int torrent_id; 36 } TrNotification; 33 guint id; 34 TrCore * core; 35 int torrent_id; 36 } 37 TrNotification; 37 38 38 39 static void 39 40 tr_notification_free (gpointer data) 40 41 { 41 TrNotification * n = data; 42 if (n->core) 43 g_object_unref (G_OBJECT (n->core)); 44 g_free (n); 42 TrNotification * n = data; 43 44 if (n->core) 45 g_object_unref (G_OBJECT (n->core)); 46 47 g_free (n); 45 48 } 46 49 … … 50 53 gpointer user_data UNUSED) 51 54 { 52 GVariant *result; 53 char **caps; 54 int i; 55 56 result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), res, NULL); 57 if (!result || !g_variant_is_of_type (result, G_VARIANT_TYPE (" (as)"))) 58 { 59 if (result) 60 g_variant_unref (result); 61 return; 62 } 63 64 g_variant_get (result, " (^a&s)", &caps); 65 for (i = 0; caps[i]; i++) 66 { 67 if (strcmp (caps[i], "actions") == 0) 68 { 69 server_supports_actions = TRUE; 70 break; 71 } 72 } 73 g_free (caps); 74 g_variant_unref (result); 55 int i; 56 char ** caps; 57 GVariant * result; 58 59 result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), res, NULL); 60 if (!result || !g_variant_is_of_type (result, G_VARIANT_TYPE ("(as)"))) 61 { 62 if (result) 63 g_variant_unref (result); 64 return; 65 } 66 67 g_variant_get (result, "(^a&s)", &caps); 68 for (i=0; caps[i]; i++) 69 { 70 if (strcmp (caps[i], "actions") == 0) 71 { 72 server_supports_actions = TRUE; 73 break; 74 } 75 } 76 77 g_free (caps); 78 g_variant_unref (result); 75 79 } 76 80 … … 82 86 gpointer user_data UNUSED) 83 87 { 84 TrNotification * n; 85 guint id; 86 87 g_return_if_fail (g_variant_is_of_type (params, G_VARIANT_TYPE (" (u*)"))); 88 89 g_variant_get (params, " (u*)", &id, NULL); 90 n = g_hash_table_lookup (active_notifications, 91 GINT_TO_POINTER ((int *) &id)); 92 if (n == NULL) 88 guint id; 89 TrNotification * n; 90 91 g_return_if_fail (g_variant_is_of_type (params, G_VARIANT_TYPE ("(u*)"))); 92 93 g_variant_get (params, "(u*)", &id, NULL); 94 n = g_hash_table_lookup (active_notifications, 95 GINT_TO_POINTER ((int *) &id)); 96 if (n == NULL) 97 return; 98 99 if (strcmp (signal_name, "NotificationClosed") == 0) 100 { 101 g_hash_table_remove (active_notifications, 102 GINT_TO_POINTER ((int *) &n->id)); 103 } 104 else if (strcmp (signal_name, "ActionInvoked") == 0 && 105 g_variant_is_of_type (params, G_VARIANT_TYPE ("(us)"))) 106 { 107 char * action; 108 tr_torrent * tor; 109 110 tor = gtr_core_find_torrent (n->core, n->torrent_id); 111 if (tor == NULL) 93 112 return; 94 113 95 if (strcmp (signal_name, "NotificationClosed") == 0) 96 { 97 g_hash_table_remove (active_notifications, 98 GINT_TO_POINTER ((int *) &n->id)); 99 } 100 else if (strcmp (signal_name, "ActionInvoked") == 0 && 101 g_variant_is_of_type (params, G_VARIANT_TYPE (" (us)"))) 102 { 103 char * action; 104 tr_torrent * tor; 105 106 tor = gtr_core_find_torrent (n->core, n->torrent_id); 107 if (tor == NULL) 108 return; 109 110 g_variant_get (params, " (u&s)", NULL, &action); 111 if (strcmp (action, "folder") == 0) 112 { 113 gtr_core_open_folder (n->core, n->torrent_id); 114 } 115 else if (strcmp (action, "file") == 0) 116 { 117 const tr_info * inf = tr_torrentInfo (tor); 118 const char * dir = tr_torrentGetDownloadDir (tor); 119 char * path = g_build_filename (dir, inf->files[0].name, NULL); 120 gtr_open_file (path); 121 g_free (path); 114 g_variant_get (params, "(u&s)", NULL, &action); 115 if (strcmp (action, "folder") == 0) 116 { 117 gtr_core_open_folder (n->core, n->torrent_id); 118 } 119 else if (strcmp (action, "file") == 0) 120 { 121 const tr_info * inf = tr_torrentInfo (tor); 122 const char * dir = tr_torrentGetDownloadDir (tor); 123 char * path = g_build_filename (dir, inf->files[0].name, NULL); 124 gtr_open_file (path); 125 g_free (path); 122 126 } 123 127 } … … 129 133 gpointer user_data UNUSED) 130 134 { 131 132 133 { 134 135 136 } 137 138 139 140 141 142 143 144 135 proxy = g_dbus_proxy_new_for_bus_finish (res, NULL); 136 if (proxy == NULL) 137 { 138 g_warning ("Failed to create proxy for %s", NOTIFICATIONS_DBUS_NAME); 139 return; 140 } 141 142 g_signal_connect (proxy, "g-signal", 143 G_CALLBACK (g_signal_callback), NULL); 144 g_dbus_proxy_call (proxy, 145 "GetCapabilities", 146 g_variant_new ("()"), 147 G_DBUS_CALL_FLAGS_NONE, -1, NULL, 148 get_capabilities_callback, NULL); 145 149 } 146 150 … … 148 152 gtr_notify_init (void) 149 153 { 150 151 152 153 154 155 156 157 158 154 active_notifications = g_hash_table_new_full (g_int_hash, g_int_equal, 155 NULL, tr_notification_free); 156 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, 157 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, 158 NULL, 159 NOTIFICATIONS_DBUS_NAME, 160 NOTIFICATIONS_DBUS_CORE_OBJECT, 161 NOTIFICATIONS_DBUS_CORE_INTERFACE, 162 NULL, dbus_proxy_ready_callback, NULL); 159 163 } 160 164 … … 164 168 gpointer user_data) 165 169 { 166 TrNotification * n = user_data;167 GVariant * result;168 169 170 if (!result || !g_variant_is_of_type (result, G_VARIANT_TYPE ("(u)")))171 { 172 173 174 175 176 } 177 178 g_variant_get (result, "(u)", &n->id);179 180 181 182 170 GVariant * result; 171 TrNotification * n = user_data; 172 173 result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), res, NULL); 174 if (!result || !g_variant_is_of_type (result, G_VARIANT_TYPE ("(u)"))) 175 { 176 if (result) 177 g_variant_unref (result); 178 tr_notification_free (n); 179 return; 180 } 181 182 g_variant_get (result, "(u)", &n->id); 183 g_hash_table_insert (active_notifications, 184 GINT_TO_POINTER ((int *)&n->id), n); 185 186 g_variant_unref (result); 183 187 } 184 188 … … 186 190 gtr_notify_torrent_completed (TrCore * core, int torrent_id) 187 191 { 188 189 190 191 192 193 194 195 196 if (!gtr_pref_flag_get (PREF_KEY_TORRENT_COMPLETE_NOTIFICATION_ENABLED))197 198 199 200 201 202 203 204 205 206 207 208 209 210 { 211 212 213 { 214 215 216 } 217 218 { 219 220 221 } 222 } 223 224 225 226 227 228 229 230 231 232 192 GVariantBuilder actions_builder; 193 TrNotification * n; 194 tr_torrent * tor; 195 const char * cmd = gtr_pref_string_get (PREF_KEY_TORRENT_COMPLETE_SOUND_COMMAND); 196 197 if (gtr_pref_flag_get (PREF_KEY_TORRENT_COMPLETE_SOUND_ENABLED)) 198 g_spawn_command_line_async (cmd, NULL); 199 200 if (!gtr_pref_flag_get (PREF_KEY_TORRENT_COMPLETE_NOTIFICATION_ENABLED)) 201 return; 202 203 g_return_if_fail (G_IS_DBUS_PROXY (proxy)); 204 205 tor = gtr_core_find_torrent (core, torrent_id); 206 207 n = g_new0 (TrNotification, 1); 208 n->core = g_object_ref (G_OBJECT (core)); 209 n->torrent_id = torrent_id; 210 211 g_variant_builder_init (&actions_builder, G_VARIANT_TYPE ("as")); 212 213 if (server_supports_actions) 214 { 215 const tr_info * inf = tr_torrentInfo (tor); 216 if (inf->fileCount == 1) 217 { 218 g_variant_builder_add (&actions_builder, "s", "file"); 219 g_variant_builder_add (&actions_builder, "s", _("Open File")); 220 } 221 else 222 { 223 g_variant_builder_add (&actions_builder, "s", "folder"); 224 g_variant_builder_add (&actions_builder, "s", _("Open Folder")); 225 } 226 } 227 228 g_dbus_proxy_call (proxy, 229 "Notify", 230 g_variant_new ("(susssasa{sv}i)", 231 "Transmission", n->id, "transmission", 232 _("Torrent Complete"), 233 tr_torrentName (tor), 234 &actions_builder, NULL, -1), 235 G_DBUS_CALL_FLAGS_NONE, -1, NULL, 236 notify_callback, n); 233 237 } 234 238 … … 236 240 gtr_notify_torrent_added (const char * name) 237 241 { 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 } 242 TrNotification * n; 243 244 g_return_if_fail (G_IS_DBUS_PROXY (proxy)); 245 246 if (!gtr_pref_flag_get (PREF_KEY_TORRENT_ADDED_NOTIFICATION_ENABLED)) 247 return; 248 249 n = g_new0 (TrNotification, 1); 250 g_dbus_proxy_call (proxy, 251 "Notify", 252 g_variant_new ("(susssasa{sv}i)", 253 "Transmission", 0, "transmission", 254 _("Torrent Added"), name, 255 NULL, NULL, -1), 256 G_DBUS_CALL_FLAGS_NONE, -1, NULL, 257 notify_callback, n); 258 }
Note: See TracChangeset
for help on using the changeset viewer.