Commit 51a345bf authored by Gustavo Carneiro's avatar Gustavo Carneiro

Move a FallbackKeyboardTranslator class to a new files,...

Move a FallbackKeyboardTranslator class to a new files, FallbackKeyboardTranslator.h and FallbackKeyboardTranslator.cpp
Move a KeyboardTranslatorReader class to a new files, KeyboardTranslatorReader.h and KeyboardTranslatorReader.cpp
Move a KeyboardTranslatorWriter class to a new files, KeyboardTranslatorWriter.h and KeyboardTranslatorWriter.cpp
parent 2b5dc82f
......@@ -94,6 +94,9 @@ set(konsoleprivate_SRCS ${sessionadaptors_SRCS}
widgets/IncrementalSearchBar.cpp
KeyBindingEditor.cpp
KeyboardTranslator.cpp
FallbackKeyboardTranslator.cpp
KeyboardTranslatorReader.cpp
KeyboardTranslatorWriter.cpp
KeyboardTranslatorManager.cpp
ProcessInfo.cpp
Profile.cpp
......
/*
This source file is part of Konsole, a terminal emulator.
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
// Own
#include "FallbackKeyboardTranslator.h"
using namespace Konsole;
FallbackKeyboardTranslator::FallbackKeyboardTranslator() :
KeyboardTranslator(QStringLiteral("fallback"))
{
setDescription(QStringLiteral("Fallback Keyboard Translator"));
// Key "TAB" should send out '\t'
KeyboardTranslator::Entry entry;
entry.setKeyCode(Qt::Key_Tab);
entry.setText("\t");
addEntry(entry);
}
/*
This source file is part of Konsole, a terminal emulator.
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
#ifndef FALLBACKKEYBOARDTRANSLATOR_H
#define FALLBACKKEYBOARDTRANSLATOR_H
// Konsole
#include "KeyboardTranslator.h"
namespace Konsole
{
class KONSOLEPRIVATE_EXPORT FallbackKeyboardTranslator : public KeyboardTranslator
{
public:
FallbackKeyboardTranslator();
};
}
#endif
......@@ -33,6 +33,7 @@
#include "ui_KeyBindingEditor.h"
#include "EditProfileDialog.h"
#include "KeyboardTranslator.h"
#include "KeyboardTranslatorReader.h"
#include "KeyboardTranslatorManager.h"
using namespace Konsole;
......
This diff is collapsed.
......@@ -304,131 +304,6 @@ private:
Q_DECLARE_OPERATORS_FOR_FLAGS(KeyboardTranslator::States)
Q_DECLARE_OPERATORS_FOR_FLAGS(KeyboardTranslator::Commands)
class KONSOLEPRIVATE_EXPORT FallbackKeyboardTranslator : public KeyboardTranslator
{
public:
FallbackKeyboardTranslator();
};
/**
* Parses the contents of a Keyboard Translator (.keytab) file and
* returns the entries found in it.
*
* Usage example:
*
* @code
* QFile source( "/path/to/keytab" );
* source.open( QIODevice::ReadOnly );
*
* KeyboardTranslator* translator = new KeyboardTranslator( "name-of-translator" );
*
* KeyboardTranslatorReader reader(source);
* while ( reader.hasNextEntry() )
* translator->addEntry(reader.nextEntry());
*
* source.close();
*
* if ( !reader.parseError() )
* {
* // parsing succeeded, do something with the translator
* }
* else
* {
* // parsing failed
* }
* @endcode
*/
class KONSOLEPRIVATE_EXPORT KeyboardTranslatorReader
{
public:
/** Constructs a new reader which parses the given @p source */
explicit KeyboardTranslatorReader(QIODevice *source);
~KeyboardTranslatorReader();
KeyboardTranslatorReader(const KeyboardTranslatorReader &) = delete;
KeyboardTranslatorReader &operator=(const KeyboardTranslatorReader &) = delete;
/**
* Returns the description text.
* TODO: More documentation
*/
QString description() const;
/** Returns true if there is another entry in the source stream */
bool hasNextEntry() const;
/** Returns the next entry found in the source stream */
KeyboardTranslator::Entry nextEntry();
/**
* Returns true if an error occurred whilst parsing the input or
* false if no error occurred.
*/
bool parseError();
/**
* Parses a condition and result string for a translator entry
* and produces a keyboard translator entry.
*
* The condition and result strings are in the same format as in
*/
static KeyboardTranslator::Entry createEntry(const QString &condition, const QString &result);
private:
struct Token {
enum Type {
TitleKeyword,
TitleText,
KeyKeyword,
KeySequence,
Command,
OutputText
};
Type type;
QString text;
};
QList<Token> tokenize(const QString &);
void readNext();
bool decodeSequence(const QString &, int &keyCode, Qt::KeyboardModifiers &modifiers,
Qt::KeyboardModifiers &modifierMask, KeyboardTranslator::States &flags,
KeyboardTranslator::States &flagMask);
static bool parseAsModifier(const QString &item, Qt::KeyboardModifier &modifier);
static bool parseAsStateFlag(const QString &item, KeyboardTranslator::State &flag);
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;
};
/** Writes a keyboard translation to disk. */
class KeyboardTranslatorWriter
{
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);
~KeyboardTranslatorWriter();
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);
/** Writes a translator entry. */
void writeEntry(const KeyboardTranslator::Entry &entry);
private:
QIODevice *_destination;
QTextStream *_writer;
};
inline int KeyboardTranslator::Entry::keyCode() const
{
return _keyCode;
......
......@@ -22,6 +22,10 @@
// Own
#include "KeyboardTranslatorManager.h"
#include "FallbackKeyboardTranslator.h"
#include "KeyboardTranslatorReader.h"
#include "KeyboardTranslatorWriter.h"
#include "konsoledebug.h"
// Qt
......
This diff is collapsed.
/*
This source file is part of Konsole, a terminal emulator.
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
#ifndef KEYBOARDTRANSLATORREADER_H
#define KEYBOARDTRANSLATORREADER_H
// Konsole
#include "KeyboardTranslator.h"
class QIODevice;
namespace Konsole
{
/**
* Parses the contents of a Keyboard Translator (.keytab) file and
* returns the entries found in it.
*
* Usage example:
*
* @code
* QFile source( "/path/to/keytab" );
* source.open( QIODevice::ReadOnly );
*
* KeyboardTranslator* translator = new KeyboardTranslator( "name-of-translator" );
*
* KeyboardTranslatorReader reader(source);
* while ( reader.hasNextEntry() )
* translator->addEntry(reader.nextEntry());
*
* source.close();
*
* if ( !reader.parseError() )
* {
* // parsing succeeded, do something with the translator
* }
* else
* {
* // parsing failed
* }
* @endcode
*/
class KONSOLEPRIVATE_EXPORT KeyboardTranslatorReader
{
public:
/** Constructs a new reader which parses the given @p source */
explicit KeyboardTranslatorReader(QIODevice *source);
~KeyboardTranslatorReader();
KeyboardTranslatorReader(const KeyboardTranslatorReader &) = delete;
KeyboardTranslatorReader &operator=(const KeyboardTranslatorReader &) = delete;
/**
* Returns the description text.
* TODO: More documentation
*/
QString description() const;
/** Returns true if there is another entry in the source stream */
bool hasNextEntry() const;
/** Returns the next entry found in the source stream */
KeyboardTranslator::Entry nextEntry();
/**
* Returns true if an error occurred whilst parsing the input or
* false if no error occurred.
*/
bool parseError();
/**
* Parses a condition and result string for a translator entry
* and produces a keyboard translator entry.
*
* The condition and result strings are in the same format as in
*/
static KeyboardTranslator::Entry createEntry(const QString &condition, const QString &result);
private:
struct Token {
enum Type {
TitleKeyword,
TitleText,
KeyKeyword,
KeySequence,
Command,
OutputText
};
Type type;
QString text;
};
QList<Token> tokenize(const QString &);
void readNext();
bool decodeSequence(const QString &, int &keyCode, Qt::KeyboardModifiers &modifiers,
Qt::KeyboardModifiers &modifierMask, KeyboardTranslator::States &flags,
KeyboardTranslator::States &flagMask);
static bool parseAsModifier(const QString &item, Qt::KeyboardModifier &modifier);
static bool parseAsStateFlag(const QString &item, KeyboardTranslator::State &flag);
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;
};
}
#endif
/*
This source file is part of Konsole, a terminal emulator.
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
// Own
#include "KeyboardTranslatorWriter.h"
// Qt
#include <QIODevice>
#include <QTextStream>
using namespace Konsole;
KeyboardTranslatorWriter::KeyboardTranslatorWriter(QIODevice *destination) :
_destination(destination),
_writer(nullptr)
{
Q_ASSERT(destination && destination->isWritable());
_writer = new QTextStream(_destination);
}
KeyboardTranslatorWriter::~KeyboardTranslatorWriter()
{
delete _writer;
}
void KeyboardTranslatorWriter::writeHeader(const QString &description)
{
*_writer << "keyboard \"" << description << '\"' << '\n';
}
void KeyboardTranslatorWriter::writeEntry(const KeyboardTranslator::Entry &entry)
{
QString result;
if (entry.command() != KeyboardTranslator::NoCommand) {
result = entry.resultToString();
} else {
result = QLatin1Char('\"') + entry.resultToString() + QLatin1Char('\"');
}
*_writer << "key " << entry.conditionToString() << " : " << result << '\n';
}
/*
This source file is part of Konsole, a terminal emulator.
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
#ifndef KEYBOARDTRANSLATORWRITER_H
#define KEYBOARDTRANSLATORWRITER_H
#include "KeyboardTranslator.h"
namespace Konsole
{
/** Writes a keyboard translation to disk. */
class KeyboardTranslatorWriter
{
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);
~KeyboardTranslatorWriter();
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);
/** Writes a translator entry. */
void writeEntry(const KeyboardTranslator::Entry &entry);
private:
QIODevice *_destination;
QTextStream *_writer;
};
}
#endif
......@@ -20,6 +20,9 @@
// Own
#include "KeyboardTranslatorTest.h"
#include "FallbackKeyboardTranslator.h"
#include "KeyboardTranslatorReader.h"
// KDE
#include <qtest.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