aboutsummaryrefslogtreecommitdiffstats
path: root/src/sdk
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-07-12 18:38:16 +0000
committersaturneric <[email protected]>2024-07-12 18:38:16 +0000
commitd1d6859e2a50a78f57388ebf0a06f0636d4d0910 (patch)
tree5ac6a57abc73902aba8979ed9b67816b1e85fb9a /src/sdk
parentfeat: adjust modules loading path (diff)
downloadGpgFrontend-d1d6859e2a50a78f57388ebf0a06f0636d4d0910.tar.gz
GpgFrontend-d1d6859e2a50a78f57388ebf0a06f0636d4d0910.zip
feat: add some ui apis to sdk
Diffstat (limited to 'src/sdk')
-rw-r--r--src/sdk/CMakeLists.txt3
-rw-r--r--src/sdk/GFSDKBasic.cpp28
-rw-r--r--src/sdk/GFSDKBasic.h17
-rw-r--r--src/sdk/GFSDKExtra.cpp13
-rw-r--r--src/sdk/GFSDKModule.cpp45
-rw-r--r--src/sdk/GFSDKModule.h3
-rw-r--r--src/sdk/GFSDKUI.cpp39
-rw-r--r--src/sdk/GFSDKUI.h19
-rw-r--r--src/sdk/private/CommonUtils.cpp82
-rw-r--r--src/sdk/private/CommonUtils.h69
10 files changed, 279 insertions, 39 deletions
diff --git a/src/sdk/CMakeLists.txt b/src/sdk/CMakeLists.txt
index 59f673e0..765c0e73 100644
--- a/src/sdk/CMakeLists.txt
+++ b/src/sdk/CMakeLists.txt
@@ -28,6 +28,7 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
# define libgpgfrontend_module_sdk
aux_source_directory(. MODULE_SDK_SOURCE)
+aux_source_directory(private MODULE_SDK_SOURCE)
add_library(gpgfrontend_module_sdk SHARED ${MODULE_SDK_SOURCE})
set(_export_file_sdk "${CMAKE_CURRENT_SOURCE_DIR}/GFSDKExport.h")
@@ -39,7 +40,7 @@ target_include_directories(gpgfrontend_module_sdk PRIVATE
target_include_directories(gpgfrontend_module_sdk PUBLIC sdk)
# link module system
-target_link_libraries(gpgfrontend_module_sdk PRIVATE gpgfrontend_core)
+target_link_libraries(gpgfrontend_module_sdk PRIVATE gpgfrontend_core gpgfrontend_ui)
# sdk export headers
file(GLOB _headerPath "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
diff --git a/src/sdk/GFSDKBasic.cpp b/src/sdk/GFSDKBasic.cpp
index 4d8af6c8..aefa022a 100644
--- a/src/sdk/GFSDKBasic.cpp
+++ b/src/sdk/GFSDKBasic.cpp
@@ -31,7 +31,8 @@
#include "core/function/SecureMemoryAllocator.h"
#include "core/function/gpg/GpgCommandExecutor.h"
#include "core/utils/BuildInfoUtils.h"
-#include "core/utils/CommonUtils.h"
+#include "sdk/private/CommonUtils.h"
+#include "ui/GpgFrontendUIInit.h"
auto GFAllocateMemory(uint32_t size) -> void* {
return GpgFrontend::SecureMemoryAllocator::Allocate(size);
@@ -42,18 +43,16 @@ void GFFreeMemory(void* ptr) {
}
auto GFProjectVersion() -> const char* {
- return GpgFrontend::GFStrDup(GpgFrontend::GetProjectVersion());
+ return GFStrDup(GpgFrontend::GetProjectVersion());
}
-auto GFQtEnvVersion() -> const char* {
- return GpgFrontend::GFStrDup(QT_VERSION_STR);
-}
+auto GFQtEnvVersion() -> const char* { return GFStrDup(QT_VERSION_STR); }
void GFExecuteCommandSync(const char* cmd, int32_t argc, const char** argv,
GFCommandExeucteCallback cb, void* data) {
QStringList args;
for (int i = 0; i < argc; i++) {
- args.append(GpgFrontend::GFUnStrDup(argv[i]));
+ args.append(GFUnStrDup(argv[i]));
}
GpgFrontend::GpgCommandExecutor::ExecuteContext const context{
@@ -74,7 +73,7 @@ void GFExecuteCommandBatchSync(int32_t context_size,
QStringList args;
const char** argv = exec_context.argv;
for (int j = 0; j < exec_context.argc; j++) {
- args.append(GpgFrontend::GFUnStrDup(argv[j]));
+ args.append(GFUnStrDup(argv[j]));
}
contexts.append(
@@ -94,7 +93,7 @@ auto StrlenSafe(const char* str, size_t max_len) -> size_t {
return end - str;
}
-auto GPGFRONTEND_MODULE_SDK_EXPORT GFModuleStrDup(const char* src) -> char* {
+auto GFModuleStrDup(const char* src) -> char* {
auto len = StrlenSafe(src, kGfStrlenMax);
if (len > kGfStrlenMax) return nullptr;
@@ -103,4 +102,15 @@ auto GPGFRONTEND_MODULE_SDK_EXPORT GFModuleStrDup(const char* src) -> char* {
dst[len] = '\0';
return dst;
-} \ No newline at end of file
+}
+
+auto GFAppActiveLocale() -> char* { return GFStrDup(QLocale().name()); }
+
+auto GFAppRegisterTranslator(char* data, int size) -> int {
+ auto b = QByteArray(data, size);
+ QMetaObject::invokeMethod(QApplication::instance()->thread(), [b]() {
+ GpgFrontend::UI::InstallTranslatorFromQMData(b);
+ });
+ GFFreeMemory(data);
+ return 0;
+}
diff --git a/src/sdk/GFSDKBasic.h b/src/sdk/GFSDKBasic.h
index 07ff6ed7..2a3071cd 100644
--- a/src/sdk/GFSDKBasic.h
+++ b/src/sdk/GFSDKBasic.h
@@ -104,4 +104,21 @@ void GPGFRONTEND_MODULE_SDK_EXPORT GFExecuteCommandBatchSync(
* @return char*
*/
auto GPGFRONTEND_MODULE_SDK_EXPORT GFModuleStrDup(const char*) -> char*;
+
+/**
+ * @brief
+ *
+ * @return char*
+ */
+auto GPGFRONTEND_MODULE_SDK_EXPORT GFAppActiveLocale() -> char*;
+
+/**
+ * @brief
+ *
+ * @param data
+ * @param size
+ * @return auto
+ */
+auto GPGFRONTEND_MODULE_SDK_EXPORT GFAppRegisterTranslator(char* data, int size)
+ -> int;
} \ No newline at end of file
diff --git a/src/sdk/GFSDKExtra.cpp b/src/sdk/GFSDKExtra.cpp
index bbfa8575..00e734da 100644
--- a/src/sdk/GFSDKExtra.cpp
+++ b/src/sdk/GFSDKExtra.cpp
@@ -28,15 +28,16 @@
#include "GFSDKExtra.h"
-#include "core/utils/BuildInfoUtils.h"
-#include "core/utils/CommonUtils.h"
+#include <core/utils/BuildInfoUtils.h>
+#include <core/utils/CommonUtils.h>
+
+#include "sdk/private/CommonUtils.h"
auto GFCompareSoftwareVersion(const char *current_version,
const char *latest_version) -> int {
- return GpgFrontend::GFCompareSoftwareVersion(
- GpgFrontend::GFUnStrDup(current_version),
- GpgFrontend::GFUnStrDup(latest_version));
+ return GpgFrontend::GFCompareSoftwareVersion(GFUnStrDup(current_version),
+ GFUnStrDup(latest_version));
}
auto GFHttpRequestUserAgent() -> const char * {
- return GpgFrontend::GFStrDup(GpgFrontend::GetHttpRequestUserAgent());
+ return GFStrDup(GpgFrontend::GetHttpRequestUserAgent());
} \ No newline at end of file
diff --git a/src/sdk/GFSDKModule.cpp b/src/sdk/GFSDKModule.cpp
index 00594488..c0215a8b 100644
--- a/src/sdk/GFSDKModule.cpp
+++ b/src/sdk/GFSDKModule.cpp
@@ -29,45 +29,40 @@
#include "GFSDKModule.h"
#include <core/module/ModuleManager.h>
-#include <core/utils/CommonUtils.h>
+#include <sdk/private/CommonUtils.h>
#include "GFSDKBasic.h"
void GFModuleListenEvent(const char *module_id, const char *event_id) {
return GpgFrontend::Module::ModuleManager::GetInstance().ListenEvent(
- GpgFrontend::GFUnStrDup(module_id).toLower(),
- GpgFrontend::GFUnStrDup(event_id).toUpper());
+ GFUnStrDup(module_id).toLower(), GFUnStrDup(event_id).toUpper());
}
auto GFModuleRetrieveRTValueOrDefault(const char *namespace_, const char *key,
const char *default_value) -> const
char * {
- return GpgFrontend::GFStrDup(
- GpgFrontend::Module::RetrieveRTValueTypedOrDefault(
- GpgFrontend::GFUnStrDup(namespace_), GpgFrontend::GFUnStrDup(key),
- GpgFrontend::GFUnStrDup(default_value)));
+ return GFStrDup(GpgFrontend::Module::RetrieveRTValueTypedOrDefault(
+ GFUnStrDup(namespace_), GFUnStrDup(key), GFUnStrDup(default_value)));
}
void GFModuleUpsertRTValue(const char *namespace_, const char *key,
const char *vaule) {
- GpgFrontend::Module::UpsertRTValue(
- GpgFrontend::GFUnStrDup(namespace_).toLower(),
- GpgFrontend::GFUnStrDup(key).toLower(), GpgFrontend::GFUnStrDup(vaule));
+ GpgFrontend::Module::UpsertRTValue(GFUnStrDup(namespace_).toLower(),
+ GFUnStrDup(key).toLower(),
+ GFUnStrDup(vaule));
}
void GFModuleUpsertRTValueBool(const char *namespace_, const char *key,
int value) {
- GpgFrontend::Module::UpsertRTValue(
- GpgFrontend::GFUnStrDup(namespace_).toLower(),
- GpgFrontend::GFUnStrDup(key).toLower(), value != 0);
+ GpgFrontend::Module::UpsertRTValue(GFUnStrDup(namespace_).toLower(),
+ GFUnStrDup(key).toLower(), value != 0);
}
auto GFModuleListRTChildKeys(const char *namespace_, const char *key,
char ***child_keys) -> int32_t {
*child_keys = nullptr;
auto keys = GpgFrontend::Module::ListRTChildKeys(
- GpgFrontend::GFUnStrDup(namespace_).toLower(),
- GpgFrontend::GFUnStrDup(key).toLower());
+ GFUnStrDup(namespace_).toLower(), GFUnStrDup(key).toLower());
if (keys.empty()) return 0;
@@ -75,7 +70,7 @@ auto GFModuleListRTChildKeys(const char *namespace_, const char *key,
static_cast<char **>(GFAllocateMemory(sizeof(char **) * keys.size()));
for (int i = 0; i < keys.size(); i++) {
- (*child_keys)[i] = GpgFrontend::GFStrDup(keys[i]);
+ (*child_keys)[i] = GFStrDup(keys[i]);
}
return static_cast<int32_t>(keys.size());
@@ -86,13 +81,21 @@ void GFModuleTriggerModuleEventCallback(GFModuleEvent *module_event,
char **argv) {
auto data_object = GpgFrontend::TransferParams();
for (int i = 0; i < argc; i++) {
- data_object->AppendObject(GpgFrontend::GFUnStrDup(argv[i]));
+ data_object->AppendObject(GFUnStrDup(argv[i]));
}
auto event = GpgFrontend::Module::ModuleManager::GetInstance().SearchEvent(
- GpgFrontend::GFUnStrDup(module_event->trigger_id).toLower());
+ GFUnStrDup(module_event->trigger_id).toLower());
if (!event) return;
- event.value()->ExecuteCallback(GpgFrontend::GFUnStrDup(module_id),
- data_object);
-} \ No newline at end of file
+ event.value()->ExecuteCallback(GFUnStrDup(module_id), data_object);
+}
+
+auto GFModuleRetrieveRTValueOrDefaultBool(const char *namespace_,
+ const char *key, int default_value)
+ -> const int {
+ return static_cast<const int>(
+ GpgFrontend::Module::RetrieveRTValueTypedOrDefault(
+ GFUnStrDup(namespace_), GFUnStrDup(key),
+ static_cast<bool>(default_value)));
+}
diff --git a/src/sdk/GFSDKModule.h b/src/sdk/GFSDKModule.h
index 67c1f492..271a4ac4 100644
--- a/src/sdk/GFSDKModule.h
+++ b/src/sdk/GFSDKModule.h
@@ -79,6 +79,9 @@ auto GPGFRONTEND_MODULE_SDK_EXPORT GFModuleRetrieveRTValueOrDefault(
const char *namespace_, const char *key, const char *default_value) -> const
char *;
+auto GPGFRONTEND_MODULE_SDK_EXPORT GFModuleRetrieveRTValueOrDefaultBool(
+ const char *namespace_, const char *key, int default_value) -> const int;
+
void GPGFRONTEND_MODULE_SDK_EXPORT GFModuleUpsertRTValue(const char *namespace_,
const char *key,
const char *vaule);
diff --git a/src/sdk/GFSDKUI.cpp b/src/sdk/GFSDKUI.cpp
index 63859763..2222fca2 100644
--- a/src/sdk/GFSDKUI.cpp
+++ b/src/sdk/GFSDKUI.cpp
@@ -24,4 +24,41 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
- */ \ No newline at end of file
+ */
+
+#include "GFSDKUI.h"
+
+#include <core/utils/CommonUtils.h>
+
+#include <QMap>
+#include <QString>
+
+#include "sdk/private/CommonUtils.h"
+#include "ui/UIModuleManager.h"
+
+auto MetaDataArrayToQMap(MetaData** meta_data_array, int size)
+ -> QMap<QString, QString> {
+ QMap<QString, QString> map;
+
+ for (int i = 0; i < size; ++i) {
+ QString const key = GFUnStrDup(meta_data_array[i]->key);
+ QString const value = GFUnStrDup(meta_data_array[i]->value);
+ map.insert(key, value);
+
+ GpgFrontend::SecureFree(meta_data_array[i]);
+ }
+
+ GpgFrontend::SecureFree(meta_data_array);
+ return map;
+}
+
+auto GFUIMountEntry(const char* id, MetaData** meta_data_array,
+ int meta_data_array_size, EntryFactory factory) -> int {
+ if (id == nullptr || factory == nullptr) return -1;
+
+ auto meta_data = MetaDataArrayToQMap(meta_data_array, meta_data_array_size);
+ return GpgFrontend::UI::UIModuleManager::GetInstance().MountEntry(
+ GFUnStrDup(id), meta_data, factory)
+ ? 0
+ : -1;
+}
diff --git a/src/sdk/GFSDKUI.h b/src/sdk/GFSDKUI.h
index 0702632a..ba9a3490 100644
--- a/src/sdk/GFSDKUI.h
+++ b/src/sdk/GFSDKUI.h
@@ -26,4 +26,21 @@
*
*/
-#pragma once \ No newline at end of file
+#pragma once
+
+#include "GFSDKExport.h"
+
+extern "C" {
+
+using EntryFactory = void* (*)(const char*);
+
+struct MetaData {
+ const char* key;
+ const char* value;
+};
+
+auto GPGFRONTEND_MODULE_SDK_EXPORT GFUIMountEntry(const char* id,
+ MetaData** meta_data_array,
+ int meta_data_array_size,
+ EntryFactory factory) -> int;
+} \ No newline at end of file
diff --git a/src/sdk/private/CommonUtils.cpp b/src/sdk/private/CommonUtils.cpp
new file mode 100644
index 00000000..7d72415e
--- /dev/null
+++ b/src/sdk/private/CommonUtils.cpp
@@ -0,0 +1,82 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#include "CommonUtils.h"
+
+#include <core/utils/MemoryUtils.h>
+
+auto GFStrDup(const QString& str) -> char* {
+ auto utf8_str = str.toUtf8();
+ auto* c_str = static_cast<char*>(
+ GpgFrontend::SecureMalloc((utf8_str.size() + 1) * sizeof(char)));
+
+ memcpy(c_str, utf8_str.constData(), utf8_str.size());
+ c_str[utf8_str.size()] = '\0';
+ return c_str;
+}
+
+auto GFUnStrDup(char* str) -> QString {
+ auto qt_str = QString::fromUtf8(str);
+ GpgFrontend::SecureFree(static_cast<void*>(const_cast<char*>(str)));
+ return qt_str;
+}
+
+auto GFUnStrDup(const char* str) -> QString {
+ return GFUnStrDup(const_cast<char*>(str));
+}
+
+auto CharArrayToQMap(char** char_array, int size) -> QMap<QString, QString> {
+ QMap<QString, QString> map;
+ for (int i = 0; i < size; i += 2) {
+ QString const key = GFUnStrDup(char_array[i]);
+ QString const value = QString::fromUtf8(char_array[i + 1]);
+ map.insert(key, value);
+ }
+ return map;
+}
+
+auto QMapToCharArray(const QMap<QString, QString>& map, int& size) -> char** {
+ size = map.size() * 2;
+ char** char_array = new char*[size];
+
+ int index = 0;
+ for (auto it = map.begin(); it != map.end(); ++it) {
+ QByteArray const key = it.key().toUtf8();
+ QByteArray const value = it.value().toUtf8();
+
+ char_array[index] = new char[key.size() + 1];
+ std::strcpy(char_array[index], key.constData());
+ index++;
+
+ char_array[index] = new char[value.size() + 1];
+ std::strcpy(char_array[index], value.constData());
+ index++;
+ }
+
+ return char_array;
+} \ No newline at end of file
diff --git a/src/sdk/private/CommonUtils.h b/src/sdk/private/CommonUtils.h
new file mode 100644
index 00000000..85704797
--- /dev/null
+++ b/src/sdk/private/CommonUtils.h
@@ -0,0 +1,69 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#pragma once
+
+/**
+ * @brief
+ *
+ * @return char*
+ */
+auto GFStrDup(const QString &) -> char *;
+
+/**
+ * @brief
+ *
+ * @param str
+ * @return QString
+ */
+auto GFUnStrDup(char *str) -> QString;
+
+/**
+ * @brief
+ *
+ * @return QString
+ */
+auto GFUnStrDup(const char *) -> QString;
+
+/**
+ * @brief
+ *
+ * @param char_array
+ * @param size
+ * @return QMap<QString, QString>
+ */
+auto CharArrayToQMap(char **char_array, int size) -> QMap<QString, QString>;
+
+/**
+ * @brief
+ *
+ * @param map
+ * @param size
+ * @return char**
+ */
+auto QMapToCharArray(const QMap<QString, QString> &map, int &size) -> char **; \ No newline at end of file