summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2014-08-08 00:07:53 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2014-08-14 23:33:18 -0300
commit7b5977a53f22c33500e2c556db8e1adee6c9f26d (patch)
tree315a328232ce4268acaa824d2e95010eaba181f7 /src/bin
parentcd169f8418578d999865ef8680760334409966d5 (diff)
epulse: Sinks View ported to emix
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/sinks_view.c207
1 files changed, 69 insertions, 138 deletions
diff --git a/src/bin/sinks_view.c b/src/bin/sinks_view.c
index 15ceee0..15cfba4 100644
--- a/src/bin/sinks_view.c
+++ b/src/bin/sinks_view.c
@@ -1,34 +1,15 @@
1#include "sinks_view.h" 1#include "sinks_view.h"
2 2
3#include "epulse.h" 3#include <emix.h>
4 4
5#define SINKS_KEY "sinks.key" 5#define SINKS_KEY "sinks.key"
6 6
7struct Sink
8{
9 int index;
10 pa_cvolume volume;
11 const char *name;
12 Eina_Bool mute;
13
14 Elm_Object_Item *item;
15 Eina_List *ports;
16};
17
18struct Sink_Port
19{
20 char *name;
21 char *description;
22 Eina_Bool active;
23};
24
25struct Sinks_View 7struct Sinks_View
26{ 8{
27 Evas_Object *self; 9 Evas_Object *self;
28 Evas_Object *genlist; 10 Evas_Object *genlist;
29 Elm_Genlist_Item_Class *itc; 11 Elm_Genlist_Item_Class *itc;
30 12
31 Eina_List *sinks;
32 Ecore_Event_Handler *disconnected; 13 Ecore_Event_Handler *disconnected;
33 Ecore_Event_Handler *sink_added; 14 Ecore_Event_Handler *sink_added;
34 Ecore_Event_Handler *sink_changed; 15 Ecore_Event_Handler *sink_changed;
@@ -40,10 +21,7 @@ static Eina_Bool
40_disconnected_cb(void *data, int type EINA_UNUSED, void *info EINA_UNUSED) 21_disconnected_cb(void *data, int type EINA_UNUSED, void *info EINA_UNUSED)
41{ 22{
42 struct Sinks_View *sv = data; 23 struct Sinks_View *sv = data;
43 struct Sink *sink; 24 elm_genlist_clear(sv->genlist);
44
45 EINA_LIST_FREE(sv->sinks, sink)
46 elm_object_item_del(sink->item);
47 25
48 return ECORE_CALLBACK_PASS_ON; 26 return ECORE_CALLBACK_PASS_ON;
49} 27}
@@ -52,31 +30,10 @@ static Eina_Bool
52_sink_add_cb(void *data, int type EINA_UNUSED, void *info) 30_sink_add_cb(void *data, int type EINA_UNUSED, void *info)
53{ 31{
54 struct Sinks_View *sv = data; 32 struct Sinks_View *sv = data;
55 struct Sink_Port *sp; 33 Emix_Sink *sink = info;
56 Epulse_Event_Sink *ev = info;
57 Port *port;
58 Eina_List *l;
59 struct Sink *sink = calloc(1, sizeof(struct Sink));
60 EINA_SAFETY_ON_NULL_RETURN_VAL(sink, ECORE_CALLBACK_PASS_ON);
61 34
62 sink->name = eina_stringshare_add(ev->base.name); 35 elm_genlist_item_append(sv->genlist, sv->itc, sink, NULL,
63 sink->index = ev->base.index; 36 ELM_GENLIST_ITEM_NONE, NULL, sv);
64 sink->volume = ev->base.volume;
65 sink->mute = ev->base.mute;
66
67 EINA_LIST_FOREACH(ev->ports, l, port)
68 {
69 sp = calloc(1, sizeof(struct Sink_Port));
70 sp->name = strdup(port->name);
71 sp->description = strdup(port->description);
72 if (port->active)
73 sp->active = EINA_TRUE;
74 sink->ports = eina_list_append(sink->ports, sp);
75 }
76
77 sv->sinks = eina_list_append(sv->sinks, sink);
78 sink->item = elm_genlist_item_append(sv->genlist, sv->itc, sink, NULL,
79 ELM_GENLIST_ITEM_NONE, NULL, sv);
80 37
81 return ECORE_CALLBACK_PASS_ON; 38 return ECORE_CALLBACK_PASS_ON;
82} 39}
@@ -85,18 +42,15 @@ static Eina_Bool
85_sink_removed_cb(void *data, int type EINA_UNUSED, void *info) 42_sink_removed_cb(void *data, int type EINA_UNUSED, void *info)
86{ 43{
87 struct Sinks_View *sv = data; 44 struct Sinks_View *sv = data;
88 Epulse_Event_Sink *ev = info; 45 Emix_Sink *ev = info;
89 Eina_List *l, *ll; 46 Elm_Object_Item *item = elm_genlist_first_item_get(sv->genlist);
90 struct Sink *sink; 47 if (ev == elm_object_item_data_get(item))
48 elm_object_item_del(item);
91 49
92 EINA_LIST_FOREACH_SAFE(sv->sinks, l, ll, sink) 50 while ((item = elm_genlist_item_next_get(item)))
93 { 51 {
94 if (sink->index == ev->base.index) 52 if (ev == elm_object_item_data_get(item))
95 { 53 elm_object_item_del(item);
96 sv->sinks = eina_list_remove_list(sv->sinks, l);
97 elm_object_item_del(sink->item);
98 break;
99 }
100 } 54 }
101 55
102 return ECORE_CALLBACK_PASS_ON; 56 return ECORE_CALLBACK_PASS_ON;
@@ -106,32 +60,27 @@ static Eina_Bool
106_sink_changed_cb(void *data, int type EINA_UNUSED, void *info) 60_sink_changed_cb(void *data, int type EINA_UNUSED, void *info)
107{ 61{
108 struct Sinks_View *sv = data; 62 struct Sinks_View *sv = data;
109 Epulse_Event_Sink *ev = info; 63 Emix_Sink *sink = info;
110 Eina_List *l; 64 Elm_Object_Item *item = elm_genlist_first_item_get(sv->genlist);
111 struct Sink *sink; 65 Evas_Object *it;
112 Evas_Object *item = NULL;
113 66
114 EINA_LIST_FOREACH(sv->sinks, l, sink) 67 while (item)
115 { 68 {
116 if (sink->index == ev->base.index) 69 if (sink == elm_object_item_data_get(item))
117 { 70 {
118 pa_volume_t vol = pa_cvolume_avg(&ev->base.volume); 71 it = elm_object_item_part_content_get(item, "item");
119 72 if (it)
120 item = elm_object_item_part_content_get(sink->item, "slider"); 73 elm_slider_value_set(it, sink->volume.volumes[0]);
121 sink->volume = ev->base.volume;
122 if (item)
123 elm_slider_value_set(item, PA_VOLUME_TO_INT(vol));
124
125 item = elm_object_item_part_content_get(sink->item, "mute");
126 sink->mute = ev->base.mute;
127 if (item)
128 elm_check_state_set(item, sink->mute);
129 74
75 it = elm_object_item_part_content_get(item, "mute");
76 if (it)
77 elm_check_state_set(it, sink->mute);
130 break; 78 break;
131 } 79 }
80 item = elm_genlist_item_next_get(item);
132 } 81 }
133 82
134 return ECORE_CALLBACK_DONE; 83 return ECORE_CALLBACK_PASS_ON;
135} 84}
136 85
137static void 86static void
@@ -140,33 +89,24 @@ _del_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED,
140{ 89{
141 struct Sinks_View *sv = data; 90 struct Sinks_View *sv = data;
142 91
143 eina_list_free(sv->sinks); 92#define ECORE_EVENT_HANDLER_DEL(_handle) \
144 if (sv->sink_added) 93 if (sv->_handle) \
145 { 94 { \
146 ecore_event_handler_del(sv->sink_added); 95 ecore_event_handler_del(sv->_handle); \
147 sv->sink_added = NULL; 96 sv->_handle = NULL; \
148 }
149 if (sv->sink_changed)
150 {
151 ecore_event_handler_del(sv->sink_changed);
152 sv->sink_changed = NULL;
153 }
154 if (sv->sink_removed)
155 {
156 ecore_event_handler_del(sv->sink_removed);
157 sv->sink_removed = NULL;
158 }
159 if (sv->disconnected)
160 {
161 ecore_event_handler_del(sv->disconnected);
162 sv->disconnected = NULL;
163 } 97 }
98
99 ECORE_EVENT_HANDLER_DEL(disconnected)
100 ECORE_EVENT_HANDLER_DEL(sink_removed)
101 ECORE_EVENT_HANDLER_DEL(sink_changed)
102 ECORE_EVENT_HANDLER_DEL(sink_added)
103#undef ECORE_EVENT_HANDLER_DEL
164} 104}
165 105
166static char * 106static char *
167_item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part) 107_item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
168{ 108{
169 struct Sink *sink = data; 109 Emix_Sink *sink = data;
170 110
171 if (!strcmp(part, "name")) 111 if (!strcmp(part, "name"))
172 { 112 {
@@ -177,57 +117,40 @@ _item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
177} 117}
178 118
179static void 119static void
180_item_del(void *data, Evas_Object *obj EINA_UNUSED)
181{
182 struct Sink *sink = data;
183 struct Sink_Port *port;
184
185 eina_stringshare_del(sink->name);
186 EINA_LIST_FREE(sink->ports, port)
187 {
188 free(port->name);
189 free(port->description);
190 free(port);
191 }
192 free(sink);
193}
194
195static void
196_volume_changed_cb(void *data, Evas_Object *o, 120_volume_changed_cb(void *data, Evas_Object *o,
197 void *event_info EINA_UNUSED) 121 void *event_info EINA_UNUSED)
198{ 122{
199 struct Sink *sink = data; 123 Emix_Sink *sink = data;
200 double val = elm_slider_value_get(o); 124 double val = elm_slider_value_get(o);
201 pa_volume_t v = INT_TO_PA_VOLUME(val); 125 Emix_Volume volume;
126 unsigned int i;
202 127
203 pa_cvolume_set(&sink->volume, sink->volume.channels, v); 128 volume.channel_count = sink->volume.channel_count;
129 volume.volumes = calloc(sink->volume.channel_count, sizeof(int));
130 for (i = 0; i < volume.channel_count; i++)
131 volume.volumes[i] = val;
204 132
205 epulse_sink_volume_set(sink->index, sink->volume); 133 emix_sink_volume_set(sink, volume);
134 free(volume.volumes);
206} 135}
207 136
208static void 137static void
209_mute_changed_cb(void *data, Evas_Object *o EINA_UNUSED, 138_mute_changed_cb(void *data, Evas_Object *o EINA_UNUSED,
210 void *event_info EINA_UNUSED) 139 void *event_info EINA_UNUSED)
211{ 140{
212 struct Sink *sink = data; 141 Emix_Sink *sink = data;
213 142
214 if (!epulse_sink_mute_set(sink->index, sink->mute)) 143 emix_sink_mute_set(sink, sink->mute);
215 {
216 ERR("Could not mute the sink: %d", sink->index);
217 sink->mute = !sink->mute;
218 return;
219 }
220} 144}
221 145
222static void 146static void
223_port_selected_cb(void *data, Evas_Object *o, 147_port_selected_cb(void *data, Evas_Object *o, void *event_info)
224 void *event_info EINA_UNUSED)
225{ 148{
226 struct Sink *sink = data; 149 Emix_Sink *sink = data;
227 Elm_Object_Item *item = event_info; 150 Elm_Object_Item *item = event_info;
228 struct Sink_Port *port = elm_object_item_data_get(item); 151 Emix_Port *port = elm_object_item_data_get(item);
229 152
230 if (!epulse_sink_port_set(sink->index, port->name)) 153 if (!emix_sink_port_set(sink, port))
231 ERR("Could not change the port"); 154 ERR("Could not change the port");
232 else 155 else
233 elm_object_text_set(o, port->description); 156 elm_object_text_set(o, port->description);
@@ -237,11 +160,10 @@ static Evas_Object *
237_item_content_get(void *data, Evas_Object *obj, const char *part) 160_item_content_get(void *data, Evas_Object *obj, const char *part)
238{ 161{
239 Evas_Object *item = NULL; 162 Evas_Object *item = NULL;
240 struct Sink *sink = data; 163 Emix_Sink *sink = data;
241 164
242 if (!strcmp(part, "slider")) 165 if (!strcmp(part, "slider"))
243 { 166 {
244 pa_volume_t vol = pa_cvolume_avg(&sink->volume);
245 item = elm_slider_add(obj); 167 item = elm_slider_add(obj);
246 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL); 168 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
247 169
@@ -250,7 +172,7 @@ _item_content_get(void *data, Evas_Object *obj, const char *part)
250 elm_slider_indicator_format_set(item, "%1.0f"); 172 elm_slider_indicator_format_set(item, "%1.0f");
251 elm_slider_span_size_set(item, 120); 173 elm_slider_span_size_set(item, 120);
252 elm_slider_min_max_set(item, 0.0, 100.0); 174 elm_slider_min_max_set(item, 0.0, 100.0);
253 elm_slider_value_set(item, PA_VOLUME_TO_INT(vol)); 175 elm_slider_value_set(item, sink->volume.volumes[0]);
254 evas_object_smart_callback_add(item, "delay,changed", 176 evas_object_smart_callback_add(item, "delay,changed",
255 _volume_changed_cb, sink); 177 _volume_changed_cb, sink);
256 } 178 }
@@ -270,8 +192,8 @@ _item_content_get(void *data, Evas_Object *obj, const char *part)
270 } 192 }
271 else if (!strcmp(part, "hover")) 193 else if (!strcmp(part, "hover"))
272 { 194 {
195 Emix_Port *sp;
273 Eina_List *l; 196 Eina_List *l;
274 struct Sink_Port *sp;
275 197
276 if (sink->ports) 198 if (sink->ports)
277 item = elm_hoversel_add(obj); 199 item = elm_hoversel_add(obj);
@@ -295,7 +217,9 @@ Evas_Object *
295sinks_view_add(Evas_Object *parent) 217sinks_view_add(Evas_Object *parent)
296{ 218{
297 Evas_Object *layout; 219 Evas_Object *layout;
220 Eina_List *l;
298 struct Sinks_View *sv; 221 struct Sinks_View *sv;
222 Emix_Sink *sink;
299 223
300 sv = calloc(1, sizeof(struct Sinks_View)); 224 sv = calloc(1, sizeof(struct Sinks_View));
301 EINA_SAFETY_ON_NULL_RETURN_VAL(sv, NULL); 225 EINA_SAFETY_ON_NULL_RETURN_VAL(sv, NULL);
@@ -308,11 +232,13 @@ sinks_view_add(Evas_Object *parent)
308 sv->genlist = elm_genlist_add(layout); 232 sv->genlist = elm_genlist_add(layout);
309 EINA_SAFETY_ON_NULL_GOTO(sv->genlist, err_genlist); 233 EINA_SAFETY_ON_NULL_GOTO(sv->genlist, err_genlist);
310 234
311 sv->disconnected = ecore_event_handler_add(DISCONNECTED, 235 sv->disconnected = ecore_event_handler_add(EMIX_DISCONNECTED_EVENT,
312 _disconnected_cb, sv); 236 _disconnected_cb, sv);
313 sv->sink_added = ecore_event_handler_add(SINK_ADDED, _sink_add_cb, sv); 237 sv->sink_added = ecore_event_handler_add(EMIX_SINK_ADDED_EVENT,
314 sv->sink_added = ecore_event_handler_add(SINK_CHANGED, _sink_changed_cb, sv); 238 _sink_add_cb, sv);
315 sv->sink_removed = ecore_event_handler_add(SINK_REMOVED, 239 sv->sink_added = ecore_event_handler_add(EMIX_SINK_CHANGED_EVENT,
240 _sink_changed_cb, sv);
241 sv->sink_removed = ecore_event_handler_add(EMIX_SINK_REMOVED_EVENT,
316 _sink_removed_cb, sv); 242 _sink_removed_cb, sv);
317 243
318 sv->itc = elm_genlist_item_class_new(); 244 sv->itc = elm_genlist_item_class_new();
@@ -320,7 +246,6 @@ sinks_view_add(Evas_Object *parent)
320 sv->itc->item_style = "sinks"; 246 sv->itc->item_style = "sinks";
321 sv->itc->func.text_get = _item_text_get; 247 sv->itc->func.text_get = _item_text_get;
322 sv->itc->func.content_get = _item_content_get; 248 sv->itc->func.content_get = _item_content_get;
323 sv->itc->func.del = _item_del;
324 249
325 evas_object_data_set(layout, SINKS_KEY, sv); 250 evas_object_data_set(layout, SINKS_KEY, sv);
326 elm_layout_content_set(layout, "list", sv->genlist); 251 elm_layout_content_set(layout, "list", sv->genlist);
@@ -330,6 +255,12 @@ sinks_view_add(Evas_Object *parent)
330 evas_object_size_hint_align_set(sv->genlist, EVAS_HINT_FILL, 255 evas_object_size_hint_align_set(sv->genlist, EVAS_HINT_FILL,
331 EVAS_HINT_FILL); 256 EVAS_HINT_FILL);
332 257
258 EINA_LIST_FOREACH((Eina_List *)emix_sinks_get(), l, sink)
259 {
260 elm_genlist_item_append(sv->genlist, sv->itc, sink, NULL,
261 ELM_GENLIST_ITEM_NONE, NULL, sv);
262 }
263
333 return layout; 264 return layout;
334 265
335 err_genlist: 266 err_genlist: