evolution r35294 - in branches/mbarnes-composer: composer mail



Author: mbarnes
Date: Tue Apr  1 01:49:07 2008
New Revision: 35294
URL: http://svn.gnome.org/viewvc/evolution?rev=35294&view=rev

Log:
Tighten up the EMsgComposer API some more.
Fix the widget style pattern for transferring color and font preferences
to the GtkHTML widget (goddamn that's ugly; I really need to fix that).


Modified:
   branches/mbarnes-composer/composer/e-msg-composer.c
   branches/mbarnes-composer/composer/e-msg-composer.h
   branches/mbarnes-composer/mail/mail-config.c

Modified: branches/mbarnes-composer/composer/e-msg-composer.c
==============================================================================
--- branches/mbarnes-composer/composer/e-msg-composer.c	(original)
+++ branches/mbarnes-composer/composer/e-msg-composer.c	Tue Apr  1 01:49:07 2008
@@ -1339,11 +1339,13 @@
 		if (e_composer_autosave_snapshot (composer))
 			g_unlink (filename);
 
-		g_signal_connect (GTK_OBJECT (composer), "send",
-				  G_CALLBACK (em_utils_composer_send_cb), NULL);
+		g_signal_connect (
+			composer, "send",
+			G_CALLBACK (em_utils_composer_send_cb), NULL);
 
-		g_signal_connect (GTK_OBJECT (composer), "save-draft",
-				  G_CALLBACK (em_utils_composer_save_draft_cb), NULL);
+		g_signal_connect (
+			composer, "save-draft",
+			G_CALLBACK (em_utils_composer_save_draft_cb), NULL);
 
 		gtk_widget_show (GTK_WIDGET (composer));
 	}
@@ -1351,33 +1353,6 @@
 	return composer;
 }
 
-static void
-setup_ui (EMsgComposer *composer)
-{
-#if 0 /* GTKHTML-EDITOR */
-	EMMenuTargetWidget *target;
-	EMsgComposerPrivate *p = composer->priv;
-	BonoboUIContainer *container;
-	char *charset;
-	char *xmlfile;
-
-	/* Populate the Charset Encoding menu and default it to whatever the user
-	   chose as his default charset in the mailer */
-	charset = composer_get_default_charset_setting ();
-	e_charset_picker_bonobo_ui_populate (p->uic, "/menu/Edit/EncodingPlaceholder",
-					     charset,
-					     menu_changed_charset_cb,
-					     composer);
-	g_free (charset);
-
-	/* Setup main menu plugin mechanism */
-	target = em_menu_target_new_widget (p->menu, (GtkWidget *)composer);
-	e_menu_update_target ((EMenu *)p->menu, target);
-	e_menu_activate ((EMenu *)p->menu, p->uic, TRUE);
-#endif /* GTKHTML-EDITOR */
-}
-
-
 /* Miscellaneous callbacks.  */
 
 static void
@@ -1821,20 +1796,27 @@
 drop_popup_copy (EPopup *ep, EPopupItem *item, gpointer data)
 {
 	struct _drop_data *m = data;
-	drop_action (m->composer, m->context, GDK_ACTION_COPY, m->selection, m->info, m->time, FALSE);
+
+	drop_action (
+		m->composer, m->context, GDK_ACTION_COPY,
+		m->selection, m->info, m->time, FALSE);
 }
 
 static void
 drop_popup_move (EPopup *ep, EPopupItem *item, gpointer data)
 {
 	struct _drop_data *m = data;
-	drop_action (m->composer, m->context, GDK_ACTION_MOVE, m->selection, m->info, m->time, FALSE);
+
+	drop_action (
+		m->composer, m->context, GDK_ACTION_MOVE,
+		m->selection, m->info, m->time, FALSE);
 }
 
 static void
 drop_popup_cancel (EPopup *ep, EPopupItem *item, gpointer data)
 {
 	struct _drop_data *m = data;
+
 	gtk_drag_finish (m->context, FALSE, FALSE, m->time);
 }
 
