Commit 5b12daa3 authored by Shashwat Jolly's avatar Shashwat Jolly
Browse files

Return smart pointers from adapter

parent 73d2f3f6
......@@ -28,7 +28,7 @@ using namespace Akonadi;
using namespace EteSyncAPI;
BaseHandler::BaseHandler(EteSyncResource *resource)
: mResource(resource), mClientState(resource->mClientState)
: mResource(resource), mClientState((resource->mClientState).get())
{
}
......@@ -62,8 +62,8 @@ void BaseHandler::setupItems(EteSyncEntry **entries, Akonadi::Collection &collec
bool BaseHandler::createEteSyncEntry(const EteSyncSyncEntry *syncEntry, const EteSyncCryptoManager *cryptoManager, const Collection &collection)
{
EteSyncEntryPtr entry(etesync_entry_from_sync_entry(cryptoManager, syncEntry, collection.remoteRevision()));
EteSyncEntryManagerPtr entryManager(etesync_entry_manager_new(mClientState->client(), collection.remoteId()));
EteSyncEntryPtr entry = etesync_entry_from_sync_entry(cryptoManager, syncEntry, collection.remoteRevision());
EteSyncEntryManagerPtr entryManager = etesync_entry_manager_new(mClientState->client(), collection.remoteId());
EteSyncEntry *entries[] = {entry.get(), NULL};
const auto result = etesync_entry_manager_create(entryManager.get(), entries, collection.remoteRevision());
if (result) {
......
......@@ -39,13 +39,13 @@ CalendarTaskBaseHandler::CalendarTaskBaseHandler(EteSyncResource *resource) : Ba
void CalendarTaskBaseHandler::getItemListFromEntries(EteSyncEntry **entries, Item::List &changedItems, Item::List &removedItems, Collection &collection, const QString &journalUid, QString &prevUid)
{
const EteSyncJournalPtr &journal = mResource->getJournal(journalUid);
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
QMap<QString, KCalendarCore::Incidence::Ptr> incidences;
for (EteSyncEntry **iter = entries; *iter; iter++) {
EteSyncEntryPtr entry(*iter);
EteSyncSyncEntryPtr syncEntry(etesync_entry_get_sync_entry(entry.get(), cryptoManager.get(), prevUid));
EteSyncSyncEntryPtr syncEntry = etesync_entry_get_sync_entry(entry.get(), cryptoManager.get(), prevUid);
CharPtr contentStr(etesync_sync_entry_get_content(syncEntry.get()));
......@@ -140,9 +140,9 @@ void CalendarTaskBaseHandler::itemAdded(const Akonadi::Item &item,
const QString journalUid = collection.remoteId();
const EteSyncJournalPtr &journal = mResource->getJournal(journalUid);
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
EteSyncSyncEntryPtr syncEntry(etesync_sync_entry_new(QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_ADD), format.toString(calendar)));
EteSyncSyncEntryPtr syncEntry = etesync_sync_entry_new(QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_ADD), format.toString(calendar));
if (!createEteSyncEntry(syncEntry.get(), cryptoManager.get(), collection)) {
return;
......@@ -165,9 +165,9 @@ void CalendarTaskBaseHandler::itemChanged(const Akonadi::Item &item,
const QString journalUid = collection.remoteId();
const EteSyncJournalPtr &journal = mResource->getJournal(journalUid);
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
EteSyncSyncEntryPtr syncEntry(etesync_sync_entry_new(QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_CHANGE), format.toString(calendar)));
EteSyncSyncEntryPtr syncEntry = etesync_sync_entry_new(QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_CHANGE), format.toString(calendar));
if (!createEteSyncEntry(syncEntry.get(), cryptoManager.get(), collection)) {
return;
......@@ -185,11 +185,11 @@ void CalendarTaskBaseHandler::itemRemoved(const Akonadi::Item &item)
const QString journalUid = collection.remoteId();
const EteSyncJournalPtr &journal = mResource->getJournal(journalUid);
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
const QString calendar = getLocalCalendar(item.remoteId());
EteSyncSyncEntryPtr syncEntry(etesync_sync_entry_new(ETESYNC_SYNC_ENTRY_ACTION_DELETE, charArrFromQString(calendar)));
EteSyncSyncEntryPtr syncEntry = etesync_sync_entry_new(QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_DELETE), calendar);
if (!createEteSyncEntry(syncEntry.get(), cryptoManager.get(), collection)) {
return;
......@@ -201,12 +201,12 @@ void CalendarTaskBaseHandler::itemRemoved(const Akonadi::Item &item)
void CalendarTaskBaseHandler::collectionAdded(const Akonadi::Collection &collection, const Akonadi::Collection &parent)
{
const QString journalUid = QStringFromCharPtr(CharPtr(etesync_gen_uid()));
EteSyncJournalPtr journal(etesync_journal_new(journalUid, ETESYNC_CURRENT_VERSION));
EteSyncJournalPtr journal = etesync_journal_new(journalUid, ETESYNC_CURRENT_VERSION);
/// TODO: Description?
EteSyncCollectionInfoPtr info(etesync_collection_info_new(etesyncCollectionType(), collection.displayName(), QString(), EteSyncDEFAULT_COLOR));
EteSyncCollectionInfoPtr info = etesync_collection_info_new(etesyncCollectionType(), collection.displayName(), QString(), EteSyncDEFAULT_COLOR);
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
etesync_journal_set_info(journal.get(), cryptoManager.get(), info.get());
......@@ -234,9 +234,9 @@ void CalendarTaskBaseHandler::collectionChanged(const Akonadi::Collection &colle
}
}
EteSyncCollectionInfoPtr info(etesync_collection_info_new(etesyncCollectionType(), collection.displayName(), QString(), journalColor));
EteSyncCollectionInfoPtr info = etesync_collection_info_new(etesyncCollectionType(), collection.displayName(), QString(), journalColor);
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
etesync_journal_set_info(journal.get(), cryptoManager.get(), info.get());
......
......@@ -47,13 +47,13 @@ void ContactHandler::getItemListFromEntries(EteSyncEntry **entries, Item::List &
{
const EteSyncJournalPtr &journal = mResource->getJournal(journalUid);
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
QMap<QString, KContacts::Addressee> contacts;
for (EteSyncEntry **iter = entries; *iter; iter++) {
EteSyncEntryPtr entry(*iter);
EteSyncSyncEntryPtr syncEntry(etesync_entry_get_sync_entry(entry.get(), cryptoManager.get(), prevUid));
EteSyncSyncEntryPtr syncEntry = etesync_entry_get_sync_entry(entry.get(), cryptoManager.get(), prevUid);
KContacts::VCardConverter converter;
CharPtr contentStr(etesync_sync_entry_get_content(syncEntry.get()));
......@@ -141,12 +141,12 @@ void ContactHandler::itemAdded(const Akonadi::Item &item,
const QString journalUid = collection.remoteId();
const EteSyncJournalPtr &journal = mResource->getJournal(journalUid);
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
KContacts::VCardConverter converter;
QByteArray content = converter.createVCard(item.payload<KContacts::Addressee>());
EteSyncSyncEntryPtr syncEntry(etesync_sync_entry_new(ETESYNC_SYNC_ENTRY_ACTION_ADD, content.constData()));
EteSyncSyncEntryPtr syncEntry = etesync_sync_entry_new(QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_ADD), QString::fromUtf8(content));
if (!createEteSyncEntry(syncEntry.get(), cryptoManager.get(), collection)) {
return;
......@@ -165,12 +165,12 @@ void ContactHandler::itemChanged(const Akonadi::Item &item,
const QString journalUid = collection.remoteId();
const EteSyncJournalPtr &journal = mResource->getJournal(journalUid);
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
KContacts::VCardConverter converter;
QByteArray content = converter.createVCard(item.payload<KContacts::Addressee>());
EteSyncSyncEntryPtr syncEntry(etesync_sync_entry_new(ETESYNC_SYNC_ENTRY_ACTION_CHANGE, content.constData()));
EteSyncSyncEntryPtr syncEntry = etesync_sync_entry_new(QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_CHANGE), QString::fromUtf8(content));
if (!createEteSyncEntry(syncEntry.get(), cryptoManager.get(), collection)) {
return;
......@@ -188,11 +188,11 @@ void ContactHandler::itemRemoved(const Akonadi::Item &item)
const QString journalUid = collection.remoteId();
const EteSyncJournalPtr &journal = mResource->getJournal(journalUid);
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
const QString contact = getLocalContact(item.remoteId());
EteSyncSyncEntryPtr syncEntry(etesync_sync_entry_new(ETESYNC_SYNC_ENTRY_ACTION_DELETE, charArrFromQString(contact)));
EteSyncSyncEntryPtr syncEntry = etesync_sync_entry_new(QStringLiteral(ETESYNC_SYNC_ENTRY_ACTION_DELETE), contact);
if (!createEteSyncEntry(syncEntry.get(), cryptoManager.get(), collection)) {
return;
......@@ -204,11 +204,11 @@ void ContactHandler::itemRemoved(const Akonadi::Item &item)
void ContactHandler::collectionAdded(const Akonadi::Collection &collection, const Akonadi::Collection &parent)
{
const QString journalUid = QStringFromCharPtr(CharPtr(etesync_gen_uid()));
EteSyncJournalPtr journal(etesync_journal_new(journalUid, ETESYNC_CURRENT_VERSION));
EteSyncJournalPtr journal = etesync_journal_new(journalUid, ETESYNC_CURRENT_VERSION);
EteSyncCollectionInfoPtr info(etesync_collection_info_new(etesyncCollectionType(), collection.displayName(), QString(), EteSyncDEFAULT_COLOR));
EteSyncCollectionInfoPtr info = etesync_collection_info_new(etesyncCollectionType(), collection.displayName(), QString(), EteSyncDEFAULT_COLOR);
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
etesync_journal_set_info(journal.get(), cryptoManager.get(), info.get());
......@@ -224,9 +224,9 @@ void ContactHandler::collectionChanged(const Akonadi::Collection &collection)
const QString journalUid = collection.remoteId();
const EteSyncJournalPtr &journal = mResource->getJournal(journalUid);
EteSyncCollectionInfoPtr info(etesync_collection_info_new(etesyncCollectionType(), collection.displayName(), QString(), EteSyncDEFAULT_COLOR));
EteSyncCollectionInfoPtr info = etesync_collection_info_new(etesyncCollectionType(), collection.displayName(), QString(), EteSyncDEFAULT_COLOR);
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal.get(), mClientState->derived(), mClientState->keypair());
etesync_journal_set_info(journal.get(), cryptoManager.get(), info.get());
......
......@@ -24,7 +24,7 @@ QString QStringFromCharPtr(const CharPtr &str)
if (str.get() == NULL) {
return QString();
}
QString ret = QString::fromLatin1(str.get());
QString ret = QString::fromUtf8(str.get());
return ret;
}
......@@ -41,12 +41,12 @@ qint32 etesync_auth_invalidate_token(const EteSync *etesync,
return etesync_auth_invalidate_token(etesync, charArrFromQString(token));
}
EteSyncCollectionInfo *etesync_collection_info_new(const QString &col_type,
const QString &display_name,
const QString &description,
qint32 color)
EteSyncCollectionInfoPtr etesync_collection_info_new(const QString &col_type,
const QString &display_name,
const QString &description,
qint32 color)
{
return etesync_collection_info_new(charArrFromQString(col_type), charArrFromQString(display_name), charArrFromQString(description), color);
return EteSyncCollectionInfoPtr(etesync_collection_info_new(charArrFromQString(col_type), charArrFromQString(display_name), charArrFromQString(description), color));
}
QString etesync_crypto_derive_key(const EteSync *etesync, const QString &salt,
......@@ -56,18 +56,18 @@ QString etesync_crypto_derive_key(const EteSync *etesync, const QString &salt,
return QStringFromCharPtr(ret);
}
EteSyncEntry *etesync_entry_from_sync_entry(const EteSyncCryptoManager *crypto_manager,
const EteSyncSyncEntry *sync_entry,
const QString &prev_uid)
EteSyncEntryPtr etesync_entry_from_sync_entry(const EteSyncCryptoManager *crypto_manager,
const EteSyncSyncEntry *sync_entry,
const QString &prev_uid)
{
return etesync_entry_from_sync_entry(crypto_manager, sync_entry, charArrFromQString(prev_uid));
return EteSyncEntryPtr(etesync_entry_from_sync_entry(crypto_manager, sync_entry, charArrFromQString(prev_uid)));
}
EteSyncSyncEntry *etesync_entry_get_sync_entry(const EteSyncEntry *entry,
const EteSyncCryptoManager *crypto_manager,
const QString &prev_uid)
EteSyncSyncEntryPtr etesync_entry_get_sync_entry(const EteSyncEntry *entry,
const EteSyncCryptoManager *crypto_manager,
const QString &prev_uid)
{
return etesync_entry_get_sync_entry(entry, crypto_manager, charArrFromQString(prev_uid));
return EteSyncSyncEntryPtr(etesync_entry_get_sync_entry(entry, crypto_manager, charArrFromQString(prev_uid)));
}
qint32 etesync_entry_manager_create(const EteSyncEntryManager *entry_manager,
......@@ -83,33 +83,33 @@ EteSyncEntry **etesync_entry_manager_list(const EteSyncEntryManager *entry_manag
return etesync_entry_manager_list(entry_manager, charArrFromQString(prev_uid), limit);
}
EteSyncEntryManager *etesync_entry_manager_new(const EteSync *etesync,
const QString &journal_uid)
EteSyncEntryManagerPtr etesync_entry_manager_new(const EteSync *etesync,
const QString &journal_uid)
{
return etesync_entry_manager_new(etesync, charArrFromQString(journal_uid));
return EteSyncEntryManagerPtr(etesync_entry_manager_new(etesync, charArrFromQString(journal_uid)));
}
EteSyncCryptoManager *etesync_journal_get_crypto_manager(const EteSyncJournal *journal,
const QString &key,
const EteSyncAsymmetricKeyPair *keypair)
EteSyncCryptoManagerPtr etesync_journal_get_crypto_manager(const EteSyncJournal *journal,
const QString &key,
const EteSyncAsymmetricKeyPair *keypair)
{
return etesync_journal_get_crypto_manager(journal, charArrFromQString(key), keypair);
return EteSyncCryptoManagerPtr(etesync_journal_get_crypto_manager(journal, charArrFromQString(key), keypair));
}
EteSyncJournal *etesync_journal_manager_fetch(const EteSyncJournalManager *journal_manager,
const QString &journal_uid)
EteSyncJournalPtr etesync_journal_manager_fetch(const EteSyncJournalManager *journal_manager,
const QString &journal_uid)
{
return etesync_journal_manager_fetch(journal_manager, charArrFromQString(journal_uid));
return EteSyncJournalPtr(etesync_journal_manager_fetch(journal_manager, charArrFromQString(journal_uid)));
}
EteSyncJournal *etesync_journal_new(const QString &uid, uint8_t version)
EteSyncJournalPtr etesync_journal_new(const QString &uid, uint8_t version)
{
return etesync_journal_new(charArrFromQString(uid), version);
return EteSyncJournalPtr(etesync_journal_new(charArrFromQString(uid), version));
}
EteSync *etesync_new(const QString &client_name, const QString &server_url)
EteSyncPtr etesync_new(const QString &client_name, const QString &server_url)
{
return etesync_new(charArrFromQString(client_name), charArrFromQString(server_url));
return EteSyncPtr(etesync_new(charArrFromQString(client_name), charArrFromQString(server_url)));
}
void etesync_set_auth_token(EteSync *etesync, const QString &token)
......@@ -117,25 +117,25 @@ void etesync_set_auth_token(EteSync *etesync, const QString &token)
etesync_set_auth_token(etesync, charArrFromQString(token));
}
EteSyncSyncEntry *etesync_sync_entry_new(const QString &action,
const QString &content)
EteSyncSyncEntryPtr etesync_sync_entry_new(const QString &action,
const QString &content)
{
return etesync_sync_entry_new(charArrFromQString(action), charArrFromQString(content));
return EteSyncSyncEntryPtr(etesync_sync_entry_new(charArrFromQString(action), charArrFromQString(content)));
}
EteSyncCryptoManager *etesync_user_info_get_crypto_manager(const EteSyncUserInfo *user_info,
const QString &key)
EteSyncCryptoManagerPtr etesync_user_info_get_crypto_manager(const EteSyncUserInfo *user_info,
const QString &key)
{
return etesync_user_info_get_crypto_manager(user_info, charArrFromQString(key));
return EteSyncCryptoManagerPtr(etesync_user_info_get_crypto_manager(user_info, charArrFromQString(key)));
}
EteSyncUserInfo *etesync_user_info_manager_fetch(const EteSyncUserInfoManager *user_info_manager,
const QString &owner)
EteSyncUserInfoPtr etesync_user_info_manager_fetch(const EteSyncUserInfoManager *user_info_manager,
const QString &owner)
{
return etesync_user_info_manager_fetch(user_info_manager, charArrFromQString(owner));
return EteSyncUserInfoPtr(etesync_user_info_manager_fetch(user_info_manager, charArrFromQString(owner)));
}
EteSyncUserInfo *etesync_user_info_new(const QString &owner, uint8_t version)
EteSyncUserInfoPtr etesync_user_info_new(const QString &owner, uint8_t version)
{
return etesync_user_info_new(charArrFromQString(owner), version);
return EteSyncUserInfoPtr(etesync_user_info_new(charArrFromQString(owner), version));
}
......@@ -98,21 +98,21 @@ QString etesync_auth_get_token(const EteSync *etesync, const QString &username,
qint32 etesync_auth_invalidate_token(const EteSync *etesync,
const QString &token);
EteSyncCollectionInfo *etesync_collection_info_new(const QString &col_type,
const QString &display_name,
const QString &description,
qint32 color);
EteSyncCollectionInfoPtr etesync_collection_info_new(const QString &col_type,
const QString &display_name,
const QString &description,
qint32 color);
QString etesync_crypto_derive_key(const EteSync *_etesync, const QString &salt,
QString etesync_crypto_derive_key(const EteSync *etesync, const QString &salt,
const QString &password);
EteSyncEntry *etesync_entry_from_sync_entry(const EteSyncCryptoManager *crypto_manager,
const EteSyncSyncEntry *sync_entry,
const QString &prev_uid);
EteSyncEntryPtr etesync_entry_from_sync_entry(const EteSyncCryptoManager *crypto_manager,
const EteSyncSyncEntry *sync_entry,
const QString &prev_uid);
EteSyncSyncEntry *etesync_entry_get_sync_entry(const EteSyncEntry *entry,
const EteSyncCryptoManager *crypto_manager,
const QString &prev_uid);
EteSyncSyncEntryPtr etesync_entry_get_sync_entry(const EteSyncEntry *entry,
const EteSyncCryptoManager *crypto_manager,
const QString &prev_uid);
qint32 etesync_entry_manager_create(const EteSyncEntryManager *entry_manager,
const EteSyncEntry *const *entries,
......@@ -121,31 +121,31 @@ qint32 etesync_entry_manager_create(const EteSyncEntryManager *entry_manager,
EteSyncEntry **etesync_entry_manager_list(const EteSyncEntryManager *entry_manager,
const QString &prev_uid, uintptr_t limit);
EteSyncEntryManager *etesync_entry_manager_new(const EteSync *etesync,
const QString &journal_uid);
EteSyncEntryManagerPtr etesync_entry_manager_new(const EteSync *etesync,
const QString &journal_uid);
EteSyncCryptoManager *etesync_journal_get_crypto_manager(const EteSyncJournal *journal,
const QString &key,
const EteSyncAsymmetricKeyPair *keypair);
EteSyncCryptoManagerPtr etesync_journal_get_crypto_manager(const EteSyncJournal *journal,
const QString &key,
const EteSyncAsymmetricKeyPair *keypair);
EteSyncJournal *etesync_journal_manager_fetch(const EteSyncJournalManager *journal_manager,
const QString &journal_uid);
EteSyncJournalPtr etesync_journal_manager_fetch(const EteSyncJournalManager *journal_manager,
const QString &journal_uid);
EteSyncJournal *etesync_journal_new(const QString &uid, uint8_t version);
EteSyncJournalPtr etesync_journal_new(const QString &uid, uint8_t version);
EteSync *etesync_new(const QString &client_name, const QString &server_url);
EteSyncPtr etesync_new(const QString &client_name, const QString &server_url);
void etesync_set_auth_token(EteSync *etesync, const QString &token);
EteSyncSyncEntry *etesync_sync_entry_new(const QString &action,
const QString &content);
EteSyncSyncEntryPtr etesync_sync_entry_new(const QString &action,
const QString &content);
EteSyncCryptoManager *etesync_user_info_get_crypto_manager(const EteSyncUserInfo *user_info,
const QString &key);
EteSyncCryptoManagerPtr etesync_user_info_get_crypto_manager(const EteSyncUserInfo *user_info,
const QString &key);
EteSyncUserInfo *etesync_user_info_manager_fetch(const EteSyncUserInfoManager *user_info_manager,
const QString &owner);
EteSyncUserInfoPtr etesync_user_info_manager_fetch(const EteSyncUserInfoManager *user_info_manager,
const QString &owner);
EteSyncUserInfo *etesync_user_info_new(const QString &owner, uint8_t version);
EteSyncUserInfoPtr etesync_user_info_new(const QString &owner, uint8_t version);
#endif
\ No newline at end of file
......@@ -39,10 +39,10 @@ void EteSyncClientState::init()
}
// Initialise EteSync client state
mClient = EteSyncPtr(etesync_new(QStringLiteral("Akonadi EteSync Resource"), mServerUrl));
mClient = etesync_new(QStringLiteral("Akonadi EteSync Resource"), mServerUrl);
mToken = etesync_auth_get_token(mClient.get(), mUsername, mPassword);
if (mToken.isEmpty()) {
qCWarning(ETESYNC_LOG) << "Unable to obtain token from server" << QString::fromLatin1(etesync_get_error_message());
qCWarning(ETESYNC_LOG) << "Unable to obtain token from server" << QStringFromCharPtr(CharPtr(etesync_get_error_message()));
Q_EMIT clientInitialised(false);
return;
}
......@@ -52,16 +52,16 @@ void EteSyncClientState::init()
// Get user keypair
EteSyncUserInfoManagerPtr userInfoManager(etesync_user_info_manager_new(mClient.get()));
EteSyncUserInfoPtr userInfo(etesync_user_info_manager_fetch(userInfoManager.get(), mUsername));
if (!userInfo) {
mUserInfo = etesync_user_info_manager_fetch(userInfoManager.get(), mUsername);
if (!mUserInfo) {
qCWarning(ETESYNC_LOG) << "User info obtained from server is NULL";
invalidateToken();
Q_EMIT clientInitialised(false);
return;
}
EteSyncCryptoManagerPtr userInfoCryptoManager(etesync_user_info_get_crypto_manager(userInfo.get(), mDerived));
EteSyncCryptoManagerPtr userInfoCryptoManager = etesync_user_info_get_crypto_manager(mUserInfo.get(), mDerived);
mKeypair = EteSyncAsymmetricKeyPairPtr(etesync_user_info_get_keypair(userInfo.get(), userInfoCryptoManager.get()));
mKeypair = EteSyncAsymmetricKeyPairPtr(etesync_user_info_get_keypair(mUserInfo.get(), userInfoCryptoManager.get()));
Q_EMIT clientInitialised(true);
}
......@@ -73,7 +73,7 @@ bool EteSyncClientState::initToken(const QString &serverUrl, const QString &user
mPassword = password;
// Initialise EteSync client state
mClient = EteSyncPtr(etesync_new(QStringLiteral("Akonadi EteSync Resource"), mServerUrl));
mClient = etesync_new(QStringLiteral("Akonadi EteSync Resource"), mServerUrl);
mToken = etesync_auth_get_token(mClient.get(), mUsername, mPassword);
if (mToken.isEmpty()) {
qCDebug(ETESYNC_LOG) << "Empty token";
......@@ -100,7 +100,7 @@ bool EteSyncClientState::initUserInfo()
{
mJournalManager = EteSyncJournalManagerPtr(etesync_journal_manager_new(mClient.get()));
EteSyncUserInfoManagerPtr userInfoManager(etesync_user_info_manager_new(mClient.get()));
mUserInfo = EteSyncUserInfoPtr(etesync_user_info_manager_fetch(userInfoManager.get(), mUsername));
mUserInfo = etesync_user_info_manager_fetch(userInfoManager.get(), mUsername);
if (!mUserInfo) {
qCWarning(ETESYNC_LOG) << "User info obtained from server is NULL";
invalidateToken();
......@@ -119,7 +119,7 @@ bool EteSyncClientState::initKeypair(const QString &encryptionPassword)
mEncryptionPassword = encryptionPassword;
mDerived = etesync_crypto_derive_key(mClient.get(), mUsername, mEncryptionPassword);
EteSyncCryptoManagerPtr userInfoCryptoManager(etesync_user_info_get_crypto_manager(mUserInfo.get(), mDerived));
EteSyncCryptoManagerPtr userInfoCryptoManager = etesync_user_info_get_crypto_manager(mUserInfo.get(), mDerived);
mKeypair = EteSyncAsymmetricKeyPairPtr(etesync_user_info_get_keypair(mUserInfo.get(), userInfoCryptoManager.get()));
if (!mKeypair) {
qCDebug(ETESYNC_LOG) << "Empty keypair";
......@@ -134,9 +134,9 @@ void EteSyncClientState::initAccount(const QString &encryptionPassword)
{
mEncryptionPassword = encryptionPassword;
mDerived = etesync_crypto_derive_key(mClient.get(), mUsername, mEncryptionPassword);
mUserInfo = EteSyncUserInfoPtr(etesync_user_info_new(mUsername, ETESYNC_CURRENT_VERSION));
mUserInfo = etesync_user_info_new(mUsername, ETESYNC_CURRENT_VERSION);
mKeypair = EteSyncAsymmetricKeyPairPtr(etesync_crypto_generate_keypair(mClient.get()));
EteSyncCryptoManagerPtr userInfoCryptoManager(etesync_user_info_get_crypto_manager(mUserInfo.get(), mDerived));
EteSyncCryptoManagerPtr userInfoCryptoManager = etesync_user_info_get_crypto_manager(mUserInfo.get(), mDerived);
etesync_user_info_set_keypair(mUserInfo.get(), userInfoCryptoManager.get(), mKeypair.get());
EteSyncUserInfoManagerPtr userInfoManager(etesync_user_info_manager_new(mClient.get()));
etesync_user_info_manager_create(userInfoManager.get(), mUserInfo.get());
......
......@@ -25,6 +25,7 @@ class EteSyncClientState : public QObject
{
Q_OBJECT
public:
typedef std::unique_ptr<EteSyncClientState> Ptr;
explicit EteSyncClientState() = default;
void init();
......
......@@ -67,8 +67,8 @@ EteSyncResource::EteSyncResource(const QString &id)
// Make local resource directory
initialiseDirectory(baseDirectoryPath());
mClientState = new EteSyncClientState();
connect(mClientState, &EteSyncClientState::clientInitialised, this, &EteSyncResource::initialiseDone);
mClientState = EteSyncClientState::Ptr(new EteSyncClientState());
connect(mClientState.get(), &EteSyncClientState::clientInitialised, this, &EteSyncResource::initialiseDone);
mClientState->init();
mHandlers.clear();
......@@ -95,7 +95,7 @@ void EteSyncResource::cleanup()
void EteSyncResource::configure(WId windowId)
{
SetupWizard wizard(mClientState);
SetupWizard wizard(mClientState.get());
if (windowId) {
wizard.setAttribute(Qt::WA_NativeWindow, true);
......@@ -173,8 +173,8 @@ bool EteSyncResource::handleTokenError()
if (etesync_get_error_code() == EteSyncErrorCode::ETESYNC_ERROR_CODE_UNAUTHORIZED) {
qCDebug(ETESYNC_LOG) << "Invalid token";
deferTask();
connect(mClientState, &EteSyncClientState::tokenRefreshed, this, &EteSyncResource::taskDone);
scheduleCustomTask(mClientState, "refreshToken", QVariant(), ResourceBase::Prepend);
connect(mClientState.get(), &EteSyncClientState::tokenRefreshed, this, &EteSyncResource::taskDone);
scheduleCustomTask(mClientState.get(), "refreshToken", QVariant(), ResourceBase::Prepend);
return false;
}
return true;
......@@ -182,7 +182,7 @@ bool EteSyncResource::handleTokenError()
void EteSyncResource::setupCollection(Collection &collection, EteSyncJournal *journal)
{
EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal, mClientState->derived(), mClientState->keypair()));
EteSyncCryptoManagerPtr cryptoManager = etesync_journal_get_crypto_manager(journal, mClientState->derived(), mClientState->keypair());
EteSyncCollectionInfoPtr info(etesync_journal_get_info(journal, cryptoManager.get()));
......@@ -296,7 +296,6 @@ void EteSyncResource::slotItemsRetrieved(KJob *job)
void EteSyncResource::aboutToQuit()
{
delete mClientState;
}
void EteSyncResource::onReloadConfiguration()
......
......@@ -84,7 +84,7 @@ private Q_SLOTS:
void slotCollectionsRetrieved(KJob *job);
private:
EteSyncClientState *mClientState = nullptr;
EteSyncClientState::Ptr mClientState;
std::vector<BaseHandler::Ptr> mHandlers;
std::map<QString, EteSyncJournalPtr> mJournalsCache;
QDateTime mJournalsCacheUpdateTime;
......
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