Commit 5c4fddc6 authored by Friedemann Kleint's avatar Friedemann Kleint

Detect Linux terminal by checking a number of known terminals.

Change the behaviour of defaultTerminalEmulator() to already
return the run option in line with terminalEmulator().

Change the QLineEdit in settings to an editable
combo offering the available terminals.

Change-Id: I333ef08ad06934bcd9fcafb50ff1eced1af6293a
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@nokia.com>
parent 813539a7
......@@ -87,6 +87,7 @@ public:
#else
void setSettings(QSettings *settings);
static QString defaultTerminalEmulator();
static QStringList availableTerminalEmulators();
static QString terminalEmulator(const QSettings *settings);
static void setTerminalEmulator(QSettings *settings, const QString &term);
#endif
......
......@@ -277,21 +277,71 @@ void ConsoleProcess::stubExited()
emit wrapperStopped();
}
struct Terminal {
const char *binary;
const char *options;
};
static const Terminal knownTerminals[] =
{
{"xterm", "-e"},
{"aterm", "-e"},
{"Eterm", "-e"},
{"rxvt", "-e"},
{"urxvt", "-e"},
{"xfce4-terminal", "-x"},
{"konsole", "--nofork -e"},
{"gnome-terminal", "-x"}
};
QString ConsoleProcess::defaultTerminalEmulator()
{
#ifdef Q_OS_MAC
return QLatin1String("/usr/X11/bin/xterm");
return QLatin1String("/usr/X11/bin/xterm -e");
#else
const Environment env = Environment::systemEnvironment();
const int terminalCount = int(sizeof(knownTerminals) / sizeof(knownTerminals[0]));
for (int i = 0; i < terminalCount; ++i) {
QString result = env.searchInPath(QLatin1String(knownTerminals[i].binary));
if (!result.isEmpty()) {
result += QLatin1Char(' ');
result += QLatin1String(knownTerminals[i].options);
return result;
}
}
return QLatin1String("xterm -e");
#endif
}
QStringList ConsoleProcess::availableTerminalEmulators()
{
#ifdef Q_OS_MAC
return QStringList(defaultTerminalEmulator());
#else
return QLatin1String("xterm");
QStringList result;
const Environment env = Environment::systemEnvironment();
const int terminalCount = int(sizeof(knownTerminals) / sizeof(knownTerminals[0]));
for (int i = 0; i < terminalCount; ++i) {
QString terminal = env.searchInPath(QLatin1String(knownTerminals[i].binary));
if (!terminal.isEmpty()) {
terminal += QLatin1Char(' ');
terminal += QLatin1String(knownTerminals[i].options);
result.push_back(terminal);
}
}
result.sort();
return result;
#endif
}
QString ConsoleProcess::terminalEmulator(const QSettings *settings)
{
const QString dflt = defaultTerminalEmulator() + QLatin1String(" -e");
if (!settings)
return dflt;
return settings->value(QLatin1String("General/TerminalEmulator"), dflt).toString();
if (settings) {
const QString value = settings->value(QLatin1String("General/TerminalEmulator")).toString();
if (!value.isEmpty())
return value;
}
return defaultTerminalEmulator();
}
void ConsoleProcess::setTerminalEmulator(QSettings *settings, const QString &term)
......
......@@ -113,10 +113,13 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
m_page->colorButton->setColor(StyleHelper::requestedBaseColor());
m_page->reloadBehavior->setCurrentIndex(EditorManager::instance()->reloadSetting());
#ifdef Q_OS_UNIX
m_page->terminalEdit->setText(ConsoleProcess::terminalEmulator(settings));
const QStringList availableTerminals = ConsoleProcess::availableTerminalEmulators();
const QString currentTerminal = ConsoleProcess::terminalEmulator(settings);
m_page->terminalComboBox->addItems(availableTerminals);
m_page->terminalComboBox->lineEdit()->setText(currentTerminal);
#else
m_page->terminalLabel->hide();
m_page->terminalEdit->hide();
m_page->terminalComboBox->hide();
m_page->resetTerminalButton->hide();
#endif
......@@ -175,7 +178,7 @@ void GeneralSettings::apply()
EditorManager::instance()->setReloadSetting(IDocument::ReloadSetting(m_page->reloadBehavior->currentIndex()));
#ifdef Q_OS_UNIX
ConsoleProcess::setTerminalEmulator(Core::ICore::settings(),
m_page->terminalEdit->text());
m_page->terminalComboBox->lineEdit()->text());
#ifndef Q_OS_MAC
Utils::UnixUtils::setFileBrowser(Core::ICore::settings(), m_page->externalFileBrowserEdit->text());
#endif
......@@ -200,7 +203,7 @@ void GeneralSettings::resetInterfaceColor()
void GeneralSettings::resetTerminal()
{
#if defined(Q_OS_UNIX)
m_page->terminalEdit->setText(ConsoleProcess::defaultTerminalEmulator() + QLatin1String(" -e"));
m_page->terminalComboBox->lineEdit()->setText(ConsoleProcess::defaultTerminalEmulator());
#endif
}
......
......@@ -124,7 +124,11 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="terminalEdit"/>
<widget class="QComboBox" name="terminalComboBox">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="externalFileBrowserLabel">
......@@ -305,7 +309,7 @@
<tabstop>colorButton</tabstop>
<tabstop>resetButton</tabstop>
<tabstop>languageBox</tabstop>
<tabstop>terminalEdit</tabstop>
<tabstop>terminalComboBox</tabstop>
<tabstop>resetTerminalButton</tabstop>
<tabstop>externalFileBrowserEdit</tabstop>
<tabstop>resetFileBrowserButton</tabstop>
......
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