@@ -2165,6 +2147,208 @@
 }
 
 static void
+msg_composer_command_before (GtkhtmlEditor *editor,
+                             const gchar *command)
+{
+	EMsgComposer *composer;
+	const gchar *data;
+
+	composer = E_MSG_COMPOSER (editor);
+
+	if (strcmp (command, "insert-paragraph") != 0)
+		return;
+
+	if (composer->priv->in_signature_insert)
+		return;
+
+	data = gtkhtml_editor_get_paragraph_data (editor, "orig");
+	if (data != NULL && *data == '1') {
+		gtkhtml_editor_run_command (editor, "text-default-color");
+		gtkhtml_editor_run_command (editor, "italic-off");
+		return;
+	};
+
+	data = gtkhtml_editor_get_paragraph_data (editor, "signature");
+	if (data != NULL && *data == '1') {
+		gtkhtml_editor_run_command (editor, "text-default-color");
+		gtkhtml_editor_run_command (editor, "italic-off");
+	}
+}
+
+static void
+msg_composer_command_after (GtkhtmlEditor *editor,
+                            const gchar *command)
+{
+	EMsgComposer *composer;
+	const gchar *data;
+
+	composer = E_MSG_COMPOSER (editor);
+
+	if (strcmp (command, "insert-paragraph") != 0)
+		return;
+
+	if (composer->priv->in_signature_insert)
+		return;
+
+	gtkhtml_editor_run_command (editor, "italic-off");
+
+	data = gtkhtml_editor_get_paragraph_data (editor, "orig");
+	if (data != NULL && *data == '1')
+		e_msg_composer_reply_indent (composer);
+	gtkhtml_editor_set_paragraph_data (editor, "orig", "0");
+
+	data = gtkhtml_editor_get_paragraph_data (editor, "signature");
+	if (data == NULL || *data != '1')
+		return;
+
+	/* Clear the signature. */
+	if (gtkhtml_editor_is_paragraph_empty (editor))
+		gtkhtml_editor_set_paragraph_data (editor, "signature" ,"0");
+
+	else if (gtkhtml_editor_is_previous_paragraph_empty (editor) &&
+		gtkhtml_editor_run_command (editor, "cursor-backward")) {
+
+		gtkhtml_editor_set_paragraph_data (editor, "signature", "0");
+		gtkhtml_editor_run_command (editor, "cursor-forward");
+	}
+
+	gtkhtml_editor_run_command (editor, "text-default-color");
+	gtkhtml_editor_run_command (editor, "italic-off");
+}
+
+static gchar *
+msg_composer_image_uri (GtkhtmlEditor *editor,
+                        const gchar *uri)
+{
+	EMsgComposer *composer;
+	GHashTable *hash_table;
+	CamelMimePart *part;
+	const gchar *cid;
+
+	composer = E_MSG_COMPOSER (editor);
+
+	hash_table = composer->priv->inline_images_by_url;
+	part = g_hash_table_lookup (hash_table, uri);
+
+	if (part == NULL && g_str_has_prefix (uri, "file:"))
+		part = e_msg_composer_add_inline_image_from_file (
+			composer, uri + 5);
+
+	if (part == NULL && g_str_has_prefix (uri, "cid:")) {
+		hash_table = composer->priv->inline_images;
+		part = g_hash_table_lookup (hash_table, uri);
+	}
+
+	if (part == NULL)
+		return NULL;
+
+	composer->priv->current_images =
+		g_list_prepend (composer->priv->current_images, part);
+
+	cid = camel_mime_part_get_content_id (part);
+	if (cid == NULL)
+		return NULL;
+
+	return g_strconcat ("cid:", cid, NULL);
+}
+
+static void
+msg_composer_link_clicked (GtkhtmlEditor *editor,
+                           const gchar *uri)
+{
+	GError *error = NULL;
+
+	if (uri == NULL || *uri == '\0')
+		return;
+
+	if (g_ascii_strncasecmp (uri, "mailto:";, 7) == 0)
+		return;
+
+	if (g_ascii_strncasecmp (uri, "thismessage:", 12) == 0)
+		return;
+
+	if (g_ascii_strncasecmp (uri, "cid:", 4) == 0)
+		return;
+
+	gnome_url_show (uri, &error);
+
+	if (error) {
+		g_warning ("%s", error->message);
+		g_error_free (error);
+	}
+}
+
+static void
+msg_composer_object_deleted (GtkhtmlEditor *editor)
+{
+	const gchar *data;
+
+	if (!gtkhtml_editor_is_paragraph_empty (editor))
+		return;
+
+	data = gtkhtml_editor_get_paragraph_data (editor, "orig");
+	if (data != NULL && *data == '1') {
+		gtkhtml_editor_set_paragraph_data (editor, "orig", "0");
+		gtkhtml_editor_run_command (editor, "indent-zero");
+		gtkhtml_editor_run_command (editor, "style-normal");
+		gtkhtml_editor_run_command (editor, "text-default-color");
+		gtkhtml_editor_run_command (editor, "italic-off");
+		gtkhtml_editor_run_command (editor, "insert-paragraph");
+		gtkhtml_editor_run_command (editor, "delete-back");
+	}
+
+	data = gtkhtml_editor_get_paragraph_data (editor, "signature");
+	if (data != NULL && *data == '1')
+		gtkhtml_editor_set_paragraph_data (editor, "signature", "0");
+}
+
+static void
+msg_composer_uri_requested (GtkhtmlEditor *editor,
+                            const gchar *uri,
+                            GtkHTMLStream *stream)
+{
+	EMsgComposer *composer;
+	GHashTable *hash_table;
+	GByteArray *array;
+	CamelDataWrapper *wrapper;
+	CamelStream *camel_stream;
+	CamelMimePart *part;
+	GtkHTML *html;
+
+	/* XXX It's unfortunate we have to expose GtkHTML structs here.
+	 *     Maybe we could rework this to use a GOutputStream. */
+
+	composer = E_MSG_COMPOSER (editor);
+	html = gtkhtml_editor_get_html (editor);
+
+	hash_table = composer->priv->inline_images_by_url;
+	part = g_hash_table_lookup (hash_table, uri);
+
+	if (part == NULL) {
+		hash_table = composer->priv->inline_images;
+		part = g_hash_table_lookup (hash_table, uri);
+	}
+
+	if (part == NULL) {
+		gtk_html_end (html, stream, GTK_HTML_STREAM_ERROR);
+		return;
+	}
+
+	array = g_byte_array_new ();
+	camel_stream = camel_stream_mem_new_with_byte_array (array);
+	wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part));
+	camel_data_wrapper_decode_to_stream (wrapper, camel_stream);
+
+	gtk_html_write (
+		gtkhtml_editor_get_html (editor), stream,
+		(gchar *) array->data, array->len);
+
+	camel_object_unref (camel_stream);
+
+	gtk_html_end (html, stream, GTK_HTML_STREAM_OK);
+}
+
+static void
 msg_composer_class_init (EMsgComposerClass *class)
 {
 	GObjectClass *object_class;
@@ -2199,6 +2383,12 @@
 	editor_class->copy_clipboard = msg_composer_copy_clipboard;
 	editor_class->paste_clipboard = msg_composer_paste_clipboard;
 	editor_class->select_all = msg_composer_select_all;
+	editor_class->command_before = msg_composer_command_before;
+	editor_class->command_after = msg_composer_command_after;
+	editor_class->image_uri = msg_composer_image_uri;
+	editor_class->link_clicked = msg_composer_link_clicked;
+	editor_class->object_deleted = msg_composer_object_deleted;
+	editor_class->uri_requested = msg_composer_uri_requested;
 
 	signals[SEND] = g_signal_new (
 		"send",
@@ -2510,6 +2700,9 @@
 {
 	EMsgComposer *composer;
 	EComposerHeaderTable *table;
+#if 0 /* GTKHTML-EDITOR */
+	EMMenuTargetWidget *target;
+#endif
 	GConfClient *client;
 	GtkToggleAction *action;
 	EMsgComposerPrivate *p;
@@ -2526,7 +2719,12 @@
 		drop_types, G_N_ELEMENTS (drop_types),
 		GDK_ACTION_COPY | GDK_ACTION_ASK | GDK_ACTION_MOVE);
 
-	setup_ui (composer);
+#if 0 /* GTKHTML-EDITOR */
+	/* Setup main menu plugin mechanism. */
+	target = em_menu_target_new_widget (p->menu, (GtkWidget *)composer);
+	e_menu_update_target ((EMenu *)p->menu, target);
+	e_menu_activate ((EMenu *)p->menu, p->uic, TRUE);
+#endif
 
 	/* Configure Headers */
 
@@ -4086,7 +4284,7 @@
 		camel_medium_set_header (
 			CAMEL_MEDIUM (msg), "X-Evolution-Format", flags);
 
-	e_msg_composer_delete (temp_composer);
+	gtk_widget_destroy (GTK_WIDGET (temp_composer));
 	g_free (flags);
 
 	return msg;
@@ -4331,12 +4529,12 @@
 	return array;
 }
 
-EAttachmentBar*
+EAttachmentBar *
 e_msg_composer_get_attachment_bar (EMsgComposer *composer)
 {
-       EMsgComposerPrivate *p = composer->priv;
+	g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL);
 
-       return (EAttachmentBar*) p->attachment_bar;
+	return E_ATTACHMENT_BAR (composer->priv->attachment_bar);
 }
 
 void
