* modest-ui-wizard.c:
[modest] / src / modest-main.c
1 /* modest-main.c -- part of modest */
2 #include <glib.h>
3
4 #include "modest-conf.h"
5 #include "modest-account-mgr.h"
6 #include "modest-identity-mgr.h"
7 #include "modest-ui.h"
8 #include "modest-icon-factory.h"
9
10 #ifdef HAVE_CONFIG_H
11 #include <config.h>
12 #endif /*HAVE_CONFIG_H*/
13 #include <gtk/gtk.h>
14
15 static void install_basic_conf_settings (ModestConf *conf);
16
17 int
18 main (int argc, char *argv[])
19 {
20         GOptionContext   *context        = NULL;
21         ModestConf       *modest_conf    = NULL;
22         ModestUI         *modest_ui      = NULL;
23
24         GError *err = NULL;
25         int retval  = 0;
26
27         static gboolean update, debug, reinstall;
28         static gchar *mailto, *subject, *bcc, *cc, *body;
29
30         static GOptionEntry options[] = {
31                 { "debug",  'd', 0, G_OPTION_ARG_NONE, &debug,
32                   "Run in debug mode" },
33                 { "update", 'u', 0, G_OPTION_ARG_NONE, &update,
34                   "Send/receive all accounts and exit"},
35                 { "mailto", 'm', 0, G_OPTION_ARG_STRING, &mailto,
36                   "Start writing a new email to <addresses>"},
37                 { "subject", 's', 0, G_OPTION_ARG_STRING, &subject,
38                   "Subject for a new mail"},
39                 { "body", 'b', 0, G_OPTION_ARG_STRING, &body,
40                   "Body for a new email"},
41                 { "cc",  0, 0, G_OPTION_ARG_STRING, &cc,
42                   "CC-addresses for a new mail (comma-separated)"},
43                 { "bcc", 0, 0, G_OPTION_ARG_STRING, &bcc,
44                   "BCC-adresses for a new mail (comma-separated)"},
45                 { "reinstall-factory-settings", 0, 0, G_OPTION_ARG_NONE, &reinstall,
46                   "Delete all settings and start over (*DESTRUCTIVE*)"
47                 },
48                 { NULL }
49         };
50
51         gtk_init (&argc, &argv);
52
53         context = g_option_context_new (NULL);
54         g_option_context_add_main_entries (context, options, NULL);
55
56         if (!g_option_context_parse (context, &argc, &argv, &err)) {
57                 g_printerr ("modest: error in command line parameter(s): %s\n",
58                          err ? err->message : "");
59                 retval = 1;
60                 goto cleanup;
61         }
62
63         if (debug) {
64                 g_log_set_always_fatal (G_LOG_LEVEL_WARNING);
65         }
66
67         modest_conf = MODEST_CONF(modest_conf_new());
68         if (!modest_conf) {
69                 g_warning ("failed to initialize config system");
70                 goto cleanup;
71         }
72
73         if (reinstall) {
74                 modest_conf_remove_key (modest_conf, MODEST_CONF_NAMESPACE, NULL);
75                 install_basic_conf_settings (modest_conf);
76                 goto cleanup;
77         }
78
79         modest_icon_factory_init ();
80
81         modest_ui = MODEST_UI(modest_ui_new (modest_conf));
82         if (!modest_ui) {
83                 g_warning ("failed to initialize ui");
84                 goto cleanup;
85         }
86
87         {
88                 gboolean ok;
89                 gtk_init (&argc, &argv);
90
91                 if (mailto||cc||bcc||subject||body) {
92                         ok = FALSE;
93 #if 0
94                         ok = modest_ui_new_edit_window (modest_ui,
95                                                          mailto,  /* to */
96                                                          cc,      /* cc */
97                                                          bcc,     /* bcc */
98                                                          subject,    /* subject */
99                                                          body,    /* body */
100                                                          NULL);   /* attachments */
101 #endif
102                 } else
103                         ok = modest_ui_show_main_window (modest_ui);
104
105                 if (!ok)
106                         g_warning ("showing window failed");
107                 else
108                         gtk_main();
109         }
110
111
112 cleanup:
113         if (err)
114                 g_error_free (err);
115
116         if (context)
117                 g_option_context_free (context);
118
119         if (modest_ui)
120                 g_object_unref (modest_ui);
121
122         if (modest_conf)
123                 g_object_unref (modest_conf);
124
125         modest_icon_factory_uninit ();
126
127         return retval;
128 }
129
130
131
132 static void
133 install_basic_conf_settings (ModestConf *conf)
134 {
135         g_return_if_fail (conf);
136
137         /* main window size */
138         modest_conf_set_int (conf, MODEST_CONF_MAIN_WINDOW_WIDTH,
139                              MODEST_CONF_MAIN_WINDOW_WIDTH_DEFAULT, NULL);
140         modest_conf_set_int (conf, MODEST_CONF_MAIN_WINDOW_HEIGHT,
141                              MODEST_CONF_MAIN_WINDOW_HEIGHT_DEFAULT, NULL);
142
143         /* edit window size */
144         modest_conf_set_int (conf, MODEST_CONF_EDIT_WINDOW_WIDTH,
145                              MODEST_CONF_EDIT_WINDOW_WIDTH_DEFAULT, NULL);
146         modest_conf_set_int (conf, MODEST_CONF_EDIT_WINDOW_HEIGHT,
147                              MODEST_CONF_EDIT_WINDOW_HEIGHT_DEFAULT, NULL);
148
149         g_print ("modest: returned to factory settings\n");
150 }
151
152