Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize code (Qt5 connects + init of params) #474

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
40 changes: 12 additions & 28 deletions lib/Emulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,19 @@

using namespace Konsole;

Emulation::Emulation() :
_currentScreen(nullptr),
_codec(nullptr),
_decoder(nullptr),
_keyTranslator(nullptr),
_usesMouse(false),
_bracketedPasteMode(false)
Emulation::Emulation()
{
// create screens with a default size
_screen[0] = new Screen(40,80);
_screen[1] = new Screen(40,80);
_currentScreen = _screen[0];

QObject::connect(&_bulkTimer1, SIGNAL(timeout()), this, SLOT(showBulk()) );
QObject::connect(&_bulkTimer2, SIGNAL(timeout()), this, SLOT(showBulk()) );
connect(&_bulkTimer1, &QTimer::timeout, this, &Emulation::showBulk);
connect(&_bulkTimer2, &QTimer::timeout, this, &Emulation::showBulk);

// listen for mouse status changes
connect(this , SIGNAL(programUsesMouseChanged(bool)) ,
SLOT(usesMouseChanged(bool)));
connect(this , SIGNAL(programBracketedPasteModeChanged(bool)) ,
SLOT(bracketedPasteModeChanged(bool)));
connect(this, &Emulation::programUsesMouseChanged, this, &Emulation::usesMouseChanged);
connect(this, &Emulation::programBracketedPasteModeChanged, this, &Emulation::bracketedPasteModeChanged);

connect(this, &Emulation::cursorChanged, this, [this] (KeyboardCursorShape cursorShape, bool blinkingCursorEnabled) {
emit titleChanged( 50, QString(QLatin1String("CursorShape=%1;BlinkingCursorEnabled=%2"))
Expand Down Expand Up @@ -104,28 +96,20 @@ ScreenWindow* Emulation::createWindow()
window->setScreen(_currentScreen);
_windows << window;

connect(window , SIGNAL(selectionChanged()),
this , SLOT(bufferedUpdate()));

connect(this , SIGNAL(outputChanged()),
window , SLOT(notifyOutputChanged()) );

connect(this, &Emulation::handleCommandFromKeyboard,
window, &ScreenWindow::handleCommandFromKeyboard);
connect(this, &Emulation::outputFromKeypressEvent,
window, &ScreenWindow::scrollToEnd);
connect(window, &ScreenWindow::selectionChanged, this, &Emulation::bufferedUpdate);
connect(this, &Emulation::outputChanged, window, &ScreenWindow::notifyOutputChanged);
connect(this, &Emulation::handleCommandFromKeyboard, window, &ScreenWindow::handleCommandFromKeyboard);
connect(this, &Emulation::outputFromKeypressEvent, window, &ScreenWindow::scrollToEnd);

return window;
}

Emulation::~Emulation()
{
QListIterator<ScreenWindow*> windowIter(_windows);
for (auto window : qAsConst(_windows))
delete window;

while (windowIter.hasNext())
{
delete windowIter.next();
}
_windows.clear();

delete _screen[0];
delete _screen[1];
Expand Down
12 changes: 6 additions & 6 deletions lib/Emulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public slots:

QList<ScreenWindow*> _windows;

Screen* _currentScreen; // pointer to the screen which is currently active,
Screen* _currentScreen = nullptr; // pointer to the screen which is currently active,
// this is one of the elements in the screen[] array

Screen* _screen[2]; // 0 = primary screen ( used by most programs, including the shell
Expand All @@ -485,9 +485,9 @@ public slots:

//decodes an incoming C-style character stream into a unicode QString using
//the current text codec. (this allows for rendering of non-ASCII characters in text files etc.)
const QTextCodec* _codec;
QTextDecoder* _decoder;
const KeyboardTranslator* _keyTranslator; // the keyboard layout
const QTextCodec* _codec = nullptr;
QTextDecoder* _decoder = nullptr;
const KeyboardTranslator* _keyTranslator = nullptr; // the keyboard layout

protected slots:
/**
Expand All @@ -508,8 +508,8 @@ private slots:
void bracketedPasteModeChanged(bool bracketedPasteMode);

private:
bool _usesMouse;
bool _bracketedPasteMode;
bool _usesMouse = false;
bool _bracketedPasteMode = false;
QTimer _bulkTimer1;
QTimer _bulkTimer2;

Expand Down
6 changes: 3 additions & 3 deletions lib/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ Filter::HotSpot::HotSpot(int startLine , int startColumn , int endLine , int end
, _startColumn(startColumn)
, _endLine(endLine)
, _endColumn(endColumn)
, _type(NotSpecified)
{
}
QList<QAction*> Filter::HotSpot::actions()
Expand Down Expand Up @@ -421,8 +420,9 @@ UrlFilter::HotSpot::UrlType UrlFilter::HotSpot::urlType() const
return StandardUrl;
else if ( EmailAddressRegExp.exactMatch(url) )
return Email;
else
return Unknown;


return Unknown;
}

void UrlFilter::HotSpot::activate(const QString& actionName)
Expand Down
2 changes: 1 addition & 1 deletion lib/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class QTERMWIDGET_EXPORT Filter : public QObject
int _startColumn;
int _endLine;
int _endColumn;
Type _type;
Type _type = NotSpecified;

};

Expand Down
14 changes: 1 addition & 13 deletions lib/History.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ FIXME: There is noticeable decrease in speed, also. Perhaps,
*/

HistoryFile::HistoryFile()
: ion(-1),
length(0),
fileMap(nullptr),
readWriteBalance(0)
{
if (tmpFile.open())
{
Expand Down Expand Up @@ -177,7 +173,7 @@ void HistoryFile::get(unsigned char* bytes, int len, int loc)
}
}

int HistoryFile::len()
int HistoryFile::len() const
{
return length;
}
Expand Down Expand Up @@ -220,10 +216,6 @@ HistoryScrollFile::HistoryScrollFile(const QString &logFileName)
{
}

HistoryScrollFile::~HistoryScrollFile()
{
}

int HistoryScrollFile::getLines()
{
return index.len() / sizeof(int);
Expand Down Expand Up @@ -425,10 +417,6 @@ HistoryScrollNone::HistoryScrollNone()
{
}

HistoryScrollNone::~HistoryScrollNone()
{
}

bool HistoryScrollNone::hasScroll()
{
return false;
Expand Down
24 changes: 12 additions & 12 deletions lib/History.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class HistoryFile

virtual void add(const unsigned char* bytes, int len);
virtual void get(unsigned char* bytes, int len, int loc);
virtual int len();
virtual int len() const final;

//mmaps the file in read-only mode
void map();
Expand All @@ -64,18 +64,18 @@ class HistoryFile


private:
int ion;
int length;
int ion = -1;
int length = 0;
QTemporaryFile tmpFile;

//pointer to start of mmap'ed file data, or 0 if the file is not mmap'ed
char* fileMap;
char* fileMap = nullptr;

//incremented whenver 'add' is called and decremented whenever
//'get' is called.
//this is used to detect when a large number of lines are being read and processed from the history
//and automatically mmap the file for better performance (saves the overhead of many lseek-read calls).
int readWriteBalance;
int readWriteBalance = 0;

//when readWriteBalance goes below this threshold, the file will be mmap'ed automatically
static const int MAP_THRESHOLD = -1000;
Expand Down Expand Up @@ -125,7 +125,7 @@ class HistoryScroll
const HistoryType& getType() { return *m_histType; }

protected:
HistoryType* m_histType;
HistoryType* m_histType = nullptr;

};

Expand All @@ -135,11 +135,11 @@ class HistoryScroll
// File-based history (e.g. file log, no limitation in length)
//////////////////////////////////////////////////////////////////////

class HistoryScrollFile : public HistoryScroll
class HistoryScrollFile final : public HistoryScroll
{
public:
HistoryScrollFile(const QString &logFileName);
~HistoryScrollFile() override;
~HistoryScrollFile() override = default;

int getLines() override;
int getLineLen(int lineno) override;
Expand All @@ -162,7 +162,7 @@ class HistoryScrollFile : public HistoryScroll
//////////////////////////////////////////////////////////////////////
// Buffer-based history (limited to a fixed nb of lines)
//////////////////////////////////////////////////////////////////////
class HistoryScrollBuffer : public HistoryScroll
class HistoryScrollBuffer final : public HistoryScroll
{
public:
typedef QVector<Character> HistoryLine;
Expand Down Expand Up @@ -219,11 +219,11 @@ class HistoryScrollBuffer : public HistoryScroll
//////////////////////////////////////////////////////////////////////
// Nothing-based history (no history :-)
//////////////////////////////////////////////////////////////////////
class HistoryScrollNone : public HistoryScroll
class HistoryScrollNone final : public HistoryScroll
{
public:
HistoryScrollNone();
~HistoryScrollNone() override;
~HistoryScrollNone() override = default;

bool hasScroll() override;

Expand Down Expand Up @@ -322,7 +322,7 @@ class CompactHistoryBlock

class CompactHistoryBlockList {
public:
CompactHistoryBlockList() {};
CompactHistoryBlockList() = default;
~CompactHistoryBlockList();

void *allocate( size_t size );
Expand Down
9 changes: 2 additions & 7 deletions lib/Pty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,15 @@ Pty::Pty(int masterFd, QObject* parent)
{
init();
}

Pty::Pty(QObject* parent)
: KPtyProcess(parent)
{
init();
}
void Pty::init()
{
_windowColumns = 0;
_windowLines = 0;
_eraseChar = 0;
_xonXoff = true;
_utf8 =true;

connect(pty(), SIGNAL(readyRead()) , this , SLOT(dataReceived()));
connect(pty(), &KPtyDevice::readyRead, this , &Pty::dataReceived);
setPtyChannels(KPtyProcess::AllChannels);
}

Expand Down
17 changes: 8 additions & 9 deletions lib/Pty.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,21 @@ Q_OBJECT
protected:
void setupChildProcess() override;

private slots:
// called when data is received from the terminal process
void dataReceived();

private:
void init();

// takes a list of key=value pairs and adds them
// to the environment for the process
void addEnvironmentVariables(const QStringList& environment);

int _windowColumns;
int _windowLines;
char _eraseChar;
bool _xonXoff;
bool _utf8;
// called when data is received from the terminal process
void dataReceived();

int _windowColumns = 0;
int _windowLines = 0;
char _eraseChar = 0;
bool _xonXoff = true;
bool _utf8 = true;
};

}
Expand Down
13 changes: 2 additions & 11 deletions lib/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,10 @@ Character Screen::defaultChar = Character(' ',
: lines(l),
columns(c),
screenLines(new ImageLine[lines+1] ),
_scrolledLines(0),
_droppedLines(0),
history(new HistoryScrollNone()),
cuX(0), cuY(0),
currentRendition(0),
_topMargin(0), _bottomMargin(0),
selBegin(0), selTopLeft(0), selBottomRight(0),
blockSelectionMode(false),
effectiveForeground(CharacterColor()), effectiveBackground(CharacterColor()), effectiveRendition(0),
lastPos(-1)
history(new HistoryScrollNone())
{
lineProperties.resize(lines+1);
for (int i=0;i<lines+1;i++)
for (int i=0; i < lines+1; ++i)
lineProperties[i]=LINE_DEFAULT;

initTabStops();
Expand Down
Loading