@@ -4349,18 +4547,15 @@
 gboolean
 e_msg_composer_request_close_all (void)
 {
-	GSList *p, *pnext;
+	GSList *iter, *next;
 
-	for (p = all_composers; p != NULL; p = pnext) {
-		EMsgComposer *composer = p->data;
-		pnext = p->next;
+	for (iter = all_composers; iter != NULL; iter = next) {
+		EMsgComposer *composer = iter->data;
+		next = iter->next;
 		gtk_action_activate (ACTION (CLOSE));
 	}
 
-	if (all_composers == NULL)
-		return TRUE;
-	else
-		return FALSE;
+	return (all_composers == NULL);
 }
 
 EMsgComposer *
@@ -4384,11 +4579,11 @@
 	composer = e_msg_composer_new_with_message (msg);
 	if (composer != NULL) {
 		g_signal_connect (
-			G_OBJECT (composer), "send",
+			composer, "send",
 			G_CALLBACK (em_utils_composer_send_cb), NULL);
 
 		g_signal_connect (
-			G_OBJECT (composer), "save-draft",
+			composer, "save-draft",
 			G_CALLBACK (em_utils_composer_save_draft_cb), NULL);
 
 		gtk_widget_show (GTK_WIDGET (composer));
@@ -4439,14 +4634,13 @@
 e_msg_composer_set_alternative (EMsgComposer *composer,
                                 gboolean alt)
 {
-	EMsgComposerPrivate *p = composer->priv;
 	GtkhtmlEditor *editor;
 
 	g_return_if_fail (E_IS_MSG_COMPOSER (composer));
 
 	editor = GTKHTML_EDITOR (composer);
 
-	p->is_alternative = alt;
+	composer->priv->is_alternative = alt;
 	gtkhtml_editor_set_html_mode (editor, !alt);
 }
 
@@ -4476,174 +4670,6 @@
 	gtkhtml_editor_run_command (editor, "italic-off");
 }
 
-void
-e_msg_composer_insert_paragraph_before (EMsgComposer *composer)
-{
-	GtkhtmlEditor *editor;
-	const gchar *data;
-
-	g_return_if_fail (E_IS_MSG_COMPOSER (composer));
-
-	if (composer->priv->in_signature_insert)
-		return;
-
-	editor = GTKHTML_EDITOR (composer);
-
-	data = gtkhtml_editor_get_paragraph_data (editor, "orig");
-	if (data != NULL && *data == '1') {
-		gtkhtml_editor_run_command (editor, "text-default-color");
-		gtkhtml_editor_run_command (editor, "italic-off");
-		return;
-	};
-
-	data = gtkhtml_editor_get_paragraph_data (editor, "signature");
-	if (data != NULL && *data == '1') {
-		gtkhtml_editor_run_command (editor, "text-default-color");
-		gtkhtml_editor_run_command (editor, "italic-off");
-	}
-}
-
-static void
-clear_signature (GtkhtmlEditor *editor)
-{
-	if (gtkhtml_editor_is_paragraph_empty (editor))
-		gtkhtml_editor_set_paragraph_data (editor, "signature" ,"0");
-
-	else if (gtkhtml_editor_is_previous_paragraph_empty (editor) &&
-		gtkhtml_editor_run_command (editor, "cursor-backward")) {
-
-		gtkhtml_editor_set_paragraph_data (editor, "signature", "0");
-		gtkhtml_editor_run_command (editor, "cursor-forward");
-	}
-
-	gtkhtml_editor_run_command (editor, "text-default-color");
-	gtkhtml_editor_run_command (editor, "italic-off");
-}
-
-void
-e_msg_composer_insert_paragraph_after (EMsgComposer *composer)
-{
-	GtkhtmlEditor *editor;
-	const gchar *data;
-
-	g_return_if_fail (E_IS_MSG_COMPOSER (composer));
-
-	if (composer->priv->in_signature_insert)
-		return;
-
-	editor = GTKHTML_EDITOR (composer);
-
-	gtkhtml_editor_run_command (editor, "italic-off");
-
-	data = gtkhtml_editor_get_paragraph_data (editor, "orig");
-	if (data != NULL && *data == '1')
-		e_msg_composer_reply_indent (composer);
-	gtkhtml_editor_set_paragraph_data (editor, "orig", "0");
-
-	data = gtkhtml_editor_get_paragraph_data (editor, "signature");
-	if (data != NULL && *data == '1')
-		clear_signature (editor);
-}
-
-void
-e_msg_composer_delete (EMsgComposer *composer)
-{
-	GtkhtmlEditor *editor;
-	const gchar *data;
-
-	g_return_if_fail (E_IS_MSG_COMPOSER (composer));
-
-	editor = GTKHTML_EDITOR (composer);
-
-	if (!gtkhtml_editor_is_paragraph_empty (editor))
-		return;
-
-	data = gtkhtml_editor_get_paragraph_data (editor, "orig");
-	if (data != NULL && *data == '1') {
-		gtkhtml_editor_set_paragraph_data (editor, "orig", "0");
-		gtkhtml_editor_run_command (editor, "indent-zero");
-		gtkhtml_editor_run_command (editor, "style-normal");
-		gtkhtml_editor_run_command (editor, "text-default-color");
-		gtkhtml_editor_run_command (editor, "italic-off");
-		gtkhtml_editor_run_command (editor, "insert-paragraph");
-		gtkhtml_editor_run_command (editor, "delete-back");
-	}
-
-	data = gtkhtml_editor_get_paragraph_data (editor, "signature");
-	if (data != NULL && *data == '1')
-		gtkhtml_editor_set_paragraph_data (editor, "signature", "0");
-}
-
-gchar *
-e_msg_composer_resolve_image_url (EMsgComposer *composer, gchar *url)
-{
-	EMsgComposerPrivate *p = composer->priv;
-	CamelMimePart *part;
-	const gchar *cid;
-
-	part = g_hash_table_lookup (p->inline_images_by_url, url);
-	if (!part && !strncmp (url, "file:", 5)) {
-		part = e_msg_composer_add_inline_image_from_file (composer, url + 5);
-	}
-	if (!part && !strncmp (url, "cid:", 4)) {
-		part = g_hash_table_lookup (p->inline_images, url);
-	}
-	if (!part)
-		return NULL;
-
-	p->current_images  = g_list_prepend (p->current_images, part);
-
-	cid = camel_mime_part_get_content_id (part);
-	if (!cid)
-		return NULL;
-
-	return g_strconcat ("cid:", cid, NULL);
-}
-
-CamelMimePart *
-e_msg_composer_url_requested (EMsgComposer *composer,
-                              const gchar *url)
-{
-	EMsgComposerPrivate *p = composer->priv;
-	CamelMimePart *part = NULL;
-
-	part = g_hash_table_lookup (p->inline_images_by_url, url);
-	if (!part)
-		part = g_hash_table_lookup (p->inline_images, url);
-	if (!part)
-		return NULL;
-
-	return part;
-}
-
-void
-e_msg_composer_link_clicked (EMsgComposer *composer,
-                             const gchar *url)
-{
-	GError *error = NULL;
-
-	g_return_if_fail (composer != NULL);
-
-	if (url == NULL || *url == '\0')
-		return;
-
-	if (g_ascii_strncasecmp (url, "mailto:";, 7) == 0)
-		return;
-
-	if (g_ascii_strncasecmp (url, "thismessage:", 12) == 0)
-		return;
-
-	if (g_ascii_strncasecmp (url, "cid:", 4) == 0)
-		return;
-
-	gnome_url_show (url, &error);
-
-	if (error) {
-		g_warning ("gnome_url_show: %s", error->message);
-		g_error_free (error);
-	}
-}
-
 EComposerHeaderTable *
 e_msg_composer_get_header_table (EMsgComposer *composer)
 {

Modified: branches/mbarnes-composer/composer/e-msg-composer.h
==============================================================================
--- branches/mbarnes-composer/composer/e-msg-composer.h	(original)
+++ branches/mbarnes-composer/composer/e-msg-composer.h	Tue Apr  1 01:49:07 2008
@@ -145,18 +145,6 @@
 						(EMsgComposer *composer);
 
 void		e_msg_composer_reply_indent	(EMsgComposer *composer);
-void		e_msg_composer_insert_paragraph_before
-						(EMsgComposer *composer);
-void		e_msg_composer_insert_paragraph_after
-						(EMsgComposer *composer);
-void		e_msg_composer_delete		(EMsgComposer *composer);
-gchar*		e_msg_composer_resolve_image_url(EMsgComposer *composer,
-						 gchar *url);
-CamelMimePart *	e_msg_composer_url_requested 	(EMsgComposer *composer,
-						 const gchar *url);
-
-void		e_msg_composer_link_clicked	(EMsgComposer *composer,
-						 const gchar *url);
 
 EComposerHeaderTable *
 		e_msg_composer_get_header_table	(EMsgComposer *composer);

Modified: branches/mbarnes-composer/mail/mail-config.c
==============================================================================
--- branches/mbarnes-composer/mail/mail-config.c	(original)
+++ branches/mbarnes-composer/mail/mail-config.c	Tue Apr  1 01:49:07 2008
@@ -215,7 +215,7 @@
 	fprintf (rc, "widget \"*.EMFolderView.*.GtkHTML\" style \"evolution-mail-custom-fonts\"\n");
 	fprintf (rc, "widget \"*.EMFolderBrowser.*.GtkHTML\" style \"evolution-mail-custom-fonts\"\n");
 	fprintf (rc, "widget \"*.EMMessageBrowser.*.GtkHTML\" style \"evolution-mail-custom-fonts\"\n");
-	fprintf (rc, "widget \"*.BonoboPlug.*.GtkHTML\" style \"evolution-mail-custom-fonts\"\n");
+	fprintf (rc, "widget \"EMsgComposer.*.GtkHTML\" style \"evolution-mail-custom-fonts\"\n");
 	fprintf (rc, "widget \"*.EvolutionMailPrintHTMLWidget\" style \"evolution-mail-custom-fonts\"\n");
 	fflush (rc);
 	fclose (rc);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]