Beta merge 2
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Alarm / AlarmConverter.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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/log/log.h>
18 #include <vector>
19 #include <app.h>
20 #include <time.h>
21 #include <CommonsJavaScript/Converter.h>
22 #include <CommonsJavaScript/Validator.h>
23 #include <CommonsJavaScript/JSUtils.h>
24 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
25 #include "AlarmRecurrence.h"
26 #include "JSAlarmRecurrence.h"
27 #include "AlarmConverter.h"
28
29
30
31 namespace TizenApis {
32 namespace Tizen1_0 {
33 namespace Alarm {
34
35 using namespace WrtDeviceApis::Commons;
36 using namespace WrtDeviceApis::CommonsJavaScript;
37 using namespace TizenApis::Tizen1_0::Alarm;
38 using namespace TizenApis::Api::Alarm;
39
40 AlarmConverter::AlarmConverter(JSContextRef context) : WrtDeviceApis::CommonsJavaScript::Converter(context)
41 {
42
43 }
44
45 AlarmConverter::~AlarmConverter()
46 {
47
48 }
49
50 AlarmRecurrence::alarm_frequency_e AlarmConverter::toRecurrenceFrequency(
51         std::string tizenValue) const
52 {
53     if (!tizenValue.compare(TIZEN_ALARM_PROPERTY_MINUTELY_RECURRENCE))
54         return AlarmRecurrence::MINUTELY_RECURRENCE;
55     else if (!tizenValue.compare(TIZEN_ALARM_PROPERTY_HOURLY_RECURRENCE))
56         return AlarmRecurrence::HOURLY_RECURRENCE;
57     else if (!tizenValue.compare(TIZEN_ALARM_PROPERTY_DAILY_RECURRENCE))
58         return AlarmRecurrence::DAILY_RECURRENCE;
59     else if (!tizenValue.compare(TIZEN_ALARM_PROPERTY_WEEKLY_RECURRENCE))
60         return AlarmRecurrence::WEEKLY_RECURRENCE;
61
62     return AlarmRecurrence::NO_RECURRENCE;
63 }
64
65 std::string AlarmConverter::toTizenValue(
66        AlarmRecurrence::alarm_frequency_e frequency ) const
67 {
68     switch (frequency) {
69     case AlarmRecurrence::MINUTELY_RECURRENCE:
70         return TIZEN_ALARM_PROPERTY_MINUTELY_RECURRENCE;
71     case AlarmRecurrence::HOURLY_RECURRENCE:
72         return TIZEN_ALARM_PROPERTY_HOURLY_RECURRENCE;
73     case AlarmRecurrence::DAILY_RECURRENCE:
74         return TIZEN_ALARM_PROPERTY_DAILY_RECURRENCE;
75     case AlarmRecurrence::WEEKLY_RECURRENCE:
76         return TIZEN_ALARM_PROPERTY_WEEKLY_RECURRENCE;
77     default:
78         return "";
79         break;
80     }
81 }
82
83
84 int toNativeValue(std::vector<std::string> daysOfTheWeek)
85 {
86     int nativeValue = 0;
87
88     for( unsigned int i=0; i<daysOfTheWeek.size(); i++ )
89     {
90         if( daysOfTheWeek[i]=="SU" )
91             nativeValue = nativeValue | ALARM_WEEK_FLAG_SUNDAY;
92         else if( daysOfTheWeek[i]=="MO" )
93             nativeValue = nativeValue | ALARM_WEEK_FLAG_MONDAY ;
94         else if( daysOfTheWeek[i]=="TU" )
95             nativeValue = nativeValue | ALARM_WEEK_FLAG_TUESDAY ;
96         else if( daysOfTheWeek[i]=="WE" )
97             nativeValue = nativeValue | ALARM_WEEK_FLAG_WEDNESDAY;
98         else if( daysOfTheWeek[i]=="TH" )
99             nativeValue = nativeValue | ALARM_WEEK_FLAG_THURSDAY ;
100         else if( daysOfTheWeek[i]=="FR" )
101             nativeValue = nativeValue | ALARM_WEEK_FLAG_FRIDAY ;
102         else if( daysOfTheWeek[i]=="SA" )
103             nativeValue = nativeValue | ALARM_WEEK_FLAG_SATURDAY ;
104     }
105     return nativeValue; 
106 }
107
108
109 service_h AlarmConverter::toService(std::string id)
110 {
111     service_h service;
112     service_create(&service);
113     LogError("[ILOVEFILM] Enter AlarmConverter toService std package = "  << id.c_str());    
114
115     service_set_operation(service, SERVICE_OPERATION_DEFAULT);
116     service_set_package(service, id.c_str());
117     return service;
118 }
119 service_h AlarmConverter::toService(std::string id, std::string page)
120 {
121     service_h service;
122     service_create(&service);
123
124     LogError("[ILOVEFILM] Enter AlarmConverter toService std package = "  << id.c_str());    
125     
126     service_set_operation(service, SERVICE_OPERATION_DEFAULT);
127     service_set_package(service, id.c_str());
128     return service;
129 }
130 }
131 }
132 }
133