Reporting each google contact XML to akonadi (I guess it will need a format
[akonadigoogledata.git] / googledataresource.cpp
blobd344f648f30ef34f3d94f1b993ae04237ccf0ed7
1 #include "googledataresource.h"
3 #include "settings.h"
4 #include "settingsadaptor.h"
6 #include <QtDBus/QDBusConnection>
8 extern "C" {
9 #include <gcalendar.h>
10 #include <gcontact.h>
11 #include <gcal_status.h>
14 using namespace Akonadi;
16 googledataResource::googledataResource( const QString &id )
17 : ResourceBase( id )
19 new SettingsAdaptor( Settings::self() );
20 QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ),
21 Settings::self(), QDBusConnection::ExportAdaptors );
24 if (!(gcal = gcal_new(GCONTACT)))
25 exit(1);
26 gcal_set_store_xml(gcal, 1);
29 googledataResource::~googledataResource()
31 gcal_delete(gcal);
32 gcal_cleanup_contacts(&all_contacts);
35 void googledataResource::retrieveCollections()
37 // TODO: this method is called when Akonadi wants to have all the
38 // collections your resource provides.
39 // Be sure to set the remote ID and the content MIME types
42 void googledataResource::retrieveItems( const Akonadi::Collection &collection )
44 Q_UNUSED( collection );
46 Item::List items;
47 int result;
49 /* Downloading the contacts can be slow and it is blocking. Will
50 * it mess up with akonadi?
52 if ((result = gcal_get_contacts(gcal, &all_contacts)))
53 exit(1);
55 /* Each google entry has a unique ID and edit_url */
56 for (size_t i = 0; i < all_contacts.length; ++i) {
58 Item item(QLatin1String("what_is_the_mime_type?"));
59 gcal_contact_t contact = gcal_contact_element(&all_contacts, i);
60 item.setRemoteId(gcal_contact_get_id(contact));
63 itemsRetrieved(items);
66 bool googledataResource::retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts )
68 Q_UNUSED( parts );
69 const QString entry_id = item.remoteId();
70 QString xml_entry;
71 /* I assume that here I can report the atom::entry data?
73 Item newItem(item);
74 gcal_contact_t contact;
77 * And another question, are the requests in the same sequence that
78 * I informed in 'retrieveItems'? For while, I try to locate the entry...
80 for (size_t i = 0; i < all_contacts.length; ++i) {
81 contact = gcal_contact_element(&all_contacts, i);
82 if (entry_id == gcal_contact_get_id(contact)) {
83 xml_entry = gcal_contact_get_xml(contact);
84 newItem.setPayload<QString>(xml_entry);
85 return true;
90 return false;
93 void googledataResource::aboutToQuit()
95 // TODO: any cleanup you need to do while there is still an active
96 // event loop. The resource will terminate after this method returns
99 void googledataResource::configure( WId windowId )
101 Q_UNUSED( windowId );
103 /* TODO:
104 * what kind of dialog to collect google acount username + password ?
106 synchronize();
109 void googledataResource::itemAdded( const Akonadi::Item &item, const Akonadi::Collection &collection )
111 Q_UNUSED( item );
112 Q_UNUSED( collection );
114 // TODO: this method is called when somebody else, e.g. a client application,
115 // has created an item in a collection managed by your resource.
117 // NOTE: There is an equivalent method for collections, but it isn't part
118 // of this template code to keep it simple
121 void googledataResource::itemChanged( const Akonadi::Item &item, const QSet<QByteArray> &parts )
123 Q_UNUSED( item );
124 Q_UNUSED( parts );
126 // TODO: this method is called when somebody else, e.g. a client application,
127 // has changed an item managed by your resource.
129 // NOTE: There is an equivalent method for collections, but it isn't part
130 // of this template code to keep it simple
133 void googledataResource::itemRemoved( const Akonadi::Item &item )
135 Q_UNUSED( item );
137 // TODO: this method is called when somebody else, e.g. a client application,
138 // has deleted an item managed by your resource.
140 // NOTE: There is an equivalent method for collections, but it isn't part
141 // of this template code to keep it simple
144 AKONADI_RESOURCE_MAIN( googledataResource )
146 #include "googledataresource.moc"