summaryrefslogtreecommitdiff
path: root/alarm-app/src/Input/TimePicker.cpp
blob: 263d715a99a70a199831a111b99edca266348d6a (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
/*
 * Copyright 2017 Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://floralicense.org/license/
 *
 * 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 "Input/TimePicker.h"
#include "System/Settings.h"
#include "Ui/Window.h"
#include "Utils/Callback.h"

using namespace Input;
using namespace std::placeholders;

TimePicker::TimePicker()
{
	System::Settings::addCallback(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR,
			{ std::bind(&TimePicker::onFormatChanged, this, _1), this });
}

TimePicker::~TimePicker()
{
	System::Settings::removeCallback(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, this);
}

tm TimePicker::getTime() const
{
	tm time = { 0 };
	elm_datetime_value_get(getEvasObject(), &time);
	return time;
}

void TimePicker::setTime(const tm &time)
{
	elm_datetime_value_set(getEvasObject(), &time);
}

Evas_Object *TimePicker::onCreate(Evas_Object *parent)
{
	auto surface = findParent<Ui::Window>(parent)->getCircleConformant();

	Evas_Object *datetime = elm_datetime_add(parent);
	eext_circle_object_datetime_add(datetime, surface);
	elm_object_style_set(datetime, "timepicker/circle");
	evas_object_smart_callback_add(datetime, "language,changed",
			makeCallback(&TimePicker::onLanguageChanged), this);
	return datetime;
}

void TimePicker::onCreated()
{
	updateFormat();
}

void TimePicker::updateFormat()
{
	bool is24hour = true;
	system_settings_get_value_bool(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, &is24hour);
	elm_datetime_format_set(getEvasObject(), is24hour ? "%%H:%%M" : "%%I:%%M %%p");
}

void TimePicker::onFormatChanged(system_settings_key_e key)
{
	updateFormat();
}

void TimePicker::onLanguageChanged(Evas_Object *datetime, void *eventInfo)
{
	updateFormat();
}