svn update: 48945 (latest:48959)
[framework/uifw/elementary.git] / src / edje_externals / elm_photocam.c
1 #include <assert.h>
2
3 #include "private.h"
4
5 typedef struct _Elm_Params_Photocam
6 {
7    const char *file;
8    double zoom;
9    const char *zoom_mode;
10    Eina_Bool paused:1;
11    Eina_Bool paused_exists:1;
12    Eina_Bool zoom_exists:1;
13 } Elm_Params_Photocam;
14
15 static const char* choices[] = {"manual", "auto fit", "auto fill", NULL};
16
17 static Elm_Photocam_Zoom_Mode
18 _zoom_mode_setting_get(const char *zoom_mode_str)
19 {
20    unsigned int i;
21
22    assert(sizeof(choices)/sizeof(choices[0]) == ELM_PHOTOCAM_ZOOM_MODE_LAST + 1);
23
24    for (i = 0; i < sizeof(choices); i++)
25      {
26         if (!strcmp(zoom_mode_str, choices[i]))
27           return i;
28      }
29    return ELM_PHOTOCAM_ZOOM_MODE_LAST;
30 }
31
32 static void
33 external_photocam_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
34 {
35    const Elm_Params_Photocam *p;
36
37    if (to_params) p = to_params;
38    else if (from_params) p = from_params;
39    else return;
40
41    if (p->file)
42      elm_photocam_file_set(obj, p->file);
43    if (p->zoom_exists)
44      elm_photocam_zoom_set(obj, p->zoom);
45    if (p->zoom_mode)
46      {
47         Elm_Photocam_Zoom_Mode set = _zoom_mode_setting_get(p->zoom_mode);
48         if (set == ELM_PHOTOCAM_ZOOM_MODE_LAST) return;
49         elm_photocam_zoom_mode_set(obj, set);
50      }
51    if (p->paused_exists)
52      elm_photocam_paused_set(obj, p->paused);
53 }
54
55 static Eina_Bool
56 external_photocam_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
57 {
58    if (!strcmp(param->name, "file"))
59      {
60         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
61           {
62              elm_photocam_file_set(obj, param->s);
63              return EINA_TRUE;
64           }
65      }
66    else if (!strcmp(param->name, "zoom"))
67      {
68         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
69           {
70              elm_photocam_zoom_set(obj, param->d);
71              return EINA_TRUE;
72           }
73      }
74    else if (!strcmp(param->name, "zoom mode"))
75      {
76         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
77           {
78              Elm_Photocam_Zoom_Mode set = _zoom_mode_setting_get(param->s);
79              if (set == ELM_PHOTOCAM_ZOOM_MODE_LAST) return EINA_FALSE;
80              elm_photocam_zoom_mode_set(obj, set);
81              return EINA_TRUE;
82           }
83      }
84    else if (!strcmp(param->name, "paused"))
85      {
86         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
87           {
88              elm_photocam_paused_set(obj, param->i);
89              return EINA_TRUE;
90           }
91      }
92
93    ERR("unknown parameter '%s' of type '%s'",
94        param->name, edje_external_param_type_str(param->type));
95
96    return EINA_FALSE;
97 }
98
99 static Eina_Bool
100 external_photocam_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
101 {
102    if (!strcmp(param->name, "file"))
103      {
104         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
105           {
106              param->s = elm_photocam_file_get(obj);
107              return EINA_TRUE;
108           }
109      }
110    else if (!strcmp(param->name, "zoom"))
111      {
112         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE)
113           {
114              param->d = elm_photocam_zoom_get(obj);
115              return EINA_TRUE;
116           }
117      }
118    else if (!strcmp(param->name, "zoom mode"))
119      {
120         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
121           {
122              Elm_Photocam_Zoom_Mode zoom_mode_set = elm_photocam_zoom_mode_get(obj);
123
124              if (zoom_mode_set == ELM_PHOTOCAM_ZOOM_MODE_LAST)
125                return EINA_FALSE;
126
127              param->s = choices[zoom_mode_set];
128              return EINA_TRUE;
129           }
130      }
131    else if(!strcmp(param->name, "paused"))
132      {
133         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
134           {
135              param->i = elm_photocam_paused_get(obj);
136              return EINA_TRUE;
137           }
138      }
139
140    ERR("unknown parameter '%s' of type '%s'",
141        param->name, edje_external_param_type_str(param->type));
142
143    return EINA_FALSE;
144 }
145
146 static void *
147 external_photocam_params_parse(void *data, Evas_Object *obj, const Eina_List *params)
148 {
149    Elm_Params_Photocam *mem;
150    Edje_External_Param *param;
151    const Eina_List *l;
152
153    mem = calloc(1, sizeof(Elm_Params_Photocam));
154    if (!mem)
155      return NULL;
156
157    EINA_LIST_FOREACH(params, l, param)
158      {
159         if (!strcmp(param->name, "file"))
160           mem->file = eina_stringshare_add(param->s);
161         else if (!strcmp(param->name, "zoom"))
162           {
163              mem->zoom = param->d;
164              mem->zoom_exists = EINA_TRUE;
165           }
166         else if (!strcmp(param->name, "zoom mode"))
167           mem->zoom_mode = eina_stringshare_add(param->s);
168         else if (!strcmp(param->name, "paused"))
169           {
170              mem->paused = !!param->i;
171              mem->paused_exists = EINA_TRUE;
172           }
173      }
174
175    return mem;
176 }
177
178 static void
179 external_photocam_params_free(void *params)
180 {
181    Elm_Params_Photocam *mem = params;
182
183    if (mem->file)
184      eina_stringshare_del(mem->file);
185    if (mem->zoom_mode)
186      eina_stringshare_del(mem->zoom_mode);
187    free(mem);
188 }
189
190 static Edje_External_Param_Info external_photocam_params[] = {
191    EDJE_EXTERNAL_PARAM_INFO_STRING("file"),
192    EDJE_EXTERNAL_PARAM_INFO_DOUBLE("zoom"),
193    EDJE_EXTERNAL_PARAM_INFO_CHOICE_FULL("zoom mode", "manual", choices),
194    EDJE_EXTERNAL_PARAM_INFO_BOOL("paused"),
195    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
196 };
197
198 DEFINE_EXTERNAL_ICON_ADD(photocam, "photocam");
199 DEFINE_EXTERNAL_TYPE_SIMPLE(photocam, "Photocam");