Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
PIM
KDE PIM Runtime
Commits
f5802290
Commit
f5802290
authored
Jun 19, 2020
by
Shashwat Jolly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement contact addition and deletion
parent
8b40ddd9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
57 deletions
+116
-57
resources/etesync/etesyncresource.cpp
resources/etesync/etesyncresource.cpp
+110
-51
resources/etesync/etesyncresource.h
resources/etesync/etesyncresource.h
+6
-6
No files found.
resources/etesync/etesyncresource.cpp
View file @
f5802290
...
...
@@ -17,7 +17,10 @@
#include "etesyncresource.h"
#include <AkonadiCore/ChangeRecorder>
#include <AkonadiCore/CollectionModifyJob>
#include <AkonadiCore/ItemFetchJob>
#include <AkonadiCore/ItemFetchScope>
#include <KLocalizedString>
#include <QDBusConnection>
...
...
@@ -45,10 +48,12 @@ EteSyncResource::EteSyncResource(const QString &id)
setNeedsNetwork
(
true
);
serverUrl
=
Settings
::
self
()
->
baseUrl
();
username
=
Settings
::
self
()
->
username
();
password
=
Settings
::
self
()
->
password
();
encryptionPassword
=
Settings
::
self
()
->
encryptionPassword
();
changeRecorder
()
->
itemFetchScope
().
fetchFullPayload
(
true
);
mServerUrl
=
Settings
::
self
()
->
baseUrl
();
mUsername
=
Settings
::
self
()
->
username
();
mPassword
=
Settings
::
self
()
->
password
();
mEncryptionPassword
=
Settings
::
self
()
->
encryptionPassword
();
connect
(
this
,
&
Akonadi
::
AgentBase
::
reloadConfiguration
,
this
,
&
EteSyncResource
::
onReloadConfiguration
);
...
...
@@ -76,7 +81,9 @@ void EteSyncResource::retrieveCollections()
Collection
collection
;
/// TODO: Remove temporary hack to handle only addressbooks
if
(
setupCollection
(
collection
,
journal
.
get
()))
continue
;
if
(
setupCollection
(
collection
,
journal
.
get
()))
{
continue
;
}
list
<<
collection
;
}
...
...
@@ -90,7 +97,7 @@ void EteSyncResource::retrieveCollections()
int
EteSyncResource
::
setupCollection
(
Collection
&
collection
,
EteSyncJournal
*
journal
)
{
int
typeNum
;
EteSyncCryptoManagerPtr
cryptoManager
(
etesync_journal_get_crypto_manager
(
journal
,
d
erived
,
k
eypair
.
get
()));
EteSyncCryptoManagerPtr
cryptoManager
(
etesync_journal_get_crypto_manager
(
journal
,
mD
erived
,
mK
eypair
.
get
()));
EteSyncCollectionInfoPtr
info
(
etesync_journal_get_info
(
journal
,
cryptoManager
.
get
()));
...
...
@@ -148,11 +155,10 @@ void EteSyncResource::retrieveItems(const Akonadi::Collection &collection)
qCDebug
(
ETESYNC_LOG
)
<<
"Retrieving entries"
;
EteSyncEntry
**
entries
=
qobject_cast
<
EntriesFetchJob
*>
(
job
)
->
entries
();
EteSyncJournalPtr
journal
(
etesync_journal_manager_fetch
(
j
ournalManager
.
get
(),
journalUid
));
EteSyncCryptoManagerPtr
cryptoManager
(
etesync_journal_get_crypto_manager
(
journal
.
get
(),
d
erived
,
k
eypair
.
get
()));
EteSyncJournalPtr
journal
(
etesync_journal_manager_fetch
(
mJ
ournalManager
.
get
(),
journalUid
));
EteSyncCryptoManagerPtr
cryptoManager
(
etesync_journal_get_crypto_manager
(
journal
.
get
(),
mD
erived
,
mK
eypair
.
get
()));
QMap
<
QString
,
KContacts
::
Addressee
>
contacts
;
QMap
<
QString
,
QString
>
remoteIDs
;
Item
::
List
changedItems
;
Item
::
List
removedItems
;
...
...
@@ -171,7 +177,6 @@ void EteSyncResource::retrieveItems(const Akonadi::Collection &collection)
// qCDebug(ETESYNC_LOG) << contact.uid();
if
(
action
==
QStringLiteral
(
ETESYNC_SYNC_ENTRY_ACTION_ADD
)
||
action
==
QStringLiteral
(
ETESYNC_SYNC_ENTRY_ACTION_CHANGE
))
{
contacts
[
contact
.
uid
()]
=
contact
;
remoteIDs
[
contact
.
uid
()]
=
QStringFromCharPtr
(
CharPtr
(
etesync_entry_get_uid
(
entry
.
get
())));
}
else
if
(
action
==
QStringLiteral
(
ETESYNC_SYNC_ENTRY_ACTION_DELETE
))
{
if
(
contacts
.
contains
(
contact
.
uid
()))
{
contacts
.
remove
(
contact
.
uid
());
...
...
@@ -202,25 +207,16 @@ void EteSyncResource::retrieveItems(const Akonadi::Collection &collection)
changedItems
<<
item
;
}
if
(
isIncremental
)
if
(
isIncremental
)
{
itemsRetrievedIncremental
(
changedItems
,
removedItems
);
else
}
else
{
itemsRetrieved
(
changedItems
);
}
});
job
->
start
();
}
bool
EteSyncResource
::
retrieveItem
(
const
Akonadi
::
Item
&
item
,
const
QSet
<
QByteArray
>
&
parts
)
{
// TODO: this method is called when Akonadi wants more data for a given
// item. You can only provide the parts that have been requested but you are
// allowed to provide all in one go
return
true
;
}
void
EteSyncResource
::
aboutToQuit
()
{
// TODO: any cleanup you need to do while there is still an active
...
...
@@ -230,21 +226,23 @@ void EteSyncResource::aboutToQuit()
void
EteSyncResource
::
onReloadConfiguration
()
{
Settings
::
self
()
->
load
();
s
erverUrl
=
Settings
::
self
()
->
baseUrl
();
u
sername
=
Settings
::
self
()
->
username
();
p
assword
=
Settings
::
self
()
->
password
();
e
ncryptionPassword
=
Settings
::
self
()
->
encryptionPassword
();
mS
erverUrl
=
Settings
::
self
()
->
baseUrl
();
mU
sername
=
Settings
::
self
()
->
username
();
mP
assword
=
Settings
::
self
()
->
password
();
mE
ncryptionPassword
=
Settings
::
self
()
->
encryptionPassword
();
//
s
erverUrl = QStringLiteral("http://0.0.0.0:9966");
//
u
sername = QStringLiteral("test@localhost");
//
p
assword = QStringLiteral("testetesync");
//
e
ncryptionPassword = QStringLiteral("etesync");
//
mS
erverUrl = QStringLiteral("http://0.0.0.0:9966");
//
mU
sername = QStringLiteral("test@localhost");
//
mP
assword = QStringLiteral("testetesync");
//
mE
ncryptionPassword = QStringLiteral("etesync");
qCDebug
(
ETESYNC_LOG
)
<<
"Resource config reload"
;
connect
(
this
,
&
EteSyncResource
::
initialiseDone
,
this
,
[
this
](
bool
successful
)
{
qCDebug
(
ETESYNC_LOG
)
<<
"Resource intialised"
;
if
(
successful
)
synchronize
();
if
(
successful
)
{
synchronize
();
}
});
initialise
();
...
...
@@ -253,28 +251,28 @@ void EteSyncResource::onReloadConfiguration()
void
EteSyncResource
::
initialise
()
{
// Initialise EteSync client state
mClient
=
EteSyncPtr
(
etesync_new
(
QStringLiteral
(
"Akonadi EteSync Resource"
),
s
erverUrl
));
QString
token
=
etesync_auth_get_token
(
mClient
.
get
(),
u
sername
,
p
assword
);
mClient
=
EteSyncPtr
(
etesync_new
(
QStringLiteral
(
"Akonadi EteSync Resource"
),
mS
erverUrl
));
QString
token
=
etesync_auth_get_token
(
mClient
.
get
(),
mU
sername
,
mP
assword
);
if
(
token
.
isEmpty
())
{
qCWarning
(
ETESYNC_LOG
)
<<
"Unable to obtain token from server"
;
Q_EMIT
initialiseDone
(
false
);
return
;
}
etesync_set_auth_token
(
mClient
.
get
(),
token
);
j
ournalManager
=
EteSyncJournalManagerPtr
(
etesync_journal_manager_new
(
mClient
.
get
()));
d
erived
=
etesync_crypto_derive_key
(
mClient
.
get
(),
u
sername
,
e
ncryptionPassword
);
mJ
ournalManager
=
EteSyncJournalManagerPtr
(
etesync_journal_manager_new
(
mClient
.
get
()));
mD
erived
=
etesync_crypto_derive_key
(
mClient
.
get
(),
mU
sername
,
mE
ncryptionPassword
);
// Get user keypair
EteSyncUserInfoManagerPtr
userInfoManager
(
etesync_user_info_manager_new
(
mClient
.
get
()));
EteSyncUserInfoPtr
userInfo
(
etesync_user_info_manager_fetch
(
userInfoManager
.
get
(),
u
sername
));
EteSyncUserInfoPtr
userInfo
(
etesync_user_info_manager_fetch
(
userInfoManager
.
get
(),
mU
sername
));
if
(
!
userInfo
)
{
qCWarning
(
ETESYNC_LOG
)
<<
"User info obtained from server is NULL"
;
Q_EMIT
initialiseDone
(
false
);
return
;
}
EteSyncCryptoManagerPtr
userInfoCryptoManager
(
etesync_user_info_get_crypto_manager
(
userInfo
.
get
(),
d
erived
));
EteSyncCryptoManagerPtr
userInfoCryptoManager
(
etesync_user_info_get_crypto_manager
(
userInfo
.
get
(),
mD
erived
));
k
eypair
=
EteSyncAsymmetricKeyPairPtr
(
etesync_user_info_get_keypair
(
userInfo
.
get
(),
userInfoCryptoManager
.
get
()));
mK
eypair
=
EteSyncAsymmetricKeyPairPtr
(
etesync_user_info_get_keypair
(
userInfo
.
get
(),
userInfoCryptoManager
.
get
()));
Q_EMIT
initialiseDone
(
true
);
}
...
...
@@ -282,31 +280,92 @@ void EteSyncResource::initialise()
void
EteSyncResource
::
itemAdded
(
const
Akonadi
::
Item
&
item
,
const
Akonadi
::
Collection
&
collection
)
{
// TODO: this method is called when somebody else, e.g. a client
// application, has created an item in a collection managed by your
// resource.
qCDebug
(
ETESYNC_LOG
)
<<
"Item added"
;
// NOTE: There is an equivalent method for collections, but it isn't part
// of this template code to keep it simple
EteSyncJournalPtr
journal
(
etesync_journal_manager_fetch
(
mJournalManager
.
get
(),
collection
.
remoteId
()));
EteSyncCryptoManagerPtr
cryptoManager
(
etesync_journal_get_crypto_manager
(
journal
.
get
(),
mDerived
,
mKeypair
.
get
()));
KContacts
::
VCardConverter
converter
;
QByteArray
content
=
converter
.
createVCard
(
item
.
payload
<
KContacts
::
Addressee
>
());
EteSyncSyncEntryPtr
syncEntry
(
etesync_sync_entry_new
(
ETESYNC_SYNC_ENTRY_ACTION_ADD
,
content
.
constData
()));
EteSyncEntryPtr
entry
(
etesync_entry_from_sync_entry
(
cryptoManager
.
get
(),
syncEntry
.
get
(),
collection
.
remoteRevision
()));
EteSyncEntryManagerPtr
entryManager
(
etesync_entry_manager_new
(
mClient
.
get
(),
collection
.
remoteId
()));
EteSyncEntry
*
entries
[]
=
{
entry
.
get
(),
NULL
};
etesync_entry_manager_create
(
entryManager
.
get
(),
entries
,
collection
.
remoteRevision
());
changeCommitted
(
item
);
// Update last UID in collection remoteRevision
const
QString
entryUid
=
QStringFromCharPtr
(
CharPtr
(
etesync_entry_get_uid
(
entry
.
get
())));
Collection
col
=
collection
;
col
.
setRemoteRevision
(
entryUid
);
new
CollectionModifyJob
(
col
,
this
);
}
void
EteSyncResource
::
itemChanged
(
const
Akonadi
::
Item
&
item
,
const
QSet
<
QByteArray
>
&
parts
)
{
// TODO: this method is called when somebody else, e.g. a client
// application, has changed an item managed by your resource.
qCDebug
(
ETESYNC_LOG
)
<<
"Item changed"
;
Collection
collection
=
item
.
parentCollection
();
// NOTE: There is an equivalent method for collections, but it isn't part
// of this template code to keep it simple
EteSyncJournalPtr
journal
(
etesync_journal_manager_fetch
(
mJournalManager
.
get
(),
collection
.
remoteId
()));
EteSyncCryptoManagerPtr
cryptoManager
(
etesync_journal_get_crypto_manager
(
journal
.
get
(),
mDerived
,
mKeypair
.
get
()));
KContacts
::
VCardConverter
converter
;
QByteArray
content
=
converter
.
createVCard
(
item
.
payload
<
KContacts
::
Addressee
>
());
EteSyncSyncEntryPtr
syncEntry
(
etesync_sync_entry_new
(
ETESYNC_SYNC_ENTRY_ACTION_CHANGE
,
content
.
constData
()));
EteSyncEntryPtr
entry
(
etesync_entry_from_sync_entry
(
cryptoManager
.
get
(),
syncEntry
.
get
(),
collection
.
remoteRevision
()));
EteSyncEntryManagerPtr
entryManager
(
etesync_entry_manager_new
(
mClient
.
get
(),
collection
.
remoteId
()));
EteSyncEntry
*
entries
[]
=
{
entry
.
get
(),
NULL
};
etesync_entry_manager_create
(
entryManager
.
get
(),
entries
,
collection
.
remoteRevision
());
changeCommitted
(
item
);
// Update last UID in collection remoteRevision
const
QString
entryUid
=
QStringFromCharPtr
(
CharPtr
(
etesync_entry_get_uid
(
entry
.
get
())));
collection
.
setRemoteRevision
(
entryUid
);
new
CollectionModifyJob
(
collection
,
this
);
}
void
EteSyncResource
::
itemRemoved
(
const
Akonadi
::
Item
&
item
)
{
// TODO: this method is called when somebody else, e.g. a client
// application, has deleted an item managed by your resource.
qCDebug
(
ETESYNC_LOG
)
<<
"Item removed"
<<
item
.
remoteId
();
// Collection collection = item.parentCollection();
// EteSyncJournalPtr journal(etesync_journal_manager_fetch(mJournalManager.get(), collection.remoteId()));
// EteSyncCryptoManagerPtr cryptoManager(etesync_journal_get_crypto_manager(journal.get(), mDerived, mKeypair.get()));
// KContacts::VCardConverter converter;
// QByteArray content = converter.createVCard(item.payload<KContacts::Addressee>());
// qCDebug(ETESYNC_LOG) << content.constData();
// EteSyncSyncEntryPtr syncEntry(etesync_sync_entry_new(ETESYNC_SYNC_ENTRY_ACTION_DELETE, ""));
// EteSyncEntryPtr entry(etesync_entry_from_sync_entry(cryptoManager.get(), syncEntry.get(), collection.remoteRevision()));
// EteSyncEntryManagerPtr entryManager(etesync_entry_manager_new(mClient.get(), collection.remoteId()));
// EteSyncEntry *entries[] = {entry.get(), NULL};
// etesync_entry_manager_create(entryManager.get(), entries, collection.remoteRevision());
// changeCommitted(item);
// NOTE: There is an equivalent method for collections, but it isn't part
// of this template code to keep it simple
// // Update last UID in collection remoteRevision
// const QString entryUid = QStringFromCharPtr(CharPtr(etesync_entry_get_uid(entry.get())));
// collection.setRemoteRevision(entryUid);
// new CollectionModifyJob(collection, this);
// free(entries);
}
AKONADI_RESOURCE_MAIN
(
EteSyncResource
)
resources/etesync/etesyncresource.h
View file @
f5802290
...
...
@@ -41,8 +41,6 @@ Q_SIGNALS:
protected
Q_SLOTS
:
void
retrieveCollections
()
override
;
void
retrieveItems
(
const
Akonadi
::
Collection
&
col
)
override
;
bool
retrieveItem
(
const
Akonadi
::
Item
&
item
,
const
QSet
<
QByteArray
>
&
parts
)
override
;
protected:
void
aboutToQuit
()
override
;
...
...
@@ -61,11 +59,13 @@ private Q_SLOTS:
void
onReloadConfiguration
();
private:
Akonadi
::
Collection
mResourceCollection
;
EteSyncPtr
mClient
=
nullptr
;
QString
d
erived
;
EteSyncJournalManagerPtr
j
ournalManager
=
nullptr
;
EteSyncAsymmetricKeyPairPtr
k
eypair
=
nullptr
;
QString
u
sername
,
p
assword
,
s
erverUrl
,
e
ncryptionPassword
;
QString
mD
erived
;
EteSyncJournalManagerPtr
mJ
ournalManager
=
nullptr
;
EteSyncAsymmetricKeyPairPtr
mK
eypair
=
nullptr
;
QString
mU
sername
,
mP
assword
,
mS
erverUrl
,
mE
ncryptionPassword
;
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment