changeset 5519:42a20beb80a7

[gaim-migrate @ 5919] Fixed up the e-mail notification. It doesn't do everything we have the capability to do, but I have no way of testing, nor the desire. Theoretically, somebody could write a plugin to replace this and have some kind of mail inbox thing :) committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 26 May 2003 00:51:23 +0000
parents bf2a7a7b739d
children 11be8ae32937
files src/gtknotify.c
diffstat 1 files changed, 138 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtknotify.c	Sun May 25 22:51:19 2003 +0000
+++ b/src/gtknotify.c	Mon May 26 00:51:23 2003 +0000
@@ -24,11 +24,33 @@
 #include "stock.h"
 #include <gtk/gtk.h>
 
-static void *gaim_gtk_notify_emails(size_t count, const char **subjects,
+/* XXX For ngettext :/ */
+#include "gaim.h"
+
+typedef struct
+{
+	struct gaim_connection *gc;
+	char *url;
+	GtkWidget *dialog;
+	GtkWidget *label;
+
+} GaimNotifyMailData;
+
+static void *gaim_gtk_notify_emails(size_t count, gboolean detailed,
+									const char **subjects,
 									const char **froms, const char **tos,
 									const char **urls, GCallback cb,
 									void *user_data);
 
+static void
+__email_response_cb(GtkDialog *dialog, gint id, GaimNotifyMailData *data)
+{
+	if (id == 0)
+		open_url(NULL, data->url);
+
+	gaim_notify_close(GAIM_NOTIFY_EMAILS, data);
+}
+
 static void *
 gaim_gtk_notify_message(GaimNotifyMsgType type, const char *title,
 						const char *primary, const char *secondary,
@@ -103,21 +125,129 @@
 					  const char *to, const char *url,
 					  GCallback cb, void *user_data)
 {
-	return gaim_gtk_notify_emails(1, &subject, &from, &to, &url, cb, user_data);
+	return gaim_gtk_notify_emails(1, TRUE,
+								  &subject, &from, &to, &url, cb, user_data);
 }
 
 static void *
-gaim_gtk_notify_emails(size_t count, const char **subjects,
-					   const char **froms, const char **tos,
-					   const char **urls, GCallback cb, void *user_data)
+gaim_gtk_notify_emails(size_t count, gboolean detailed,
+					   const char **subjects, const char **froms,
+					   const char **tos, const char **urls,
+					   GCallback cb, void *user_data)
 {
-	return NULL;
+	GaimNotifyMailData *data;
+	GtkWidget *dialog;
+	GtkWidget *vbox;
+	GtkWidget *hbox;
+	GtkWidget *label;
+	GtkWidget *img;
+	char *detail_text;
+	char *label_text;
+
+	data = g_new0(GaimNotifyMailData, 1);
+
+	data->url = g_strdup(urls[0]);
+
+	/* Create the dialog. */
+	dialog = gtk_dialog_new_with_buttons("", NULL, 0,
+					     GTK_STOCK_CLOSE,      1,
+						 GAIM_STOCK_OPEN_MAIL, 0,
+					     NULL);
+	data->dialog = dialog;
+
+	g_signal_connect(G_OBJECT(dialog), "response",
+					 G_CALLBACK(__email_response_cb), data);
+
+	/* Setup the dialog */
+	gtk_container_set_border_width(GTK_CONTAINER(dialog), 6);
+	gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 6);
+	gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
+	gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
+	gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 12);
+
+	/* Setup the main horizontal box */
+	hbox = gtk_hbox_new(FALSE, 12);
+	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
+
+	/* Dialog icon. */
+	img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_INFO,
+								   GTK_ICON_SIZE_DIALOG);
+	gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
+	gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
+
+	/* Vertical box */
+	vbox = gtk_vbox_new(FALSE, 12);
+
+	gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
+
+	/* Descriptive label */
+	detail_text = g_strdup_printf(
+		ngettext("%s has %d new message.", "%s has %d new messages.", count),
+		*tos, count);
+
+	if (count == 1) {
+		char *from_text = NULL, *subject_text = NULL;
+
+		if (froms != NULL) {
+			from_text = g_strdup_printf(
+				"<span weight=\"bold\">From:</span> %s", *froms);
+		}
+
+		if (subjects != NULL) {
+			subject_text = g_strdup_printf(
+				"<span weight=\"bold\">Subject:</span> %s", *subjects);
+		}
+
+		label_text = g_strdup_printf(
+			"<span weight=\"bold\" size=\"larger\">You have mail!</span>"
+			"\n\n%s%s%s%s",
+			detail_text,
+			(from_text == NULL && subject_text == NULL ? "" : "\n\n"),
+			(from_text == NULL ? "" : from_text),
+			(subject_text == NULL ? "" : subject_text));
+
+		if (from_text != NULL)
+			g_free(from_text);
+
+		if (subject_text != NULL)
+			g_free(subject_text);
+	}
+	else {
+		label_text = g_strdup_printf(
+			"<span weight=\"bold\" size=\"larger\">You have mail!</span>"
+			"\n\n%s", detail_text);
+	}
+
+	g_free(detail_text);
+
+	label = gtk_label_new(NULL);
+
+	gtk_label_set_markup(GTK_LABEL(label), label_text);
+	gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
+	gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
+	gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);
+
+	g_free(label_text);
+
+	/* Show everything. */
+	gtk_widget_show_all(dialog);
+
+	return data;
 }
 
 static void
-gaim_gtk_close_notify(GaimNotifyType type, void *ptr)
+gaim_gtk_close_notify(GaimNotifyType type, void *ui_handle)
 {
-	gtk_widget_destroy(GTK_WIDGET(ptr));
+	if (type == GAIM_NOTIFY_EMAIL || type == GAIM_NOTIFY_EMAILS) {
+		GaimNotifyMailData *data = (GaimNotifyMailData *)ui_handle;
+
+		gtk_widget_destroy(data->dialog);
+
+		g_free(data->url);
+		g_free(data);
+	}
+	else
+		gtk_widget_destroy(GTK_WIDGET(ui_handle));
 }
 
 static GaimNotifyUiOps ops =