summaryrefslogtreecommitdiff
path: root/src/ui/popup-bin/popup.cpp
blob: 9c5cc924e55436fcf60ed5a0265096970b4db347 (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
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
/*
 *  Copyright (c) 2016 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
 */
/*
 * @file        popup.cpp
 * @author      Janusz Kozerski (j.kozerski@samsung.com)
 * @author      Sangwan Kwon (sangwan.kwon@samsung.com)
 * @version     1.0
 * @brief
 */
#include "popup.h"

#include <memory>
#include <exception>

#include "common/log.h"

#define __(str) dgettext(SERVICE_NAME, str)

using namespace CCHECKER::UI;

Popup::Popup(const app_t &app) : m_app(app)
{
	m_win = elm_win_add(nullptr, "Cert Checker Popup", ELM_WIN_NOTIFICATION);
	elm_win_indicator_opacity_set(m_win, ELM_WIN_INDICATOR_TRANSLUCENT);
	elm_win_borderless_set(m_win, EINA_TRUE);
	elm_win_alpha_set(m_win, EINA_TRUE);

	m_popup = elm_popup_add(m_win);
	this->setDefaultProperties(m_popup);

	m_box = elm_box_add(m_popup);
	this->setDefaultProperties(m_box);
	evas_object_show(m_box);

	m_title = elm_label_add(m_box);
	setDefaultProperties(m_title);
	elm_object_part_text_set(m_popup, "title,text",
		__("SID_TITLE_OCSP_VERIFICATION_FAILED"));
	elm_box_pack_end(m_box, m_title);
	evas_object_show(m_title);

	m_content = elm_label_add(m_box);
	this->setDefaultProperties(m_content);

	char *buff = NULL;
	if (m_app.app_id == std::string(CCHECKER::TEMP_APP_ID)) {
		auto content = __("SID_CONTENT_OCSP_PACKAGE VERIFICATION_FAILED");
		if (-1 == asprintf(&buff, content, m_app.pkg_id.c_str()))
			throw std::bad_alloc();
	} else {
		auto content = __("SID_CONTENT_OCSP_VERIFICATION_FAILED");
		if (-1 == asprintf(&buff, content, m_app.app_id.c_str(),
				m_app.pkg_id.c_str()))
			throw std::bad_alloc();
	}
	this->setText(m_content, buff);
	free(buff);
	elm_box_pack_end(m_box, m_content);
	evas_object_show(m_content);

	elm_object_part_content_set(m_popup, "default", m_box);

	m_keepBtn = elm_button_add(m_popup);
	elm_object_style_set(m_keepBtn, "bottom");
	elm_object_text_set(m_keepBtn, __("SID_BTN_OCSP_KEEP_APP"));
	elm_object_part_content_set(m_popup, "button1", m_keepBtn);
	m_keepType = ResponseType::KEEP;
	this->callbackRegister(m_keepBtn, &m_keepType);
	evas_object_show(m_keepBtn);

	m_uninstallBtn = elm_button_add(m_popup);
	elm_object_style_set(m_uninstallBtn, "bottom");
	elm_object_text_set(m_uninstallBtn, __("SID_BTN_OCSP_UNINSTALL_APP"));
	elm_object_part_content_set(m_popup, "button2", m_uninstallBtn);
	m_uninstallType = ResponseType::UNINSTALL;
	this->callbackRegister(m_uninstallBtn, &m_uninstallType);
	evas_object_show(m_uninstallBtn);

	evas_object_show(m_popup);
	evas_object_show(m_win);
}

Popup::~Popup()
{
	evas_object_del(m_win);
}

int Popup::response = -1;

ResponseType Popup::run(void) noexcept
{
	elm_run();
	return static_cast<ResponseType>(response);
}

void Popup::setDefaultProperties(Evas_Object *obj) noexcept
{
	// Set width as maximum, height as minimum.
	evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, 0);
	// Set width as fill parent, height as center.
	evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, 0.5);
}

void Popup::setText(Evas_Object *obj, const std::string &text) noexcept
{
	// Enable text line-break automatically.
	elm_label_line_wrap_set(obj, ELM_WRAP_WORD);
	elm_object_text_set(obj, text.c_str());
}

void Popup::callbackRegister(Evas_Object *obj, ResponseType *type) noexcept
{
	evas_object_smart_callback_add(obj, "clicked", btnClickedCb, type);
}

void Popup::btnClickedCb(void *data, Evas_Object *, void *) noexcept
{
	response = *(reinterpret_cast<int *>(data));
	LogDebug("Response : " << response);
	elm_exit();
}