Commit 4a0ba9e0 authored by Méven Car's avatar Méven Car

KCM/Component Revamp Terminal Emulator UI

Summary:
Revamp UI, to use a simple combobox
 * Other... choice allows to select any programe
 * Keep konsole as default
 * changed & default works
 * List in the combobox known TerminalEmulator installed

Test Plan:
Before:
{F7886218}

After:

{F7886219}

{F7886220}

Reviewers: #plasma, ervin, ngraham

Reviewed By: ervin, ngraham

Subscribers: plasma-devel

Tags: #plasma

Maniphest Tasks: T12551

Differential Revision: https://phabricator.kde.org/D26705
parent d1f62c16
/***************************************************************************
componentchooser.cpp - description
-------------------
copyright : (C) 2002 by Joseph Wenninger
email : jowenn@kde.org
copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org>
copyright : (C) 2020 by Méven Car <meven.car@enioka.com>
***************************************************************************/
/***************************************************************************
......@@ -29,62 +29,83 @@
#include <kurlrequester.h>
#include <kconfiggroup.h>
#include <KLocalizedString>
#include <KServiceTypeTrader>
#include <QUrl>
CfgTerminalEmulator::CfgTerminalEmulator(QWidget *parent)
: QWidget(parent), Ui::TerminalEmulatorConfig_UI(), CfgPlugin()
{
setupUi(this);
connect(terminalLE, &QLineEdit::textChanged, this, &CfgTerminalEmulator::configChanged);
connect(terminalCB, &QRadioButton::toggled, this, &CfgTerminalEmulator::configChanged);
connect(otherCB, &QRadioButton::toggled, this, &CfgTerminalEmulator::configChanged);
connect(btnSelectTerminal, &QToolButton::clicked, this, &CfgTerminalEmulator::selectTerminalApp);
setupUi(this);
connect(terminalCombo, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated), this, &CfgTerminalEmulator::selectTerminalEmulator);
}
CfgTerminalEmulator::~CfgTerminalEmulator() {
}
void CfgTerminalEmulator::configChanged()
void CfgTerminalEmulator::selectTerminalEmulator(int index)
{
emit changed(true);
if (index == terminalCombo->count() - 1) {
selectTerminalApp();
} else {
emit changed(m_currentIndex != index);
}
}
void CfgTerminalEmulator::defaults()
{
load(nullptr);
terminalCB->setChecked(true);
if (m_konsoleIndex != -1) {
terminalCombo->setCurrentIndex(m_konsoleIndex);
}
}
bool CfgTerminalEmulator::isDefaults() const
{
return terminalCB->isChecked();
return m_konsoleIndex == -1 || m_konsoleIndex == terminalCombo->currentIndex();
}
void CfgTerminalEmulator::load(KConfig *)
{
TerminalSettings settings;
QString terminal = settings.terminalApplication();
if (terminal == QLatin1String("konsole"))
{
terminalLE->setText(QStringLiteral("xterm"));
terminalCB->setChecked(true);
}
else
{
terminalLE->setText(terminal);
otherCB->setChecked(true);
}
const QString terminal = settings.terminalApplication();
m_currentIndex = -1;
terminalCombo->clear();
const auto constraint = QStringLiteral("'TerminalEmulator' in Categories AND (not exist NoDisplay OR NoDisplay == false)");
const auto terminalEmulators = KServiceTypeTrader::self()->query(QStringLiteral("Application"), constraint);
for (const auto &service : terminalEmulators) {
terminalCombo->addItem(QIcon::fromTheme(service->icon()), service->name(), service->exec());
if (!terminal.isEmpty() && service->exec() == terminal) {
terminalCombo->setCurrentIndex(terminalCombo->count() - 1);
m_currentIndex = terminalCombo->count() - 1;
}
if (service->exec() == QStringLiteral("konsole")) {
m_konsoleIndex = terminalCombo->count() - 1;
}
}
if (!terminal.isEmpty() && m_currentIndex == -1) {
// we have a terminal specified by the user
terminalCombo->addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), terminal, terminal);
terminalCombo->setCurrentIndex(terminalCombo->count() - 1);
m_currentIndex = terminalCombo->count() - 1;
}
// add a other option to add a new terminal emulator with KOpenWithDialog
terminalCombo->addItem(QIcon::fromTheme(QStringLiteral("application-x-shellscript")), i18n("Other..."), QStringLiteral());
emit changed(false);
}
void CfgTerminalEmulator::save(KConfig *)
{
const QString terminal = terminalCombo->currentData().toString();
m_currentIndex = terminalCombo->currentIndex();
TerminalSettings settings;
settings.setTerminalApplication(terminalCB->isChecked() ? settings.defaultTerminalApplicationValue() : terminalLE->text());
settings.setTerminalApplication(terminal);
settings.save();
QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.klauncher5"),
......@@ -92,7 +113,7 @@ void CfgTerminalEmulator::save(KConfig *)
QStringLiteral("org.kde.KLauncher"),
QStringLiteral("reparseConfiguration"));
QDBusConnection::sessionBus().send(message);
emit changed(false);
emit changed(false);
}
void CfgTerminalEmulator::selectTerminalApp()
......@@ -100,13 +121,27 @@ void CfgTerminalEmulator::selectTerminalApp()
QList<QUrl> urlList;
KOpenWithDialog dlg(urlList, i18n("Select preferred terminal application:"), QString(), this);
// hide "Run in &terminal" here, we don't need it for a Terminal Application
dlg.hideRunInTerminal();
if (dlg.exec() != QDialog::Accepted) return;
QString client = dlg.text();
if (!client.isEmpty())
{
terminalLE->setText(client);
}
dlg.hideRunInTerminal();
dlg.setSaveNewApplications(true);
if (dlg.exec() != QDialog::Accepted) {
terminalCombo->setCurrentIndex(m_currentIndex);
return;
}
const auto service = dlg.service();
// if the selected service is already in the list
const auto matching = terminalCombo->model()->match(terminalCombo->model()->index(0,0), Qt::DisplayRole, service->exec());
if (!matching.isEmpty()) {
const int index = matching.at(0).row();
terminalCombo->setCurrentIndex(index);
changed(index != m_currentIndex);
} else {
const QString icon = !service->icon().isEmpty() ? service->icon() : QStringLiteral("application-x-shellscript");
terminalCombo->insertItem(terminalCombo->count() -1, QIcon::fromTheme(icon), service->name(), service->exec());
terminalCombo->setCurrentIndex(terminalCombo->count() - 2);
changed(true);
}
}
// vim: sw=4 ts=4 noet
/***************************************************************************
componentchooserterminal.h - description
-------------------
copyright : (C) 2002 by Joseph Wenninger
email : jowenn@kde.org
copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org>
copyright : (C) 2020 by Méven Car <meven.car@enioka.com>
***************************************************************************/
/***************************************************************************
......@@ -33,11 +33,15 @@ public:
bool isDefaults() const override;
protected Q_SLOTS:
void selectTerminalApp();
void configChanged();
void selectTerminalApp();
void selectTerminalEmulator(int index);
Q_SIGNALS:
void changed(bool);
private:
int m_currentIndex = -1;
int m_konsoleIndex = -1;
};
#endif
......@@ -2,66 +2,29 @@
<ui version="4.0">
<class>TerminalEmulatorConfig_UI</class>
<widget class="QWidget" name="TerminalEmulatorConfig_UI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>246</width>
<height>118</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="terminalCB">
<property name="text">
<string>&amp;Use Konsole as terminal application</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="otherCB">
<property name="text">
<string>Use a different &amp;terminal program:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<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>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="terminalLE">
<property name="enabled">
<bool>false</bool>
</property>
<property name="whatsThis">
<string>Press this button to select your favorite terminal client. Please note that the file you select has to have the executable attribute set in order to be accepted.&lt;br/&gt; Also note that some programs that utilize Terminal Emulator will not work if you add command line arguments (Example: konsole -ls).</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnSelectTerminal">
<property name="enabled">
<bool>false</bool>
</property>
<property name="whatsThis">
<string>Click here to browse for terminal program.</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
<widget class="QComboBox" name="terminalCombo"/>
</item>
<item>
<spacer>
......@@ -82,38 +45,5 @@
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>otherCB</sender>
<signal>toggled(bool)</signal>
<receiver>terminalLE</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>otherCB</sender>
<signal>toggled(bool)</signal>
<receiver>btnSelectTerminal</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>
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