Add translation wrapper 05/122205/10
authorZofia Abramowska <z.abramowska@samsung.com>
Thu, 30 Mar 2017 13:02:20 +0000 (15:02 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 3 Apr 2017 17:13:21 +0000 (19:13 +0200)
Add classes wrapping po transaltion for popup messages

Change-Id: Icd4d360742231ffe18c8ca459f47aa9dc9a1bcb9

src/agent/notification-daemon/CMakeLists.txt
src/agent/notification-daemon/ui/Po.cpp [new file with mode: 0644]
src/agent/notification-daemon/ui/Po.h [new file with mode: 0644]

index 5a8d33aa3aceb2a94d17df28218a657bccad322a..df7f199b635df878569fd2acdeadd5e318580a7e 100644 (file)
@@ -29,6 +29,7 @@ SET(ASKUSER_NOTIFICATION_SOURCES
     ${NOTIF_PATH}/main.cpp
     ${NOTIF_PATH}/GuiRunner.cpp
     ${NOTIF_PATH}/AskUserTalker.cpp
+    ${NOTIF_PATH}/ui/Po.cpp
     ${ASKUSER_PATH}/common/log/alog.cpp
     ${ASKUSER_PATH}/common/socket/Socket.cpp
     ${ASKUSER_PATH}/common/socket/Poll.cpp
diff --git a/src/agent/notification-daemon/ui/Po.cpp b/src/agent/notification-daemon/ui/Po.cpp
new file mode 100644 (file)
index 0000000..093efb8
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ *  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
diff --git a/src/agent/notification-daemon/ui/Po.h b/src/agent/notification-daemon/ui/Po.h
new file mode 100644 (file)
index 0000000..983cbcd
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ *  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