summaryrefslogtreecommitdiff
path: root/src/edje_external/elementary/elm_clock.c
blob: 2e9589989f98aa487bb12ba4d610fd2176e90046 (plain)
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
#include "private.h"

typedef struct _Elm_Params_Clock
{
   Elm_Params base;
   int hrs, min, sec;
   Eina_Bool hrs_exists:1;
   Eina_Bool min_exists:1;
   Eina_Bool sec_exists:1;
   Eina_Bool edit:1;
   Eina_Bool ampm:1;
   Eina_Bool seconds:1;
} Elm_Params_Clock;

static void
external_clock_state_set(void *data EINA_UNUSED, Evas_Object *obj,
                         const void *from_params, const void *to_params,
                         float pos EINA_UNUSED)
{
   const Elm_Params_Clock *p;

   if (to_params) p = to_params;
   else if (from_params) p = from_params;
   else return;

   if ((p->hrs_exists) && (p->min_exists) && (p->sec_exists))
     elm_clock_time_set(obj, p->hrs, p->min, p->sec);
   else if ((p->hrs_exists) || (p->min_exists) || (p->sec_exists))
     {
        int hrs, min, sec;
        elm_clock_time_get(obj, &hrs, &min, &sec);
        if (p->hrs_exists)
          hrs = p->hrs;
        if (p->min_exists)
          min = p->min;
        if (p->sec_exists)
          sec = p->sec;
        elm_clock_time_set(obj, hrs, min, sec);
     }
   if (p->edit)
     elm_clock_edit_set(obj, p->edit);
   if (p->ampm)
     elm_clock_show_am_pm_set(obj, p->ampm);
   if (p->seconds)
     elm_clock_show_seconds_set(obj, p->seconds);
}

static Eina_Bool
external_clock_param_set(void *data EINA_UNUSED, Evas_Object *obj,
                         const Edje_External_Param *param)
{
   if (!strcmp(param->name, "hours"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
          {
             int hrs, min, sec;
             elm_clock_time_get(obj, &hrs, &min, &sec);
             elm_clock_time_set(obj, param->i, min, sec);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "minutes"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
          {
             int hrs, min, sec;
             elm_clock_time_get(obj, &hrs, &min, &sec);
             elm_clock_time_set(obj, hrs, param->i, sec);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "seconds"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
          {
             int hrs, min, sec;
             elm_clock_time_get(obj, &hrs, &min, &sec);
             elm_clock_time_set(obj, hrs, min, param->i);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "editable"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             elm_clock_edit_set(obj, param->i);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "am/pm"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             elm_clock_show_am_pm_set(obj, param->i);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "show seconds"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             elm_clock_show_seconds_set(obj, param->i);
             return EINA_TRUE;
          }
     }

   ERR("unknown parameter '%s' of type '%s'",
       param->name, edje_external_param_type_str(param->type));

   return EINA_FALSE;
}

static Eina_Bool
external_clock_param_get(void *data EINA_UNUSED, const Evas_Object *obj,
                         Edje_External_Param *param)
{
   if (!strcmp(param->name, "hours"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
          {
             int hrs, min, sec;
             elm_clock_time_get(obj, &hrs, &min, &sec);
             param->i = hrs;
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "minutes"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
          {
             int hrs, min, sec;
             elm_clock_time_get(obj, &hrs, &min, &sec);
             param->i = min;
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "seconds"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
          {
             int hrs, min, sec;
             elm_clock_time_get(obj, &hrs, &min, &sec);
             param->i = sec;
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "editable"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             param->i = elm_clock_edit_get(obj);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "am/pm"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             param->i = elm_clock_show_am_pm_get(obj);
             return EINA_TRUE;
          }
     }
   else if (!strcmp(param->name, "show seconds"))
     {
        if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
          {
             param->i = elm_clock_show_seconds_get(obj);
             return EINA_TRUE;
          }
     }

   ERR("unknown parameter '%s' of type '%s'",
       param->name, edje_external_param_type_str(param->type));

   return EINA_FALSE;
}

static void *
external_clock_params_parse(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                            const Eina_List *params)
{
   Elm_Params_Clock *mem;
   Edje_External_Param *param;
   const Eina_List *l;

   mem = calloc(1, sizeof(Elm_Params_Clock));
   if (!mem)
     return NULL;

   EINA_LIST_FOREACH(params, l, param)
     {
        if (!strcmp(param->name, "hours"))
          {
             mem->hrs = param->i;
             mem->hrs_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "minutes"))
          {
             mem->min = param->i;
             mem->min_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "seconds"))
          {
             mem->sec = param->i;
             mem->sec_exists = EINA_TRUE;
          }
        else if (!strcmp(param->name, "editable"))
          mem->edit = !!param->i;
        else if (!strcmp(param->name, "am/pm"))
          mem->ampm = !!param->i;
        else if (!strcmp(param->name, "show seconds"))
          mem->seconds = !!param->i;
     }

   return mem;
}

static Evas_Object *external_clock_content_get(void *data EINA_UNUSED,
                                               const Evas_Object *obj EINA_UNUSED, const char *content EINA_UNUSED)
{
   ERR("No content.");
   return NULL;
}

static void
external_clock_params_free(void *params)
{
   Elm_Params_Clock *mem = params;

   free(mem);
}

static Edje_External_Param_Info external_clock_params[] = {
     DEFINE_EXTERNAL_COMMON_PARAMS,
     EDJE_EXTERNAL_PARAM_INFO_INT("hours"),
     EDJE_EXTERNAL_PARAM_INFO_INT("minutes"),
     EDJE_EXTERNAL_PARAM_INFO_INT("seconds"),
     EDJE_EXTERNAL_PARAM_INFO_BOOL("editable"),
     EDJE_EXTERNAL_PARAM_INFO_BOOL("am/pm"),
     EDJE_EXTERNAL_PARAM_INFO_BOOL("show seconds"),
     EDJE_EXTERNAL_PARAM_INFO_SENTINEL
};

DEFINE_EXTERNAL_ICON_ADD(clock, "clock");
DEFINE_EXTERNAL_TYPE_SIMPLE(clock, "Clock");