diff --git a/src/configuredialog/configureappearancepage.h b/src/configuredialog/configureappearancepage.h --- a/src/configuredialog/configureappearancepage.h +++ b/src/configuredialog/configureappearancepage.h @@ -172,6 +172,7 @@ MessageViewer::ConfigureWidget *mViewerSettings = nullptr; Gravatar::GravatarConfigWidget *mGravatarConfigWidget = nullptr; QCheckBox *mSystemTrayCheck = nullptr; + QCheckBox *mStartInTrayCheck = nullptr; QCheckBox *mShowNumberInTaskBar = nullptr; }; diff --git a/src/configuredialog/configureappearancepage.cpp b/src/configuredialog/configureappearancepage.cpp --- a/src/configuredialog/configureappearancepage.cpp +++ b/src/configuredialog/configureappearancepage.cpp @@ -876,8 +876,22 @@ // "Enable system tray applet" check box mSystemTrayCheck = new QCheckBox(i18n("Enable system tray icon"), this); systrayBoxlayout->addWidget(mSystemTrayCheck); - connect(mSystemTrayCheck, &QCheckBox::stateChanged, - this, &ConfigModuleTab::slotEmitChanged); + + // "Enable start in system tray" check box + mStartInTrayCheck = new QCheckBox(i18n("Start minimized to tray")); + systrayBoxlayout->addWidget(mStartInTrayCheck); + + // Dependencies between the two checkboxes + connect(mStartInTrayCheck, &QCheckBox::stateChanged, this, [this](int state) { + if (state == Qt::Checked) + mSystemTrayCheck->setCheckState(Qt::Checked); + slotEmitChanged(); + }); + connect(mSystemTrayCheck, &QCheckBox::stateChanged, this, [this](int state) { + if(state == Qt::Unchecked) + mStartInTrayCheck->setCheckState(Qt::Unchecked); + slotEmitChanged(); + }); // "Enable system tray applet" check box mShowNumberInTaskBar = new QCheckBox(i18n("Show unread email in Taskbar"), this); @@ -896,6 +910,7 @@ void AppearancePage::ReaderTab::doLoadOther() { loadWidget(mSystemTrayCheck, KMailSettings::self()->systemTrayEnabledItem()); + loadWidget(mStartInTrayCheck, KMailSettings::self()->startInTrayItem()); loadWidget(mShowNumberInTaskBar, KMailSettings::self()->showUnreadInTaskbarItem()); loadWidget(mCloseAfterReplyOrForwardCheck, MessageViewer::MessageViewerSettings::self()->closeAfterReplyOrForwardItem()); mViewerSettings->readConfig(); @@ -905,6 +920,7 @@ void AppearancePage::ReaderTab::save() { saveCheckBox(mSystemTrayCheck, KMailSettings::self()->systemTrayEnabledItem()); + saveCheckBox(mStartInTrayCheck, KMailSettings::self()->startInTrayItem()); saveCheckBox(mShowNumberInTaskBar, KMailSettings::self()->showUnreadInTaskbarItem()); KMailSettings::self()->save(); saveCheckBox(mCloseAfterReplyOrForwardCheck, MessageViewer::MessageViewerSettings::self()->closeAfterReplyOrForwardItem()); diff --git a/src/kmail_options.h b/src/kmail_options.h --- a/src/kmail_options.h +++ b/src/kmail_options.h @@ -45,6 +45,9 @@ QStringLiteral("check"), i18n("Only check for new mail")) << QCommandLineOption( + QStringLiteral("startintray"), + i18n("Start minimized to tray")) + << QCommandLineOption( QStringLiteral("composer"), i18n("Only open composer window")) << QCommandLineOption( diff --git a/src/kmkernel.h b/src/kmkernel.h --- a/src/kmkernel.h +++ b/src/kmkernel.h @@ -317,7 +317,7 @@ bool doSessionManagement(); bool firstInstance() const; void setFirstInstance(bool value); - void action(bool mailto, bool check, const QString &to, const QString &cc, const QString &bcc, const QString &subj, const QString &body, const QUrl &messageFile, const QList &attach, const QStringList &customHeaders, const QString &replyTo, const QString &inReplyTo, const QString &identity); + void action(bool mailto, bool check, bool startInTray, const QString &to, const QString &cc, const QString &bcc, const QString &subj, const QString &body, const QUrl &messageFile, const QList &attach, const QStringList &customHeaders, const QString &replyTo, const QString &inReplyTo, const QString &identity); //sets online status for akonadi accounts. true for online, false for offline void setAccountStatus(bool); @@ -478,7 +478,7 @@ void verifyAccount(); void resourceGoOnLine(); - void openReader(bool onlyCheck); + void openReader(bool onlyCheck, bool startInTray); QSharedPointer currentFolderCollection(); void saveConfig(); diff --git a/src/kmkernel.cpp b/src/kmkernel.cpp --- a/src/kmkernel.cpp +++ b/src/kmkernel.cpp @@ -274,6 +274,7 @@ QUrl messageFile; QList attachURLs; QString identity; + bool startInTray = false; bool mailto = false; bool checkMail = false; bool viewOnly = false; @@ -371,6 +372,11 @@ checkMail = true; } + if(parser.isSet(QStringLiteral("startintray"))) { + KMailSettings::self()->setSystemTrayEnabled(true); + startInTray = true; + } + if (parser.isSet(QStringLiteral("identity"))) { identity = parser.value(QStringLiteral("identity")); } @@ -456,7 +462,7 @@ if (viewOnly) { viewMessage(messageFile); } else { - action(mailto, checkMail, to, cc, bcc, subj, body, messageFile, + action(mailto, checkMail, startInTray, to, cc, bcc, subj, body, messageFile, attachURLs, customHeaders, replyTo, inReplyTo, identity); } return true; @@ -496,7 +502,7 @@ void KMKernel::openReader() { - openReader(false); + openReader(false, false); } QStringList KMKernel::accounts() const @@ -526,7 +532,7 @@ } } -void KMKernel::openReader(bool onlyCheck) +void KMKernel::openReader(bool onlyCheck, bool startInTray) { KMainWindow *ktmw = nullptr; @@ -546,7 +552,8 @@ } } else { KMMainWin *win = new KMMainWin; - win->show(); + if(!startInTray && !KMailSettings::self()->startInTray()) + win->show(); activate = false; // new window: no explicit activation (#73591) } } @@ -1143,14 +1150,14 @@ } } -void KMKernel::action(bool mailto, bool check, const QString &to, const QString &cc, const QString &bcc, const QString &subj, const QString &body, const QUrl &messageFile, const QList &attachURLs, const QStringList &customHeaders, const QString &replyTo, const QString &inReplyTo, const QString &identity) +void KMKernel::action(bool mailto, bool check, bool startInTray, const QString &to, const QString &cc, const QString &bcc, const QString &subj, const QString &body, const QUrl &messageFile, const QList &attachURLs, const QStringList &customHeaders, const QString &replyTo, const QString &inReplyTo, const QString &identity) { if (mailto) { openComposer(to, cc, bcc, subj, body, 0, messageFile.toLocalFile(), QUrl::toStringList(attachURLs), customHeaders, replyTo, inReplyTo, identity); } else { - openReader(check); + openReader(check, startInTray); } if (check) { diff --git a/src/settings/kmail.kcfg.cmake b/src/settings/kmail.kcfg.cmake --- a/src/settings/kmail.kcfg.cmake +++ b/src/settings/kmail.kcfg.cmake @@ -84,6 +84,10 @@ false + + + false + true