Commit c85ac1fc authored by Milan Crha's avatar Milan Crha
Browse files

Reuse WebDAV discovery dialog in Google and CalDAV calendar configs

parent 9001fb60
......@@ -156,7 +156,6 @@ evolution_util_include_HEADERS = \
e-cell-percent.h \
e-cell-pixbuf.h \
e-cell-popup.h \
e-cell-renderer-color.h \
e-cell-size.h \
e-cell-text.h \
e-cell-toggle.h \
......@@ -429,7 +428,6 @@ libevolution_util_la_SOURCES = \
e-cell-percent.c \
e-cell-pixbuf.c \
e-cell-popup.c \
e-cell-renderer-color.c \
e-cell-size.c \
e-cell-text.c \
e-cell-toggle.c \
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-cell-renderer-color.c
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "e-cell-renderer-color.h"
#include <string.h>
#include <glib/gi18n-lib.h>
#define E_CELL_RENDERER_COLOR_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_CELL_RENDERER_COLOR, ECellRendererColorPrivate))
enum {
PROP_0,
PROP_COLOR
};
struct _ECellRendererColorPrivate {
GdkColor *color;
};
G_DEFINE_TYPE (
ECellRendererColor,
e_cell_renderer_color,
GTK_TYPE_CELL_RENDERER)
static void
cell_renderer_color_get_size (GtkCellRenderer *cell,
GtkWidget *widget,
const GdkRectangle *cell_area,
gint *x_offset,
gint *y_offset,
gint *width,
gint *height)
{
gint color_width = 16;
gint color_height = 16;
gint calc_width;
gint calc_height;
gfloat xalign;
gfloat yalign;
guint xpad;
guint ypad;
g_object_get (
cell, "xalign", &xalign, "yalign", &yalign,
"xpad", &xpad, "ypad", &ypad, NULL);
calc_width = (gint) xpad * 2 + color_width;
calc_height = (gint) ypad * 2 + color_height;
if (cell_area && color_width > 0 && color_height > 0) {
if (x_offset) {
*x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
(1.0 - xalign) : xalign) *
(cell_area->width - calc_width));
*x_offset = MAX (*x_offset, 0);
}
if (y_offset) {
*y_offset =(yalign *
(cell_area->height - calc_height));
*y_offset = MAX (*y_offset, 0);
}
} else {
if (x_offset) *x_offset = 0;
if (y_offset) *y_offset = 0;
}
if (width)
*width = calc_width;
if (height)
*height = calc_height;
}
static void
cell_renderer_color_render (GtkCellRenderer *cell,
cairo_t *cr,
GtkWidget *widget,
const GdkRectangle *background_area,
const GdkRectangle *cell_area,
GtkCellRendererState flags)
{
ECellRendererColorPrivate *priv;
GdkRectangle pix_rect;
GdkRectangle draw_rect;
GdkRGBA rgba;
guint xpad;
guint ypad;
priv = E_CELL_RENDERER_COLOR_GET_PRIVATE (cell);
if (priv->color == NULL)
return;
cell_renderer_color_get_size (
cell, widget, cell_area,
&pix_rect.x, &pix_rect.y,
&pix_rect.width, &pix_rect.height);
g_object_get (cell, "xpad", &xpad, "ypad", &ypad, NULL);
pix_rect.x += cell_area->x + xpad;
pix_rect.y += cell_area->y + ypad;
pix_rect.width -= xpad * 2;
pix_rect.height -= ypad * 2;
if (!gdk_rectangle_intersect (cell_area, &pix_rect, &draw_rect))
return;
rgba.red = priv->color->red / 65535.0;
rgba.green = priv->color->green / 65535.0;
rgba.blue = priv->color->blue / 65535.0;
rgba.alpha = 1.0;
gdk_cairo_set_source_rgba (cr, &rgba);
cairo_rectangle (cr, pix_rect.x, pix_rect.y, draw_rect.width, draw_rect.height);
cairo_fill (cr);
}
static void
cell_renderer_color_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
ECellRendererColorPrivate *priv;
priv = E_CELL_RENDERER_COLOR_GET_PRIVATE (object);
switch (property_id) {
case PROP_COLOR:
if (priv->color != NULL)
gdk_color_free (priv->color);
priv->color = g_value_dup_boxed (value);
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
cell_renderer_color_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
ECellRendererColorPrivate *priv;
priv = E_CELL_RENDERER_COLOR_GET_PRIVATE (object);
switch (property_id) {
case PROP_COLOR:
g_value_set_boxed (value, priv->color);
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
cell_renderer_color_finalize (GObject *object)
{
ECellRendererColorPrivate *priv;
priv = E_CELL_RENDERER_COLOR_GET_PRIVATE (object);
if (priv->color != NULL)
gdk_color_free (priv->color);
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (e_cell_renderer_color_parent_class)->finalize (object);
}
static void
e_cell_renderer_color_class_init (ECellRendererColorClass *class)
{
GObjectClass *object_class;
GtkCellRendererClass *cell_class;
g_type_class_add_private (class, sizeof (ECellRendererColorPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->set_property = cell_renderer_color_set_property;
object_class->get_property = cell_renderer_color_get_property;
object_class->finalize = cell_renderer_color_finalize;
cell_class = GTK_CELL_RENDERER_CLASS (class);
cell_class->get_size = cell_renderer_color_get_size;
cell_class->render = cell_renderer_color_render;
g_object_class_install_property (
object_class,
PROP_COLOR,
g_param_spec_boxed (
"color",
"Color Info",
"The color to render",
GDK_TYPE_COLOR,
G_PARAM_READWRITE));
}
static void
e_cell_renderer_color_init (ECellRendererColor *cellcolor)
{
cellcolor->priv = E_CELL_RENDERER_COLOR_GET_PRIVATE (cellcolor);
g_object_set (cellcolor, "xpad", 4, NULL);
}
/**
* e_cell_renderer_color_new:
*
* Since: 2.22
**/
GtkCellRenderer *
e_cell_renderer_color_new (void)
{
return g_object_new (E_TYPE_CELL_RENDERER_COLOR, NULL);
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-cell-renderer-color.h
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION)
#error "Only <e-util/e-util.h> should be included directly."
#endif
#ifndef _E_CELL_RENDERER_COLOR_H_
#define _E_CELL_RENDERER_COLOR_H_
#include <gtk/gtk.h>
/* Standard GObject macros */
#define E_TYPE_CELL_RENDERER_COLOR \
(e_cell_renderer_color_get_type ())
#define E_CELL_RENDERER_COLOR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST \
((obj), E_TYPE_CELL_RENDERER_COLOR, ECellRendererColor))
#define E_CELL_RENDERER_COLOR_CLASS(cls) \
(G_TYPE_CHECK_CLASS_CAST \
((cls), E_TYPE_CELL_RENDERER_COLOR, ECellRendererColorClass))
#define E_IS_CELL_RENDERER_COLOR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE \
((obj), E_TYPE_CELL_RENDERER_COLOR))
#define E_IS_CELL_RENDERER_COLOR_CLASS(cls) \
(G_TYPE_CHECK_CLASS_TYPE ((cls), E_TYPE_CELL_RENDERER_COLOR))
#define E_CELL_RENDERER_COLOR_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS \
((obj), E_TYPE_CELL_RENDERER_COLOR, ECellRendererColorClass))
G_BEGIN_DECLS
typedef struct _ECellRendererColor ECellRendererColor;
typedef struct _ECellRendererColorClass ECellRendererColorClass;
typedef struct _ECellRendererColorPrivate ECellRendererColorPrivate;
/**
* ECellRendererColor:
*
* Since: 2.22
**/
struct _ECellRendererColor {
GtkCellRenderer parent;
ECellRendererColorPrivate *priv;
};
struct _ECellRendererColorClass {
GtkCellRendererClass parent_class;
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
};
GType e_cell_renderer_color_get_type (void) G_GNUC_CONST;
GtkCellRenderer *e_cell_renderer_color_new (void);
G_END_DECLS
#endif /* _E_CELL_RENDERER_COLOR_H_ */
......@@ -20,8 +20,9 @@
#include <config.h>
#endif
#include <libedataserverui/libedataserverui.h>
#include "e-source-combo-box.h"
#include "e-cell-renderer-color.h"
#define E_SOURCE_COMBO_BOX_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
......@@ -47,7 +48,7 @@ enum {
};
enum {
COLUMN_COLOR, /* GDK_TYPE_COLOR */
COLUMN_COLOR, /* GDK_TYPE_RGBA */
COLUMN_NAME, /* G_TYPE_STRING */
COLUMN_SENSITIVE, /* G_TYPE_BOOLEAN */
COLUMN_UID, /* G_TYPE_STRING */
......@@ -65,7 +66,7 @@ source_combo_box_traverse (GNode *node,
GtkTreeModel *model;
GtkTreeIter iter;
GString *indented;
GdkColor color;
GdkRGBA rgba;
const gchar *ext_name;
const gchar *display_name;
const gchar *uid;
......@@ -104,12 +105,12 @@ source_combo_box_traverse (GNode *node,
color_spec = e_source_selectable_get_color (extension);
if (color_spec != NULL && *color_spec != '\0')
use_color = gdk_color_parse (color_spec, &color);
use_color = gdk_rgba_parse (&rgba, color_spec);
}
gtk_list_store_set (
GTK_LIST_STORE (model), &iter,
COLUMN_COLOR, use_color ? &color : NULL,
COLUMN_COLOR, use_color ? &rgba : NULL,
COLUMN_NAME, indented->str,
COLUMN_SENSITIVE, sensitive,
COLUMN_UID, uid,
......@@ -326,7 +327,7 @@ source_combo_box_constructed (GObject *object)
store = gtk_list_store_new (
NUM_COLUMNS,
GDK_TYPE_COLOR, /* COLUMN_COLOR */
GDK_TYPE_RGBA, /* COLUMN_COLOR */
G_TYPE_STRING, /* COLUMN_NAME */
G_TYPE_BOOLEAN, /* COLUMN_SENSITIVE */
G_TYPE_STRING); /* COLUMN_UID */
......@@ -343,7 +344,7 @@ source_combo_box_constructed (GObject *object)
gtk_cell_layout_pack_start (layout, renderer, FALSE);
gtk_cell_layout_set_attributes (
layout, renderer,
"color", COLUMN_COLOR,
"rgba", COLUMN_COLOR,
"sensitive", COLUMN_SENSITIVE,
NULL);
......
......@@ -24,7 +24,8 @@
#include <string.h>
#include "e-cell-renderer-color.h"
#include <libedataserverui/libedataserverui.h>
#include "e-source-selector.h"
#define E_SOURCE_SELECTOR_GET_PRIVATE(obj) \
......@@ -1707,7 +1708,7 @@ e_source_selector_init (ESourceSelector *selector)
tree_store = gtk_tree_store_new (
NUM_COLUMNS,
G_TYPE_STRING, /* COLUMN_NAME */
GDK_TYPE_COLOR, /* COLUMN_COLOR */
GDK_TYPE_RGBA, /* COLUMN_COLOR */
G_TYPE_BOOLEAN, /* COLUMN_ACTIVE */
G_TYPE_STRING, /* COLUMN_ICON_NAME */
G_TYPE_BOOLEAN, /* COLUMN_SHOW_COLOR */
......@@ -1730,7 +1731,7 @@ e_source_selector_init (ESourceSelector *selector)
GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
gtk_tree_view_column_pack_start (column, renderer, FALSE);
gtk_tree_view_column_add_attribute (
column, renderer, "color", COLUMN_COLOR);
column, renderer, "rgba", COLUMN_COLOR);
gtk_tree_view_column_add_attribute (
column, renderer, "visible", COLUMN_SHOW_COLOR);
......@@ -2571,7 +2572,7 @@ e_source_selector_update_row (ESourceSelector *selector,
extension = e_source_get_extension (source, extension_name);
if (extension != NULL) {
GdkColor color;
GdkRGBA rgba;
const gchar *color_spec = NULL;
const gchar *icon_name;
gboolean show_color;
......@@ -2587,7 +2588,7 @@ e_source_selector_update_row (ESourceSelector *selector,
E_SOURCE_SELECTABLE (extension));
if (color_spec != NULL && *color_spec != '\0')
show_color = gdk_color_parse (color_spec, &color);
show_color = gdk_rgba_parse (&rgba, color_spec);
show_icons = e_source_selector_get_show_icons (selector);
icon_name = source_selector_get_icon_name (selector, source);
......@@ -2597,7 +2598,7 @@ e_source_selector_update_row (ESourceSelector *selector,
gtk_tree_store_set (
GTK_TREE_STORE (model), &iter,
COLUMN_NAME, display_name,
COLUMN_COLOR, show_color ? &color : NULL,
COLUMN_COLOR, show_color ? &rgba : NULL,
COLUMN_ACTIVE, selected,
COLUMN_ICON_NAME, icon_name,
COLUMN_SHOW_COLOR, show_color,
......
......@@ -69,7 +69,6 @@
#include <e-util/e-cell-percent.h>
#include <e-util/e-cell-pixbuf.h>
#include <e-util/e-cell-popup.h>
#include <e-util/e-cell-renderer-color.h>
#include <e-util/e-cell-size.h>
#include <e-util/e-cell-text.h>
#include <e-util/e-cell-toggle.h>
......
......@@ -11,11 +11,7 @@ module_cal_config_caldav_la_CPPFLAGS = \
$(NULL)
module_cal_config_caldav_la_SOURCES = \
evolution-cal-config-caldav.c \
e-caldav-chooser.c \
e-caldav-chooser.h \
e-caldav-chooser-dialog.c \
e-caldav-chooser-dialog.h
evolution-cal-config-caldav.c
module_cal_config_caldav_la_LIBADD = \
$(top_builddir)/e-util/libevolution-util.la \
......
/*
* e-caldav-chooser-dialog.c
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include "e-caldav-chooser-dialog.h"
#include <config.h>
#include <glib/gi18n-lib.h>
#define E_CALDAV_CHOOSER_DIALOG_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_CALDAV_CHOOSER_DIALOG, ECaldavChooserDialogPrivate))
struct _ECaldavChooserDialogPrivate {
ECaldavChooser *chooser;
GCancellable *cancellable;
GtkWidget *info_bar; /* not referenced */
GtkWidget *info_bar_label; /* not referenced */
};
enum {
PROP_0,
PROP_CHOOSER
};
/* Forward Declarations */
static void caldav_chooser_dialog_populated_cb
(GObject *source_object,
GAsyncResult *result,
gpointer user_data);
static void caldav_chooser_dialog_credentials_prompt_cb
(GObject *source_object,
GAsyncResult *result,
gpointer user_data);
G_DEFINE_DYNAMIC_TYPE (
ECaldavChooserDialog,
e_caldav_chooser_dialog,
GTK_TYPE_DIALOG)
static void
caldav_chooser_dialog_done (ECaldavChooserDialog *dialog,
const GError *error)
{
GdkWindow *window;
/* Reset the mouse cursor to normal. */
window = gtk_widget_get_window (GTK_WIDGET (dialog));
gdk_window_set_cursor (window, NULL);
if (error != NULL) {
GtkLabel *label;
label = GTK_LABEL (dialog->priv->info_bar_label);
gtk_label_set_text (label, error->message);
gtk_widget_show (dialog->priv->info_bar);
}
}
/* It's a little weird to have the callback called on the #ESource,
but it's simpler than writing a proxy around the e-trust-prompt
async call, which would be unnecessary anyway. */
static void
caldav_chooser_dialog_trust_prompt_done_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
ECaldavChooserDialog *dialog;
ECaldavChooser *chooser;
ETrustPromptResponse response = E_TRUST_PROMPT_RESPONSE_UNKNOWN;
GError *error = NULL;
g_return_if_fail (E_IS_SOURCE (source_object));
g_return_if_fail (E_IS_CALDAV_CHOOSER_DIALOG (user_data));
dialog = E_CALDAV_CHOOSER_DIALOG (user_data);
chooser = e_caldav_chooser_dialog_get_chooser (dialog);
if (!e_trust_prompt_run_for_source_finish (E_SOURCE (source_object), result, &response, &error)) {
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
/* close also the dialog */
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
} else {
caldav_chooser_dialog_done (dialog, error);
}
} else if (response == E_TRUST_PROMPT_RESPONSE_ACCEPT ||
response == E_TRUST_PROMPT_RESPONSE_ACCEPT_TEMPORARILY) {
e_caldav_chooser_populate (
chooser, dialog->priv->cancellable,
caldav_chooser_dialog_populated_cb,
g_object_ref (dialog));
} else {
g_warn_if_fail (error == NULL);
error = e_caldav_chooser_new_ssl_trust_error (chooser);
caldav_chooser_dialog_done (dialog, error);
}
g_clear_error (&error);
g_object_unref (dialog);
}
static void
caldav_chooser_dialog_authenticate_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
ECaldavChooserDialog *dialog = user_data;
ECaldavChooser *chooser;
GError *error = NULL;
g_return_if_fail (E_IS_CALDAV_CHOOSER (source_object));
chooser = E_CALDAV_CHOOSER (source_object);
if (!e_caldav_chooser_authenticate_finish (chooser, result, &error)) {
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
/* close also the dialog */
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
} else if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED)) {
e_caldav_chooser_run_credentials_prompt (
chooser,
caldav_chooser_dialog_credentials_prompt_cb,
g_object_ref (dialog));
} else if (g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_SSL_FAILED)) {
e_caldav_chooser_run_trust_prompt (chooser, GTK_WINDOW (dialog),
dialog->priv->cancellable,
caldav_chooser_dialog_trust_prompt_done_cb,
g_object_ref (dialog));