KIO

executablefileopendialog.cpp
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
27 connect(buttonBox, &QDialogButtonBox::rejected, this, &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(executeButton, &QPushButton::clicked, this, &ExecutableFileOpenDialog::executeFile);
39 } else if (mode == OpenAsExecute) {
40 connect(executeButton, &QPushButton::clicked, this, &ExecutableFileOpenDialog::openFile);
41 } else { // mode == OpenOrExecute
42 connect(executeButton, &QPushButton::clicked, this, &ExecutableFileOpenDialog::executeFile);
43
44 QPushButton *openButton = new QPushButton(i18n("&Open"), this);
45 openButton->setIcon(QIcon::fromTheme(QStringLiteral("document-preview")));
46 buttonBox->addButton(openButton, QDialogButtonBox::AcceptRole);
47
48 connect(openButton, &QPushButton::clicked, this, &ExecutableFileOpenDialog::openFile);
49 }
50
51 // Add Execute button last so that Open is first in the button box
52 buttonBox->addButton(executeButton, QDialogButtonBox::AcceptRole);
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"
QString i18n(const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
void clicked(bool checked)
void setIcon(const QIcon &icon)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
QPushButton * addButton(StandardButton button)
QPushButton * button(StandardButton which) const const
QIcon fromTheme(const QString &name)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setFocus()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 11:56:19 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.