* check for the required provider data at startup time; cleanup code a bit
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 20 Sep 2007 13:23:11 +0000 (13:23 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 20 Sep 2007 13:23:11 +0000 (13:23 +0000)
pmo-trunk-r3370

src/maemo/easysetup/modest-easysetup-country-combo-box.c
src/maemo/modest-maemo-utils.c
src/maemo/modest-maemo-utils.h
src/maemo/modest-platform.c

index 9c37ebf..a3213a9 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <stdio.h>
 
+#include "../modest-maemo-utils.h"
 #include "modest-easysetup-country-combo-box.h"
 #include <gtk/gtkliststore.h>
 #include <gtk/gtkcelllayout.h>
@@ -176,7 +177,6 @@ parse_mcc_mapping_line (const char* line,  char** country)
                        else  /* error */
                                return 0;
                } else {
-                       printf ("%c", kar);
                        my_country [j++] = kar;
                }
        }
@@ -202,22 +202,8 @@ load_from_file (EasysetupCountryComboBox *self)
        
        char line[MAX_LINE_LEN];
        guint previous_mcc = 0;
-               
-       /* Load the file one line at a time: */
-#ifdef MODEST_HILDON_VERSION_0
-       const gchar* filepath = PROVIDER_DATA_DIR "/mcc_mapping";
-#else
-       /* This is the official version, in the 'operator-wizard-settings' package */
-       const gchar* filepath = "/usr/share/operator-wizard/mcc_mapping";
-#endif /*MODEST_HILDON_VERSION_0*/
-       /* printf ("DEBUG: %s: filepath=%s\n", __FUNCTION__, filepath); */
-       FILE *file = fopen(filepath, "r");
-       if (!file) {
-               const gchar* filepath_hack = HACK_TOP_SRCDIR "src/maemo/easysetup/mcc_mapping";
-               g_warning ("Could not locate the official mcc_mapping countries list file from %s, "
-                       "so attempting to load it instead from %s", filepath, filepath_hack);
-               file = fopen(filepath_hack, "r");
-       }
+       
+       FILE *file = modest_maemo_open_mcc_mapping_file ();
        if (!file) {
                g_warning("Could not open mcc_mapping file");
                return;
index 2c38a9e..1344f13 100644 (file)
@@ -655,3 +655,26 @@ modest_maemo_toggle_action_set_active_block_notify (GtkToggleAction *action, gbo
        }
 
 }
+
+
+
+FILE*
+modest_maemo_open_mcc_mapping_file (void)
+{
+       FILE* result;
+       
+       /* Load the file one line at a time: */
+#ifdef MODEST_HILDON_VERSION_0
+       const gchar* filepath = PROVIDER_DATA_DIR "/mcc_mapping";
+#else
+       const gchar* filepath = "/usr/share/operator-wizard/mcc_mapping";
+#endif /*MODEST_HILDON_VERSION_0*/
+       
+       result = fopen (filepath, "r"); 
+       if (!result) 
+               g_printerr ("modest: failed to open mcc mapping file");
+       
+       return result;
+}
+
+
index a147024..e8a1e9b 100644 (file)
@@ -32,7 +32,9 @@
 #define __MODEST_MAEMO_UTILS_H__
 
 #include <gtk/gtk.h>
+#include <stdio.h> /* for FILE* */
 #include <modest-protocol-info.h>
+#include <tny-fs-stream.h>
 
 #define MODEST_MAEMO_UTILS_MYDOCS_FOLDER "MyDocs"
 #define MODEST_MAEMO_UTILS_DEFAULT_IMAGE_FOLDER ".images"
@@ -143,8 +145,25 @@ void modest_maemo_show_information_note_in_main_context_and_forget (GtkWindow *p
 void modest_maemo_show_dialog_and_forget (GtkWindow *parent_window, GtkDialog *dialog);
 
 
+/**
+ * modest_maemo_open_mcc_mapping_file:
+ *
+ * open the mcc mapping file, or NULL if it fails
+ *
+ * Returns: file ptr or NULL in case of error
+ */
+FILE* modest_maemo_open_mcc_mapping_file (void);
+
+/**
+ * modest_maemo_set_thumbable_scrollbar:
+ * @win: a scrollable window
+ * @thumbable: set it to thumbable (TRUE) or small (FALSE)
+ *
+ * changes the thumbability of scrollbars in a scrollable window
+ */
 void modest_maemo_set_thumbable_scrollbar (GtkScrolledWindow *win, gboolean thumbable);
 
+
 /**
  * modest_maemo_toggle_action_set_active_block_notify:
  * @action: a #GtkToggleAction
index 45f9541..f41dd95 100644 (file)
@@ -76,12 +76,40 @@ on_modest_conf_update_interval_changed (ModestConf* self,
        }
 }
 
+
+
+static gboolean
+check_required_files (void)
+{
+       FILE *mcc_file = modest_maemo_open_mcc_mapping_file ();
+       if (!mcc_file) {
+               g_printerr ("modest: check for mcc file failed\n");
+               return FALSE;
+       } else 
+               fclose (mcc_file);
+
+       if (access (MODEST_PROVIDERS_DATA_PATH, R_OK) != 0) {
+               g_printerr ("modest: cannot find providers data\n");
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+
+
 gboolean
 modest_platform_init (int argc, char *argv[])
 {
        osso_hw_state_t hw_state = { 0 };
        DBusConnection *con;    
 
+       if (!check_required_files ()) {
+               g_printerr ("modest: missing required files\n");
+               return FALSE;
+       }
+
+       
        osso_context =
                osso_initialize(PACKAGE,PACKAGE_VERSION,
                                FALSE, NULL);   
@@ -95,7 +123,7 @@ modest_platform_init (int argc, char *argv[])
                return FALSE;
 
        }
-       
+
        /* Add a D-Bus handler to be used when the main osso-rpc 
         * D-Bus handler has not handled something.
         * We use this for D-Bus methods that need to use more complex types