Warning, file /frameworks/kio/src/widgets/executablefileopendialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2014 Arjun A.K. <arjunak234@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "executablefileopendialog_p.h"
0009 
0010 #include <QCheckBox>
0011 #include <QDialogButtonBox>
0012 #include <QLabel>
0013 #include <QPushButton>
0014 #include <QVBoxLayout>
0015 
0016 #include <KLocalizedString>
0017 
0018 ExecutableFileOpenDialog::ExecutableFileOpenDialog(ExecutableFileOpenDialog::Mode mode, QWidget *parent)
0019     : QDialog(parent)
0020 {
0021     QLabel *label = new QLabel(i18n("What do you wish to do with this file?"), this);
0022 
0023     m_dontAskAgain = new QCheckBox(this);
0024     m_dontAskAgain->setText(i18n("Do not ask again"));
0025 
0026     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel, this);
0027     connect(buttonBox, &QDialogButtonBox::rejected, this, &ExecutableFileOpenDialog::reject);
0028 
0029     QVBoxLayout *layout = new QVBoxLayout(this);
0030     layout->addWidget(label);
0031     layout->addWidget(m_dontAskAgain);
0032     layout->addWidget(buttonBox);
0033 
0034     QPushButton *executeButton = new QPushButton(i18n("&Execute"), this);
0035     executeButton->setIcon(QIcon::fromTheme(QStringLiteral("system-run")));
0036 
0037     if (mode == OnlyExecute) {
0038         connect(executeButton, &QPushButton::clicked, this, &ExecutableFileOpenDialog::executeFile);
0039     } else if (mode == OpenAsExecute) {
0040         connect(executeButton, &QPushButton::clicked, this, &ExecutableFileOpenDialog::openFile);
0041     } else { // mode == OpenOrExecute
0042         connect(executeButton, &QPushButton::clicked, this, &ExecutableFileOpenDialog::executeFile);
0043 
0044         QPushButton *openButton = new QPushButton(i18n("&Open"), this);
0045         openButton->setIcon(QIcon::fromTheme(QStringLiteral("document-preview")));
0046         buttonBox->addButton(openButton, QDialogButtonBox::AcceptRole);
0047 
0048         connect(openButton, &QPushButton::clicked, this, &ExecutableFileOpenDialog::openFile);
0049     }
0050 
0051     // Add Execute button last so that Open is first in the button box
0052     buttonBox->addButton(executeButton, QDialogButtonBox::AcceptRole);
0053     buttonBox->button(QDialogButtonBox::Cancel)->setFocus();
0054 }
0055 
0056 ExecutableFileOpenDialog::ExecutableFileOpenDialog(QWidget *parent)
0057     : ExecutableFileOpenDialog(ExecutableFileOpenDialog::OpenOrExecute, parent)
0058 {
0059 }
0060 
0061 bool ExecutableFileOpenDialog::isDontAskAgainChecked() const
0062 {
0063     return m_dontAskAgain->isChecked();
0064 }
0065 
0066 void ExecutableFileOpenDialog::executeFile()
0067 {
0068     done(ExecuteFile);
0069 }
0070 
0071 void ExecutableFileOpenDialog::openFile()
0072 {
0073     done(OpenFile);
0074 }
0075 
0076 #include "moc_executablefileopendialog_p.cpp"