1 /* modest-main.c -- part of modest */
4 #include "modest-conf.h"
5 #include "modest-account-mgr.h"
10 #endif /*HAVE_CONFIG_H*/
12 #if defined (MODEST_ENABLE_HILDON_UI) || defined (MODEST_ENABLE_GTK_UI)
16 static void install_basic_conf_settings (ModestConf *conf);
17 static void install_test_account (ModestConf *conf);
21 main (int argc, char *argv[])
23 GOptionContext *context = NULL;
24 ModestConf *modest_conf = NULL;
25 ModestUI *modest_ui = NULL;
30 static gboolean update, debug, reinstall;
31 static gchar *mailto, *subject, *bcc, *cc, *body;
33 static GOptionEntry options[] = {
34 { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
35 "Run in debug mode" },
36 { "update", 'u', 0, G_OPTION_ARG_NONE, &update,
37 "Send/receive all accounts and exit"},
38 { "mailto", 'm', 0, G_OPTION_ARG_STRING, &mailto,
39 "Start writing a new email to <addresses>"},
40 { "subject", 's', 0, G_OPTION_ARG_STRING, &subject,
41 "Subject for a new mail"},
42 { "body", 'b', 0, G_OPTION_ARG_STRING, &body,
43 "Body for a new email"},
44 /* { "bodyfile", 'f', 0, G_OPTION_ARG_STRING, &bodyfile, */
45 /* "Body for a new email"}, */
46 { "cc", 0, 0, G_OPTION_ARG_STRING, &cc,
47 "CC-addresses for a new mail (comma-separated)"},
48 { "bcc", 0, 0, G_OPTION_ARG_STRING, &bcc,
49 "BCC-adresses for a new mail (comma-separated)"},
50 /* { "attach", 's', 0, G_OPTION_ARG_STRING, &attach, */
51 /* "Attachements for a new email (comma-separated)"}, */
52 { "reinstall-factory-settings", 0, 0, G_OPTION_ARG_NONE, &reinstall,
53 "Delete all settings and start over (*DESTRUCTIVE*)"
60 context = g_option_context_new (NULL);
61 g_option_context_add_main_entries (context, options, NULL);
63 if (!g_option_context_parse (context, &argc, &argv, &err)) {
64 g_printerr ("modest: error in command line parameter(s): %s\n",
65 err ? err->message : "");
70 modest_conf = MODEST_CONF(modest_conf_new());
72 g_warning ("failed to initialize config system");
77 modest_conf_remove_key (modest_conf, MODEST_CONF_NAMESPACE, NULL);
78 install_basic_conf_settings (modest_conf);
79 install_test_account (modest_conf);
83 modest_ui = MODEST_UI(modest_ui_new (modest_conf));
85 g_warning ("failed to initialize ui");
89 #if defined (MODEST_ENABLE_HILDON_UI) || defined (MODEST_ENABLE_GTK_UI)
92 gtk_init (&argc, &argv);
94 if (mailto||cc||bcc||subject||body)
95 ok = modest_ui_show_edit_window (modest_ui,
99 subject, /* subject */
101 NULL); /* attachments */
103 ok = modest_ui_show_main_window (modest_ui);
106 g_warning ("showing window failed");
111 /* do something else... */
120 g_option_context_free (context);
123 g_object_unref (modest_ui);
126 g_object_unref (modest_conf);
134 install_basic_conf_settings (ModestConf *conf)
136 g_return_if_fail (conf);
138 /* main window size */
139 modest_conf_set_int (conf, MODEST_CONF_MAIN_WINDOW_WIDTH,
140 MODEST_CONF_MAIN_WINDOW_WIDTH_DEFAULT, NULL);
141 modest_conf_set_int (conf, MODEST_CONF_MAIN_WINDOW_HEIGHT,
142 MODEST_CONF_MAIN_WINDOW_HEIGHT_DEFAULT, NULL);
144 /* edit window size */
145 modest_conf_set_int (conf, MODEST_CONF_EDIT_WINDOW_WIDTH,
146 MODEST_CONF_EDIT_WINDOW_WIDTH_DEFAULT, NULL);
147 modest_conf_set_int (conf, MODEST_CONF_EDIT_WINDOW_HEIGHT,
148 MODEST_CONF_EDIT_WINDOW_HEIGHT_DEFAULT, NULL);
150 g_print ("modest: returned to factory settings\n");
156 install_test_account (ModestConf *conf)
158 ModestAccountMgr *acc_mgr;
159 const gchar *acc_name = "test";
160 g_return_if_fail (conf);
162 acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (conf));
164 g_warning ("failed to instantiate account mgr");
168 if (modest_account_mgr_account_exists (acc_mgr, acc_name, NULL)) {
169 if (!modest_account_mgr_remove_account(acc_mgr, acc_name, NULL)) {
170 g_warning ("could not delete existing account");
175 if (!modest_account_mgr_add_account (acc_mgr, acc_name, NULL))
176 g_warning ("failed to add test account");
179 modest_account_mgr_set_account_string (acc_mgr, acc_name,
181 MODEST_ACCOUNT_TYPE_STORE,
184 modest_account_mgr_set_account_string (acc_mgr, acc_name,
185 MODEST_ACCOUNT_PROTO,
186 MODEST_ACCOUNT_PROTO_IMAP,
189 modest_account_mgr_set_account_string (acc_mgr, acc_name,
190 MODEST_ACCOUNT_SERVER,
194 modest_account_mgr_set_account_string (acc_mgr, acc_name,
199 g_object_unref (G_OBJECT(acc_mgr));