Skip to content

Commit

Permalink
Merge branch 'sync_changes' into 'master'
Browse files Browse the repository at this point in the history
[buteo-sync-plugins-email] Adapt to nemo email changes. Contributes to JB#47500

See merge request mer-core/buteo-sync-plugins-email!4
  • Loading branch information
pvuorela committed Oct 11, 2019
2 parents e06020a + f34b851 commit 085831b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion rpm/buteo-sync-plugins-email.spec
Expand Up @@ -11,7 +11,7 @@ BuildRequires: pkgconfig(Qt5Network)
BuildRequires: pkgconfig(Qt5DBus)
BuildRequires: pkgconfig(QmfClient)
BuildRequires: pkgconfig(accounts-qt5)
BuildRequires: nemo-qml-plugin-email-qt5-devel >= 0.1.72
BuildRequires: nemo-qml-plugin-email-qt5-devel >= 0.6.0
BuildRequires: buteo-syncfw-qt5-devel >= 0.6.36
Requires: buteo-syncfw-qt5-msyncd

Expand Down
42 changes: 23 additions & 19 deletions src/syncemailclient.cpp
Expand Up @@ -46,9 +46,11 @@ extern "C" void destroyPlugin(SyncEmailClient *client)

SyncEmailClient::SyncEmailClient(const QString& pluginName,
const Buteo::SyncProfile& profile,
Buteo::PluginCbInterface *cbInterface) :
ClientPlugin(pluginName, profile, cbInterface)
Buteo::PluginCbInterface *cbInterface)
: ClientPlugin(pluginName, profile, cbInterface),
m_emailAgent(nullptr)
{
connect(&m_ipcTimeout, SIGNAL(timeout()), this, SLOT(ipcTimeout()));
}

SyncEmailClient::~SyncEmailClient()
Expand All @@ -65,14 +67,12 @@ bool SyncEmailClient::init()

// if messageserver is not running, EmailAgent will attempt to start it via systemd
m_emailAgent = new EmailAgent(this);
m_emailAgent->setBackgroundProcess(true);
connect(m_emailAgent, SIGNAL(synchronizingChanged(EmailAgent::Status)), this, SLOT(syncStatusChanged(EmailAgent::Status)));
connect(m_emailAgent, SIGNAL(ipcConnectionEstablished()), this, SLOT(ipcConnected()));
return true;
}

bool SyncEmailClient::uninit()
{
disconnect(m_emailAgent, SIGNAL(synchronizingChanged(EmailAgent::Status)), this, SLOT(syncStatusChanged(EmailAgent::Status)));
delete m_emailAgent;
m_emailAgent = 0;
return true;
Expand All @@ -84,9 +84,7 @@ bool SyncEmailClient::startSync()
triggerSync();
} else {
qWarning() << Q_FUNC_INFO << "IPC not connect yet, waiting....";
connect(m_emailAgent, SIGNAL(ipcConnectionEstablished()), this, SLOT(ipcConnected()));
// Since the process running this plugin can cause a wakelock we dont want to wait long time for IPC connection
connect(&m_ipcTimeout, SIGNAL(timeout()), this, SLOT(ipcTimeout()));
m_ipcTimeout.start(30000);
}
return true;
Expand All @@ -113,32 +111,38 @@ void SyncEmailClient::connectivityStateChanged(Sync::ConnectivityType, bool)
// TODO
}

void SyncEmailClient::syncStatusChanged(EmailAgent::Status status)
void SyncEmailClient::syncStatusChanged()
{
// 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);
}
disconnect(m_emailAgent, 0, this, 0);
updateResults(Buteo::SyncResults(QDateTime::currentDateTime(), Buteo::SyncResults::SYNC_RESULT_SUCCESS,
Buteo::SyncResults::NO_ERROR));
emit success(getProfileName(), "Sync completed");
}
}

void SyncEmailClient::cancelSync()
{
disconnect(m_emailAgent, 0, this, 0);
m_emailAgent->cancelAll();
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::ipcConnected()
{
disconnect(m_emailAgent, SIGNAL(ipcConnectionEstablished()), this, SLOT(ipcConnected()));
m_ipcTimeout.stop();
// give it a bit more time to make sure all data is properly loaded
QTimer::singleShot(5000,this,SLOT(triggerSync()));
QTimer::singleShot(5000, this, SLOT(triggerSync()));
}

void SyncEmailClient::triggerSync()
{
qDebug() << Q_FUNC_INFO << "Starting scheduled sync for email account: " << m_accountId.toULongLong();

connect(m_emailAgent, SIGNAL(synchronizingChanged()), this, SLOT(syncStatusChanged()));
connect(m_emailAgent, SIGNAL(networkConnectionRequested()), this, SLOT(cancelSync()));
m_emailAgent->syncAccounts(QMailAccountIdList() << m_accountId);
}

Expand Down
5 changes: 2 additions & 3 deletions src/syncemailclient.h
Expand Up @@ -64,14 +64,13 @@ public slots:
virtual void connectivityStateChanged(Sync::ConnectivityType type, bool state);

private slots:
void syncStatusChanged(EmailAgent::Status status);
void syncStatusChanged();
void cancelSync();
void ipcConnected();
void triggerSync();
void ipcTimeout();

private:
Buteo::ProfileManager m_profileManager;
Buteo::SyncProfile *m_syncProfile;
Buteo::SyncResults m_syncResults;
EmailAgent *m_emailAgent;
QMailAccountId m_accountId;
Expand Down

0 comments on commit 085831b

Please sign in to comment.