File indexing completed on 2024-04-14 04:52:55
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2000 Alexander Neundorf <neundorf@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 // Own 0008 #include "kshellcmddialog.h" 0009 0010 // Qt 0011 #include <QLayout> 0012 #include <QLabel> 0013 #include <QPushButton> 0014 #include <QDialogButtonBox> 0015 0016 // KDE 0017 #include <KLocalizedString> 0018 #include <KStandardGuiItem> 0019 0020 // Local 0021 #include "kshellcmdexecutor.h" 0022 0023 KShellCommandDialog::KShellCommandDialog(const QString &title, const QString &command, QWidget *parent, bool modal) 0024 : QDialog(parent) 0025 { 0026 setModal(modal); 0027 0028 QLabel *label = new QLabel(title, this); 0029 m_shell = new KShellCommandExecutor(command, this); 0030 0031 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close|QDialogButtonBox::Cancel, this); 0032 cancelButton = buttonBox->button(QDialogButtonBox::Cancel); 0033 closeButton = buttonBox->button(QDialogButtonBox::Close); 0034 closeButton->setDefault(true); 0035 0036 label->resize(label->sizeHint()); 0037 m_shell->resize(m_shell->sizeHint()); 0038 0039 QVBoxLayout *box = new QVBoxLayout(this); 0040 box->addWidget(label); 0041 box->addWidget(m_shell); 0042 box->setStretchFactor(m_shell, 1); 0043 box->addWidget(buttonBox); 0044 0045 m_shell->setFocus(); 0046 0047 connect(cancelButton, &QAbstractButton::clicked, m_shell, &KShellCommandExecutor::slotFinished); 0048 connect(m_shell, &KShellCommandExecutor::finished, this, &KShellCommandDialog::disableStopButton); 0049 connect(closeButton, &QAbstractButton::clicked, this, &KShellCommandDialog::slotClose); 0050 } 0051 0052 KShellCommandDialog::~KShellCommandDialog() 0053 { 0054 delete m_shell; 0055 m_shell = nullptr; 0056 } 0057 0058 void KShellCommandDialog::disableStopButton() 0059 { 0060 cancelButton->setEnabled(false); 0061 } 0062 0063 void KShellCommandDialog::slotClose() 0064 { 0065 delete m_shell; 0066 m_shell = nullptr; 0067 accept(); 0068 } 0069 0070 //blocking 0071 int KShellCommandDialog::executeCommand() 0072 { 0073 if (m_shell == nullptr) { 0074 return 0; 0075 } 0076 0077 m_shell->exec(); 0078 return exec(); 0079 } 0080