File indexing completed on 2024-04-14 08:26:23

0001 /*
0002     SPDX-FileCopyrightText: 2007 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003     SPDX-FileCopyrightText: 2013 Jean-Nicolas Artaud <jeannicolasartaud@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 // Self
0009 #include "invaliddialog.h"
0010 
0011 // Qt
0012 #include <QLabel>
0013 #include <QListWidget>
0014 #include <QVBoxLayout>
0015 
0016 // KDE
0017 #include <QDialogButtonBox>
0018 #include <QPushButton>
0019 
0020 InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent)
0021     : QDialog(parent)
0022 {
0023     auto *mainLayout = new QVBoxLayout(this);
0024     setWindowTitle(caption);
0025     // Info only means users can only click on ok
0026     QDialogButtonBox *buttonBox;
0027     QPushButton *okButton;
0028     if (infoOnly) {
0029         buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
0030         okButton = buttonBox->button(QDialogButtonBox::Ok);
0031     } else {
0032         buttonBox = new QDialogButtonBox(QDialogButtonBox::No | QDialogButtonBox::Yes);
0033         okButton = buttonBox->button(QDialogButtonBox::Yes);
0034     }
0035     okButton->setDefault(true);
0036     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0037     connect(buttonBox, &QDialogButtonBox::accepted, this, &InvalidDialog::accept);
0038     connect(buttonBox, &QDialogButtonBox::rejected, this, &InvalidDialog::reject);
0039 
0040     m_clipList = new QListWidget(this);
0041     mainLayout->addWidget(new QLabel(message));
0042     mainLayout->addWidget(m_clipList);
0043     mainLayout->addWidget(buttonBox);
0044 }
0045 
0046 InvalidDialog::~InvalidDialog()
0047 {
0048     delete m_clipList;
0049 }
0050 
0051 void InvalidDialog::addClip(const QString &id, const QString &path)
0052 {
0053     auto *item = new QListWidgetItem(path);
0054     item->setData(Qt::UserRole, id);
0055     m_clipList->addItem(item);
0056 }
0057 
0058 QStringList InvalidDialog::getIds() const
0059 {
0060     QStringList ids;
0061     ids.reserve(m_clipList->count());
0062     for (int i = 0; i < m_clipList->count(); ++i) {
0063         ids << m_clipList->item(i)->data(Qt::UserRole).toString();
0064     }
0065     return ids;
0066 }