* modest-main.c, modest-runtime.[ch]:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 29 Jan 2007 07:17:23 +0000 (07:17 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 29 Jan 2007 07:17:23 +0000 (07:17 +0000)
- some further cleanups

pmo-trunk-r745

src/modest-main.c
src/modest-runtime.c
src/modest-runtime.h

index 1453cff..7446ef5 100644 (file)
@@ -47,7 +47,6 @@
 #include <modest-tny-platform-factory.h>
 #include <modest-mail-operation.h>
 
-
 static int start_ui (const gchar* mailto, const gchar *cc, const gchar *bcc,
                     const gchar* subject, const gchar *body);
 static int send_mail (const gchar* mailto, const gchar *cc, const gchar *bcc,
@@ -56,12 +55,12 @@ static int send_mail (const gchar* mailto, const gchar *cc, const gchar *bcc,
 int
 main (int argc, char *argv[])
 {
-       GOptionContext     *context       = NULL;
+       GOptionContext     *context = NULL;
        
        GError *err = NULL;
        int retval  = MODEST_ERR_NONE;
                
-       static gboolean batch=FALSE, factory_settings=FALSE;
+       static gboolean batch = FALSE;
        static gchar    *mailto, *subject, *bcc, *cc, *body, *account;
 
        static GOptionEntry options[] = {
@@ -79,8 +78,6 @@ main (int argc, char *argv[])
                  N_("Account to use (if specified, default account is used)"), NULL},
                { "batch", 'y', 0, G_OPTION_ARG_NONE, &batch,
                  N_("Run in batch mode (don't show UI)"), NULL},
-               { "factory-settings", 0, 0, G_OPTION_ARG_NONE, &factory_settings,
-                 N_("return to factory settings"), NULL},
                { NULL, 0, 0, 0, NULL, NULL, NULL }
        };
 
@@ -101,16 +98,13 @@ main (int argc, char *argv[])
        }
        g_option_context_free (context);
        
-       if (!getenv("DISPLAY"))
-               batch = TRUE; 
-       
        if (!batch) {
-               if (!gtk_init_check(&argc, &argv)) {
-                       g_printerr ("modest: failed to start graphical ui\n");
+               if (!modest_runtime_init_ui (argc, argv)) {
+                       g_printerr ("modest: cannot start UI\n");
+                       retval = MODEST_ERR_UI;
                        goto cleanup;
-               }
-               retval = start_ui (mailto, cc, bcc, subject, body);
-
+               } else
+                       retval = start_ui (mailto, cc, bcc, subject, body);
        } else 
                retval = send_mail (mailto, cc, bcc, subject, body);
        
@@ -130,7 +124,6 @@ start_ui (const gchar* mailto, const gchar *cc, const gchar *bcc,
        ModestUI *modest_ui = NULL;
        
        gint retval = 0;
-
        modest_ui = modest_ui_new ();
 
        if (mailto||cc||bcc||subject||body) {
index 5d96766..15824f1 100644 (file)
@@ -106,6 +106,7 @@ gboolean
 modest_runtime_init (void)
 {
        ModestSingletons *my_singletons;
+       gboolean reset;
        
        if (_singletons) {
                g_printerr ("modest: modest_runtime_init can only be called once\n");
@@ -132,9 +133,10 @@ modest_runtime_init (void)
                return FALSE;
        }
 #endif /* MODEST_PLATFORM_ID==2 */
-       
-       if (!init_header_columns(modest_singletons_get_conf (my_singletons),
-                                FALSE)) {
+
+       /* based on the debug settings, we decide whether to overwrite old settings */
+       reset = modest_runtime_get_debug_flags () & MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS;
+       if (!init_header_columns(modest_singletons_get_conf (my_singletons), reset)) {
                modest_runtime_uninit ();
                g_printerr ("modest: failed to init header columns\n");
                return FALSE;
@@ -163,6 +165,17 @@ modest_runtime_init (void)
 
 
 gboolean
+modest_runtime_init_ui (gint argc, gchar** argv)
+{
+       if (!gtk_init_check(&argc, &argv)) {
+               g_printerr ("modest: failed to initialize graphical ui\n");
+               return FALSE;
+       }
+       return TRUE;
+}
+
+
+gboolean
 modest_runtime_uninit (void)
 {
        if (!_singletons) {
@@ -229,11 +242,12 @@ modest_runtime_get_widget_factory     (void)
 ModestRuntimeDebugFlags
 modest_runtime_get_debug_flags ()
 {
-       GDebugKey debug_keys[] = {
+       static const GDebugKey debug_keys[] = {
                { "abort-on-warning", MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING },
                { "log-actions",      MODEST_RUNTIME_DEBUG_LOG_ACTIONS },
                { "debug-objects",    MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS },
-               { "debug-signals",    MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS }
+               { "debug-signals",    MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS },
+               { "factory-settings", MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS }
        };
        const gchar *str;
        static ModestRuntimeDebugFlags debug_flags = -1;
@@ -448,9 +462,8 @@ debug_g_type_init (void)
                gflags |= G_TYPE_DEBUG_OBJECTS;
        if (mflags & MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS)
                gflags |= G_TYPE_DEBUG_SIGNALS;
-       
-       g_type_init_with_debug_flags (gflags);
 
+       g_type_init_with_debug_flags (gflags);
 }
 
 static void
index 785f48e..9097eb4 100644 (file)
@@ -48,6 +48,7 @@ typedef enum {
        MODEST_RUNTIME_DEBUG_LOG_ACTIONS           = 1 << 1, /* not in use atm */
        MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS         = 1 << 2, /* for g_type_init */
        MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS         = 1 << 3, /* for g_type_init */
+       MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS      = 1 << 4, /* reset to factory defaults */
 } ModestRuntimeDebugFlags;
 
 /**
@@ -64,6 +65,18 @@ gboolean modest_runtime_init (void);
 
 
 /**
+ * modest_runtime_init_ui:
+ * @argc: the #argc argument to the main function
+ * @argv: the #argv argument to the main function
+ * 
+ * initialize the modest UI; this replaces the call to
+ * gtk_init
+ *  
+ * TRUE if this succeeded, FALSE otherwise.
+ */
+gboolean modest_runtime_init_ui (gint argc, gchar** argv);
+
+/**
  * modest_runtime_uinit:
  *
  * uninitialize the modest runtime system; free all the