Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/KeyboardTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ QString KeyboardTranslatorManager::findTranslatorPath(const QString& name)
//return KGlobal::dirs()->findResource("data","konsole/"+name+".keytab");
}

void KeyboardTranslatorManager::addKeyboardLayoutDir(const QString &custom_dir)
{
add_custom_kb_layout_dir(custom_dir);
}

void KeyboardTranslatorManager::findTranslators()
{
QDir dir(get_kb_layout_dir());
Expand Down
7 changes: 7 additions & 0 deletions lib/KeyboardTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,13 @@ class KONSOLEPRIVATE_EXPORT KeyboardTranslatorManager
* translators is started.
*/
QList<QString> allTranslators();

/**
* @brief Allows to add a custom location of keyboard layout.
*
* @param[in] custom_dir Custom location of keyboard layout (must end with /).
*/
void addKeyboardLayoutDir(const QString& custom_dir);

/** Returns the global KeyboardTranslatorManager instance. */
static KeyboardTranslatorManager* instance();
Expand Down
5 changes: 5 additions & 0 deletions lib/qtermwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,11 @@ void QTermWidget::addCustomColorSchemeDir(const QString& custom_dir)
ColorSchemeManager::instance()->addCustomColorSchemeDir(custom_dir);
}

void QTermWidget::addCustomKeyboardLayoutDir(const QString &custom_dir)
{
KeyboardTranslatorManager::instance()->addKeyboardLayoutDir(custom_dir);
}

void QTermWidget::setSize(const QSize &size)
{
m_impl->m_terminalDisplay->setSize(size.width(), size.height());
Expand Down
1 change: 1 addition & 0 deletions lib/qtermwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class QTERMWIDGET_EXPORT QTermWidget : public QWidget, public QTermWidgetInterfa
QStringList getAvailableColorSchemes() override;
static QStringList availableColorSchemes();
static void addCustomColorSchemeDir(const QString& custom_dir);
static void addCustomKeyboardLayoutDir(const QString& custom_dir);

/** Sets the history size (in lines)
*
Expand Down
45 changes: 35 additions & 10 deletions lib/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
#include <QDir>
#include <QtDebug>


Q_LOGGING_CATEGORY(qtermwidgetLogger, "qtermwidget", QtWarningMsg)

static QStringList custom_kb_layout_dirs;

void add_custom_kb_layout_dir(const QString& custom_dir)
{
if (!custom_kb_layout_dirs.contains(custom_dir))
custom_kb_layout_dirs << custom_dir;
}

/*! Helper function to get possible location of layout files.
By default the KB_LAYOUT_DIR is used (linux/BSD/macports).
But in some cases (apple bundle) there can be more locations).
Expand All @@ -27,26 +34,44 @@ QString get_kb_layout_dir()
return rval;
}

#ifdef Q_OS_MAC
// subdir in the app location
d.setPath(QCoreApplication::applicationDirPath() + QLatin1String("/kb-layouts/"));
k = QCoreApplication::applicationDirPath()
+ QDir::separator() + QLatin1String("kb-layouts") + QDir::separator();
d.setPath(k);
//qDebug() << d.path();
if (d.exists())
return QCoreApplication::applicationDirPath() + QLatin1String("/kb-layouts/");
return k;

d.setPath(QCoreApplication::applicationDirPath() + QLatin1String("/../Resources/kb-layouts/"));
k = QCoreApplication::applicationDirPath()
+ QDir::separator() + QLatin1String("..") + QDir::separator()
+ QLatin1String("Resources") + QDir::separator() + QLatin1String("kb-layouts") + QDir::separator();
d.setPath(k);
if (d.exists())
return QCoreApplication::applicationDirPath() + QLatin1String("/../Resources/kb-layouts/");
#endif
return k;

k = QCoreApplication::applicationDirPath()
+ QDir::separator() + QLatin1String("..")
+ QDir::separator() + QLatin1String("share")
+ QDir::separator() + QLatin1String("qtermwidget6")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't had time to check the whole patch, but "share" and "qtermwidget6" shouldn't be hard coded.

Also, this number of QDir::separator() looks ugly. We don't (and won't) support MS Windows.

+ QDir::separator() + QLatin1String("kb-layouts") + QDir::separator();
d.setPath(k);
if(d.exists())
return k;

for (const QString& custom_dir : std::as_const(custom_kb_layout_dirs))
{
d.setPath(custom_dir);
if (d.exists())
return custom_dir + QDir::separator();
}

//qDebug() << "Cannot find KB_LAYOUT_DIR. Default:" << k;
return QString();
}

/*! Helper function to add custom location of color schemes.
*/
namespace {
QStringList custom_color_schemes_dirs;
}
static QStringList custom_color_schemes_dirs;
void add_custom_color_scheme_dir(const QString& custom_dir)
{
if (!custom_color_schemes_dirs.contains(custom_dir))
Expand Down
1 change: 1 addition & 0 deletions lib/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QStringList>
#include <QLoggingCategory>

void add_custom_kb_layout_dir(const QString &custom_dir);
QString get_kb_layout_dir();
void add_custom_color_scheme_dir(const QString& custom_dir);
const QStringList get_color_schemes_dirs();
Expand Down