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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#include <Elementary.h>
#include "elm_priv.h"
#define MY_CLASS ELM_APP_CLIENT_VIEW_CLASS
#define MY_CLASS_NAME "Elm_App_Client_View"
typedef struct
{
Eldbus_Proxy *view_proxy;
Elm_App_View_State state;
Eina_Stringshare *path;
} Elm_App_Client_View_Data;
static const char *_string_prop_get(const Eina_Value *v)
{
const char *str;
if (!v)
return "";
eina_value_get(v, &str);
return str;
}
static int _int_prop_get(const Eina_Value *v)
{
int num;
if (!v)
return 0;
eina_value_get(v, &num);
return num;
}
static short _short_prop_get(const Eina_Value *v)
{
short num;
if (!v)
return 0;
eina_value_get(v, &num);
return num;
}
static void
_prop_changed(void *user_data, Eldbus_Proxy *proxy EINA_UNUSED, void *event_info)
{
Eldbus_Proxy_Event_Property_Changed *prop_event = event_info;
Elm_App_Client_View *eo = user_data;
const Eina_Value *v = prop_event->value;
Elm_App_Client_View_Data *cdata = eo_data_scope_get(eo, MY_CLASS);
if (!strcmp(prop_event->name, "Title"))
efl_event_callback_call(eo, ELM_APP_CLIENT_VIEW_EVENT_TITLE_CHANGED, (void *) _string_prop_get(v));
else if (!strcmp(prop_event->name, "IconName"))
efl_event_callback_call(eo, ELM_APP_CLIENT_VIEW_EVENT_ICON_CHANGED, (void *) _string_prop_get(v));
else if (!strcmp(prop_event->name, "IconPixels"))
efl_event_callback_call(eo, ELM_APP_CLIENT_VIEW_EVENT_ICON_PIXELS_CHANGED, NULL);
else if (!strcmp(prop_event->name, "NewEvents"))
efl_event_callback_call(eo, ELM_APP_CLIENT_VIEW_EVENT_NEW_EVENTS_CHANGED, (void *)(uintptr_t)_int_prop_get(v));
else if (!strcmp(prop_event->name, "Progress"))
efl_event_callback_call(eo, ELM_APP_CLIENT_VIEW_EVENT_PROGRESS_CHANGED, (void *)(uintptr_t)_short_prop_get(v));
else if (!strcmp(prop_event->name, "State"))
{
cdata->state = _string_state_to_id(_string_prop_get(v));
efl_event_callback_call(eo, ELM_APP_CLIENT_VIEW_EVENT_STATE_CHANGED, (void *)(uintptr_t)cdata->state);
}
else if (!strcmp(prop_event->name, "WindowId"))
efl_event_callback_call(eo, ELM_APP_CLIENT_VIEW_EVENT_WINDOW_CHANGED, (void *)(uintptr_t)_int_prop_get(v));
else
return;
efl_event_callback_call(eo, ELM_APP_CLIENT_VIEW_EVENT_PROPERTY_CHANGED, (void *) prop_event->name);
}
static void
_props_loaded(void *user_data, Eldbus_Proxy *proxy EINA_UNUSED, void *event_info EINA_UNUSED)
{
const Eina_Hash *props = eldbus_proxy_property_local_get_all(proxy);
Eina_Iterator *iter;
Eina_Hash_Tuple *t;
iter = eina_hash_iterator_tuple_new(props);
EINA_ITERATOR_FOREACH(iter, t)
{
Eldbus_Proxy_Event_Property_Changed event;
event.name = t->key;
event.proxy = proxy;
event.value = t->data;
_prop_changed(user_data, proxy, &event);
}
eina_iterator_free(iter);
}
void
elm_app_client_view_internal_state_set(Eo *eo, Elm_App_View_State state)
{
Elm_App_Client_View_Data *cdata;
Eina_Bool changed = EINA_FALSE;
EINA_SAFETY_ON_NULL_RETURN(eo);
EINA_SAFETY_ON_FALSE_RETURN(eo_isa(eo, ELM_APP_CLIENT_VIEW_CLASS));
cdata = eo_data_scope_get(eo, MY_CLASS);
changed = cdata->state != state;
cdata->state = state;
if (!changed)
return;
efl_event_callback_call(eo, ELM_APP_CLIENT_VIEW_EVENT_STATE_CHANGED, (void *)(uintptr_t)cdata->state);
}
EOLIAN static Eo *
_elm_app_client_view_efl_object_finalize(Eo *eo, Elm_App_Client_View_Data *data)
{
Elm_App_Client *parent = NULL;
const char *package = data->path;
Eldbus_Connection *conn;
Eldbus_Object *obj;
parent = efl_parent_get(eo);
EINA_SAFETY_ON_TRUE_RETURN_VAL((!parent) ||
(!eo_isa(parent, ELM_APP_CLIENT_CLASS)), NULL);
EINA_SAFETY_ON_NULL_RETURN_VAL(data->path, NULL);
package = elm_app_client_package_get(parent);
eldbus_init();
conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
obj = eldbus_object_get(conn, package, data->path);
data->view_proxy = eldbus_proxy_get(obj,
"org.enlightenment.ApplicationView1");
eldbus_proxy_properties_monitor(data->view_proxy, EINA_TRUE);
eldbus_proxy_event_callback_add(data->view_proxy,
ELDBUS_PROXY_EVENT_PROPERTY_CHANGED,
_prop_changed, eo);
eldbus_proxy_event_callback_add(data->view_proxy,
ELDBUS_PROXY_EVENT_PROPERTY_LOADED,
_props_loaded, eo);
return efl_finalize(eo_super(eo, MY_CLASS));
}
static void
_dbus_state_set_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending)
{
Elm_App_Client_View *eo = data;
Elm_App_Client_View_Cb cb = eldbus_pending_data_del(pending, "cb");
void *user_data = eldbus_pending_data_del(pending, "user_data");
const char *error = NULL, *error_message = NULL;
if (!cb) return;
if (!eldbus_message_error_get(msg, &error, &error_message))
error_message = NULL;
cb(user_data, eo, error, error_message);
}
static void
_dbus_action_do(Eo *eo, Eldbus_Proxy *proxy, const char *action, Elm_App_Client_View_Cb cb, const void *data)
{
Eldbus_Pending *pending;
if (!cb)
{
eldbus_proxy_call(proxy, action, NULL, NULL, -1, "");
return;
}
pending = eldbus_proxy_call(proxy, action, _dbus_state_set_cb, eo, -1, "");
eldbus_pending_data_set(pending, "cb", cb);
eldbus_pending_data_set(pending, "user_data", data);
}
EOLIAN static void
_elm_app_client_view_resume(Eo *eo, Elm_App_Client_View_Data *data, Elm_App_Client_View_Cb cb, const void *user_data)
{
_dbus_action_do(eo, data->view_proxy, "Resume", cb, user_data);
}
EOLIAN static void
_elm_app_client_view_pause(Eo *eo, Elm_App_Client_View_Data *data, Elm_App_Client_View_Cb cb, const void *user_data)
{
_dbus_action_do(eo, data->view_proxy, "Pause", cb, user_data);
}
EOLIAN static void
_elm_app_client_view_close(Eo *eo, Elm_App_Client_View_Data *data, Elm_App_Client_View_Cb cb, const void *user_data)
{
_dbus_action_do(eo, data->view_proxy, "Close", cb, user_data);
}
EOLIAN static const char*
_elm_app_client_view_title_get(Eo *eo EINA_UNUSED, Elm_App_Client_View_Data *data)
{
Eina_Value *v;
v = eldbus_proxy_property_local_get(data->view_proxy, "Title");
return _string_prop_get(v);
}
EOLIAN static const char*
_elm_app_client_view_icon_get(Eo *eo EINA_UNUSED, Elm_App_Client_View_Data *data)
{
Eina_Value *v;
v = eldbus_proxy_property_local_get(data->view_proxy, "IconName");
return _string_prop_get(v);
}
EOLIAN static void
_elm_app_client_view_icon_pixels_get(Eo *obj EINA_UNUSED, Elm_App_Client_View_Data *pd EINA_UNUSED,
unsigned int *w EINA_UNUSED, unsigned int *h EINA_UNUSED,
Eina_Bool *has_alpha EINA_UNUSED, const unsigned char **pixels EINA_UNUSED)
{
//TODO
}
EOLIAN static unsigned short
_elm_app_client_view_progress_get(Eo *eo EINA_UNUSED, Elm_App_Client_View_Data *data)
{
Eina_Value *v;
v = eldbus_proxy_property_local_get(data->view_proxy, "Progress");
return _short_prop_get(v);
}
EOLIAN static int
_elm_app_client_view_new_events_get(Eo *eo EINA_UNUSED, Elm_App_Client_View_Data *data)
{
Eina_Value *v;
v = eldbus_proxy_property_local_get(data->view_proxy, "NewEvents");
return _int_prop_get(v);
}
EOLIAN static Elm_App_View_State
_elm_app_client_view_state_get(Eo *eo EINA_UNUSED, Elm_App_Client_View_Data *data)
{
return data->state;
}
EOLIAN static int
_elm_app_client_view_window_get(Eo *eo EINA_UNUSED, Elm_App_Client_View_Data *data)
{
Eina_Value *v;
v = eldbus_proxy_property_local_get(data->view_proxy, "WindowId");
return _int_prop_get(v);
}
EOLIAN static void
_elm_app_client_view_path_set(Eo *eo, Elm_App_Client_View_Data *data, const char *path)
{
if (efl_finalized_get(eo))
{
ERR("Can't set id after object has been created.");
return;
}
data->path = eina_stringshare_add(path);
}
EOLIAN static const char*
_elm_app_client_view_path_get(Eo *eo EINA_UNUSED, Elm_App_Client_View_Data *data)
{
Eldbus_Object *obj;
obj = eldbus_proxy_object_get(data->view_proxy);
return eldbus_object_path_get(obj);
}
EOLIAN static const char*
_elm_app_client_view_package_get(Eo *eo EINA_UNUSED, Elm_App_Client_View_Data *data)
{
Eldbus_Object *obj;
obj = eldbus_proxy_object_get(data->view_proxy);
return eldbus_object_bus_name_get(obj);
}
EOLIAN static void
_elm_app_client_view_efl_object_destructor(Eo *eo, Elm_App_Client_View_Data *data)
{
Eldbus_Object *obj;
Eldbus_Connection *conn;
eldbus_proxy_properties_monitor(data->view_proxy, EINA_FALSE);
obj = eldbus_proxy_object_get(data->view_proxy);
conn = eldbus_object_connection_get(obj);
eldbus_proxy_unref(data->view_proxy);
eldbus_object_unref(obj);
eldbus_connection_unref(conn);
eldbus_shutdown();
eina_stringshare_del(data->path);
efl_destructor(eo_super(eo, MY_CLASS));
}
#include "elm_app_client_view.eo.c"
|