File indexing completed on 2024-10-27 04:50:59

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "incorrectidentityfolderwarning.h"
0008 #include <KLocalizedString>
0009 
0010 IncorrectIdentityFolderWarning::IncorrectIdentityFolderWarning(QWidget *parent)
0011     : KMessageWidget(parent)
0012 {
0013     setPosition(KMessageWidget::Header);
0014     setVisible(false);
0015     setCloseButtonVisible(true);
0016     setMessageType(Warning);
0017     setWordWrap(true);
0018     connect(this, &IncorrectIdentityFolderWarning::hideAnimationFinished, this, &IncorrectIdentityFolderWarning::slotHideAnnimationFinished);
0019 }
0020 
0021 IncorrectIdentityFolderWarning::~IncorrectIdentityFolderWarning() = default;
0022 
0023 void IncorrectIdentityFolderWarning::mailTransportIsInvalid()
0024 {
0025     mMailTransportIsInvalid = true;
0026     updateText();
0027 }
0028 
0029 void IncorrectIdentityFolderWarning::fccIsInvalid()
0030 {
0031     mFccIsInvalid = true;
0032     updateText();
0033 }
0034 
0035 void IncorrectIdentityFolderWarning::identityInvalid()
0036 {
0037     mIdentityIsInvalid = true;
0038     updateText();
0039 }
0040 
0041 void IncorrectIdentityFolderWarning::dictionaryInvalid()
0042 {
0043     mDictionaryIsInvalid = true;
0044     updateText();
0045 }
0046 
0047 void IncorrectIdentityFolderWarning::clearFccInvalid()
0048 {
0049     if (mFccIsInvalid) {
0050         mFccIsInvalid = false;
0051         updateText();
0052     }
0053 }
0054 
0055 void IncorrectIdentityFolderWarning::addNewLine(QString &str)
0056 {
0057     if (!str.isEmpty()) {
0058         str += QLatin1Char('\n');
0059     }
0060 }
0061 
0062 void IncorrectIdentityFolderWarning::updateText()
0063 {
0064     QString text;
0065     if (mMailTransportIsInvalid) {
0066         text = i18n("Transport was not found. Please verify that you will use a correct mail transport.");
0067     }
0068     if (mFccIsInvalid) {
0069         addNewLine(text);
0070         text += i18n("Sent Folder is not defined. Please set it before sending the mail.");
0071     }
0072     if (mIdentityIsInvalid) {
0073         addNewLine(text);
0074         text += i18n("Identity was not found. Please verify that you will use a correct identity.");
0075     }
0076     if (mDictionaryIsInvalid) {
0077         addNewLine(text);
0078         text += i18n("Dictionary was not found. Please verify that you will use a correct dictionary.");
0079     }
0080     if (text.isEmpty()) {
0081         animatedHide();
0082         setText(QString());
0083     } else {
0084         setText(text);
0085         animatedShow();
0086     }
0087 }
0088 
0089 void IncorrectIdentityFolderWarning::slotHideAnnimationFinished()
0090 {
0091     mMailTransportIsInvalid = false;
0092     mFccIsInvalid = false;
0093     mIdentityIsInvalid = false;
0094     mDictionaryIsInvalid = false;
0095 }
0096 
0097 #include "moc_incorrectidentityfolderwarning.cpp"