In my university lab course I want to implement the tomboy REST API as akonadi resource:
Current plan is to use the QNetworkAccessManager class for this.
For testing I will use Grauphel (Owncloud) on server side.
Description of the API:
I need also a library that implements OAuth 1.0. For now I have two candidates:
I think the better candidate is QOAuth because it looks lesser dead than the other. But what think you?
o2 (https://github.com/pipacs/o2) looks good as well, supports OAuth1 and seems to be still maintained.
From my own experience with writing Akonadi resources, you should consider using KIO's KJob instead of directly using QNetworkAccessManager: KIO gives you integration with KDE proxy settings, certificate chain and other goodies, and the design pattern of KJobs is well-suited for the ResourceBase API, as it enforces statelessness (is that a word?), which is a good way to prevent unexpected and hard-to-debug issues in the resources.
Feel free to talk to us on kde-pim mailinglist or #kontact IRC channel if you need any help or have some questions regarding Akonadi (our tutorials and manuals are slightly outdated, so you might get in trouble even if you follow them...)
thank you for your comment.
QOAuth is no option anymore because it's not working properly. Using kQOAuth could be also problematic because it support only HTTP POST and not HTTP PUT. The API description is unclear in this point.
So o2 is an interesting option because it does only OAuth and the other stuff is done directly with QNetworkAccessManager.
But I don't understand how I could use KIO::KJob. Some example resource would be helpful. But for this I'll write a mail soon.
Link to the repository:
A little status update:
For OAuth I use now the suggested o2. Because of cmake it was a little bit difficult getting it working.
I want to use the following KJob classes:
it should provide the full OAuth stuff using the library o2
It's needed for the configuration it should do the OAuth registration process
getting the client credentials
It should retrieve all items
It should get the specific item
For the first 3 classes I have a rudimentary implementation now. I use o2 and KIO::AccessManager (o2 needs a QNetworkAccessManager!) for accessing the server. I parse the received data with QJsonDocument.
Current question is, how I have to save the notes data in Akonadi::Item. I studied the code of KJots and I think I have to use KMime:Message, but the details are still unclear.
I hope I have the right idea now:
KMime::Message::Ptr akonadiNote = KMime::Message::Ptr(new KMime::Message);
akonadiNote->subject(true)->fromUnicodeString( jsonNote["title"].toString(), "utf-8" );
Problem is now the debugging. How can read the debug messages like
qCDebug(log_tomboynotesresource) << "Resource started";
The OAuth authentication works now. Also getting access to seems to be working (no QNetwork-Reply error).
So the problem now seems to be parsing the JSON data. I think I use QJsonDocument not correctly.
The KJobs are now asyncron. I have now a new KJob for receiving the collections. This is needed for receiving the remote id.
A little update from yesterday: Getting all items with correct id works now.
I have also now a Job class for collections for getting the global sync revision. This also seems to be working now.
I'm now working on getting the notes content. On the beginning this was a little confusing because the mime type wasn't correctly, so the corresponding method wasn't called
I get now also now content and the remote revision. I think that I had not set everything correctly from the original item, so that the result wasn't recognized properly. I now doing this:
resultItem = Akonadi::Item(item);
The setPayload part seems to to be invalid, so the note content is not visible at the moment.
The resource provides read-only access now. The next steps are a network error handling and a configuration dialog.
The resource provides a configuration dialog now
Today a was working on the write access. The deletion of an note works now, but the resource blocks after this operation and is then unusable.
Adding and modifying don't work at the moment. The note data seems not to be available as payload.
Reading, deleting and modifying works now. Adding is still a problem. A reason could be the date format.
And adding works also now :)
Believe never the documentation ;)
Diff added to phabricator