1 #include "googledataresource.h"
4 #include "settingsadaptor.h"
6 #include <QtDBus/QDBusConnection>
11 #include <gcal_status.h>
14 using namespace Akonadi
;
16 googledataResource::googledataResource( const QString
&id
)
19 new SettingsAdaptor( Settings::self() );
20 QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ),
21 Settings::self(), QDBusConnection::ExportAdaptors
);
24 if (!(gcal
= gcal_new(GCONTACT
)))
26 gcal_set_store_xml(gcal
, 1);
29 googledataResource::~googledataResource()
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
);
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
)))
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
)
69 const QString entry_id
= item
.remoteId();
71 /* I assume that here I can report the atom::entry data?
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
);
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
);
104 * what kind of dialog to collect google acount username + password ?
109 void googledataResource::itemAdded( const Akonadi::Item
&item
, const Akonadi::Collection
&collection
)
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
)
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
)
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"