--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co.
+ *
+ * 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 src/agent/notification-daemon/ui/Po.cpp
+ * @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @brief Declaration of Po message generation class
+ */
+
+#include <cstdio>
+#include <cstdlib>
+#include <libintl.h>
+#include <map>
+#include <memory>
+#include <string>
+#include <unistd.h>
+
+#include "Po.h"
+
+#include <exception/ErrnoException.h>
+#include <policy/PkgInfo.h>
+#include <policy/PrivilegeInfo.h>
+
+namespace AskUser {
+
+namespace {
+enum class MsgType {
+ MSG_POPUP_TITLE,
+
+ MSG_POPUP_TEXT,
+ MSG_POPUP_LAUNCH_TEXT,
+
+ MSG_POPUP_CHECKBOX,
+ MSG_POPUP_ALLOW_BTN,
+ MSG_POPUP_DENY_BTN,
+
+ MSG_TOAST_DENY_TEXT,
+ MSG_TOAST_FAIL_TEXT,
+};
+
+std::map<MsgType, const char*> MSG_PO = {
+ {MsgType::MSG_POPUP_TITLE, "IDS_IDLE_HEADER_PRIVACY_REQUEST"},
+ {MsgType::MSG_POPUP_TEXT, "IDS_IDLE_POP_ALLOW_P1SS_TO_ACCESS_YOUR_P2SS_Q"},
+ {MsgType::MSG_POPUP_LAUNCH_TEXT, "IDS_IDLE_POP_ALLOW_P1SS_TO_ACCESS_YOUR_P2SS_LIST_Q"},
+ {MsgType::MSG_POPUP_CHECKBOX, "IDS_ST_OPT_DONT_SHOW_AGAIN"},
+ {MsgType::MSG_POPUP_ALLOW_BTN,"IDS_IDLE_BUTTON_ALLOW_ABB7"},
+ {MsgType::MSG_POPUP_DENY_BTN, "IDS_IDLE_BUTTON_DENY"},
+ {MsgType::MSG_TOAST_DENY_TEXT, "IDS_IDLE_TOAST_P1SS_ACCESS_TO_YOUR_P2SS_WAS_DENIED"},
+ {MsgType::MSG_TOAST_FAIL_TEXT, "IDS_IDLE_TOAST_P1SS_FAILED_TO_LAUNCH"}
+};
+
+template <typename ...Args>
+std::string makeFromFormat(const char *format, Args... args) {
+ char *buf;
+ int ret = asprintf(&buf, format, args...);
+ if (ret == -1) {
+ throw ErrnoException("asprintf failed");
+ }
+ std::unique_ptr<char, decltype(std::free) *> bufPtr(buf, std::free);
+ return std::string(buf);
+}
+
+const char *getFormat(enum MsgType type) {
+ return dgettext(PROJECT_NAME, MSG_PO[type]);
+}
+
+std::string getPkgLabel(const std::string &pkgName) {
+ PkgInfo pkgInfo(pkgName, geteuid());
+ return pkgInfo.pkgLabel();
+}
+
+std::string getPrivacyList(const std::vector<std::string> &privs) {
+ std::string privacyList = "";
+ for (auto &priv : privs) {
+ std::string privacyName = PrivilegeInfo::getPrivacyDisplayName(priv);
+ if (privacyList.find(privacyName) == std::string::npos) {
+ privacyList.append("<br/>");
+ privacyList.append(privacyName);
+ }
+ }
+ return privacyList;
+}
+} // namespace anonymous
+
+namespace Notification {
+namespace Po {
+std::string createPopupCheckMsg(const std::string &, const std::string &pkgName, const std::string &priv) {
+ return makeFromFormat(getFormat(MsgType::MSG_POPUP_TEXT), getPkgLabel(pkgName).c_str(),
+ PrivilegeInfo::getPrivacyDisplayName(priv).c_str());
+}
+std::string createPopupLaunchMsg(const std::string &, const std::string &pkgName, const std::vector<std::string> &privs) {
+ return makeFromFormat(getFormat(MsgType::MSG_POPUP_LAUNCH_TEXT), getPkgLabel(pkgName).c_str(), getPrivacyList(privs).c_str());
+}
+
+std::string createToastDenyMsg(const std::string &, const std::string &pkgName, const std::string &priv) {
+ return makeFromFormat(getFormat(MsgType::MSG_TOAST_DENY_TEXT), getPkgLabel(pkgName).c_str(),
+ PrivilegeInfo::getPrivacyDisplayName(priv).c_str());
+}
+std::string createToastFailMsg(const std::string &, const std::string &pkgName) {
+ return makeFromFormat(getFormat(MsgType::MSG_TOAST_FAIL_TEXT), getPkgLabel(pkgName).c_str());
+}
+
+std::string getPopupTitleMsg() {
+ return makeFromFormat("%s", getFormat(MsgType::MSG_POPUP_TITLE));
+}
+std::string getAllowButtonMsg() {
+ return makeFromFormat("%s", getFormat(MsgType::MSG_POPUP_ALLOW_BTN));
+}
+std::string getDenyButtonMsg() {
+ return makeFromFormat("%s", getFormat(MsgType::MSG_POPUP_DENY_BTN));
+}
+std::string getCheckBoxMsg() {
+ return makeFromFormat("%s", getFormat(MsgType::MSG_POPUP_CHECKBOX));
+}
+
+} //namespace Po
+} //namepace Notification
+} //namespace AskUser
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co.
+ *
+ * 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 src/agent/notification-daemon/ui/Po.h
+ * @author Zofia Abramowska <z.abramowska@samsung.com>
+ * @brief Declaration of Po message generation class
+ */
+
+#include <string>
+#include <vector>
+
+namespace AskUser {
+namespace Notification {
+namespace Po {
+
+std::string createPopupCheckMsg(const std::string &appName, const std::string &pkgName, const std::string &priv);
+std::string createPopupLaunchMsg(const std::string &appName, const std::string &pkgName, const std::vector<std::string> &privs);
+std::string createPrivilegeDescr(const std::string &priv);
+std::string createToastDenyMsg(const std::string &appName, const std::string &pkgName, const std::string &priv);
+std::string createToastFailMsg(const std::string &appName, const std::string &pkgName);
+
+std::string getPopupTitleMsg();
+std::string getAllowButtonMsg();
+std::string getDenyButtonMsg();
+std::string getCheckBoxMsg();
+
+} // namespace Po
+} // namespace Notification
+} // namespace AskUser