summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2014-08-08 00:35:15 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2014-08-14 23:33:18 -0300
commitabb65b2ba5ea7b0a1e005538aacc9bc199be820f (patch)
treef20e59be02ebc9e733651c04a6659ea183cc2bdd /src
parent7b5977a53f22c33500e2c556db8e1adee6c9f26d (diff)
epulse: Sources View ported to emix
Diffstat (limited to 'src')
-rw-r--r--src/bin/sources_view.c169
1 files changed, 59 insertions, 110 deletions
diff --git a/src/bin/sources_view.c b/src/bin/sources_view.c
index 0740c14..bbf4008 100644
--- a/src/bin/sources_view.c
+++ b/src/bin/sources_view.c
@@ -1,26 +1,15 @@
1#include "sources_view.h" 1#include "sources_view.h"
2 2
3#include "epulse.h" 3#include <emix.h>
4 4
5#define SOURCES_KEY "sources.key" 5#define SOURCES_KEY "sources.key"
6 6
7struct Source
8{
9 int index;
10 pa_cvolume volume;
11 const char *name;
12 Eina_Bool mute;
13
14 Elm_Object_Item *item;
15};
16
17struct Sources_View 7struct Sources_View
18{ 8{
19 Evas_Object *self; 9 Evas_Object *self;
20 Evas_Object *genlist; 10 Evas_Object *genlist;
21 Elm_Genlist_Item_Class *itc; 11 Elm_Genlist_Item_Class *itc;
22 12
23 Eina_List *sources;
24 Ecore_Event_Handler *disconnected; 13 Ecore_Event_Handler *disconnected;
25 Ecore_Event_Handler *source_added; 14 Ecore_Event_Handler *source_added;
26 Ecore_Event_Handler *source_changed; 15 Ecore_Event_Handler *source_changed;
@@ -31,10 +20,7 @@ static Eina_Bool
31_disconnected_cb(void *data, int type EINA_UNUSED, void *info EINA_UNUSED) 20_disconnected_cb(void *data, int type EINA_UNUSED, void *info EINA_UNUSED)
32{ 21{
33 struct Sources_View *sv = data; 22 struct Sources_View *sv = data;
34 struct Source *source; 23 elm_genlist_clear(sv->genlist);
35
36 EINA_LIST_FREE(sv->sources, source)
37 elm_object_item_del(source->item);
38 24
39 return ECORE_CALLBACK_PASS_ON; 25 return ECORE_CALLBACK_PASS_ON;
40} 26}
@@ -43,74 +29,57 @@ static Eina_Bool
43_source_add_cb(void *data, int type EINA_UNUSED, void *info) 29_source_add_cb(void *data, int type EINA_UNUSED, void *info)
44{ 30{
45 struct Sources_View *sv = data; 31 struct Sources_View *sv = data;
46 Epulse_Event *ev = info; 32 Emix_Source *source= info;
47 struct Source *source = calloc(1, sizeof(struct Source));
48 EINA_SAFETY_ON_NULL_RETURN_VAL(source, ECORE_CALLBACK_PASS_ON);
49
50 source->name = eina_stringshare_add(ev->name);
51 source->index = ev->index;
52 source->volume = ev->volume;
53 source->mute = ev->mute;
54 33
55 sv->sources = eina_list_append(sv->sources, source); 34 elm_genlist_item_append(sv->genlist, sv->itc, source, NULL,
56 source->item = elm_genlist_item_append(sv->genlist, sv->itc, source, NULL, 35 ELM_GENLIST_ITEM_NONE, NULL, sv);
57 ELM_GENLIST_ITEM_NONE, NULL, sv);
58 36
59 return ECORE_CALLBACK_DONE; 37 return ECORE_CALLBACK_PASS_ON;
60} 38}
61 39
62static Eina_Bool 40static Eina_Bool
63_source_removed_cb(void *data, int type EINA_UNUSED, void *info) 41_source_removed_cb(void *data, int type EINA_UNUSED, void *info)
64{ 42{
65 struct Sources_View *sv = data; 43 struct Sources_View *sv = data;
66 Epulse_Event *ev = info; 44 Emix_Source *source = info;
67 Eina_List *l, *ll; 45 Elm_Object_Item *item = elm_genlist_first_item_get(sv->genlist);
68 struct Source *source; 46 if (source == elm_object_item_data_get(item))
47 elm_object_item_del(item);
69 48
70 EINA_LIST_FOREACH_SAFE(sv->sources, l, ll, source) 49 while ((item = elm_genlist_item_next_get(item)))
71 { 50 {
72 if (source->index == ev->index) 51 if (source == elm_object_item_data_get(item))
73 { 52 elm_object_item_del(item);
74 sv->sources = eina_list_remove_list(sv->sources, l);
75 elm_object_item_del(source->item);
76 break;
77 }
78 } 53 }
79 54
80 return ECORE_CALLBACK_DONE; 55 return ECORE_CALLBACK_PASS_ON;
81} 56}
82 57
83static Eina_Bool 58static Eina_Bool
84_source_changed_cb(void *data, int type EINA_UNUSED, void *info) 59_source_changed_cb(void *data, int type EINA_UNUSED, void *info)
85{ 60{
86 struct Sources_View *sv = data; 61 struct Sources_View *sv = data;
87 Epulse_Event *ev = info; 62 Emix_Source *source = info;
88 Eina_List *l; 63 Elm_Object_Item *item = elm_genlist_first_item_get(sv->genlist);
89 struct Source *source; 64 Evas_Object *it;
90 Evas_Object *item = NULL;
91 65
92 EINA_LIST_FOREACH(sv->sources, l, source) 66 while (item)
93 { 67 {
94 if (source->index == ev->index) 68 if (source == elm_object_item_data_get(item))
95 { 69 {
96 pa_volume_t vol = pa_cvolume_avg(&ev->volume); 70 it = elm_object_item_part_content_get(item, "item");
97 71 if (it)
98 item = elm_object_item_part_content_get(source->item, "slider"); 72 elm_slider_value_set(it, source->volume.volumes[0]);
99 source->volume = ev->volume; 73
100 if (item) 74 it = elm_object_item_part_content_get(item, "mute");
101 elm_slider_value_set(item, PA_VOLUME_TO_INT(vol)); 75 if (it)
102 76 elm_check_state_set(it, source->mute);
103 item = elm_object_item_part_content_get(source->item, "mute");
104 source->mute = ev->mute;
105 if (item)
106 {
107 elm_check_state_set(item, source->mute);
108 }
109 break; 77 break;
110 } 78 }
79 item = elm_genlist_item_next_get(item);
111 } 80 }
112 81
113 return ECORE_CALLBACK_DONE; 82 return ECORE_CALLBACK_PASS_ON;
114} 83}
115 84
116static void 85static void
@@ -119,33 +88,24 @@ _del_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED,
119{ 88{
120 struct Sources_View *sv = data; 89 struct Sources_View *sv = data;
121 90
122 eina_list_free(sv->sources); 91#define ECORE_EVENT_HANDLER_DEL(_handle) \
123 if (sv->disconnected) 92 if (sv->_handle) \
124 { 93 { \
125 ecore_event_handler_del(sv->disconnected); 94 ecore_event_handler_del(sv->_handle); \
126 sv->disconnected = NULL; 95 sv->_handle = NULL; \
127 }
128 if (sv->source_added)
129 {
130 ecore_event_handler_del(sv->source_added);
131 sv->source_added = NULL;
132 }
133 if (sv->source_changed)
134 {
135 ecore_event_handler_del(sv->source_changed);
136 sv->source_changed = NULL;
137 }
138 if (sv->source_removed)
139 {
140 ecore_event_handler_del(sv->source_removed);
141 sv->source_removed = NULL;
142 } 96 }
97
98 ECORE_EVENT_HANDLER_DEL(disconnected)
99 ECORE_EVENT_HANDLER_DEL(source_removed)
100 ECORE_EVENT_HANDLER_DEL(source_changed)
101 ECORE_EVENT_HANDLER_DEL(source_added)
102#undef ECORE_EVENT_HANDLER_DEL
143} 103}
144 104
145static char * 105static char *
146_item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part) 106_item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
147{ 107{
148 struct Source *source = data; 108 Emix_Source *source = data;
149 109
150 if (!strcmp(part, "name")) 110 if (!strcmp(part, "name"))
151 { 111 {
@@ -156,50 +116,39 @@ _item_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
156} 116}
157 117
158static void 118static void
159_item_del(void *data, Evas_Object *obj EINA_UNUSED) 119_volume_changed_cb(void *data, Evas_Object *o, void *event_info EINA_UNUSED)
160{ 120{
161 struct Source *source = data; 121 Emix_Source *source = data;
162
163 eina_stringshare_del(source->name);
164 free(source);
165}
166
167static void
168_volume_changed_cb(void *data, Evas_Object *o,
169 void *event_info EINA_UNUSED)
170{
171 struct Source *source = data;
172 double val = elm_slider_value_get(o); 122 double val = elm_slider_value_get(o);
173 pa_volume_t v = INT_TO_PA_VOLUME(val); 123 Emix_Volume volume;
124 unsigned int i;
174 125
175 pa_cvolume_set(&source->volume, source->volume.channels, v); 126 volume.channel_count = source->volume.channel_count;
127 volume.volumes = calloc(source->volume.channel_count, sizeof(int));
128 for (i = 0; i < volume.channel_count; i++)
129 volume.volumes[i] = val;
176 130
177 epulse_source_volume_set(source->index, source->volume); 131 emix_source_volume_set(source, volume);
132 free(volume.volumes);
178} 133}
179 134
180static void 135static void
181_mute_changed_cb(void *data, Evas_Object *o EINA_UNUSED, 136_mute_changed_cb(void *data, Evas_Object *o EINA_UNUSED,
182 void *event_info EINA_UNUSED) 137 void *event_info EINA_UNUSED)
183{ 138{
184 struct Source *source = data; 139 Emix_Source *source = data;
185 140
186 if (!epulse_source_mute_set(source->index, source->mute)) 141 emix_source_mute_set(source, source->mute);
187 {
188 ERR("Could not mute the source: %d", source->index);
189 source->mute = !source->mute;
190 return;
191 }
192} 142}
193 143
194static Evas_Object * 144static Evas_Object *
195_item_content_get(void *data, Evas_Object *obj, const char *part) 145_item_content_get(void *data, Evas_Object *obj, const char *part)
196{ 146{
197 Evas_Object *item = NULL; 147 Evas_Object *item = NULL;
198 struct Source *source = data; 148 Emix_Source *source = data;
199 149
200 if (!strcmp(part, "slider")) 150 if (!strcmp(part, "slider"))
201 { 151 {
202 pa_volume_t vol = pa_cvolume_avg(&source->volume);
203 item = elm_slider_add(obj); 152 item = elm_slider_add(obj);
204 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL); 153 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
205 154
@@ -208,7 +157,7 @@ _item_content_get(void *data, Evas_Object *obj, const char *part)
208 elm_slider_indicator_format_set(item, "%1.0f"); 157 elm_slider_indicator_format_set(item, "%1.0f");
209 elm_slider_span_size_set(item, 120); 158 elm_slider_span_size_set(item, 120);
210 elm_slider_min_max_set(item, 0.0, 100.0); 159 elm_slider_min_max_set(item, 0.0, 100.0);
211 elm_slider_value_set(item, PA_VOLUME_TO_INT(vol)); 160 elm_slider_value_set(item, source->volume.volumes[0]);
212 evas_object_smart_callback_add(item, "delay,changed", 161 evas_object_smart_callback_add(item, "delay,changed",
213 _volume_changed_cb, source); 162 _volume_changed_cb, source);
214 } 163 }
@@ -247,12 +196,13 @@ sources_view_add(Evas_Object *parent)
247 sv->genlist = elm_genlist_add(layout); 196 sv->genlist = elm_genlist_add(layout);
248 EINA_SAFETY_ON_NULL_GOTO(sv->genlist, err_genlist); 197 EINA_SAFETY_ON_NULL_GOTO(sv->genlist, err_genlist);
249 198
250 sv->disconnected = ecore_event_handler_add(DISCONNECTED, 199 sv->disconnected = ecore_event_handler_add(EMIX_DISCONNECTED_EVENT,
251 _disconnected_cb, sv); 200 _disconnected_cb, sv);
252 sv->source_added = ecore_event_handler_add(SOURCE_ADDED, _source_add_cb, sv); 201 sv->source_added = ecore_event_handler_add(EMIX_SOURCE_ADDED_EVENT,
253 sv->source_added = ecore_event_handler_add(SOURCE_CHANGED, 202 _source_add_cb, sv);
203 sv->source_added = ecore_event_handler_add(EMIX_SOURCE_CHANGED_EVENT,
254 _source_changed_cb, sv); 204 _source_changed_cb, sv);
255 sv->source_removed = ecore_event_handler_add(SOURCE_REMOVED, 205 sv->source_removed = ecore_event_handler_add(EMIX_SOURCE_REMOVED_EVENT,
256 _source_removed_cb, sv); 206 _source_removed_cb, sv);
257 207
258 sv->itc = elm_genlist_item_class_new(); 208 sv->itc = elm_genlist_item_class_new();
@@ -260,7 +210,6 @@ sources_view_add(Evas_Object *parent)
260 sv->itc->item_style = "sources"; 210 sv->itc->item_style = "sources";
261 sv->itc->func.text_get = _item_text_get; 211 sv->itc->func.text_get = _item_text_get;
262 sv->itc->func.content_get = _item_content_get; 212 sv->itc->func.content_get = _item_content_get;
263 sv->itc->func.del = _item_del;
264 213
265 evas_object_data_set(layout, SOURCES_KEY, sv); 214 evas_object_data_set(layout, SOURCES_KEY, sv);
266 elm_layout_content_set(layout, "list", sv->genlist); 215 elm_layout_content_set(layout, "list", sv->genlist);