File indexing completed on 2024-04-21 04:18:47
0001 // vim: set tabstop=4 shiftwidth=4 expandtab: 0002 /* 0003 Gwenview: an image viewer 0004 Copyright 2009 Aurélien Gâteau <agateau@kde.org> 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License 0008 as published by the Free Software Foundation; either version 2 0009 of the License, or (at your option) any later version. 0010 0011 This program is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with this program; if not, write to the Free Software 0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. 0019 0020 */ 0021 // Self 0022 #include "dialogpage.h" 0023 0024 // Qt 0025 #include <QAction> 0026 #include <QEventLoop> 0027 #include <QList> 0028 #include <QPushButton> 0029 #include <QVBoxLayout> 0030 0031 // KF 0032 #include <KGuiItem> 0033 #include <KMessageBox> 0034 0035 // Local 0036 #include <ui_dialogpage.h> 0037 0038 namespace Gwenview 0039 { 0040 struct DialogPagePrivate : public Ui_DialogPage { 0041 QVBoxLayout *mLayout = nullptr; 0042 QList<QPushButton *> mButtons; 0043 QEventLoop *mEventLoop = nullptr; 0044 DialogPage *q = nullptr; 0045 QStringList failedFileList; 0046 QStringList failedDirList; 0047 QAction *fileDetails = nullptr; 0048 QAction *dirDetails = nullptr; 0049 0050 void setupFailedListActions() 0051 { 0052 fileDetails = new QAction(i18n("Show failed files...")); 0053 mErrorMessageWidget->addAction(fileDetails); 0054 QObject::connect(fileDetails, &QAction::triggered, q, &DialogPage::slotShowFailedFileDetails); 0055 fileDetails->setVisible(false); 0056 0057 dirDetails = new QAction(i18n("Show failed subfolders...")); 0058 mErrorMessageWidget->addAction(dirDetails); 0059 QObject::connect(dirDetails, &QAction::triggered, q, &DialogPage::slotShowFailedDirDetails); 0060 dirDetails->setVisible(false); 0061 } 0062 0063 void showErrors(const QStringList &files, const QStringList &dirs) 0064 { 0065 mErrorMessageWidget->setVisible(true); 0066 failedFileList.clear(); 0067 failedDirList.clear(); 0068 QStringList message; 0069 if (!files.isEmpty()) { 0070 failedFileList = files; 0071 message << i18np("Failed to import %1 document.", "Failed to import %1 documents.", files.count()); 0072 fileDetails->setVisible(true); 0073 } else 0074 fileDetails->setVisible(false); 0075 0076 if (!dirs.isEmpty()) { 0077 failedDirList = dirs; 0078 message << i18np("Failed to create %1 destination subfolder.", "Failed to create %1 destination subfolders.", dirs.count()); 0079 dirDetails->setVisible(true); 0080 } else 0081 dirDetails->setVisible(false); 0082 0083 mErrorMessageWidget->setText(message.join(QStringLiteral("<br/>"))); 0084 mErrorMessageWidget->animatedShow(); 0085 } 0086 0087 void showFailedFileDetails() 0088 { 0089 const QString message = i18n("Failed to import documents:"); 0090 KMessageBox::errorList(q, message, failedFileList); 0091 } 0092 0093 void showFailedDirDetails() 0094 { 0095 const QString message = i18n("Failed to create subfolders:"); 0096 KMessageBox::errorList(q, message, failedDirList); 0097 } 0098 }; 0099 0100 DialogPage::DialogPage(QWidget *parent) 0101 : QWidget(parent) 0102 , d(new DialogPagePrivate) 0103 { 0104 d->q = this; 0105 d->setupUi(this); 0106 d->mLayout = new QVBoxLayout(d->mButtonContainer); 0107 d->setupFailedListActions(); 0108 d->mErrorMessageWidget->hide(); 0109 } 0110 0111 DialogPage::~DialogPage() 0112 { 0113 delete d; 0114 } 0115 0116 void DialogPage::removeButtons() 0117 { 0118 qDeleteAll(d->mButtons); 0119 d->mButtons.clear(); 0120 } 0121 0122 void DialogPage::setText(const QString &text) 0123 { 0124 d->mLabel->setText(text); 0125 } 0126 0127 int DialogPage::addButton(const KGuiItem &item) 0128 { 0129 const int id = d->mButtons.size(); 0130 auto button = new QPushButton; 0131 KGuiItem::assign(button, item); 0132 button->setFixedHeight(button->sizeHint().height() * 2); 0133 0134 connect(button, &QAbstractButton::clicked, this, [this, id]() { 0135 d->mEventLoop->exit(id); 0136 }); 0137 d->mLayout->addWidget(button); 0138 d->mButtons << button; 0139 return id; 0140 } 0141 0142 void DialogPage::slotShowErrors(const QStringList &files, const QStringList &dirs) 0143 { 0144 d->showErrors(files, dirs); 0145 } 0146 0147 void DialogPage::slotShowFailedFileDetails() 0148 { 0149 d->showFailedFileDetails(); 0150 } 0151 0152 void DialogPage::slotShowFailedDirDetails() 0153 { 0154 d->showFailedDirDetails(); 0155 } 0156 0157 int DialogPage::exec() 0158 { 0159 QEventLoop loop; 0160 d->mEventLoop = &loop; 0161 return loop.exec(); 0162 } 0163 0164 } // namespace 0165 0166 #include "moc_dialogpage.cpp"