From 89441016f3d9e975f1a336b44240b54b0ae93e2b Mon Sep 17 00:00:00 2001 From: JP Rosevear Date: Mon, 3 Jan 2005 19:00:02 +0000 Subject: utility routine to make it easier to add info items 2005-01-03 JP Rosevear * itip-view.c (itip_view_add_upper_info_item_printf): utility routine to make it easier to add info items (itip_view_add_lower_info_item_printf): ditto * itip-view.h: new protos * itip-formatter.c: use new printf routines everyhwere it makes sense svn path=/trunk/; revision=28220 --- plugins/itip-formatter/ChangeLog | 11 ++++++++ plugins/itip-formatter/itip-formatter.c | 39 ++++++++-------------------- plugins/itip-formatter/itip-view.c | 46 +++++++++++++++++++++++++++++++++ plugins/itip-formatter/itip-view.h | 8 ++++-- 4 files changed, 74 insertions(+), 30 deletions(-) diff --git a/plugins/itip-formatter/ChangeLog b/plugins/itip-formatter/ChangeLog index 9106d2ccd0..cee826074b 100644 --- a/plugins/itip-formatter/ChangeLog +++ b/plugins/itip-formatter/ChangeLog @@ -1,5 +1,16 @@ 2005-01-03 JP Rosevear + * itip-view.c (itip_view_add_upper_info_item_printf): utility + routine to make it easier to add info items + (itip_view_add_lower_info_item_printf): ditto + + * itip-view.h: new protos + + * itip-formatter.c: use new printf routines everyhwere it makes + sense + +2005-01-03 JP Rosevear + * itip-formatter.c (find_cal_opened_cb): move the adjust item work here when we actually have the calendar (pitip_free): implement a free function diff --git a/plugins/itip-formatter/itip-formatter.c b/plugins/itip-formatter/itip-formatter.c index 75b51b8433..58681586ef 100644 --- a/plugins/itip-formatter/itip-formatter.c +++ b/plugins/itip-formatter/itip-formatter.c @@ -277,11 +277,8 @@ cal_opened_cb (ECal *ecal, ECalendarStatus status, gpointer data) g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, cal_opened_cb, NULL); if (status != E_CALENDAR_STATUS_OK) { - char *warn; - - warn = g_strdup_printf ("Failed to load the calendar '%s'", e_source_peek_name (source)); - itip_view_add_lower_info_item (ITIP_VIEW (pitip->view), ITIP_VIEW_INFO_ITEM_TYPE_WARNING, warn); - g_free (warn); + itip_view_add_lower_info_item_printf (ITIP_VIEW (pitip->view), ITIP_VIEW_INFO_ITEM_TYPE_WARNING, + "Failed to load the calendar '%s'", e_source_peek_name (source)); g_hash_table_remove (pitip->ecals[source_type], e_source_peek_uid (source)); @@ -370,14 +367,11 @@ find_cal_opened_cb (ECal *ecal, ECalendarStatus status, gpointer data) g_signal_handlers_disconnect_matched (ecal, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, find_cal_opened_cb, NULL); if (status != E_CALENDAR_STATUS_OK) { - char *warn; - /* FIXME Do we really want to warn here? If we fail * to find the item, this won't be cleared but the * selector might be shown */ - warn = g_strdup_printf ("Failed to load the calendar '%s'", e_source_peek_name (source)); - itip_view_add_lower_info_item (ITIP_VIEW (pitip->view), ITIP_VIEW_INFO_ITEM_TYPE_WARNING, warn); - g_free (warn); + itip_view_add_lower_info_item_printf (ITIP_VIEW (pitip->view), ITIP_VIEW_INFO_ITEM_TYPE_WARNING, + "Failed to load the calendar '%s'", e_source_peek_name (source)); g_hash_table_remove (pitip->ecals[source_type], e_source_peek_uid (source)); @@ -385,24 +379,17 @@ find_cal_opened_cb (ECal *ecal, ECalendarStatus status, gpointer data) } /* Check for conflicts */ + /* If the query fails, we'll just ignore it */ /* FIXME Limit the calendars checked for conflicts? */ /* FIXME What happens for recurring conflicts? */ if (e_cal_get_object_list (ecal, fd->sexp, &objects, NULL) && g_list_length (objects) > 0) { - char *info; - - g_message ("Conflicting item found"); - info = g_strdup_printf ("An appointment in the calendar '%s' conflicts with this meeting", e_source_peek_name (source)); - itip_view_add_upper_info_item (ITIP_VIEW (pitip->view), ITIP_VIEW_INFO_ITEM_TYPE_WARNING, info); - g_free (info); + itip_view_add_upper_info_item_printf (ITIP_VIEW (pitip->view), ITIP_VIEW_INFO_ITEM_TYPE_WARNING, + "An appointment in the calendar '%s' conflicts with this meeting", e_source_peek_name (source)); e_cal_free_object_list (objects); - } else { - g_message ("Query failed"); } if (e_cal_get_object (ecal, fd->uid, NULL, &icalcomp, NULL)) { - char *info; - icalcomponent_free (icalcomp); pitip->current_ecal = ecal; @@ -419,9 +406,8 @@ find_cal_opened_cb (ECal *ecal, ECalendarStatus status, gpointer data) itip_view_clear_lower_info_items (ITIP_VIEW (pitip->view)); pitip->progress_info_id = 0; - info = g_strdup_printf ("Found the appointment in the calendar '%s'", e_source_peek_name (source)); - itip_view_add_lower_info_item (ITIP_VIEW (pitip->view), ITIP_VIEW_INFO_ITEM_TYPE_INFO, info); - g_free (info); + itip_view_add_lower_info_item_printf (ITIP_VIEW (pitip->view), ITIP_VIEW_INFO_ITEM_TYPE_INFO, + "Found the appointment in the calendar '%s'", e_source_peek_name (source)); set_buttons_sensitive (pitip); } @@ -740,11 +726,8 @@ update_attendee_status (FormatItipPObject *pitip) } if (!e_cal_modify_object (pitip->current_ecal, icalcomp, CALOBJ_MOD_ALL, &error)) { - char *info; - - info = g_strdup_printf (_("Unable to update attendee statusAttendee status updated. %s"), error->message); - itip_view_add_lower_info_item (ITIP_VIEW (pitip->view), ITIP_VIEW_INFO_ITEM_TYPE_ERROR, info); - g_free (info); + itip_view_add_lower_info_item_printf (ITIP_VIEW (pitip->view), ITIP_VIEW_INFO_ITEM_TYPE_ERROR, + _("Unable to update attendee statusAttendee status updated. %s"), error->message); g_error_free (error); } else { diff --git a/plugins/itip-formatter/itip-view.c b/plugins/itip-formatter/itip-view.c index 3734b74d92..a8a8a1e979 100644 --- a/plugins/itip-formatter/itip-view.c +++ b/plugins/itip-formatter/itip-view.c @@ -1048,6 +1048,29 @@ itip_view_add_upper_info_item (ItipView *view, ItipViewInfoItemType type, const return item->id; } +guint +itip_view_add_upper_info_item_printf (ItipView *view, ItipViewInfoItemType type, const char *format, ...) +{ + ItipViewPrivate *priv; + va_list args; + char *message; + guint id; + + g_return_val_if_fail (view != NULL, 0); + g_return_val_if_fail (ITIP_IS_VIEW (view), 0); + + priv = view->priv; + + va_start (args, format); + message = g_strdup_vprintf (format, args); + va_end (args); + + id = itip_view_add_upper_info_item (view, type, message); + g_free (message); + + return id; +} + void itip_view_remove_upper_info_item (ItipView *view, guint id) { @@ -1123,6 +1146,29 @@ itip_view_add_lower_info_item (ItipView *view, ItipViewInfoItemType type, const return item->id; } +guint +itip_view_add_lower_info_item_printf (ItipView *view, ItipViewInfoItemType type, const char *format, ...) +{ + ItipViewPrivate *priv; + va_list args; + char *message; + guint id; + + g_return_val_if_fail (view != NULL, 0); + g_return_val_if_fail (ITIP_IS_VIEW (view), 0); + + priv = view->priv; + + va_start (args, format); + message = g_strdup_vprintf (format, args); + va_end (args); + + id = itip_view_add_lower_info_item (view, type, message); + g_free (message); + + return id; +} + void itip_view_remove_lower_info_item (ItipView *view, guint id) { diff --git a/plugins/itip-formatter/itip-view.h b/plugins/itip-formatter/itip-view.h index 24b167dd31..d71f0796eb 100644 --- a/plugins/itip-formatter/itip-view.h +++ b/plugins/itip-formatter/itip-view.h @@ -23,6 +23,8 @@ #ifndef _ITIP_VIEW_H_ #define _ITIP_VIEW_H_ +#include +#include #include #include #include @@ -118,11 +120,13 @@ const struct tm *itip_view_get_start (ItipView *view); void itip_view_set_end (ItipView *view, struct tm *end); const struct tm *itip_view_get_end (ItipView *view); -guint itip_view_add_upper_info_item (ItipView *view, ItipViewInfoItemType, const char *message); +guint itip_view_add_upper_info_item (ItipView *view, ItipViewInfoItemType type, const char *message); +guint itip_view_add_upper_info_item_printf (ItipView *view, ItipViewInfoItemType, const char *format, ...) G_GNUC_PRINTF (3, 4); void itip_view_remove_upper_info_item (ItipView *view, guint id); void itip_view_clear_upper_info_items (ItipView *view); -guint itip_view_add_lower_info_item (ItipView *view, ItipViewInfoItemType, const char *message); +guint itip_view_add_lower_info_item (ItipView *view, ItipViewInfoItemType type, const char *message); +guint itip_view_add_lower_info_item_printf (ItipView *view, ItipViewInfoItemType type, const char *format, ...) G_GNUC_PRINTF (3, 4); void itip_view_remove_lower_info_item (ItipView *view, guint id); void itip_view_clear_lower_info_items (ItipView *view); -- cgit v1.2.3