Commit b7676178 authored by Kurt Hindenburg's avatar Kurt Hindenburg

uncrustify using kf5 config

parent 9bd78534
This diff is collapsed.
This diff is collapsed.
...@@ -32,10 +32,10 @@ ...@@ -32,10 +32,10 @@
using namespace Konsole; using namespace Konsole;
KeyboardTranslatorManager::KeyboardTranslatorManager() KeyboardTranslatorManager::KeyboardTranslatorManager() :
: _haveLoadedAll(false) _haveLoadedAll(false),
, _fallbackTranslator(0) _fallbackTranslator(0),
, _translators(QHash<QString, KeyboardTranslator*>()) _translators(QHash<QString, KeyboardTranslator *>())
{ {
_fallbackTranslator = new FallbackKeyboardTranslator(); _fallbackTranslator = new FallbackKeyboardTranslator();
} }
...@@ -52,16 +52,17 @@ KeyboardTranslatorManager* KeyboardTranslatorManager::instance() ...@@ -52,16 +52,17 @@ KeyboardTranslatorManager* KeyboardTranslatorManager::instance()
return theKeyboardTranslatorManager; return theKeyboardTranslatorManager;
} }
void KeyboardTranslatorManager::addTranslator(KeyboardTranslator* translator) void KeyboardTranslatorManager::addTranslator(KeyboardTranslator *translator)
{ {
_translators.insert(translator->name(), translator); _translators.insert(translator->name(), translator);
if (!saveTranslator(translator)) if (!saveTranslator(translator)) {
qCDebug(KonsoleDebug) << "Unable to save translator" << translator->name() qCDebug(KonsoleDebug) << "Unable to save translator" << translator->name()
<< "to disk."; << "to disk.";
}
} }
bool KeyboardTranslatorManager::deleteTranslator(const QString& name) bool KeyboardTranslatorManager::deleteTranslator(const QString &name)
{ {
Q_ASSERT(_translators.contains(name)); Q_ASSERT(_translators.contains(name));
...@@ -76,21 +77,21 @@ bool KeyboardTranslatorManager::deleteTranslator(const QString& name) ...@@ -76,21 +77,21 @@ bool KeyboardTranslatorManager::deleteTranslator(const QString& name)
} }
} }
QString KeyboardTranslatorManager::findTranslatorPath(const QString& name) QString KeyboardTranslatorManager::findTranslatorPath(const QString &name)
{ {
return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konsole/") + name + QStringLiteral(".keytab")); return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konsole/") + name + QStringLiteral(".keytab"));
} }
void KeyboardTranslatorManager::findTranslators() void KeyboardTranslatorManager::findTranslators()
{ {
QStringList list; QStringList list;
const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("konsole"), QStandardPaths::LocateDirectory); const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("konsole"),
QStandardPaths::LocateDirectory);
list.reserve(dirs.size()); list.reserve(dirs.size());
Q_FOREACH (const QString& dir, dirs) { Q_FOREACH (const QString &dir, dirs) {
const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.keytab")); const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.keytab"));
Q_FOREACH (const QString& file, fileNames) { Q_FOREACH (const QString &file, fileNames) {
list.append(dir + QLatin1Char('/') + file); list.append(dir + QLatin1Char('/') + file);
} }
} }
...@@ -98,37 +99,42 @@ void KeyboardTranslatorManager::findTranslators() ...@@ -98,37 +99,42 @@ void KeyboardTranslatorManager::findTranslators()
// add the name of each translator to the list and associated // add the name of each translator to the list and associated
// the name with a null pointer to indicate that the translator // the name with a null pointer to indicate that the translator
// has not yet been loaded from disk // has not yet been loaded from disk
foreach(const QString& translatorPath, list) { foreach (const QString &translatorPath, list) {
QString name = QFileInfo(translatorPath).baseName(); QString name = QFileInfo(translatorPath).baseName();
if (!_translators.contains(name)) if (!_translators.contains(name)) {
_translators.insert(name, 0); _translators.insert(name, 0);
}
} }
_haveLoadedAll = true; _haveLoadedAll = true;
} }
const KeyboardTranslator* KeyboardTranslatorManager::findTranslator(const QString& name) const KeyboardTranslator *KeyboardTranslatorManager::findTranslator(const QString &name)
{ {
if (name.isEmpty()) if (name.isEmpty()) {
return defaultTranslator(); return defaultTranslator();
}
if (_translators.contains(name) && _translators[name] != 0) if (_translators.contains(name) && _translators[name] != 0) {
return _translators[name]; return _translators[name];
}
KeyboardTranslator* translator = loadTranslator(name); KeyboardTranslator *translator = loadTranslator(name);
if (translator != 0) if (translator != 0) {
_translators[name] = translator; _translators[name] = translator;
else if (!name.isEmpty()) } else if (!name.isEmpty()) {
qCDebug(KonsoleDebug) << "Unable to load translator" << name; qCDebug(KonsoleDebug) << "Unable to load translator" << name;
}
return translator; return translator;
} }
bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator* translator) bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator *translator)
{ {
const QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/konsole/"); const QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
+ QStringLiteral("/konsole/");
QDir().mkpath(dir); QDir().mkpath(dir);
const QString path = dir + translator->name() + QStringLiteral(".keytab"); const QString path = dir + translator->name() + QStringLiteral(".keytab");
...@@ -137,7 +143,7 @@ bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator* transla ...@@ -137,7 +143,7 @@ bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator* transla
QFile destination(path); QFile destination(path);
if (!destination.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!destination.open(QIODevice::WriteOnly | QIODevice::Text)) {
qCDebug(KonsoleDebug) << "Unable to save keyboard translation:" qCDebug(KonsoleDebug) << "Unable to save keyboard translation:"
<< destination.errorString(); << destination.errorString();
return false; return false;
} }
...@@ -145,7 +151,7 @@ bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator* transla ...@@ -145,7 +151,7 @@ bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator* transla
KeyboardTranslatorWriter writer(&destination); KeyboardTranslatorWriter writer(&destination);
writer.writeHeader(translator->description()); writer.writeHeader(translator->description());
foreach(const KeyboardTranslator::Entry& entry, translator->entries()) { foreach (const KeyboardTranslator::Entry &entry, translator->entries()) {
writer.writeEntry(entry); writer.writeEntry(entry);
} }
} }
...@@ -155,24 +161,27 @@ bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator* transla ...@@ -155,24 +161,27 @@ bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator* transla
return true; return true;
} }
KeyboardTranslator* KeyboardTranslatorManager::loadTranslator(const QString& name) KeyboardTranslator *KeyboardTranslatorManager::loadTranslator(const QString &name)
{ {
const QString& path = findTranslatorPath(name); const QString &path = findTranslatorPath(name);
QFile source(path); QFile source(path);
if (name.isEmpty() || !source.open(QIODevice::ReadOnly | QIODevice::Text)) if (name.isEmpty() || !source.open(QIODevice::ReadOnly | QIODevice::Text)) {
return 0; return 0;
}
return loadTranslator(&source, name); return loadTranslator(&source, name);
} }
KeyboardTranslator* KeyboardTranslatorManager::loadTranslator(QIODevice* source, const QString& name) KeyboardTranslator *KeyboardTranslatorManager::loadTranslator(QIODevice *source,
const QString &name)
{ {
auto translator = new KeyboardTranslator(name); auto translator = new KeyboardTranslator(name);
KeyboardTranslatorReader reader(source); KeyboardTranslatorReader reader(source);
translator->setDescription(reader.description()); translator->setDescription(reader.description());
while (reader.hasNextEntry()) while (reader.hasNextEntry()) {
translator->addEntry(reader.nextEntry()); translator->addEntry(reader.nextEntry());
}
source->close(); source->close();
...@@ -184,11 +193,11 @@ KeyboardTranslator* KeyboardTranslatorManager::loadTranslator(QIODevice* source, ...@@ -184,11 +193,11 @@ KeyboardTranslator* KeyboardTranslatorManager::loadTranslator(QIODevice* source,
} }
} }
const KeyboardTranslator* KeyboardTranslatorManager::defaultTranslator() const KeyboardTranslator *KeyboardTranslatorManager::defaultTranslator()
{ {
// Try to find the default.keytab file if it exists, otherwise // Try to find the default.keytab file if it exists, otherwise
// fall back to the internal hard-coded fallback translator // fall back to the internal hard-coded fallback translator
const KeyboardTranslator* translator = findTranslator(QStringLiteral("default")); const KeyboardTranslator *translator = findTranslator(QStringLiteral("default"));
if (translator == nullptr) { if (translator == nullptr) {
translator = _fallbackTranslator; translator = _fallbackTranslator;
} }
......
...@@ -32,8 +32,7 @@ ...@@ -32,8 +32,7 @@
class QIODevice; class QIODevice;
namespace Konsole namespace Konsole {
{
/** /**
* Manages the keyboard translations available for use by terminal sessions, * Manages the keyboard translations available for use by terminal sessions,
* see KeyboardTranslator. * see KeyboardTranslator.
...@@ -51,8 +50,8 @@ public: ...@@ -51,8 +50,8 @@ public:
KeyboardTranslatorManager(); KeyboardTranslatorManager();
~KeyboardTranslatorManager(); ~KeyboardTranslatorManager();
KeyboardTranslatorManager(const KeyboardTranslatorManager&) = delete; KeyboardTranslatorManager(const KeyboardTranslatorManager &) = delete;
KeyboardTranslatorManager& operator=(const KeyboardTranslatorManager&) = delete; KeyboardTranslatorManager &operator=(const KeyboardTranslatorManager &) = delete;
/** /**
* Adds a new translator. If a translator with the same name * Adds a new translator. If a translator with the same name
...@@ -60,17 +59,17 @@ public: ...@@ -60,17 +59,17 @@ public:
* *
* TODO: More documentation. * TODO: More documentation.
*/ */
void addTranslator(KeyboardTranslator* translator); void addTranslator(KeyboardTranslator *translator);
/** /**
* Deletes a translator. Returns true on successful deletion or false otherwise. * Deletes a translator. Returns true on successful deletion or false otherwise.
* *
* TODO: More documentation * TODO: More documentation
*/ */
bool deleteTranslator(const QString& name); bool deleteTranslator(const QString &name);
/** Returns the default translator for Konsole. */ /** Returns the default translator for Konsole. */
const KeyboardTranslator* defaultTranslator(); const KeyboardTranslator *defaultTranslator();
/** /**
* Returns the keyboard translator with the given name or 0 if no translator * Returns the keyboard translator with the given name or 0 if no translator
...@@ -79,7 +78,7 @@ public: ...@@ -79,7 +78,7 @@ public:
* The first time that a translator with a particular name is requested, * The first time that a translator with a particular name is requested,
* the on-disk .keytab file is loaded and parsed. * the on-disk .keytab file is loaded and parsed.
*/ */
const KeyboardTranslator* findTranslator(const QString& name); const KeyboardTranslator *findTranslator(const QString &name);
/** /**
* Returns a list of the names of available keyboard translators. * Returns a list of the names of available keyboard translators.
* *
...@@ -89,24 +88,23 @@ public: ...@@ -89,24 +88,23 @@ public:
QStringList allTranslators(); QStringList allTranslators();
/** Returns the global KeyboardTranslatorManager instance. */ /** Returns the global KeyboardTranslatorManager instance. */
static KeyboardTranslatorManager* instance(); static KeyboardTranslatorManager *instance();
private: private:
void findTranslators(); // locate all available translators void findTranslators(); // locate all available translators
// loads the translator with the given name // loads the translator with the given name
KeyboardTranslator* loadTranslator(const QString& name); KeyboardTranslator *loadTranslator(const QString &name);
KeyboardTranslator* loadTranslator(QIODevice* device, const QString& name); KeyboardTranslator *loadTranslator(QIODevice *device, const QString &name);
bool saveTranslator(const KeyboardTranslator* translator); bool saveTranslator(const KeyboardTranslator *translator);
QString findTranslatorPath(const QString& name); QString findTranslatorPath(const QString &name);
bool _haveLoadedAll; bool _haveLoadedAll;
const KeyboardTranslator* _fallbackTranslator; const KeyboardTranslator *_fallbackTranslator;
QHash<QString, KeyboardTranslator*> _translators; QHash<QString, KeyboardTranslator *> _translators;
}; };
} }
#endif // KEYBOARDTRANSLATOR_MANAGER_H #endif // KEYBOARDTRANSLATOR_MANAGER_H
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