From 5d566e74c57ba4d086ec83f4590719a602a83823 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 13 Oct 2005 08:06:40 +0000 Subject: win32: use ShellExecute() to launch attachments. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@642 ee746299-78ed-0310-b773-934348b2243d --- libsylph/utils.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ libsylph/utils.h | 9 +++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) (limited to 'libsylph') 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 #ifdef G_OS_WIN32 +# include # include # include # include @@ -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 */ -- cgit v1.2.3