changeset 15237:2bcb8684bfb5

[gaim-migrate @ 18026] Sean came up with the idea to give the windows folks an easy way to browse to the logs directory. I implemented it. Hopefully this will avoid a FAQ or two. I also noticed and plugged a small and rarely encountered leak. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Wed, 20 Dec 2006 05:43:51 +0000
parents 6d0925ac1ed6
children 658f815e2b58
files gtk/gtklog.c gtk/win32/gtkwin32dep.c gtk/win32/gtkwin32dep.h
diffstat 3 files changed, 50 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/gtklog.c	Tue Dec 19 18:52:18 2006 +0000
+++ b/gtk/gtklog.c	Wed Dec 20 05:43:51 2006 +0000
@@ -163,9 +163,18 @@
 	gaim_gtk_clear_cursor(lv->window);
 }
 
-static gboolean destroy_cb(GtkWidget *w, gint resp, struct log_viewer_hash_t *ht) {
+static void destroy_cb(GtkWidget *w, gint resp, struct log_viewer_hash_t *ht) {
 	GaimGtkLogViewer *lv = syslog_viewer;
 
+#ifdef _WIN32
+	if (resp == GTK_RESPONSE_HELP) {
+		char *logdir = g_build_filename(gaim_user_dir(), "logs", NULL);
+		gtkwgaim_shell_execute(logdir, "explore", NULL);
+		g_free(logdir);
+		return;
+	}
+#endif
+
 	if (ht != NULL) {
 		lv = g_hash_table_lookup(log_viewers, ht);
 		g_hash_table_remove(log_viewers, ht);
@@ -182,8 +191,6 @@
 	g_free(lv);
 
 	gtk_widget_destroy(w);
-
-	return TRUE;
 }
 
 static void log_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, GaimGtkLogViewer *viewer) {
@@ -345,6 +352,10 @@
 	/* Window ***********/
 	lv->window = gtk_dialog_new_with_buttons(title, NULL, 0,
 					     GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
+#ifdef _WIN32
+	/* Steal the "HELP" response and use it to trigger browsing to the logs folder */
+	gtk_dialog_add_button(GTK_DIALOG(lv->window), _("_Browse logs folder"), GTK_RESPONSE_HELP);
+#endif
 	gtk_container_set_border_width (GTK_CONTAINER(lv->window), GAIM_HIG_BOX_SPACE);
 	gtk_dialog_set_has_separator(GTK_DIALOG(lv->window), FALSE);
 	gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(lv->window)->vbox), 0);
@@ -450,7 +461,7 @@
 }
 
 void gaim_gtk_log_show(GaimLogType type, const char *screenname, GaimAccount *account) {
-	struct log_viewer_hash_t *ht = g_new0(struct log_viewer_hash_t, 1);
+	struct log_viewer_hash_t *ht;
 	GaimGtkLogViewer *lv = NULL;
 	const char *name = screenname;
 	char *title;
@@ -458,6 +469,8 @@
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(screenname != NULL);
 
+	ht = g_new0(struct log_viewer_hash_t, 1);
+
 	ht->type = type;
 	ht->screenname = g_strdup(screenname);
 	ht->account = account;
@@ -466,6 +479,7 @@
 		log_viewers = g_hash_table_new(log_viewer_hash, log_viewer_equal);
 	} else if ((lv = g_hash_table_lookup(log_viewers, ht))) {
 		gtk_window_present(GTK_WINDOW(lv->window));
+		g_free(ht->screenname);
 		g_free(ht);
 		return;
 	}
--- a/gtk/win32/gtkwin32dep.c	Tue Dec 19 18:52:18 2006 +0000
+++ b/gtk/win32/gtkwin32dep.c	Wed Dec 20 05:43:51 2006 +0000
@@ -119,7 +119,7 @@
 		if(untar(tmpfile, destdir, UNTAR_FORCE | UNTAR_QUIET))
 			ret = 1;
 		else {
-			gaim_debug_error("gtkwgaim_gz_untar", "Failure untaring %s\n", tmpfile);
+			gaim_debug_error("gtkwgaim_gz_untar", "Failure untarring %s\n", tmpfile);
 			ret = 0;
 		}
 		g_unlink(tmpfile);
