summaryrefslogtreecommitdiff
path: root/src/bin/playbacks_view.c
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2014-08-07 18:52:55 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2014-08-14 23:33:18 -0300
commitf84820c5dcecf939b3f1e3bf1f8de6dd480e4fbc (patch)
treef60933757ef7dfb19f6212051627ca8f9e20376a /src/bin/playbacks_view.c
parent70f9dcb95db647eda4b844936cbb8c446f51b683 (diff)
epulse: playback's view ported to emix
Diffstat (limited to '')
-rw-r--r--src/bin/playbacks_view.c241
1 files changed, 76 insertions, 165 deletions
diff --git a/src/bin/playbacks_view.c b/src/bin/playbacks_view.c
index c245b51..5ac0a6c 100644
--- a/src/bin/playbacks_view.c
+++ b/src/bin/playbacks_view.c
@@ -1,14 +1,9 @@
1#include "playbacks_view.h" 1#include "playbacks_view.h"
2 2
3#include "epulse.h" 3#include <emix.h>
4 4
5#define PLAYBACKS_KEY "playbacks.key" 5#define PLAYBACKS_KEY "playbacks.key"
6 6
7struct Sink
8{
9 int index;
10 const char *name;
11};
12 7
13struct Playbacks_View 8struct Playbacks_View
14{ 9{
@@ -16,47 +11,19 @@ struct Playbacks_View
16 Evas_Object *genlist; 11 Evas_Object *genlist;
17 Elm_Genlist_Item_Class *itc; 12 Elm_Genlist_Item_Class *itc;
18 13
19 Eina_List *inputs;
20 Eina_List *sinks;
21
22 Ecore_Event_Handler *disconnected; 14 Ecore_Event_Handler *disconnected;
23 Ecore_Event_Handler *sink_input_added; 15 Ecore_Event_Handler *sink_input_added;
24 Ecore_Event_Handler *sink_input_changed; 16 Ecore_Event_Handler *sink_input_changed;
25 Ecore_Event_Handler *sink_input_removed; 17 Ecore_Event_Handler *sink_input_removed;
26
27 Ecore_Event_Handler *sink_added; 18 Ecore_Event_Handler *sink_added;
28 Ecore_Event_Handler *sink_removed; 19 Ecore_Event_Handler *sink_removed;
29}; 20};
30 21
31struct Sink_Input
32{
33 struct Playbacks_View *pv;
34
35 int index;
36 int sink_index;
37 pa_cvolume volume;
38 const char *name;
39 const char *icon;
40 Eina_Bool mute;
41
42 Elm_Object_Item *item;
43};
44
45 static Eina_Bool 22 static Eina_Bool
46_disconnected_cb(void *data, int type EINA_UNUSED, void *info EINA_UNUSED) 23_disconnected_cb(void *data, int type EINA_UNUSED, void *info EINA_UNUSED)
47{ 24{
48 struct Playbacks_View *pv = data; 25 struct Playbacks_View *pv = data;
49 struct Sink_Input *si; 26 elm_genlist_clear(pv->genlist);
50 struct Sink *sink;
51
52 EINA_LIST_FREE(pv->inputs, si)
53 elm_object_item_del(si->item);
54
55 EINA_LIST_FREE(pv->sinks, sink)
56 {
57 eina_stringshare_del(sink->name);
58 free(sink);
59 }
60 27
61 return ECORE_CALLBACK_PASS_ON; 28 return ECORE_CALLBACK_PASS_ON;
62} 29}
@@ -66,21 +33,10 @@ _sink_input_add_cb(void *data, int type EINA_UNUSED,
66 void *info) 33 void *info)
67{ 34{
68 struct Playbacks_View *pv = data; 35 struct Playbacks_View *pv = data;
69 Epulse_Event_Sink_Input *ev = info; 36 Emix_Sink_Input *input = info;
70 struct Sink_Input *input = calloc(1, sizeof(struct Sink_Input)); 37
71 EINA_SAFETY_ON_NULL_RETURN_VAL(input, ECORE_CALLBACK_PASS_ON); 38 elm_genlist_item_append(pv->genlist, pv->itc, input, NULL,
72 39 ELM_GENLIST_ITEM_NONE, NULL, pv);
73 input->name = eina_stringshare_add(ev->base.name);
74 input->icon = eina_stringshare_add(ev->icon);
75 input->index = ev->base.index;
76 input->sink_index = ev->sink;
77 input->volume = ev->base.volume;
78 input->mute = ev->base.mute;
79 input->pv = pv;
80
81 pv->inputs = eina_list_append(pv->inputs, input);
82 input->item = elm_genlist_item_append(pv->genlist, pv->itc, input, NULL,
83 ELM_GENLIST_ITEM_NONE, NULL, pv);
84 40
85 return ECORE_CALLBACK_DONE; 41 return ECORE_CALLBACK_DONE;
86} 42}
@@ -90,21 +46,18 @@ _sink_input_removed_cb(void *data, int type EINA_UNUSED,
90 void *info) 46 void *info)
91{ 47{
92 struct Playbacks_View *pv = data; 48 struct Playbacks_View *pv = data;
93 Epulse_Event_Sink_Input *ev = info; 49 Emix_Sink_Input *ev = info;
94 Eina_List *l, *ll; 50 Elm_Object_Item *item = elm_genlist_first_item_get(pv->genlist);
95 struct Sink_Input *input; 51 if (ev == elm_object_item_data_get(item))
52 elm_object_item_del(item);
96 53
97 EINA_LIST_FOREACH_SAFE(pv->inputs, l, ll, input) 54 while ((item = elm_genlist_item_next_get(item)))
98 { 55 {
99 if (input->index == ev->base.index) 56 if (ev == elm_object_item_data_get(item))
100 { 57 elm_object_item_del(item);
101 pv->inputs = eina_list_remove_list(pv->inputs, l);
102 elm_object_item_del(input->item);
103 break;
104 }
105 } 58 }
106 59
107 return ECORE_CALLBACK_DONE; 60 return ECORE_CALLBACK_PASS_ON;
108} 61}
109 62
110static Eina_Bool 63static Eina_Bool
@@ -112,70 +65,42 @@ _sink_input_changed_cb(void *data, int type EINA_UNUSED,
112 void *info) 65 void *info)
113{ 66{
114 struct Playbacks_View *pv = data; 67 struct Playbacks_View *pv = data;
115 Epulse_Event_Sink_Input *ev = info; 68 Emix_Sink_Input *ev = info;
116 Eina_List *l; 69 Elm_Object_Item *item = elm_genlist_first_item_get(pv->genlist);
117 struct Sink_Input *input; 70 Evas_Object *it;
118 Evas_Object *item = NULL; 71
72 while (item)
73 {
74 if (ev == elm_object_item_data_get(item))
75 {
76 it = elm_object_item_part_content_get(item, "item");
77 if (it)
78 elm_slider_value_set(it, ev->volume.volumes[0]);
79
80 it = elm_object_item_part_content_get(item, "mute");
81 if (it)
82 elm_check_state_set(it, ev->mute);
83 break;
84 }
85 item = elm_genlist_item_next_get(item);
86 }
119 87
120 EINA_LIST_FOREACH(pv->inputs, l, input) 88 return ECORE_CALLBACK_PASS_ON;
121 {
122 if (input->index == ev->base.index)
123 {
124 pa_volume_t vol = pa_cvolume_avg(&ev->base.volume);
125
126 item = elm_object_item_part_content_get(input->item, "item");
127 input->volume = ev->base.volume;
128 if (item)
129 elm_slider_value_set(item, PA_VOLUME_TO_INT(vol));
130
131 item = elm_object_item_part_content_get(input->item, "mute");
132 input->mute = ev->base.mute;
133 if (item)
134 {
135 elm_check_state_set(item, input->mute);
136 }
137 break;
138 }
139 }
140
141 return ECORE_CALLBACK_DONE;
142} 89}
143 90
144static Eina_Bool 91static Eina_Bool
145_sink_add_cb(void *data, int type EINA_UNUSED, 92_sink_added_cb(void *data, int type EINA_UNUSED, void *info EINA_UNUSED)
146 void *info)
147{ 93{
148 struct Playbacks_View *pv = data; 94 struct Playbacks_View *pv = data;
149 Epulse_Event_Sink *ev = info;
150 struct Sink *sink = calloc(1, sizeof(struct Sink));
151 EINA_SAFETY_ON_NULL_RETURN_VAL(sink, ECORE_CALLBACK_PASS_ON);
152
153 sink->name = eina_stringshare_add(ev->base.name);
154 sink->index = ev->base.index;
155
156 pv->sinks = eina_list_append(pv->sinks, sink);
157 elm_genlist_realized_items_update(pv->genlist); 95 elm_genlist_realized_items_update(pv->genlist);
158 96
159 return ECORE_CALLBACK_PASS_ON; 97 return ECORE_CALLBACK_PASS_ON;
160} 98}
161 99
162static Eina_Bool 100static Eina_Bool
163_sink_removed_cb(void *data, int type EINA_UNUSED, 101_sink_removed_cb(void *data, int type EINA_UNUSED, void *info EINA_UNUSED)
164 void *info)
165{ 102{
166 struct Playbacks_View *pv = data; 103 struct Playbacks_View *pv = data;
167 Epulse_Event_Sink *ev = info;
168 Eina_List *l, *ll;
169 struct Sink *sink;
170
171 EINA_LIST_FOREACH_SAFE(pv->sinks, l, ll, sink)
172 {
173 if (sink->index == ev->base.index)
174 {
175 pv->sinks = eina_list_remove_list(pv->sinks, l);
176 break;
177 }
178 }
179 104
180 elm_genlist_realized_items_update(pv->genlist); 105 elm_genlist_realized_items_update(pv->genlist);
181 return ECORE_CALLBACK_PASS_ON; 106 return ECORE_CALLBACK_PASS_ON;
@@ -188,14 +113,6 @@ _del_cb(void *data,
188 void *event_info EINA_UNUSED) 113 void *event_info EINA_UNUSED)
189{ 114{
190 struct Playbacks_View *pv = data; 115 struct Playbacks_View *pv = data;
191 struct Sink *sink;
192 eina_list_free(pv->inputs);
193
194 EINA_LIST_FREE(pv->sinks, sink)
195 {
196 eina_stringshare_del(sink->name);
197 free(sink);
198 }
199 116
200#define ECORE_EVENT_HANDLER_DEL(_handle) \ 117#define ECORE_EVENT_HANDLER_DEL(_handle) \
201 if (pv->_handle) \ 118 if (pv->_handle) \
@@ -208,69 +125,57 @@ _del_cb(void *data,
208 ECORE_EVENT_HANDLER_DEL(sink_input_added) 125 ECORE_EVENT_HANDLER_DEL(sink_input_added)
209 ECORE_EVENT_HANDLER_DEL(sink_input_changed) 126 ECORE_EVENT_HANDLER_DEL(sink_input_changed)
210 ECORE_EVENT_HANDLER_DEL(sink_input_removed) 127 ECORE_EVENT_HANDLER_DEL(sink_input_removed)
211 ECORE_EVENT_HANDLER_DEL(sink_added)
212 ECORE_EVENT_HANDLER_DEL(sink_removed) 128 ECORE_EVENT_HANDLER_DEL(sink_removed)
129 ECORE_EVENT_HANDLER_DEL(sink_added)
213#undef ECORE_EVENT_HANDLER_DEL 130#undef ECORE_EVENT_HANDLER_DEL
214} 131}
215 132
216static char * 133static char *
217_item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part) 134_item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
218{ 135{
219 struct Sink_Input *input = data; 136 Emix_Sink_Input *input = data;
220 137
221 if (!strcmp(part, "name")) 138 if (!strcmp(part, "name"))
222 { 139 return strdup(input->name);
223 return strdup(input->name);
224 }
225 140
226 return NULL; 141 return NULL;
227} 142}
228 143
229static void 144static void
230_item_del(void *data, Evas_Object *obj EINA_UNUSED)
231{
232 struct Sink_Input *input = data;
233
234 eina_stringshare_del(input->name);
235 eina_stringshare_del(input->icon);
236 free(input);
237}
238
239static void
240_volume_changed_cb(void *data, Evas_Object *o, 145_volume_changed_cb(void *data, Evas_Object *o,
241 void *event_info EINA_UNUSED) 146 void *event_info EINA_UNUSED)
242{ 147{
243 struct Sink_Input *input = data; 148 Emix_Sink_Input *input = data;
244 double val = elm_slider_value_get(o); 149 double val = elm_slider_value_get(o);
245 pa_volume_t v = INT_TO_PA_VOLUME(val); 150 Emix_Volume volume;
151 unsigned int i;
246 152
247 pa_cvolume_set(&input->volume, input->volume.channels, v); 153 volume.channel_count = input->volume.channel_count;
154 volume.volumes = calloc(input->volume.channel_count, sizeof(int));
155 for (i = 0; i < volume.channel_count; i++)
156 volume.volumes[i] = val;
248 157
249 epulse_sink_input_volume_set(input->index, input->volume); 158 emix_sink_input_volume_set(input, volume);
159 free(volume.volumes);
250} 160}
251 161
252static void 162static void
253_mute_changed_cb(void *data, Evas_Object *o EINA_UNUSED, 163_mute_changed_cb(void *data, Evas_Object *o EINA_UNUSED,
254 void *event_info EINA_UNUSED) 164 void *event_info EINA_UNUSED)
255{ 165{
256 struct Sink_Input *input = data; 166 Emix_Sink_Input *input = data;
257 167
258 if (!epulse_sink_input_mute_set(input->index, input->mute)) 168 emix_sink_input_mute_set(input, input->mute);
259 {
260 ERR("Could not mute the input: %d", input->index);
261 input->mute = !input->mute;
262 return;
263 }
264} 169}
265 170
266static void 171static void
267_sink_selected(void *data, Evas_Object *obj, void *event_info) 172_sink_selected(void *data, Evas_Object *obj, void *event_info)
268{ 173{
269 struct Sink_Input *input = data; 174 Emix_Sink_Input *input = data;
270 Elm_Object_Item *item = event_info; 175 Elm_Object_Item *item = event_info;
271 struct Sink *sink = elm_object_item_data_get(item); 176 Emix_Sink *sink = elm_object_item_data_get(item);
272 177
273 epulse_sink_input_move(input->index, sink->index); 178 emix_sink_input_sink_change(input, sink);
274 elm_object_text_set(obj, sink->name); 179 elm_object_text_set(obj, sink->name);
275} 180}
276 181
@@ -278,11 +183,10 @@ static Evas_Object *
278_item_content_get(void *data, Evas_Object *obj, const char *part) 183_item_content_get(void *data, Evas_Object *obj, const char *part)
279{ 184{
280 Evas_Object *item = NULL; 185 Evas_Object *item = NULL;
281 struct Sink_Input *input = data; 186 Emix_Sink_Input *input = data;
282 187
283 if (!strcmp(part, "slider")) 188 if (!strcmp(part, "slider"))
284 { 189 {
285 pa_volume_t vol = pa_cvolume_avg(&input->volume);
286 item = elm_slider_add(obj); 190 item = elm_slider_add(obj);
287 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL); 191 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
288 192
@@ -291,7 +195,7 @@ _item_content_get(void *data, Evas_Object *obj, const char *part)
291 elm_slider_indicator_format_set(item, "%1.0f"); 195 elm_slider_indicator_format_set(item, "%1.0f");
292 elm_slider_span_size_set(item, 120); 196 elm_slider_span_size_set(item, 120);
293 elm_slider_min_max_set(item, 0.0, 100.0); 197 elm_slider_min_max_set(item, 0.0, 100.0);
294 elm_slider_value_set(item, PA_VOLUME_TO_INT(vol)); 198 elm_slider_value_set(item, input->volume.volumes[0]);
295 199
296 evas_object_smart_callback_add(item, "delay,changed", 200 evas_object_smart_callback_add(item, "delay,changed",
297 _volume_changed_cb, input); 201 _volume_changed_cb, input);
@@ -312,28 +216,28 @@ _item_content_get(void *data, Evas_Object *obj, const char *part)
312 } 216 }
313 else if (!strcmp(part, "icon")) 217 else if (!strcmp(part, "icon"))
314 { 218 {
315 EINA_SAFETY_ON_NULL_RETURN_VAL(input->icon, NULL); 219 /*EINA_SAFETY_ON_NULL_RETURN_VAL(input->icon, NULL);*/
316 220
317 item = elm_icon_add(obj); 221 item = elm_icon_add(obj);
318 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL); 222 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
319 223
320 elm_icon_standard_set(item, input->icon); 224 /*elm_icon_standard_set(item, input->icon);*/
321 } 225 }
322 else if (!strcmp(part, "hover")) 226 else if (!strcmp(part, "hover"))
323 { 227 {
324 Eina_List *l; 228 Eina_List *l;
325 struct Sink *sink; 229 Emix_Sink *sink;
326 item = elm_hoversel_add(obj); 230 item = elm_hoversel_add(obj);
327 231
328 EINA_LIST_FOREACH(input->pv->sinks, l, sink) 232 EINA_LIST_FOREACH((Eina_List *)emix_sinks_get(), l, sink)
329 { 233 {
330 if (sink->index == input->sink_index) 234 if (sink == input->sink)
331 elm_object_text_set(item, sink->name); 235 elm_object_text_set(item, sink->name);
332 elm_hoversel_item_add(item, sink->name, NULL, 236 elm_hoversel_item_add(item, sink->name, NULL,
333 ELM_ICON_NONE, NULL, sink); 237 ELM_ICON_NONE, NULL, sink);
334 } 238 }
335 evas_object_smart_callback_add(item, "selected", 239 evas_object_smart_callback_add(item, "selected",
336 _sink_selected, input); 240 _sink_selected, input);
337 } 241 }
338 242
339 return item; 243 return item;
@@ -344,6 +248,8 @@ playbacks_view_add(Evas_Object *parent)
344{ 248{
345 Evas_Object *layout; 249 Evas_Object *layout;
346 struct Playbacks_View *pv; 250 struct Playbacks_View *pv;
251 Emix_Sink_Input *input;
252 Eina_List *l;
347 253
348 pv = calloc(1, sizeof(struct Playbacks_View)); 254 pv = calloc(1, sizeof(struct Playbacks_View));
349 EINA_SAFETY_ON_NULL_RETURN_VAL(pv, NULL); 255 EINA_SAFETY_ON_NULL_RETURN_VAL(pv, NULL);
@@ -356,25 +262,24 @@ playbacks_view_add(Evas_Object *parent)
356 pv->genlist = elm_genlist_add(layout); 262 pv->genlist = elm_genlist_add(layout);
357 EINA_SAFETY_ON_NULL_GOTO(pv->genlist, err_genlist); 263 EINA_SAFETY_ON_NULL_GOTO(pv->genlist, err_genlist);
358 264
359 pv->disconnected = ecore_event_handler_add(DISCONNECTED, 265 pv->disconnected = ecore_event_handler_add(EMIX_DISCONNECTED_EVENT,
360 _disconnected_cb, pv); 266 _disconnected_cb, pv);
361 pv->sink_input_added = ecore_event_handler_add(SINK_INPUT_ADDED, 267 pv->sink_input_added = ecore_event_handler_add(EMIX_SINK_INPUT_ADDED_EVENT,
362 _sink_input_add_cb, pv); 268 _sink_input_add_cb, pv);
363 pv->sink_input_added = ecore_event_handler_add(SINK_INPUT_CHANGED, 269 pv->sink_input_added = ecore_event_handler_add(EMIX_SINK_INPUT_CHANGED_EVENT,
364 _sink_input_changed_cb, pv); 270 _sink_input_changed_cb, pv);
365 pv->sink_input_removed = ecore_event_handler_add(SINK_INPUT_REMOVED, 271 pv->sink_input_removed = ecore_event_handler_add(EMIX_SINK_INPUT_REMOVED_EVENT,
366 _sink_input_removed_cb, pv); 272 _sink_input_removed_cb, pv);
367 pv->sink_added = ecore_event_handler_add(SINK_ADDED, 273 pv->sink_removed = ecore_event_handler_add(EMIX_SINK_REMOVED_EVENT,
368 _sink_add_cb, pv);
369 pv->sink_removed = ecore_event_handler_add(SINK_REMOVED,
370 _sink_removed_cb, pv); 274 _sink_removed_cb, pv);
275 pv->sink_added = ecore_event_handler_add(EMIX_SINK_ADDED_EVENT,
276 _sink_added_cb, pv);
371 277
372 pv->itc = elm_genlist_item_class_new(); 278 pv->itc = elm_genlist_item_class_new();
373 EINA_SAFETY_ON_NULL_GOTO(pv->itc, err_genlist); 279 EINA_SAFETY_ON_NULL_GOTO(pv->itc, err_genlist);
374 pv->itc->item_style = "playbacks"; 280 pv->itc->item_style = "playbacks";
375 pv->itc->func.text_get = _item_text_get; 281 pv->itc->func.text_get = _item_text_get;
376 pv->itc->func.content_get = _item_content_get; 282 pv->itc->func.content_get = _item_content_get;
377 pv->itc->func.del = _item_del;
378 283
379 evas_object_data_set(layout, PLAYBACKS_KEY, pv); 284 evas_object_data_set(layout, PLAYBACKS_KEY, pv);
380 elm_layout_content_set(layout, "list", pv->genlist); 285 elm_layout_content_set(layout, "list", pv->genlist);
@@ -384,6 +289,12 @@ playbacks_view_add(Evas_Object *parent)
384 evas_object_size_hint_align_set(pv->genlist, EVAS_HINT_FILL, 289 evas_object_size_hint_align_set(pv->genlist, EVAS_HINT_FILL,
385 EVAS_HINT_FILL); 290 EVAS_HINT_FILL);
386 291
292 EINA_LIST_FOREACH((Eina_List *)emix_sink_inputs_get(), l, input)
293 {
294 elm_genlist_item_append(pv->genlist, pv->itc, input, NULL,
295 ELM_GENLIST_ITEM_NONE, NULL, pv);
296 }
297
387 return layout; 298 return layout;
388 299
389 err_genlist: 300 err_genlist: