diff --git a/src/opencomposerjob.h b/src/opencomposerjob.h --- a/src/opencomposerjob.h +++ b/src/opencomposerjob.h @@ -38,15 +38,11 @@ void start() override; private: - void slotServiceOwnerChanged(const QString &, const QString &, const QString &); - void timeout(); - void processMail(); QString mDBusService; QString mError; QString mTo, mCc, mBcc; KMime::Message::Ptr mMessage; KIdentityManagement::Identity mIdentity; - bool mSuccess; }; } #endif diff --git a/src/opencomposerjob.cpp b/src/opencomposerjob.cpp --- a/src/opencomposerjob.cpp +++ b/src/opencomposerjob.cpp @@ -19,7 +19,6 @@ #include "opencomposerjob.h" -#include #include #include @@ -36,71 +35,16 @@ , mBcc(bcc) , mMessage(message) , mIdentity(identity) - , mSuccess(false) { - connect( - QDBusConnection::sessionBus().interface(), &QDBusConnectionInterface::serviceOwnerChanged, - this, &OpenComposerJob::slotServiceOwnerChanged); } OpenComposerJob::~OpenComposerJob() { } void OpenComposerJob::start() -{ - mSuccess = false; - if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral( - "org.kde.kmail"))) { - QMetaObject::invokeMethod(this, &OpenComposerJob::processMail, Qt::QueuedConnection); - } - //Check if Kontact is already running and if not ... - int result = KDBusServiceStarter::self()->findServiceFor(QStringLiteral("DBUS/Mailer"), - QString(), - &mError, &mDBusService); - if (result != 0) { - // ... start Kontact - result = KDBusServiceStarter::self()->startServiceFor(QStringLiteral( - "DBUS/Mailer"), QString(), - &mError, &mDBusService); - if (result != 0) { - const bool ok = QProcess::startDetached(QStringLiteral("kontact")); - if (!ok) { - setError(KJob::UserDefinedError); - setErrorText(i18nc("errormessage: can't create a kontact process", - "Can't create composer: Failed to start kontact.")); - emitResult(); - return; - } - } - } - - QTimer::singleShot(10000, this, &OpenComposerJob::timeout); -} - -void OpenComposerJob::timeout() -{ - if (!mSuccess) { - setError(KJob::UserDefinedError); - setErrorText(i18nc( - "errormessage: No connection via dbus nor starting kontact process worked.", - "Can't create composer: Neither dbus nor kontact responded in time.")); - emitResult(); - } -} - -void OpenComposerJob::slotServiceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner) -{ - Q_UNUSED(oldOwner); - if (name == QLatin1String("org.kde.kmail") && !newOwner.isEmpty()) { - processMail(); - } -} - -void OpenComposerJob::processMail() { Q_ASSERT(mMessage); - mSuccess = true; unsigned int identity = mIdentity.uoid(); @@ -137,6 +81,8 @@ << attachParamAttr << attachParamValue << attachContDisp << attachCharset << identity; } + + // with D-Bus autostart, this will start kmail if it's not running yet QDBusInterface kmailObj(QStringLiteral("org.kde.kmail"), QStringLiteral( "/KMail"), QStringLiteral("org.kde.kmail.kmail"));