Revision 642

libsylph/utils.c (revision 642)
42 42
#include <time.h>
43 43

  
44 44
#ifdef G_OS_WIN32
45
#  include <windows.h>
45 46
#  include <wchar.h>
46 47
#  include <direct.h>
47 48
#  include <io.h>
......
426 427
	return dest;
427 428
}
428 429

  
430
/* Similar to g_str_has_suffix() but case-insensitive */
431
gboolean str_has_suffix_case(const gchar *str, const gchar *suffix)
432
{
433
	size_t len, s_len;
434

  
435
	if (!str || !suffix)
436
		return FALSE;
437

  
438
	len = strlen(str);
439
	s_len = strlen(suffix);
440

  
441
	if (s_len > len)
442
		return FALSE;
443

  
444
	return (g_ascii_strcasecmp(str + (len - s_len), suffix) == 0);
445
}
446

  
429 447
/* Examine if next block is non-ASCII string */
430 448
gboolean is_next_nonascii(const gchar *s)
431 449
{
......
3063 3081
	return ret;
3064 3082
}
3065 3083

  
3084
gint execute_open_file(const gchar *file, const gchar *content_type)
3085
{
3086
	g_return_val_if_fail(file != NULL, -1);
3087

  
3088
#ifdef G_OS_WIN32
3089
	log_print("opening %s - %s\n", file, content_type ? content_type : "");
3090

  
3091
	if (G_WIN32_HAVE_WIDECHAR_API()) {
3092
		wchar_t *wpath;
3093

  
3094
		wpath = g_utf8_to_utf16(file, -1, NULL, NULL, NULL);
3095
		if (wpath == NULL)
3096
			return -1;
3097

  
3098
		ShellExecuteW(NULL, L"open", wpath, NULL, NULL, SW_SHOWNORMAL);
3099

  
3100
		g_free(wpath);
3101

  
3102
		return 0;
3103
	} else {
3104
		gchar *cp_path;
3105

  
3106
		cp_path = g_locale_from_utf8(file, -1, NULL, NULL, NULL);
3107
		if (cp_path == NULL)
3108
			return -1;
3109

  
3110
		ShellExecuteA(NULL, "open", cp_path, NULL, NULL, SW_SHOWNORMAL);
3111

  
3112
		g_free(cp_path);
3113

  
3114
		return 0;
3115
	}
3116
#endif
3117
	return 0;
3118
}
3119

  
3066 3120
gchar *get_command_output(const gchar *cmdline)
3067 3121
{
3068 3122
	gchar *child_stdout;
libsylph/utils.h (revision 642)
234 234
			 const gchar	*src,
235 235
			 size_t		 n);
236 236

  
237
gboolean is_next_nonascii	(const gchar *s);
238
gint get_next_word_len		(const gchar *s);
237
gboolean str_has_suffix_case	(const gchar	*str,
238
				 const gchar	*suffix);
239 239

  
240
gboolean is_next_nonascii	(const gchar	*s);
241
gint get_next_word_len		(const gchar	*s);
242

  
240 243
/* functions for string parsing */
241 244
gint subject_compare			(const gchar	*s1,
242 245
					 const gchar	*s2);
......
428 431
gint execute_sync		(gchar *const	 argv[]);
429 432
gint execute_command_line	(const gchar	*cmdline,
430 433
				 gboolean	 async);
434
gint execute_open_file		(const gchar	*file,
435
				 const gchar	*content_type);
431 436
gchar *get_command_output	(const gchar	*cmdline);
432 437

  
433 438
/* open URI with external browser */
src/mimeview.c (revision 642)
42 42
#include <stdio.h>
43 43
#include <unistd.h>
44 44

  
45
#ifdef G_OS_WIN32
46
#  include <windows.h>
47
#endif
48

  
45 49
#include "main.h"
46 50
#include "mimeview.h"
47 51
#include "textview.h"
......
1115 1119
	const gchar *def_cmd;
1116 1120
	const gchar *p;
1117 1121

  
1122
#ifdef G_OS_WIN32
1123
	if (!cmdline) {
1124
		DWORD dwtype;
1125
		AlertValue avalue;
1126

  
1127
		if (str_has_suffix_case(filename, ".exe") ||
1128
		    str_has_suffix_case(filename, ".com") ||
1129
		    str_has_suffix_case(filename, ".scr") ||
1130
		    str_has_suffix_case(filename, ".pif") ||
1131
		    str_has_suffix_case(filename, ".bat") ||
1132
		    str_has_suffix_case(filename, ".vbs") ||
1133
		    str_has_suffix_case(filename, ".js")  ||
1134
		    GetBinaryType(filename, &dwtype)) {
1135
			avalue = alertpanel_full
1136
				(_("Opening executable file"),
1137
				 _("This is an executable file. Do you really want to launch it?"),
1138
				 ALERT_WARNING, G_ALERTALTERNATE, FALSE,
1139
				 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
1140
			if (avalue != G_ALERTDEFAULT)
1141
				return;
1142
		}
1143
		execute_open_file(filename, partinfo->content_type);
1144
		return;
1145
	}
1146
#endif
1118 1147
	if (cmdline) {
1119 1148
		cmd = cmdline;
1120 1149
		def_cmd = NULL;
ChangeLog (revision 642)
1 1
2005-10-13
2 2

  
3
	* libsylph/utils.[ch]
4
	  src/mimeview.c: win32: use ShellExecute() to launch attachments, and
5
	  warn on launching an executable file.
6

  
7
2005-10-13
8

  
3 9
	* libsylph/folder.[ch]
4 10
	  src/prefs_folder_item.c
5 11
	  src/folderview.c: enabled the property of the top folder.

Also available in: Unified diff