From 6375ba9a6cf327e665d98c5820992ab7fb80a6d0 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 29 Nov 2008 15:26:50 +0000 Subject: Get drag-and-drop-to-source-selector working for contacts, memos and tasks. Utilizes the new ESourceSelector::data-dropped signal. svn path=/branches/kill-bonobo/; revision=36822 --- calendar/gui/e-memos.c | 120 ------------------------------------------------- 1 file changed, 120 deletions(-) (limited to 'calendar/gui/e-memos.c') diff --git a/calendar/gui/e-memos.c b/calendar/gui/e-memos.c index 99e9fb2e18..04efd14dd1 100644 --- a/calendar/gui/e-memos.c +++ b/calendar/gui/e-memos.c @@ -193,126 +193,6 @@ setup_config (EMemos *memos) priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not)); } -struct AffectedComponents { - EMemoTable *memo_table; - GSList *components; /* contains pointers to ECalModelComponent */ -}; - -/** - * get_selected_components_cb - * Helper function to fill list of selected components in EMemoTable. - * 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->memo_table) - return; - - ac->components = g_slist_prepend (ac->components, e_cal_model_get_component_at (E_CAL_MODEL (e_memo_table_get_model (ac->memo_table)), model_row)); -} - -/** - * do_for_selected_components - * Calls function func for all selected components in memo_table. - * - * @param memo_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 - * @param user_data User data, will be passed to func. - **/ -static void -do_for_selected_components (EMemoTable *memo_table, GFunc func, gpointer user_data) -{ - ETable *etable; - struct AffectedComponents ac; - - g_return_if_fail (memo_table != NULL); - - ac.memo_table = memo_table; - ac.components = NULL; - - etable = e_table_scrolled_get_table (E_TABLE_SCROLLED (memo_table->etable)); - e_table_selected_row_foreach (etable, get_selected_components_cb, &ac); - - g_slist_foreach (ac.components, func, user_data); - g_slist_free (ac.components); -} - -/** - * obtain_list_of_components - * As a callback function to convert each ECalModelComponent to string - * of format "source_uid\ncomponent_str" and add this newly allocated - * string to the list of components. Strings should be freed with g_free. - * - * @param data ECalModelComponent object. - * @param user_data Pointer to GSList list, where to put new strings. - **/ -static void -obtain_list_of_components (gpointer data, gpointer user_data) -{ - GSList **list; - ECalModelComponent *comp_data; - - list = (GSList **) user_data; - comp_data = (ECalModelComponent *) data; - - if (list && comp_data) { - char *comp_str; - icalcomponent *vcal; - - vcal = e_cal_util_new_top_level (); - e_cal_util_add_timezones_from_component (vcal, comp_data->icalcomp); - icalcomponent_add_component (vcal, icalcomponent_new_clone (comp_data->icalcomp)); - - comp_str = icalcomponent_as_ical_string (vcal); - if (comp_str) { - ESource *source = e_cal_get_source (comp_data->client); - const char *source_uid = e_source_peek_uid (source); - - *list = g_slist_prepend (*list, g_strdup_printf ("%s\n%s", source_uid, comp_str)); - - /* do not free this pointer, it owns libical */ - /* g_free (comp_str); */ - } - - icalcomponent_free (vcal); - g_free (comp_str); - } -} - -static void -table_drag_data_get (ETable *table, - int row, - int col, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - EMemos *memos) -{ - EMemosPrivate *priv; - - priv = memos->priv; - - if (info == TARGET_VCALENDAR) { - /* we will pass an icalcalendar component for both types */ - GSList *components = NULL; - - do_for_selected_components (E_MEMO_TABLE (priv->memos_view), obtain_list_of_components, &components); - - if (components) { - cal_comp_selection_set_string_list (selection_data, components); - - g_slist_foreach (components, (GFunc)g_free, NULL); - g_slist_free (components); - } - } -} - static void setup_widgets (EMemos *memos) { -- cgit v1.2.3