From 812cb8543a1f9d4e9026cc48a5418d3b2b7093df Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Wed, 22 Oct 2008 10:33:36 +0000 Subject: [PATCH] * Fixes NB#89461, sort dialog is now a HildonPickerDialog with the proper options pmo-trunk-r6141 --- src/hildon2/modest-hildon-sort-dialog.c | 273 +++++++++++++++++++++++++++++-- src/hildon2/modest-hildon-sort-dialog.h | 6 +- 2 files changed, 263 insertions(+), 16 deletions(-) diff --git a/src/hildon2/modest-hildon-sort-dialog.c b/src/hildon2/modest-hildon-sort-dialog.c index b2e56da..6b10294 100644 --- a/src/hildon2/modest-hildon-sort-dialog.c +++ b/src/hildon2/modest-hildon-sort-dialog.c @@ -27,12 +27,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "modest-defs.h" +#include "modest-text-utils.h" #include "modest-hildon-sort-dialog.h" #include "widgets/modest-sort-criterium-view.h" -static gint modest_hildon_sort_dialog_add_sort_key (ModestSortCriteriumView *self, - const gchar *sort_key); +static gint modest_hildon_sort_dialog_add_sort_key (ModestSortCriteriumView *self, const gchar *sort_key); static void modest_hildon_sort_dialog_set_sort_key (ModestSortCriteriumView *self, gint key); static void modest_hildon_sort_dialog_set_sort_order (ModestSortCriteriumView *self, GtkSortType sort_type); static gint modest_hildon_sort_dialog_get_sort_key (ModestSortCriteriumView *self); @@ -41,10 +42,40 @@ static void modest_sort_criterium_view_init (gpointer g_iface, gpointer iface_da G_DEFINE_TYPE_EXTENDED (ModestHildonSortDialog, modest_hildon_sort_dialog, - HILDON_TYPE_SORT_DIALOG, + HILDON_TYPE_PICKER_DIALOG, 0, G_IMPLEMENT_INTERFACE (MODEST_TYPE_SORT_CRITERIUM_VIEW, modest_sort_criterium_view_init)); +typedef struct _ModestHildonSortDialogPrivate ModestHildonSortDialogPrivate; +struct _ModestHildonSortDialogPrivate { + gint id; + GtkSortType sort_type; +}; + +#define MODEST_HILDON_SORT_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ + MODEST_TYPE_HILDON_SORT_DIALOG, \ + ModestHildonSortDialogPrivate)) + +enum { + MODEST_HILDON_SORT_DIALOG_RECIPIENT_AZ, + MODEST_HILDON_SORT_DIALOG_RECIPIENT_ZA, + MODEST_HILDON_SORT_DIALOG_DATE_NEWEST, + MODEST_HILDON_SORT_DIALOG_DATE_OLDEST, + MODEST_HILDON_SORT_DIALOG_SUBJECT_AZ, + MODEST_HILDON_SORT_DIALOG_SUBJECT_ZA, + MODEST_HILDON_SORT_DIALOG_ATTACHMENT, + MODEST_HILDON_SORT_DIALOG_SIZE_LARGEST, + MODEST_HILDON_SORT_DIALOG_SIZE_SMALLEST, + MODEST_HILDON_SORT_DIALOG_PRIORITY, + MODEST_HILDON_SORT_DIALOG_NUM_SORT_CRITERIUM +}; + +enum { + NAME_COLUMN, + ID_COLUMN, + NUM_COLUMS +}; + static void modest_hildon_sort_dialog_finalize (GObject *object) { @@ -58,52 +89,214 @@ modest_hildon_sort_dialog_class_init (ModestHildonSortDialogClass *klass) object_class->finalize = modest_hildon_sort_dialog_finalize; + g_type_class_add_private (object_class, sizeof(ModestHildonSortDialogClass)); } static void modest_hildon_sort_dialog_init (ModestHildonSortDialog *self) { + ModestHildonSortDialogPrivate *priv; + + priv = MODEST_HILDON_SORT_DIALOG_GET_PRIVATE(self); + priv->id = 0; + priv->sort_type = GTK_SORT_ASCENDING; } static gint -modest_hildon_sort_dialog_add_sort_key (ModestSortCriteriumView *self, - const gchar *sort_key) +modest_hildon_sort_dialog_add_sort_key (ModestSortCriteriumView *self, const gchar *sort_key) { - g_return_val_if_fail (MODEST_IS_HILDON_SORT_DIALOG (self), 0); + ModestHildonSortDialogPrivate *priv; + + priv = MODEST_HILDON_SORT_DIALOG_GET_PRIVATE(self); - return hildon_sort_dialog_add_sort_key (HILDON_SORT_DIALOG (self), sort_key); + /* We return a different ID each time, it does not really + matter which one we return, we just want them to be + different */ + return priv->id++; } static void modest_hildon_sort_dialog_set_sort_key (ModestSortCriteriumView *self, gint key) { + HildonTouchSelector *selector; + ModestHildonSortDialogPrivate *priv; + gint active; + g_return_if_fail (MODEST_IS_HILDON_SORT_DIALOG (self)); - hildon_sort_dialog_set_sort_key (HILDON_SORT_DIALOG (self), key); + priv = MODEST_HILDON_SORT_DIALOG_GET_PRIVATE(self); + selector = hildon_picker_dialog_get_selector (HILDON_PICKER_DIALOG (self)); + + /* Map to our selector */ + switch (key) { + case 0: + if (priv->sort_type == GTK_SORT_ASCENDING) + active = MODEST_HILDON_SORT_DIALOG_RECIPIENT_AZ; + else + active = MODEST_HILDON_SORT_DIALOG_RECIPIENT_ZA; + break; + case 1: + if (priv->sort_type == GTK_SORT_ASCENDING) + active = MODEST_HILDON_SORT_DIALOG_DATE_OLDEST; + else + active = MODEST_HILDON_SORT_DIALOG_DATE_NEWEST; + break; + case 2: + if (priv->sort_type == GTK_SORT_ASCENDING) + active = MODEST_HILDON_SORT_DIALOG_SUBJECT_AZ; + else + active = MODEST_HILDON_SORT_DIALOG_SUBJECT_ZA; + break; + case 3: + active = MODEST_HILDON_SORT_DIALOG_ATTACHMENT; + break; + case 4: + if (priv->sort_type == GTK_SORT_ASCENDING) + active = MODEST_HILDON_SORT_DIALOG_SIZE_SMALLEST; + else + active = MODEST_HILDON_SORT_DIALOG_SIZE_LARGEST; + break; + case 5: + active = MODEST_HILDON_SORT_DIALOG_PRIORITY; + break; + default: + g_warning ("%s, no valid key found... falling back to default (0)", __FUNCTION__); + active = 0; + } + hildon_touch_selector_set_active (selector, 0, active); } static void -modest_hildon_sort_dialog_set_sort_order (ModestSortCriteriumView *self, GtkSortType sort_type) +modest_hildon_sort_dialog_set_sort_order (ModestSortCriteriumView *self, + GtkSortType sort_type) { + HildonTouchSelector *selector; + gint active, new; + ModestHildonSortDialogPrivate *priv; + g_return_if_fail (MODEST_IS_HILDON_SORT_DIALOG (self)); - hildon_sort_dialog_set_sort_order (HILDON_SORT_DIALOG (self), sort_type); + priv = MODEST_HILDON_SORT_DIALOG_GET_PRIVATE(self); + selector = hildon_picker_dialog_get_selector (HILDON_PICKER_DIALOG (self)); + active = hildon_touch_selector_get_active (selector, 0); + + /* Map to our selector, we need to check the current selected + key because this way we allow to select the order first and + then the key */ + switch (active) { + case MODEST_HILDON_SORT_DIALOG_RECIPIENT_AZ: + case MODEST_HILDON_SORT_DIALOG_RECIPIENT_ZA: + if (sort_type == GTK_SORT_ASCENDING) + new = MODEST_HILDON_SORT_DIALOG_RECIPIENT_ZA; + else + new = MODEST_HILDON_SORT_DIALOG_RECIPIENT_AZ; + break; + case MODEST_HILDON_SORT_DIALOG_DATE_NEWEST: + case MODEST_HILDON_SORT_DIALOG_DATE_OLDEST: + if (sort_type == GTK_SORT_ASCENDING) + new = MODEST_HILDON_SORT_DIALOG_DATE_NEWEST; + else + new = MODEST_HILDON_SORT_DIALOG_DATE_OLDEST; + break; + case MODEST_HILDON_SORT_DIALOG_SUBJECT_AZ: + case MODEST_HILDON_SORT_DIALOG_SUBJECT_ZA: + if (sort_type == GTK_SORT_ASCENDING) + new = MODEST_HILDON_SORT_DIALOG_SUBJECT_ZA; + else + new = MODEST_HILDON_SORT_DIALOG_SUBJECT_AZ; + break; + case MODEST_HILDON_SORT_DIALOG_ATTACHMENT: + new = MODEST_HILDON_SORT_DIALOG_ATTACHMENT; + break; + case MODEST_HILDON_SORT_DIALOG_SIZE_LARGEST: + case MODEST_HILDON_SORT_DIALOG_SIZE_SMALLEST: + if (sort_type == GTK_SORT_ASCENDING) + new = MODEST_HILDON_SORT_DIALOG_SIZE_SMALLEST; + else + new = MODEST_HILDON_SORT_DIALOG_SIZE_LARGEST; + break; + case MODEST_HILDON_SORT_DIALOG_PRIORITY: + new = MODEST_HILDON_SORT_DIALOG_PRIORITY; + break; + default: + g_warning ("%s, no valid key found... falling back to current (%d)", __FUNCTION__, active); + new = active; + } + + /* Activate the proper index */ + hildon_touch_selector_set_active (selector, 0, new); + priv->sort_type = sort_type; } static gint modest_hildon_sort_dialog_get_sort_key (ModestSortCriteriumView *self) { + HildonTouchSelector *selector; + gint active; + g_return_val_if_fail (MODEST_IS_HILDON_SORT_DIALOG (self), 0); - return hildon_sort_dialog_get_sort_key (HILDON_SORT_DIALOG (self)); + selector = hildon_picker_dialog_get_selector (HILDON_PICKER_DIALOG (self)); + active = hildon_touch_selector_get_active (selector, 0); + + switch (active) { + case MODEST_HILDON_SORT_DIALOG_RECIPIENT_AZ: + case MODEST_HILDON_SORT_DIALOG_RECIPIENT_ZA: + return 0; + case MODEST_HILDON_SORT_DIALOG_DATE_NEWEST: + case MODEST_HILDON_SORT_DIALOG_DATE_OLDEST: + return 1; + case MODEST_HILDON_SORT_DIALOG_SUBJECT_AZ: + case MODEST_HILDON_SORT_DIALOG_SUBJECT_ZA: + return 2; + case MODEST_HILDON_SORT_DIALOG_ATTACHMENT: + return 3; + case MODEST_HILDON_SORT_DIALOG_SIZE_LARGEST: + case MODEST_HILDON_SORT_DIALOG_SIZE_SMALLEST: + return 4; + case MODEST_HILDON_SORT_DIALOG_PRIORITY: + return 5; + default: + /* Default is order by ascending date */ + g_return_val_if_reached (1); + return 1; + } } static GtkSortType modest_hildon_sort_dialog_get_sort_order (ModestSortCriteriumView *self) { + HildonTouchSelector *selector; + GtkTreeModel *model; + GtkTreeIter iter; + gint id; + g_return_val_if_fail (MODEST_IS_HILDON_SORT_DIALOG (self), GTK_SORT_ASCENDING); - return hildon_sort_dialog_get_sort_order (HILDON_SORT_DIALOG (self)); + selector = hildon_picker_dialog_get_selector (HILDON_PICKER_DIALOG (self)); + hildon_touch_selector_get_selected (selector, 0, &iter); + + model = hildon_touch_selector_get_model (selector, 0); + gtk_tree_model_get (model, &iter, ID_COLUMN, &id, -1); + + switch (id) { + case MODEST_HILDON_SORT_DIALOG_RECIPIENT_AZ: + case MODEST_HILDON_SORT_DIALOG_SUBJECT_AZ: + case MODEST_HILDON_SORT_DIALOG_DATE_OLDEST: + case MODEST_HILDON_SORT_DIALOG_SIZE_SMALLEST: + return GTK_SORT_ASCENDING; + case MODEST_HILDON_SORT_DIALOG_RECIPIENT_ZA: + case MODEST_HILDON_SORT_DIALOG_DATE_NEWEST: + case MODEST_HILDON_SORT_DIALOG_SUBJECT_ZA: + case MODEST_HILDON_SORT_DIALOG_SIZE_LARGEST: + case MODEST_HILDON_SORT_DIALOG_ATTACHMENT: + case MODEST_HILDON_SORT_DIALOG_PRIORITY: + return GTK_SORT_DESCENDING; + default: + /* Default is order by ascending date */ + g_return_val_if_reached (GTK_SORT_ASCENDING); + return GTK_SORT_ASCENDING; + } } static void @@ -119,15 +312,69 @@ modest_sort_criterium_view_init (gpointer g_iface, iface->set_sort_order_func = modest_hildon_sort_dialog_set_sort_order; } +static void +modest_hildon_sort_dialog_fill (ModestHildonSortDialog *self) +{ + GtkListStore *names_list; + GtkWidget *selector; + GtkTreeIter iter; + HildonTouchSelectorColumn *column; + + /* Fill in model */ + names_list = gtk_list_store_new (NUM_COLUMS, G_TYPE_STRING, G_TYPE_INT); + gtk_list_store_append (names_list, &iter); + gtk_list_store_set (names_list, &iter, NAME_COLUMN, _("mcen_li_sort_sender_recipient_az"), + ID_COLUMN, MODEST_HILDON_SORT_DIALOG_RECIPIENT_AZ, -1); + gtk_list_store_append (names_list, &iter); + gtk_list_store_set (names_list, &iter, NAME_COLUMN, _("mcen_li_sort_sender_recipient_za"), + ID_COLUMN, MODEST_HILDON_SORT_DIALOG_RECIPIENT_ZA, -1); + gtk_list_store_append (names_list, &iter); + gtk_list_store_set (names_list, &iter, NAME_COLUMN, _("mcen_li_sort_date_newest"), + ID_COLUMN, MODEST_HILDON_SORT_DIALOG_DATE_NEWEST, -1); + gtk_list_store_append (names_list, &iter); + gtk_list_store_set (names_list, &iter, NAME_COLUMN, _("mcen_li_sort_date_oldest"), + ID_COLUMN, MODEST_HILDON_SORT_DIALOG_DATE_OLDEST, -1); + gtk_list_store_append (names_list, &iter); + gtk_list_store_set (names_list, &iter, NAME_COLUMN, _("mcen_li_sort_subject_az"), + ID_COLUMN, MODEST_HILDON_SORT_DIALOG_SUBJECT_AZ, -1); + gtk_list_store_append (names_list, &iter); + gtk_list_store_set (names_list, &iter, NAME_COLUMN, _("mcen_li_sort_subject_za"), + ID_COLUMN, MODEST_HILDON_SORT_DIALOG_SUBJECT_ZA, -1); + gtk_list_store_append (names_list, &iter); + gtk_list_store_set (names_list, &iter, NAME_COLUMN, _("mcen_li_sort_attachment"), + ID_COLUMN, MODEST_HILDON_SORT_DIALOG_ATTACHMENT, -1); + gtk_list_store_append (names_list, &iter); + gtk_list_store_set (names_list, &iter, NAME_COLUMN, _("mcen_li_sort_size_largest"), + ID_COLUMN, MODEST_HILDON_SORT_DIALOG_SIZE_LARGEST, -1); + gtk_list_store_append (names_list, &iter); + gtk_list_store_set (names_list, &iter, NAME_COLUMN, _("mcen_li_sort_size_smallest"), + ID_COLUMN, MODEST_HILDON_SORT_DIALOG_SIZE_SMALLEST, -1); + gtk_list_store_append (names_list, &iter); + gtk_list_store_set (names_list, &iter, NAME_COLUMN, _("mcen_li_sort_priority"), + ID_COLUMN, MODEST_HILDON_SORT_DIALOG_PRIORITY, -1); + + /* Add columns */ + selector = hildon_touch_selector_new (); + column = hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector), + GTK_TREE_MODEL (names_list), TRUE); + g_object_set (G_OBJECT (column), "text-column", NAME_COLUMN, NULL); + + /* Set the selector */ + hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (self), HILDON_TOUCH_SELECTOR (selector)); +} + GtkWidget* modest_hildon_sort_dialog_new (GtkWindow *parent) { GtkWidget *result = g_object_new (MODEST_TYPE_HILDON_SORT_DIALOG, NULL); + modest_hildon_sort_dialog_fill (MODEST_HILDON_SORT_DIALOG (result)); if (parent) gtk_window_set_transient_for(GTK_WINDOW(result), parent); + /* Set title */ + gtk_window_set_title (GTK_WINDOW (result), _CS("ckdg_ti_sort")); + return result; } - diff --git a/src/hildon2/modest-hildon-sort-dialog.h b/src/hildon2/modest-hildon-sort-dialog.h index 8fd7227..ee3e2ea 100644 --- a/src/hildon2/modest-hildon-sort-dialog.h +++ b/src/hildon2/modest-hildon-sort-dialog.h @@ -31,7 +31,7 @@ #define __MODEST_HILDON_SORT_DIALOG #include -#include +#include #include G_BEGIN_DECLS @@ -59,12 +59,12 @@ G_BEGIN_DECLS MODEST_TYPE_HILDON_SORT_DIALOG, ModestHildonSortDialogClass)) typedef struct { - HildonSortDialog parent; + HildonPickerDialog parent; } ModestHildonSortDialog; typedef struct { - HildonSortDialogClass parent_class; + HildonPickerDialogClass parent_class; } ModestHildonSortDialogClass; -- 1.7.9.5