summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-10-04 21:42:06 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-10-04 21:42:06 +0200
commitbb94536743f40b7defb19a8186d2797b09ba0973 (patch)
treee23124a5f720e6ad6a225c47d94431213ce00b8b
parentd6bc2513ea7824d6f6a51a4eead3ae0374d2ad8b (diff)
more work
-rw-r--r--data/efl-netctl.desktop9
-rw-r--r--data/meson.build2
-rw-r--r--src/bin/backend.c195
-rw-r--r--src/bin/backend.h12
-rw-r--r--src/bin/main.c106
5 files changed, 275 insertions, 49 deletions
diff --git a/data/efl-netctl.desktop b/data/efl-netctl.desktop
index 02c49cb..71266c3 100644
--- a/data/efl-netctl.desktop
+++ b/data/efl-netctl.desktop
@@ -2,16 +2,7 @@
2#Encoding=UTF-8 2#Encoding=UTF-8
3Type=Application 3Type=Application
4Name=Efl-Netctl 4Name=Efl-Netctl
5Name[ko]=터미놀로지
6Comment=EFL based netctl frontend 5Comment=EFL based netctl frontend
7Comment[da]=Terminalemulator
8Comment[eo]=Terminalimitilo
9Comment[es]=Emulador de terminal
10Comment[gl]=Emulador de terminal
11Comment[it]=Emulatore di terminale
12Comment[pt]=Emulador de terminal
13Comment[ru]=Эмулятор терминала
14Comment[ko]=터미널 에뮬레이터
15Keywords=network;efl;frontend;wifi; 6Keywords=network;efl;frontend;wifi;
16Exec=efl-netctl 7Exec=efl-netctl
17Icon=efl-netctl 8Icon=efl-netctl
diff --git a/data/meson.build b/data/meson.build
index e30ff2b..f6bd679 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -3,7 +3,7 @@ install_data('efl-netctl.desktop',
3 install_mode: 'rw-r--r--' 3 install_mode: 'rw-r--r--'
4) 4)
5 5
6install_data('logo_small.png', 6install_data('efl-netctl.png',
7 install_dir: join_paths(get_option('datadir'), 'icons/hicolor/128x128/apps'), 7 install_dir: join_paths(get_option('datadir'), 'icons/hicolor/128x128/apps'),
8 install_mode : 'rw-r--r--' 8 install_mode : 'rw-r--r--'
9) 9)
diff --git a/src/bin/backend.c b/src/bin/backend.c
index f9a9035..367b7d3 100644
--- a/src/bin/backend.c
+++ b/src/bin/backend.c
@@ -13,7 +13,9 @@ typedef struct {
13static Eina_Hash *profiles; 13static Eina_Hash *profiles;
14static int version = 0; 14static int version = 0;
15static New_Data _cb; 15static New_Data _cb;
16static Ecore_Exe *fetcher_exe, *start_try; 16static Ecore_Exe *fetcher_exe;
17
18static Ecore_Exe *start, *store, *restore, *stop_all, *stop, *restart, *switch_to, *enable, *disable;
17 19
18Eina_Iterator* 20Eina_Iterator*
19connection_profiles_list(void) 21connection_profiles_list(void)
@@ -48,15 +50,15 @@ _connection_details_fetch_handler(void* user, const char* section,
48 50
49 #define MATCH(n) strcmp(name, n) == 0 51 #define MATCH(n) strcmp(name, n) == 0
50 if (MATCH("Description")) { 52 if (MATCH("Description")) {
51 pconfig->desc = strdup(value); 53 pconfig->desc = eina_strdup(value);
52 } else if (MATCH("Interface")) { 54 } else if (MATCH("Interface")) {
53 pconfig->interface = strdup(value); 55 pconfig->interface = eina_strdup(value);
54 } else if (MATCH("Security")) { 56 } else if (MATCH("Security")) {
55 pconfig->security = strdup(value); 57 pconfig->security = eina_strdup(value);
56 } else if (MATCH("IP")) { 58 } else if (MATCH("IP")) {
57 pconfig->ip = strdup(value); 59 pconfig->ip = eina_strdup(value);
58 } else if (MATCH("ESSID")) { 60 } else if (MATCH("ESSID")) {
59 pconfig->essid = strdup(value); 61 pconfig->essid = eina_strdup(value);
60 } else { 62 } else {
61 return 0; /* unknown section/name, error */ 63 return 0; /* unknown section/name, error */
62 } 64 }
@@ -80,21 +82,71 @@ connection_details_fetch(const char *profile, Connection_Config *details)
80 return EINA_TRUE; 82 return EINA_TRUE;
81} 83}
82 84
85static Ecore_Exe*
86_run_command(const char *command)
87{
88 Eina_Strbuf *buf = eina_strbuf_new();
89 eina_strbuf_append(buf, "/usr/bin/netctl ");
90 eina_strbuf_append(buf, command);
91
92 return ecore_exe_pipe_run(eina_strbuf_release(buf), ECORE_EXE_PIPE_READ, eina_binbuf_new());
93}
94
95static Ecore_Exe*
96_run_profile_command(const char *command, const char *profile)
97{
98 Eina_Strbuf *buf = eina_strbuf_new();
99 eina_strbuf_append(buf, "/usr/bin/netctl ");
100 eina_strbuf_append(buf, command);
101 eina_strbuf_append(buf, " ");
102 eina_strbuf_append(buf, profile);
103
104 return ecore_exe_pipe_run(eina_strbuf_release(buf), ECORE_EXE_PIPE_READ, eina_binbuf_new());
105}
106void
107connection_store(void)
108{
109 EINA_SAFETY_ON_FALSE_RETURN(store == NULL);
110
111 store = _run_command("store");
112}
113
114void
115connection_restore(void)
116{
117 EINA_SAFETY_ON_FALSE_RETURN(restore == NULL);
118
119 restore = _run_command("restore");
120}
121
122void
123connection_stop_all(void)
124{
125 EINA_SAFETY_ON_FALSE_RETURN(stop_all == NULL);
126
127 stop_all = _run_command("stop-all");
128}
129
130void
131connection_reload(void)
132{
133 EINA_SAFETY_ON_FALSE_RETURN(fetcher_exe == NULL);
134
135 fetcher_exe = ecore_exe_pipe_run("/usr/bin/netctl list", ECORE_EXE_PIPE_READ, eina_binbuf_new());
136}
137
138
83Eina_Bool 139Eina_Bool
84connection_attempt_connect(const char *conf) 140connection_attempt_connect(const char *conf)
85{ 141{
86 Found_Connection_Profile *profile; 142 Found_Connection_Profile *profile;
87 143
88 EINA_SAFETY_ON_FALSE_RETURN_VAL(start_try == NULL, EINA_FALSE); 144 EINA_SAFETY_ON_FALSE_RETURN_VAL(start == NULL, EINA_FALSE);
89 145
90 profile = eina_hash_find(profiles, conf); 146 profile = eina_hash_find(profiles, conf);
91 EINA_SAFETY_ON_NULL_RETURN_VAL(profile, EINA_FALSE); 147 EINA_SAFETY_ON_NULL_RETURN_VAL(profile, EINA_FALSE);
92 148
93 Eina_Strbuf *buf = eina_strbuf_new(); 149 start = _run_profile_command("start", profile->path);
94 eina_strbuf_append(buf, "/usr/bin/netctl start ");
95 eina_strbuf_append(buf, profile->path);
96
97 start_try = ecore_exe_pipe_run(eina_strbuf_release(buf), ECORE_EXE_PIPE_READ, eina_binbuf_new());
98 150
99 return EINA_TRUE; 151 return EINA_TRUE;
100} 152}
@@ -110,6 +162,71 @@ connection_is_active(const char *conf)
110 return profile->active; 162 return profile->active;
111} 163}
112 164
165void
166connection_stop(const char *conf)
167{
168 Found_Connection_Profile *profile;
169
170 EINA_SAFETY_ON_FALSE_RETURN(stop == NULL);
171
172 profile = eina_hash_find(profiles, conf);
173 EINA_SAFETY_ON_NULL_RETURN(profile);
174
175 stop = _run_profile_command("stop", profile->path);
176}
177
178void
179connection_restart(const char *conf)
180{
181 Found_Connection_Profile *profile;
182
183 EINA_SAFETY_ON_FALSE_RETURN(restart == NULL);
184
185 profile = eina_hash_find(profiles, conf);
186 EINA_SAFETY_ON_NULL_RETURN(profile);
187
188 restart = _run_profile_command("restart", profile->path);
189}
190
191void
192connection_switch_to(const char *conf)
193{
194 Found_Connection_Profile *profile;
195
196 EINA_SAFETY_ON_FALSE_RETURN(switch_to == NULL);
197
198 profile = eina_hash_find(profiles, conf);
199 EINA_SAFETY_ON_NULL_RETURN(profile);
200
201 switch_to = _run_profile_command("switch-to", profile->path);
202}
203
204void
205connection_enable(const char *conf)
206{
207 Found_Connection_Profile *profile;
208
209 EINA_SAFETY_ON_FALSE_RETURN(enable == NULL);
210
211 profile = eina_hash_find(profiles, conf);
212 EINA_SAFETY_ON_NULL_RETURN(profile);
213
214 enable = _run_profile_command("enable", profile->path);
215}
216
217void
218connection_disable(const char *conf)
219{
220 Found_Connection_Profile *profile;
221
222 EINA_SAFETY_ON_FALSE_RETURN(disable == NULL);
223
224 profile = eina_hash_find(profiles, conf);
225 EINA_SAFETY_ON_NULL_RETURN(profile);
226
227 disable = _run_profile_command("disable", profile->path);
228}
229
113static inline Found_Connection_Profile* 230static inline Found_Connection_Profile*
114_get_or_create(const char *wifi_config_file) 231_get_or_create(const char *wifi_config_file)
115{ 232{
@@ -130,13 +247,6 @@ _get_or_create(const char *wifi_config_file)
130 return profiles_data; 247 return profiles_data;
131} 248}
132 249
133
134static void
135_spawn(void)
136{
137 fetcher_exe = ecore_exe_pipe_run("/usr/bin/netctl list", ECORE_EXE_PIPE_READ, eina_binbuf_new());
138}
139
140static void 250static void
141_parse_netctl_list_result(Eina_Binbuf *buf) 251_parse_netctl_list_result(Eina_Binbuf *buf)
142{ 252{
@@ -156,6 +266,8 @@ _parse_netctl_list_result(Eina_Binbuf *buf)
156 266
157 if (lines[i][0] == '*') 267 if (lines[i][0] == '*')
158 profiles_data->active = EINA_TRUE; 268 profiles_data->active = EINA_TRUE;
269 else
270 profiles_data->active = EINA_FALSE;
159 } 271 }
160 free(lines); 272 free(lines);
161 273
@@ -194,13 +306,28 @@ _event_del(void *data, int ecore_type, void *event_info)
194 _parse_netctl_list_result(ecore_exe_data_get(del->exe)); 306 _parse_netctl_list_result(ecore_exe_data_get(del->exe));
195 fetcher_exe = NULL; 307 fetcher_exe = NULL;
196 } 308 }
197 if (del->exe == start_try) 309#define CHECK_FIELD(f) \
198 { 310 if (del->exe == f) \
199 start_try = NULL; 311 { \
200 //refetch everything 312 f = NULL; \
201 _spawn(); 313 connection_reload(); \
202 } 314 }
203 315 CHECK_FIELD(start)
316 CHECK_FIELD(restore)
317 CHECK_FIELD(stop_all)
318 CHECK_FIELD(stop)
319 CHECK_FIELD(restart)
320 CHECK_FIELD(switch_to)
321#undef CHECK_FIELD
322#define CHECK_FIELD(f) \
323 if (del->exe == f) \
324 { \
325 f = NULL; \
326 }
327 CHECK_FIELD(store)
328 CHECK_FIELD(enable)
329 CHECK_FIELD(disable)
330#undef CHECK_FIELD
204 331
205 return ECORE_CALLBACK_PASS_ON; 332 return ECORE_CALLBACK_PASS_ON;
206} 333}
@@ -211,8 +338,18 @@ _event_data(void *data, int ecore_type, void *event_info)
211 Ecore_Exe_Event_Data *d = event_info; 338 Ecore_Exe_Event_Data *d = event_info;
212 Eina_Binbuf *buf; 339 Eina_Binbuf *buf;
213 340
214 if (d->exe != fetcher_exe && d->exe != start_try) return ECORE_CALLBACK_PASS_ON; 341#define CHECK_FIELD(f) (d->exe != f) &&
215 342 if (CHECK_FIELD(fetcher_exe)
343 CHECK_FIELD(start)
344 CHECK_FIELD(store)
345 CHECK_FIELD(restore)
346 CHECK_FIELD(stop_all)
347 CHECK_FIELD(stop)
348 CHECK_FIELD(restart)
349 CHECK_FIELD(switch_to)
350 CHECK_FIELD(enable)
351 CHECK_FIELD(disable) 1)
352 return ECORE_CALLBACK_PASS_ON;
216 buf = ecore_exe_data_get(fetcher_exe); 353 buf = ecore_exe_data_get(fetcher_exe);
217 354
218 eina_binbuf_append_length(buf, d->data, d->size); 355 eina_binbuf_append_length(buf, d->data, d->size);
@@ -228,5 +365,7 @@ connection_backend_init(New_Data cb)
228 365
229 profiles = eina_hash_string_small_new(free); 366 profiles = eina_hash_string_small_new(free);
230 _cb = cb; 367 _cb = cb;
231 _spawn(); 368 connection_reload();
369
370 return EINA_TRUE;
232} 371}
diff --git a/src/bin/backend.h b/src/bin/backend.h
index 65aedf4..01e5487 100644
--- a/src/bin/backend.h
+++ b/src/bin/backend.h
@@ -23,7 +23,17 @@ Eina_Iterator* connection_profiles_list(void);
23Eina_Bool connection_details_fetch(const char *key, Connection_Config *details); 23Eina_Bool connection_details_fetch(const char *key, Connection_Config *details);
24Eina_Bool connection_attempt_connect(const char *key); 24Eina_Bool connection_attempt_connect(const char *key);
25 25
26Eina_Bool connection_is_active(const char *conf);
27Eina_Bool connection_backend_init(New_Data cb); 26Eina_Bool connection_backend_init(New_Data cb);
28 27
28void connection_store(void);
29void connection_restore(void);
30void connection_stop_all(void);
31void connection_reload(void);
32
33Eina_Bool connection_is_active(const char *conf);
34void connection_stop(const char *conf);
35void connection_restart(const char *conf);
36void connection_switch_to(const char *conf);
37void connection_enable(const char *conf);
38void connection_disable(const char *conf);
29#endif 39#endif
diff --git a/src/bin/main.c b/src/bin/main.c
index 1fee475..b0e02b9 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -119,7 +119,7 @@ _connect(void *data, const Efl_Event *ev)
119 119
120 120
121static Efl_Ui_Default_Item* 121static Efl_Ui_Default_Item*
122_create_item(const char *icon, const char *label) 122_create_item(const char *icon, const char *label, Efl_Event_Cb cb, const void *data)
123{ 123{
124 Efl_Ui_Default_Item *item, *img; 124 Efl_Ui_Default_Item *item, *img;
125 125
@@ -130,11 +130,97 @@ _create_item(const char *icon, const char *label)
130 efl_text_set(item, label); 130 efl_text_set(item, label);
131 efl_content_set(item, img); 131 efl_content_set(item, img);
132 efl_gfx_hint_size_min_set(img, EINA_SIZE2D(30, 30)); 132 efl_gfx_hint_size_min_set(img, EINA_SIZE2D(30, 30));
133 efl_event_callback_add(item, EFL_UI_EVENT_SELECTED_CHANGED, cb, data);
133 134
134 return item; 135 return item;
135} 136}
136 137
137static void 138static void
139_profile_stop_cb(void *data, const Efl_Event *ev)
140{
141 const char *active_profile = data;
142
143 if (!efl_ui_selectable_selected_get(ev->object)) return;
144
145 connection_stop(active_profile);
146}
147
148static void
149_profile_restart_cb(void *data, const Efl_Event *ev)
150{
151 const char *active_profile = data;
152
153 if (!efl_ui_selectable_selected_get(ev->object)) return;
154
155 connection_restart(active_profile);
156}
157
158static void
159_profile_switch_to_cb(void *data, const Efl_Event *ev)
160{
161 const char *active_profile = data;
162
163 if (!efl_ui_selectable_selected_get(ev->object)) return;
164
165 connection_switch_to(active_profile);
166}
167
168static void
169_profile_enable_cb(void *data, const Efl_Event *ev)
170{
171 const char *active_profile = data;
172
173 if (!efl_ui_selectable_selected_get(ev->object)) return;
174
175 connection_enable(active_profile);
176}
177
178static void
179_profile_disable_cb(void *data, const Efl_Event *ev)
180{
181 const char *active_profile = data;
182
183 if (!efl_ui_selectable_selected_get(ev->object)) return;
184
185 connection_disable(active_profile);
186}
187
188static void
189_reload_cb(void *data, const Efl_Event *ev)
190{
191 if (!efl_ui_selectable_selected_get(ev->object)) return;
192
193 connection_reload();
194 _wait_mode();
195}
196
197static void
198_stop_all_cb(void *data, const Efl_Event *ev)
199{
200 if (!efl_ui_selectable_selected_get(ev->object)) return;
201
202 connection_stop_all();
203 _wait_mode();
204}
205
206static void
207_store_cb(void *data, const Efl_Event *ev)
208{
209 if (!efl_ui_selectable_selected_get(ev->object)) return;
210
211 connection_store();
212}
213
214static void
215_restore_cb(void *data, const Efl_Event *ev)
216{
217 if (!efl_ui_selectable_selected_get(ev->object)) return;
218
219 connection_restore();
220 _wait_mode();
221}
222
223static void
138_selection_changed_cb(void *data, const Efl_Event *ev) 224_selection_changed_cb(void *data, const Efl_Event *ev)
139{ 225{
140 Efl_Ui_Table *table; 226 Efl_Ui_Table *table;
@@ -189,11 +275,11 @@ _selection_changed_cb(void *data, const Efl_Event *ev)
189 efl_gfx_hint_weight_set(bar, 1.0, 0.0); 275 efl_gfx_hint_weight_set(bar, 1.0, 0.0);
190 efl_gfx_hint_align_set(connect, 1.0, 0.0); 276 efl_gfx_hint_align_set(connect, 1.0, 0.0);
191 efl_pack_end(overall_box, bar); 277 efl_pack_end(overall_box, bar);
192 efl_pack_end(bar, _create_item("media-playback-stop", "Stop")); 278 efl_pack_end(bar, _create_item("media-playback-stop", "Stop", _profile_stop_cb, active_profile));
193 efl_pack_end(bar, _create_item("view-refresh", "Restart")); 279 efl_pack_end(bar, _create_item("view-refresh", "Restart", _profile_restart_cb, active_profile));
194 efl_pack_end(bar, _create_item("network-wireless", "Switch to")); 280 efl_pack_end(bar, _create_item("network-wireless", "Switch to", _profile_switch_to_cb, active_profile));
195 efl_pack_end(bar, _create_item("const char *icon", "Enable")); 281 efl_pack_end(bar, _create_item("const char *icon", "Enable", _profile_enable_cb, active_profile));
196 efl_pack_end(bar, _create_item("const char *icon", "Disable")); 282 efl_pack_end(bar, _create_item("const char *icon", "Disable", _profile_disable_cb, active_profile));
197 283
198 connection_details_fetch(active_profile, &conf); 284 connection_details_fetch(active_profile, &conf);
199 285
@@ -243,10 +329,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
243 329
244 Eo *tab_bar = efl_add(EFL_UI_TAB_BAR_CLASS, win); 330 Eo *tab_bar = efl_add(EFL_UI_TAB_BAR_CLASS, win);
245 efl_gfx_hint_weight_set(tab_bar, 1.0, 0.0); 331 efl_gfx_hint_weight_set(tab_bar, 1.0, 0.0);
246 efl_pack_end(tab_bar, _create_item("view-refresh", "Reload")); 332 efl_pack_end(tab_bar, _create_item("view-refresh", "Reload", _reload_cb, NULL));
247 efl_pack_end(tab_bar, _create_item("process-stop", "Stop all")); 333 efl_pack_end(tab_bar, _create_item("process-stop", "Stop all", _stop_all_cb, NULL));
248 efl_pack_end(tab_bar, _create_item("document-save", "Store")); 334 efl_pack_end(tab_bar, _create_item("document-save", "Store", _store_cb, NULL));
249 efl_pack_end(tab_bar, _create_item("document-open", "Restore")); 335 efl_pack_end(tab_bar, _create_item("document-open", "Restore", _restore_cb, NULL));
250 efl_pack_end(box, tab_bar); 336 efl_pack_end(box, tab_bar);
251 337
252 container = efl_add(EFL_UI_LIST_CLASS, win, 338 container = efl_add(EFL_UI_LIST_CLASS, win,