Show common addressbook and calendar errors in an alert sink

This commit is contained in:
Milan Crha
2010-12-14 17:44:16 +01:00
parent ffa69c8bef
commit a6bce7b74b
11 changed files with 80 additions and 74 deletions

View File

@ -208,7 +208,7 @@ e_contact_editor_contact_added (EABEditor *editor,
if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
return;
eab_error_dialog (_("Error adding contact"), error);
eab_error_dialog (NULL, _("Error adding contact"), error);
}
static void
@ -222,7 +222,7 @@ e_contact_editor_contact_modified (EABEditor *editor,
if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
return;
eab_error_dialog (_("Error modifying contact"), error);
eab_error_dialog (NULL, _("Error modifying contact"), error);
}
static void
@ -236,7 +236,7 @@ e_contact_editor_contact_deleted (EABEditor *editor,
if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
return;
eab_error_dialog (_("Error removing contact"), error);
eab_error_dialog (NULL, _("Error removing contact"), error);
}
static void
@ -2735,7 +2735,7 @@ contact_editor_book_loaded_cb (ESource *source,
g_warn_if_fail (book == NULL);
parent = eab_editor_get_window (EAB_EDITOR (editor));
eab_load_error_dialog (GTK_WIDGET (parent), source, error);
eab_load_error_dialog (GTK_WIDGET (parent), NULL, source, error);
source_combo_box = e_builder_get_widget (
editor->builder, "source-combo-box-source");

View File

@ -221,7 +221,7 @@ contact_list_editor_book_loaded_cb (ESource *source,
GtkWindow *parent;
parent = eab_editor_get_window (EAB_EDITOR (editor));
eab_load_error_dialog (GTK_WIDGET (parent), source, error);
eab_load_error_dialog (GTK_WIDGET (parent), NULL, source, error);
e_source_combo_box_set_active (
E_SOURCE_COMBO_BOX (WIDGET (SOURCE_MENU)),
@ -1157,7 +1157,7 @@ contact_list_editor_contact_added (EABEditor *editor,
if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
return;
eab_error_dialog (_("Error adding list"), error);
eab_error_dialog (NULL, _("Error adding list"), error);
}
static void
@ -1171,7 +1171,7 @@ contact_list_editor_contact_modified (EABEditor *editor,
if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
return;
eab_error_dialog (_("Error modifying list"), error);
eab_error_dialog (NULL, _("Error modifying list"), error);
}
static void
@ -1185,7 +1185,7 @@ contact_list_editor_contact_deleted (EABEditor *editor,
if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED))
return;
eab_error_dialog (_("Error removing list"), error);
eab_error_dialog (NULL, _("Error removing list"), error);
}
static void

View File

@ -324,7 +324,7 @@ book_view_loaded (EBook *book,
EAddressbookModel *model = closure;
if (error) {
eab_error_dialog (_("Error getting book view"), error);
eab_error_dialog (NULL, _("Error getting book view"), error);
return;
}

View File

@ -147,7 +147,7 @@ contact_modified_cb (EBook* book, const GError *error,
gpointer user_data)
{
if (error)
eab_error_dialog (_("Error modifying card"), error);
eab_error_dialog (NULL, _("Error modifying card"), error);
}
static void

View File

@ -1099,11 +1099,12 @@ search_result (EAddressbookView *view,
const gchar *error_msg)
{
EShellView *shell_view;
EShellWindow *shell_window;
EAlertSink *alert_sink;
shell_view = e_addressbook_view_get_shell_view (view);
shell_window = e_shell_view_get_shell_window (shell_view);
eab_search_result_dialog (GTK_WIDGET (shell_window), status, error_msg);
alert_sink = E_ALERT_SINK (e_shell_view_get_shell_content (shell_view));
eab_search_result_dialog (alert_sink, status, error_msg);
}
static void
@ -1141,18 +1142,17 @@ static void
backend_died (EAddressbookView *view)
{
EShellView *shell_view;
EShellWindow *shell_window;
EAlertSink *alert_sink;
EAddressbookModel *model;
EBook *book;
shell_view = e_addressbook_view_get_shell_view (view);
shell_window = e_shell_view_get_shell_window (shell_view);
alert_sink = E_ALERT_SINK (e_shell_view_get_shell_content (shell_view));
model = e_addressbook_view_get_model (view);
book = e_addressbook_model_get_book (model);
e_alert_run_dialog_for_args (
GTK_WINDOW (shell_window),
e_alert_submit (alert_sink,
"addressbook:backend-died",
e_book_get_uri (book), NULL);
}
@ -1277,7 +1277,7 @@ delete_contacts_cb (EBook *book, const GError *error, gpointer closure)
break;
default :
/* Unknown error */
eab_error_dialog (_("Failed to delete contact"), error);
eab_error_dialog (NULL, _("Failed to delete contact"), error);
break;
}
}
@ -1520,10 +1520,12 @@ view_transfer_contacts (EAddressbookView *view,
{
EBook *book;
GList *contacts = NULL;
GtkWindow *parent;
EShellView *shell_view;
EAlertSink *alert_sink;
book = e_addressbook_model_get_book (view->priv->model);
parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
shell_view = e_addressbook_view_get_shell_view (view);
alert_sink = E_ALERT_SINK (e_shell_view_get_shell_content (shell_view));
if (all) {
EBookQuery *query;
@ -1534,8 +1536,8 @@ view_transfer_contacts (EAddressbookView *view,
e_book_query_unref (query);
if (error) {
e_alert_run_dialog_for_args (
parent, "addressbook:search-error",
e_alert_submit (
alert_sink, "addressbook:search-error",
error->message, NULL);
g_error_free (error);
return;
@ -1544,7 +1546,7 @@ view_transfer_contacts (EAddressbookView *view,
contacts = e_addressbook_view_get_selected (view);
}
eab_transfer_contacts (book, contacts, delete_from_source, parent);
eab_transfer_contacts (book, contacts, delete_from_source, alert_sink);
g_object_unref (book);
}

View File

@ -47,19 +47,25 @@
#include <camel/camel.h>
void
eab_error_dialog (const gchar *msg, const GError *error)
eab_error_dialog (EAlertSink *alert_sink, const gchar *msg, const GError *error)
{
if (error && error->message)
e_alert_run_dialog_for_args (e_shell_get_active_window (NULL),
"addressbook:generic-error",
msg, error->message, NULL);
if (error && error->message) {
if (alert_sink)
e_alert_submit (alert_sink,
"addressbook:generic-error",
msg, error->message, NULL);
else
e_alert_run_dialog_for_args (
e_shell_get_active_window (NULL),
"addressbook:generic-error",
msg, error->message, NULL);
}
}
void
eab_load_error_dialog (GtkWidget *parent, ESource *source, const GError *error)
eab_load_error_dialog (GtkWidget *parent, EAlertSink *alert_sink, ESource *source, const GError *error)
{
gchar *label_string, *label = NULL, *uri;
GtkWidget *dialog;
gboolean can_detail_error = TRUE;
g_return_if_fail (source != NULL);
@ -130,16 +136,22 @@ eab_load_error_dialog (GtkWidget *parent, ESource *source, const GError *error)
}
}
dialog = e_alert_dialog_new_for_args ((GtkWindow *) parent, "addressbook:load-error", label_string, NULL);
g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
if (alert_sink) {
e_alert_submit (alert_sink, "addressbook:load-error", label_string, NULL);
} else {
GtkWidget *dialog;
dialog = e_alert_dialog_new_for_args ((GtkWindow *) parent, "addressbook:load-error", label_string, NULL);
g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
gtk_widget_show (dialog);
}
gtk_widget_show (dialog);
g_free (label);
g_free (uri);
}
void
eab_search_result_dialog (GtkWidget *parent,
eab_search_result_dialog (EAlertSink *alert_sink,
EBookViewStatus status,
const gchar *error_msg)
{
@ -181,7 +193,7 @@ eab_search_result_dialog (GtkWidget *parent,
g_return_if_reached ();
}
e_alert_run_dialog_for_args ((GtkWindow *) parent, "addressbook:search-error", str, NULL);
e_alert_submit (alert_sink, "addressbook:search-error", str, NULL);
g_free (str);
}
@ -318,6 +330,7 @@ struct ContactCopyProcess_ {
EBook *source;
EBook *destination;
ContactCopyDone done_cb;
EAlertSink *alert_sink;
};
static void
@ -365,7 +378,7 @@ contact_added_cb (EBook* book, const GError *error, const gchar *id, gpointer us
if (error && !g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED)) {
process->book_status = FALSE;
eab_error_dialog (_("Error adding contact"), error);
eab_error_dialog (process->alert_sink, _("Error adding contact"), error);
}
else if (g_error_matches (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED)) {
process->book_status = FALSE;
@ -421,12 +434,13 @@ void
eab_transfer_contacts (EBook *source_book,
GList *contacts /* adopted */,
gboolean delete_from_source,
GtkWindow *parent_window)
EAlertSink *alert_sink)
{
ESource *destination;
static gchar *last_uid = NULL;
ContactCopyProcess *process;
gchar *desc;
GtkWindow *window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (alert_sink)));
g_return_if_fail (E_IS_BOOK (source_book));
@ -450,7 +464,7 @@ eab_transfer_contacts (EBook *source_book,
destination = eab_select_source (
e_book_get_source (source_book),
desc, NULL, last_uid, parent_window);
desc, NULL, last_uid, window);
if (!destination)
return;
@ -466,6 +480,7 @@ eab_transfer_contacts (EBook *source_book,
process->source = g_object_ref (source_book);
process->contacts = contacts;
process->destination = NULL;
process->alert_sink = alert_sink;
if (delete_from_source)
process->done_cb = delete_contacts;
@ -473,7 +488,7 @@ eab_transfer_contacts (EBook *source_book,
process->done_cb = NULL;
e_load_book_source_async (
destination, parent_window, NULL,
destination, window, NULL,
(GAsyncReadyCallback) book_loaded_cb, process);
}

View File

@ -26,22 +26,25 @@
#include <gtk/gtk.h>
#include <libebook/e-book.h>
#include "e-util/e-alert-sink.h"
G_BEGIN_DECLS
void eab_error_dialog (const gchar *msg,
void eab_error_dialog (EAlertSink *alert_sink,
const gchar *msg,
const GError *error);
void eab_load_error_dialog (GtkWidget *parent,
EAlertSink *alert_sink,
ESource *source,
const GError *error);
void eab_search_result_dialog (GtkWidget *parent,
void eab_search_result_dialog (EAlertSink *alert_sink,
EBookViewStatus status,
const gchar *error_msg);
gint eab_prompt_save_dialog (GtkWindow *parent);
void eab_transfer_contacts (EBook *source_book,
GList *contacts, /* adopted */
gboolean delete_from_source,
GtkWindow *parent_window);
EAlertSink *alert_sink);
gchar * eab_suggest_filename (GList *contact_list);
ESource * eab_select_source (ESource *except_source,
const gchar *title,

View File

@ -197,8 +197,15 @@ book_shell_view_loaded_cb (ESource *source,
e_addressbook_model_set_book (model, book);
e_addressbook_model_force_folder_bar_message (model);
} else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
eab_load_error_dialog (NULL /* XXX */, source, error);
} else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
EShellView *shell_view;
EAlertSink *alert_sink;
shell_view = e_addressbook_view_get_shell_view (view);
alert_sink = E_ALERT_SINK (e_shell_view_get_shell_content (shell_view));
eab_load_error_dialog (NULL, alert_sink, source, error);
}
if (error != NULL)
g_error_free (error);

View File

@ -161,13 +161,11 @@ cal_shell_sidebar_client_opened_cb (ECalShellSidebar *cal_shell_sidebar,
ECal *client)
{
EShellView *shell_view;
EShellWindow *shell_window;
EShellSidebar *shell_sidebar;
const gchar *message;
shell_sidebar = E_SHELL_SIDEBAR (cal_shell_sidebar);
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_window = e_shell_view_get_shell_window (shell_view);
if (g_error_matches (error, E_CALENDAR_ERROR,
E_CALENDAR_STATUS_AUTHENTICATION_FAILED) ||
@ -188,16 +186,14 @@ cal_shell_sidebar_client_opened_cb (ECalShellSidebar *cal_shell_sidebar,
return;
case E_CALENDAR_STATUS_REPOSITORY_OFFLINE:
e_alert_run_dialog_for_args (
GTK_WINDOW (shell_window),
e_alert_submit (E_ALERT_SINK (e_shell_view_get_shell_content (shell_view)),
"calendar:prompt-no-contents-offline-calendar",
NULL);
/* fall through */
default:
if (error->code != E_CALENDAR_STATUS_REPOSITORY_OFFLINE) {
e_alert_run_dialog_for_args (
GTK_WINDOW (shell_window),
e_alert_submit (E_ALERT_SINK (e_shell_view_get_shell_content (shell_view)),
"calendar:failed-open-calendar",
error->message, NULL);
}
@ -226,7 +222,6 @@ cal_shell_sidebar_default_loaded_cb (ESource *source,
EShellSidebar *shell_sidebar)
{
ECalShellSidebarPrivate *priv;
EShellWindow *shell_window;
EShellView *shell_view;
ECal *client;
GError *error = NULL;
@ -234,7 +229,6 @@ cal_shell_sidebar_default_loaded_cb (ESource *source,
priv = E_CAL_SHELL_SIDEBAR_GET_PRIVATE (shell_sidebar);
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_window = e_shell_view_get_shell_window (shell_view);
client = e_load_cal_source_finish (source, result, &error);
@ -243,8 +237,7 @@ cal_shell_sidebar_default_loaded_cb (ESource *source,
goto exit;
} else if (error != NULL) {
e_alert_run_dialog_for_args (
GTK_WINDOW (shell_window),
e_alert_submit (E_ALERT_SINK (e_shell_view_get_shell_content (shell_view)),
"calendar:failed-open-calendar",
error->message, NULL);
g_error_free (error);

View File

@ -169,13 +169,11 @@ memo_shell_sidebar_client_opened_cb (EMemoShellSidebar *memo_shell_sidebar,
ECal *client)
{
EShellView *shell_view;
EShellWindow *shell_window;
EShellSidebar *shell_sidebar;
const gchar *message;
shell_sidebar = E_SHELL_SIDEBAR (memo_shell_sidebar);
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_window = e_shell_view_get_shell_window (shell_view);
if (g_error_matches (error, E_CALENDAR_ERROR,
E_CALENDAR_STATUS_AUTHENTICATION_FAILED) ||
@ -196,16 +194,14 @@ memo_shell_sidebar_client_opened_cb (EMemoShellSidebar *memo_shell_sidebar,
return;
case E_CALENDAR_STATUS_REPOSITORY_OFFLINE:
e_alert_run_dialog_for_args (
GTK_WINDOW (shell_window),
e_alert_submit (get_alert_sink (shell_view),
"calendar:prompt-no-contents-offline-memos",
NULL);
/* fall through */
default:
if (error->code != E_CALENDAR_STATUS_REPOSITORY_OFFLINE) {
e_alert_run_dialog_for_args (
GTK_WINDOW (shell_window),
e_alert_submit (get_alert_sink (shell_view),
"calendar:failed-open-memos",
error->message, NULL);
}
@ -234,7 +230,6 @@ memo_shell_sidebar_default_loaded_cb (ESource *source,
EShellSidebar *shell_sidebar)
{
EMemoShellSidebarPrivate *priv;
EShellWindow *shell_window;
EShellView *shell_view;
ECal *client;
GError *error = NULL;
@ -242,7 +237,6 @@ memo_shell_sidebar_default_loaded_cb (ESource *source,
priv = E_MEMO_SHELL_SIDEBAR_GET_PRIVATE (shell_sidebar);
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_window = e_shell_view_get_shell_window (shell_view);
client = e_load_cal_source_finish (source, result, &error);
@ -251,8 +245,7 @@ memo_shell_sidebar_default_loaded_cb (ESource *source,
goto exit;
} else if (error != NULL) {
e_alert_run_dialog_for_args (
GTK_WINDOW (shell_window),
e_alert_submit (get_alert_sink (shell_view),
"calendar:failed-open-memos",
error->message, NULL);
g_error_free (error);

View File

@ -169,13 +169,11 @@ task_shell_sidebar_client_opened_cb (ETaskShellSidebar *task_shell_sidebar,
ECal *client)
{
EShellView *shell_view;
EShellWindow *shell_window;
EShellSidebar *shell_sidebar;
const gchar *message;
shell_sidebar = E_SHELL_SIDEBAR (task_shell_sidebar);
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_window = e_shell_view_get_shell_window (shell_view);
if (g_error_matches (error, E_CALENDAR_ERROR,
E_CALENDAR_STATUS_AUTHENTICATION_FAILED) ||
@ -196,16 +194,14 @@ task_shell_sidebar_client_opened_cb (ETaskShellSidebar *task_shell_sidebar,
return;
case E_CALENDAR_STATUS_REPOSITORY_OFFLINE:
e_alert_run_dialog_for_args (
GTK_WINDOW (shell_window),
e_alert_submit (get_alert_sink (shell_view),
"calendar:prompt-no-contents-offline-tasks",
NULL);
/* fall through */
default:
if (error->code != E_CALENDAR_STATUS_REPOSITORY_OFFLINE) {
e_alert_run_dialog_for_args (
GTK_WINDOW (shell_window),
e_alert_submit (get_alert_sink (shell_view),
"calendar:failed-open-tasks",
error->message, NULL);
}
@ -234,7 +230,6 @@ task_shell_sidebar_default_loaded_cb (ESource *source,
EShellSidebar *shell_sidebar)
{
ETaskShellSidebarPrivate *priv;
EShellWindow *shell_window;
EShellView *shell_view;
ECal *client;
GError *error = NULL;
@ -242,7 +237,6 @@ task_shell_sidebar_default_loaded_cb (ESource *source,
priv = E_TASK_SHELL_SIDEBAR_GET_PRIVATE (shell_sidebar);
shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
shell_window = e_shell_view_get_shell_window (shell_view);
client = e_load_cal_source_finish (source, result, &error);
@ -251,8 +245,7 @@ task_shell_sidebar_default_loaded_cb (ESource *source,
goto exit;
} else if (error != NULL) {
e_alert_run_dialog_for_args (
GTK_WINDOW (shell_window),
e_alert_submit (get_alert_sink (shell_view),
"calendar:failed-open-tasks",
error->message, NULL);
g_error_free (error);