1 /* modest-main.c -- part of modest */
4 #include "modest-conf.h"
5 #include "modest-account-mgr.h"
6 #include "modest-identity-mgr.h"
8 #include "modest-icon-factory.h"
12 #endif /*HAVE_CONFIG_H*/
15 #ifdef IS_HILDON /* Hildon includes */
17 #define APPLICATION_DBUS_SERVICE "modest"
21 static void install_basic_conf_settings (ModestConf *conf);
22 static void install_test_account (ModestConf *conf);
26 main (int argc, char *argv[])
28 GOptionContext *context = NULL;
29 ModestConf *modest_conf = NULL;
30 ModestUI *modest_ui = NULL;
35 static gboolean update, debug, reinstall;
36 static gchar *mailto, *subject, *bcc, *cc, *body;
38 static GOptionEntry options[] = {
39 { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
40 "Run in debug mode" },
41 { "update", 'u', 0, G_OPTION_ARG_NONE, &update,
42 "Send/receive all accounts and exit"},
43 { "mailto", 'm', 0, G_OPTION_ARG_STRING, &mailto,
44 "Start writing a new email to <addresses>"},
45 { "subject", 's', 0, G_OPTION_ARG_STRING, &subject,
46 "Subject for a new mail"},
47 { "body", 'b', 0, G_OPTION_ARG_STRING, &body,
48 "Body for a new email"},
49 { "cc", 0, 0, G_OPTION_ARG_STRING, &cc,
50 "CC-addresses for a new mail (comma-separated)"},
51 { "bcc", 0, 0, G_OPTION_ARG_STRING, &bcc,
52 "BCC-adresses for a new mail (comma-separated)"},
53 { "reinstall-factory-settings", 0, 0, G_OPTION_ARG_NONE, &reinstall,
54 "Delete all settings and start over (*DESTRUCTIVE*)"
60 osso_context_t *osso_context;
65 context = g_option_context_new (NULL);
66 g_option_context_add_main_entries (context, options, NULL);
68 if (!g_option_context_parse (context, &argc, &argv, &err)) {
69 g_printerr ("modest: error in command line parameter(s): %s\n",
70 err ? err->message : "");
76 g_log_set_always_fatal (G_LOG_LEVEL_WARNING);
79 modest_conf = MODEST_CONF(modest_conf_new());
81 g_warning ("failed to initialize config system");
85 gtk_init (&argc, &argv);
87 modest_icon_factory_init ();
90 modest_conf_remove_key (modest_conf, MODEST_CONF_NAMESPACE, NULL);
91 install_basic_conf_settings (modest_conf);
95 modest_ui = MODEST_UI(modest_ui_new (modest_conf));
97 g_warning ("failed to initialize ui");
102 /* Initialize maemo application */
103 osso_context = osso_initialize(APPLICATION_DBUS_SERVICE, "0.1", TRUE, NULL);
105 /* Check that initialization was ok */
106 if (osso_context == NULL)
112 gtk_init (&argc, &argv);
114 if (mailto||cc||bcc||subject||body) {
116 ok = modest_ui_new_edit_window (modest_ui,
120 subject, /* subject */
122 NULL); /* attachments */
125 ok = modest_ui_show_main_window (modest_ui);
128 g_warning ("showing window failed");
139 g_option_context_free (context);
142 g_object_unref (modest_ui);
145 g_object_unref (modest_conf);
147 modest_icon_factory_uninit ();
155 install_basic_conf_settings (ModestConf *conf)
157 g_return_if_fail (conf);
159 /* main window size */
160 modest_conf_set_int (conf, MODEST_CONF_MAIN_WINDOW_WIDTH,
161 MODEST_CONF_MAIN_WINDOW_WIDTH_DEFAULT, NULL);
162 modest_conf_set_int (conf, MODEST_CONF_MAIN_WINDOW_HEIGHT,
163 MODEST_CONF_MAIN_WINDOW_HEIGHT_DEFAULT, NULL);
165 /* edit window size */
166 modest_conf_set_int (conf, MODEST_CONF_EDIT_WINDOW_WIDTH,
167 MODEST_CONF_EDIT_WINDOW_WIDTH_DEFAULT, NULL);
168 modest_conf_set_int (conf, MODEST_CONF_EDIT_WINDOW_HEIGHT,
169 MODEST_CONF_EDIT_WINDOW_HEIGHT_DEFAULT, NULL);
171 g_print ("modest: returned to factory settings\n");
176 install_test_account (ModestConf *conf)
178 ModestAccountMgr *acc_mgr;
179 ModestIdentityMgr *id_mgr;
180 const gchar *acc_name = "test";
181 g_return_if_fail (conf);
183 acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (conf));
185 g_warning ("failed to instantiate account mgr");
189 if (modest_account_mgr_account_exists (acc_mgr, acc_name, NULL)) {
190 if (!modest_account_mgr_remove_account(acc_mgr, acc_name, NULL)) {
191 g_warning ("could not delete existing account");
195 if (!modest_account_mgr_add_account (acc_mgr, acc_name, "mystore", "mytransport", NULL))
196 g_warning ("failed to add test account");
199 modest_account_mgr_add_server_account (acc_mgr, "mystore", "localhost", "djcb",
201 modest_account_mgr_add_server_account (acc_mgr, "mytransport", "localhost", NULL,
205 id_mgr = MODEST_IDENTITY_MGR(modest_identity_mgr_new (conf));
206 if (modest_identity_mgr_identity_exists(id_mgr, "myidentity", NULL)) {
207 if (!modest_identity_mgr_remove_identity(id_mgr, "myidentity", NULL)) {
208 g_warning ("could not delete existing identity");
211 if (!modest_identity_mgr_add_identity (id_mgr,
212 MODEST_IDENTITY_DEFAULT_IDENTITY,
215 "", "", FALSE, NULL, FALSE ))
216 g_warning ("failed to add test identity");
218 g_object_unref (G_OBJECT(acc_mgr));
219 g_object_unref (G_OBJECT(id_mgr));