1 #include "feedingitsync.h"
3 #include <libsyncpluginmgr/PluginCbInterface.h>
9 #include <meventfeed.h>
11 extern "C" EventsExample* createPlugin(const QString& aPluginName,
12 const Buteo::SyncProfile& aProfile,
13 Buteo::PluginCbInterface *aCbInterface)
15 QFile file("/home/user/out.txt");
16 file.open(QIODevice::WriteOnly | QIODevice::Text);
18 QTextStream out(&file);
19 out << "create plugin \n";
21 return new EventsExample(aPluginName, aProfile, aCbInterface);
24 extern "C" void destroyPlugin(EventsExample*aClient)
29 EventsExample::EventsExample(const QString& aPluginName,
30 const Buteo::SyncProfile& aProfile,
31 Buteo::PluginCbInterface *aCbInterface) :
32 ClientPlugin(aPluginName, aProfile, aCbInterface)
37 EventsExample::~EventsExample()
42 bool EventsExample::init()
45 QFile file("/home/user/out.txt");
46 file.open(QIODevice::WriteOnly | QIODevice::Text);
48 QTextStream out(&file);
49 out << "init plugin \n";
51 //The sync profiles can have some specific key/value pairs this info
52 //can be accessed by this method.
53 iProperties = iProfile.allNonStorageKeys();
55 //return false - if error
56 //syncfw will call this method first if the plugin is able to initialize properly
57 //and its ready for sync it should return 'true' in case of any error return false.
61 bool EventsExample::uninit()
64 // called before unloading the plugin , the plugin should clean up
68 bool EventsExample::startSync()
72 // This method is called after init(), the plugin is expected to return
73 // either true or false based on if the sync was started successfully or
74 // it failed for some reason
75 //call appropriate slots based on the status of operation success/failed...
77 // Create a new GConfItem object
78 GConfItem *boolItem = new GConfItem("/apps/ControlPanel/FeedingIt/EnableUpdates");
79 if (!boolItem->value().isValid()) {
84 if (boolItem->value().toBool()) {
85 GConfItem *updateFreq = new GConfItem("/apps/ControlPanel/FeedingIt/UpdateFrequency");
87 if (!updateFreq->value().isValid()) {
90 GConfItem *runsItem = new GConfItem("/apps/ControlPanel/FeedingIt/NumberOfRuns");
91 if (!runsItem->value().isValid()) {
94 runsItem->set(runsItem->value().toInt()+1);
95 if (runsItem->value().toInt() >= updateFreq->value().toInt()) {
96 QDBusInterface feedingitdbus("org.marcoz.feedingit", "/org/marcoz/feedingit/update", "org.marcoz.feedingit");
97 feedingitdbus.call("UpdateAll");
101 QTimer::singleShot(60000, this, SLOT(syncSuccess()));
106 void EventsExample::abortSync(Sync::SyncStatus aStatus)
110 // This method is called if used cancels the
111 // sync in between , with the applet use case
112 // it should not ideally happen as there is no UI
113 // in case of device sync and accounts sync we have
117 bool EventsExample::cleanUp()
121 // this method is called in case of account being deleted
122 // or the profile being deleted from UI in case of applet
123 // it will not be called ....need to check as if there
124 // can be any use case for this
128 Buteo::SyncResults EventsExample::getSyncResults() const
134 void EventsExample::connectivityStateChanged(Sync::ConnectivityType aType,
138 // This function notifies of the plugin of any connectivity related state changes
139 LOG_DEBUG("Received connectivity change event:" << aType << " changed to " << aState);
140 if ((aType == Sync::CONNECTIVITY_INTERNET) && (aState == false)) {
141 // Network disconnect!!
145 void EventsExample::syncSuccess()
148 updateResults(Buteo::SyncResults(QDateTime::currentDateTime(), Buteo::SyncResults::SYNC_RESULT_SUCCESS, Buteo::SyncResults::NO_ERROR));
149 //Notify Sync FW of result - Now sync fw will call uninit and then will unload plugin
150 emit success(getProfileName(), "Success!!");
153 void EventsExample::syncFailed()
156 //Notify Sync FW of result - Now sync fw will call uninit and then will unload plugin
157 updateResults(Buteo::SyncResults(QDateTime::currentDateTime(),
158 Buteo::SyncResults::SYNC_RESULT_FAILED, Buteo::SyncResults::ABORTED));
159 emit error(getProfileName(), "Error!!", Buteo::SyncResults::SYNC_RESULT_FAILED);
162 void EventsExample::updateResults(const Buteo::SyncResults &aResults)
166 iResults.setScheduled(true);
169 void EventsExample::updateFeed()
173 GConfItem *boolItem = new GConfItem("/apps/ControlPanel/FeedingIt/EnableFeed");
176 if (boolItem->value().toBool()) {
177 bool success = false;
178 //Ok assuming that we now have the data that needs to be updated to event feed
179 qlonglong id = MEventFeed::instance()->addItem(QString("icon-m-transfer-sync"),
180 QString("Update Started"),
181 QString("Event Feed updated"),
183 QDateTime::currentDateTime(),
187 QString("FeedingIt"),
188 QString("FeedingIt RSS Reader"));