iwd: extract shared state/security label helpers
Both popup.c and gadget.c carried near-identical _state_label/_sec_label
helpers, with the gadget version using bare ints instead of the
Iwd_Security enum. Move to iwd/iwd_labels.{c,h} and use the enum
consistently.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b03d10b164
commit
ad3d752b12
5 changed files with 49 additions and 57 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include "iwd/iwd_manager.h"
|
||||
#include "iwd/iwd_device.h"
|
||||
#include "iwd/iwd_network.h"
|
||||
#include "iwd/iwd_labels.h"
|
||||
#include <e_gadcon.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
|
@ -75,30 +76,6 @@ _icon_name_for_state(Iwd_State s)
|
|||
return "network-wireless";
|
||||
}
|
||||
|
||||
static const char *
|
||||
_state_label(Iwd_State s)
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case IWD_STATE_OFF: return "Wi-Fi disabled";
|
||||
case IWD_STATE_IDLE: return "Disconnected";
|
||||
case IWD_STATE_SCANNING: return "Scanning";
|
||||
case IWD_STATE_CONNECTING: return "Connecting";
|
||||
case IWD_STATE_CONNECTED: return "Connected";
|
||||
case IWD_STATE_ERROR: return "Error";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static const char *
|
||||
_sec_label(int s)
|
||||
{
|
||||
/* Iwd_Security values, kept in sync with iwd_network.h. */
|
||||
switch (s) { case 0: return "open"; case 1: return "WPA";
|
||||
case 2: return "802.1X"; case 3: return "WEP"; }
|
||||
return "?";
|
||||
}
|
||||
|
||||
static void
|
||||
_build_tooltip(Instance *inst, Iwd_State s)
|
||||
{
|
||||
|
|
@ -109,13 +86,13 @@ _build_tooltip(Instance *inst, Iwd_State s)
|
|||
if (n)
|
||||
snprintf(buf, sizeof(buf), "Wi-Fi: %s — %s — signal %d/4",
|
||||
n->ssid ? n->ssid : "?",
|
||||
_sec_label(n->security),
|
||||
iwd_security_label(n->security),
|
||||
iwd_network_signal_tier(n));
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "Wi-Fi: connected");
|
||||
}
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "Wi-Fi: %s", _state_label(s));
|
||||
snprintf(buf, sizeof(buf), "Wi-Fi: %s", iwd_state_label(s));
|
||||
elm_object_tooltip_text_set(inst->o_base, buf);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "iwd/iwd_device.h"
|
||||
#include "iwd/iwd_network.h"
|
||||
#include "iwd/iwd_agent.h"
|
||||
#include "iwd/iwd_labels.h"
|
||||
#include "ui/wifi_auth.h"
|
||||
#include "ui/wifi_hidden.h"
|
||||
#include <e_gadcon_popup.h>
|
||||
|
|
@ -66,33 +67,6 @@ _hidden_pending_timeout(void *data EINA_UNUSED)
|
|||
|
||||
/* ----- helpers --------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
_state_label(Iwd_State s)
|
||||
{
|
||||
switch (s) {
|
||||
case IWD_STATE_OFF: return "Wi-Fi disabled";
|
||||
case IWD_STATE_IDLE: return "Disconnected";
|
||||
case IWD_STATE_SCANNING: return "Scanning…";
|
||||
case IWD_STATE_CONNECTING: return "Connecting…";
|
||||
case IWD_STATE_CONNECTED: return "Connected";
|
||||
case IWD_STATE_ERROR: return "Error";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static const char *
|
||||
_sec_label(Iwd_Security s)
|
||||
{
|
||||
switch (s) {
|
||||
case IWD_SEC_OPEN: return "open";
|
||||
case IWD_SEC_PSK: return "WPA";
|
||||
case IWD_SEC_8021X: return "802.1X";
|
||||
case IWD_SEC_WEP: return "WEP";
|
||||
case IWD_SEC_UNKNOWN: return "?";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static int
|
||||
_net_cmp(const void *a, const void *b)
|
||||
{
|
||||
|
|
@ -255,7 +229,7 @@ _rebuild_list(Popup *p)
|
|||
_signal_bars(iwd_network_signal_tier(n)),
|
||||
n->known_path ? "★ " : " ",
|
||||
raw_ssid,
|
||||
_sec_label(n->security),
|
||||
iwd_security_label(n->security),
|
||||
n->connected ? " ✔" : "");
|
||||
elm_object_text_set(btn, label);
|
||||
evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0);
|
||||
|
|
@ -291,11 +265,11 @@ _refresh(Popup *p)
|
|||
if (err)
|
||||
{
|
||||
char buf[320];
|
||||
snprintf(buf, sizeof(buf), "%s — %s", _state_label(s), err);
|
||||
snprintf(buf, sizeof(buf), "%s — %s", iwd_state_label(s), err);
|
||||
elm_object_text_set(p->status_lbl, buf);
|
||||
}
|
||||
else
|
||||
elm_object_text_set(p->status_lbl, _state_label(s));
|
||||
elm_object_text_set(p->status_lbl, iwd_state_label(s));
|
||||
}
|
||||
if (p->btn_toggle)
|
||||
elm_object_text_set(p->btn_toggle, s == IWD_STATE_OFF ? "Enable" : "Disable");
|
||||
|
|
@ -444,7 +418,7 @@ _on_passphrase_request(void *data EINA_UNUSED, Iwd_Agent_Request *req, const cha
|
|||
_pending_req = req;
|
||||
|
||||
const char *ssid = req_ssid ? req_ssid : "network";
|
||||
const char *sec = n ? _sec_label(n->security) : NULL;
|
||||
const char *sec = n ? iwd_security_label(n->security) : NULL;
|
||||
_pending_dialog = wifi_auth_prompt(_popup ? _popup->box : e_comp->elm,
|
||||
ssid, sec, _on_auth_done, NULL);
|
||||
}
|
||||
|
|
|
|||
28
src/iwd/iwd_labels.c
Normal file
28
src/iwd/iwd_labels.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include "iwd_labels.h"
|
||||
|
||||
const char *
|
||||
iwd_state_label(Iwd_State s)
|
||||
{
|
||||
switch (s) {
|
||||
case IWD_STATE_OFF: return "Wi-Fi disabled";
|
||||
case IWD_STATE_IDLE: return "Disconnected";
|
||||
case IWD_STATE_SCANNING: return "Scanning…";
|
||||
case IWD_STATE_CONNECTING: return "Connecting…";
|
||||
case IWD_STATE_CONNECTED: return "Connected";
|
||||
case IWD_STATE_ERROR: return "Error";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
const char *
|
||||
iwd_security_label(Iwd_Security s)
|
||||
{
|
||||
switch (s) {
|
||||
case IWD_SEC_OPEN: return "open";
|
||||
case IWD_SEC_PSK: return "WPA";
|
||||
case IWD_SEC_8021X: return "802.1X";
|
||||
case IWD_SEC_WEP: return "WEP";
|
||||
case IWD_SEC_UNKNOWN: return "?";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
12
src/iwd/iwd_labels.h
Normal file
12
src/iwd/iwd_labels.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef IWD_LABELS_H
|
||||
#define IWD_LABELS_H
|
||||
|
||||
#include "iwd_manager.h"
|
||||
#include "iwd_network.h"
|
||||
|
||||
/* Short, user-facing labels for state and security enums. The pointers
|
||||
* returned are static literals — do not free. */
|
||||
const char *iwd_state_label (Iwd_State s);
|
||||
const char *iwd_security_label(Iwd_Security s);
|
||||
|
||||
#endif
|
||||
|
|
@ -10,6 +10,7 @@ e_iwd_sources = [
|
|||
'iwd/iwd_manager.c',
|
||||
'iwd/iwd_device.c',
|
||||
'iwd/iwd_network.c',
|
||||
'iwd/iwd_labels.c',
|
||||
'ui/wifi_list.c',
|
||||
'ui/wifi_auth.c',
|
||||
'ui/wifi_hidden.c',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue