-/* Copyright (c) 2007, Nokia Corporation
+/* Copyright (c) 2006, 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.
*/
-#define _GNU_SOURCE /* So we can use the getline() function, which is a convenient GNU extension. */
-#include <stdio.h>
-
#include "modest-easysetup-provider-combo-box.h"
#include <gtk/gtkliststore.h>
#include <gtk/gtkcelllayout.h>
#include <stdlib.h>
#include <string.h> /* For memcpy() */
+/* Include config.h so that _() works: */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
G_DEFINE_TYPE (EasysetupProviderComboBox, easysetup_provider_combo_box, GTK_TYPE_COMBO_BOX);
#define PROVIDER_COMBO_BOX_GET_PRIVATE(o) \
return g_object_new (EASYSETUP_TYPE_PROVIDER_COMBO_BOX, NULL);
}
-void easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, ModestPresets *presets, gint country_id)
+void easysetup_provider_combo_box_fill (EasysetupProviderComboBox *combobox, ModestPresets *presets, GSList * list_country_id)
{
+ /* If the list is empty then use mmc=0 to get the providers for all countries: */
+ GSList *list = list_country_id;
+ GSList *fake_list = NULL;
+ if (!list_country_id) {
+ fake_list = g_slist_append(fake_list, GUINT_TO_POINTER(0));
+ list = fake_list;
+ }
+
+
EasysetupProviderComboBoxPrivate *priv = PROVIDER_COMBO_BOX_GET_PRIVATE (combobox);
/* Remove any existing rows: */
GtkListStore *liststore = GTK_LIST_STORE (priv->model);
gtk_list_store_clear (liststore);
- /* Add the appropriate rows for this country, from the presets file: */
- gchar ** provider_ids = NULL;
- gchar ** provider_names = modest_presets_get_providers (presets, country_id,
- TRUE /* include_globals */, &provider_ids);
+ GSList *provider_ids_used_already = NULL;
- gchar ** iter_provider_names = provider_names;
- gchar ** iter_provider_ids = provider_ids;
- while(iter_provider_names && *iter_provider_names && iter_provider_ids && *iter_provider_ids)
- {
- const gchar* provider_name = *iter_provider_names;
- if(!provider_name)
- continue;
+ GSList *iter_ids = list;
+ while (iter_ids) {
+ const guint country_id = GPOINTER_TO_UINT (iter_ids->data);
+
+ /* Add the appropriate rows for this country, from the presets file: */
+ gchar ** provider_ids = NULL;
+ gchar ** provider_names = modest_presets_get_providers (presets, country_id,
+ TRUE /* include_globals */, &provider_ids);
+
+ gchar ** iter_provider_names = provider_names;
+ gchar ** iter_provider_ids = provider_ids;
+ while(iter_provider_names && *iter_provider_names && iter_provider_ids && *iter_provider_ids)
+ {
+ const gchar* provider_name = *iter_provider_names;
+ if(!provider_name)
+ continue;
+
+ const gchar* provider_id = *iter_provider_ids;
+ if(!provider_id)
+ continue;
- const gchar* provider_id = *iter_provider_ids;
- if(!provider_id)
- continue;
+ /* Prevent duplicate providers: */
+ if (g_slist_find_custom (provider_ids_used_already,
+ provider_id, (GCompareFunc)strcmp) == NULL) {
+ /* printf("debug: provider_name=%s\n", provider_name); */
+
+ /* Add the row: */
+ GtkTreeIter iter;
+ gtk_list_store_append (liststore, &iter);
+
+ gtk_list_store_set(liststore, &iter,
+ MODEL_COL_ID, provider_id,
+ MODEL_COL_NAME, provider_name, -1);
+
+ provider_ids_used_already = g_slist_append (
+ provider_ids_used_already, (gpointer)g_strdup (provider_id));
+ }
+
+ ++iter_provider_names;
+ ++iter_provider_ids;
+ }
- /* printf("debug: provider_name=%s\n", provider_name); */
-
- /* Add the row: */
- GtkTreeIter iter;
- gtk_list_store_append (liststore, &iter);
- gtk_list_store_set(liststore, &iter, MODEL_COL_ID, provider_id, MODEL_COL_NAME, provider_name, -1);
+ /* Free the result of modest_presets_get_providers()
+ * as specified by its documentation: */
+ g_strfreev (provider_names);
+ g_strfreev (provider_ids);
- ++iter_provider_names;
- ++iter_provider_ids;
+ iter_ids = g_slist_next (iter_ids);
}
- /* Free the result of modest_presets_get_providers()
- * as specified by its documentation: */
- g_strfreev (provider_names);
- g_strfreev (provider_ids);
-
/* Add the "Other" item: */
/* Note that ID 0 means "Other" for us: */
/* TODO: We need a Logical ID for this text. */
GtkTreeIter iter;
- gtk_list_store_append (liststore, &iter);
- gtk_list_store_set (liststore, &iter, MODEL_COL_ID, 0, MODEL_COL_NAME, _("Other..."), -1);
+ gtk_list_store_prepend (liststore, &iter);
+ gtk_list_store_set (liststore, &iter, MODEL_COL_ID, 0, MODEL_COL_NAME, _("mcen_va_serviceprovider_other"), -1);
/* Select the "Other" item: */
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
+
+ g_slist_foreach (provider_ids_used_already, (GFunc)g_free, NULL);
+ g_slist_free (provider_ids_used_already);
+
+ if (fake_list)
+ g_slist_free (fake_list);
}
/**