G_DEFINE_TYPE (EasysetupCountryComboBox, easysetup_country_combo_box, GTK_TYPE_COMBO_BOX);
-#define COUNTRY_COMBO_BOX_GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), EASYSETUP_TYPE_COUNTRY_COMBO_BOX, EasysetupCountryComboBoxPrivate))
-
-typedef struct _EasysetupCountryComboBoxPrivate EasysetupCountryComboBoxPrivate;
-
-struct _EasysetupCountryComboBoxPrivate
+typedef struct
{
GtkTreeModel *model;
-};
+} ModestEasysetupCountryComboBoxPrivate;
+
+#define MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+ MODEST_EASYSETUP_TYPE_COUNTRY_COMBO_BOX, \
+ ModestEasysetupCountryComboBoxPrivate))
static void
easysetup_country_combo_box_get_property (GObject *object, guint property_id,
static void
easysetup_country_combo_box_finalize (GObject *object)
{
- EasysetupCountryComboBoxPrivate *priv = COUNTRY_COMBO_BOX_GET_PRIVATE (object);
+ ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (object);
g_object_unref (G_OBJECT (priv->model));
G_OBJECT_CLASS (easysetup_country_combo_box_parent_class)->finalize (object);
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- g_type_class_add_private (klass, sizeof (EasysetupCountryComboBoxPrivate));
+ g_type_class_add_private (klass, sizeof (ModestEasysetupCountryComboBoxPrivate));
object_class->get_property = easysetup_country_combo_box_get_property;
object_class->set_property = easysetup_country_combo_box_set_property;
parse_mcc_mapping_line (const char* line, char** country)
{
int i, j;
- static char* mcc="123"; /* the mcc code, always 3 bytes*/
+ char mcc[4]; /* the mcc code, always 3 bytes*/
static char my_country[128];
if (!line) {
mcc[0] = line[0];
mcc[1] = line[1];
mcc[2] = line[2];
+ mcc[3] = '\0';
*country = my_country;
- return effective_mcc (atoi(mcc));
+
+ return effective_mcc ((int) strtol ((const char*)mcc, NULL, 10));
}
/** Note that the mcc_mapping file is installed
static void
load_from_file (EasysetupCountryComboBox *self)
{
- EasysetupCountryComboBoxPrivate *priv = COUNTRY_COMBO_BOX_GET_PRIVATE (self);
+ ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (self);
GtkListStore *liststore = GTK_LIST_STORE (priv->model);
char line[MAX_LINE_LEN];
return;
}
- while (fgets (line, MAX_LINE_LEN, file) > 0) {
+ while (fgets (line, MAX_LINE_LEN, file) != NULL) {
int mcc;
char *country = NULL;
static void
easysetup_country_combo_box_init (EasysetupCountryComboBox *self)
{
- EasysetupCountryComboBoxPrivate *priv = COUNTRY_COMBO_BOX_GET_PRIVATE (self);
+ ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (self);
+ priv->model = NULL;
+}
+
+void
+easysetup_country_combo_box_load_data(EasysetupCountryComboBox *self)
+{
+ ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (self);
/* Create a tree model for the combo box,
* with a string for the name, and an int for the MCC ID.
/* Setup the combo box: */
GtkComboBox *combobox = GTK_COMBO_BOX (self);
- gtk_combo_box_set_model (combobox, priv->model);
/* Country column:
* The ID model column in not shown in the view. */
/* Fill the model with rows: */
load_from_file (self);
+ /* Set this _after_ loading from file, it makes loading faster */
+ gtk_combo_box_set_model (combobox, priv->model);
}
EasysetupCountryComboBox*
easysetup_country_combo_box_new (void)
{
- return g_object_new (EASYSETUP_TYPE_COUNTRY_COMBO_BOX, NULL);
+ return g_object_new (MODEST_EASYSETUP_TYPE_COUNTRY_COMBO_BOX, NULL);
}
/**
GtkTreeIter active;
const gboolean found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &active);
if (found) {
- EasysetupCountryComboBoxPrivate *priv = COUNTRY_COMBO_BOX_GET_PRIVATE (self);
+ ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (self);
gint mcc = 0;
gtk_tree_model_get (priv->model, &active, MODEL_COL_MCC, &mcc, -1);
return mcc;
gboolean
easysetup_country_combo_box_set_active_country_mcc (EasysetupCountryComboBox *self, guint mcc)
{
- EasysetupCountryComboBoxPrivate *priv = COUNTRY_COMBO_BOX_GET_PRIVATE (self);
+ ModestEasysetupCountryComboBoxPrivate *priv = MODEST_EASYSETUP_COUNTRY_COMBO_BOX_GET_PRIVATE (self);
GtkTreeIter iter;
if (!gtk_tree_model_get_iter_first (priv->model, &iter))