Commit b7676178 authored by Kurt Hindenburg's avatar Kurt Hindenburg

uncrustify using kf5 config

parent 9bd78534
This diff is collapsed.
......@@ -34,8 +34,7 @@
class QIODevice;
class QTextStream;
namespace Konsole
{
namespace Konsole {
/**
* A converter which maps between key sequences pressed by the user and the
* character strings which should be sent to the terminal and commands
......@@ -153,7 +152,7 @@ public:
Qt::KeyboardModifiers keyboardModifiers = Qt::NoModifier) const;
/** Sets the character sequence associated with this entry */
void setText(const QByteArray& aText);
void setText(const QByteArray &aText);
/**
* Returns the character sequence associated with this entry,
......@@ -234,16 +233,14 @@ public:
* Returns true if this entry matches the given key sequence, specified
* as a combination of @p keyCode , @p modifiers and @p state.
*/
bool matches(int keyCode ,
Qt::KeyboardModifiers modifiers ,
States flags) const;
bool matches(int keyCode, Qt::KeyboardModifiers modifiers, States flags) const;
bool operator==(const Entry& rhs) const;
bool operator==(const Entry &rhs) const;
private:
void insertModifier(QString& item , int modifier) const;
void insertState(QString& item , int state) const;
QByteArray unescape(const QByteArray& text) const;
void insertModifier(QString &item, int modifier) const;
void insertState(QString &item, int state) const;
QByteArray unescape(const QByteArray &text) const;
int _keyCode;
Qt::KeyboardModifiers _modifiers;
......@@ -256,7 +253,7 @@ public:
};
/** Constructs a new keyboard translator with the given @p name */
explicit KeyboardTranslator(const QString& name);
explicit KeyboardTranslator(const QString &name);
//KeyboardTranslator(const KeyboardTranslator& other);
......@@ -264,13 +261,13 @@ public:
QString name() const;
/** Sets the name of this keyboard translator */
void setName(const QString& name);
void setName(const QString &name);
/** Returns the descriptive name of this keyboard translator */
QString description() const;
/** Sets the descriptive name of this keyboard translator */
void setDescription(const QString& description);
void setDescription(const QString &description);
/**
* Looks for an entry in this keyboard translator which matches the given
......@@ -283,26 +280,24 @@ public:
* @param modifiers A combination of modifiers
* @param state Optional flags which specify the current state of the terminal
*/
Entry findEntry(int keyCode ,
Qt::KeyboardModifiers modifiers ,
States state = NoState) const;
Entry findEntry(int keyCode, Qt::KeyboardModifiers modifiers, States state = NoState) const;
/**
* Adds an entry to this keyboard translator's table. Entries can be looked up according
* to their key sequence using findEntry()
*/
void addEntry(const Entry& entry);
void addEntry(const Entry &entry);
/**
* Replaces an entry in the translator. If the @p existing entry is null,
* then this is equivalent to calling addEntry(@p replacement)
*/
void replaceEntry(const Entry& existing , const Entry& replacement);
void replaceEntry(const Entry &existing, const Entry &replacement);
/**
* Removes an entry from the table.
*/
void removeEntry(const Entry& entry);
void removeEntry(const Entry &entry);
/** Returns a list of all entries in the translator. */
QList<Entry> entries() const;
......@@ -355,11 +350,11 @@ class KeyboardTranslatorReader
{
public:
/** Constructs a new reader which parses the given @p source */
explicit KeyboardTranslatorReader(QIODevice* source);
explicit KeyboardTranslatorReader(QIODevice *source);
~KeyboardTranslatorReader();
KeyboardTranslatorReader(const KeyboardTranslatorReader&) = delete;
KeyboardTranslatorReader& operator=(const KeyboardTranslatorReader&) = delete;
KeyboardTranslatorReader(const KeyboardTranslatorReader &) = delete;
KeyboardTranslatorReader &operator=(const KeyboardTranslatorReader &) = delete;
/**
* Returns the description text.
......@@ -384,8 +379,7 @@ public:
*
* The condition and result strings are in the same format as in
*/
static KeyboardTranslator::Entry createEntry(const QString& condition ,
const QString& result);
static KeyboardTranslator::Entry createEntry(const QString &condition, const QString &result);
private:
struct Token {
enum Type {
......@@ -399,21 +393,18 @@ private:
Type type;
QString text;
};
QList<Token> tokenize(const QString&);
QList<Token> tokenize(const QString &);
void readNext();
bool decodeSequence(const QString& ,
int& keyCode,
Qt::KeyboardModifiers& modifiers,
Qt::KeyboardModifiers& modifierMask,
KeyboardTranslator::States& state,
KeyboardTranslator::States& stateFlags);
static bool parseAsModifier(const QString& item , Qt::KeyboardModifier& modifier);
static bool parseAsStateFlag(const QString& item , KeyboardTranslator::State& state);
static bool parseAsKeyCode(const QString& item , int& keyCode);
static bool parseAsCommand(const QString& text , KeyboardTranslator::Command& command);
QIODevice* _source;
bool decodeSequence(const QString &, int &keyCode, Qt::KeyboardModifiers &modifiers,
Qt::KeyboardModifiers &modifierMask, KeyboardTranslator::States &state,
KeyboardTranslator::States &stateFlags);
static bool parseAsModifier(const QString &item, Qt::KeyboardModifier &modifier);
static bool parseAsStateFlag(const QString &item, KeyboardTranslator::State &state);
static bool parseAsKeyCode(const QString &item, int &keyCode);
static bool parseAsCommand(const QString &text, KeyboardTranslator::Command &command);
QIODevice *_source;
QString _description;
KeyboardTranslator::Entry _nextEntry;
bool _hasNext;
......@@ -427,29 +418,30 @@ public:
* Constructs a new writer which saves data into @p destination.
* The caller is responsible for closing the device when writing is complete.
*/
explicit KeyboardTranslatorWriter(QIODevice* destination);
explicit KeyboardTranslatorWriter(QIODevice *destination);
~KeyboardTranslatorWriter();
KeyboardTranslatorWriter(const KeyboardTranslatorWriter&) = delete;
KeyboardTranslatorWriter& operator=(const KeyboardTranslatorWriter&) = delete;
KeyboardTranslatorWriter(const KeyboardTranslatorWriter &) = delete;
KeyboardTranslatorWriter &operator=(const KeyboardTranslatorWriter &) = delete;
/**
* Writes the header for the keyboard translator.
* @param description Description of the keyboard translator.
*/
void writeHeader(const QString& description);
void writeHeader(const QString &description);
/** Writes a translator entry. */
void writeEntry(const KeyboardTranslator::Entry& entry);
void writeEntry(const KeyboardTranslator::Entry &entry);
private:
QIODevice* _destination;
QTextStream* _writer;
QIODevice *_destination;
QTextStream *_writer;
};
inline int KeyboardTranslator::Entry::keyCode() const
{
return _keyCode;
}
inline void KeyboardTranslator::Entry::setKeyCode(int aKeyCode)
{
_keyCode = aKeyCode;
......@@ -459,6 +451,7 @@ inline void KeyboardTranslator::Entry::setModifiers(Qt::KeyboardModifiers modifi
{
_modifiers = modifier;
}
inline Qt::KeyboardModifiers KeyboardTranslator::Entry::modifiers() const
{
return _modifiers;
......@@ -468,6 +461,7 @@ inline void KeyboardTranslator::Entry::setModifierMask(Qt::KeyboardModifiers ma
{
_modifierMask = mask;
}
inline Qt::KeyboardModifiers KeyboardTranslator::Entry::modifierMask() const
{
return _modifierMask;
......@@ -475,26 +469,29 @@ inline Qt::KeyboardModifiers KeyboardTranslator::Entry::modifierMask() const
inline bool KeyboardTranslator::Entry::isNull() const
{
return (*this == Entry());
return *this == Entry();
}
inline void KeyboardTranslator::Entry::setCommand(Command aCommand)
{
_command = aCommand;
}
inline KeyboardTranslator::Command KeyboardTranslator::Entry::command() const
{
return _command;
}
inline void KeyboardTranslator::Entry::setText(const QByteArray& aText)
inline void KeyboardTranslator::Entry::setText(const QByteArray &aText)
{
_text = unescape(aText);
}
inline int oneOrZero(int value)
{
return value ? 1 : 0;
}
inline QByteArray KeyboardTranslator::Entry::text(bool expandWildCards,
Qt::KeyboardModifiers keyboardModifiers) const
{
......@@ -507,10 +504,11 @@ inline QByteArray KeyboardTranslator::Entry::text(bool expandWildCards,
modifierValue += oneOrZero(keyboardModifiers & Qt::ControlModifier) << 2;
for (int i = 0; i < _text.length(); i++) {
if (expandedText[i] == '*')
if (expandedText[i] == '*') {
expandedText[i] = '0' + modifierValue;
}
}
}
return expandedText;
}
......@@ -519,6 +517,7 @@ inline void KeyboardTranslator::Entry::setState(States aState)
{
_state = aState;
}
inline KeyboardTranslator::States KeyboardTranslator::Entry::state() const
{
return _state;
......@@ -528,6 +527,7 @@ inline void KeyboardTranslator::Entry::setStateMask(States aStateMask)
{
_stateMask = aStateMask;
}
inline KeyboardTranslator::States KeyboardTranslator::Entry::stateMask() const
{
return _stateMask;
......@@ -535,7 +535,6 @@ inline KeyboardTranslator::States KeyboardTranslator::Entry::stateMask() const
}
Q_DECLARE_METATYPE(Konsole::KeyboardTranslator::Entry)
Q_DECLARE_METATYPE(const Konsole::KeyboardTranslator*)
Q_DECLARE_METATYPE(const Konsole::KeyboardTranslator *)
#endif // KEYBOARDTRANSLATOR_H
......@@ -32,10 +32,10 @@
using namespace Konsole;
KeyboardTranslatorManager::KeyboardTranslatorManager()
: _haveLoadedAll(false)
, _fallbackTranslator(0)
, _translators(QHash<QString, KeyboardTranslator*>())
KeyboardTranslatorManager::KeyboardTranslatorManager() :
_haveLoadedAll(false),
_fallbackTranslator(0),
_translators(QHash<QString, KeyboardTranslator *>())
{
_fallbackTranslator = new FallbackKeyboardTranslator();
}
......@@ -52,16 +52,17 @@ KeyboardTranslatorManager* KeyboardTranslatorManager::instance()
return theKeyboardTranslatorManager;
}
void KeyboardTranslatorManager::addTranslator(KeyboardTranslator* translator)
void KeyboardTranslatorManager::addTranslator(KeyboardTranslator *translator)
{
_translators.insert(translator->name(), translator);
if (!saveTranslator(translator))
if (!saveTranslator(translator)) {
qCDebug(KonsoleDebug) << "Unable to save translator" << translator->name()
<< "to disk.";
}
}
bool KeyboardTranslatorManager::deleteTranslator(const QString& name)
bool KeyboardTranslatorManager::deleteTranslator(const QString &name)
{
Q_ASSERT(_translators.contains(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"));
}
void KeyboardTranslatorManager::findTranslators()
{
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());
Q_FOREACH (const QString& dir, dirs) {
Q_FOREACH (const QString &dir, dirs) {
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);
}
}
......@@ -98,37 +99,42 @@ void KeyboardTranslatorManager::findTranslators()
// add the name of each translator to the list and associated
// the name with a null pointer to indicate that the translator
// has not yet been loaded from disk
foreach(const QString& translatorPath, list) {
foreach (const QString &translatorPath, list) {
QString name = QFileInfo(translatorPath).baseName();
if (!_translators.contains(name))
if (!_translators.contains(name)) {
_translators.insert(name, 0);
}
}
_haveLoadedAll = true;
}
const KeyboardTranslator* KeyboardTranslatorManager::findTranslator(const QString& name)
const KeyboardTranslator *KeyboardTranslatorManager::findTranslator(const QString &name)
{
if (name.isEmpty())
if (name.isEmpty()) {
return defaultTranslator();
}
if (_translators.contains(name) && _translators[name] != 0)
if (_translators.contains(name) && _translators[name] != 0) {
return _translators[name];
}
KeyboardTranslator* translator = loadTranslator(name);
KeyboardTranslator *translator = loadTranslator(name);
if (translator != 0)
if (translator != 0) {
_translators[name] = translator;
else if (!name.isEmpty())
} else if (!name.isEmpty()) {
qCDebug(KonsoleDebug) << "Unable to load translator" << name;
}
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);
const QString path = dir + translator->name() + QStringLiteral(".keytab");
......@@ -145,7 +151,7 @@ bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator* transla
KeyboardTranslatorWriter writer(&destination);
writer.writeHeader(translator->description());
foreach(const KeyboardTranslator::Entry& entry, translator->entries()) {
foreach (const KeyboardTranslator::Entry &entry, translator->entries()) {
writer.writeEntry(entry);
}
}
......@@ -155,24 +161,27 @@ bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator* transla
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);
if (name.isEmpty() || !source.open(QIODevice::ReadOnly | QIODevice::Text))
if (name.isEmpty() || !source.open(QIODevice::ReadOnly | QIODevice::Text)) {
return 0;
}
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);
KeyboardTranslatorReader reader(source);
translator->setDescription(reader.description());
while (reader.hasNextEntry())
while (reader.hasNextEntry()) {
translator->addEntry(reader.nextEntry());
}
source->close();
......@@ -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
// fall back to the internal hard-coded fallback translator
const KeyboardTranslator* translator = findTranslator(QStringLiteral("default"));
const KeyboardTranslator *translator = findTranslator(QStringLiteral("default"));
if (translator == nullptr) {
translator = _fallbackTranslator;
}
......
......@@ -32,8 +32,7 @@
class QIODevice;
namespace Konsole
{
namespace Konsole {
/**
* Manages the keyboard translations available for use by terminal sessions,
* see KeyboardTranslator.
......@@ -51,8 +50,8 @@ public:
KeyboardTranslatorManager();
~KeyboardTranslatorManager();
KeyboardTranslatorManager(const KeyboardTranslatorManager&) = delete;
KeyboardTranslatorManager& operator=(const KeyboardTranslatorManager&) = delete;
KeyboardTranslatorManager(const KeyboardTranslatorManager &) = delete;
KeyboardTranslatorManager &operator=(const KeyboardTranslatorManager &) = delete;
/**
* Adds a new translator. If a translator with the same name
......@@ -60,17 +59,17 @@ public:
*
* TODO: More documentation.
*/
void addTranslator(KeyboardTranslator* translator);
void addTranslator(KeyboardTranslator *translator);
/**
* Deletes a translator. Returns true on successful deletion or false otherwise.
*
* TODO: More documentation
*/
bool deleteTranslator(const QString& name);
bool deleteTranslator(const QString &name);
/** 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
......@@ -79,7 +78,7 @@ public:
* The first time that a translator with a particular name is requested,
* 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.
*
......@@ -89,24 +88,23 @@ public:
QStringList allTranslators();
/** Returns the global KeyboardTranslatorManager instance. */
static KeyboardTranslatorManager* instance();
static KeyboardTranslatorManager *instance();
private:
void findTranslators(); // locate all available translators
// loads the translator with the given name
KeyboardTranslator* loadTranslator(const QString& name);
KeyboardTranslator* loadTranslator(QIODevice* device, const QString& name);
KeyboardTranslator *loadTranslator(const QString &name);
KeyboardTranslator *loadTranslator(QIODevice *device, const QString &name);
bool saveTranslator(const KeyboardTranslator* translator);
QString findTranslatorPath(const QString& name);
bool saveTranslator(const KeyboardTranslator *translator);
QString findTranslatorPath(const QString &name);
bool _haveLoadedAll;
const KeyboardTranslator* _fallbackTranslator;
QHash<QString, KeyboardTranslator*> _translators;
const KeyboardTranslator *_fallbackTranslator;
QHash<QString, KeyboardTranslator *> _translators;
};
}
#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