From 8e88511ff8e810825a3c79f3f3a3cd0add92e520 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Wed, 1 Oct 2008 07:00:33 +0000 Subject: [PATCH] * Added new ModestSelectorPicker that will replace ModestComboBox in hildon2 UI. * Use selector picker for from field in editor. * Some improvements in country picker, and better usage of HildonPickerButton and HildonTouchSelector APIs. pmo-trunk-r5825 --- src/hildon2/Makefile.am | 3 +- src/hildon2/modest-country-picker.c | 11 +- src/hildon2/modest-easysetup-wizard-dialog.c | 17 +- src/hildon2/modest-msg-edit-window.c | 22 +- src/hildon2/modest-selector-picker.c | 299 ++++++++++++++++++++++++++ src/hildon2/modest-selector-picker.h | 127 +++++++++++ 6 files changed, 461 insertions(+), 18 deletions(-) create mode 100644 src/hildon2/modest-selector-picker.c create mode 100644 src/hildon2/modest-selector-picker.h diff --git a/src/hildon2/Makefile.am b/src/hildon2/Makefile.am index a412ae7..6d7fe13 100644 --- a/src/hildon2/Makefile.am +++ b/src/hildon2/Makefile.am @@ -78,7 +78,8 @@ libmodest_ui_la_SOURCES= \ modest-osso-autosave-callbacks.h \ modest-osso-state-saving.c \ modest-osso-state-saving.h \ - modest-presets.h modest-presets.c + modest-presets.h modest-presets.c \ + modest-selector-picker.h modest-selector-picker.c if MODEST_USE_DUMMY_ADDRESS_BOOK # nothing diff --git a/src/hildon2/modest-country-picker.c b/src/hildon2/modest-country-picker.c index f7ea929..686cb05 100644 --- a/src/hildon2/modest-country-picker.c +++ b/src/hildon2/modest-country-picker.c @@ -290,6 +290,7 @@ modest_country_picker_load_data(ModestCountryPicker *self) /* Set this _after_ loading from file, it makes loading faster */ hildon_touch_selector_set_model (HILDON_TOUCH_SELECTOR (selector), 0, GTK_TREE_MODEL (model)); + g_object_unref (model); } ModestCountryPicker* @@ -332,20 +333,22 @@ gboolean modest_country_picker_set_active_country_locale (ModestCountryPicker *self) { ModestCountryPickerPrivate *priv = MODEST_COUNTRY_PICKER_GET_PRIVATE (self); + GtkWidget *selector; GtkTreeIter iter; gint current_mcc; GtkTreeModel *model; - model = hildon_touch_selector_get_model (hildon_picker_button_get_selector - (HILDON_PICKER_BUTTON (self)), 0); + selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (self))); + model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0); if (!gtk_tree_model_get_iter_first (model, &iter)) return FALSE; do { gtk_tree_model_get (model, &iter, MODEL_COL_MCC, ¤t_mcc, -1); if (priv->locale_mcc == current_mcc) { - hildon_touch_selector_select_iter (hildon_picker_button_get_selector - (HILDON_PICKER_BUTTON (self)), 0, + hildon_touch_selector_select_iter (HILDON_TOUCH_SELECTOR (selector), 0, &iter, TRUE); + hildon_button_set_value (HILDON_BUTTON (self), + hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector))); return TRUE; } } while (gtk_tree_model_iter_next (model, &iter)); diff --git a/src/hildon2/modest-easysetup-wizard-dialog.c b/src/hildon2/modest-easysetup-wizard-dialog.c index a4ae4b7..8ddc972 100644 --- a/src/hildon2/modest-easysetup-wizard-dialog.c +++ b/src/hildon2/modest-easysetup-wizard-dialog.c @@ -334,6 +334,14 @@ on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data) invoke_enable_buttons_vfunc(self); } +static void +on_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data) +{ + ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); + g_assert(self); + invoke_enable_buttons_vfunc(self); +} + /** This is a convenience function to create a caption containing a mandatory widget. * When the widget is edited, the enable_buttons() vfunc will be called. */ @@ -446,6 +454,7 @@ on_entry_max (ModestValidatingEntry *self, gpointer user_data) static GtkWidget* create_page_account_details (ModestEasysetupWizardDialog *self) { + GtkWidget *caption; GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE); GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails")); ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self); @@ -462,11 +471,11 @@ create_page_account_details (ModestEasysetupWizardDialog *self) /* The country widgets: */ priv->account_country_picker = GTK_WIDGET (modest_country_picker_new ()); - GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"), - priv->account_country_picker, NULL, HILDON_CAPTION_OPTIONAL); + hildon_button_set_title (HILDON_BUTTON (priv->account_country_picker), _("mcen_fi_country")); + g_signal_connect (G_OBJECT (priv->account_country_picker), "value-changed", + G_CALLBACK (on_picker_button_value_changed), self); + gtk_box_pack_start (GTK_BOX (box), priv->account_country_picker, FALSE, FALSE, MODEST_MARGIN_HALF); gtk_widget_show (priv->account_country_picker); - gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF); - gtk_widget_show (caption); /* connect to country combo's changed signal, so we can fill the provider combo: */ g_signal_connect (G_OBJECT (hildon_picker_button_get_selector diff --git a/src/hildon2/modest-msg-edit-window.c b/src/hildon2/modest-msg-edit-window.c index 511eb0c..539d64c 100644 --- a/src/hildon2/modest-msg-edit-window.c +++ b/src/hildon2/modest-msg-edit-window.c @@ -43,7 +43,7 @@ #include #include -#include +#include #include #include @@ -723,7 +723,7 @@ connect_signals (ModestMsgEditWindow *obj) static void init_window (ModestMsgEditWindow *obj) { - GtkWidget *from_caption, *to_caption, *subject_caption; + GtkWidget *to_caption, *subject_caption; GtkWidget *main_vbox; ModestMsgEditWindowPrivate *priv; GtkActionGroup *action_group; @@ -794,7 +794,7 @@ init_window (ModestMsgEditWindow *obj) /* Note: This ModestPairList* must exist for as long as the combo * that uses it, because the ModestComboBox uses the ID opaquely, * so it can't know how to manage its memory. */ - priv->from_field = modest_combo_box_new (NULL, g_str_equal); + priv->from_field = modest_selector_picker_new (NULL, g_str_equal); priv->to_field = modest_recpt_editor_new (); priv->cc_field = modest_recpt_editor_new (); @@ -819,7 +819,6 @@ init_window (ModestMsgEditWindow *obj) priv->header_box = gtk_vbox_new (FALSE, 0); - from_caption = hildon_caption_new (size_group, _("mail_va_from"), priv->from_field, NULL, 0); to_caption = hildon_caption_new (size_group, _("mail_va_to"), priv->to_field, NULL, 0); priv->cc_caption = hildon_caption_new (size_group, _("mail_va_cc"), priv->cc_field, NULL, 0); priv->bcc_caption = hildon_caption_new (size_group, _("mail_va_hotfix1"), priv->bcc_field, NULL, 0); @@ -835,7 +834,7 @@ init_window (ModestMsgEditWindow *obj) gtk_size_group_add_widget (size_group, priv->attachments_view); g_object_unref (size_group); - gtk_box_pack_start (GTK_BOX (priv->header_box), from_caption, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (priv->header_box), priv->from_field, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (priv->header_box), to_caption, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (priv->header_box), priv->cc_caption, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (priv->header_box), priv->bcc_caption, FALSE, FALSE, 0); @@ -1492,8 +1491,13 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre parent_priv->menubar = modest_maemo_utils_get_manager_menubar_as_menu (parent_priv->ui_manager, "/MenuBar"); hildon_window_set_menu (HILDON_WINDOW (obj), GTK_MENU (parent_priv->menubar)); priv->from_field_protos = get_transports (); - modest_combo_box_set_pair_list (MODEST_COMBO_BOX (priv->from_field), priv->from_field_protos); - modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->from_field), (gpointer) account_name); + modest_selector_picker_set_pair_list (MODEST_SELECTOR_PICKER (priv->from_field), priv->from_field_protos); + modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), (gpointer) account_name); + hildon_button_set_title (HILDON_BUTTON (priv->from_field), + _("mail_va_from")); + hildon_button_set_value (HILDON_BUTTON (priv->from_field), + hildon_touch_selector_get_current_text + (HILDON_TOUCH_SELECTOR (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->from_field))))); modest_msg_edit_window_setup_toolbar (MODEST_MSG_EDIT_WINDOW (obj)); hildon_window_add_toolbar (HILDON_WINDOW (obj), GTK_TOOLBAR (priv->find_toolbar)); @@ -1608,7 +1612,7 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window) priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (edit_window); - account_name = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->from_field)); + account_name = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); g_return_val_if_fail (account_name, NULL); @@ -3144,7 +3148,7 @@ modest_msg_edit_window_is_modified (ModestMsgEditWindow *editor) return TRUE; if (gtk_text_buffer_get_modified (priv->text_buffer)) return TRUE; - account_name = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->from_field)); + account_name = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); if (!priv->original_account_name || strcmp(account_name, priv->original_account_name)) { return TRUE; } diff --git a/src/hildon2/modest-selector-picker.c b/src/hildon2/modest-selector-picker.c new file mode 100644 index 0000000..5fb4d86 --- /dev/null +++ b/src/hildon2/modest-selector-picker.c @@ -0,0 +1,299 @@ +/* Copyright (c) 2006, 2008 Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include "modest-selector-picker.h" + +/* 'private'/'protected' functions */ +static void modest_selector_picker_class_init (ModestSelectorPickerClass *klass); +static void modest_selector_picker_init (ModestSelectorPicker *obj); +static void modest_selector_picker_finalize (GObject *obj); + +enum { + COLUMN_ID, + COLUMN_DISPLAY_NAME, + COLUMN_NUM +}; + +typedef struct _ModestSelectorPickerPrivate ModestSelectorPickerPrivate; +struct _ModestSelectorPickerPrivate { + GEqualFunc id_equal_func; + +}; +#define MODEST_SELECTOR_PICKER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ + MODEST_TYPE_SELECTOR_PICKER, \ + ModestSelectorPickerPrivate)) +/* globals */ +static GObjectClass *parent_class = NULL; + +GType +modest_selector_picker_get_type (void) +{ + static GType my_type = 0; + if (!my_type) { + static const GTypeInfo my_info = { + sizeof(ModestSelectorPickerClass), + NULL, /* base init */ + NULL, /* base finalize */ + (GClassInitFunc) modest_selector_picker_class_init, + NULL, /* class finalize */ + NULL, /* class data */ + sizeof(ModestSelectorPicker), + 1, /* n_preallocs */ + (GInstanceInitFunc) modest_selector_picker_init, + NULL + }; + my_type = g_type_register_static (HILDON_TYPE_PICKER_BUTTON, + "ModestSelectorPicker", + &my_info, 0); + } + return my_type; +} + +static void +modest_selector_picker_class_init (ModestSelectorPickerClass *klass) +{ + GObjectClass *gobject_class; + gobject_class = (GObjectClass*) klass; + + parent_class = g_type_class_peek_parent (klass); + gobject_class->finalize = modest_selector_picker_finalize; + + g_type_class_add_private (gobject_class, sizeof(ModestSelectorPickerPrivate)); + +} + +static void +modest_selector_picker_init (ModestSelectorPicker *obj) +{ +} + +static void +modest_selector_picker_finalize (GObject *obj) +{ +/* free/unref instance resources here */ + G_OBJECT_CLASS(parent_class)->finalize (obj); +} + +static gchar * +touch_selector_print_func (HildonTouchSelector *selector) +{ + GtkTreeIter iter; + if (hildon_touch_selector_get_selected (HILDON_TOUCH_SELECTOR (selector), 0, &iter)) { + GtkTreeModel *model; + GValue value = {0,}; + + model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0); + gtk_tree_model_get_value (model, &iter, COLUMN_DISPLAY_NAME, &value); + return g_value_dup_string (&value); + } + return NULL; +} + +static GtkTreeModel* +get_model (ModestPairList *pairs) +{ + GtkTreeIter iter; + GtkListStore *store; + GSList *cursor; + + store = gtk_list_store_new (2, + G_TYPE_POINTER, /* the id */ + G_TYPE_STRING); /* the display name */ + cursor = pairs; + while (cursor) { + ModestPair *pair = (ModestPair*)cursor->data; + gtk_list_store_insert_with_values (store, &iter, G_MAXINT, + COLUMN_ID, pair->first, + COLUMN_DISPLAY_NAME, pair->second, + -1); + cursor = cursor->next; + } + + return GTK_TREE_MODEL (store); +} + +static GtkWidget * +create_touch_selector (GtkTreeModel *model) +{ + GtkCellRenderer *renderer; + GtkWidget *selector; + + renderer = gtk_cell_renderer_text_new (); + g_object_set (G_OBJECT (renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); + + selector = hildon_touch_selector_new (); + hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector), GTK_TREE_MODEL (model), + renderer, "text", COLUMN_DISPLAY_NAME, NULL); + + hildon_touch_selector_set_model (HILDON_TOUCH_SELECTOR(selector), 0, model); + hildon_touch_selector_set_print_func (HILDON_TOUCH_SELECTOR (selector), touch_selector_print_func); + + return selector; +} + +void +modest_selector_picker_set_pair_list (ModestSelectorPicker *self, ModestPairList *pairs) +{ + GtkTreeModel *model; + GtkTreeIter iter; + GtkWidget *selector; + + model = get_model (pairs); + + selector = create_touch_selector (model); + gtk_tree_model_get_iter_first (GTK_TREE_MODEL(model), &iter); + hildon_touch_selector_select_iter (HILDON_TOUCH_SELECTOR (selector), 0, &iter, TRUE); + g_object_unref (model); + + hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (self), HILDON_TOUCH_SELECTOR (selector)); +} + + + +GtkWidget* +modest_selector_picker_new (ModestPairList *pairs, GEqualFunc id_equal_func) +{ + GtkTreeModel *model; + GObject *obj; + ModestSelectorPickerPrivate *priv; + GtkTreeIter iter; + + obj = G_OBJECT(g_object_new(MODEST_TYPE_SELECTOR_PICKER, + "size", HILDON_SIZE_AUTO, + "arrangement", HILDON_BUTTON_ARRANGEMENT_VERTICAL, + NULL)); + priv = MODEST_SELECTOR_PICKER_GET_PRIVATE(obj); + + model = get_model (pairs); + if (model) { + GtkWidget *selector; + + selector = create_touch_selector (model); + gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter); + hildon_touch_selector_select_iter (HILDON_TOUCH_SELECTOR (selector), 0, &iter, TRUE); + g_object_unref (model); + + hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (obj), HILDON_TOUCH_SELECTOR (selector)); + } + + if (id_equal_func) + priv->id_equal_func = id_equal_func; + else + priv->id_equal_func = g_direct_equal; /* compare the ptr values */ + + return GTK_WIDGET(obj); +} + + + +static void +get_active (ModestSelectorPicker *self, GValue *val, gint column) +{ + GtkTreeIter iter; + GtkWidget *selector; + g_return_if_fail (self); + + selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (self))); + + if (hildon_touch_selector_get_selected (HILDON_TOUCH_SELECTOR (selector), 0, &iter)) { + GtkTreeModel *model; + + model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0); + gtk_tree_model_get_value (model, &iter, column, val); + } +} + +gpointer +modest_selector_picker_get_active_id (ModestSelectorPicker *self) +{ + GValue val = {0,}; + + g_return_val_if_fail (self, NULL); + + /* Do not unset the GValue */ + get_active (self, &val, COLUMN_ID); + + return g_value_get_pointer (&val); +} + + +void +modest_selector_picker_set_active_id (ModestSelectorPicker *self, gpointer id) +{ + GtkTreeModel *model; + GtkTreeIter iter; + ModestSelectorPickerPrivate *priv; + gboolean found = FALSE; + GtkWidget *selector; + + g_return_if_fail (self); + + priv = MODEST_SELECTOR_PICKER_GET_PRIVATE(self); + selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (self))); + + model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR(selector), 0); + if (!gtk_tree_model_get_iter_first (model, &iter)) + return; /* empty list */ + + do { + gpointer row_id; + gtk_tree_model_get (model, &iter, COLUMN_ID, &row_id, -1); + if ((priv->id_equal_func)(id, row_id)) { + hildon_touch_selector_select_iter (HILDON_TOUCH_SELECTOR (selector), 0, + &iter, TRUE); + + hildon_button_set_value (HILDON_BUTTON (self), + hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector))); + found = TRUE; + } + } while (!found && gtk_tree_model_iter_next (model, &iter)); + + if (!found) + g_printerr ("modest: could not set the active id\n"); +} + + + +const gchar* +modest_selector_picker_get_active_display_name (ModestSelectorPicker *self) +{ + const GValue val = {0,}; + const gchar *retval; + + g_return_val_if_fail (self, NULL); + + /* Do not unset the GValue */ + get_active (self, (GValue *)&val, COLUMN_DISPLAY_NAME); + retval = g_value_get_string (&val); + + return retval; +} diff --git a/src/hildon2/modest-selector-picker.h b/src/hildon2/modest-selector-picker.h new file mode 100644 index 0000000..a353504 --- /dev/null +++ b/src/hildon2/modest-selector-picker.h @@ -0,0 +1,127 @@ +/* Copyright (c) 2006, 2008 Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MODEST_SELECTOR_PICKER_H__ +#define __MODEST_SELECTOR_PICKER_H__ + +#include +#include + +G_BEGIN_DECLS + +/* convenience macros */ +#define MODEST_TYPE_SELECTOR_PICKER (modest_selector_picker_get_type()) +#define MODEST_SELECTOR_PICKER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_SELECTOR_PICKER,ModestSelectorPicker)) +#define MODEST_SELECTOR_PICKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_SELECTOR_PICKER,GObject)) +#define MODEST_IS_SELECTOR_PICKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_SELECTOR_PICKER)) +#define MODEST_IS_SELECTOR_PICKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_SELECTOR_PICKER)) +#define MODEST_SELECTOR_PICKER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_SELECTOR_PICKER,ModestSelectorPickerClass)) + +typedef struct _ModestSelectorPicker ModestSelectorPicker; +typedef struct _ModestSelectorPickerClass ModestSelectorPickerClass; + +struct _ModestSelectorPicker { + HildonPickerButton parent; + /* insert public members, if any */ +}; + +struct _ModestSelectorPickerClass { + HildonPickerButtonClass parent_class; +}; + + +/* member functions */ +GType modest_selector_picker_get_type (void) G_GNUC_CONST; + +/** + * modest_selector_picker_new + * @pairs: a #ModestPairList; each element should be a ptr to a #ModestPair, + * with the first item in the pair being an opaque ID, and the second item being + * a gchar* string for display. + * If the ID is a string or other non fundamental type, you must make sure that + * the instance remains allocated for the lifetime of this combo box. + * The simplest way to achieve this is to ensure that the ModestPairList exists + * for as long as the combo box. + * @cmp_id_func: a GEqualFunc to compare the ids (= the first elements of the pairs) + * For example, if the ids are strings, you can use g_str_equal. + * + * (If you provide NULL for this parameter, the id ptr address will be compared) + * + * create a new modest selector picker. + * + * Returns: a new ModestSelectorPicker instance, or NULL in case of failure + */ +GtkWidget* modest_selector_picker_new (ModestPairList* pairs, + GEqualFunc id_equal_func); + +/** + * modest_selector_picker_set_pair_list: + * @combo: a #ModestSelectorPicker + * @pairs: a #ModestPairList + * + * sets the model of the picker with a new pair list. + */ +void modest_selector_picker_set_pair_list (ModestSelectorPicker *combo, + ModestPairList *pairs); +/** + * modest_selector_picker_get_active_id + * @self: a valid ModestSelectorPicker instance + * + * get the id for the currently active item, or NULL if there's nothing chosen + * (ie., the id is the first element of the pair) + * + * Returns: the id or NULL if there's nothing chosen. + */ +gpointer modest_selector_picker_get_active_id (ModestSelectorPicker *self); + +/** + * modest_selector_picker_set_active_id + * @self: a valid ModestSelectorPicker instance + * @id: the id to make active + * + * set the active item + * + */ +void modest_selector_picker_set_active_id (ModestSelectorPicker *self, gpointer id); + +/** + * modest_selector_picker_get_active_display_name + * @self: a valid ModestSelectorPicker instance + * + * get the display name for the currently active lemma, or NULL if + * there's nothing chosen + * + * Returns: the display name or NULL if there's nothing chosen. + */ +const gchar* modest_selector_picker_get_active_display_name (ModestSelectorPicker *self); + +G_END_DECLS + +#endif /* __MODEST_SELECTOR_PICKER_H__ */ + -- 1.7.9.5