aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--libsylph/utils.c54
-rw-r--r--libsylph/utils.h9
-rw-r--r--src/mimeview.c29
4 files changed, 96 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 33928578..0f81464b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2005-10-13
+ * libsylph/utils.[ch]
+ src/mimeview.c: win32: use ShellExecute() to launch attachments, and
+ warn on launching an executable file.
+
+2005-10-13
+
* libsylph/folder.[ch]
src/prefs_folder_item.c
src/folderview.c: enabled the property of the top folder.
diff --git a/libsylph/utils.c b/libsylph/utils.c
index 579edee7..b06cae6e 100644
--- a/libsylph/utils.c
+++ b/libsylph/utils.c
@@ -42,6 +42,7 @@
#include <time.h>
#ifdef G_OS_WIN32
+# include <windows.h>
# include <wchar.h>
# include <direct.h>
# include <io.h>
@@ -426,6 +427,23 @@ gchar *strncpy2(gchar *dest, const gchar *src, size_t n)
return dest;
}
+/* Similar to g_str_has_suffix() but case-insensitive */
+gboolean str_has_suffix_case(const gchar *str, const gchar *suffix)
+{
+ size_t len, s_len;
+
+ if (!str || !suffix)
+ return FALSE;
+
+ len = strlen(str);
+ s_len = strlen(suffix);
+
+ if (s_len > len)
+ return FALSE;
+
+ return (g_ascii_strcasecmp(str + (len - s_len), suffix) == 0);
+}
+
/* Examine if next block is non-ASCII string */
gboolean is_next_nonascii(const gchar *s)
{
@@ -3063,6 +3081,42 @@ gint execute_command_line(const gchar *cmdline, gboolean async)
return ret;
}
+gint execute_open_file(const gchar *file, const gchar *content_type)
+{
+ g_return_val_if_fail(file != NULL, -1);
+
+#ifdef G_OS_WIN32
+ log_print("opening %s - %s\n", file, content_type ? content_type : "");
+
+ if (G_WIN32_HAVE_WIDECHAR_API()) {
+ wchar_t *wpath;
+
+ wpath = g_utf8_to_utf16(file, -1, NULL, NULL, NULL);
+ if (wpath == NULL)
+ return -1;
+
+ ShellExecuteW(NULL, L"open", wpath, NULL, NULL, SW_SHOWNORMAL);
+
+ g_free(wpath);
+
+ return 0;
+ } else {
+ gchar *cp_path;
+
+ cp_path = g_locale_from_utf8(file, -1, NULL, NULL, NULL);
+ if (cp_path == NULL)
+ return -1;
+
+ ShellExecuteA(NULL, "open", cp_path, NULL, NULL, SW_SHOWNORMAL);
+
+ g_free(cp_path);
+
+ return 0;
+ }
+#endif
+ return 0;
+}
+
gchar *get_command_output(const gchar *cmdline)
{
gchar *child_stdout;
diff --git a/libsylph/utils.h b/libsylph/utils.h
index 311525b0..f628551f 100644
--- a/libsylph/utils.h
+++ b/libsylph/utils.h
@@ -234,8 +234,11 @@ gchar *strncpy2 (gchar *dest,
const gchar *src,
size_t n);
-gboolean is_next_nonascii (const gchar *s);
-gint get_next_word_len (const gchar *s);
+gboolean str_has_suffix_case (const gchar *str,
+ const gchar *suffix);
+
+gboolean is_next_nonascii (const gchar *s);
+gint get_next_word_len (const gchar *s);
/* functions for string parsing */
gint subject_compare (const gchar *s1,
@@ -428,6 +431,8 @@ gint execute_async (gchar *const argv[]);
gint execute_sync (gchar *const argv[]);
gint execute_command_line (const gchar *cmdline,
gboolean async);
+gint execute_open_file (const gchar *file,
+ const gchar *content_type);
gchar *get_command_output (const gchar *cmdline);
/* open URI with external browser */
diff --git a/src/mimeview.c b/src/mimeview.c
index 5a365f76..7f67b163 100644
--- a/src/mimeview.c
+++ b/src/mimeview.c
@@ -42,6 +42,10 @@
#include <stdio.h>
#include <unistd.h>
+#ifdef G_OS_WIN32
+# include <windows.h>
+#endif
+
#include "main.h"
#include "mimeview.h"
#include "textview.h"
@@ -1115,6 +1119,31 @@ static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
const gchar *def_cmd;
const gchar *p;
+#ifdef G_OS_WIN32
+ if (!cmdline) {
+ DWORD dwtype;
+ AlertValue avalue;
+
+ if (str_has_suffix_case(filename, ".exe") ||
+ str_has_suffix_case(filename, ".com") ||
+ str_has_suffix_case(filename, ".scr") ||
+ str_has_suffix_case(filename, ".pif") ||
+ str_has_suffix_case(filename, ".bat") ||
+ str_has_suffix_case(filename, ".vbs") ||
+ str_has_suffix_case(filename, ".js") ||
+ GetBinaryType(filename, &dwtype)) {
+ avalue = alertpanel_full
+ (_("Opening executable file"),
+ _("This is an executable file. Do you really want to launch it?"),
+ ALERT_WARNING, G_ALERTALTERNATE, FALSE,
+ GTK_STOCK_YES, GTK_STOCK_NO, NULL);
+ if (avalue != G_ALERTDEFAULT)
+ return;
+ }
+ execute_open_file(filename, partinfo->content_type);
+ return;
+ }
+#endif
if (cmdline) {
cmd = cmdline;
def_cmd = NULL;