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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
|
/*
* Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <Elementary.h>
#include <Eina.h>
#include "dbg.h"
#include "settingviewmgr.h"
#include "data_wrapper.h"
#include "timeout_handler.h"
#include "view_maincatalog.h"
#include "view_uigadget.h"
#include "view_sublist.h"
#include "view_pwd_popup.h"
#include "view_system_clock.h"
#include "view_need_pwd.h"
//#include "settingviewmgr.h"
#define MAINCATALOG "maincatalog"
#define PATH_FACTOR 3
struct SSettingMgr {
Evas_Object *win;
int depth;
unsigned int refresh;
unsigned int relaunch;
Eina_List *view_list;
struct settingmgr_data *data;
Eina_Array *item_path;
struct timeout_handler *handler;
Eina_Bool is_freeze;
};
struct _settinginfo {
Evas_Object *base;
CSettingBaseView *sclass;
struct settingview_data *sview;
};
struct settingui_func_map {
const char *style;
CSettingBaseView *view;
//struct setting_class* (*get_vclass)(void);
};
CSettingBaseView::CSettingBaseView(const char *pViewId)
{
m_title = new char[strlen(pViewId) + 1];
strcpy(m_title, pViewId);
}
CSettingBaseView::~CSettingBaseView()
{
delete[] m_title;
}
Evas_Object *CSettingBaseView::Base(void)
{
return NULL;
}
static struct settingui_func_map g_func_map[5];/* = {
{
.style = STYLE_UIGADGET,
.get_vclass = view_uigadget_get_vclass
},
{
.style = STYLE_CTXPOPUP,
.get_vclass = view_sublist_get_vclass
},
{
.style = STYLE_PASSCODE_POPUP,
.get_vclass = view_passcode_popup_get_vclass
},
{
.style = STYLE_CLOCK_CTXPOPUP,
.get_vclass = view_system_clock_get_vclass
},
{
.style = STYLE_NEED_PASSCODE,
.get_vclass = view_need_passcode_get_vclass
}*/
//};
/**
* This function is invoked to build setting view data.
*
* @param mgr [in] The SSettingMgr data pointer.
* @param name[in] The item name to be created view.
* @return The settingview_data data pointer, NULL on error.
*/
static struct settingview_data *_build_setting_view(
struct SSettingMgr *mgr, const char *name)
{
struct settingview_data *data;
int r;
if (!mgr || !mgr->data || !name) {
_ERR("Parameter error!");
return NULL;
}
r = viewmgr_data_read_jsonfile_into_hash(mgr->data, name);
if (r != 0) {
_ERR("Read new json file failed\n");
return NULL;
}
data = viewmgr_data_build_view(mgr->data, name);
if (!data) {
_ERR("Build view data failed\n");
return NULL;
}
return data;
}
CMainCatalogView g_maincatalog(VCLASS_TITLE_MAIN_VIEW);
/**
* This function is invoked to get setting_class data pointer, this data stand for a kind of view.
*
* @param mgr [in] The SSettingMgr data pointer.
* @param view[in] The settingview_data data pointer.
* @return The setting_class data pointer, NULL on error.
*/
static CSettingBaseView *_get_view_class(SSettingMgr *mgr,
struct settingview_data *view)
{
CSettingBaseView *vclass;
struct settingitem *parent;
Eina_List *list;
const char *style;
int size, i;
if (!mgr || !view) {
_ERR("Parameter error!");
return NULL;
}
parent = viewdata_get_parentitem(view);
list = settingitem_get_subitems(parent);
style = settingitem_get_settingui_style(parent);
if (!list && !style) {
_ERR("there is something wrong in json file.");
return NULL;
}
vclass = NULL;
if (list && !style) {
if (mgr->depth == 1)
vclass = &g_maincatalog;// view_maincatalog_get_vclass();
} else {
size = sizeof(g_func_map) / sizeof(*g_func_map);
for (i = 0; i < size; i++) {
if (!strncmp(style, g_func_map[i].style, strlen(style))
&& g_func_map[i].view) {
vclass = g_func_map[i].view;// get_vclass();
break;
}
}
}
return vclass;
}
/**
* This function is invoked to hide all views stored in view list.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return void.
*/
void _hide_view_in_list(struct SSettingMgr *mgr)
{
Eina_List *l;
struct _settinginfo *sinfo;
void* obj;
if (!mgr) {
_ERR("Invalid arguments\n");
return;
}
EINA_LIST_FOREACH(mgr->view_list, l, obj) {
sinfo = (struct _settinginfo *) obj;
sinfo->sclass->Hide();
//if (sinfo->sclass->hide)
// sinfo->sclass->hide(sinfo->base);
}
}
/**
* This function is invoked to show all views stored in view list.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return void.
*/
void _show_view_in_list(struct SSettingMgr *mgr)
{
Eina_List *l;
struct _settinginfo *sinfo;
void* obj;
if (!mgr) {
_ERR("Invalid arguments\n");
return;
}
EINA_LIST_FOREACH(mgr->view_list, l, obj) {
sinfo = (struct _settinginfo *) obj;
sinfo->sclass->Show();
//if (sinfo->sclass->show)
// sinfo->sclass->show(sinfo->base);
}
}
/**
* This function is invoked to destroy all views stored in view list.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return void.
*/
void _destroy_views_in_list(struct SSettingMgr *mgr)
{
Eina_List *l;
struct _settinginfo *sinfo;
void* obj;
if (!mgr) {
_ERR("Invalid arguments\n");
return;
}
EINA_LIST_FOREACH(mgr->view_list, l, obj) {
sinfo = (struct _settinginfo *) obj;
sinfo->sclass->Destroy();
//if (sinfo->sclass->destroy)
// sinfo->sclass->destroy(sinfo->base);
}
}
/**
* This function is invoked to freeze all views's event stored in view list.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return void.
*/
void _frozen_view_in_list(struct SSettingMgr *mgr)
{
Eina_List *l;
struct _settinginfo *sinfo;
void* obj;
if (!mgr) {
_ERR("Invalid argument");
return;
}
if(mgr->view_list) {
EINA_LIST_REVERSE_FOREACH(mgr->view_list, l, obj) {
sinfo = (struct _settinginfo *)obj;
sinfo->sclass->Frozen();
//if (sinfo->sclass->frozen)
// sinfo->sclass->frozen(sinfo->base);
}
}
}
/**
* This function is invoked to activate all views's event stored in view list.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return void.
*/
void _active_view_in_list(struct SSettingMgr *mgr)
{
Eina_List *l;
struct _settinginfo *sinfo;
void* obj;
if (!mgr) {
_ERR("Invalid argument");
return;
}
EINA_LIST_REVERSE_FOREACH(mgr->view_list, l, obj) {
sinfo = (struct _settinginfo *)obj;
sinfo->sclass->Active();
//if (sinfo->sclass->active)
// sinfo->sclass->active(sinfo->base);
}
}
CSettingMgr *CSettingMgr::instance = NULL;
/**
* This function is invoked to initialize setting manager.
*
* @param win [in] The window's evas object.
* @return The SSettingMgr data pointer.
*/
bool CSettingMgr::Initialize(Evas_Object *win)
{
ASSERT(!instance);
instance = new CSettingMgr;
if (!instance) {
return false;
}
instance->m = new SSettingMgr;
if (!instance->m) {
delete instance;
return false;
}
struct settingmgr_data *data;
struct timeout_handler *handler;
if (!win)
return NULL;
data = viewmgr_data_init();
if (!data) {
_ERR("viewmgr_data_init failed!");
delete instance->m;
delete instance;
instance = NULL;
return false;
}
handler = timeout_handler_init(TIMEOUT_SECS);
if (!handler) {
_ERR("Fail to init timeout handler");
viewmgr_data_fini(data);
delete instance->m;
delete instance;
instance = NULL;
return false;
}
CUiGadgetView g_uigadget(VCLASS_TITLE_UG);
CSublistView g_sublist(VCLASS_TITLE_SUBLIST);
CPasscodePopupView g_passcodePopup(VCLASS_TITLE_CHANGE_PASSCODE);
CSystemClockView g_systemclock(VCLASS_TITLE_SYSTEM_CLOCK);
CNeedPasscodeView g_needpasscode(VCLASS_TITLE_NEED_PASSCODE);
g_func_map[0].style = STYLE_UIGADGET;
g_func_map[0].view = &g_uigadget;
g_func_map[1].style = STYLE_CTXPOPUP;
g_func_map[1].view = &g_sublist;
g_func_map[2].style = STYLE_PASSCODE_POPUP;
g_func_map[2].view = &g_passcodePopup;
g_func_map[3].style = STYLE_CLOCK_CTXPOPUP;
g_func_map[3].view = &g_systemclock;
g_func_map[4].style = STYLE_NEED_PASSCODE;
g_func_map[4].view = &g_needpasscode;
instance->m->win = win;
instance->m->depth = 0;
instance->m->data = data;
instance->m->handler = handler;
instance->m->is_freeze = EINA_FALSE;
instance->m->view_list = NULL;
instance->m->item_path = NULL;
return true;
}
/**
* This function is invoked to destroy all views stored in view list and release
* SSettingMgr data structure.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return void.
*/
void CSettingMgr::Finalize(void)
{
ASSERT(instance);
ASSERT(instance->m);
struct _settinginfo *sinfo;
void* obj;
_hide_view_in_list(instance->m);
_destroy_views_in_list(instance->m);
EINA_LIST_FREE(instance->m->view_list, obj)
{
sinfo = (struct _settinginfo *)obj;
free(sinfo);
}
if (instance->m->item_path)
eina_array_free(instance->m->item_path);
viewmgr_data_fini(instance->m->data);
timeout_handler_fini(instance->m->handler);
delete instance->m;
delete instance;
instance = NULL;
}
CSettingMgr *CSettingMgr::GetInstance(void)
{
return instance;
}
/**
* This function is invoked to push a view with specific name and data.
*
* Firstly, it will build view data, then get specific view class to create view.
* Otherwise, it will freeze or hide background view and store _settinginfo data into view list.
*
* @param mgr [in] The SSettingMgr data pointer.
* @param name [in] The item name to be pushed view.
* @param data [in] The function specific data passed by caller.
* @return 0 if success, -1 if fail.
*/
bool CSettingMgr::ViewPush(const char *name, void *data)
{
ASSERT(m);
ASSERT(name);
struct _settinginfo *sinfo;
CSettingBaseView *sclass;
struct settingview_data *view;
m->depth++;
sinfo = new _settinginfo;
if (!sinfo)
return false;
view = _build_setting_view(m, name);
if (!view) {
_ERR("Build setting view data failed\n");
goto error;
}
sclass = _get_view_class(m, view);
if (!sclass) {
_ERR("failed to get view class.");
goto error;
}
if (!sclass->Create(view, data)) {
_ERR("failed to create base layout.");
goto error;
}
_frozen_view_in_list(m);
if (sclass->hide_view)
_hide_view_in_list(m);
sclass->Show();
sinfo->base = sclass->Base();
sinfo->sclass = sclass;
sinfo->sview = view;
m->view_list = eina_list_prepend(m->view_list, sinfo);
return 0;
error:
m->depth--;
free(sinfo);
viewdata_release(view);
return -1;
}
/**
* This function is invoked to pop top view.
*
* Firstly, get top view's _settinginfo data from view list, then call destroy interface of
* view class, finally it will refresh second view, activate and show all views behind top view.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return void.
*/
void CSettingMgr::ViewPop(void)
{
ASSERT(m);
struct _settinginfo *sinfo, *prev;
CSettingBaseView *sclass;
int hide;
char *item;
const char *title;
m->depth--;
sinfo = (struct _settinginfo *) eina_list_data_get(m->view_list);
if (!sinfo) {
_DBG("get sinfo failed\n");
return;
}
sclass = sinfo->sclass;
hide = sclass->hide_view;
title = sclass->Title();
item = NULL;
if (!strncmp(title, VCLASS_TITLE_BOTTOM_SLIDER, strlen(title)))
item = (char *)evas_object_data_del(sinfo->base, SELECTED_ITEM_ID);
sclass->Destroy();
m->view_list = eina_list_remove_list(m->view_list, m->view_list);
free(sinfo);
if (!m->view_list)
return;
prev = (struct _settinginfo *) eina_list_data_get(m->view_list);
if (!prev || !prev->sclass)
return;
sclass = prev->sclass;
if (item && !strncmp(title, VCLASS_TITLE_BOTTOM_SLIDER, strlen(title)))
evas_object_data_set(prev->base, SELECTED_ITEM_ID, item);
sclass->Refresh();
sclass->Update();
_active_view_in_list(m);
if (hide)
_show_view_in_list(m);
}
/**
* This function is invoked to get window's evas object.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return The window's evas object, NULL on error.
*/
Evas_Object *CSettingMgr::Window(void)
{
ASSERT(m);
return m->win;
}
/**
* This function is invoked to get view data with specific name.
*
* @param mgr [in] The SSettingMgr data pointer.
* @param name [in] The view name to be got.
* @return The settingview_data data pointer, NULL on error.
*/
settingview_data *CSettingMgr::GetView(const char *name)
{
ASSERT(m);
return _build_setting_view(m, name);
}
/**
* This function is invoked to get setting manager data.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return The settingmgr_data data pointer, NULL on error.
*/
settingmgr_data *CSettingMgr::GetData(void)
{
ASSERT(m);
return m->data;
}
/**
* This function is invoked to get view list.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return The Eina_List data pointer, NULL on error.
*/
Eina_List *CSettingMgr::GetViewList(void)
{
ASSERT(m);
return m->view_list;
}
/**
* This function is invoked to launch view with specific item name.
*
* When launch setting by command-line, this function will be invoked. In this launching
* way, setting will be launched and move focus to specific item.
*
* @param mgr [in] The SSettingMgr data pointer.
* @param name [in] The item name.
* @return 0 if success, -1 if fail.
*/
bool CSettingMgr::LaunchItem(const char *name)
{
ASSERT(m);
ASSERT(name);
const char *parent;
struct settingitem *item;
Eina_Array *path;
int i, cnt;
path = eina_array_new(1);
if (!path) {
_ERR("new eina array failed.");
return false;
}
eina_array_push(path, name);
parent = parser_get_parent_item_name(JSON_HELPER_FILE, name);
if (!parent) {
_ERR("get parent item name failed.");
eina_array_free(path);
return false;
}
eina_array_push(path, parent);
do {
viewmgr_data_read_jsonfile_into_hash(m->data, parent);
item = viewmgr_data_get_settingitem(m->data, parent);
if (!item)
break;
parent = settingitem_get_parentitem(item);
eina_array_push(path, parent);
} while (parent && strncmp(parent, MAINCATALOG, strlen(parent)));
m->item_path = path;
ViewPush(MAINCATALOG, NULL);
cnt = eina_array_count(path);
for (i = cnt - PATH_FACTOR; i > 0; i--)
ViewPush((const char *) eina_array_data_get(path, i), NULL);
return true;
}
/**
* This function is invoked to get item path.
*
* Item path is a value described all node value from root node to item
* in setting tree of json files.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return The Eina_Array data pointer, NULL on error.
*/
Eina_Array *CSettingMgr::GetItemPath(void)
{
ASSERT(m);
return m->item_path;
}
/**
* This function is invoked to refresh all view stored in view list.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return void.
*/
void CSettingMgr::ViewRefresh(void)
{
ASSERT(m);
struct _settinginfo *info;
CSettingBaseView *vclass;
if (!m->view_list)
return;
info = (struct _settinginfo *) eina_list_data_get(m->view_list);
if (!info)
return;
vclass = info->sclass;
vclass->Refresh();
vclass->Update();
}
/**
* This function is invoked to set refresh flag.
*
* @param mgr [in] The SSettingMgr data pointer.
* @param val [in] The value to be set.
* @return void.
*/
void CSettingMgr::SetRefreshFlag(unsigned int val)
{
ASSERT(m);
m->refresh = val;
}
/**
* This function is invoked to get refresh flag.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return The refresh flag value, -1 if fail.
*/
unsigned int CSettingMgr::GetRefreshFlag(void)
{
ASSERT(m);
return m->refresh;
}
/**
* This function is invoked to set relaunch flag.
*
* @param mgr [in] The SSettingMgr data pointer.
* @param val [in] The value to be set.
* @return void.
*/
void CSettingMgr::SetRelaunchFlag(unsigned int val)
{
ASSERT(m);
m->relaunch = val;
}
/**
* This function is invoked to get relaunch flag.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return The refresh flag value, -1 if fail.
*/
unsigned int CSettingMgr::GetRelaunchFlag(void)
{
ASSERT(m);
return m->relaunch;
}
/**
* This function wrapped timeout_handler interface to freeze timer.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return void.
*/
void CSettingMgr::FreezeTimeout(void)
{
ASSERT(m);
m->is_freeze = EINA_TRUE;
timeout_handler_freeze_timer(m->handler);
}
/**
* This function wrapped timeout_handler interface to thaw timer.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return void.
*/
void CSettingMgr::ThawTimeout(void)
{
ASSERT(m);
timeout_handler_thaw_timer(m->handler);
m->is_freeze = EINA_FALSE;
}
/**
* This function is invoked to get timeout freeze state.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return EINA_TRUE if current state is frozen
* EINA_FALSE if current state is normal or occurred error.
*/
Eina_Bool CSettingMgr::GetTimeoutFreezeState(void)
{
ASSERT(m);
return m->is_freeze;
}
/**
* This function is invoked to refresh all views when system language changed.
*
* @param mgr [in] The SSettingMgr data pointer.
* @return void.
*/
void CSettingMgr::LangChanged(void)
{
ASSERT(m);
struct _settinginfo *sinfo;
Eina_List *l;
void* obj;
if (!m->view_list) {
_ERR("Invalid argument");
return;
}
EINA_LIST_FOREACH(m->view_list, l, obj) {
sinfo = (struct _settinginfo *) obj;
if (!sinfo || !sinfo->sclass) {
_ERR("settings info is NULL");
return;
}
sinfo->sclass->LangChanged();
}
}
|