Changeset View
Changeset View
Standalone View
Standalone View
libksieve/ksieveui/vacation/multiimapvacationmanager.cpp
Show All 12 Lines | /* | ||||
You should have received a copy of the GNU General Public License along | You should have received a copy of the GNU General Public License along | ||||
with this program; if not, write to the Free Software Foundation, Inc., | with this program; if not, write to the Free Software Foundation, Inc., | ||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
*/ | */ | ||||
#include "multiimapvacationmanager.h" | #include "multiimapvacationmanager.h" | ||||
#include "vacationcheckjob.h" | #include "vacationcheckjob.h" | ||||
#include "util/util.h" | #include "util/util.h" | ||||
#include <managescriptsjob/checkkep14supportjob.h> | |||||
#include <managescriptsjob/parseuserscriptjob.h> | |||||
#include <kmanagesieve/sievejob.h> | |||||
#include <Akonadi/AgentInstance> | #include <Akonadi/AgentInstance> | ||||
#include <KMessageBox> | #include <KMessageBox> | ||||
#include <KLocalizedString> | #include <KLocalizedString> | ||||
using namespace KSieveUi; | using namespace KSieveUi; | ||||
MultiImapVacationManager::MultiImapVacationManager(QObject *parent) | MultiImapVacationManager::MultiImapVacationManager(QObject *parent) | ||||
: QObject(parent), | : QObject(parent), | ||||
mNumberOfJobs(0), | mNumberOfJobs(0), | ||||
mQuestionAsked(false), | |||||
mCheckInProgress(false) | mCheckInProgress(false) | ||||
{ | { | ||||
} | } | ||||
MultiImapVacationManager::~MultiImapVacationManager() | MultiImapVacationManager::~MultiImapVacationManager() | ||||
{ | { | ||||
} | } | ||||
void MultiImapVacationManager::checkVacation() | QMap <QString, KUrl> MultiImapVacationManager::serverList() | ||||
{ | { | ||||
if (mCheckInProgress) | QMap <QString, KUrl> list; | ||||
return; | |||||
mNumberOfJobs = 0; | |||||
mCheckInProgress = true; | |||||
mQuestionAsked = false; | |||||
const Akonadi::AgentInstance::List instances = KSieveUi::Util::imapAgentInstances(); | const Akonadi::AgentInstance::List instances = KSieveUi::Util::imapAgentInstances(); | ||||
foreach ( const Akonadi::AgentInstance &instance, instances ) { | foreach ( const Akonadi::AgentInstance &instance, instances ) { | ||||
if ( instance.status() == Akonadi::AgentInstance::Broken ) | if ( instance.status() == Akonadi::AgentInstance::Broken ) | ||||
continue; | continue; | ||||
const KUrl url = KSieveUi::Util::findSieveUrlForAccount( instance.identifier() ); | const KUrl url = KSieveUi::Util::findSieveUrlForAccount( instance.identifier() ); | ||||
if ( !url.isEmpty() ) { | if ( !url.isEmpty() ) { | ||||
const QString serverName = instance.name(); | list.insert(instance.name(), url); | ||||
} | |||||
} | |||||
return list; | |||||
} | |||||
void MultiImapVacationManager::checkVacation(const QString &serverName, const KUrl &url) | |||||
{ | |||||
++mNumberOfJobs; | ++mNumberOfJobs; | ||||
if (!mKep14Support.contains(serverName)) { | |||||
CheckKep14SupportJob *checkKep14Job = new CheckKep14SupportJob(this); | |||||
checkKep14Job->setProperty(QLatin1String("triggerScript").latin1(), true); | |||||
checkKep14Job->setServerName(serverName); | |||||
checkKep14Job->setServerUrl(url); | |||||
connect(checkKep14Job, SIGNAL(result(CheckKep14SupportJob*,bool)), SLOT(slotCheckKep14Ended(CheckKep14SupportJob*,bool))); | |||||
checkKep14Job->start(); | |||||
} | |||||
VacationCheckJob *job = new VacationCheckJob(url, serverName, this); | VacationCheckJob *job = new VacationCheckJob(url, serverName, this); | ||||
connect(job, SIGNAL(scriptActive(bool,QString)), this, SLOT(slotScriptActive(bool,QString))); | job->setKep14Support(mKep14Support[serverName]); | ||||
connect(job, SIGNAL(scriptActive(VacationCheckJob*,QString,bool)), this, SLOT(slotScriptActive(VacationCheckJob*,QString,bool))); | |||||
job->start(); | |||||
} | } | ||||
void MultiImapVacationManager::checkVacation() | |||||
{ | |||||
if (mCheckInProgress) | |||||
return; | |||||
mNumberOfJobs = 0; | |||||
mCheckInProgress = true; | |||||
QMap <QString, KUrl> list = serverList(); | |||||
foreach ( const QString &serverName, list.keys() ) { | |||||
const KUrl url = list.value(serverName); | |||||
checkVacation(serverName, url); | |||||
} | } | ||||
} | } | ||||
void MultiImapVacationManager::slotScriptActive(bool active, const QString &serverName) | void MultiImapVacationManager::slotScriptActive(VacationCheckJob* job, QString scriptName, bool active) | ||||
{ | { | ||||
--mNumberOfJobs; | --mNumberOfJobs; | ||||
Q_EMIT scriptActive(active, serverName); | if (mNumberOfJobs == 0) { | ||||
mCheckInProgress = false; | |||||
} | |||||
job->deleteLater(); | |||||
if (active) { | if (job->noScriptFound()) { | ||||
if (!mQuestionAsked) { | emit scriptActive(false, job->serverName()); | ||||
mQuestionAsked = true; | return; | ||||
if ( KMessageBox::questionYesNo( 0, i18n( "There is still an active out-of-office reply configured.\n" | |||||
"Do you want to edit it?"), i18n("Out-of-office reply still active"), | |||||
KGuiItem( i18n( "Edit"), QLatin1String("document-properties") ), | |||||
KGuiItem( i18n("Ignore"), QLatin1String("dialog-cancel") ) ) | |||||
== KMessageBox::Yes ) { | |||||
Q_EMIT requestEditVacation(); | |||||
} | } | ||||
emit scriptActive(active, job->serverName()); | |||||
emit scriptAvailable(job->serverName(), job->sieveCapabilities(), scriptName, job->script(), active); | |||||
} | } | ||||
void MultiImapVacationManager::slotCheckKep14Ended(CheckKep14SupportJob *job, bool success) | |||||
{ | |||||
job->deleteLater(); | |||||
if (!success) { | |||||
--mNumberOfJobs; | |||||
return; | |||||
} | } | ||||
if (mNumberOfJobs == 0) | mKep14Support.insert(job->serverName(), job->hasKep14Support()); | ||||
mCheckInProgress = false; | |||||
VacationCheckJob *checkJob = new VacationCheckJob(job->serverUrl(), job->serverName(), this); | |||||
checkJob->setKep14Support(job->hasKep14Support()); | |||||
connect(checkJob, SIGNAL(scriptActive(VacationCheckJob*,QString,bool)), | |||||
SLOT(slotScriptActive(VacationCheckJob*,QString,bool))); | |||||
checkJob->start(); | |||||
} | } |