Commit 86fd0f2f authored by Alexander Lohnau's avatar Alexander Lohnau 💬

Remove unnecessary code and function calls

Summary:
The ShellConfig class has been deleted. This config class was in KDE4 for the runOptions widget used and the class/the settings are not used anymore.
Additionally the context type check has been removed, because this is already solved using the ignore types.
Futhermore the match icon and the list of actions can be reused.

Test Plan: Should compile and execute shell commands as before.

Reviewers: davidedmundson, ngraham, broulik, meven, #plasma

Reviewed By: meven

Subscribers: meven, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D27495
parent 715be958
add_definitions(-DTRANSLATION_DOMAIN=\"plasma_runner_shell\")
set(krunner_shell_SRCS
shellrunner.cpp
shell_config.cpp
)
set(krunner_shell_SRCS shellrunner.cpp)
ki18n_wrap_ui(krunner_shell_SRCS shellOptions.ui)
add_library(krunner_shell MODULE ${krunner_shell_SRCS})
target_link_libraries(krunner_shell
KF5::KIOCore
......@@ -14,7 +10,6 @@ target_link_libraries(krunner_shell
KF5::Plasma
KF5::Runner
KF5::Completion
Qt5::Widgets
)
install(TARGETS krunner_shell DESTINATION ${KDE_INSTALL_PLUGINDIR})
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>shellOptions</class>
<widget class="QWidget" name="shellOptions">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>325</width>
<height>112</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>3</number>
</property>
<item row="0" column="0" rowspan="5" colspan="2">
<layout class="QHBoxLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="gbAdvanced">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>3</number>
</property>
<item row="3" column="1">
<widget class="QLabel" name="lbUsername">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="whatsThis">
<string>Enter the user you want to run the application as here.</string>
</property>
<property name="text">
<string>User&amp;name:</string>
</property>
<property name="buddy">
<cstring>leUsername</cstring>
</property>
</widget>
</item>
<item row="4" column="2" colspan="2">
<widget class="KLineEdit" name="lePassword">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>5</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="whatsThis">
<string>Enter the password here for the user you specified above.</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="lbPassword">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="whatsThis">
<string>Enter the password here for the user you specified above.</string>
</property>
<property name="text">
<string>Pass&amp;word:</string>
</property>
<property name="buddy">
<cstring>lePassword</cstring>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QCheckBox" name="cbRunInTerminal">
<property name="whatsThis">
<string>Check this option if the application you want to run is a text mode application. The application will then be run in a terminal emulator window.</string>
</property>
<property name="text">
<string>Run in &amp;terminal window</string>
</property>
</widget>
</item>
<item row="3" column="2" colspan="2">
<widget class="KLineEdit" name="leUsername">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>5</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="whatsThis">
<string>Enter the user you want to run the application as here.</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="QCheckBox" name="cbRunAsOther">
<property name="whatsThis">
<string>Check this option if you want to run the application with a different user id. Every process has a user id associated with it. This id code determines file access and other permissions. The password of the user is required to do this.</string>
</property>
<property name="text">
<string>Run as a different &amp;user</string>
</property>
</widget>
</item>
<item row="3" column="0" rowspan="2">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>cbRunInTerminal</tabstop>
<tabstop>cbRunAsOther</tabstop>
<tabstop>leUsername</tabstop>
<tabstop>lePassword</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>cbRunAsOther</sender>
<signal>toggled(bool)</signal>
<receiver>lbUsername</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>153</x>
<y>59</y>
</hint>
<hint type="destinationlabel">
<x>96</x>
<y>62</y>
</hint>
</hints>
</connection>
<connection>
<sender>cbRunAsOther</sender>
<signal>toggled(bool)</signal>
<receiver>leUsername</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>127</x>
<y>59</y>
</hint>
<hint type="destinationlabel">
<x>188</x>
<y>62</y>
</hint>
</hints>
</connection>
<connection>
<sender>cbRunAsOther</sender>
<signal>toggled(bool)</signal>
<receiver>lbPassword</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>81</x>
<y>45</y>
</hint>
<hint type="destinationlabel">
<x>146</x>
<y>101</y>
</hint>
</hints>
</connection>
<connection>
<sender>cbRunAsOther</sender>
<signal>toggled(bool)</signal>
<receiver>lePassword</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>114</x>
<y>41</y>
</hint>
<hint type="destinationlabel">
<x>323</x>
<y>101</y>
</hint>
</hints>
</connection>
</connections>
</ui>
/***************************************************************************
* Copyright 2008 by Montel Laurent <montel@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "shell_config.h"
#include <KConfigGroup>
#include <QDebug>
#include <KPluginFactory>
#include <KPluginLoader>
#include <krunner/abstractrunner.h>
ShellConfig::ShellConfig(const KConfigGroup &config, QWidget* parent)
: QWidget(parent),
m_config(config)
{
QHBoxLayout *hboxLayout = new QHBoxLayout(parent);
hboxLayout->addWidget(this);
m_ui.setupUi(this);
#ifdef Q_OS_UNIX
connect(m_ui.cbRunAsOther, &QAbstractButton::clicked, this, &ShellConfig::slotUpdateUser);
#else
m_ui.cbRunAsOther->hide();
m_ui.lbUsername->hide();
m_ui.leUsername->hide();
m_ui.lbPassword->hide();
m_ui.lePassword->hide();
#endif
}
ShellConfig::~ShellConfig()
{
}
void ShellConfig::slotUpdateUser(bool b)
{
if (b) {
m_ui.leUsername->setFocus();
}
}
/***************************************************************************
* Copyright 2008 by Montel Laurent <montel@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#ifndef SHELLCONFIG_H
#define SHELLCONFIG_H
#include <QWidget>
#include <KConfigGroup>
#include "ui_shellOptions.h"
class ShellConfig : public QWidget
{
Q_OBJECT
public:
explicit ShellConfig(const KConfigGroup &config, QWidget* parent = nullptr);
~ShellConfig() override;
Ui::shellOptions m_ui;
protected Q_SLOTS:
void slotUpdateUser(bool);
private:
KConfigGroup m_config;
};
#endif
......@@ -20,34 +20,27 @@
#include "shellrunner.h"
#include <KAuthorized>
#include <QDebug>
#include <KLocalizedString>
#include <KRun>
#include <KShell>
#include <QStandardPaths>
#include <KToolInvocation>
#include <Plasma/Theme>
#include "shell_config.h"
K_EXPORT_PLASMA_RUNNER(shell, ShellRunner)
static QString s_runInTerminalId = QStringLiteral("runInTerminal");
ShellRunner::ShellRunner(QObject *parent, const QVariantList &args)
: Plasma::AbstractRunner(parent, args)
{
setObjectName( QLatin1String("Command" ));
setObjectName(QStringLiteral("Command"));
setPriority(AbstractRunner::HighestPriority);
setHasRunOptions(true);
m_enabled = KAuthorized::authorize(QStringLiteral("run_command")) && KAuthorized::authorize(QStringLiteral("shell_access"));
setIgnoredTypes(Plasma::RunnerContext::Directory | Plasma::RunnerContext::File |
Plasma::RunnerContext::NetworkLocation | Plasma::RunnerContext::UnknownType |
Plasma::RunnerContext::Help);
addSyntax(Plasma::RunnerSyntax(QStringLiteral(":q:"), i18n("Finds commands that match :q:, using common shell syntax")));
addAction(s_runInTerminalId, QIcon::fromTheme(QStringLiteral("utilities-terminal")), i18n("Run in Terminal Window"));
m_actionList = {addAction(QStringLiteral("runInTerminal"),
QIcon::fromTheme(QStringLiteral("utilities-terminal")),
i18n("Run in Terminal Window"))};
m_matchIcon = QIcon::fromTheme(QStringLiteral("system-run"));
}
ShellRunner::~ShellRunner()
......@@ -56,33 +49,26 @@ ShellRunner::~ShellRunner()
void ShellRunner::match(Plasma::RunnerContext &context)
{
if (!m_enabled) {
if (!context.isValid() || !m_enabled) {
return;
}
if (context.type() == Plasma::RunnerContext::Executable ||
context.type() == Plasma::RunnerContext::ShellCommand) {
const QString term = context.query();
Plasma::QueryMatch match(this);
match.setId(term);
match.setType(Plasma::QueryMatch::ExactMatch);
match.setIconName(QStringLiteral("system-run"));
match.setText(i18n("Run %1", term));
match.setRelevance(0.7);
context.addMatch(match);
}
const QString term = context.query();
Plasma::QueryMatch match(this);
match.setId(term);
match.setType(Plasma::QueryMatch::ExactMatch);
match.setIcon(m_matchIcon);
match.setText(i18n("Run %1", term));
match.setRelevance(0.7);
context.addMatch(match);
}
void ShellRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
{
Q_UNUSED(match);
if (m_enabled) {
if (match.selectedAction() && match.selectedAction() == action(s_runInTerminalId)) {
KToolInvocation::invokeTerminal(context.query());
} else {
KRun::runCommand(context.query(), nullptr);
}
if (match.selectedAction()) {
KToolInvocation::invokeTerminal(context.query());
} else {
KRun::runCommand(context.query(), nullptr);
}
}
......@@ -90,7 +76,7 @@ QList<QAction *> ShellRunner::actionsForMatch(const Plasma::QueryMatch &match)
{
Q_UNUSED(match)
return {action(s_runInTerminalId)};
return m_actionList;
}
#include "shellrunner.moc"
......@@ -19,7 +19,7 @@
#ifndef SHELLRUNNER_H
#define SHELLRUNNER_H
#include <krunner/abstractrunner.h>
#include <KRunner/AbstractRunner>
/**
* This class runs programs using the literal name of the binary, much as one
......@@ -39,6 +39,8 @@ class ShellRunner : public Plasma::AbstractRunner
private:
bool m_enabled;
QList<QAction *> m_actionList;
QIcon m_matchIcon;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment