1 /* Setup if we need connman? */
2 #include "e_wizard.h"
3 #include "e_wizard_api.h"
4 
5 static void
_recommend_connman(E_Wizard_Page * pg EINA_UNUSED)6 _recommend_connman(E_Wizard_Page *pg EINA_UNUSED)
7 {
8    Evas_Object *of, *ob;
9 
10    api->wizard_title_set(_("Network Management"));
11 
12    of = elm_frame_add(e_comp->elm);
13    ob = elm_label_add(of);
14    elm_object_content_set(of, ob);
15 #if defined(USE_MODULE_CONNMAN) || defined(USE_MODULE_WIRELESS)
16    elm_object_text_set(of, _("Connman network service not found"));
17 
18 
19    elm_object_text_set(ob, _("Install/Enable Connman service for network management support"));
20 #else
21    elm_object_text_set(of, _("Connman and Wireless modules disabled"));
22    elm_object_text_set(ob, _("Install one of these modules for network management support"));
23 #endif
24    evas_object_show(ob);
25    evas_object_show(of);
26 
27    api->wizard_page_show(of);
28 //   pg->data = o;
29 
30    api->wizard_button_next_enable_set(1);
31 }
32 
33 static Eldbus_Connection *conn;
34 static Eldbus_Pending *pending_connman;
35 static Ecore_Timer *connman_timeout = NULL;
36 
37 static Eina_Bool
_connman_fail(void * data)38 _connman_fail(void *data)
39 {
40    E_Wizard_Page *pg = data;
41    E_Config_Module *em;
42    Eina_List *l;
43 
44    EINA_LIST_FOREACH(e_config->modules, l, em)
45      {
46         if (!em->name) continue;
47         if (!strcmp(em->name, "connman"))
48           {
49              e_config->modules = eina_list_remove_list
50                  (e_config->modules, l);
51              if (em->name) eina_stringshare_del(em->name);
52              free(em);
53              break;
54           }
55      }
56 
57    e_config_save_queue();
58 
59    connman_timeout = NULL;
60    _recommend_connman(pg);
61    return EINA_FALSE;
62 }
63 
64 static Eina_Bool
_page_next_call(void * data EINA_UNUSED)65 _page_next_call(void *data EINA_UNUSED)
66 {
67    api->wizard_next();
68    return ECORE_CALLBACK_CANCEL;
69 }
70 
71 static void
_check_connman_owner(void * data,const Eldbus_Message * msg,Eldbus_Pending * pending EINA_UNUSED)72 _check_connman_owner(void *data, const Eldbus_Message *msg,
73                      Eldbus_Pending *pending EINA_UNUSED)
74 {
75    const char *id;
76    pending_connman = NULL;
77 
78    if (connman_timeout)
79      {
80         ecore_timer_del(connman_timeout);
81         connman_timeout = NULL;
82      }
83 
84    if (eldbus_message_error_get(msg, NULL, NULL))
85      goto fail;
86 
87    if (!eldbus_message_arguments_get(msg, "s", &id))
88      goto fail;
89 
90    if (id[0] != ':')
91      goto fail;
92 
93    api->wizard_button_next_enable_set(1);
94    ecore_idler_add(_page_next_call, NULL);
95    return;
96 
97 fail:
98    _connman_fail(data);
99 }
100 /*
101 
102 E_API int
103 wizard_page_init(E_Wizard_Page *pg EINA_UNUSED, Eina_Bool *need_xdg_desktops EINA_UNUSED, Eina_Bool *need_xdg_icons EINA_UNUSED)
104 {
105    return 1;
106 }
107 
108 E_API int
109 wizard_page_shutdown(E_Wizard_Page *pg EINA_UNUSED)
110 {
111    return 1;
112 }
113 */
114 E_API int
wizard_page_show(E_Wizard_Page * pg)115 wizard_page_show(E_Wizard_Page *pg)
116 {
117    Eina_Bool have_connman = EINA_FALSE;
118 
119 #if defined(USE_MODULE_CONNMAN) || defined(USE_MODULE_WIRELESS)
120    conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
121 #endif
122    if (conn)
123      {
124         if (pending_connman)
125           eldbus_pending_cancel(pending_connman);
126 
127         pending_connman = eldbus_name_owner_get(conn, "net.connman",
128                                                _check_connman_owner, pg);
129         if (connman_timeout)
130           ecore_timer_del(connman_timeout);
131         connman_timeout = ecore_timer_loop_add(0.5, _connman_fail, pg);
132         have_connman = EINA_TRUE;
133         api->wizard_button_next_enable_set(0);
134      }
135    if (!have_connman)
136      {
137         E_Config_Module *em;
138         Eina_List *l;
139         EINA_LIST_FOREACH(e_config->modules, l, em)
140           {
141              if (!em->name) continue;
142              if (!strcmp(em->name, "connman"))
143                {
144                   e_config->modules = eina_list_remove_list
145                       (e_config->modules, l);
146                   if (em->name) eina_stringshare_del(em->name);
147                   free(em);
148                   break;
149                }
150           }
151         e_config_save_queue();
152         _recommend_connman(pg);
153      }
154    api->wizard_title_set(_("Checking to see if Connman exists"));
155    return 1; /* 1 == show ui, and wait for user, 0 == just continue */
156 }
157 
158 E_API int
wizard_page_hide(E_Wizard_Page * pg EINA_UNUSED)159 wizard_page_hide(E_Wizard_Page *pg EINA_UNUSED)
160 {
161    if (pending_connman)
162      {
163         eldbus_pending_cancel(pending_connman);
164         pending_connman = NULL;
165      }
166    if (connman_timeout)
167      {
168         ecore_timer_del(connman_timeout);
169         connman_timeout = NULL;
170      }
171    if (conn)
172      eldbus_connection_unref(conn);
173    conn = NULL;
174 
175    return 1;
176 }
177 /*
178 E_API int
179 wizard_page_apply(E_Wizard_Page *pg EINA_UNUSED)
180 {
181    return 1;
182 }
183 */
184