aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2011-04-13 22:29:23 +0800
committerMatthew Barnes <mbarnes@redhat.com>2011-04-13 23:00:48 +0800
commit230d74c4640640a083d2bc56325e8db2b4c2172d (patch)
treed96a0f255a0f1e97a3869a7fb1b5ad09a7cb0c38 /widgets
parent1347b66c5e8b51d1eb412688e14cb838a43db828 (diff)
downloadgsoc2013-evolution-230d74c4640640a083d2bc56325e8db2b4c2172d.tar
gsoc2013-evolution-230d74c4640640a083d2bc56325e8db2b4c2172d.tar.gz
gsoc2013-evolution-230d74c4640640a083d2bc56325e8db2b4c2172d.tar.bz2
gsoc2013-evolution-230d74c4640640a083d2bc56325e8db2b4c2172d.tar.lz
gsoc2013-evolution-230d74c4640640a083d2bc56325e8db2b4c2172d.tar.xz
gsoc2013-evolution-230d74c4640640a083d2bc56325e8db2b4c2172d.tar.zst
gsoc2013-evolution-230d74c4640640a083d2bc56325e8db2b4c2172d.zip
EWebView: Implement the EAlertSink interface
Shows alerts directly in the HTML area, similar to GtkInfoBar.
Diffstat (limited to 'widgets')
-rw-r--r--widgets/misc/e-web-view.c123
-rw-r--r--widgets/misc/e-web-view.h3
2 files changed, 116 insertions, 10 deletions
diff --git a/widgets/misc/e-web-view.c b/widgets/misc/e-web-view.c
index ff507d8476..5e25475eca 100644
--- a/widgets/misc/e-web-view.c
+++ b/widgets/misc/e-web-view.c
@@ -14,9 +14,6 @@
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
- *
- * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
- *
*/
#include "e-web-view.h"
@@ -28,12 +25,18 @@
#include <camel/camel.h>
#include <e-util/e-util.h>
+#include <e-util/e-alert-dialog.h>
+#include <e-util/e-alert-sink.h>
#include <e-util/e-extensible.h>
#include <e-util/e-plugin-ui.h>
#include "e-popup-action.h"
#include "e-selectable.h"
+#define E_WEB_VIEW_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_WEB_VIEW, EWebViewPrivate))
+
typedef struct _EWebViewRequest EWebViewRequest;
struct _EWebViewPrivate {
@@ -118,6 +121,7 @@ static const gchar *ui =
"</ui>";
/* Forward Declarations */
+static void e_web_view_alert_sink_init (EAlertSinkInterface *interface);
static void e_web_view_selectable_init (ESelectableInterface *interface);
G_DEFINE_TYPE_WITH_CODE (
@@ -127,6 +131,9 @@ G_DEFINE_TYPE_WITH_CODE (
G_IMPLEMENT_INTERFACE (
E_TYPE_EXTENSIBLE, NULL)
G_IMPLEMENT_INTERFACE (
+ E_TYPE_ALERT_SINK,
+ e_web_view_alert_sink_init)
+ G_IMPLEMENT_INTERFACE (
E_TYPE_SELECTABLE,
e_web_view_selectable_init))
@@ -680,7 +687,7 @@ web_view_dispose (GObject *object)
{
EWebViewPrivate *priv;
- priv = E_WEB_VIEW (object)->priv;
+ priv = E_WEB_VIEW_GET_PRIVATE (object);
if (priv->ui_manager != NULL) {
g_object_unref (priv->ui_manager);
@@ -721,7 +728,7 @@ web_view_finalize (GObject *object)
{
EWebViewPrivate *priv;
- priv = E_WEB_VIEW (object)->priv;
+ priv = E_WEB_VIEW_GET_PRIVATE (object);
/* All URI requests should be complete or cancelled by now. */
if (priv->requests != NULL)
@@ -1049,6 +1056,103 @@ web_view_update_actions (EWebView *web_view)
}
static void
+web_view_submit_alert (EAlertSink *alert_sink,
+ EAlert *alert)
+{
+ GtkIconInfo *icon_info;
+ EWebView *web_view;
+ GtkWidget *dialog;
+ GString *buffer;
+ const gchar *icon_name = NULL;
+ gpointer parent;
+ gint size = 0;
+
+ web_view = E_WEB_VIEW (alert_sink);
+
+ parent = gtk_widget_get_toplevel (GTK_WIDGET (web_view));
+ parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
+
+ /* We use equivalent named icons instead of stock IDs,
+ * since it's easier to get the filename of the icon. */
+ switch (e_alert_get_message_type (alert)) {
+ case GTK_MESSAGE_INFO:
+ icon_name = "dialog-information";
+ break;
+
+ case GTK_MESSAGE_WARNING:
+ icon_name = "dialog-warning";
+ break;
+
+ case GTK_MESSAGE_ERROR:
+ icon_name = "dialog-error";
+ break;
+
+ default:
+ dialog = e_alert_dialog_new (parent, alert);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ return;
+ }
+
+ gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &size, NULL);
+
+ icon_info = gtk_icon_theme_lookup_icon (
+ gtk_icon_theme_get_default (),
+ icon_name, size, GTK_ICON_LOOKUP_NO_SVG);
+ g_return_if_fail (icon_info != NULL);
+
+ buffer = g_string_sized_new (512);
+
+ g_string_append (
+ buffer,
+ "<html>"
+ "<head>"
+ "<meta http-equiv=\"content-type\""
+ " content=\"text/html; charset=utf-8\">"
+ "</head>"
+ "<body>");
+
+ g_string_append (
+ buffer,
+ "<table bgcolor='#000000' width='100%'"
+ " cellpadding='1' cellspacing='0'>"
+ "<tr>"
+ "<td>"
+ "<table bgcolor='#dddddd' width='100%' cellpadding='6'>"
+ "<tr>");
+
+ g_string_append_printf (
+ buffer,
+ "<tr>"
+ "<td valign='top'>"
+ "<img src='%s'/>"
+ "</td>"
+ "<td align='left' width='100%%'>"
+ "<h3>%s</h3>"
+ "%s"
+ "</td>"
+ "</tr>",
+ gtk_icon_info_get_filename (icon_info),
+ e_alert_get_primary_text (alert),
+ e_alert_get_secondary_text (alert));
+
+ g_string_append (
+ buffer,
+ "</table>"
+ "</td>"
+ "</tr>"
+ "</table>"
+ "</body>"
+ "</html>");
+
+ e_web_view_load_string (web_view, buffer->str);
+
+ g_string_free (buffer, TRUE);
+
+ gtk_icon_info_free (icon_info);
+}
+
+static void
web_view_selectable_update_actions (ESelectable *selectable,
EFocusTracker *focus_tracker,
GdkAtom *clipboard_targets,
@@ -1381,6 +1485,12 @@ e_web_view_class_init (EWebViewClass *class)
}
static void
+e_web_view_alert_sink_init (EAlertSinkInterface *interface)
+{
+ interface->submit_alert = web_view_submit_alert;
+}
+
+static void
e_web_view_selectable_init (ESelectableInterface *interface)
{
interface->update_actions = web_view_selectable_update_actions;
@@ -1401,8 +1511,7 @@ e_web_view_init (EWebView *web_view)
const gchar *id;
GError *error = NULL;
- web_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (
- web_view, E_TYPE_WEB_VIEW, EWebViewPrivate);
+ web_view->priv = E_WEB_VIEW_GET_PRIVATE (web_view);
ui_manager = gtk_ui_manager_new ();
web_view->priv->ui_manager = ui_manager;
diff --git a/widgets/misc/e-web-view.h b/widgets/misc/e-web-view.h
index 1ad87c6756..723d942cce 100644
--- a/widgets/misc/e-web-view.h
+++ b/widgets/misc/e-web-view.h
@@ -14,9 +14,6 @@
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
- *
- * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
- *
*/
/* This is intended to serve as a common base class for all HTML viewing