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: ...@@ -87,6 +87,7 @@ public:
#else #else
void setSettings(QSettings *settings); void setSettings(QSettings *settings);
static QString defaultTerminalEmulator(); static QString defaultTerminalEmulator();
static QStringList availableTerminalEmulators();
static QString terminalEmulator(const QSettings *settings); static QString terminalEmulator(const QSettings *settings);
static void setTerminalEmulator(QSettings *settings, const QString &term); static void setTerminalEmulator(QSettings *settings, const QString &term);
#endif #endif
......
...@@ -277,21 +277,71 @@ void ConsoleProcess::stubExited() ...@@ -277,21 +277,71 @@ void ConsoleProcess::stubExited()
emit wrapperStopped(); 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() QString ConsoleProcess::defaultTerminalEmulator()
{ {
#ifdef Q_OS_MAC #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 #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 #endif
} }
QString ConsoleProcess::terminalEmulator(const QSettings *settings) QString ConsoleProcess::terminalEmulator(const QSettings *settings)
{ {
const QString dflt = defaultTerminalEmulator() + QLatin1String(" -e"); if (settings) {
if (!settings) const QString value = settings->value(QLatin1String("General/TerminalEmulator")).toString();
return dflt; if (!value.isEmpty())
return settings->value(QLatin1String("General/TerminalEmulator"), dflt).toString(); return value;
}
return defaultTerminalEmulator();
} }
void ConsoleProcess::setTerminalEmulator(QSettings *settings, const QString &term) void ConsoleProcess::setTerminalEmulator(QSettings *settings, const QString &term)
......
...@@ -113,10 +113,13 @@ QWidget *GeneralSettings::createPage(QWidget *parent) ...@@ -113,10 +113,13 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
m_page->colorButton->setColor(StyleHelper::requestedBaseColor()); m_page->colorButton->setColor(StyleHelper::requestedBaseColor());
m_page->reloadBehavior->setCurrentIndex(EditorManager::instance()->reloadSetting()); m_page->reloadBehavior->setCurrentIndex(EditorManager::instance()->reloadSetting());
#ifdef Q_OS_UNIX #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 #else
m_page->terminalLabel->hide(); m_page->terminalLabel->hide();
m_page->terminalEdit->hide(); m_page->terminalComboBox->hide();
m_page->resetTerminalButton->hide(); m_page->resetTerminalButton->hide();
#endif #endif
...@@ -175,7 +178,7 @@ void GeneralSettings::apply() ...@@ -175,7 +178,7 @@ void GeneralSettings::apply()
EditorManager::instance()->setReloadSetting(IDocument::ReloadSetting(m_page->reloadBehavior->currentIndex())); EditorManager::instance()->setReloadSetting(IDocument::ReloadSetting(m_page->reloadBehavior->currentIndex()));
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
ConsoleProcess::setTerminalEmulator(Core::ICore::settings(), ConsoleProcess::setTerminalEmulator(Core::ICore::settings(),
m_page->terminalEdit->text()); m_page->terminalComboBox->lineEdit()->text());
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
Utils::UnixUtils::setFileBrowser(Core::ICore::settings(), m_page->externalFileBrowserEdit->text()); Utils::UnixUtils::setFileBrowser(Core::ICore::settings(), m_page->externalFileBrowserEdit->text());
#endif #endif
...@@ -200,7 +203,7 @@ void GeneralSettings::resetInterfaceColor() ...@@ -200,7 +203,7 @@ void GeneralSettings::resetInterfaceColor()
void GeneralSettings::resetTerminal() void GeneralSettings::resetTerminal()
{ {
#if defined(Q_OS_UNIX) #if defined(Q_OS_UNIX)
m_page->terminalEdit->setText(ConsoleProcess::defaultTerminalEmulator() + QLatin1String(" -e")); m_page->terminalComboBox->lineEdit()->setText(ConsoleProcess::defaultTerminalEmulator());
#endif #endif
} }
......
...@@ -124,7 +124,11 @@ ...@@ -124,7 +124,11 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <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>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="externalFileBrowserLabel"> <widget class="QLabel" name="externalFileBrowserLabel">
...@@ -305,7 +309,7 @@ ...@@ -305,7 +309,7 @@
<tabstop>colorButton</tabstop> <tabstop>colorButton</tabstop>
<tabstop>resetButton</tabstop> <tabstop>resetButton</tabstop>
<tabstop>languageBox</tabstop> <tabstop>languageBox</tabstop>
<tabstop>terminalEdit</tabstop> <tabstop>terminalComboBox</tabstop>
<tabstop>resetTerminalButton</tabstop> <tabstop>resetTerminalButton</tabstop>
<tabstop>externalFileBrowserEdit</tabstop> <tabstop>externalFileBrowserEdit</tabstop>
<tabstop>resetFileBrowserButton</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