2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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
8 * http://floralicense.org/license/
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.
17 #include <Elementary.h>
19 #include <dpl/wrt-dao-rw/widget_dao.h>
20 #include <dpl/foreach.h>
21 #include <dpl/assert.h>
24 #include "wac_feature.h"
25 #include "tizen_feature.h"
28 namespace WebAppDetailSetting {
30 void PermView::onFeatureClicked(void */*data*/,
36 it = static_cast<Elm_Object_Item*>(event_info);
38 elm_genlist_item_selected_set(it, EINA_FALSE);
39 elm_genlist_item_expanded_set(it, !elm_genlist_item_expanded_get(it));
42 void PermView::onPermClicked(void *data,
47 FeatureData *featureData;
49 Elm_Object_Item *parent_it;
51 it = static_cast<Elm_Object_Item*>(event_info);
53 permData = static_cast<PermData *>(data);
55 featureData = permData->m_featureData;
57 ace_set_widget_resource_preference(
59 const_cast<char *>(featureData->m_feature->getUri().c_str()),
61 ace_preference_t perm;
62 ace_get_widget_resource_preference(
64 const_cast<char *>(featureData->m_feature->getUri().c_str()),
66 featureData->m_feature->setPerm(perm);
67 elm_genlist_item_selected_set(it, EINA_FALSE);
68 elm_genlist_item_update(it);
69 parent_it = elm_genlist_item_parent_get(it);
71 elm_genlist_item_update(parent_it);
74 void PermView::onExpanded(void */*data*/, Evas_Object *obj, void *event_info)
76 static Elm_Genlist_Item_Class itc;
78 Elm_Object_Item *newIt;
80 FeatureData *featureData;
82 Assert(obj && event_info);
83 it = static_cast<Elm_Object_Item *>(event_info);
84 featureData = static_cast<FeatureData *>(elm_object_item_data_get(it));
87 itc.item_style = "dialogue/1text.1icon.2/expandable2";
88 itc.func.text_get = getPermStr;
89 itc.func.content_get = getPermRadio;
90 itc.func.state_get = NULL;
91 itc.func.del = delPermData;
94 permData = new PermData(featureData, ACE_PREFERENCE_DENY);
95 newIt = elm_genlist_item_append(obj,
99 ELM_GENLIST_ITEM_NONE,
105 permData = new PermData(featureData, ACE_PREFERENCE_DENY);
106 newIt = elm_genlist_item_append(obj,
110 ELM_GENLIST_ITEM_NONE,
116 } catch (const std::bad_alloc &) {
121 void PermView::onContracted(void */*data*/,
122 Evas_Object */*obj*/,
128 it = static_cast<Elm_Object_Item *>(event_info);
129 elm_genlist_item_subitems_clear(it);
132 char *PermView::getPermStr(void *data,
133 Evas_Object */*obj*/,
134 const char */*part*/)
139 permData = static_cast<PermData *>(data);
140 switch (permData->m_type) {
141 case ACE_PREFERENCE_DENY:
143 return strdup("Deny");
144 case ACE_PREFERENCE_DEFAULT:
147 return strdup("Default");
153 Evas_Object *PermView::getPermRadio(void *data,
154 Evas_Object */*obj*/,
155 const char */*part*/)
158 FeatureData *featureData;
160 Evas_Object *radio_grp;
164 permData = static_cast<PermData *>(data);
165 featureData = permData->m_featureData;
168 radio_grp = featureData->m_rg;
170 radio = elm_radio_add(radio_grp);
174 type = static_cast<int>(permData->m_type);
175 elm_radio_state_value_set(radio, type);
176 elm_radio_group_add(radio, radio_grp);
177 if (permData->m_type == featureData->m_feature->getPerm())
178 elm_radio_value_set(radio, type);
183 void PermView::delPermData(void *data, Evas_Object */*obj*/)
187 permData = static_cast<PermData *>(data);
191 char *PermView::getFeatureTitle(void */*data*/,
192 Evas_Object */*obj*/,
193 const char */*part*/)
200 return strdup(title);
203 char *PermView::getFeatureStr(void *data,
204 Evas_Object */*obj*/,
205 const char */*part*/)
208 FeatureData *featureData;
210 featureData = static_cast<FeatureData *>(data);
214 str = featureData->m_feature->getName().c_str();
221 char *PermView::getFeatureStrWithPerm(void *data,
222 Evas_Object */*obj*/,
226 FeatureData *featureData;
228 featureData = static_cast<FeatureData *>(data);
233 if (!strcmp(part, "elm.text.1")) {
234 str = featureData->m_feature->getName().c_str();
235 } else if (!strcmp(part, "elm.text.2")) {
237 switch (featureData->m_feature->getPerm()) {
238 case ACE_PREFERENCE_DENY:
242 case ACE_PREFERENCE_DEFAULT:
256 void PermView::delFeatureData(void *data, Evas_Object */*obj*/)
258 FeatureData *featureData;
260 featureData = static_cast<FeatureData *>(data);
262 if (featureData->m_rg)
263 evas_object_del(featureData->m_rg);
268 char *PermView::getUriTitle(void */*data*/,
269 Evas_Object */*obj*/,
270 const char */*part*/)
277 return strdup(title);
280 char *PermView::getUriStr(void *data,
281 Evas_Object */*obj*/,
282 const char */*part*/)
287 uriData = static_cast<UriData *>(data);
291 str = uriData->m_uri.c_str();
298 void PermView::delUriData(void *data, Evas_Object */*obj*/)
302 uriData = static_cast<UriData*>(data);
306 void PermView::addFeatureTitle(Evas_Object *gl)
308 static Elm_Genlist_Item_Class itc;
311 itc.item_style = "dialogue/title";
312 itc.func.text_get = getFeatureTitle;
313 itc.func.content_get = NULL;
314 itc.func.state_get = NULL;
316 elm_genlist_item_append(gl,
320 ELM_GENLIST_ITEM_NONE,
325 void PermView::addFeatureWithPerm(Evas_Object *gl, int idx)
327 static Elm_Genlist_Item_Class itc;
328 FeatureData *featureData;
333 itc.item_style = "dialogue/2text.3/expandable";
334 itc.func.text_get = getFeatureStrWithPerm;
335 itc.func.content_get = NULL;
336 itc.func.state_get = NULL;
337 itc.func.del = delFeatureData;
339 rg = elm_radio_add(gl);
344 featureData = new FeatureData(&m_featureMap[idx], m_appID, rg);
345 it = elm_genlist_item_append(gl,
347 static_cast<void *>(featureData),
349 ELM_GENLIST_ITEM_TREE,
356 } catch (const std::bad_alloc &) {
361 void PermView::addFeature(Evas_Object *gl, int idx)
363 static Elm_Genlist_Item_Class itc;
364 FeatureData *featureData;
368 itc.item_style = "dialogue/1text";
369 itc.func.text_get = getFeatureStr;
370 itc.func.content_get = NULL;
371 itc.func.state_get = NULL;
372 itc.func.del = delFeatureData;
375 featureData = new FeatureData(&m_featureMap[idx], m_appID);
376 it = elm_genlist_item_append(gl,
378 static_cast<void *>(featureData),
380 ELM_GENLIST_ITEM_NONE,
387 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
388 } catch (const std::bad_alloc &) {
392 void PermView::addFeatureList(Evas_Object *gl)
394 std::map<int, Feature>::iterator it;
396 if (m_featureMap.empty())
401 case WrtDB::APP_TYPE_WAC20:
402 for (it = m_featureMap.begin(); it != m_featureMap.end(); it++)
403 addFeatureWithPerm(gl, it->first);
405 case WrtDB::APP_TYPE_TIZENWEBAPP:
406 for (it = m_featureMap.begin(); it != m_featureMap.end(); it++)
407 addFeature(gl, it->first);
413 evas_object_smart_callback_add(gl, "expanded", onExpanded, NULL);
414 evas_object_smart_callback_add(gl, "contracted", onContracted, NULL);
417 void PermView::addUriTitle(Evas_Object *gl)
419 static Elm_Genlist_Item_Class itc;
422 itc.item_style = "dialogue/title";
423 itc.func.text_get = getUriTitle;
424 itc.func.content_get = NULL;
425 itc.func.state_get = NULL;
427 elm_genlist_item_append(gl,
431 ELM_GENLIST_ITEM_NONE,
436 void PermView::addUri(Evas_Object *gl, DPL::String &uri)
439 static Elm_Genlist_Item_Class itc;
443 itc.item_style = "dialogue/1text";
444 itc.func.text_get = getUriStr;
445 itc.func.content_get = NULL;
446 itc.func.state_get = NULL;
447 itc.func.del = delUriData;
450 uriData = new UriData(DPL::ToUTF8String(uri));
451 it = elm_genlist_item_append(gl,
453 static_cast<void *>(uriData),
455 ELM_GENLIST_ITEM_NONE,
462 elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
463 } catch (const std::bad_alloc &) {
467 void PermView::addAccessInfo(Evas_Object *gl)
469 if (m_accessInfo.empty())
473 FOREACH(accessInfo, m_accessInfo)
474 addUri(gl, accessInfo->strIRI);
477 Evas_Object *PermView::createContent(Evas_Object *parent)
482 if (m_featureMap.empty() && m_accessInfo.empty()) {
483 eo = elm_layout_add(parent);
486 elm_layout_theme_set(eo, "layout", "nocontents", "full");
487 elm_object_part_text_set(eo, "elm.text", D_("IDS_COM_BODY_NO_CONTENTS"));
491 eo = elm_genlist_add(parent);
501 Evas_Object *PermView::loadView(void)
504 WrtDB::DbWidgetFeatureSet features;
509 m_dao.Reset(new WrtDB::WidgetDAO(m_appID));
510 features = m_dao->getFeaturesList();
511 m_appType = m_dao->getWidgetType().appType;
513 case WrtDB::APP_TYPE_WAC20:
514 m_featureMap = WacFeature::getFeatureMap(features, m_appID);
516 case WrtDB::APP_TYPE_TIZENWEBAPP:
517 m_featureMap = TizenFeature::getFeatureMap(features);
522 m_dao->getWidgetAccessInfo(m_accessInfo);
524 ctnt = createContent(m_parent);
531 } catch (const std::bad_alloc &) {
536 PermView::PermView(Evas_Object *parent, int appID) :
538 m_appType(WrtDB::APP_TYPE_UNKNOWN),
542 m_featureMap.clear();
543 m_accessInfo.clear();
546 PermView::~PermView(void)
550 } /* WebAppDetailSetting */