1 /* modest-main.c -- part of modest */
4 #include "modest-conf.h"
5 #include "modest-account-mgr.h"
10 #endif /*HAVE_CONFIG_H*/
13 static void install_basic_conf_settings (ModestConf *conf);
14 static void install_test_account (ModestConf *conf);
18 main (int argc, char *argv[])
20 GOptionContext *context = NULL;
21 ModestConf *modest_conf = NULL;
22 ModestUI *modest_ui = NULL;
27 static gboolean update, debug, reinstall;
28 static gchar *mailto, *subject, *bcc, *cc, *body;
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*)"
54 context = g_option_context_new (NULL);
55 g_option_context_add_main_entries (context, options, NULL);
57 if (!g_option_context_parse (context, &argc, &argv, &err)) {
58 g_printerr ("modest: error in command line parameter(s): %s\n",
59 err ? err->message : "");
65 g_log_set_always_fatal (G_LOG_LEVEL_WARNING);
68 modest_conf = MODEST_CONF(modest_conf_new());
70 g_warning ("failed to initialize config system");
75 modest_conf_remove_key (modest_conf, MODEST_CONF_NAMESPACE, NULL);
76 install_basic_conf_settings (modest_conf);
77 install_test_account (modest_conf);
83 gtk_init (&argc, &argv);
84 modest_ui = MODEST_UI(modest_ui_new (modest_conf));
86 g_warning ("failed to initialize 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");
117 g_option_context_free (context);
120 g_object_unref (modest_ui);
123 g_object_unref (modest_conf);
131 install_basic_conf_settings (ModestConf *conf)
133 g_return_if_fail (conf);
135 /* main window size */
136 modest_conf_set_int (conf, MODEST_CONF_MAIN_WINDOW_WIDTH,
137 MODEST_CONF_MAIN_WINDOW_WIDTH_DEFAULT, NULL);
138 modest_conf_set_int (conf, MODEST_CONF_MAIN_WINDOW_HEIGHT,
139 MODEST_CONF_MAIN_WINDOW_HEIGHT_DEFAULT, NULL);
141 /* edit window size */
142 modest_conf_set_int (conf, MODEST_CONF_EDIT_WINDOW_WIDTH,
143 MODEST_CONF_EDIT_WINDOW_WIDTH_DEFAULT, NULL);
144 modest_conf_set_int (conf, MODEST_CONF_EDIT_WINDOW_HEIGHT,
145 MODEST_CONF_EDIT_WINDOW_HEIGHT_DEFAULT, NULL);
147 g_print ("modest: returned to factory settings\n");
152 install_test_account (ModestConf *conf)
154 ModestAccountMgr *acc_mgr;
155 const gchar *acc_name = "test";
156 g_return_if_fail (conf);
158 acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (conf));
160 g_warning ("failed to instantiate account mgr");
164 if (modest_account_mgr_account_exists (acc_mgr, acc_name, NULL)) {
165 if (!modest_account_mgr_remove_account(acc_mgr, acc_name, NULL)) {
166 g_warning ("could not delete existing account");
170 if (!modest_account_mgr_add_account (acc_mgr, acc_name, "mystore", "mytransport", NULL))
171 g_warning ("failed to add test account");
174 modest_account_mgr_add_server_account (acc_mgr, "mystore", "localhost", "djcb",
176 modest_account_mgr_add_server_account (acc_mgr, "mytransport", "localhost", NULL,
179 g_object_unref (G_OBJECT(acc_mgr));