diff options
author | Milan Crha <mcrha@src.gnome.org> | 2007-09-27 16:04:06 +0800 |
---|---|---|
committer | Milan Crha <mcrha@src.gnome.org> | 2007-09-27 16:04:06 +0800 |
commit | fec468e9409d12dc2b37546d646908209da42fdd (patch) | |
tree | ee616ffb6ce2cdf77e2b3659c6f4b87d35a61344 /calendar/gui | |
parent | 2805d6a9fc030eefb5bfc6db91b7552b73090e65 (diff) | |
download | gsoc2013-evolution-fec468e9409d12dc2b37546d646908209da42fdd.tar gsoc2013-evolution-fec468e9409d12dc2b37546d646908209da42fdd.tar.gz gsoc2013-evolution-fec468e9409d12dc2b37546d646908209da42fdd.tar.bz2 gsoc2013-evolution-fec468e9409d12dc2b37546d646908209da42fdd.tar.lz gsoc2013-evolution-fec468e9409d12dc2b37546d646908209da42fdd.tar.xz gsoc2013-evolution-fec468e9409d12dc2b37546d646908209da42fdd.tar.zst gsoc2013-evolution-fec468e9409d12dc2b37546d646908209da42fdd.zip |
2007-09-27 mcrha Fix for bug #324472
svn path=/trunk/; revision=34313
Diffstat (limited to 'calendar/gui')
-rw-r--r-- | calendar/gui/e-cal-model-tasks.c | 113 | ||||
-rw-r--r-- | calendar/gui/e-cal-model-tasks.h | 4 | ||||
-rw-r--r-- | calendar/gui/e-calendar-table.c | 95 |
3 files changed, 138 insertions, 74 deletions
diff --git a/calendar/gui/e-cal-model-tasks.c b/calendar/gui/e-cal-model-tasks.c index 2b386daa87..9afd09fe5c 100644 --- a/calendar/gui/e-cal-model-tasks.c +++ b/calendar/gui/e-cal-model-tasks.c @@ -51,6 +51,7 @@ static char *ecmt_value_to_string (ETableModel *etm, int col, const void *value) static const char *ecmt_get_color_for_component (ECalModel *model, ECalModelComponent *comp_data); static void ecmt_fill_component_from_model (ECalModel *model, ECalModelComponent *comp_data, ETableModel *source_model, gint row); +static void commit_component_changes (ECalModelComponent *comp_data); G_DEFINE_TYPE (ECalModelTasks, e_cal_model_tasks, E_TYPE_CAL_MODEL) @@ -829,12 +830,7 @@ ecmt_set_value_at (ETableModel *etm, int col, int row, const void *value) break; } - /* FIXME ask about mod type */ - if (!e_cal_modify_object (comp_data->client, comp_data->icalcomp, CALOBJ_MOD_ALL, NULL)) { - g_warning (G_STRLOC ": Could not modify the object!"); - - /* FIXME Show error dialog */ - } + commit_component_changes (comp_data); } static gboolean @@ -1098,69 +1094,88 @@ e_cal_model_tasks_new (void) } /** - * e_cal_model_tasks_mark_task_complete - */ -void -e_cal_model_tasks_mark_task_complete (ECalModelTasks *model, gint model_row) + * e_cal_model_tasks_mark_comp_complete + * Marks component as complete and commits changes to the calendar backend. + * + * @param model Currently not used... + * @param comp_data Component of our interest + **/ +void e_cal_model_tasks_mark_comp_complete (ECalModelTasks *model, ECalModelComponent *comp_data) { - ECalModelComponent *comp_data; - - g_return_if_fail (E_IS_CAL_MODEL_TASKS (model)); - g_return_if_fail (model_row >= 0 && model_row < e_table_model_row_count (E_TABLE_MODEL (model))); + g_return_if_fail (model != NULL); + g_return_if_fail (comp_data != NULL); - comp_data = e_cal_model_get_component_at (E_CAL_MODEL (model), model_row); - if (comp_data) { - e_table_model_pre_change (E_TABLE_MODEL (model)); + /* we will receive changes when committed, so don't do this */ + /*e_table_model_pre_change (E_TABLE_MODEL (model));*/ - ensure_task_complete (comp_data, -1); + ensure_task_complete (comp_data, -1); - e_table_model_row_changed (E_TABLE_MODEL (model), model_row); - } + /*e_table_model_row_changed (E_TABLE_MODEL (model), model_row);*/ + + commit_component_changes (comp_data); } /** - * e_cal_model_tasks_mark_task_incomplete - */ -void -e_cal_model_tasks_mark_task_incomplete (ECalModelTasks *model, gint model_row) + * e_cal_model_tasks_mark_comp_incomplete + * Marks component as incomplete and commits changes to the calendar backend. + * + * @param model Currently not used... + * @param comp_data Component of our interest + **/ +void e_cal_model_tasks_mark_comp_incomplete (ECalModelTasks *model, ECalModelComponent *comp_data) { - ECalModelComponent *comp_data; icalproperty *prop,*prop1; - g_return_if_fail (E_IS_CAL_MODEL_TASKS (model)); - g_return_if_fail (model_row >= 0 && model_row < e_table_model_row_count (E_TABLE_MODEL (model))); + g_return_if_fail (model != NULL); + g_return_if_fail (comp_data != NULL); + + /* we will receive changes when committed, so don't do this */ + /*e_table_model_pre_change (E_TABLE_MODEL (model));*/ - comp_data = e_cal_model_get_component_at (E_CAL_MODEL (model), model_row); - if (comp_data) - { - e_table_model_pre_change (E_TABLE_MODEL (model)); - /* Status */ - prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_STATUS_PROPERTY); - if (prop) + /* Status */ + prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_STATUS_PROPERTY); + if (prop) icalproperty_set_status (prop, ICAL_STATUS_NEEDSACTION); - else + else icalcomponent_add_property (comp_data->icalcomp, icalproperty_new_status (ICAL_STATUS_NEEDSACTION)); - - /*complete property*/ - prop1= icalcomponent_get_first_property (comp_data->icalcomp, ICAL_COMPLETED_PROPERTY); - if (prop1) - { + + /*complete property*/ + prop1 = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_COMPLETED_PROPERTY); + if (prop1) { icalcomponent_remove_property (comp_data->icalcomp, prop1); icalproperty_free (prop1); - } - - /* Percent. */ - prop1 = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_PERCENTCOMPLETE_PROPERTY); - if (prop1) - { + } + + /* Percent. */ + prop1 = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_PERCENTCOMPLETE_PROPERTY); + if (prop1) { icalcomponent_remove_property (comp_data->icalcomp, prop1); icalproperty_free (prop1); - } - - e_table_model_row_changed (E_TABLE_MODEL (model), model_row); } + + /*e_table_model_row_changed (E_TABLE_MODEL (model), model_row);*/ + + commit_component_changes (comp_data); } +/** + * commit_component_changes + * Commits changes to the backend calendar of the component. + * + * @param comp_data Component of our interest, which has been changed. + **/ +static void +commit_component_changes (ECalModelComponent *comp_data) +{ + g_return_if_fail (comp_data != NULL); + + /* FIXME ask about mod type */ + if (!e_cal_modify_object (comp_data->client, comp_data->icalcomp, CALOBJ_MOD_ALL, NULL)) { + g_warning (G_STRLOC ": Could not modify the object!"); + + /* FIXME Show error dialog */ + } +} /** * e_cal_model_tasks_update_due_tasks diff --git a/calendar/gui/e-cal-model-tasks.h b/calendar/gui/e-cal-model-tasks.h index b57c967115..2de52d541d 100644 --- a/calendar/gui/e-cal-model-tasks.h +++ b/calendar/gui/e-cal-model-tasks.h @@ -61,8 +61,8 @@ typedef struct { GType e_cal_model_tasks_get_type (void); ECalModelTasks *e_cal_model_tasks_new (void); -void e_cal_model_tasks_mark_task_complete (ECalModelTasks *model, gint model_row); -void e_cal_model_tasks_mark_task_incomplete (ECalModelTasks *model, gint model_row); +void e_cal_model_tasks_mark_comp_complete (ECalModelTasks *model, ECalModelComponent *comp_data); +void e_cal_model_tasks_mark_comp_incomplete (ECalModelTasks *model, ECalModelComponent *comp_data); void e_cal_model_tasks_update_due_tasks (ECalModelTasks *model); G_END_DECLS diff --git a/calendar/gui/e-calendar-table.c b/calendar/gui/e-calendar-table.c index 633f7e2290..90dff52288 100644 --- a/calendar/gui/e-calendar-table.c +++ b/calendar/gui/e-calendar-table.c @@ -104,7 +104,7 @@ static gint e_calendar_table_on_key_press (ETable *table, static struct tm e_calendar_table_get_current_time (ECellDateEdit *ecde, gpointer data); -static void mark_row_complete_cb (int model_row, gpointer data); +static void mark_as_complete_cb (EPopup *ep, EPopupItem *pitem, void *data); static void hide_completed_rows (ECalModel *model, GList *clients_list, char *hide_sexp, GPtrArray *comp_objects); static void show_completed_rows (ECalModel *model, GList *clients_list, char *show_sexp, GPtrArray *comp_objects); @@ -548,13 +548,10 @@ e_calendar_table_open_selected (ECalendarTable *cal_table) void e_calendar_table_complete_selected (ECalendarTable *cal_table) { - ETable *etable; - g_return_if_fail (cal_table != NULL); g_return_if_fail (E_IS_CALENDAR_TABLE (cal_table)); - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); - e_table_selected_row_foreach (etable, mark_row_complete_cb, cal_table); + mark_as_complete_cb (NULL, NULL, cal_table); } /* Used from e_table_selected_row_foreach(); puts the selected row number in an @@ -1183,46 +1180,98 @@ e_calendar_table_on_forward (EPopup *ep, EPopupItem *pitem, void *data) } } -/* Used from e_table_selected_row_foreach() */ +struct AffectedComponents { + ECalendarTable *cal_table; + GSList *components; /* contains pointers to ECalModelComponent */ +}; + +/** + * get_selected_components_cb + * Helper function to fill list of selected components in ECalendarTable. + * This function is called from e_table_selected_row_foreach. + **/ +static void +get_selected_components_cb (int model_row, gpointer data) +{ + struct AffectedComponents *ac = (struct AffectedComponents *) data; + + if (!ac || !ac->cal_table) + return; + + ac->components = g_slist_prepend (ac->components, e_cal_model_get_component_at (E_CAL_MODEL (ac->cal_table->model), model_row)); +} + +/** + * do_for_selected_components + * Calls function func for all selected components in cal_table. + * + * @param cal_table Table with selected components of our interest + * @param func Function to be called on each selected component from cal_table. + * The first parameter of this function is a pointer to ECalModelComponent and + * the second parameter of this function is pointer to cal_table + **/ static void -mark_row_complete_cb (int model_row, gpointer data) +do_for_selected_components (ECalendarTable *cal_table, GFunc func) +{ + ETable *etable; + struct AffectedComponents ac; + + g_return_if_fail (cal_table != NULL); + + ac.cal_table = cal_table; + ac.components = NULL; + + etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); + e_table_selected_row_foreach (etable, get_selected_components_cb, &ac); + + g_slist_foreach (ac.components, func, cal_table); + g_slist_free (ac.components); +} + +/** + * mark_comp_complete_cb + * Function used in call to @ref do_for_selected_components to mark each component as complete + **/ +static void +mark_comp_complete_cb (gpointer data, gpointer user_data) { ECalendarTable *cal_table; + ECalModelComponent *comp_data; - cal_table = E_CALENDAR_TABLE (data); - e_cal_model_tasks_mark_task_complete (E_CAL_MODEL_TASKS (cal_table->model), model_row); + comp_data = (ECalModelComponent *) data; + cal_table = E_CALENDAR_TABLE (user_data); + + e_cal_model_tasks_mark_comp_complete (E_CAL_MODEL_TASKS (cal_table->model), comp_data); } -/* Used from e_table_selected_row_foreach() */ +/** + * mark_comp_incomplete_cb + * Function used in call to @ref do_for_selected_components to mark each component as incomplete + **/ static void -mark_row_incomplete_cb (int model_row, gpointer data) +mark_comp_incomplete_cb (gpointer data, gpointer user_data) { ECalendarTable *cal_table; + ECalModelComponent *comp_data; - cal_table = E_CALENDAR_TABLE (data); - e_cal_model_tasks_mark_task_incomplete (E_CAL_MODEL_TASKS (cal_table->model), model_row); + comp_data = (ECalModelComponent *) data; + cal_table = E_CALENDAR_TABLE (user_data); + + e_cal_model_tasks_mark_comp_incomplete (E_CAL_MODEL_TASKS (cal_table->model), comp_data); } /* Callback used for the "mark tasks as incomplete" menu item */ static void mark_as_incomplete_cb (EPopup *ep, EPopupItem *pitem, void *data) { - ECalendarTable *cal_table = data; - ETable *etable; - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); - e_table_selected_row_foreach (etable, mark_row_incomplete_cb, cal_table); + do_for_selected_components (data, mark_comp_incomplete_cb); } /* Callback used for the "mark tasks as complete" menu item */ static void mark_as_complete_cb (EPopup *ep, EPopupItem *pitem, void *data) { - ECalendarTable *cal_table = data; - ETable *etable; - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (cal_table->etable)); - e_table_selected_row_foreach (etable, mark_row_complete_cb, cal_table); + do_for_selected_components (data, mark_comp_complete_cb); } /* Opens the URL of the task */ |