aboutsummaryrefslogtreecommitdiff
path: root/libsylph
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-10-13 08:06:40 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-10-13 08:06:40 +0000
commit5d566e74c57ba4d086ec83f4590719a602a83823 (patch)
treed7e129f0f3ff055c2b342a0b10e609c966960b4f /libsylph
parent2ebd418a6e4f86de03434eb357cc577a4e366f5d (diff)
win32: use ShellExecute() to launch attachments.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@642 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph')
-rw-r--r--libsylph/utils.c54
-rw-r--r--libsylph/utils.h9
2 files changed, 61 insertions, 2 deletions
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 */