File indexing completed on 2024-11-10 04:50:02
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "filteractionmissingsoundurldialog.h" 0008 0009 #include <KConfigGroup> 0010 #include <KLocalizedString> 0011 #include <KSharedConfig> 0012 #include <KUrlRequester> 0013 #include <KWindowConfig> 0014 #include <QDialogButtonBox> 0015 #include <QLabel> 0016 #include <QPushButton> 0017 #include <QVBoxLayout> 0018 #include <QWindow> 0019 0020 using namespace MailCommon; 0021 namespace 0022 { 0023 static const char myFilterActionMissingSoundUrlDialogGroupName[] = "FilterActionMissingSoundUrlDialog"; 0024 } 0025 0026 FilterActionMissingSoundUrlDialog::FilterActionMissingSoundUrlDialog(const QString &filtername, const QString &argStr, QWidget *parent) 0027 : QDialog(parent) 0028 , mUrlWidget(new KUrlRequester(this)) 0029 { 0030 setModal(true); 0031 setWindowTitle(i18nc("@title:window", "Select sound")); 0032 0033 auto mainLayout = new QVBoxLayout(this); 0034 0035 auto label = new QLabel(i18n("Sound file was \"%1\".", argStr)); 0036 label->setObjectName(QLatin1StringView("oldlabel")); 0037 mainLayout->addWidget(label); 0038 0039 label = new QLabel(this); 0040 label->setObjectName(QLatin1StringView("selectlabel")); 0041 label->setText( 0042 i18n("Sound file is missing. " 0043 "Please select a sound to use with filter \"%1\"", 0044 filtername)); 0045 label->setWordWrap(true); 0046 mainLayout->addWidget(label); 0047 mUrlWidget->setObjectName(QLatin1StringView("urlwidget")); 0048 mainLayout->addWidget(mUrlWidget); 0049 0050 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0051 buttonBox->setObjectName(QLatin1StringView("buttonbox")); 0052 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0053 okButton->setDefault(true); 0054 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0055 connect(buttonBox, &QDialogButtonBox::accepted, this, &FilterActionMissingSoundUrlDialog::accept); 0056 connect(buttonBox, &QDialogButtonBox::rejected, this, &FilterActionMissingSoundUrlDialog::reject); 0057 0058 mainLayout->addWidget(buttonBox); 0059 readConfig(); 0060 } 0061 0062 FilterActionMissingSoundUrlDialog::~FilterActionMissingSoundUrlDialog() 0063 { 0064 writeConfig(); 0065 } 0066 0067 QString FilterActionMissingSoundUrlDialog::soundUrl() const 0068 { 0069 return mUrlWidget->url().path(); 0070 } 0071 0072 void FilterActionMissingSoundUrlDialog::readConfig() 0073 { 0074 create(); // ensure a window is created 0075 windowHandle()->resize(QSize(500, 300)); 0076 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingSoundUrlDialogGroupName)); 0077 KWindowConfig::restoreWindowSize(windowHandle(), group); 0078 resize(windowHandle()->size()); // workaround for QTBUG-40584 0079 } 0080 0081 void FilterActionMissingSoundUrlDialog::writeConfig() 0082 { 0083 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myFilterActionMissingSoundUrlDialogGroupName)); 0084 KWindowConfig::saveWindowSize(windowHandle(), group); 0085 group.sync(); 0086 } 0087 0088 #include "moc_filteractionmissingsoundurldialog.cpp"