|Summary:||Implement tomboy REST API as Akonadi resource|
|Product:||[Frameworks and Libraries] Akonadi||Reporter:||Stefan <sstaeglich>|
|Component:||general||Assignee:||kdepim bugs <kdepim-bugs>|
|Latest Commit:||ca589ee212d2734b190383969e1a9fc5d2cd720d||Version Fixed In:||16.08|
Description Stefan 2016-05-11 11:34:46 UTC
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. Reproducible: Always Description of the API: https://wiki.gnome.org/Apps/Tomboy/Synchronization/REST/1.0
Comment 1 Stefan 2016-05-28 18:04:14 UTC
I need also a library that implements OAuth 1.0. For now I have two candidates: QOAuth: https://github.com/ayoy/qoauth kQOAuth: https://github.com/kypeli/kQOAuth I think the better candidate is QOAuth because it looks lesser dead than the other. But what think you?
Comment 2 Daniel Vrátil 2016-06-01 14:34:24 UTC
Hi, 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...)
Comment 3 Stefan 2016-06-01 15:08:16 UTC
Hello, 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.
Comment 4 Stefan 2016-06-01 16:04:40 UTC
Link to the repository: https://github.com/staeglis/tomboynotes
Comment 5 Stefan 2016-06-18 08:10:37 UTC
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: - TomboyJobBase: it should provide the full OAuth stuff using the library o2 - TomboyServerAuthenticateJob: It's needed for the configuration it should do the OAuth registration process getting the client credentials - TomboyItemsDownloadJob: It should retrieve all items - TomboyItemDownloadJob: It should get the specific item - TomboyItemUploadJob 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.
Comment 6 Stefan 2016-06-18 11:27:19 UTC
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" ); akonadiNote->contentType()->setMimeType("text/plain"); akonadiNote->contentType()->setCharset("utf-8"); akonadiNote->contentTransferEncoding(true)->setEncoding(KMime::Headers::CEquPr); akonadiNote->mainBodyPart()->fromUnicodeString(jsonNote["note-content"].toString().toUtf8()); akonadiNote->assemble(); resultItem.setPayload<KMime::Message::Ptr>(akonadiNote); Problem is now the debugging. How can read the debug messages like qCDebug(log_tomboynotesresource) << "Resource started";
Comment 7 Stefan 2016-06-19 11:44:13 UTC
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.
Comment 8 Stefan 2016-06-20 16:21:14 UTC
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
Comment 9 Stefan 2016-06-21 10:46:34 UTC
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.
Comment 10 Stefan 2016-06-21 13:05:15 UTC
The resource provides read-only access now. The next steps are a network error handling and a configuration dialog.
Comment 11 Stefan 2016-06-22 20:33:47 UTC
The resource provides a configuration dialog now
Comment 12 Stefan 2016-06-23 20:12:03 UTC
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.
Comment 13 Stefan 2016-06-25 10:10:40 UTC
Reading, deleting and modifying works now. Adding is still a problem. A reason could be the date format.
Comment 14 Stefan 2016-06-25 15:12:56 UTC
And adding works also now :) Believe never the documentation ;)
Comment 15 Stefan 2016-06-28 20:34:13 UTC
Diff added to phabricator