Commit 48f41523 authored by Shashwat Jolly's avatar Shashwat Jolly
Browse files

Create new Etebase C++ adapter

Needed for handling smart pointers and QStrgin <-> char * conversions
Also added relevant include dirs to the resource CMakeLists.txt
parent a7a40b87
......@@ -2,6 +2,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"akonadi_etesync_resource\")
set(etesyncresource_common_SRCS
etesyncadapter.cpp
etebaseadapter.cpp
)
kconfig_add_kcfg_files(etesyncresource_common_SRCS
......@@ -51,9 +52,11 @@ qt5_add_dbus_adaptor(etesyncresource_SRCS
add_executable(akonadi_etesync_resource ${etesyncresource_SRCS})
set_target_properties(akonadi_etesync_resource PROPERTIES MACOSX_BUNDLE FALSE)
target_include_directories(akonadi_etesync_resource PRIVATE ${ETESYNC_INCLUDE_DIRS})
target_include_directories(akonadi_etesync_resource PRIVATE ${ETEBASE_INCLUDE_DIRS})
target_link_libraries(akonadi_etesync_resource
${ETESYNC_LIBRARIES}
${ETEBASE_LIBRARIES}
Qt5::DBus
KF5::AkonadiAgentBase
KF5::ConfigCore
......
/*
* SPDX-FileCopyrightText: 2020 Shashwat Jolly <shashwat.jolly@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "etebaseadapter.h"
#include "etesync_debug.h"
QString QStringFromCharPtr(const CharPtr &str)
{
if (str.get() == nullptr) {
return QString();
}
const QString ret = QString::fromUtf8(str.get());
return ret;
}
EtebaseClient *etebase_client_new(const QString &client_name, const QString &server_url)
{
return etebase_client_new(charArrFromQString(client_name), charArrFromQString(server_url));
}
EtebaseAccount *etebase_account_login(const EtebaseClient *client, const QString &username, const QString &password)
{
return etebase_account_login(client, charArrFromQString(username), charArrFromQString(password));
}
/*
* SPDX-FileCopyrightText: 2020 Shashwat Jolly <shashwat.jolly@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef ETEBASEADAPTER_H
#define ETEBASEADAPTER_H
#include <etebase.h>
#include <QString>
#include <memory>
#include <vector>
#define charArrFromQString(str) ((str).isNull() ? nullptr : qUtf8Printable((str)))
struct EtebaseDeleter
{
void operator()(EtebaseClient *ptr)
{
etebase_client_destroy(ptr);
}
void operator()(EtebaseAccount *ptr)
{
etebase_account_destroy(ptr);
}
void operator()(char *ptr)
{
std::free(ptr);
}
};
using EtebaseClientPtr = std::unique_ptr<EtebaseClient, EtebaseDeleter>;
using EtebaseAccountPtr = std::unique_ptr<EtebaseAccount, EtebaseDeleter>;
using CharPtr = std::unique_ptr<char, EtebaseDeleter>;
QString QStringFromCharPtr(const CharPtr &str);
EtebaseClient *etebase_client_new(const QString &client_name, const QString &server_url);
EtebaseAccount *etebase_account_login(const EtebaseClient *client, const QString &username, const QString &password);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment