1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <glib/gi18n.h>
35 #include "modest-conf.h"
36 #include "modest-account-mgr.h"
37 #include "modest-identity-mgr.h"
38 #include "modest-ui.h"
39 #include "modest-icon-factory.h"
43 #endif /*HAVE_CONFIG_H*/
45 #ifdef MODEST_ENABLE_HILDON /* Hildon includes */
47 #endif /* MODEST_ENABLE_HILDON */
50 #define MODEST_ERR_NONE 0
51 #define MODEST_ERR_OPTIONS 1
52 #define MODEST_ERR_CONF 2
53 #define MODEST_ERR_UI 3
54 #define MODEST_ERR_HILDON 4
55 #define MODEST_ERR_RUN 5
58 static gboolean hildon_init (); /* NOP if HILDON is not defined */
60 static int start_ui (ModestConf *conf, const gchar* mailto, const gchar *cc,
61 const gchar *bcc, const gchar* subject, const gchar *body);
64 main (int argc, char *argv[])
66 GOptionContext *context = NULL;
67 ModestConf *modest_conf = NULL;
68 ModestUI *modest_ui = NULL;
71 int retval = MODEST_ERR_NONE;
73 static gboolean update, debug, batch;
74 static gchar *mailto, *subject, *bcc, *cc, *body;
76 static GOptionEntry options[] = {
77 { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
78 "Run in debug mode" },
79 { "update", 'u', 0, G_OPTION_ARG_NONE, &update,
80 "Send/receive active accounts"},
81 { "mailto", 'm', 0, G_OPTION_ARG_STRING, &mailto,
82 "Start writing a new email to <addresses>"},
83 { "subject", 's', 0, G_OPTION_ARG_STRING, &subject,
84 "Subject for a new mail"},
85 { "body", 'b', 0, G_OPTION_ARG_STRING, &body,
86 "Body for a new email"},
87 { "cc", 'c', 0, G_OPTION_ARG_STRING, &cc,
88 "Cc: addresses for a new mail (comma-separated)"},
89 { "bcc", 'd', 0, G_OPTION_ARG_STRING, &bcc,
90 "Bcc: addresses for a new mail (comma-separated)"},
91 { "batch", 'b', 0, G_OPTION_ARG_NONE, &batch,
92 "Run in batch mode (don't show UI)"},
98 context = g_option_context_new (NULL);
99 g_option_context_add_main_entries (context, options, NULL);
101 if (!g_option_context_parse (context, &argc, &argv, &err)) {
102 g_printerr ("modest: error in command line parameter(s): '%s', exiting\n",
103 err ? err->message : "");
105 retval = MODEST_ERR_OPTIONS;
108 g_option_context_free (context);
110 modest_conf = MODEST_CONF(modest_conf_new());
112 g_printerr ("modest: failed to initialize config system, exiting\n");
113 retval = MODEST_ERR_CONF;
117 gtk_init (&argc, &argv);
118 retval = start_ui (modest_conf, mailto, cc, bcc, subject, body);
121 g_object_unref (modest_conf);
128 start_ui (ModestConf *conf, const gchar* mailto, const gchar *cc, const gchar *bcc,
129 const gchar* subject, const gchar *body)
134 modest_ui = MODEST_UI(modest_ui_new (conf));
136 g_printerr ("modest: failed to initialize ui, exiting\n");
137 retval = MODEST_ERR_UI;
141 modest_icon_factory_init ();
143 if (!hildon_init ()) { /* NOP if hildon is not defined */
144 g_printerr ("modest: failed to initialize hildon, exiting\n");
145 retval = MODEST_ERR_HILDON;
149 if (mailto||cc||bcc||subject||body) {
151 /* ok = modest_ui_new_edit_window (modest_ui, */
152 /* mailto, /\* to *\/ */
154 /* bcc, /\* bcc *\/ */
155 /* subject, /\* subject *\/ */
156 /* body, /\* body *\/ */
157 /* NULL); /\* attachments *\/ */
159 ok = modest_ui_show_main_window (modest_ui);
162 g_printerr ("modest: showing window failed");
163 retval = MODEST_ERR_RUN;
171 g_object_unref (modest_ui);
173 modest_icon_factory_uninit ();
181 #ifdef MODEST_ENABLE_HILDON
183 osso_context_t *osso_context =
184 osso_initialize(PACKAGE, PACKAGE_VERSION,
188 g_printerr ("modest: failed to aquire osso context, exiting");
191 #endif /* MODEST_ENABLE_HILDON */