@@ -131,51 +131,66 @@
 	}
 }
 
-void gtkwgaim_notify_uri(const char *uri) {
+void gtkwgaim_shell_execute(const char *target, const char *verb, const char *clazz) {
 
-	/* We'll allow whatever URI schemes are supported by the
-	 * default http browser.
-	 */
+	g_return_if_fail(target != NULL);
+	g_return_if_fail(verb != NULL);
 
 	if (G_WIN32_HAVE_WIDECHAR_API()) {
 		SHELLEXECUTEINFOW wsinfo;
-		wchar_t *w_uri;
+		wchar_t *w_uri, *w_verb, *w_clazz = NULL;
 
-		w_uri = g_utf8_to_utf16(uri, -1, NULL, NULL, NULL);
+		w_uri = g_utf8_to_utf16(target, -1, NULL, NULL, NULL);
+		w_verb = g_utf8_to_utf16(verb, -1, NULL, NULL, NULL);
 
 		memset(&wsinfo, 0, sizeof(wsinfo));
 		wsinfo.cbSize = sizeof(wsinfo);
-		wsinfo.fMask = SEE_MASK_CLASSNAME;
-		wsinfo.lpVerb = L"open";
+		wsinfo.lpVerb = w_verb;
 		wsinfo.lpFile = w_uri;
 		wsinfo.nShow = SW_SHOWNORMAL;
-		wsinfo.lpClass = L"http";
+		if (clazz != NULL) {
+			w_clazz = g_utf8_to_utf16(clazz, -1, NULL, NULL, NULL);
+			wsinfo.fMask |= SEE_MASK_CLASSNAME;
+			wsinfo.lpClass = w_clazz;
+		}
 
 		if(!ShellExecuteExW(&wsinfo))
 			gaim_debug_error("gtkwgaim", "Error opening URI: %s error: %d\n",
-				uri, (int) wsinfo.hInstApp);
+				target, (int) wsinfo.hInstApp);
 
 		g_free(w_uri);
+		g_free(w_verb);
+		g_free(w_clazz);
 	} else {
 		SHELLEXECUTEINFOA sinfo;
 		gchar *locale_uri;
 
-		locale_uri = g_locale_from_utf8(uri, -1, NULL, NULL, NULL);
+		locale_uri = g_locale_from_utf8(target, -1, NULL, NULL, NULL);
 
 		memset(&sinfo, 0, sizeof(sinfo));
 		sinfo.cbSize = sizeof(sinfo);
-		sinfo.fMask = SEE_MASK_CLASSNAME;
-		sinfo.lpVerb = "open";
+		sinfo.lpVerb = verb;
 		sinfo.lpFile = locale_uri;
 		sinfo.nShow = SW_SHOWNORMAL;
-		sinfo.lpClass = "http";
+		if (clazz != NULL) {
+			sinfo.fMask |= SEE_MASK_CLASSNAME;
+			sinfo.lpClass = clazz;
+		}
 
 		if(!ShellExecuteExA(&sinfo))
 			gaim_debug_error("gtkwgaim", "Error opening URI: %s error: %d\n",
-				uri, (int) sinfo.hInstApp);
+				target, (int) sinfo.hInstApp);
 
 		g_free(locale_uri);
 	}
+
+}
+
+void gtkwgaim_notify_uri(const char *uri) {
+	/* We'll allow whatever URI schemes are supported by the
+	 * default http browser.
+	 */
+	gtkwgaim_shell_execute(uri, "open", "http");
 }
 
 #define WM_FOCUS_REQUEST (WM_APP + 13)
--- a/gtk/win32/gtkwin32dep.h	Tue Dec 19 18:52:18 2006 +0000
+++ b/gtk/win32/gtkwin32dep.h	Wed Dec 20 05:43:51 2006 +0000
@@ -34,6 +34,7 @@
 
 /* Misc */
 void gtkwgaim_notify_uri(const char *uri);
+void gtkwgaim_shell_execute(const char *target, const char *verb, const char *clazz);
 void gtkwgaim_ensure_onscreen(GtkWidget *win);
 void gtkwgaim_conv_blink(GaimConversation *conv, GaimMessageFlags flags);