From 2403bbcdd196745314786af3b6318de56ef3948e Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Fri, 24 Apr 2009 19:40:31 +0200 Subject: Use new ESourceList API (simplifies code) ** Part of fix for bug #569652 --- calendar/gui/calendar-component.c | 85 ++++++++------------------------------- calendar/gui/memos-component.c | 58 +++++++------------------- calendar/gui/tasks-component.c | 58 +++++++------------------- 3 files changed, 47 insertions(+), 154 deletions(-) (limited to 'calendar/gui') diff --git a/calendar/gui/calendar-component.c b/calendar/gui/calendar-component.c index a44b279f19..942960bff5 100644 --- a/calendar/gui/calendar-component.c +++ b/calendar/gui/calendar-component.c @@ -158,23 +158,15 @@ calcomp_vpane_resized (GtkWidget *vpane, GdkEventButton *e, CalendarComponentVie static void ensure_sources (CalendarComponent *component) { - GSList *groups; ESourceList *source_list; - ESourceGroup *group; ESourceGroup *on_this_computer; - ESourceGroup *on_the_web; ESourceGroup *contacts; - ESourceGroup *weather; ESource *personal_source; ESource *birthdays_source; - char *base_uri, *base_uri_proto; + char *base_uri, *base_uri_proto, base_uri_proto_seventh; const gchar *base_dir; gchar *create_source; - on_this_computer = NULL; - on_the_web = NULL; - contacts = NULL; - weather = NULL; personal_source = NULL; birthdays_source = NULL; @@ -187,28 +179,22 @@ ensure_sources (CalendarComponent *component) base_uri = g_build_filename (base_dir, "local", NULL); base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL); + if (strlen (base_uri_proto) > 7) { + /* compare only file:// part. If user home dir name changes we do not want to create + one more group */ + base_uri_proto_seventh = base_uri_proto[7]; + base_uri_proto[7] = 0; + } else { + base_uri_proto_seventh = -1; + } - groups = e_source_list_peek_groups (source_list); - if (groups) { - /* groups are already there, we need to search for things... */ - GSList *g; - - for (g = groups; g; g = g->next) { - - group = E_SOURCE_GROUP (g->data); - - /* compare only file:// part. If user home dir name changes we do not want to create - one more group */ + on_this_computer = e_source_list_ensure_group (source_list, _("On This Computer"), base_uri_proto, TRUE); + contacts = e_source_list_ensure_group (source_list, _("Contacts"), CONTACTS_BASE_URI, TRUE); + e_source_list_ensure_group (source_list, _("On The Web"), WEB_BASE_URI, FALSE); + e_source_list_ensure_group (source_list, _("Weather"), WEATHER_BASE_URI, FALSE); - if (!on_this_computer && !strncmp (base_uri_proto, e_source_group_peek_base_uri (group), 7)) - on_this_computer = group; - else if (!on_the_web && !strcmp (WEB_BASE_URI, e_source_group_peek_base_uri (group))) - on_the_web = group; - else if (!contacts && !strcmp (CONTACTS_BASE_URI, e_source_group_peek_base_uri (group))) - contacts = group; - else if (!weather && !strcmp (WEATHER_BASE_URI, e_source_group_peek_base_uri (group))) - weather = group; - } + if (base_uri_proto_seventh != -1) { + base_uri_proto[7] = base_uri_proto_seventh; } if (on_this_computer) { @@ -238,16 +224,6 @@ ensure_sources (CalendarComponent *component) and too late to prevent user seeing "Can not Open ... because of invalid uri" error.*/ e_source_list_sync (source_list,NULL); } - - /* ensure the group name is in current locale, not read from configuration */ - e_source_group_set_name (on_this_computer, _("On This Computer")); - } - else { - /* create the local source group */ - group = e_source_group_new (_("On This Computer"), base_uri_proto); - e_source_list_add_group (source_list, group, -1); - - on_this_computer = group; } if (personal_source) { @@ -282,17 +258,6 @@ ensure_sources (CalendarComponent *component) e_source_set_color_spec (personal_source, "#BECEDD"); } - if (on_the_web) { - /* ensure the group name is in current locale, not read from configuration */ - e_source_group_set_name (on_the_web, _("On The Web")); - } else { - /* Create the On the web source group */ - group = e_source_group_new (_("On The Web"), WEB_BASE_URI); - e_source_list_add_group (source_list, group, -1); - - on_the_web = group; - } - if (contacts) { GSList *sources = e_source_group_peek_sources (contacts); if (sources) { @@ -311,14 +276,6 @@ ensure_sources (CalendarComponent *component) g_slist_free (l); } } - - /* ensure the group name is in current locale, not read from configuration */ - e_source_group_set_name (contacts, _("Contacts")); - } else { - /* Create the contacts group */ - group = e_source_group_new (_("Contacts"), CONTACTS_BASE_URI); - e_source_list_add_group (source_list, group, -1); - contacts = group; } create_source = e_source_group_get_property (contacts, "create_source"); @@ -341,18 +298,10 @@ ensure_sources (CalendarComponent *component) if (e_source_peek_color_spec (birthdays_source) == NULL) e_source_set_color_spec (birthdays_source, "#DDBECE"); - if (weather) { - /* ensure the group name is in current locale, not read from configuration */ - e_source_group_set_name (weather, _("Weather")); - } else { - /* Create the weather group */ - group = e_source_group_new (_("Weather"), WEATHER_BASE_URI); - e_source_list_add_group (source_list, group, -1); - weather = group; - } - component->priv->source_list = source_list; + g_object_unref (on_this_computer); + g_object_unref (contacts); g_free (base_uri_proto); g_free (base_uri); } diff --git a/calendar/gui/memos-component.c b/calendar/gui/memos-component.c index 3fbebd7e3e..0e422d548d 100644 --- a/calendar/gui/memos-component.c +++ b/calendar/gui/memos-component.c @@ -123,17 +123,12 @@ struct _MemosComponentPrivate { static void ensure_sources (MemosComponent *component) { - GSList *groups; ESourceList *source_list; - ESourceGroup *group; ESourceGroup *on_this_computer; - ESourceGroup *on_the_web; ESource *personal_source; - char *base_uri, *base_uri_proto; + char *base_uri, *base_uri_proto, base_uri_proto_seventh; const gchar *base_dir; - on_this_computer = NULL; - on_the_web = NULL; personal_source = NULL; if (!e_cal_get_sources (&source_list, E_CAL_SOURCE_TYPE_JOURNAL, NULL)) { @@ -145,24 +140,20 @@ ensure_sources (MemosComponent *component) base_uri = g_build_filename (base_dir, "local", NULL); base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL); + if (strlen (base_uri_proto) > 7) { + /* compare only file:// part. If user home dir name changes we do not want to create + one more group */ + base_uri_proto_seventh = base_uri_proto[7]; + base_uri_proto[7] = 0; + } else { + base_uri_proto_seventh = -1; + } - groups = e_source_list_peek_groups (source_list); - if (groups) { - /* groups are already there, we need to search for things... */ - GSList *g; - - for (g = groups; g; g = g->next) { - - group = E_SOURCE_GROUP (g->data); - - /* compare only file:// part. If user home dir name changes we do not want to create - one more group */ + on_this_computer = e_source_list_ensure_group (source_list, _("On This Computer"), base_uri_proto, TRUE); + e_source_list_ensure_group (source_list, _("On The Web"), WEB_BASE_URI, FALSE); - if (!on_this_computer && !strncmp (base_uri_proto, e_source_group_peek_base_uri (group), 7)) - on_this_computer = group; - else if (!on_the_web && !strcmp (WEB_BASE_URI, e_source_group_peek_base_uri (group))) - on_the_web = group; - } + if (base_uri_proto_seventh != -1) { + base_uri_proto[7] = base_uri_proto_seventh; } if (on_this_computer) { @@ -192,16 +183,6 @@ ensure_sources (MemosComponent *component) and too late to prevent user seeing "Can not Open ... because of invalid uri" error.*/ e_source_list_sync (source_list,NULL); } - - /* ensure the group name is in current locale, not read from configuration */ - e_source_group_set_name (on_this_computer, _("On This Computer")); - } - else { - /* create the local source group */ - group = e_source_group_new (_("On This Computer"), base_uri_proto); - e_source_list_add_group (source_list, group, -1); - - on_this_computer = group; } if (personal_source) { @@ -235,18 +216,9 @@ ensure_sources (MemosComponent *component) personal_source = source; } - if (on_the_web) { - /* ensure the group name is in current locale, not read from configuration */ - e_source_group_set_name (on_the_web, _("On The Web")); - } else { - /* Create the source group */ - group = e_source_group_new (_("On The Web"), WEB_BASE_URI); - e_source_list_add_group (source_list, group, -1); - - on_the_web = group; - } - component->priv->source_list = source_list; + + g_object_unref (on_this_computer); g_free (base_uri_proto); g_free (base_uri); } diff --git a/calendar/gui/tasks-component.c b/calendar/gui/tasks-component.c index 7564c1bf92..9ed21d5186 100644 --- a/calendar/gui/tasks-component.c +++ b/calendar/gui/tasks-component.c @@ -120,17 +120,12 @@ struct _TasksComponentPrivate { static void ensure_sources (TasksComponent *component) { - GSList *groups; ESourceList *source_list; - ESourceGroup *group; ESourceGroup *on_this_computer; - ESourceGroup *on_the_web; ESource *personal_source; - char *base_uri, *base_uri_proto; + char *base_uri, *base_uri_proto, base_uri_proto_seventh; const gchar *base_dir; - on_this_computer = NULL; - on_the_web = NULL; personal_source = NULL; if (!e_cal_get_sources (&source_list, E_CAL_SOURCE_TYPE_TODO, NULL)) { @@ -142,24 +137,20 @@ ensure_sources (TasksComponent *component) base_uri = g_build_filename (base_dir, "local", NULL); base_uri_proto = g_filename_to_uri (base_uri, NULL, NULL); + if (strlen (base_uri_proto) > 7) { + /* compare only file:// part. If user home dir name changes we do not want to create + one more group */ + base_uri_proto_seventh = base_uri_proto[7]; + base_uri_proto[7] = 0; + } else { + base_uri_proto_seventh = -1; + } - groups = e_source_list_peek_groups (source_list); - if (groups) { - /* groups are already there, we need to search for things... */ - GSList *g; - - for (g = groups; g; g = g->next) { - - group = E_SOURCE_GROUP (g->data); - - /* compare only file:// part. If user home dir name changes we do not want to create - one more group */ + on_this_computer = e_source_list_ensure_group (source_list, _("On This Computer"), base_uri_proto, TRUE); + e_source_list_ensure_group (source_list, _("On The Web"), WEB_BASE_URI, FALSE); - if (!on_this_computer && !strncmp (base_uri_proto, e_source_group_peek_base_uri (group), 7)) - on_this_computer = group; - else if (!on_the_web && !strcmp (WEB_BASE_URI, e_source_group_peek_base_uri (group))) - on_the_web = group; - } + if (base_uri_proto_seventh != -1) { + base_uri_proto[7] = base_uri_proto_seventh; } if (on_this_computer) { @@ -189,16 +180,6 @@ ensure_sources (TasksComponent *component) and too late to prevent user seeing "Can not Open ... because of invalid uri" error.*/ e_source_list_sync (source_list,NULL); } - - /* ensure the group name is in current locale, not read from configuration */ - e_source_group_set_name (on_this_computer, _("On This Computer")); - } - else { - /* create the local source group */ - group = e_source_group_new (_("On This Computer"), base_uri_proto); - e_source_list_add_group (source_list, group, -1); - - on_this_computer = group; } if (personal_source) { @@ -232,18 +213,9 @@ ensure_sources (TasksComponent *component) personal_source = source; } - if (!on_the_web) { - /* Create the LDAP source group */ - group = e_source_group_new (_("On The Web"), WEB_BASE_URI); - e_source_list_add_group (source_list, group, -1); - - on_the_web = group; - } else { - /* ensure the group name is in current locale, not read from configuration */ - e_source_group_set_name (on_the_web, _("On The Web")); - } - component->priv->source_list = source_list; + + g_object_unref (on_this_computer); g_free (base_uri_proto); g_free (base_uri); } -- cgit v1.2.3 From 65464532b52b16dfaf529208cfcc798ea303711a Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Fri, 24 Apr 2009 20:41:00 +0200 Subject: Possible leak fix ** Part of fix for bug #571272 --- calendar/gui/e-cal-model.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'calendar/gui') diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c index 4fcfbd7609..ed4eb0f9dd 100644 --- a/calendar/gui/e-cal-model.c +++ b/calendar/gui/e-cal-model.c @@ -1336,10 +1336,13 @@ search_by_id_and_client (ECalModelPrivate *priv, ECal *client, const ECalCompone if (comp_data) { const char *uid; char *rid = NULL; + struct icaltimetype icalrid; gboolean has_rid = (id->rid && *id->rid); uid = icalcomponent_get_uid (comp_data->icalcomp); - rid = icaltime_as_ical_string_r (icalcomponent_get_recurrenceid (comp_data->icalcomp)); + icalrid = icalcomponent_get_recurrenceid (comp_data->icalcomp); + if (!icaltime_is_null_time (icalrid)) + rid = icaltime_as_ical_string_r (icalrid); if (uid && *uid) { if ((!client || comp_data->client == client) && !strcmp (id->uid, uid)) { @@ -1352,8 +1355,9 @@ search_by_id_and_client (ECalModelPrivate *priv, ECal *client, const ECalCompone g_free (rid); return comp_data; } - g_free (rid); } + + g_free (rid); } } -- cgit v1.2.3 From 7088736007cca0e65306cd511ef50b5a57ae28b5 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Fri, 24 Apr 2009 20:53:03 +0200 Subject: Calendar - do not close editor after error ** Fix for bug #573704 --- calendar/gui/dialogs/comp-editor.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'calendar/gui') diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c index 7a083a37a1..f3034359c6 100644 --- a/calendar/gui/dialogs/comp-editor.c +++ b/calendar/gui/dialogs/comp-editor.c @@ -1206,9 +1206,11 @@ action_save_cb (GtkAction *action, g_clear_error (&error); } - } + } else + correct = FALSE; - close_dialog (editor); + if (correct) + close_dialog (editor); } static void @@ -3113,14 +3115,13 @@ real_send_comp (CompEditor *editor, ECalComponentItipMethod method, gboolean str set_attendees_for_delegation (send_comp, address, method); } - if (!e_cal_component_has_attachments (priv->comp) - || e_cal_get_static_capability (priv->client, CAL_STATIC_CAPABILITY_CREATE_MESSAGES)) { + if (!e_cal_component_has_attachments (priv->comp) + || e_cal_get_static_capability (priv->client, CAL_STATIC_CAPABILITY_CREATE_MESSAGES)) { if (itip_send_comp (method, send_comp, priv->client, NULL, NULL, users, strip_alarms)) { g_object_unref (send_comp); return TRUE; } - } else { /* Clone the component with attachments set to CID:... */ int num_attachments, i; @@ -3138,9 +3139,14 @@ real_send_comp (CompEditor *editor, ECalComponentItipMethod method, gboolean str mime_attach_list = comp_editor_get_mime_attach_list (editor); if (itip_send_comp (method, send_comp, priv->client, NULL, mime_attach_list, users, strip_alarms)) { - save_comp (editor); + gboolean saved = save_comp (editor); + g_object_unref (send_comp); - return TRUE; + + if (!saved) + comp_editor_set_changed (editor, TRUE); + + return saved; } } -- cgit v1.2.3 From b29f1ed5e653974acf983f211901139d0f76cf12 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Mon, 27 Apr 2009 12:07:09 +0200 Subject: Allow Last Modified and Created columns for event table ** Fix for bug #575773 * gui/e-calendar-table.etspec: * gui/e-cal-list-view.etspec: * gui/e-memo-table.etspec: * gui/e-cal-model.h: (ECalModelField), (struct _ECalModelComponent): * gui/e-cal-model.c: (get_datetime_from_utc), (ecm_value_at), (ecm_duplicate_value), (ecm_free_value), (ecm_initialize_value), (ecm_value_is_empty), (ecm_value_to_string), (e_cal_view_objects_modified_cb), (e_cal_model_component_finalize), (e_cal_model_component_init): Allow showing CREATED and LAST-MODIFIED properties in a table. * gui/print.c: (print_comp_draw_real): * gui/e-cal-component-preview.c: (write_html): * conduits/todo/todo-conduit.c: (local_record_from_comp): Possible leak fix. --- calendar/gui/e-cal-component-preview.c | 4 +- calendar/gui/e-cal-list-view.etspec | 6 ++- calendar/gui/e-cal-model.c | 69 ++++++++++++++++++++++++++++++++++ calendar/gui/e-cal-model.h | 4 ++ calendar/gui/e-calendar-table.etspec | 14 ++++--- calendar/gui/e-memo-table.etspec | 2 + calendar/gui/print.c | 4 +- 7 files changed, 93 insertions(+), 10 deletions(-) (limited to 'calendar/gui') diff --git a/calendar/gui/e-cal-component-preview.c b/calendar/gui/e-cal-component-preview.c index 221ae36753..0c759a1591 100644 --- a/calendar/gui/e-cal-component-preview.c +++ b/calendar/gui/e-cal-component-preview.c @@ -272,9 +272,11 @@ write_html (GtkHTMLStream *stream, ECal *ecal, ECalComponent *comp, icaltimezone gtk_html_stream_printf (stream, "%s", str); g_free (str); - e_cal_component_free_priority (priority_value); } + if (priority_value) + e_cal_component_free_priority (priority_value); + /* write description and URL */ gtk_html_stream_printf (stream, "
"); diff --git a/calendar/gui/e-cal-list-view.etspec b/calendar/gui/e-cal-list-view.etspec index 2168d7363e..f8f2d72853 100644 --- a/calendar/gui/e-cal-list-view.etspec +++ b/calendar/gui/e-cal-list-view.etspec @@ -1,9 +1,11 @@ - + - + + + diff --git a/calendar/gui/e-cal-model.c b/calendar/gui/e-cal-model.c index ed4eb0f9dd..20306b7128 100644 --- a/calendar/gui/e-cal-model.c +++ b/calendar/gui/e-cal-model.c @@ -435,6 +435,43 @@ get_dtstart (ECalModel *model, ECalModelComponent *comp_data) return comp_data->dtstart; } +static ECellDateEditValue* +get_datetime_from_utc (ECalModel *model, ECalModelComponent *comp_data, icalproperty_kind propkind, struct icaltimetype (*get_value)(const icalproperty* prop), ECellDateEditValue **buffer) +{ + ECalModelPrivate *priv; + struct icaltimetype tt_value; + icalproperty *prop; + ECellDateEditValue *res; + + g_return_val_if_fail (buffer!= NULL, NULL); + + if (*buffer) + return *buffer; + + priv = model->priv; + + prop = icalcomponent_get_first_property (comp_data->icalcomp, propkind); + if (!prop) + return NULL; + + tt_value = get_value (prop); + + /* these are always in UTC, thus convert to default zone, if any and done */ + if (priv->zone) + icaltimezone_convert_time (&tt_value, icaltimezone_get_utc_timezone (), priv->zone); + + if (!icaltime_is_valid_time (tt_value) || icaltime_is_null_time (tt_value)) + return NULL; + + res = g_new0 (ECellDateEditValue, 1); + res->tt = tt_value; + res->zone = NULL; + + *buffer = res; + + return res; +} + static char * get_summary (ECalModelComponent *comp_data) { @@ -484,6 +521,10 @@ ecm_value_at (ETableModel *etm, int col, int row) return get_description (comp_data); case E_CAL_MODEL_FIELD_DTSTART : return (void *) get_dtstart (model, comp_data); + case E_CAL_MODEL_FIELD_CREATED : + return (void *) get_datetime_from_utc (model, comp_data, ICAL_CREATED_PROPERTY, icalproperty_get_created, &comp_data->created); + case E_CAL_MODEL_FIELD_LASTMODIFIED : + return (void *) get_datetime_from_utc (model, comp_data, ICAL_LASTMODIFIED_PROPERTY, icalproperty_get_lastmodified, &comp_data->lastmodified); case E_CAL_MODEL_FIELD_HAS_ALARMS : return GINT_TO_POINTER ((icalcomponent_get_first_component (comp_data->icalcomp, ICAL_VALARM_COMPONENT) != NULL)); @@ -878,6 +919,8 @@ ecm_duplicate_value (ETableModel *etm, int col, const void *value) case E_CAL_MODEL_FIELD_COMPONENT : return icalcomponent_new_clone ((icalcomponent *) value); case E_CAL_MODEL_FIELD_DTSTART : + case E_CAL_MODEL_FIELD_CREATED : + case E_CAL_MODEL_FIELD_LASTMODIFIED : if (value) { ECellDateEditValue *dv, *orig_dv; @@ -911,6 +954,8 @@ ecm_free_value (ETableModel *etm, int col, void *value) case E_CAL_MODEL_FIELD_COLOR : break; case E_CAL_MODEL_FIELD_DTSTART : + case E_CAL_MODEL_FIELD_CREATED : + case E_CAL_MODEL_FIELD_LASTMODIFIED : if (value) g_free (value); break; @@ -940,6 +985,8 @@ ecm_initialize_value (ETableModel *etm, int col) case E_CAL_MODEL_FIELD_SUMMARY : return g_strdup (""); case E_CAL_MODEL_FIELD_DTSTART : + case E_CAL_MODEL_FIELD_CREATED : + case E_CAL_MODEL_FIELD_LASTMODIFIED : case E_CAL_MODEL_FIELD_HAS_ALARMS : case E_CAL_MODEL_FIELD_ICON : case E_CAL_MODEL_FIELD_COLOR : @@ -978,6 +1025,8 @@ ecm_value_is_empty (ETableModel *etm, int col, const void *value) case E_CAL_MODEL_FIELD_SUMMARY : return string_is_empty (value); case E_CAL_MODEL_FIELD_DTSTART : + case E_CAL_MODEL_FIELD_CREATED : + case E_CAL_MODEL_FIELD_LASTMODIFIED : return value ? FALSE : TRUE; case E_CAL_MODEL_FIELD_HAS_ALARMS : case E_CAL_MODEL_FIELD_ICON : @@ -1001,6 +1050,8 @@ ecm_value_to_string (ETableModel *etm, int col, const void *value) case E_CAL_MODEL_FIELD_SUMMARY : return g_strdup (value); case E_CAL_MODEL_FIELD_DTSTART : + case E_CAL_MODEL_FIELD_CREATED : + case E_CAL_MODEL_FIELD_LASTMODIFIED : return e_cal_model_date_value_to_string (E_CAL_MODEL (etm), value); case E_CAL_MODEL_FIELD_ICON : if (GPOINTER_TO_INT (value) == 0) @@ -1571,6 +1622,14 @@ e_cal_view_objects_modified_cb (ECalView *query, GList *objects, gpointer user_d g_free (comp_data->completed); comp_data->completed = NULL; } + if (comp_data->created) { + g_free (comp_data->created); + comp_data->created = NULL; + } + if (comp_data->lastmodified) { + g_free (comp_data->lastmodified); + comp_data->lastmodified = NULL; + } if (comp_data->color) { g_free (comp_data->color); comp_data->color = NULL; @@ -2311,6 +2370,14 @@ e_cal_model_component_finalize (GObject *object) g_free (comp_data->completed); comp_data->completed = NULL; } + if (comp_data->created) { + g_free (comp_data->created); + comp_data->created = NULL; + } + if (comp_data->lastmodified) { + g_free (comp_data->lastmodified); + comp_data->lastmodified = NULL; + } if (comp_data->color) { g_free (comp_data->color); comp_data->color = NULL; @@ -2328,6 +2395,8 @@ e_cal_model_component_init (ECalModelComponent *comp) comp->dtend = NULL; comp->due = NULL; comp->completed = NULL; + comp->created = NULL; + comp->lastmodified = NULL; comp->color = NULL; } diff --git a/calendar/gui/e-cal-model.h b/calendar/gui/e-cal-model.h index 80ba4d4b5b..6ec66a3554 100644 --- a/calendar/gui/e-cal-model.h +++ b/calendar/gui/e-cal-model.h @@ -53,6 +53,8 @@ typedef enum { E_CAL_MODEL_FIELD_ICON, /* not a real field */ E_CAL_MODEL_FIELD_SUMMARY, E_CAL_MODEL_FIELD_UID, + E_CAL_MODEL_FIELD_CREATED, + E_CAL_MODEL_FIELD_LASTMODIFIED, E_CAL_MODEL_FIELD_LAST } ECalModelField; @@ -86,6 +88,8 @@ struct _ECalModelComponent { ECellDateEditValue *dtend; ECellDateEditValue *due; ECellDateEditValue *completed; + ECellDateEditValue *created; + ECellDateEditValue *lastmodified; gchar *color; ECalModelComponentPrivate *priv; diff --git a/calendar/gui/e-calendar-table.etspec b/calendar/gui/e-calendar-table.etspec index 4e1e6c175c..d63e0928e5 100644 --- a/calendar/gui/e-calendar-table.etspec +++ b/calendar/gui/e-calendar-table.etspec @@ -2,13 +2,15 @@ - - - - - - + + + + + + + + diff --git a/calendar/gui/e-memo-table.etspec b/calendar/gui/e-memo-table.etspec index a16793ecf1..aad61a0227 100644 --- a/calendar/gui/e-memo-table.etspec +++ b/calendar/gui/e-memo-table.etspec @@ -3,6 +3,8 @@ + + diff --git a/calendar/gui/print.c b/calendar/gui/print.c index ccf0c7c618..adbfc2cc77 100644 --- a/calendar/gui/print.c +++ b/calendar/gui/print.c @@ -2583,7 +2583,6 @@ print_comp_draw_real (GtkPrintOperation *operation, char *priority_string, *pri_text; priority_string = e_cal_util_priority_to_string (*priority); - e_cal_component_free_priority (priority); pri_text = g_strdup_printf (_("Priority: %s"), priority_string); top = bound_text (context, font, pri_text, -1, @@ -2592,6 +2591,9 @@ print_comp_draw_real (GtkPrintOperation *operation, g_free (pri_text); } + if (priority) + e_cal_component_free_priority (priority); + /* Percent Complete */ e_cal_component_get_percent (comp, &percent); if (percent) { -- cgit v1.2.3 From d4def43e4d7fba2b8a123b7d11af8170b0f93a1b Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Mon, 27 Apr 2009 12:13:35 +0200 Subject: Sanitize values from GConf before using them ** Fix for bug #491755 * gui/alarm-notify/config-data.c: (config_data_set_last_notification_time), (config_data_get_last_notification_time): Sanitize values from GConf before using them. --- calendar/gui/alarm-notify/config-data.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'calendar/gui') diff --git a/calendar/gui/alarm-notify/config-data.c b/calendar/gui/alarm-notify/config-data.c index 81cbc3480c..5a05cfd341 100644 --- a/calendar/gui/alarm-notify/config-data.c +++ b/calendar/gui/alarm-notify/config-data.c @@ -259,7 +259,7 @@ void config_data_set_last_notification_time (time_t t) { GConfClient *client; - time_t current_t; + time_t current_t, now = time (NULL); g_return_if_fail (t != -1); @@ -269,7 +269,7 @@ config_data_set_last_notification_time (time_t t) /* we only store the new notification time if it is bigger than the already stored one */ current_t = gconf_client_get_int (client, KEY_LAST_NOTIFICATION_TIME, NULL); - if (t > current_t) + if (t > current_t || current_t > now) gconf_client_set_int (client, KEY_LAST_NOTIFICATION_TIME, t, NULL); } @@ -290,8 +290,14 @@ config_data_get_last_notification_time (void) return -1; value = gconf_client_get_without_default (client, KEY_LAST_NOTIFICATION_TIME, NULL); - if (value) - return (time_t) gconf_value_get_int (value); + if (value) { + time_t val = (time_t) gconf_value_get_int (value), now = time (NULL); + + if (val > now) + val = now; + + return val; + } return time (NULL); } -- cgit v1.2.3 From e377ea5e61171e57f9e892652d0fd1f77953eda8 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 27 Apr 2009 14:53:18 -0400 Subject: =?UTF-8?q?Bug=20516933=20=E2=80=93=20Rewrite=20attachment=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rewrite the attachment UI to better utilize GIO and also to migrate from GnomeIconList to GtkIconView. This also introduces a "List View" option similar to Nautilus, as well as the EAttachmentHandler framework for extending attachment handling (may eventually replace EMFormatHook). This commit also fixes a number of secondary attachment bugs: Bug 311609 – new attachment bar should use regular gtk+ expander Bug 314923 – Drag and Drop in attachment window is inconsistent and requires additional click Bug 338179 – attachment saving ... Bug 350364 – Action to get info about attachments Bug 383047 – Viewing mail attachments Bug 427235 – Can't copy attachment mime type string Bug 454091 – Cannot save multiple attachments who have the same name Bug 494629 – Rethink composer's attachment UI Bug 553970 – Evolution ignores umask when saving attachments Bug 577375 – mailto: and attach doesn't URL un-escape --- calendar/gui/e-attachment-handler-calendar.c | 511 +++++++++++++++++++++++++++ calendar/gui/e-attachment-handler-calendar.h | 65 ++++ 2 files changed, 576 insertions(+) create mode 100644 calendar/gui/e-attachment-handler-calendar.c create mode 100644 calendar/gui/e-attachment-handler-calendar.h (limited to 'calendar/gui') diff --git a/calendar/gui/e-attachment-handler-calendar.c b/calendar/gui/e-attachment-handler-calendar.c new file mode 100644 index 0000000000..5beb6e07d3 --- /dev/null +++ b/calendar/gui/e-attachment-handler-calendar.c @@ -0,0 +1,511 @@ +/* + * e-attachment-handler-calendar.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; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "e-attachment-handler-calendar.h" + +#include +#include +#include +#include +#include + +#include "calendar/common/authentication.h" + +#define E_ATTACHMENT_HANDLER_CALENDAR_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_ATTACHMENT_HANDLER_CALENDAR, EAttachmentHandlerCalendarPrivate)) + +typedef struct _ImportContext ImportContext; + +struct _EAttachmentHandlerCalendarPrivate { + gint placeholder; +}; + +struct _ImportContext { + ECal *client; + icalcomponent *component; + ECalSourceType source_type; +}; + +static gpointer parent_class; + +static const gchar *ui = +"" +" " +" " +" " +" " +" " +" " +""; + +static icalcomponent * +attachment_handler_get_component (EAttachment *attachment) +{ + CamelDataWrapper *wrapper; + CamelMimePart *mime_part; + CamelStream *stream; + GByteArray *buffer; + icalcomponent *component; + const gchar *key = "__icalcomponent__"; + + component = g_object_get_data (G_OBJECT (attachment), key); + if (component != NULL) + return component; + + mime_part = e_attachment_get_mime_part (attachment); + if (!CAMEL_IS_MIME_PART (mime_part)) + return NULL; + + buffer = g_byte_array_new (); + stream = camel_stream_mem_new (); + camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream), buffer); + wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part)); + camel_data_wrapper_decode_to_stream (wrapper, stream); + camel_object_unref (stream); + + component = e_cal_util_parse_ics_string ((gchar *) buffer->data); + + g_byte_array_free (buffer, TRUE); + + if (component == NULL) + return NULL; + + g_object_set_data_full ( + G_OBJECT (attachment), key, component, + (GDestroyNotify) icalcomponent_free); + + return component; +} + +static gboolean +attachment_handler_update_objects (ECal *client, + icalcomponent *component) +{ + icalcomponent_kind kind; + icalcomponent *vcalendar; + gboolean success; + + kind = icalcomponent_isa (component); + + switch (kind) { + case ICAL_VTODO_COMPONENT: + case ICAL_VEVENT_COMPONENT: + vcalendar = e_cal_util_new_top_level (); + if (icalcomponent_get_method (component) == ICAL_METHOD_CANCEL) + icalcomponent_set_method (vcalendar, ICAL_METHOD_CANCEL); + else + icalcomponent_set_method (vcalendar, ICAL_METHOD_PUBLISH); + icalcomponent_add_component ( + vcalendar, icalcomponent_new_clone (component)); + break; + + case ICAL_VCALENDAR_COMPONENT: + vcalendar = icalcomponent_new_clone (component); + if (!icalcomponent_get_first_property (vcalendar, ICAL_METHOD_PROPERTY)) + icalcomponent_set_method (vcalendar, ICAL_METHOD_PUBLISH); + break; + + default: + return FALSE; + } + + success = e_cal_receive_objects (client, vcalendar, NULL); + + icalcomponent_free (vcalendar); + + return success; +} + +static void +attachment_handler_import_event (ECal *client, + ECalendarStatus status, + EAttachment *attachment) +{ + icalcomponent *component; + icalcomponent *subcomponent; + icalcompiter iter; + + /* FIXME Notify the user somehow. */ + g_return_if_fail (status == E_CALENDAR_STATUS_OK); + + component = attachment_handler_get_component (attachment); + g_return_if_fail (component != NULL); + + iter = icalcomponent_begin_component (component, ICAL_ANY_COMPONENT); + + while ((subcomponent = icalcompiter_deref (&iter)) != NULL) { + icalcomponent_kind kind; + + kind = icalcomponent_isa (subcomponent); + icalcompiter_next (&iter); + + if (kind == ICAL_VEVENT_COMPONENT) + continue; + + if (kind == ICAL_VTIMEZONE_COMPONENT) + continue; + + icalcomponent_remove_component (component, subcomponent); + icalcomponent_free (subcomponent); + } + + /* XXX Do something with the return value. */ + attachment_handler_update_objects (client, component); + + g_object_unref (attachment); + g_object_unref (client); +} + +static void +attachment_handler_import_todo (ECal *client, + ECalendarStatus status, + EAttachment *attachment) +{ + icalcomponent *component; + icalcomponent *subcomponent; + icalcompiter iter; + + /* FIXME Notify the user somehow. */ + g_return_if_fail (status == E_CALENDAR_STATUS_OK); + + component = attachment_handler_get_component (attachment); + g_return_if_fail (component != NULL); + + iter = icalcomponent_begin_component (component, ICAL_ANY_COMPONENT); + + while ((subcomponent = icalcompiter_deref (&iter)) != NULL) { + icalcomponent_kind kind; + + kind = icalcomponent_isa (subcomponent); + icalcompiter_next (&iter); + + if (kind == ICAL_VTODO_COMPONENT) + continue; + + if (kind == ICAL_VTIMEZONE_COMPONENT) + continue; + + icalcomponent_remove_component (component, subcomponent); + icalcomponent_free (subcomponent); + } + + /* XXX Do something with the return value. */ + attachment_handler_update_objects (client, component); + + g_object_unref (attachment); + g_object_unref (client); +} + +static void +attachment_handler_row_activated_cb (GtkDialog *dialog) +{ + gtk_dialog_response (dialog, GTK_RESPONSE_OK); +} + +static void +attachment_handler_run_dialog (GtkWindow *parent, + EAttachment *attachment, + ECalSourceType source_type, + const gchar *title) +{ + GtkWidget *dialog; + GtkWidget *container; + GtkWidget *widget; + GCallback callback; + ESourceSelector *selector; + ESourceList *source_list; + ESource *source; + ECal *client; + icalcomponent *component; + GError *error = NULL; + + component = attachment_handler_get_component (attachment); + g_return_if_fail (component != NULL); + + e_cal_get_sources (&source_list, source_type, &error); + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + return; + } + + source = e_source_list_peek_source_any (source_list); + g_return_if_fail (source != NULL); + + dialog = gtk_dialog_new_with_buttons ( + title, parent, GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); + + widget = gtk_button_new_with_mnemonic (_("I_mport")); + gtk_button_set_image ( + GTK_BUTTON (widget), gtk_image_new_from_icon_name ( + "stock_mail-import", GTK_ICON_SIZE_MENU)); + gtk_dialog_add_action_widget ( + GTK_DIALOG (dialog), widget, GTK_RESPONSE_OK); + gtk_widget_show (widget); + + gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); + gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 400); + + container = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); + + widget = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy ( + GTK_SCROLLED_WINDOW (widget), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type ( + GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN); + gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); + gtk_widget_show (widget); + + container = widget; + + widget = e_source_selector_new (source_list); + selector = E_SOURCE_SELECTOR (widget); + e_source_selector_set_primary_selection (selector, source); + e_source_selector_show_selection (selector, FALSE); + gtk_container_add (GTK_CONTAINER (container), widget); + gtk_widget_show (widget); + + g_signal_connect_swapped ( + widget, "row-activated", + G_CALLBACK (attachment_handler_row_activated_cb), dialog); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK) + goto exit; + + source = e_source_selector_peek_primary_selection (selector); + if (source == NULL) + goto exit; + + client = auth_new_cal_from_source (source, source_type); + if (client == NULL) + goto exit; + + if (source_type == E_CAL_SOURCE_TYPE_EVENT) + callback = G_CALLBACK (attachment_handler_import_event); + else if (source_type == E_CAL_SOURCE_TYPE_TODO) + callback = G_CALLBACK (attachment_handler_import_todo); + else + goto exit; + + g_object_ref (attachment); + g_signal_connect (client, "cal-opened", callback, attachment); + e_cal_open_async (client, FALSE); + +exit: + gtk_widget_destroy (dialog); +} + +static void +attachment_handler_import_to_calendar (GtkAction *action, + EAttachmentHandler *handler) +{ + EAttachment *attachment; + EAttachmentView *view; + GList *selected; + gpointer parent; + + view = e_attachment_handler_get_view (handler); + + parent = gtk_widget_get_toplevel (GTK_WIDGET (view)); + parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL; + + selected = e_attachment_view_get_selected_attachments (view); + g_return_if_fail (g_list_length (selected) == 1); + attachment = E_ATTACHMENT (selected->data); + + attachment_handler_run_dialog ( + parent, attachment, + E_CAL_SOURCE_TYPE_EVENT, + _("Select a Calendar")); + + g_object_unref (attachment); + g_list_free (selected); +} + +static void +attachment_handler_import_to_tasks (GtkAction *action, + EAttachmentHandler *handler) +{ + EAttachment *attachment; + EAttachmentView *view; + GList *selected; + gpointer parent; + + view = e_attachment_handler_get_view (handler); + + parent = gtk_widget_get_toplevel (GTK_WIDGET (view)); + parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL; + + selected = e_attachment_view_get_selected_attachments (view); + g_return_if_fail (g_list_length (selected) == 1); + attachment = E_ATTACHMENT (selected->data); + + attachment_handler_run_dialog ( + parent, attachment, + E_CAL_SOURCE_TYPE_TODO, + _("Select a Task List")); + + g_object_unref (attachment); + g_list_free (selected); +} + +static GtkActionEntry standard_entries[] = { + + { "import-to-calendar", + "stock_mail-import", + N_("I_mport to Calendar"), + NULL, + NULL, /* XXX Add a tooltip! */ + G_CALLBACK (attachment_handler_import_to_calendar) }, + + { "import-to-tasks", + "stock_mail-import", + N_("I_mport to Tasks"), + NULL, + NULL, /* XXX Add a tooltip! */ + G_CALLBACK (attachment_handler_import_to_tasks) } +}; + +static void +attachment_handler_calendar_update_actions (EAttachmentView *view) +{ + EAttachment *attachment; + GtkAction *action; + GList *selected; + icalcomponent *component; + icalcomponent *subcomponent; + icalcomponent_kind kind; + gboolean is_vevent = FALSE; + gboolean is_vtodo = FALSE; + + selected = e_attachment_view_get_selected_attachments (view); + + if (g_list_length (selected) != 1) + goto exit; + + attachment = E_ATTACHMENT (selected->data); + component = attachment_handler_get_component (attachment); + + if (component == NULL) + goto exit; + + subcomponent = icalcomponent_get_inner (component); + + if (subcomponent == NULL) + goto exit; + + kind = icalcomponent_isa (subcomponent); + is_vevent = (kind == ICAL_VEVENT_COMPONENT); + is_vtodo = (kind == ICAL_VTODO_COMPONENT); + +exit: + action = e_attachment_view_get_action (view, "import-to-calendar"); + gtk_action_set_visible (action, is_vevent); + + action = e_attachment_view_get_action (view, "import-to-tasks"); + gtk_action_set_visible (action, is_vtodo); + + g_list_foreach (selected, (GFunc) g_object_unref, NULL); + g_list_free (selected); +} + +static void +attachment_handler_calendar_constructed (GObject *object) +{ + EAttachmentHandler *handler; + EAttachmentView *view; + GtkActionGroup *action_group; + GtkUIManager *ui_manager; + GError *error = NULL; + + handler = E_ATTACHMENT_HANDLER (object); + + /* Chain up to parent's constructed() method. */ + G_OBJECT_CLASS (parent_class)->constructed (object); + + view = e_attachment_handler_get_view (handler); + + action_group = e_attachment_view_add_action_group (view, "calendar"); + gtk_action_group_add_actions ( + action_group, standard_entries, + G_N_ELEMENTS (standard_entries), handler); + + ui_manager = e_attachment_view_get_ui_manager (view); + gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, &error); + + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } + + g_signal_connect ( + view, "update_actions", + G_CALLBACK (attachment_handler_calendar_update_actions), + NULL); +} + +static void +attachment_handler_calendar_class_init (EAttachmentHandlerCalendarClass *class) +{ + GObjectClass *object_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EAttachmentHandlerCalendarPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->constructed = attachment_handler_calendar_constructed; +} + +static void +attachment_handler_calendar_init (EAttachmentHandlerCalendar *handler) +{ + handler->priv = E_ATTACHMENT_HANDLER_CALENDAR_GET_PRIVATE (handler); +} + +GType +e_attachment_handler_calendar_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EAttachmentHandlerCalendarClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) attachment_handler_calendar_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EAttachmentHandlerCalendar), + 0, /* n_preallocs */ + (GInstanceInitFunc) attachment_handler_calendar_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + E_TYPE_ATTACHMENT_HANDLER, + "EAttachmentHandlerCalendar", &type_info, 0); + } + + return type; +} diff --git a/calendar/gui/e-attachment-handler-calendar.h b/calendar/gui/e-attachment-handler-calendar.h new file mode 100644 index 0000000000..b6788611f8 --- /dev/null +++ b/calendar/gui/e-attachment-handler-calendar.h @@ -0,0 +1,65 @@ +/* + * e-attachment-handler-calendar.h + * + * 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; either + * version 2 of the License, or (at your option) version 3. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef E_ATTACHMENT_HANDLER_CALENDAR_H +#define E_ATTACHMENT_HANDLER_CALENDAR_H + +#include + +/* Standard GObject macros */ +#define E_TYPE_ATTACHMENT_HANDLER_CALENDAR \ + (e_attachment_handler_calendar_get_type ()) +#define E_ATTACHMENT_HANDLER_CALENDAR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_ATTACHMENT_HANDLER_CALENDAR, EAttachmentHandlerCalendar)) +#define E_ATTACHMENT_HANDLER_CALENDAR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_ATTACHMENT_HANDLER_CALENDAR, EAttachmentHandlerCalendarClass)) +#define E_IS_ATTACHMENT_HANDLER_CALENDAR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_ATTACHMENT_HANDLER_CALENDAR)) +#define E_IS_ATTACHMENT_HANDLER_CALENDAR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_ATTACHMENT_HANDLER_CALENDAR)) +#define E_ATTACHMENT_HANDLER_CALENDAR_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_ATTACHMENT_HANDLER_CALENDAR, EAttachmentHandlerCalendarClass)) + +G_BEGIN_DECLS + +typedef struct _EAttachmentHandlerCalendar EAttachmentHandlerCalendar; +typedef struct _EAttachmentHandlerCalendarClass EAttachmentHandlerCalendarClass; +typedef struct _EAttachmentHandlerCalendarPrivate EAttachmentHandlerCalendarPrivate; + +struct _EAttachmentHandlerCalendar { + EAttachmentHandler parent; + EAttachmentHandlerCalendarPrivate *priv; +}; + +struct _EAttachmentHandlerCalendarClass { + EAttachmentHandlerClass parent_class; +}; + +GType e_attachment_handler_calendar_get_type (void); + +G_END_DECLS + +#endif /* E_ATTACHMENT_HANDLER_CALENDAR_H */ -- cgit v1.2.3 From 4449a34101406bffe508dd40b8b653f7c7d14c7d Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 27 Apr 2009 15:36:19 -0400 Subject: Commit the rest of the attachment UI rewrite Oops, last commit only included the -new- files. This also removes EExpander, which is no longer used. --- calendar/gui/Makefile.am | 2 + calendar/gui/calendar-component.c | 4 + calendar/gui/dialogs/comp-editor.c | 1229 ++++++++--------------------------- calendar/gui/dialogs/event-editor.c | 2 - calendar/gui/e-cal-popup.c | 417 ------------ calendar/gui/e-cal-popup.h | 2 - 6 files changed, 295 insertions(+), 1361 deletions(-) (limited to 'calendar/gui') diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am index e61f6a1f91..b5dab7aeac 100644 --- a/calendar/gui/Makefile.am +++ b/calendar/gui/Makefile.am @@ -69,6 +69,8 @@ etspec_DATA = \ libevolution_calendar_la_SOURCES = \ $(IDL_GENERATED) \ + e-attachment-handler-calendar.c \ + e-attachment-handler-calendar.h \ cal-search-bar.c \ cal-search-bar.h \ calendar-config.c \ diff --git a/calendar/gui/calendar-component.c b/calendar/gui/calendar-component.c index 942960bff5..4d30929272 100644 --- a/calendar/gui/calendar-component.c +++ b/calendar/gui/calendar-component.c @@ -58,6 +58,7 @@ #include "e-util/e-error.h" #include "e-cal-menu.h" #include "e-cal-popup.h" +#include "e-attachment-handler-calendar.h" /* IDs for user creatable items */ #define CREATE_EVENT_ID "event" @@ -1576,6 +1577,9 @@ calendar_component_class_init (CalendarComponentClass *class) object_class->dispose = impl_dispose; object_class->finalize = impl_finalize; + + /* Register attachment handler types. */ + e_attachment_handler_calendar_get_type (); } static void diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c index f3034359c6..6456a5ce04 100644 --- a/calendar/gui/dialogs/comp-editor.c +++ b/calendar/gui/dialogs/comp-editor.c @@ -63,9 +63,9 @@ #include "../e-cal-popup.h" #include "../calendar-config-keys.h" #include "cal-attachment-select-file.h" +#include "widgets/misc/e-attachment-view.h" +#include "widgets/misc/e-attachment-paned.h" -#include "e-attachment-bar.h" -#include "misc/e-expander.h" #include "e-util/e-error.h" #define COMP_EDITOR_GET_PRIVATE(obj) \ @@ -95,12 +95,7 @@ struct _CompEditorPrivate { GtkNotebook *notebook; /* Attachment handling */ - GtkWidget *attachment_bar; - GtkWidget *attachment_scrolled_window; - GtkWidget *attachment_expander; - GtkWidget *attachment_expander_label; - GtkWidget *attachment_expander_icon; - GtkWidget *attachment_expander_num; + GtkWidget *attachment_view; /* Manages menus and toolbars */ GtkUIManager *manager; @@ -151,7 +146,7 @@ static const gchar *ui = " " " " " " -" " +" " " " " " " " @@ -163,13 +158,10 @@ static const gchar *ui = " " " " " " -" " -" " " " ""; static void comp_editor_show_help (CompEditor *editor); -static void setup_widgets (CompEditor *editor); static void real_edit_comp (CompEditor *editor, ECalComponent *comp); static gboolean real_send_comp (CompEditor *editor, ECalComponentItipMethod method, gboolean strip_alarms); @@ -180,43 +172,9 @@ static void page_dates_changed_cb (CompEditor *editor, CompEditorPageDates *date static void obj_modified_cb (ECal *client, GList *objs, gpointer data); static void obj_removed_cb (ECal *client, GList *uids, gpointer data); -static gboolean open_attachment (EAttachmentBar *bar, CompEditor *editor); G_DEFINE_TYPE (CompEditor, comp_editor, GTK_TYPE_WINDOW) -enum { - DND_TYPE_MESSAGE_RFC822, - DND_TYPE_X_UID_LIST, - DND_TYPE_TEXT_URI_LIST, - DND_TYPE_NETSCAPE_URL, - DND_TYPE_TEXT_VCARD, - DND_TYPE_TEXT_CALENDAR, -}; - -static GtkTargetEntry drop_types[] = { - { "message/rfc822", 0, DND_TYPE_MESSAGE_RFC822 }, - { "x-uid-list", 0, DND_TYPE_X_UID_LIST }, - { "text/uri-list", 0, DND_TYPE_TEXT_URI_LIST }, - { "_NETSCAPE_URL", 0, DND_TYPE_NETSCAPE_URL }, - { "text/x-vcard", 0, DND_TYPE_TEXT_VCARD }, - { "text/calendar", 0, DND_TYPE_TEXT_CALENDAR }, -}; - -#define num_drop_types (sizeof (drop_types) / sizeof (drop_types[0])) - -static struct { - char *target; - GdkAtom atom; - guint32 actions; -} drag_info[] = { - { "message/rfc822", NULL, GDK_ACTION_COPY }, - { "x-uid-list", NULL, GDK_ACTION_ASK|GDK_ACTION_MOVE|GDK_ACTION_COPY }, - { "text/uri-list", NULL, GDK_ACTION_COPY }, - { "_NETSCAPE_URL", NULL, GDK_ACTION_COPY }, - { "text/x-vcard", NULL, GDK_ACTION_COPY }, - { "text/calendar", NULL, GDK_ACTION_COPY }, -}; - enum { OBJECT_CREATED, LAST_SIGNAL @@ -224,397 +182,53 @@ enum { static guint comp_editor_signals[LAST_SIGNAL] = { 0 }; -static void -attach_message(CompEditor *editor, CamelMimeMessage *msg) -{ - CamelMimePart *mime_part; - const char *subject; - guint i; - char *filename = NULL; - - mime_part = camel_mime_part_new(); - camel_mime_part_set_disposition(mime_part, "inline"); - subject = camel_mime_message_get_subject(msg); - if (subject) { - char *desc = g_strdup_printf(_("Attached message - %s"), subject); - - camel_mime_part_set_description(mime_part, desc); - g_free(desc); - } else - camel_mime_part_set_description(mime_part, _("Attached message")); - - i = e_attachment_bar_get_num_attachments (E_ATTACHMENT_BAR (editor->priv->attachment_bar)); - i++; - filename = g_strdup_printf ("email%d",i); - camel_mime_part_set_filename (mime_part, filename); - - camel_medium_set_content_object((CamelMedium *)mime_part, (CamelDataWrapper *)msg); - camel_mime_part_set_content_type(mime_part, "message/rfc822"); - e_attachment_bar_attach_mime_part(E_ATTACHMENT_BAR(editor->priv->attachment_bar), mime_part); - camel_object_unref(mime_part); - g_free (filename); -} - -struct _drop_data { - CompEditor *editor; - - GdkDragContext *context; - /* Only selection->data and selection->length are valid */ - GtkSelectionData *selection; - - guint32 action; - guint info; - guint time; - - unsigned int move:1; - unsigned int moved:1; - unsigned int aborted:1; -}; - -static void -drop_action(CompEditor *editor, GdkDragContext *context, guint32 action, GtkSelectionData *selection, guint info, guint time) -{ - char *tmp, *str, **urls; - CamelMimePart *mime_part; - CamelStream *stream; - CamelURL *url; - CamelMimeMessage *msg; - char *content_type; - int i, success=FALSE, delete=FALSE; - - switch (info) { - case DND_TYPE_MESSAGE_RFC822: - d(printf ("dropping a message/rfc822\n")); - /* write the message(s) out to a CamelStream so we can use it */ - stream = camel_stream_mem_new (); - camel_stream_write (stream, (char *)selection->data, selection->length); - camel_stream_reset (stream); - - msg = camel_mime_message_new (); - if (camel_data_wrapper_construct_from_stream((CamelDataWrapper *)msg, stream) != -1) { - attach_message(editor, msg); - success = TRUE; - delete = action == GDK_ACTION_MOVE; - } - - camel_object_unref(msg); - camel_object_unref(stream); - break; - case DND_TYPE_TEXT_URI_LIST: - case DND_TYPE_NETSCAPE_URL: - d(printf ("dropping a text/uri-list\n")); - tmp = g_strndup ((char *)selection->data, selection->length); - urls = g_strsplit (tmp, "\n", 0); - g_free (tmp); - - for (i = 0; urls[i] != NULL; i++) { - str = g_strstrip (urls[i]); - if (urls[i][0] == '#') - continue; - - if (!g_ascii_strncasecmp (str, "mailto:", 7)) { - /* TODO does not handle mailto now */ - } else { - url = camel_url_new (str, NULL); - - if (url == NULL) - continue; - - if (!g_ascii_strcasecmp (url->protocol, "file")) - e_attachment_bar_attach - (E_ATTACHMENT_BAR (editor->priv->attachment_bar), - url->path, - "attachment"); - else - e_attachment_bar_attach_remote_file - (E_ATTACHMENT_BAR (editor->priv->attachment_bar), - str, "attachment"); - - camel_url_free (url); - } - } - - g_strfreev (urls); - success = TRUE; - break; - case DND_TYPE_TEXT_VCARD: - case DND_TYPE_TEXT_CALENDAR: - content_type = gdk_atom_name (selection->type); - d(printf ("dropping a %s\n", content_type)); - - mime_part = camel_mime_part_new (); - camel_mime_part_set_content (mime_part, (char *)selection->data, selection->length, content_type); - camel_mime_part_set_disposition (mime_part, "inline"); - - e_attachment_bar_attach_mime_part - (E_ATTACHMENT_BAR (editor->priv->attachment_bar), - mime_part); - - camel_object_unref (mime_part); - g_free (content_type); - - success = TRUE; - break; - case DND_TYPE_X_UID_LIST: { - GPtrArray *uids; - char *inptr, *inend; - CamelFolder *folder; - CamelException ex = CAMEL_EXCEPTION_INITIALISER; - - /* NB: This all runs synchronously, could be very slow/hang/block the ui */ - - uids = g_ptr_array_new(); - - inptr = (char *)selection->data; - inend = (char *)(selection->data + selection->length); - while (inptr < inend) { - char *start = inptr; - - while (inptr < inend && *inptr) - inptr++; - - if (start > (char *)selection->data) - g_ptr_array_add(uids, g_strndup(start, inptr-start)); - - inptr++; - } - - if (uids->len > 0) { - folder = mail_tool_uri_to_folder((char *)selection->data, 0, &ex); - if (folder) { - if (uids->len == 1) { - msg = camel_folder_get_message(folder, uids->pdata[0], &ex); - if (msg == NULL) - goto fail; - attach_message(editor, msg); - } else { - CamelMultipart *mp = camel_multipart_new(); - char *desc; - char *filename = NULL; - guint num; - - camel_data_wrapper_set_mime_type((CamelDataWrapper *)mp, "multipart/digest"); - camel_multipart_set_boundary(mp, NULL); - for (i=0;ilen;i++) { - - msg = camel_folder_get_message(folder, uids->pdata[i], &ex); - if (msg) { - mime_part = camel_mime_part_new(); - camel_mime_part_set_disposition(mime_part, "inline"); - camel_medium_set_content_object((CamelMedium *)mime_part, (CamelDataWrapper *)msg); - camel_mime_part_set_content_type(mime_part, "message/rfc822"); - camel_multipart_add_part(mp, mime_part); - camel_object_unref(mime_part); - camel_object_unref(msg); - } else { - camel_object_unref(mp); - goto fail; - } - } - mime_part = camel_mime_part_new(); - camel_medium_set_content_object((CamelMedium *)mime_part, (CamelDataWrapper *)mp); - /* translators, this count will always be >1 */ - desc = g_strdup_printf(ngettext("Attached message", "%d attached messages", uids->len), uids->len); - camel_mime_part_set_description(mime_part, desc); - g_free(desc); - - num = e_attachment_bar_get_num_attachments (E_ATTACHMENT_BAR (editor->priv->attachment_bar)); - num++; - filename = g_strdup_printf ("email%d", num); - camel_mime_part_set_filename (mime_part, filename); - - e_attachment_bar_attach_mime_part - (E_ATTACHMENT_BAR(editor->priv->attachment_bar), mime_part); - camel_object_unref(mime_part); - camel_object_unref(mp); - g_free (filename); - } - success = TRUE; - delete = action == GDK_ACTION_MOVE; - fail: - if (camel_exception_is_set(&ex)) { - char *name; - - camel_object_get(folder, NULL, CAMEL_FOLDER_NAME, &name, NULL); - e_error_run((GtkWindow *)editor, "mail-editor:attach-nomessages", - name?name:(char *)selection->data, camel_exception_get_description(&ex), NULL); - camel_object_free(folder, CAMEL_FOLDER_NAME, name); - } - camel_object_unref(folder); - } else { - e_error_run((GtkWindow *)editor, "mail-editor:attach-nomessages", - (char *)selection->data, camel_exception_get_description(&ex), NULL); - } - - camel_exception_clear(&ex); - } - - g_ptr_array_free(uids, TRUE); - - break; } - default: - d(printf ("dropping an unknown\n")); - break; - } - - printf("Drag finished, success %d delete %d\n", success, delete); - - gtk_drag_finish(context, success, delete, time); -} - -static void -drop_popup_copy (EPopup *ep, EPopupItem *item, void *data) -{ - struct _drop_data *m = data; - drop_action(m->editor, m->context, GDK_ACTION_COPY, m->selection, m->info, m->time); -} - -static void -drop_popup_move (EPopup *ep, EPopupItem *item, void *data) -{ - struct _drop_data *m = data; - drop_action(m->editor, m->context, GDK_ACTION_MOVE, m->selection, m->info, m->time); -} - -static void -drop_popup_cancel(EPopup *ep, EPopupItem *item, void *data) -{ - struct _drop_data *m = data; - gtk_drag_finish(m->context, FALSE, FALSE, m->time); -} - -static EPopupItem drop_popup_menu[] = { - { E_POPUP_ITEM, "00.emc.02", N_("_Copy"), drop_popup_copy, NULL, "mail-copy", 0 }, - { E_POPUP_ITEM, "00.emc.03", N_("_Move"), drop_popup_move, NULL, "mail-move", 0 }, - { E_POPUP_BAR, "10.emc" }, - { E_POPUP_ITEM, "99.emc.00", N_("Cancel _Drag"), drop_popup_cancel, NULL, NULL, 0 }, -}; - -static void -drop_popup_free(EPopup *ep, GSList *items, void *data) -{ - struct _drop_data *m = data; - - g_slist_free(items); - - g_object_unref(m->context); - g_object_unref(m->editor); - g_free(m->selection->data); - g_free(m->selection); - g_free(m); -} - -static void -drag_data_received (CompEditor *editor, GdkDragContext *context, - int x, int y, GtkSelectionData *selection, - guint info, guint time) -{ - if (selection->data == NULL || selection->length == -1) - return; - - if (context->action == GDK_ACTION_ASK) { - ECalPopup *ecp; - GSList *menus = NULL; - GtkMenu *menu; - int i; - struct _drop_data *m; - - m = g_malloc0(sizeof(*m)); - m->context = context; - g_object_ref(context); - m->editor = editor; - g_object_ref(editor); - m->action = context->action; - m->info = info; - m->time = time; - m->selection = g_malloc0(sizeof(*m->selection)); - m->selection->data = g_malloc(selection->length); - memcpy(m->selection->data, selection->data, selection->length); - m->selection->length = selection->length; - - ecp = e_cal_popup_new("org.gnome.evolution.calendar.editor.popup.drop"); - for (i=0;iaction, selection, info, time); - } -} - -static gboolean -drag_motion(GObject *o, GdkDragContext *context, gint x, gint y, guint time, CompEditor *editor) -{ - GList *targets; - GdkDragAction action, actions = 0; - - for (targets = context->targets; targets; targets = targets->next) { - int i; - - for (i=0;idata == (void *)drag_info[i].atom) - actions |= drag_info[i].actions; - } - - actions &= context->actions; - action = context->suggested_action; - /* we default to copy */ - if (action == GDK_ACTION_ASK && (actions & (GDK_ACTION_MOVE|GDK_ACTION_COPY)) != (GDK_ACTION_MOVE|GDK_ACTION_COPY)) - action = GDK_ACTION_COPY; - - gdk_drag_status(context, action, time); - - return action != 0; -} - -static void -add_to_bar (CompEditor *editor, GPtrArray *file_list, int is_inline) -{ - CompEditorPrivate *priv = editor->priv; - int i; - - for (i = 0; i < file_list->len; i++) { - CamelURL *url; - - if (!(url = camel_url_new (file_list->pdata[i], NULL))) - continue; - - if (!g_ascii_strcasecmp (url->protocol, "file")) { - e_attachment_bar_attach((EAttachmentBar *)priv->attachment_bar, url->path, is_inline ? "inline" : "attachment"); - } else { - e_attachment_bar_attach_remote_file ((EAttachmentBar *)priv->attachment_bar, file_list->pdata[i], is_inline ? "inline" : "attachment"); - } - - camel_url_free (url); - } -} - static GSList * get_attachment_list (CompEditor *editor) { - GSList *parts = NULL, *list = NULL, *p = NULL; + EAttachmentStore *store; + EAttachmentView *view; + GtkTreeModel *model; + GtkTreeIter iter; + GSList *parts = NULL, *list = NULL; const char *comp_uid = NULL; const char *local_store = e_cal_get_local_attachment_store (editor->priv->client); + gboolean valid; int ticker=0; + e_cal_component_get_uid (editor->priv->comp, &comp_uid); - parts = e_attachment_bar_get_parts((EAttachmentBar *)editor->priv->attachment_bar); + view = E_ATTACHMENT_VIEW (editor->priv->attachment_view); + store = e_attachment_view_get_store (view); - for (p = parts; p!=NULL ; p = p->next) { + model = GTK_TREE_MODEL (store); + valid = gtk_tree_model_get_iter_first (model, &iter); + + while (valid) { + EAttachment *attachment; CamelDataWrapper *wrapper; + CamelMimePart *mime_part; CamelStream *stream; char *attach_file_url; char *safe_fname, *utf8_safe_fname; char *filename; + gint column_id; + + column_id = E_ATTACHMENT_STORE_COLUMN_ATTACHMENT; + gtk_tree_model_get (model, &iter, column_id, &attachment, -1); + mime_part = e_attachment_get_mime_part (attachment); + g_object_unref (attachment); + + valid = gtk_tree_model_iter_next (model, &iter); - wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (p->data)); + if (mime_part == NULL) + continue; + + wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part)); /* Extract the content from the stream and write it down * as a mime part file into the directory denoting the * calendar source */ - utf8_safe_fname = camel_file_util_safe_filename (camel_mime_part_get_filename ((CamelMimePart *) p->data)); + utf8_safe_fname = camel_file_util_safe_filename (camel_mime_part_get_filename (mime_part)); /* It is absolutely fine to get a NULL from the filename of * mime part. We assume that it is named "Attachment" @@ -993,20 +607,21 @@ static void action_attach_cb (GtkAction *action, CompEditor *editor) { - GPtrArray *file_list; - gboolean is_inline = FALSE; - int i; - - file_list = comp_editor_select_file_attachments (editor, &is_inline); + EAttachmentStore *store; + EAttachmentView *view; - if (file_list) { - add_to_bar (editor, file_list, is_inline); + view = E_ATTACHMENT_VIEW (editor->priv->attachment_view); + store = e_attachment_view_get_store (view); - for (i = 0; i < file_list->len; i++) - g_free (file_list->pdata[i]); + e_attachment_store_run_load_dialog (store, GTK_WINDOW (editor)); +} - g_ptr_array_free (file_list, TRUE); - } +static void +action_classification_cb (GtkRadioAction *action, + GtkRadioAction *current, + CompEditor *editor) +{ + comp_editor_set_changed (editor, TRUE); } static void @@ -1132,12 +747,17 @@ action_save_cb (GtkAction *action, CompEditor *editor) { CompEditorPrivate *priv = editor->priv; + EAttachmentStore *store; + EAttachmentView *view; ECalComponentText text; gboolean delegated = FALSE; gboolean read_only, correct = FALSE; ECalComponent *comp; - if (e_attachment_bar_get_download_count (E_ATTACHMENT_BAR (editor->priv->attachment_bar)) ){ + view = E_ATTACHMENT_VIEW (priv->attachment_view); + store = e_attachment_view_get_store (view); + + if (e_attachment_store_get_num_loading (store) > 0) { gboolean response = 1; /*FIXME: Cannot use mail functions from calendar!!!! */ #if 0 @@ -1519,6 +1139,40 @@ static GtkToggleActionEntry coordinated_toggle_entries[] = { FALSE } }; +static void +comp_editor_setup_recent_menu (CompEditor *editor) +{ + EAttachmentView *view; + GtkUIManager *ui_manager; + GtkAction *action; + GtkActionGroup *action_group; + const gchar *action_name; + const gchar *path; + guint merge_id; + + ui_manager = editor->priv->manager; + view = E_ATTACHMENT_VIEW (editor->priv->attachment_view); + action_group = comp_editor_get_action_group (editor, "individual"); + merge_id = gtk_ui_manager_new_merge_id (ui_manager); + path = "/main-menu/insert-menu/recent-placeholder"; + action_name = "recent-menu"; + + action = e_attachment_view_recent_action_new ( + view, action_name, _("Recent _Documents")); + + if (action != NULL) { + gtk_action_group_add_action (action_group, action); + g_object_unref (action); + + gtk_ui_manager_add_ui ( + ui_manager, merge_id, path, + action_name, action_name, + GTK_UI_MANAGER_AUTO, FALSE); + } + + gtk_ui_manager_ensure_update (ui_manager); +} + static void comp_editor_set_property (GObject *object, guint property_id, @@ -1695,15 +1349,89 @@ comp_editor_map (GtkWidget *widget) GTK_WIDGET_CLASS (comp_editor_parent_class)->map (widget); } +static gboolean +comp_editor_delete_event (GtkWidget *widget, + GdkEventAny *event) +{ + CompEditor *editor; + + editor = COMP_EDITOR (widget); + + commit_all_fields (editor); + + if (prompt_and_save_changes (editor, TRUE)) + close_dialog (editor); + + return TRUE; +} + +static gboolean +comp_editor_key_press_event (GtkWidget *widget, + GdkEventKey *event) +{ + CompEditor *editor; + + editor = COMP_EDITOR (widget); + + if (event->keyval == GDK_Escape) { + commit_all_fields (editor); + + if (prompt_and_save_changes (editor, TRUE)) + close_dialog (editor); + + return TRUE; + } + + /* Chain up to parent's key_press_event() method. */ + return GTK_WIDGET_CLASS (comp_editor_parent_class)-> + key_press_event (widget, event); +} + +static gboolean +comp_editor_drag_motion (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time) +{ + CompEditorPrivate *priv; + EAttachmentView *view; + + priv = COMP_EDITOR_GET_PRIVATE (widget); + view = E_ATTACHMENT_VIEW (priv->attachment_view); + + return e_attachment_view_drag_motion (view, context, x, y, time); +} + +static void +comp_editor_drag_data_received (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection, + guint info, + guint time) +{ + CompEditorPrivate *priv; + EAttachmentView *view; + + priv = COMP_EDITOR_GET_PRIVATE (widget); + view = E_ATTACHMENT_VIEW (priv->attachment_view); + + /* Forward the data to the attachment view. Note that calling + * e_attachment_view_drag_data_received() will not work because + * that function only handles the case where all the other drag + * handlers have failed. */ + e_attachment_paned_drag_data_received ( + E_ATTACHMENT_PANED (view), + context, x, y, selection, info, time); +} + static void comp_editor_class_init (CompEditorClass *class) { GObjectClass *object_class; GtkWidgetClass *widget_class; - int i; - - for (i = 0; i < G_N_ELEMENTS (drag_info); i++) - drag_info[i].atom = gdk_atom_intern(drag_info[i].target, FALSE); g_type_class_add_private (class, sizeof (CompEditorPrivate)); @@ -1715,6 +1443,10 @@ comp_editor_class_init (CompEditorClass *class) widget_class = GTK_WIDGET_CLASS (class); widget_class->map = comp_editor_map; + widget_class->delete_event = comp_editor_delete_event; + widget_class->key_press_event = comp_editor_key_press_event; + widget_class->drag_motion = comp_editor_drag_motion; + widget_class->drag_data_received = comp_editor_drag_data_received; class->help_section = "usage-calendar"; class->edit_comp = real_edit_comp; @@ -1776,20 +1508,19 @@ comp_editor_class_init (CompEditorClass *class) G_TYPE_NONE, 0); } -static void -classification_changed_cb (GtkRadioAction *action, GtkRadioAction *current, CompEditor *editor) -{ - g_return_if_fail (IS_COMP_EDITOR (editor)); - - comp_editor_set_changed (editor, TRUE); -} - static void comp_editor_init (CompEditor *editor) { CompEditorPrivate *priv; + EAttachmentView *view; + GdkDragAction drag_actions; + GtkTargetList *target_list; + GtkTargetEntry *targets; GtkActionGroup *action_group; GtkAction *action; + GtkWidget *container; + GtkWidget *widget; + gint n_targets; GError *error = NULL; editor->priv = priv = COMP_EDITOR_GET_PRIVATE (editor); @@ -1798,17 +1529,18 @@ comp_editor_init (CompEditor *editor) priv->changed = FALSE; priv->needs_send = FALSE; priv->mod = CALOBJ_MOD_ALL; - priv->existing_org = FALSE; - priv->user_org = FALSE; - priv->warned = FALSE; + priv->existing_org = FALSE; + priv->user_org = FALSE; + priv->warned = FALSE; priv->is_group_item = FALSE; - priv->attachment_bar = e_attachment_bar_new (NULL); priv->manager = gtk_ui_manager_new (); - gtk_window_add_accel_group ( - GTK_WINDOW (editor), - gtk_ui_manager_get_accel_group (priv->manager)); + gtk_window_add_accel_group ( + GTK_WINDOW (editor), + gtk_ui_manager_get_accel_group (priv->manager)); + + /* Setup Action Groups */ action_group = gtk_action_group_new ("core"); gtk_action_group_set_translation_domain ( @@ -1833,11 +1565,7 @@ comp_editor_init (CompEditor *editor) action_group, classification_radio_entries, G_N_ELEMENTS (classification_radio_entries), E_CAL_COMPONENT_CLASS_PUBLIC, - G_CALLBACK (classification_changed_cb), editor); - action = e_attachment_bar_recent_action_new ( - E_ATTACHMENT_BAR (priv->attachment_bar), - "attach-recent", _("Recent _Documents")); - gtk_action_group_add_action (action_group, action); + G_CALLBACK (action_classification_cb), editor); gtk_ui_manager_insert_action_group ( priv->manager, action_group, 0); g_object_unref (action_group); @@ -1867,14 +1595,57 @@ comp_editor_init (CompEditor *editor) g_error_free (error); } - setup_widgets (editor); + /* Setup Widgets */ + + container = GTK_WIDGET (editor); + + widget = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (container), widget); + gtk_widget_show (widget); + + container = widget; + + widget = comp_editor_get_managed_widget (editor, "/main-menu"); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); + + widget = comp_editor_get_managed_widget (editor, "/main-toolbar"); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); + + widget = e_attachment_paned_new (); + gtk_container_set_border_width (GTK_CONTAINER (widget), 6); + gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); + priv->attachment_view = g_object_ref (widget); + gtk_widget_show (widget); + + container = e_attachment_paned_get_content_area ( + E_ATTACHMENT_PANED (priv->attachment_view)); + + widget = gtk_notebook_new (); + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), FALSE); + gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); + priv->notebook = GTK_NOTEBOOK (widget); + gtk_widget_show (widget); + + comp_editor_setup_recent_menu (editor); - /* DND support */ - gtk_drag_dest_set (GTK_WIDGET (editor), GTK_DEST_DEFAULT_ALL, drop_types, num_drop_types, GDK_ACTION_COPY|GDK_ACTION_ASK|GDK_ACTION_MOVE); - g_signal_connect(editor, "drag_data_received", G_CALLBACK (drag_data_received), NULL); - g_signal_connect(editor, "drag-motion", G_CALLBACK(drag_motion), editor); + /* Drag-and-Drop Support */ - gtk_window_set_type_hint (GTK_WINDOW (editor), GDK_WINDOW_TYPE_HINT_NORMAL); + view = E_ATTACHMENT_VIEW (priv->attachment_view); + target_list = e_attachment_view_get_target_list (view); + drag_actions = e_attachment_view_get_drag_actions (view); + + targets = gtk_target_table_new_from_list (target_list, &n_targets); + + gtk_drag_dest_set ( + GTK_WIDGET (editor), GTK_DEST_DEFAULT_ALL, + targets, n_targets, drag_actions); + + gtk_target_table_free (targets, n_targets); + + gtk_window_set_type_hint ( + GTK_WINDOW (editor), GDK_WINDOW_TYPE_HINT_NORMAL); } static gboolean @@ -1927,401 +1698,16 @@ prompt_and_save_changes (CompEditor *editor, gboolean send) } } -static int -delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data) -{ - CompEditor *editor = COMP_EDITOR (data); - - commit_all_fields (editor); - - if (prompt_and_save_changes (editor, TRUE)) - close_dialog (editor); - - return TRUE; -} - static void -attachment_bar_changed_cb (EAttachmentBar *bar, - void *data) +attachment_store_changed_cb (CompEditor *editor) { - CompEditor *editor = COMP_EDITOR (data); - - guint attachment_num = e_attachment_bar_get_num_attachments ( - E_ATTACHMENT_BAR (editor->priv->attachment_bar)); - if (attachment_num) { - gchar *num_text = g_strdup_printf ( - ngettext ("%d Attachment", "%d Attachments", attachment_num), - attachment_num); - gtk_label_set_markup (GTK_LABEL (editor->priv->attachment_expander_num), - num_text); - g_free (num_text); - - gtk_widget_show (editor->priv->attachment_expander_icon); - e_expander_set_expanded(E_EXPANDER(editor->priv->attachment_expander),TRUE); - - } else { - gtk_label_set_text (GTK_LABEL (editor->priv->attachment_expander_num), ""); - gtk_widget_hide (editor->priv->attachment_expander_icon); - e_expander_set_expanded(E_EXPANDER(editor->priv->attachment_expander),FALSE); - } - - /* Mark the editor as changed so it prompts about unsaved changes on close */ comp_editor_set_changed (editor, TRUE); - -} - -static void -attachment_expander_activate_cb (EExpander *expander, - void *data) -{ - CompEditor *editor = COMP_EDITOR (data); - gboolean show = e_expander_get_expanded (expander); - - /* Update the expander label */ - if (show) - gtk_label_set_text_with_mnemonic (GTK_LABEL (editor->priv->attachment_expander_label), - _("Hide Attachment _Bar")); - else - gtk_label_set_text_with_mnemonic (GTK_LABEL (editor->priv->attachment_expander_label), - _("Show Attachment _Bar")); -} - -static gboolean -open_attachment (EAttachmentBar *bar, CompEditor *editor) -{ - GnomeIconList *icon_list; - GList *p; - int num; - char *attach_file_url; - - if (E_IS_ATTACHMENT_BAR (bar)) { - icon_list = GNOME_ICON_LIST (bar); - p = gnome_icon_list_get_selection (icon_list); - if (p) { - EAttachment *attachment; - GSList *list; - const char *comp_uid = NULL; - char *filename = NULL; - const char *local_store = e_cal_get_local_attachment_store (editor->priv->client); - - e_cal_component_get_uid (editor->priv->comp, &comp_uid); - num = GPOINTER_TO_INT (p->data); - list = e_attachment_bar_get_attachment (bar, num); - attachment = list->data; - g_slist_free (list); - - filename = g_strdup_printf ("%s-%s", - comp_uid, - camel_mime_part_get_filename(attachment->body)); - - attach_file_url = g_build_path ("/", local_store, filename, NULL); - - /* launch the url now */ - e_show_uri (GTK_WINDOW (editor), attach_file_url); - - g_free (filename); - g_free (attach_file_url); } - return TRUE; - } else - return FALSE; -} - -static gboolean -attachment_bar_icon_clicked_cb (EAttachmentBar *bar, GdkEvent *event, CompEditor *editor) -{ - if (E_IS_ATTACHMENT_BAR (bar) && event->type == GDK_2BUTTON_PRESS) - if (open_attachment (bar, editor)) - return TRUE; - return FALSE; -} - -/* Callbacks. */ - -static void -cab_open(EPopup *ep, EPopupItem *item, void *data) -{ - EAttachmentBar *bar = data; - CompEditor *editor = COMP_EDITOR (gtk_widget_get_toplevel (GTK_WIDGET (bar))); - - if (!open_attachment (bar, editor)) - g_message ("\n Open failed"); -} - -static void -cab_add(EPopup *ep, EPopupItem *item, void *data) -{ - EAttachmentBar *bar = data; - CompEditor *editor = COMP_EDITOR (gtk_widget_get_toplevel (GTK_WIDGET (bar))); - GPtrArray *file_list; - gboolean is_inline = FALSE; - int i; - - file_list = comp_editor_select_file_attachments (editor, &is_inline); - /*TODO add a good implementation here */ - if (!file_list) - return; - for (i = 0; i < file_list->len; i++) { - CamelURL *url; - - url = camel_url_new (file_list->pdata[i], NULL); - if (url == NULL) - continue; - - if (!g_ascii_strcasecmp (url->protocol, "file")) - e_attachment_bar_attach (bar, url->path, is_inline ? "inline" : "attachment"); - else - e_attachment_bar_attach_remote_file (bar, file_list->pdata[i], is_inline ? "inline" : "attachment"); - g_free (file_list->pdata[i]); - camel_url_free (url); - } - - g_ptr_array_free (file_list, TRUE); -} - -static void -cab_properties(EPopup *ep, EPopupItem *item, void *data) -{ - EAttachmentBar *bar = data; - - e_attachment_bar_edit_selected(bar); -} - -static void -cab_remove(EPopup *ep, EPopupItem *item, void *data) -{ - EAttachmentBar *bar = data; - - e_attachment_bar_remove_selected(bar); -} - -/* Popup menu handling. */ -static EPopupItem cab_popups[] = { - { E_POPUP_ITEM, "10.attach", N_("_Open"), cab_open, NULL, GTK_STOCK_OPEN, E_CAL_POPUP_ATTACHMENTS_ONE}, - { E_POPUP_ITEM, "20.attach", N_("_Remove"), cab_remove, NULL, GTK_STOCK_REMOVE, E_CAL_POPUP_ATTACHMENTS_MANY | E_CAL_POPUP_ATTACHMENTS_MODIFY }, - { E_POPUP_ITEM, "30.attach", N_("_Properties"), cab_properties, NULL, GTK_STOCK_PROPERTIES, E_CAL_POPUP_ATTACHMENTS_ONE }, - { E_POPUP_BAR, "40.attach.00", NULL, NULL, NULL, NULL, E_CAL_POPUP_ATTACHMENTS_MANY|E_CAL_POPUP_ATTACHMENTS_ONE }, - { E_POPUP_ITEM, "40.attach.01", N_("_Add attachment..."), cab_add, NULL, GTK_STOCK_ADD, E_CAL_POPUP_ATTACHMENTS_MODIFY}, -}; - -static void -cab_popup_position(GtkMenu *menu, int *x, int *y, gboolean *push_in, gpointer user_data) -{ - EAttachmentBar *bar = user_data; - GnomeIconList *icon_list = user_data; - GList *selection; - GnomeCanvasPixbuf *image; - - gdk_window_get_origin (((GtkWidget*) bar)->window, x, y); - - selection = gnome_icon_list_get_selection (icon_list); - if (selection == NULL) - return; - - image = gnome_icon_list_get_icon_pixbuf_item (icon_list, GPOINTER_TO_INT(selection->data)); - if (image == NULL) - return; - - /* Put menu to the center of icon. */ - *x += (int)(image->item.x1 + image->item.x2) / 2; - *y += (int)(image->item.y1 + image->item.y2) / 2; -} - -static void -cab_popups_free(EPopup *ep, GSList *l, void *data) -{ - g_slist_free(l); -} - -/* if id != -1, then use it as an index for target of the popup */ -static void -cab_popup(EAttachmentBar *bar, GdkEventButton *event, int id) -{ - GSList *attachments = NULL, *menus = NULL; - int i; - ECalPopup *ecp; - ECalPopupTargetAttachments *t; - GtkMenu *menu; - CompEditor *editor = COMP_EDITOR (gtk_widget_get_toplevel (GTK_WIDGET (bar))); - - attachments = e_attachment_bar_get_attachment(bar, id); - - for (i=0;itarget.widget = (GtkWidget *)bar; - menu = e_popup_create_menu_once((EPopup *)ecp, (EPopupTarget *)t, 0); - - if (event == NULL) - gtk_menu_popup(menu, NULL, NULL, cab_popup_position, bar, 0, gtk_get_current_event_time()); - else - gtk_menu_popup(menu, NULL, NULL, NULL, NULL, event->button, event->time); -} - -/* GtkWidget methods. */ - -static gboolean -popup_menu_event (EAttachmentBar *bar) -{ - cab_popup (bar, NULL, -1); - - return TRUE; -} - - -static int -button_press_event (EAttachmentBar *bar, - GdkEventButton *event) -{ - GnomeIconList *icon_list = GNOME_ICON_LIST (bar); - int icon_number = -1; - - if (event->button != 3) - return FALSE; - - if (!gnome_icon_list_get_selection (icon_list)) { - icon_number = gnome_icon_list_get_icon_at (icon_list, event->x, event->y); - if (icon_number >= 0) { - gnome_icon_list_unselect_all(icon_list); - gnome_icon_list_select_icon (icon_list, icon_number); - } - } - - cab_popup(bar, event, icon_number); - - return TRUE; -} - -static gint -key_press_event (EAttachmentBar *bar, - GdkEventKey *event) -{ - if (event->keyval == GDK_Delete) { - e_attachment_bar_remove_selected (bar); - return TRUE; - } - - return FALSE; -} - -static gint -editor_key_press_event (CompEditor *editor, - GdkEventKey *event) -{ - if (event->keyval == GDK_Escape) { - commit_all_fields (editor); - - if (prompt_and_save_changes (editor, TRUE)) - close_dialog (editor); - - return TRUE; - } - - return FALSE; } /* Menu callbacks */ -static void -setup_widgets (CompEditor *editor) -{ - CompEditorPrivate *priv; - GtkWidget *expander_hbox; - GtkWidget *widget; - GtkWidget *vbox; - - priv = editor->priv; - - /* Useful vbox */ - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (editor), vbox); - gtk_widget_show (vbox); - - /* Main Menu */ - widget = comp_editor_get_managed_widget (editor, "/main-menu"); - gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); - gtk_widget_show (widget); - - /* Main Toolbar */ - widget = comp_editor_get_managed_widget (editor, "/main-toolbar"); - gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); - gtk_widget_show (widget); - - /* Notebook */ - widget = gtk_notebook_new (); - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), FALSE); - gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0); - gtk_widget_show (widget); - priv->notebook = GTK_NOTEBOOK (widget); - - g_signal_connect (editor, "delete_event", G_CALLBACK (delete_event_cb), editor); - g_signal_connect (editor, "key_press_event", G_CALLBACK (editor_key_press_event), editor); - - /*Attachments */ - priv->attachment_scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->attachment_scrolled_window), - GTK_SHADOW_IN); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->attachment_scrolled_window), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - - g_signal_connect (priv->attachment_bar, "button_press_event", G_CALLBACK (button_press_event), NULL); - g_signal_connect (priv->attachment_bar, "key_press_event", G_CALLBACK (key_press_event), NULL); - g_signal_connect (priv->attachment_bar, "popup-menu", G_CALLBACK (popup_menu_event), NULL); - - GTK_WIDGET_SET_FLAGS (priv->attachment_bar, GTK_CAN_FOCUS); - gtk_container_add (GTK_CONTAINER (priv->attachment_scrolled_window), - priv->attachment_bar); - gtk_widget_show (priv->attachment_bar); - g_signal_connect (priv->attachment_bar, "changed", - G_CALLBACK (attachment_bar_changed_cb), editor); - g_signal_connect (GNOME_ICON_LIST (priv->attachment_bar), "event", - G_CALLBACK (attachment_bar_icon_clicked_cb), editor); - priv->attachment_expander_label = - gtk_label_new_with_mnemonic (_("Show Attachment _Bar")); - priv->attachment_expander_num = gtk_label_new (""); - gtk_label_set_use_markup (GTK_LABEL (priv->attachment_expander_num), TRUE); - gtk_misc_set_alignment (GTK_MISC (priv->attachment_expander_label), 0.0, 0.5); - gtk_misc_set_alignment (GTK_MISC (priv->attachment_expander_num), 1.0, 0.5); - expander_hbox = gtk_hbox_new (FALSE, 0); - - priv->attachment_expander_icon = gtk_image_new_from_icon_name ("mail-attachment", GTK_ICON_SIZE_MENU); - gtk_misc_set_alignment (GTK_MISC (priv->attachment_expander_icon), 1, 0.5); - gtk_widget_set_size_request (priv->attachment_expander_icon, 100, -1); - - gtk_box_pack_start (GTK_BOX (expander_hbox), priv->attachment_expander_label, - TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (expander_hbox), priv->attachment_expander_icon, - TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (expander_hbox), priv->attachment_expander_num, - TRUE, TRUE, 0); - gtk_widget_show_all (expander_hbox); - gtk_widget_hide (priv->attachment_expander_icon); - - priv->attachment_expander = e_expander_new (""); - e_expander_set_label_widget (E_EXPANDER (priv->attachment_expander), expander_hbox); - atk_object_set_name (gtk_widget_get_accessible (priv->attachment_expander), _("Show Attachments")); - atk_object_set_description (gtk_widget_get_accessible (priv->attachment_expander), _("Press space key to toggle attachment bar")); - gtk_container_add (GTK_CONTAINER (priv->attachment_expander), priv->attachment_scrolled_window); - - gtk_box_pack_start (GTK_BOX (vbox), priv->attachment_expander, FALSE, FALSE, 4); - gtk_widget_show (priv->attachment_expander); - e_expander_set_expanded (E_EXPANDER (priv->attachment_expander), FALSE); - g_signal_connect_after (priv->attachment_expander, "activate", - G_CALLBACK (attachment_expander_activate_cb), editor); -} - - static void comp_editor_show_help (CompEditor *editor) { @@ -2861,12 +2247,14 @@ comp_editor_get_client (CompEditor *editor) static void set_attachment_list (CompEditor *editor, GSList *attach_list) { - GSList *p = NULL; - const char *comp_uid= NULL; + EAttachmentStore *store; + EAttachmentView *view; + GSList *iter = NULL; - e_cal_component_get_uid (editor->priv->comp, &comp_uid); + view = E_ATTACHMENT_VIEW (editor->priv->attachment_view); + store = e_attachment_view_get_store (view); - if (e_attachment_bar_get_num_attachments (E_ATTACHMENT_BAR (editor->priv->attachment_bar))) { + if (e_attachment_store_get_num_attachments (store) > 0) { /* To prevent repopulating the * bar due to redraw functions in fill_widget. * Assumes it can be set only once. @@ -2874,112 +2262,55 @@ set_attachment_list (CompEditor *editor, GSList *attach_list) return; } - for (p = attach_list; p != NULL; p = p->next) { - char *attach_filename; - CamelMimePart *part; - CamelDataWrapper *wrapper; - CamelStream *stream; - struct stat statbuf; - char *mime_type, *file_name; - char *ptr; - - attach_filename = (char *) p->data; - /* should we assert if g_str_has_prefix (attach_filename, "file://")) - * here - */ - /* get url sans protocol and add it to the bar. - * how to set the filename properly */ - file_name = g_filename_from_uri (attach_filename, NULL, NULL); - if (!file_name) - continue; - - if (g_stat (file_name, &statbuf) < 0) { - g_warning ("Cannot attach file %s: %s", file_name, g_strerror (errno)); - g_free (file_name); - continue; - } - - /* return if it's not a regular file */ - if (!S_ISREG (statbuf.st_mode)) { - g_warning ("Cannot attach file %s: not a regular file", file_name); - g_free (file_name); - return; - } - - stream = camel_stream_fs_new_with_name (file_name, O_RDONLY, 0); - if (!stream) { - g_warning ("Cannot attach file %s: %s", file_name, g_strerror (errno)); - g_free (file_name); - return; - } - - mime_type = e_util_guess_mime_type (file_name, TRUE); - if (mime_type) { - if (!g_ascii_strcasecmp (mime_type, "message/rfc822")) { - wrapper = (CamelDataWrapper *) camel_mime_message_new (); - } else { - wrapper = camel_data_wrapper_new (); - } - - camel_data_wrapper_construct_from_stream (wrapper, stream); - camel_data_wrapper_set_mime_type (wrapper, mime_type); - g_free (mime_type); - } else { - wrapper = camel_data_wrapper_new (); - camel_data_wrapper_construct_from_stream (wrapper, stream); - camel_data_wrapper_set_mime_type (wrapper, "application/octet-stream"); - } - - camel_object_unref (stream); - - part = camel_mime_part_new (); - camel_medium_set_content_object (CAMEL_MEDIUM (part), wrapper); - camel_object_unref (wrapper); + for (iter = attach_list; iter != NULL; iter = iter->next) { + EAttachment *attachment; + const gchar *uri = iter->data; - camel_mime_part_set_disposition (part, "attachment"); - - ptr = strstr (file_name, comp_uid); - if (ptr) { - ptr += strlen(comp_uid); - if (*ptr++ == '-') - camel_mime_part_set_filename (part, ptr); - } - g_free (file_name); - - e_attachment_bar_attach_mime_part ((EAttachmentBar *) editor->priv->attachment_bar, part); - e_expander_set_expanded (E_EXPANDER (editor->priv->attachment_expander), TRUE); - - camel_object_unref (part); + attachment = e_attachment_new_for_uri (uri); + e_attachment_store_add_attachment (store, attachment); + e_attachment_load_async ( + attachment, (GAsyncReadyCallback) + e_attachment_load_handle_error, editor); + g_object_unref (attachment); } } static void fill_widgets (CompEditor *editor) { + EAttachmentStore *store; + EAttachmentView *view; CompEditorPrivate *priv; GList *l; GtkAction *action; + view = E_ATTACHMENT_VIEW (editor->priv->attachment_view); + store = e_attachment_view_get_store (view); + priv = editor->priv; /*Check if attachments are available here and set them*/ if (e_cal_component_has_attachments (priv->comp)) { GSList *attachment_list = NULL; e_cal_component_get_attachment_list (priv->comp, &attachment_list); - g_signal_handlers_block_by_func(priv->attachment_bar, G_CALLBACK (attachment_bar_changed_cb), editor); + g_signal_handlers_block_by_func ( + store, G_CALLBACK (attachment_store_changed_cb), + editor); set_attachment_list (editor, attachment_list); - g_signal_handlers_unblock_by_func(priv->attachment_bar, G_CALLBACK (attachment_bar_changed_cb), editor); + g_signal_handlers_unblock_by_func ( + store, G_CALLBACK (attachment_store_changed_cb), + editor); g_slist_foreach (attachment_list, (GFunc)g_free, NULL); g_slist_free (attachment_list); } action = comp_editor_get_action (editor, "classify-public"); - g_signal_handlers_block_by_func (action, G_CALLBACK (classification_changed_cb), editor); + g_signal_handlers_block_by_func (action, G_CALLBACK (action_classification_cb), editor); for (l = priv->pages; l != NULL; l = l->next) comp_editor_page_fill_widgets (l->data, priv->comp); - g_signal_handlers_unblock_by_func (action, G_CALLBACK (classification_changed_cb), editor); + g_signal_handlers_unblock_by_func (action, G_CALLBACK (action_classification_cb), editor); } static void @@ -3303,20 +2634,41 @@ comp_editor_close (CompEditor *editor) GSList * comp_editor_get_mime_attach_list (CompEditor *editor) { + EAttachmentStore *store; + EAttachmentView *view; + GtkTreeModel *model; + GtkTreeIter iter; struct CalMimeAttach *cal_mime_attach; - GSList *attach_list = NULL, *l, *parts; + GSList *attach_list = NULL; + gboolean valid; + + view = E_ATTACHMENT_VIEW (editor->priv->attachment_view); + store = e_attachment_view_get_store (view); - /* TODO assert sanity of bar */ - parts = e_attachment_bar_get_parts (E_ATTACHMENT_BAR (editor->priv->attachment_bar)); - for (l = parts; l ; l = l->next) { + model = GTK_TREE_MODEL (store); + valid = gtk_tree_model_get_iter_first (model, &iter); + while (valid) { + EAttachment *attachment; CamelDataWrapper *wrapper; + CamelMimePart *mime_part; CamelStreamMem *mstream; unsigned char *buffer = NULL; const char *desc, *disp; + gint column_id; + + column_id = E_ATTACHMENT_STORE_COLUMN_ATTACHMENT; + gtk_tree_model_get (model, &iter, column_id, &attachment, -1); + mime_part = e_attachment_get_mime_part (attachment); + g_object_unref (attachment); + + valid = gtk_tree_model_iter_next (model, &iter); + + if (mime_part == NULL) + continue; cal_mime_attach = g_malloc0 (sizeof (struct CalMimeAttach)); - wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (l->data)); + wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part)); mstream = (CamelStreamMem *) camel_stream_mem_new (); camel_data_wrapper_decode_to_stream (wrapper, (CamelStream *) mstream); @@ -3324,15 +2676,14 @@ comp_editor_get_mime_attach_list (CompEditor *editor) cal_mime_attach->encoded_data = (char *)buffer; cal_mime_attach->length = mstream->buffer->len; - cal_mime_attach->filename = g_strdup (camel_mime_part_get_filename - ((CamelMimePart *) l->data)); - desc = camel_mime_part_get_description ((CamelMimePart *) l->data); + cal_mime_attach->filename = g_strdup (camel_mime_part_get_filename (mime_part)); + desc = camel_mime_part_get_description (mime_part); if (!desc || *desc == '\0') desc = _("attachment"); cal_mime_attach->description = g_strdup (desc); cal_mime_attach->content_type = g_strdup (camel_data_wrapper_get_mime_type (wrapper)); - disp = camel_mime_part_get_disposition ((CamelMimePart *)l->data); + disp = camel_mime_part_get_disposition (mime_part); if (disp && !g_ascii_strcasecmp(disp, "inline")) cal_mime_attach->disposition = TRUE; @@ -3342,8 +2693,6 @@ comp_editor_get_mime_attach_list (CompEditor *editor) } - g_slist_free (parts); - return attach_list; } diff --git a/calendar/gui/dialogs/event-editor.c b/calendar/gui/dialogs/event-editor.c index a579d77348..f32f24501d 100644 --- a/calendar/gui/dialogs/event-editor.c +++ b/calendar/gui/dialogs/event-editor.c @@ -512,8 +512,6 @@ event_editor_init (EventEditor *ee) g_signal_connect_swapped ( ee->priv->model, "row_deleted", G_CALLBACK (event_editor_model_changed_cb), ee); - - gtk_window_set_default_size (GTK_WINDOW (ee), 300, 225); } static void diff --git a/calendar/gui/e-cal-popup.c b/calendar/gui/e-cal-popup.c index b9f0d5f8d5..0292f16c71 100644 --- a/calendar/gui/e-cal-popup.c +++ b/calendar/gui/e-cal-popup.c @@ -86,378 +86,11 @@ ecalp_target_free(EPopup *ep, EPopupTarget *t) /* Standard menu code */ -static char * -temp_save_part(CamelMimePart *part, char *path, gboolean file) -{ - const char *filename; - char *tmpdir, *utf8_mfilename = NULL, *mfilename = NULL, *usepath; - CamelStream *stream; - CamelDataWrapper *wrapper; - - if (!path) { - tmpdir = e_mkdtemp("evolution-tmp-XXXXXX"); - if (tmpdir == NULL) { - return NULL; - } - - filename = camel_mime_part_get_filename (part); - if (filename == NULL) { - /* This is the default filename used for temporary file creation */ - filename = _("Unknown"); - } else { - utf8_mfilename = g_strdup (filename); - e_filename_make_safe (utf8_mfilename); - mfilename = g_filename_from_utf8 ((const char *) utf8_mfilename, -1, NULL, NULL, NULL); - g_free (utf8_mfilename); - filename = (const char *) mfilename; - } - - path = g_build_filename(tmpdir, filename, NULL); - g_free(tmpdir); - g_free(mfilename); - } else if (!file) { - tmpdir = path; - filename = camel_mime_part_get_filename (part); - if (filename == NULL) { - /* This is the default filename used for temporary file creation */ - filename = _("Unknown"); - } else { - utf8_mfilename = g_strdup (filename); - e_filename_make_safe (utf8_mfilename); - mfilename = g_filename_from_utf8 ((const char *)utf8_mfilename, -1, NULL, NULL, NULL); - g_free (utf8_mfilename); - filename = (const char *) mfilename; - } - - path = g_build_filename(tmpdir, filename, NULL); - g_free(mfilename); - } - - if (strstr (path, "://")) - usepath = path; - else - usepath = g_strjoin (NULL, "file://", path, NULL); - - wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part)); - stream = camel_stream_vfs_new_with_uri (usepath, CAMEL_STREAM_VFS_CREATE); - - if (usepath != path) - g_free (usepath); - - if (!stream) { - /* TODO handle error conditions */ - g_message ("DEBUG: could not open the file to write\n"); - return NULL; - } - - if (camel_data_wrapper_decode_to_stream (wrapper, (CamelStream *) stream) == -1) { - camel_stream_close (stream); - camel_object_unref (stream); - g_message ("DEBUG: could not write to file\n"); - return NULL; - } - - camel_stream_close(stream); - camel_object_unref(stream); - - return path; -} - -static void -ecalp_part_popup_saveas(EPopup *ep, EPopupItem *item, void *data) -{ - EPopupTarget *t = ep->target; - CamelMimePart *part = NULL; - char *file, *mfilename = NULL; - const char *filename; - - part = ((EAttachment *) ((ECalPopupTargetAttachments *) t)->attachments->data)->body; - filename = camel_mime_part_get_filename (part); - if (filename == NULL) { - /* This is the default filename used for temporary file creation */ - filename = _("Unknown"); - } else { - mfilename = g_strdup(filename); - e_filename_make_safe(mfilename); - filename = mfilename; - } - file = e_file_dialog_save (_("Save As..."), filename); - - if (file) - temp_save_part (part, file, TRUE); - - g_free (file); - g_free (mfilename); -} - -static void -ecalp_part_popup_save_selected(EPopup *ep, EPopupItem *item, void *data) -{ - GSList *parts; - EPopupTarget *t = ep->target; - char *dir, *path; - - dir = e_file_dialog_save_folder (_("Select folder to save selected attachments...")); - parts = ((ECalPopupTargetAttachments *) t)->attachments; - - for (;parts; parts=parts->next) { - path = temp_save_part (((EAttachment *)parts->data)->body, dir, FALSE); - /* Probably we 'll do some reporting in next release, like listing the saved files and locations */ - g_free (path); - } -} - -static void -ecalp_part_popup_set_background(EPopup *ep, EPopupItem *item, void *data) -{ - EPopupTarget *t = ep->target; - GConfClient *gconf; - char *str, *filename, *path, *extension; - unsigned int i=1; - CamelMimePart *part = NULL; - - part = ((EAttachment *) ((ECalPopupTargetAttachments *) t)->attachments->data)->body; - - if (!part) - return; - - filename = g_strdup(camel_mime_part_get_filename(part)); - - /* if filename is blank, create a default filename based on MIME type */ - if (!filename || !filename[0]) { - CamelContentType *ct; - - ct = camel_mime_part_get_content_type(part); - g_free (filename); - filename = g_strdup_printf (_("untitled_image.%s"), ct->subtype); - } - - e_filename_make_safe(filename); - - path = g_build_filename(g_get_home_dir(), ".gnome2", "wallpapers", filename, NULL); - - extension = strrchr(filename, '.'); - if (extension) - *extension++ = 0; - - /* if file exists, stick a (number) on the end */ - while (g_file_test(path, G_FILE_TEST_EXISTS)) { - char *name; - name = g_strdup_printf(extension?"%s (%d).%s":"%s (%d)", filename, i++, extension); - g_free(path); - path = g_build_filename(g_get_home_dir(), ".gnome2", "wallpapers", name, NULL); - g_free(name); - } - - g_free(filename); - - if (temp_save_part(part, path, TRUE)) { - gconf = gconf_client_get_default(); - - /* if the filename hasn't changed, blank the filename before - * setting it so that gconf detects a change and updates it */ - if ((str = gconf_client_get_string(gconf, "/desktop/gnome/background/picture_filename", NULL)) != NULL - && strcmp (str, path) == 0) { - gconf_client_set_string(gconf, "/desktop/gnome/background/picture_filename", "", NULL); - } - - g_free (str); - gconf_client_set_string(gconf, "/desktop/gnome/background/picture_filename", path, NULL); - - /* if GNOME currently doesn't display a picture, set to "wallpaper" - * display mode, otherwise leave it alone */ - if ((str = gconf_client_get_string(gconf, "/desktop/gnome/background/picture_options", NULL)) == NULL - || strcmp(str, "none") == 0) { - gconf_client_set_string(gconf, "/desktop/gnome/background/picture_options", "wallpaper", NULL); - } - - gconf_client_suggest_sync(gconf, NULL); - - g_free(str); - g_object_unref(gconf); - } - - g_free(path); -} - -static const EPopupItem ecalp_standard_part_apps_bar = { E_POPUP_BAR, "99.object" }; - -static ECalPopupItem ecalp_attachment_object_popups[] = { - { E_POPUP_ITEM, "00.attach.00", N_("_Save As..."), ecalp_part_popup_saveas, NULL, "document-save-as", E_CAL_POPUP_ATTACHMENTS_ONE }, - { E_POPUP_ITEM, "00.attach.10", N_("Set as _Background"), ecalp_part_popup_set_background, NULL, NULL, E_CAL_POPUP_ATTACHMENTS_IMAGE }, - { E_POPUP_ITEM, "00.attach.20", N_("_Save Selected"), ecalp_part_popup_save_selected, NULL, "document-save-as", E_CAL_POPUP_ATTACHMENTS_MULTIPLE }, - { E_POPUP_BAR, "05.attach", }, -}; - -static void -ecalp_apps_open_in(EPopup *ep, EPopupItem *item, void *data) -{ - char *path; - EPopupTarget *target = ep->target; - CamelMimePart *part; - - part = ((EAttachment *) ((ECalPopupTargetAttachments *) target)->attachments->data)->body; - - path = temp_save_part(part, NULL, FALSE); - if (path) { - GAppInfo *app = item->user_data; - GList *uris = NULL; - GError *error = NULL; - - if (g_app_info_supports_files (app)) { - GFile *file = g_file_new_for_path (path); - - uris = g_list_append (uris, file); - g_app_info_launch (app, uris, NULL, &error); - g_object_unref (file); - } else { - char *uri; - - uri = e_util_filename_to_uri (path); - uris = g_list_append (uris, uri); - - g_app_info_launch_uris (app, uris, NULL, &error); - g_free (uri); - } - - if (error) { - g_warning ("%s", error->message); - g_error_free (error); - } - - g_list_free (uris); - g_free (path); - } -} - -static void -ecalp_apps_popup_free(EPopup *ep, GSList *free_list, void *data) -{ - while (free_list) { - GSList *n = free_list->next; - EPopupItem *item = free_list->data; - - if (item->user_data && item->activate == ecalp_apps_open_in) - g_object_unref (item->user_data); - - g_free(item->path); - g_free(item->label); - g_free(item); - g_slist_free_1(free_list); - - free_list = n; - } -} - -static void -ecalp_standard_items_free(EPopup *ep, GSList *items, void *data) -{ - g_slist_free(items); -} - -static void -ecalp_standard_menu_factory (EPopup *ecalp, void *data) -{ - int i, len; - EPopupItem *items; - GSList *menus = NULL; - GList *apps = NULL; - char *mime_type = NULL; - const char *filename = NULL; - - switch (ecalp->target->type) { - case E_CAL_POPUP_TARGET_ATTACHMENTS: { - ECalPopupTargetAttachments *t = (ECalPopupTargetAttachments *)ecalp->target; - GSList *list = t->attachments; - EAttachment *attachment; - - items = ecalp_attachment_object_popups; - len = G_N_ELEMENTS(ecalp_attachment_object_popups); - - if (g_slist_length(list) != 1 || !((EAttachment *)list->data)->is_available_local) { - break; - } - - /* Only one attachment selected */ - attachment = list->data; - mime_type = camel_data_wrapper_get_mime_type((CamelDataWrapper *)attachment->body); - filename = camel_mime_part_get_filename(attachment->body); - - - break; } - default: - items = NULL; - len = 0; - } - - if (mime_type) { - gchar *cp; - - /* does gvfs expect lowercase MIME types? */ - for (cp = mime_type; *cp != '\0'; cp++) - *cp = g_ascii_tolower (*cp); - - cp = g_content_type_from_mime_type (mime_type); - apps = g_app_info_get_all_for_type (cp ? cp : mime_type); - g_free (cp); - - if (apps == NULL || strcmp(mime_type, "application/octet-stream") == 0) { - if (filename) { - gchar *name_type; - - name_type = e_util_guess_mime_type (filename, FALSE); - cp = g_content_type_from_mime_type (name_type); - /* show alternative apps first */ - apps = g_list_concat (g_app_info_get_all_for_type (cp ? cp : name_type), apps); - g_free (cp); - g_free (name_type); - } - } - g_free (mime_type); - - if (apps) { - GSList *open_menus = NULL; - GList *l; - - menus = g_slist_prepend(menus, (void *)&ecalp_standard_part_apps_bar); - - for (l = apps, i = 0; l; l = l->next, i++) { - GAppInfo *app = l->data; - EPopupItem *item; - - item = g_malloc0(sizeof(*item)); - item->type = E_POPUP_ITEM; - item->path = g_strdup_printf("99.object.%02d", i); - item->label = g_strdup_printf(_("Open in %s..."), g_app_info_get_name (app)); - item->activate = ecalp_apps_open_in; - item->user_data = app; - - open_menus = g_slist_prepend(open_menus, item); - } - - if (open_menus) - e_popup_add_items(ecalp, open_menus, NULL, ecalp_apps_popup_free, NULL); - - g_list_free (apps); - } - } - - for (i=0;itarget->mask) == 0) - menus = g_slist_prepend(menus, &items[i]); - } - - if (menus) - e_popup_add_items(ecalp, menus, NULL, ecalp_standard_items_free, NULL); -} - static void ecalp_class_init(GObjectClass *klass) { klass->finalize = ecalp_finalise; ((EPopupClass *)klass)->target_free = ecalp_target_free; - - e_popup_class_add_factory((EPopupClass *)klass, NULL, ecalp_standard_menu_factory, NULL); } GType @@ -750,56 +383,6 @@ e_cal_popup_target_new_source(ECalPopup *eabp, ESourceSelector *selector) return t; } -/** - * e_cal_popup_target_new_attachments: - * @ecp: - * @attachments: A list of CalAttachment objects, reffed for - * the list. Will be unreff'd once finished with. - * - * Owns the list @attachments and their items after they're passed in. - * - * Return value: - **/ -ECalPopupTargetAttachments * -e_cal_popup_target_new_attachments(ECalPopup *ecp, CompEditor *editor, GSList *attachments) -{ - ECalPopupTargetAttachments *t = e_popup_target_new(&ecp->popup, E_CAL_POPUP_TARGET_ATTACHMENTS, sizeof(*t)); - guint32 mask = ~0; - int len = g_slist_length(attachments); - ECal *client = comp_editor_get_client (editor); - CompEditorFlags flags = comp_editor_get_flags (editor); - gboolean read_only = FALSE; - GError *error = NULL; - - if (!e_cal_is_read_only (client, &read_only, &error)) { - if (error->code != E_CALENDAR_STATUS_BUSY) - read_only = TRUE; - g_error_free (error); - } - - if (!read_only && (!(flags & COMP_EDITOR_MEETING) || - (flags & COMP_EDITOR_NEW_ITEM) || - (flags & COMP_EDITOR_USER_ORG))) - mask &= ~ E_CAL_POPUP_ATTACHMENTS_MODIFY; - - t->attachments = attachments; - if (len > 0) - mask &= ~ E_CAL_POPUP_ATTACHMENTS_MANY; - - if (len == 1 && ((EAttachment *)attachments->data)->is_available_local) { - if (camel_content_type_is(((CamelDataWrapper *) ((EAttachment *) attachments->data)->body)->mime_type, "image", "*")) - mask &= ~ E_CAL_POPUP_ATTACHMENTS_IMAGE; - mask &= ~ E_CAL_POPUP_ATTACHMENTS_ONE; - } - - if (len > 1) - mask &= ~ E_CAL_POPUP_ATTACHMENTS_MULTIPLE; - - t->target.mask = mask; - - return t; -} - /* ********************************************************************** */ /* Popup menu plugin handler */ diff --git a/calendar/gui/e-cal-popup.h b/calendar/gui/e-cal-popup.h index fb899c3961..34874efdba 100644 --- a/calendar/gui/e-cal-popup.h +++ b/calendar/gui/e-cal-popup.h @@ -195,8 +195,6 @@ ECalPopup *e_cal_popup_new(const char *menuid); ECalPopupTargetSelect *e_cal_popup_target_new_select(ECalPopup *eabp, struct _ECalModel *model, GPtrArray *events); ECalPopupTargetSource *e_cal_popup_target_new_source(ECalPopup *eabp, struct _ESourceSelector *selector); -ECalPopupTargetAttachments * e_cal_popup_target_new_attachments (ECalPopup *ecp, - CompEditor *editor, GSList *attachments); /* ********************************************************************** */ -- cgit v1.2.3 From de003c135ac993e323edcbd97f74aa28c43601f1 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 27 Apr 2009 20:27:02 -0400 Subject: Use consistent variable names for GtkUIManager --- calendar/gui/dialogs/comp-editor.c | 34 +++++++++++++++++----------------- calendar/gui/dialogs/event-editor.c | 8 ++++---- calendar/gui/dialogs/memo-editor.c | 8 ++++---- calendar/gui/dialogs/task-editor.c | 8 ++++---- 4 files changed, 29 insertions(+), 29 deletions(-) (limited to 'calendar/gui') diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c index 6456a5ce04..5d842d673a 100644 --- a/calendar/gui/dialogs/comp-editor.c +++ b/calendar/gui/dialogs/comp-editor.c @@ -98,7 +98,7 @@ struct _CompEditorPrivate { GtkWidget *attachment_view; /* Manages menus and toolbars */ - GtkUIManager *manager; + GtkUIManager *ui_manager; gchar *summary; @@ -1150,7 +1150,7 @@ comp_editor_setup_recent_menu (CompEditor *editor) const gchar *path; guint merge_id; - ui_manager = editor->priv->manager; + ui_manager = editor->priv->ui_manager; view = E_ATTACHMENT_VIEW (editor->priv->attachment_view); action_group = comp_editor_get_action_group (editor, "individual"); merge_id = gtk_ui_manager_new_merge_id (ui_manager); @@ -1282,9 +1282,9 @@ comp_editor_dispose (GObject *object) priv->comp = NULL; } - if (priv->manager != NULL) { - g_object_unref (priv->manager); - priv->manager = NULL; + if (priv->ui_manager != NULL) { + g_object_unref (priv->ui_manager); + priv->ui_manager = NULL; } /* Chain up to parent's dispose() method. */ @@ -1534,11 +1534,11 @@ comp_editor_init (CompEditor *editor) priv->warned = FALSE; priv->is_group_item = FALSE; - priv->manager = gtk_ui_manager_new (); + priv->ui_manager = gtk_ui_manager_new (); gtk_window_add_accel_group ( GTK_WINDOW (editor), - gtk_ui_manager_get_accel_group (priv->manager)); + gtk_ui_manager_get_accel_group (priv->ui_manager)); /* Setup Action Groups */ @@ -1549,7 +1549,7 @@ comp_editor_init (CompEditor *editor) action_group, core_entries, G_N_ELEMENTS (core_entries), editor); gtk_ui_manager_insert_action_group ( - priv->manager, action_group, 0); + priv->ui_manager, action_group, 0); g_object_unref (action_group); action_group = gtk_action_group_new ("individual"); @@ -1567,7 +1567,7 @@ comp_editor_init (CompEditor *editor) E_CAL_COMPONENT_CLASS_PUBLIC, G_CALLBACK (action_classification_cb), editor); gtk_ui_manager_insert_action_group ( - priv->manager, action_group, 0); + priv->ui_manager, action_group, 0); g_object_unref (action_group); action_group = gtk_action_group_new ("coordinated"); @@ -1577,7 +1577,7 @@ comp_editor_init (CompEditor *editor) action_group, coordinated_toggle_entries, G_N_ELEMENTS (coordinated_toggle_entries), editor); gtk_ui_manager_insert_action_group ( - priv->manager, action_group, 0); + priv->ui_manager, action_group, 0); g_object_unref (action_group); /* Fine Tuning */ @@ -1589,7 +1589,7 @@ comp_editor_init (CompEditor *editor) action = comp_editor_get_action (editor, "save"); gtk_action_set_sensitive (action, FALSE); - gtk_ui_manager_add_ui_from_string (priv->manager, ui, -1, &error); + gtk_ui_manager_add_ui_from_string (priv->ui_manager, ui, -1, &error); if (error != NULL) { g_warning ("%s: %s", G_STRFUNC, error->message); g_error_free (error); @@ -1940,7 +1940,7 @@ comp_editor_get_ui_manager (CompEditor *editor) { g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL); - return editor->priv->manager; + return editor->priv->ui_manager; } GtkAction * @@ -1953,7 +1953,7 @@ comp_editor_get_action (CompEditor *editor, g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL); g_return_val_if_fail (action_name != NULL, NULL); - iter = gtk_ui_manager_get_action_groups (editor->priv->manager); + iter = gtk_ui_manager_get_action_groups (editor->priv->ui_manager); while (iter != NULL && action == NULL) { GtkActionGroup *action_group = iter->data; @@ -1975,7 +1975,7 @@ comp_editor_get_action_group (CompEditor *editor, g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL); g_return_val_if_fail (group_name != NULL, NULL); - iter = gtk_ui_manager_get_action_groups (editor->priv->manager); + iter = gtk_ui_manager_get_action_groups (editor->priv->ui_manager); while (iter != NULL) { GtkActionGroup *action_group = iter->data; const gchar *name; @@ -1993,14 +1993,14 @@ GtkWidget * comp_editor_get_managed_widget (CompEditor *editor, const gchar *widget_path) { - GtkUIManager *manager; + GtkUIManager *ui_manager; GtkWidget *widget; g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL); g_return_val_if_fail (widget_path != NULL, NULL); - manager = comp_editor_get_ui_manager (editor); - widget = gtk_ui_manager_get_widget (manager, widget_path); + ui_manager = comp_editor_get_ui_manager (editor); + widget = gtk_ui_manager_get_widget (ui_manager, widget_path); g_return_val_if_fail (widget != NULL, NULL); return widget; diff --git a/calendar/gui/dialogs/event-editor.c b/calendar/gui/dialogs/event-editor.c index f32f24501d..7755894f6c 100644 --- a/calendar/gui/dialogs/event-editor.c +++ b/calendar/gui/dialogs/event-editor.c @@ -463,7 +463,7 @@ static void event_editor_init (EventEditor *ee) { CompEditor *editor = COMP_EDITOR (ee); - GtkUIManager *manager; + GtkUIManager *ui_manager; GtkActionGroup *action_group; GtkAction *action; GError *error = NULL; @@ -486,9 +486,9 @@ event_editor_init (EventEditor *ee) action_group, meeting_entries, G_N_ELEMENTS (meeting_entries), ee); - manager = comp_editor_get_ui_manager (editor); - gtk_ui_manager_add_ui_from_string (manager, ui, -1, &error); - e_plugin_ui_register_manager ("event-editor", manager, ee); + ui_manager = comp_editor_get_ui_manager (editor); + gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, &error); + e_plugin_ui_register_manager ("event-editor", ui_manager, ee); if (error != NULL) { g_critical ("%s: %s", G_STRFUNC, error->message); diff --git a/calendar/gui/dialogs/memo-editor.c b/calendar/gui/dialogs/memo-editor.c index 4fbf35d916..b90bd6fb3c 100644 --- a/calendar/gui/dialogs/memo-editor.c +++ b/calendar/gui/dialogs/memo-editor.c @@ -134,15 +134,15 @@ static void memo_editor_init (MemoEditor *me) { CompEditor *editor = COMP_EDITOR (me); - GtkUIManager *manager; + GtkUIManager *ui_manager; GError *error = NULL; me->priv = MEMO_EDITOR_GET_PRIVATE (me); me->priv->updating = FALSE; - manager = comp_editor_get_ui_manager (editor); - gtk_ui_manager_add_ui_from_string (manager, ui, -1, &error); - e_plugin_ui_register_manager ("memo-editor", manager, me); + ui_manager = comp_editor_get_ui_manager (editor); + gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, &error); + e_plugin_ui_register_manager ("memo-editor", ui_manager, me); if (error != NULL) { g_critical ("%s: %s", G_STRFUNC, error->message); diff --git a/calendar/gui/dialogs/task-editor.c b/calendar/gui/dialogs/task-editor.c index 4b8f8698b9..eef1d64468 100644 --- a/calendar/gui/dialogs/task-editor.c +++ b/calendar/gui/dialogs/task-editor.c @@ -302,7 +302,7 @@ static void task_editor_init (TaskEditor *te) { CompEditor *editor = COMP_EDITOR (te); - GtkUIManager *manager; + GtkUIManager *ui_manager; GtkActionGroup *action_group; GError *error = NULL; @@ -344,9 +344,9 @@ task_editor_init (TaskEditor *te) action_group, assigned_task_entries, G_N_ELEMENTS (assigned_task_entries), te); - manager = comp_editor_get_ui_manager (editor); - gtk_ui_manager_add_ui_from_string (manager, ui, -1, &error); - e_plugin_ui_register_manager ("task-editor", manager, te); + ui_manager = comp_editor_get_ui_manager (editor); + gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, &error); + e_plugin_ui_register_manager ("task-editor", ui_manager, te); if (error != NULL) { g_critical ("%s: %s", G_STRFUNC, error->message); -- cgit v1.2.3 From a9e1c0f8e729915f756ee38854e20a8f04f3684b Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 27 Apr 2009 20:56:23 -0400 Subject: Simplify action and action group lookups in CompEditor. --- calendar/gui/dialogs/comp-editor.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) (limited to 'calendar/gui') diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c index 5d842d673a..68b240cc25 100644 --- a/calendar/gui/dialogs/comp-editor.c +++ b/calendar/gui/dialogs/comp-editor.c @@ -1947,46 +1947,28 @@ GtkAction * comp_editor_get_action (CompEditor *editor, const gchar *action_name) { - GtkAction *action = NULL; - GList *iter; + GtkUIManager *ui_manager; g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL); g_return_val_if_fail (action_name != NULL, NULL); - iter = gtk_ui_manager_get_action_groups (editor->priv->ui_manager); - while (iter != NULL && action == NULL) { - GtkActionGroup *action_group = iter->data; - - action = gtk_action_group_get_action ( - action_group, action_name); - iter = g_list_next (iter); - } - g_return_val_if_fail (action != NULL, NULL); + ui_manager = comp_editor_get_ui_manager (editor); - return action; + return e_lookup_action (ui_manager, action_name); } GtkActionGroup * comp_editor_get_action_group (CompEditor *editor, const gchar *group_name) { - GList *iter; + GtkUIManager *ui_manager; g_return_val_if_fail (IS_COMP_EDITOR (editor), NULL); g_return_val_if_fail (group_name != NULL, NULL); - iter = gtk_ui_manager_get_action_groups (editor->priv->ui_manager); - while (iter != NULL) { - GtkActionGroup *action_group = iter->data; - const gchar *name; - - name = gtk_action_group_get_name (action_group); - if (strcmp (name, group_name) == 0) - return action_group; - iter = g_list_next (iter); - } + ui_manager = comp_editor_get_ui_manager (editor); - g_return_val_if_reached (NULL); + return e_lookup_action_group (ui_manager, group_name); } GtkWidget * -- cgit v1.2.3