summaryrefslogtreecommitdiff
path: root/src/e_mod_config.c
blob: 73790c9b7b81e814ce2451e2de3fbf3dfb99e705 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <e.h>
#include "e_mod_main.h"

struct _E_Config_Dialog_Data {
    const char *device;
    Eina_List  *devs;
    int        dev_num;
    double     poll_time;
    int        always_text;
    int        show_percent;
};

static void *_create_data(E_Config_Dialog *cfd);
static void _free_data   (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static void _fill_data   (Config_Item     *ci,  E_Config_Dialog_Data *cfdata);

static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
static int          _basic_apply_data    (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);

static void _wlan_config_get_devices(Eina_List *devs);

void _config_wlan_module(Config_Item *ci) {
    E_Config_Dialog      *cfd = NULL;
    E_Config_Dialog_View *v   = NULL;

    char buf[PATH_MAX];

    if (e_config_dialog_find("Wlan", "_e_modules_wlan_config_dialog"))
        return;

    v = E_NEW(E_Config_Dialog_View, 1);
    v->create_cfdata        = _create_data;
    v->free_cfdata          = _free_data;
    v->basic.apply_cfdata   = _basic_apply_data;
    v->basic.create_widgets = _basic_create_widgets;

    snprintf(buf, sizeof(buf), "%s/e-module-wlan.edj", wlan_config->mod_dir);
    cfd = e_config_dialog_new(e_util_comp_current_get(), D_("Wlan Settings"),
        "Wlan", "_e_modules_wlan_config_dialog", buf, 0, v, ci);
    wlan_config->config_dialog = cfd;
}

static void _fill_data(Config_Item *ci, E_Config_Dialog_Data *cfdata) {
    Eina_List *l;
    char      *tmp;
    int        i = 0;

    cfdata->poll_time    = ci->poll_time;
    cfdata->always_text  = ci->always_text;
    cfdata->show_percent = ci->show_percent;

    cfdata->device = NULL;
    if (ci->device) cfdata->device = eina_stringshare_add(ci->device);

    if (!cfdata->device) return;

    _wlan_config_get_devices(cfdata->devs);
    if (!cfdata->devs) return;

    EINA_LIST_FOREACH(cfdata->devs, l, tmp) {
        if (!strcmp(cfdata->device, tmp)) {
            cfdata->dev_num = i;
            break;
        }
        i++;
    }
}

static void *_create_data(E_Config_Dialog *cfd) {
    E_Config_Dialog_Data *cfdata = E_NEW(E_Config_Dialog_Data, 1);
    Config_Item          *ci     = cfd->data;
    _fill_data(ci, cfdata);
    return cfdata;
}

static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) {
    const char *data;

    if (!wlan_config) return;
    wlan_config->config_dialog = NULL;
    eina_stringshare_del(cfdata->device);

    if (cfdata->devs) {
        EINA_LIST_FREE(cfdata->devs, data) eina_stringshare_del(data);
        eina_list_free(cfdata->devs);
    }

    E_FREE(cfdata);
}

static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas,
E_Config_Dialog_Data *cfdata) {
    Evas_Object   *o, *of, *ob;
    E_Radio_Group *rg;
    Eina_List    *l;
    char         *tmp;
    int           i = 0;

    o  = e_widget_list_add(evas, 0, 0);
    of = e_widget_framelist_add(evas, D_("General Settings"), 0);

    rg = e_widget_radio_group_new(&(cfdata->always_text));
    ob = e_widget_radio_add(evas, D_("Always Show Text"), 1, rg);
    e_widget_framelist_object_append(of, ob);

    ob = e_widget_radio_add(evas, D_("Show Text On Mouse Over"), 0, rg);
    e_widget_framelist_object_append(of, ob);

    ob = e_widget_check_add(evas, D_("Show Text As Percent"),
        &(cfdata->show_percent));
    e_widget_framelist_object_append(of, ob);

    ob = e_widget_label_add(evas, D_("Check Interval:"));
    e_widget_framelist_object_append(of, ob);

    ob = e_widget_slider_add(evas, 1, 0, D_("%1.0f seconds"),
        1.0, 60.0, 1.0, 0, &(cfdata->poll_time), NULL, 150);
    e_widget_framelist_object_append(of, ob);

    e_widget_list_object_append(o, of, 1, 1, 0.5);

    if (cfdata->devs) {
        of = e_widget_framelist_add(evas, D_("Device Settings"), 0);
        rg = e_widget_radio_group_new(&(cfdata->dev_num));
        EINA_LIST_FOREACH(cfdata->devs, l, tmp) {
            ob = e_widget_radio_add(evas, tmp, i, rg);
            e_widget_framelist_object_append(of, ob);
            i++;
        }
        e_widget_list_object_append (o, of, 1, 1, 0.5);
    }

    return o;
}

static int _basic_apply_data(E_Config_Dialog *cfd,
E_Config_Dialog_Data *cfdata) {
    Config_Item *ci;
    char        *tmp;

    ci               = cfd->data;
    ci->poll_time    = cfdata->poll_time;

    ci->always_text  = cfdata->always_text;
    ci->show_percent = cfdata->show_percent;

    if (cfdata->devs) {
        cfdata->devs = eina_list_nth_list(cfdata->devs, cfdata->dev_num);
        tmp = eina_list_data_get(cfdata->devs);
        if (tmp) {
            if (ci->device) eina_stringshare_del(ci->device);
            ci->device = eina_stringshare_add(tmp);
            E_FREE(tmp);
        }
    }

    e_config_save_queue();
    _wlan_config_updated(ci);

    return 1;
}

static void _wlan_config_get_devices(Eina_List *devs) {
    FILE         *stat;
    char          dev[64];
    char          buf[256];
    unsigned long dummy;
    float         dummy_float;

    if (!(stat = fopen("/proc/net/wireless", "r"))) return;

    while (fgets(buf, 256, stat)) {
        int i;
        for (i = 0; buf[i]; ++i)
            if (buf[i] == ':') buf[i] = ' ';
        if (sscanf (buf, "%s %lu %f %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu "
            "%lu %lu %lu %lu\n", dev, &dummy, &dummy_float, &dummy,
            &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy,
            &dummy, &dummy, &dummy, &dummy, &dummy, &dummy) < 4) continue;
        devs = eina_list_append(devs, eina_stringshare_add(dev));
    }
    fclose(stat);
}