| 3203 g_free(text); |
3203 g_free(text); |
| 3204 |
3204 |
| 3205 return TRUE; |
3205 return TRUE; |
| 3206 } |
3206 } |
| 3207 |
3207 |
| |
3208 /** |
| |
3209 * @param filename The path to a file. Specifically this is the link target |
| |
3210 * from a link in an IM window with the leading "file://" removed. |
| |
3211 */ |
| 3208 static void |
3212 static void |
| 3209 file_open_uri(GtkWebView *webview, const char *uri) |
3213 open_file(GtkWebView *webview, const char *filename) |
| 3210 { |
3214 { |
| 3211 /* Copied from gtkft.c:open_button_cb */ |
3215 /* Copied from gtkft.c:open_button_cb */ |
| 3212 #ifdef _WIN32 |
3216 #ifdef _WIN32 |
| 3213 /* If using Win32... */ |
3217 /* If using Win32... */ |
| 3214 int code; |
3218 int code; |
| 3215 if (purple_str_has_prefix(uri, "file://")) |
3219 /* Escape URI by replacing double-quote with 2 double-quotes. */ |
| 3216 { |
3220 gchar *escaped = purple_strreplace(filename, "\"", "\"\""); |
| 3217 gchar *escaped = g_shell_quote(uri); |
3221 gchar *param = g_strconcat("/select,\"", escaped, "\"", NULL); |
| 3218 gchar *param = g_strconcat("/select,\"", uri, "\"", NULL); |
3222 wchar_t *wc_param = g_utf8_to_utf16(param, -1, NULL, NULL, NULL); |
| 3219 wchar_t *wc_param = g_utf8_to_utf16(param, -1, NULL, NULL, NULL); |
3223 |
| 3220 |
3224 /* TODO: Better to use SHOpenFolderAndSelectItems()? */ |
| 3221 code = (int)ShellExecuteW(NULL, L"OPEN", L"explorer.exe", wc_param, NULL, SW_NORMAL); |
3225 code = (int)ShellExecuteW(NULL, L"OPEN", L"explorer.exe", wc_param, NULL, SW_NORMAL); |
| 3222 |
3226 |
| 3223 g_free(wc_param); |
3227 g_free(wc_param); |
| 3224 g_free(param); |
3228 g_free(param); |
| 3225 g_free(escaped); |
3229 g_free(escaped); |
| 3226 } else { |
|
| 3227 wchar_t *wc_filename = g_utf8_to_utf16( |
|
| 3228 uri, -1, NULL, NULL, NULL); |
|
| 3229 |
|
| 3230 code = (int)ShellExecuteW(NULL, NULL, wc_filename, NULL, NULL, |
|
| 3231 SW_SHOW); |
|
| 3232 |
|
| 3233 g_free(wc_filename); |
|
| 3234 } |
|
| 3235 |
3230 |
| 3236 if (code == SE_ERR_ASSOCINCOMPLETE || code == SE_ERR_NOASSOC) |
3231 if (code == SE_ERR_ASSOCINCOMPLETE || code == SE_ERR_NOASSOC) |
| 3237 { |
3232 { |
| 3238 purple_notify_error(webview, NULL, |
3233 purple_notify_error(webview, NULL, |
| 3239 _("There is no application configured to open this type of file."), |
3234 _("There is no application configured to open this type of file."), |
| 3241 } |
3236 } |
| 3242 else if (code < 32) |
3237 else if (code < 32) |
| 3243 { |
3238 { |
| 3244 purple_notify_error(webview, NULL, |
3239 purple_notify_error(webview, NULL, |
| 3245 _("An error occurred while opening the file."), NULL, NULL); |
3240 _("An error occurred while opening the file."), NULL, NULL); |
| 3246 purple_debug_warning("gtkutils", "filename: %s; code: %d\n", uri, code); |
3241 purple_debug_warning("gtkutils", "filename: %s; code: %d\n", |
| |
3242 filename, code); |
| 3247 } |
3243 } |
| 3248 #else |
3244 #else |
| 3249 char *command = NULL; |
3245 char *command = NULL; |
| 3250 char *tmp = NULL; |
3246 char *tmp = NULL; |
| 3251 GError *error = NULL; |
3247 GError *error = NULL; |
| 3252 |
3248 |
| 3253 if (purple_running_gnome()) |
3249 if (purple_running_gnome()) |
| 3254 { |
3250 { |
| 3255 char *escaped = g_shell_quote(uri); |
3251 char *escaped = g_shell_quote(filename); |
| 3256 command = g_strdup_printf("gnome-open %s", escaped); |
3252 command = g_strdup_printf("gnome-open %s", escaped); |
| 3257 g_free(escaped); |
3253 g_free(escaped); |
| 3258 } |
3254 } |
| 3259 else if (purple_running_kde()) |
3255 else if (purple_running_kde()) |
| 3260 { |
3256 { |
| 3261 char *escaped = g_shell_quote(uri); |
3257 char *escaped = g_shell_quote(filename); |
| 3262 |
3258 |
| 3263 if (purple_str_has_suffix(uri, ".desktop")) |
3259 if (purple_str_has_suffix(filename, ".desktop")) |
| 3264 command = g_strdup_printf("kfmclient openURL %s 'text/plain'", escaped); |
3260 command = g_strdup_printf("kfmclient openURL %s 'text/plain'", escaped); |
| 3265 else |
3261 else |
| 3266 command = g_strdup_printf("kfmclient openURL %s", escaped); |
3262 command = g_strdup_printf("kfmclient openURL %s", escaped); |
| 3267 g_free(escaped); |
3263 g_free(escaped); |
| 3268 } |
3264 } |
| 3269 else |
3265 else |
| 3270 { |
3266 { |
| 3271 purple_notify_uri(NULL, uri); |
3267 purple_notify_uri(NULL, filename); |
| 3272 return; |
3268 return; |
| 3273 } |
3269 } |
| 3274 |
3270 |
| 3275 if (purple_program_is_valid(command)) |
3271 if (purple_program_is_valid(command)) |
| 3276 { |
3272 { |
| 3277 gint exit_status; |
3273 gint exit_status; |
| 3278 if (!g_spawn_command_line_sync(command, NULL, NULL, &exit_status, &error)) |
3274 if (!g_spawn_command_line_sync(command, NULL, NULL, &exit_status, &error)) |
| 3279 { |
3275 { |
| 3280 tmp = g_strdup_printf(_("Error launching %s: %s"), |
3276 tmp = g_strdup_printf(_("Error launching %s: %s"), |
| 3281 uri, error->message); |
3277 filename, error->message); |
| 3282 purple_notify_error(webview, NULL, _("Unable to open file."), tmp, NULL); |
3278 purple_notify_error(webview, NULL, _("Unable to open file."), tmp, NULL); |
| 3283 g_free(tmp); |
3279 g_free(tmp); |
| 3284 g_error_free(error); |
3280 g_error_free(error); |
| 3285 } |
3281 } |
| 3286 if (exit_status != 0) |
3282 if (exit_status != 0) |
| 3297 |
3293 |
| 3298 #define FILELINKSIZE (sizeof("file://") - 1) |
3294 #define FILELINKSIZE (sizeof("file://") - 1) |
| 3299 static gboolean |
3295 static gboolean |
| 3300 file_clicked_cb(GtkWebView *webview, const char *uri) |
3296 file_clicked_cb(GtkWebView *webview, const char *uri) |
| 3301 { |
3297 { |
| 3302 file_open_uri(webview, uri + FILELINKSIZE); |
3298 /* Strip "file://" from the URI. */ |
| |
3299 open_file(webview, uri + FILELINKSIZE); |
| 3303 return TRUE; |
3300 return TRUE; |
| 3304 } |
3301 } |
| 3305 |
3302 |
| 3306 static gboolean |
3303 static gboolean |
| 3307 open_containing_cb(GtkWebView *webview, const char *uri) |
3304 open_containing_cb(GtkWebView *webview, const char *uri) |
| 3308 { |
3305 { |
| 3309 char *dir = g_path_get_dirname(uri + FILELINKSIZE); |
3306 char *dir = g_path_get_dirname(uri + FILELINKSIZE); |
| 3310 file_open_uri(webview, dir); |
3307 open_file(webview, dir); |
| 3311 g_free(dir); |
3308 g_free(dir); |
| 3312 return TRUE; |
3309 return TRUE; |
| 3313 } |
3310 } |
| 3314 |
3311 |
| 3315 static gboolean |
3312 static gboolean |