1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2014 Arjun A.K. <arjunak234@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "executablefileopendialog_p.h"
9
10#include <QCheckBox>
11#include <QDialogButtonBox>
12#include <QLabel>
13#include <QPushButton>
14#include <QVBoxLayout>
15
16#include <KLocalizedString>
17
18ExecutableFileOpenDialog::ExecutableFileOpenDialog(ExecutableFileOpenDialog::Mode mode, QWidget *parent)
19 : QDialog(parent)
20{
21 QLabel *label = new QLabel(i18n("What do you wish to do with this file?"), this);
22
23 m_dontAskAgain = new QCheckBox(this);
24 m_dontAskAgain->setText(i18n("Do not ask again"));
25
26 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel, this);
27 connect(sender: buttonBox, signal: &QDialogButtonBox::rejected, context: this, slot: &ExecutableFileOpenDialog::reject);
28
29 QVBoxLayout *layout = new QVBoxLayout(this);
30 layout->addWidget(label);
31 layout->addWidget(m_dontAskAgain);
32 layout->addWidget(buttonBox);
33
34 QPushButton *executeButton = new QPushButton(i18n("&Execute"), this);
35 executeButton->setIcon(QIcon::fromTheme(QStringLiteral("system-run")));
36
37 if (mode == OnlyExecute) {
38 connect(sender: executeButton, signal: &QPushButton::clicked, context: this, slot: &ExecutableFileOpenDialog::executeFile);
39 } else if (mode == OpenAsExecute) {
40 connect(sender: executeButton, signal: &QPushButton::clicked, context: this, slot: &ExecutableFileOpenDialog::openFile);
41 } else { // mode == OpenOrExecute
42 connect(sender: executeButton, signal: &QPushButton::clicked, context: this, slot: &ExecutableFileOpenDialog::executeFile);
43
44 QPushButton *openButton = new QPushButton(i18n("&Open"), this);
45 openButton->setIcon(QIcon::fromTheme(QStringLiteral("document-preview")));
46 buttonBox->addButton(button: openButton, role: QDialogButtonBox::AcceptRole);
47
48 connect(sender: openButton, signal: &QPushButton::clicked, context: this, slot: &ExecutableFileOpenDialog::openFile);
49 }
50
51 // Add Execute button last so that Open is first in the button box
52 buttonBox->addButton(button: executeButton, role: QDialogButtonBox::AcceptRole);
53 buttonBox->button(which: QDialogButtonBox::Cancel)->setFocus();
54}
55
56ExecutableFileOpenDialog::ExecutableFileOpenDialog(QWidget *parent)
57 : ExecutableFileOpenDialog(ExecutableFileOpenDialog::OpenOrExecute, parent)
58{
59}
60
61bool ExecutableFileOpenDialog::isDontAskAgainChecked() const
62{
63 return m_dontAskAgain->isChecked();
64}
65
66void ExecutableFileOpenDialog::executeFile()
67{
68 done(ExecuteFile);
69}
70
71void ExecutableFileOpenDialog::openFile()
72{
73 done(OpenFile);
74}
75
76#include "moc_executablefileopendialog_p.cpp"
77

source code of kio/src/widgets/executablefileopendialog.cpp