Tizen 2.0 Release
[apps/home/wrt-setting.git] / webapp-detail / wac_feature.cpp
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://floralicense.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 <dpl/foreach.h>
18 #include "wac_feature.h"
19 #include "util.h"
20 #include <ace-settings/ace_api_settings.h>
21
22 namespace WebAppDetailSetting {
23
24 const char *WacFeature::m_feature[] = {
25     "http://wacapps.net/api/accelerometer",
26     "http://wacapps.net/api/orientation",
27     "http://wacapps.net/api/camera",
28     "http://wacapps.net/api/devicestatus",
29     "http://wacapps.net/api/filesystem",
30     "http://wacapps.net/api/messaging",
31     "http://www.w3.org/TR/geolocation-API/",
32     "http://wacapps.net/api/pim.contact",
33     "http://wacapps.net/api/pim.calendar",
34     "http://wacapps.net/api/pim.task",
35     "http://wacapps.net/api/deviceinteraction",
36 };
37
38 /* FIXME: i18n */
39 const char *WacFeature::m_featureName[] = {
40     N_("Accelerometer"),
41     N_("Rotation"),
42     N_("Camera"),
43     N_("Device status"),
44     N_("File system"),
45     N_("Messaging"),
46     N_("Location"),
47     N_("Contacts"),
48     N_("Calendar"),
49     N_("Task"),
50     N_("Device interaction"),
51 };
52
53 std::map<int, Feature> WacFeature::getFeatureMap(
54         WrtDB::DbWidgetFeatureSet &features,
55         int appID)
56 {
57     std::string uri;
58     std::map<int, Feature> featureMap;
59     unsigned int i;
60
61     FOREACH(feature, features) {
62         for (i = 0; i < sizeof(m_feature) / sizeof(*m_feature); i++) {
63             if (featureMap.find(i) != featureMap.end())
64                 continue;
65
66             uri = DPL::ToUTF8String(feature->name);
67             if (!uri.compare(0,
68                         strlen(m_feature[i]),
69                         m_feature[i])) {
70                 featureMap[i] = Feature(m_featureName[i],
71                                 m_feature[i]);
72                 ace_preference_t perm;
73                 ace_get_widget_resource_preference(
74                         appID,
75                         const_cast<char *>(m_feature[i]),
76                         &perm);
77                 featureMap[i].setPerm(perm);
78
79                 break;
80             }
81         }
82     }
83
84     return featureMap;
85 }
86
87 } /* WebAppDetailSetting */