summaryrefslogtreecommitdiff
path: root/src/module/e_mod_config.c
blob: f723e89336b2a727c654cb2a2248422684aced83 (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "e.h"
#include "e_mod_config.h"
#include "e_mod_main.h"

#include <emix.h>

typedef struct _Emix_Config
{
   const char *backend;
   int notify;
   int mute;
   int meter;

   emix_config_backend_changed cb;
   emix_config_meter_changed meter_cb;
   const void *userdata;
} Emix_Config;

struct _E_Config_Dialog_Data
{
   Emix_Config config;
   Evas_Object *list;
};

static E_Config_DD *cd;
static Emix_Config *_config;

static E_Config_DD*
_emix_config_dd_new(void)
{
   E_Config_DD *result = E_CONFIG_DD_NEW("Emix_Config", Emix_Config);

   E_CONFIG_VAL(result, Emix_Config, backend, STR);
   E_CONFIG_VAL(result, Emix_Config, notify, INT);
   E_CONFIG_VAL(result, Emix_Config, mute, INT);
   E_CONFIG_VAL(result, Emix_Config, meter, INT);

   return result;
}

const char *
emix_config_backend_get(void)
{
   return _config->backend;
}

void
emix_config_backend_set(const char *backend)
{
   eina_stringshare_replace(&_config->backend, backend);
   e_config_domain_save("module.emix", cd, _config);
}

Eina_Bool
emix_config_notify_get(void)
{
   return _config->notify;
}

Eina_Bool
emix_config_desklock_mute_get(void)
{
   return _config->mute;
}

Eina_Bool
emix_config_meter_get(void)
{
   return _config->meter;
}

static void
_config_set(Emix_Config *config)
{
   if ((config->backend) && (_config->backend != config->backend))
     eina_stringshare_replace(&_config->backend, config->backend);

   _config->notify = config->notify;
   _config->mute = config->mute;
   _config->meter = config->meter;

   DBG("SAVING CONFIG %s %d %d %d", _config->backend, config->notify,
       config->mute, config->meter);
   e_config_domain_save("module.emix", cd, config);
}

void
emix_config_init(emix_config_backend_changed cb,
                 emix_config_meter_changed meter_cb, const void *userdata)
{
   const Eina_List *l;

   EINA_SAFETY_ON_FALSE_RETURN(emix_init());
   cd = _emix_config_dd_new();
   _config = e_config_domain_load("module.emix", cd);
   if (!_config)
     {
        _config = E_NEW(Emix_Config, 1);
        l = emix_backends_available();
        if (l)
          _config->backend = eina_stringshare_add(l->data);
     }

   _config->cb = cb;
   _config->meter_cb = meter_cb;
   _config->userdata = userdata;
   DBG("Config loaded, backend to use: %s", _config->backend);
}

void
emix_config_shutdown(void)
{
   E_CONFIG_DD_FREE(cd);
   if (_config->backend)
     eina_stringshare_del(_config->backend);
   free(_config);
   emix_shutdown();
}

static void*
_create_data(E_Config_Dialog *cfg EINA_UNUSED)
{
   E_Config_Dialog_Data *d;

   d = E_NEW(E_Config_Dialog_Data, 1);
   d->config.backend = eina_stringshare_add(_config->backend);
   d->config.notify = _config->notify;
   d->config.mute = _config->mute;
   d->config.meter = _config->meter;

   return d;
}

static void
_free_data(E_Config_Dialog *c EINA_UNUSED, E_Config_Dialog_Data *cf)
{
   eina_stringshare_del(cf->config.backend);
   free(cf);
}

static Evas_Object *
_basic_create_widgets(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas,
                      E_Config_Dialog_Data *cfdata)
{
   Evas_Object *o, *l;
   const Eina_List *node;
   char *name;
   int i = 0;

   o = e_widget_list_add(evas, 0, 0);

   l = e_widget_check_add(evas, "Notify on volume change", &cfdata->config.notify);
   e_widget_list_object_append(o, l, 0, 0, 0);

   l = e_widget_check_add(evas, "Mute on lock", &cfdata->config.mute);
   e_widget_list_object_append(o, l, 0, 0, 0);

   l = e_widget_check_add(evas, "Enable volume meter", &cfdata->config.meter);
   e_widget_list_object_append(o, l, 0, 0, 0);

   l = e_widget_label_add(evas, "Backend to use:");
   e_widget_list_object_append(o, l, 0, 0, 0);

   cfdata->list = l = e_widget_ilist_add(evas, 0, 0, NULL);
   e_widget_ilist_multi_select_set(l, EINA_FALSE);
   e_widget_size_min_set(l, 100, 100);
   EINA_LIST_FOREACH(emix_backends_available(), node, name)
     {
        e_widget_ilist_append(l, NULL, name, NULL, NULL, NULL);
        i ++;
        if (_config->backend && !strcmp(_config->backend, name))
          e_widget_ilist_selected_set(l, i);
     }
   e_widget_ilist_go(l);
   e_widget_ilist_thaw(l);
   e_widget_list_object_append(o, l, 1, 1, 0);

   return o;
}

static int
_basic_apply_data(E_Config_Dialog *cfd EINA_UNUSED,
                  E_Config_Dialog_Data *cfdata)
{
   char *new_backend = eina_list_nth(
                            emix_backends_available(),
                            e_widget_ilist_selected_get(cfdata->list));

   eina_stringshare_replace(&cfdata->config.backend, new_backend);

   _config_set(&cfdata->config);
   if (_config->cb)
      _config->cb(new_backend, (void *)_config->userdata);
   if (_config->meter_cb)
      _config->meter_cb(!!_config->meter, (void *)_config->userdata);
   return 1;
}

E_Config_Dialog*
emix_config_popup_new(E_Comp *comp, const char *p EINA_UNUSED)
{
   E_Config_Dialog *cfd;
   E_Config_Dialog_View *v;

   if (e_config_dialog_find("E", "windows/emix"))
      return NULL;

   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;

   cfd = e_config_dialog_new(comp,
                             "Emix Configuration",
                             "E", "windows/emix",
                             NULL,
                             0, v, NULL);
   return cfd;
}