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()
41 c
.setParent(Collection::root());
42 c
.setRemoteId("google-contacts");
45 QStringList mimeTypes
;
46 mimeTypes
<< "text/directory";
47 c
.setContentMimeTypes(mimeTypes
);
49 Collection::List list
;
51 collectionsRetrieved(list
);
55 void googledataResource::retrieveItems( const Akonadi::Collection
&collection
)
57 Q_UNUSED( collection
);
62 /* Downloading the contacts can be slow and it is blocking. Will
63 * it mess up with akonadi?
65 if ((result
= gcal_get_contacts(gcal
, &all_contacts
)))
68 /* Each google entry has a unique ID and edit_url */
69 for (size_t i
= 0; i
< all_contacts
.length
; ++i
) {
71 Item
item(QLatin1String("text/directory"));
72 gcal_contact_t contact
= gcal_contact_element(&all_contacts
, i
);
73 item
.setRemoteId(gcal_contact_get_id(contact
));
78 itemsRetrieved(items
);
81 bool googledataResource::retrieveItem( const Akonadi::Item
&item
, const QSet
<QByteArray
> &parts
)
84 const QString entry_id
= item
.remoteId();
87 gcal_contact_t contact
;
88 KABC::Addressee addressee
;
89 KABC::PhoneNumber number
;
93 * And another question, are the requests in the same sequence that
94 * I informed in 'retrieveItems'? For while, I try to locate the entry...
96 for (size_t i
= 0; i
< all_contacts
.length
; ++i
) {
97 contact
= gcal_contact_element(&all_contacts
, i
);
98 if (entry_id
== gcal_contact_get_id(contact
)) {
100 temp
= gcal_contact_get_title(contact
);
101 addressee
.setNameFromString(temp
);
104 temp
= gcal_contact_get_email(contact
);
105 addressee
.insertEmail(temp
, true);
107 /* edit url: required to do edit/delete */
108 temp
= gcal_contact_get_url(contact
);
109 addressee
.setUid(temp
);
111 /* ETag: required by Google Data protocol 2.0 */
112 temp
= gcal_contact_get_etag(contact
);
114 addressee
.insertKey(key
);
116 /* TODO: telefone, address, etc */
118 newItem
.setPayload
<KABC::Addressee
>(addressee
);
127 void googledataResource::aboutToQuit()
129 // TODO: any cleanup you need to do while there is still an active
130 // event loop. The resource will terminate after this method returns
133 void googledataResource::configure( WId windowId
)
135 Q_UNUSED( windowId
);
138 * what kind of dialog to collect google acount username + password ?
143 void googledataResource::itemAdded( const Akonadi::Item
&item
, const Akonadi::Collection
&collection
)
146 Q_UNUSED( collection
);
148 // TODO: this method is called when somebody else, e.g. a client application,
149 // has created an item in a collection managed by your resource.
151 // NOTE: There is an equivalent method for collections, but it isn't part
152 // of this template code to keep it simple
155 void googledataResource::itemChanged( const Akonadi::Item
&item
, const QSet
<QByteArray
> &parts
)
160 // TODO: this method is called when somebody else, e.g. a client application,
161 // has changed an item managed by your resource.
163 // NOTE: There is an equivalent method for collections, but it isn't part
164 // of this template code to keep it simple
167 void googledataResource::itemRemoved( const Akonadi::Item
&item
)
171 // TODO: this method is called when somebody else, e.g. a client application,
172 // has deleted an item managed by your resource.
174 // NOTE: There is an equivalent method for collections, but it isn't part
175 // of this template code to keep it simple
178 AKONADI_RESOURCE_MAIN( googledataResource
)
180 #include "googledataresource.moc"