new popup that fits better our theme.
[profile/ivi/lemolo.git] / dialer / main.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4 #include <Elementary.h>
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 #include "log.h"
8 #include "ofono.h"
9 #include "gui.h"
10 #include "rc.h"
11
12 #include <Ecore_Getopt.h>
13
14 static const char def_modem_hardware_api[] =
15         "SimManager,"
16         "VoiceCallManager,"
17         "MessageManager,"
18         "SimToolkit,"
19         "CallForwarding";
20
21 static const char def_modem_hfp_api[] =
22         "VoiceCallManager";
23
24 static const char def_modem_type[] =
25         "hardware";
26
27 static const Ecore_Getopt options = {
28         PACKAGE_NAME,
29         "%prog [options]",
30         PACKAGE_VERSION,
31         "(C) 2012 Intel Corporation",
32         "GPL-2" /* TODO: check license with Intel */,
33         "Phone Dialer using oFono and EFL.",
34         EINA_FALSE,
35         {ECORE_GETOPT_STORE_STR('H', "theme", "path to theme EDJ file."),
36          ECORE_GETOPT_STORE_STR('m', "modem", "Modem object path in oFono."),
37          ECORE_GETOPT_STORE_STR('a', "api", "oFono modem APIs to use, comma "
38                                 "separated. Example: "
39                                 "SimManager,VoiceCallManager. See --list-api"),
40          ECORE_GETOPT_STORE_TRUE('A', "list-api", "list all oFono modem API."),
41          ECORE_GETOPT_STORE_DEF_STR('t', "type", "oFono modem type to use.",
42                                         def_modem_type),
43          ECORE_GETOPT_STORE_TRUE('T', "list-types",
44                                         "list all oFono modem types."),
45          ECORE_GETOPT_VERSION('V', "version"),
46          ECORE_GETOPT_COPYRIGHT('C', "copyright"),
47          ECORE_GETOPT_LICENSE('L', "license"),
48          ECORE_GETOPT_HELP('h', "help"),
49          ECORE_GETOPT_SENTINEL
50         }
51 };
52
53 int _log_domain = -1;
54 int _app_exit_code = EXIT_SUCCESS;
55
56 EAPI int elm_main(int argc, char **argv)
57 {
58         int args;
59         char *modem_path = NULL;
60         char *modem_api = NULL;
61         char *modem_type = NULL;
62         char *theme = NULL;
63         Eina_Bool list_api = EINA_FALSE;
64         Eina_Bool list_type = EINA_FALSE;
65         Eina_Bool quit_option = EINA_FALSE;
66         Ecore_Getopt_Value values[] = {
67                 ECORE_GETOPT_VALUE_STR(theme),
68                 ECORE_GETOPT_VALUE_STR(modem_path),
69                 ECORE_GETOPT_VALUE_STR(modem_api),
70                 ECORE_GETOPT_VALUE_BOOL(list_api),
71                 ECORE_GETOPT_VALUE_STR(modem_type),
72                 ECORE_GETOPT_VALUE_BOOL(list_type),
73                 ECORE_GETOPT_VALUE_BOOL(quit_option),
74                 ECORE_GETOPT_VALUE_BOOL(quit_option),
75                 ECORE_GETOPT_VALUE_BOOL(quit_option),
76                 ECORE_GETOPT_VALUE_BOOL(quit_option),
77                 ECORE_GETOPT_VALUE_NONE
78         };
79
80         _log_domain = eina_log_domain_register("dialer", NULL);
81         if (_log_domain < 0)
82         {
83                 EINA_LOG_CRIT("Could not create log domain 'dialer'.");
84                 elm_shutdown();
85                 return EXIT_FAILURE;
86         }
87
88         args = ecore_getopt_parse(&options, values, argc, argv);
89         if (args < 0)
90         {
91                 ERR("Could not parse command line options.");
92                 _app_exit_code = EXIT_FAILURE;
93                 goto end;
94         }
95         if (list_api) {
96                 puts("Supported oFono API:");
97                 ofono_modem_api_list(stdout, "\t", "\n");
98                 goto end;
99         }
100         if (list_type) {
101                 puts("Supported oFono type:");
102                 ofono_modem_type_list(stdout, "\t", "\n");
103                 goto end;
104         }
105
106         if (quit_option)
107                 goto end;
108
109         if (!rc_init()) {
110                 CRITICAL("Could not setup remote control via DBus.");
111                 _app_exit_code = EXIT_FAILURE;
112                 goto end;
113         }
114
115         if (!ofono_init()) {
116                 CRITICAL("Could not setup ofono");
117                 _app_exit_code = EXIT_FAILURE;
118                 goto end_rc;
119         }
120
121         if (modem_path) {
122                 INF("User-defined modem path: %s", modem_path);
123                 ofono_modem_path_wanted_set(modem_path);
124         }
125
126         if (modem_api) {
127                 INF("User-defined modem API: %s", modem_api);
128                 ofono_modem_api_require(modem_api);
129         } else {
130                 const char *api;
131                 if (!modem_type)
132                         api = def_modem_hardware_api;
133                 else if (strstr(modem_type, "hfp"))
134                         api = def_modem_hfp_api;
135                 else if (strcmp(modem_type, "hardware"))
136                         api = def_modem_hardware_api;
137                 else {
138                         WRN("modem type not handled: %s", modem_type);
139                         api = "VoiceCallManager";
140                 }
141
142                 INF("Using default modem API: %s", api);
143                 ofono_modem_api_require(api);
144         }
145
146         if (modem_type) {
147                 INF("User-defined modem type: %s", modem_type);
148                 ofono_modem_type_require(modem_type);
149         } else {
150                 INF("Using default modem type: %s", def_modem_type);
151                 ofono_modem_type_require(def_modem_type);
152         }
153
154         if (!gui_init(theme)) {
155                 CRITICAL("Could not setup graphical user interface");
156                 _app_exit_code = EXIT_FAILURE;
157                 goto end_ofono;
158         }
159
160         INF("Entering main loop");
161         elm_run();
162         INF("Quit main loop");
163
164         gui_shutdown();
165
166 end_ofono:
167         ofono_shutdown();
168 end_rc:
169         rc_shutdown();
170 end:
171         elm_shutdown();
172
173         return _app_exit_code;
174 }
175
176 #endif
177 ELM_MAIN()