Initial upload of minicontrol(tagging)
[apps/home/minicontrol.git] / src / minicontrol-viewer.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *  http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <Elementary.h>
18 #include <Ecore_Evas.h>
19
20 #include "minicontrol-internal.h"
21 #include "minicontrol-type.h"
22 #include "minicontrol-viewer.h"
23 #include "minicontrol-log.h"
24
25 #define MINICTRL_PLUG_DATA_KEY "__minictrl_plug_name"
26
27 static void _minictrl_plug_server_del(Ecore_Evas *ee)
28 {
29         char *svr_name = NULL;
30
31         svr_name = ecore_evas_data_get(ee, MINICTRL_PLUG_DATA_KEY);
32         if (!svr_name) {
33                 ERR("fail to get svr_name");
34                 return;
35         }
36
37         INFO("server - %s is deleted", svr_name);
38
39         /* send message to remve plug */
40         _minictrl_provider_message_send(MINICTRL_DBUS_SIG_STOP,
41                                         svr_name, 0, 0,
42                                         MINICONTROL_PRIORITY_LOW);
43 }
44
45 static void _minictrl_plug_del(void *data, Evas *e,
46                         Evas_Object *obj, void *event_info)
47 {
48         Ecore_Evas *ee = NULL;
49         char *svr_name = NULL;
50
51         ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
52         if (!ee)
53                 return;
54
55         svr_name = ecore_evas_data_get(ee, MINICTRL_PLUG_DATA_KEY);
56         if (svr_name)
57                 free(svr_name);
58
59         ecore_evas_data_set(ee, MINICTRL_PLUG_DATA_KEY, NULL);
60 }
61
62 EXPORT_API
63 Evas_Object *minicontrol_viewer_image_object_get(const Evas_Object *obj)
64 {
65         return elm_plug_image_object_get(obj);
66 }
67
68 EXPORT_API Evas_Object *minicontrol_viewer_add(Evas_Object *parent,
69                                                 const char *svr_name)
70 {
71         Evas_Object *plug = NULL;
72         Evas_Object *plug_img = NULL;
73         Ecore_Evas *ee = NULL;
74
75         plug = elm_plug_add(parent);
76         if (!plug) {
77                 ERR("fail to create plug");
78                 return NULL;
79         }
80
81         if (!elm_plug_connect(plug, svr_name, 0, EINA_FALSE)) {
82                 ERR("Cannot connect plug[%s]", svr_name);
83                 evas_object_del(plug);
84                 return NULL;
85         }
86
87         plug_img = elm_plug_image_object_get(plug);
88
89         ee = ecore_evas_object_ecore_evas_get(plug_img);
90         ecore_evas_data_set(ee, MINICTRL_PLUG_DATA_KEY, strdup(svr_name));
91         ecore_evas_callback_delete_request_set(ee, _minictrl_plug_server_del);
92
93         evas_object_event_callback_add(plug, EVAS_CALLBACK_DEL,
94                                         _minictrl_plug_del, plug);
95
96         return plug;
97 }
98