forked from nemomobile/buteo-sync-plugins-email
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncemailclient.cpp
107 lines (93 loc) · 3.32 KB
/
syncemailclient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Copyright (C) 2013 Jolla Ltd.
*
* Contributors: Valerio Valerio <valerio.valerio@jollamobile.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#include "syncemailclient.h"
#include <QDebug>
extern "C" SyncEmailClient* createPlugin(const QString& pluginName,
const Buteo::SyncProfile& profile,
Buteo::PluginCbInterface *cbInterface)
{
return new SyncEmailClient(pluginName, profile, cbInterface);
}
extern "C" void destroyPlugin(SyncEmailClient *client)
{
delete client;
}
SyncEmailClient::SyncEmailClient(const QString& pluginName,
const Buteo::SyncProfile& profile,
Buteo::PluginCbInterface *cbInterface) :
ClientPlugin(pluginName, profile, cbInterface)
{
}
SyncEmailClient::~SyncEmailClient()
{
}
bool SyncEmailClient::init()
{
m_emailAgent = EmailAgent::instance();
connect(m_emailAgent, SIGNAL(synchronizingChanged(EmailAgent::Status)), this, SLOT(syncStatusChanged(EmailAgent::Status)));
return true;
}
bool SyncEmailClient::uninit()
{
disconnect(m_emailAgent, SIGNAL(synchronizingChanged(EmailAgent::Status)), this, SLOT(syncStatusChanged(EmailAgent::Status)));
return true;
}
bool SyncEmailClient::startSync()
{
qDebug() << Q_FUNC_INFO << "Starting scheduled sync...";
m_emailAgent->accountsSync(true);
return true;
}
void SyncEmailClient::abortSync(Sync::SyncStatus status)
{
//TODO: check if there's a use case for this (some place in the UI ?)
Q_UNUSED(status)
}
Buteo::SyncResults SyncEmailClient::getSyncResults() const
{
return m_syncResults;
}
bool SyncEmailClient::cleanUp()
{
return true;
}
void SyncEmailClient::connectivityStateChanged(Sync::ConnectivityType, bool)
{
// TODO
}
void SyncEmailClient::syncStatusChanged(EmailAgent::Status status)
{
// TODO: Do we need to care about various status here ?
// if so status info needs to be added to EmailAgent
if (!m_emailAgent->synchronizing()) {
if (status == EmailAgent::Completed) {
updateResults(Buteo::SyncResults(QDateTime::currentDateTime(), Buteo::SyncResults::SYNC_RESULT_SUCCESS, Buteo::SyncResults::NO_ERROR));
emit success(getProfileName(), "Sync completed");
} else if (status == EmailAgent::Error) {
updateResults(Buteo::SyncResults(QDateTime::currentDateTime(), Buteo::SyncResults::SYNC_RESULT_FAILED, Buteo::SyncResults::ABORTED));
emit error(getProfileName(), "Sync failed", Buteo::SyncResults::SYNC_RESULT_FAILED);
}
}
}
void SyncEmailClient::updateResults(const Buteo::SyncResults &results)
{
m_syncResults = results;
m_syncResults.setScheduled(true);
}