1 #include "googledataresource.h"
4 #include "settingsadaptor.h"
6 #include <QtDBus/QDBusConnection>
7 #include <kabc/addressee.h>
8 #include <kabc/phonenumber.h>
12 #include <gcalendar.h>
14 #include <gcal_status.h>
17 using namespace Akonadi
;
19 googledataResource::googledataResource( const QString
&id
)
22 new SettingsAdaptor( Settings::self() );
23 QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ),
24 Settings::self(), QDBusConnection::ExportAdaptors
);
27 if (!(gcal
= gcal_new(GCONTACT
)))
29 gcal_set_store_xml(gcal
, 1);
32 googledataResource::~googledataResource()
35 gcal_cleanup_contacts(&all_contacts
);
38 void googledataResource::retrieveCollections()
40 // TODO: this method is called when Akonadi wants to have all the
41 // collections your resource provides.
42 // Be sure to set the remote ID and the content MIME types
45 void googledataResource::retrieveItems( const Akonadi::Collection
&collection
)
47 Q_UNUSED( collection
);
52 /* Downloading the contacts can be slow and it is blocking. Will
53 * it mess up with akonadi?
55 if ((result
= gcal_get_contacts(gcal
, &all_contacts
)))
58 /* Each google entry has a unique ID and edit_url */
59 for (size_t i
= 0; i
< all_contacts
.length
; ++i
) {
61 Item
item(QLatin1String("what_is_the_mime_type?"));
62 gcal_contact_t contact
= gcal_contact_element(&all_contacts
, i
);
63 item
.setRemoteId(gcal_contact_get_id(contact
));
68 itemsRetrieved(items
);
71 bool googledataResource::retrieveItem( const Akonadi::Item
&item
, const QSet
<QByteArray
> &parts
)
74 const QString entry_id
= item
.remoteId();
77 gcal_contact_t contact
;
78 KABC::Addressee addressee
;
79 KABC::PhoneNumber number
;
83 * And another question, are the requests in the same sequence that
84 * I informed in 'retrieveItems'? For while, I try to locate the entry...
86 for (size_t i
= 0; i
< all_contacts
.length
; ++i
) {
87 contact
= gcal_contact_element(&all_contacts
, i
);
88 if (entry_id
== gcal_contact_get_id(contact
)) {
90 temp
= gcal_contact_get_title(contact
);
91 addressee
.setNameFromString(temp
);
94 temp
= gcal_contact_get_email(contact
);
95 addressee
.insertEmail(temp
, true);
97 /* edit url: required to do edit/delete */
98 temp
= gcal_contact_get_url(contact
);
99 addressee
.setUid(temp
);
101 /* ETag: required by Google Data protocol 2.0 */
102 temp
= gcal_contact_get_etag(contact
);
104 addressee
.insertKey(key
);
106 /* TODO: telefone, address, etc */
108 newItem
.setPayload
<KABC::Addressee
>(addressee
);
117 void googledataResource::aboutToQuit()
119 // TODO: any cleanup you need to do while there is still an active
120 // event loop. The resource will terminate after this method returns
123 void googledataResource::configure( WId windowId
)
125 Q_UNUSED( windowId
);
128 * what kind of dialog to collect google acount username + password ?
133 void googledataResource::itemAdded( const Akonadi::Item
&item
, const Akonadi::Collection
&collection
)
136 Q_UNUSED( collection
);
138 // TODO: this method is called when somebody else, e.g. a client application,
139 // has created an item in a collection managed by your resource.
141 // NOTE: There is an equivalent method for collections, but it isn't part
142 // of this template code to keep it simple
145 void googledataResource::itemChanged( const Akonadi::Item
&item
, const QSet
<QByteArray
> &parts
)
150 // TODO: this method is called when somebody else, e.g. a client application,
151 // has changed an item managed by your resource.
153 // NOTE: There is an equivalent method for collections, but it isn't part
154 // of this template code to keep it simple
157 void googledataResource::itemRemoved( const Akonadi::Item
&item
)
161 // TODO: this method is called when somebody else, e.g. a client application,
162 // has deleted an item managed by your resource.
164 // NOTE: There is an equivalent method for collections, but it isn't part
165 // of this template code to keep it simple
168 AKONADI_RESOURCE_MAIN( googledataResource
)
170 #include "googledataresource.moc"