diff --git a/lib/Emulation.cpp b/lib/Emulation.cpp index 723f5d20..87735d58 100644 --- a/lib/Emulation.cpp +++ b/lib/Emulation.cpp @@ -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")) @@ -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 windowIter(_windows); + for (auto window : qAsConst(_windows)) + delete window; - while (windowIter.hasNext()) - { - delete windowIter.next(); - } + _windows.clear(); delete _screen[0]; delete _screen[1]; diff --git a/lib/Emulation.h b/lib/Emulation.h index 7d2263b5..f72afcaf 100644 --- a/lib/Emulation.h +++ b/lib/Emulation.h @@ -474,7 +474,7 @@ public slots: QList _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 @@ -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: /** @@ -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; diff --git a/lib/Filter.cpp b/lib/Filter.cpp index f2192929..d3e8e67c 100644 --- a/lib/Filter.cpp +++ b/lib/Filter.cpp @@ -283,7 +283,6 @@ Filter::HotSpot::HotSpot(int startLine , int startColumn , int endLine , int end , _startColumn(startColumn) , _endLine(endLine) , _endColumn(endColumn) - , _type(NotSpecified) { } QList Filter::HotSpot::actions() @@ -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) diff --git a/lib/Filter.h b/lib/Filter.h index 5da1242b..2d12333e 100644 --- a/lib/Filter.h +++ b/lib/Filter.h @@ -127,7 +127,7 @@ class QTERMWIDGET_EXPORT Filter : public QObject int _startColumn; int _endLine; int _endColumn; - Type _type; + Type _type = NotSpecified; }; diff --git a/lib/History.cpp b/lib/History.cpp index ec3536bd..6f46017d 100644 --- a/lib/History.cpp +++ b/lib/History.cpp @@ -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()) { @@ -177,7 +173,7 @@ void HistoryFile::get(unsigned char* bytes, int len, int loc) } } -int HistoryFile::len() +int HistoryFile::len() const { return length; } @@ -220,10 +216,6 @@ HistoryScrollFile::HistoryScrollFile(const QString &logFileName) { } -HistoryScrollFile::~HistoryScrollFile() -{ -} - int HistoryScrollFile::getLines() { return index.len() / sizeof(int); @@ -425,10 +417,6 @@ HistoryScrollNone::HistoryScrollNone() { } -HistoryScrollNone::~HistoryScrollNone() -{ -} - bool HistoryScrollNone::hasScroll() { return false; diff --git a/lib/History.h b/lib/History.h index eb8c9e10..169e6af6 100644 --- a/lib/History.h +++ b/lib/History.h @@ -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(); @@ -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; @@ -125,7 +125,7 @@ class HistoryScroll const HistoryType& getType() { return *m_histType; } protected: - HistoryType* m_histType; + HistoryType* m_histType = nullptr; }; @@ -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; @@ -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 HistoryLine; @@ -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; @@ -322,7 +322,7 @@ class CompactHistoryBlock class CompactHistoryBlockList { public: - CompactHistoryBlockList() {}; + CompactHistoryBlockList() = default; ~CompactHistoryBlockList(); void *allocate( size_t size ); diff --git a/lib/Pty.cpp b/lib/Pty.cpp index 821517a3..76103b0c 100644 --- a/lib/Pty.cpp +++ b/lib/Pty.cpp @@ -256,6 +256,7 @@ Pty::Pty(int masterFd, QObject* parent) { init(); } + Pty::Pty(QObject* parent) : KPtyProcess(parent) { @@ -263,13 +264,7 @@ Pty::Pty(QObject* parent) } 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); } diff --git a/lib/Pty.h b/lib/Pty.h index f427a53a..fbf83c31 100644 --- a/lib/Pty.h +++ b/lib/Pty.h @@ -191,10 +191,6 @@ Q_OBJECT protected: void setupChildProcess() override; - private slots: - // called when data is received from the terminal process - void dataReceived(); - private: void init(); @@ -202,11 +198,14 @@ Q_OBJECT // 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; }; } diff --git a/lib/Screen.cpp b/lib/Screen.cpp index bd6a375d..5805f286 100644 --- a/lib/Screen.cpp +++ b/lib/Screen.cpp @@ -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 ImageLine; // [0..columns] ImageLine* screenLines; // [lines] - int _scrolledLines; + int _scrolledLines = 0; QRect _lastScrolledRegion; - int _droppedLines; + int _droppedLines = 0; QVarLengthArray lineProperties; // history buffer --------------- - HistoryScroll* history; + HistoryScroll* history = nullptr; // cursor location - int cuX; - int cuY; + int cuX = 0; + int cuY = 0; // cursor color and rendition info CharacterColor currentForeground; CharacterColor currentBackground; - quint8 currentRendition; + quint8 currentRendition = 0; // margins ---------------- - int _topMargin; - int _bottomMargin; + int _topMargin = 0; + int _bottomMargin = 0; // states ---------------- bool currentModes[MODES_SCREEN]; @@ -657,15 +657,15 @@ class Screen QBitArray tabStops; // selection ------------------- - int selBegin; // The first location selected. - int selTopLeft; // TopLeft Location. - int selBottomRight; // Bottom Right Location. - bool blockSelectionMode; // Column selection mode + int selBegin = 0; // The first location selected. + int selTopLeft = 0; // TopLeft Location. + int selBottomRight = 0; // Bottom Right Location. + bool blockSelectionMode = false; // Column selection mode // effective colors and rendition ------------ CharacterColor effectiveForeground; // These are derived from CharacterColor effectiveBackground; // the cu_* variables above - quint8 effectiveRendition; // to speed up operation + quint8 effectiveRendition = 0; // to speed up operation class SavedState { @@ -682,7 +682,7 @@ class Screen SavedState savedState; // last position where we added a character - int lastPos; + int lastPos = -1; // used in REP (repeating char) unsigned short lastDrawnChar; diff --git a/lib/ScreenWindow.cpp b/lib/ScreenWindow.cpp index a6ce7c27..9c6faa79 100644 --- a/lib/ScreenWindow.cpp +++ b/lib/ScreenWindow.cpp @@ -30,20 +30,14 @@ using namespace Konsole; ScreenWindow::ScreenWindow(QObject* parent) : QObject(parent) - , _screen(nullptr) - , _windowBuffer(nullptr) - , _windowBufferSize(0) - , _bufferNeedsUpdate(true) - , _windowLines(1) - , _currentLine(0) - , _trackOutput(true) - , _scrollCount(0) { } + ScreenWindow::~ScreenWindow() { delete[] _windowBuffer; } + void ScreenWindow::setScreen(Screen* screen) { Q_ASSERT( screen ); diff --git a/lib/ScreenWindow.h b/lib/ScreenWindow.h index 3a75c085..9de12da5 100644 --- a/lib/ScreenWindow.h +++ b/lib/ScreenWindow.h @@ -248,15 +248,15 @@ public slots: int endWindowLine() const; void fillUnusedArea(); - Screen* _screen; // see setScreen() , screen() - Character* _windowBuffer; - int _windowBufferSize; - bool _bufferNeedsUpdate; - - int _windowLines; - int _currentLine; // see scrollTo() , currentLine() - bool _trackOutput; // see setTrackOutput() , trackOutput() - int _scrollCount; // count of lines which the window has been scrolled by since + Screen* _screen = nullptr; // see setScreen() , screen() + Character* _windowBuffer = nullptr; + int _windowBufferSize = 0; + bool _bufferNeedsUpdate = true; + + int _windowLines = 1; + int _currentLine = 0; // see scrollTo() , currentLine() + bool _trackOutput = true; // see setTrackOutput() , trackOutput() + int _scrollCount = 0; // count of lines which the window has been scrolled by since // the last call to resetScrollCount() }; diff --git a/lib/SearchBar.cpp b/lib/SearchBar.cpp index 1de92f45..23406add 100644 --- a/lib/SearchBar.cpp +++ b/lib/SearchBar.cpp @@ -28,11 +28,11 @@ SearchBar::SearchBar(QWidget *parent) : QWidget(parent) widget.setupUi(this); setAutoFillBackground(true); // make it always opaque, especially inside translucent windows connect(widget.closeButton, &QAbstractButton::clicked, this, &SearchBar::hide); - connect(widget.searchTextEdit, SIGNAL(textChanged(QString)), this, SIGNAL(searchCriteriaChanged())); - connect(widget.findPreviousButton, SIGNAL(clicked()), this, SIGNAL(findPrevious())); - connect(widget.findNextButton, SIGNAL(clicked()), this, SIGNAL(findNext())); + connect(widget.searchTextEdit, &QLineEdit::textChanged, this, &SearchBar::searchCriteriaChanged); + connect(widget.findPreviousButton, &QToolButton::clicked, this, &SearchBar::findPrevious); + connect(widget.findNextButton, &QToolButton::clicked, this, &SearchBar::findNext); - connect(this, SIGNAL(searchCriteriaChanged()), this, SLOT(clearBackgroundColor())); + connect(this, &SearchBar::searchCriteriaChanged, this, &SearchBar::clearBackgroundColor); QMenu *optionsMenu = new QMenu(widget.optionsButton); widget.optionsButton->setMenu(optionsMenu); @@ -40,39 +40,39 @@ SearchBar::SearchBar(QWidget *parent) : QWidget(parent) m_matchCaseMenuEntry = optionsMenu->addAction(tr("Match case")); m_matchCaseMenuEntry->setCheckable(true); m_matchCaseMenuEntry->setChecked(true); - connect(m_matchCaseMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(searchCriteriaChanged())); + connect(m_matchCaseMenuEntry, &QAction::toggled, this, &SearchBar::searchCriteriaChanged); m_useRegularExpressionMenuEntry = optionsMenu->addAction(tr("Regular expression")); m_useRegularExpressionMenuEntry->setCheckable(true); - connect(m_useRegularExpressionMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(searchCriteriaChanged())); + connect(m_useRegularExpressionMenuEntry, &QAction::toggled, this, &SearchBar::searchCriteriaChanged); m_highlightMatchesMenuEntry = optionsMenu->addAction(tr("Highlight all matches")); m_highlightMatchesMenuEntry->setCheckable(true); m_highlightMatchesMenuEntry->setChecked(true); - connect(m_highlightMatchesMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(highlightMatchesChanged(bool))); + connect(m_highlightMatchesMenuEntry, &QAction::toggled, this, &SearchBar::highlightMatchesChanged); } SearchBar::~SearchBar() { } -QString SearchBar::searchText() +QString SearchBar::searchText() const { return widget.searchTextEdit->text(); } -bool SearchBar::useRegularExpression() +bool SearchBar::useRegularExpression() const { return m_useRegularExpressionMenuEntry->isChecked(); } -bool SearchBar::matchCase() +bool SearchBar::matchCase() const { return m_matchCaseMenuEntry->isChecked(); } -bool SearchBar::highlightAllMatches() +bool SearchBar::highlightAllMatches() const { return m_highlightMatchesMenuEntry->isChecked(); } @@ -107,11 +107,11 @@ void SearchBar::keyReleaseEvent(QKeyEvent* keyEvent) { if (keyEvent->modifiers() == Qt::ShiftModifier) { - Q_EMIT findPrevious(); + emit findPrevious(); } else { - Q_EMIT findNext(); + emit findNext(); } } else if (keyEvent->key() == Qt::Key_Escape) diff --git a/lib/SearchBar.h b/lib/SearchBar.h index 1200884f..67c5e4d6 100644 --- a/lib/SearchBar.h +++ b/lib/SearchBar.h @@ -30,12 +30,10 @@ class SearchBar : public QWidget { SearchBar(QWidget* parent = nullptr); ~SearchBar() override; virtual void show(); - QString searchText(); - bool useRegularExpression(); - bool matchCase(); - bool highlightAllMatches(); - -public slots: + QString searchText() const; + bool useRegularExpression() const; + bool matchCase() const; + bool highlightAllMatches() const; void noMatchFound(); void hide(); @@ -48,14 +46,13 @@ public slots: protected: void keyReleaseEvent(QKeyEvent* keyEvent) override; -private slots: +private: void clearBackgroundColor(); -private: Ui::SearchBar widget; - QAction *m_matchCaseMenuEntry; - QAction *m_useRegularExpressionMenuEntry; - QAction *m_highlightMatchesMenuEntry; + QAction *m_matchCaseMenuEntry = nullptr; + QAction *m_useRegularExpressionMenuEntry = nullptr; + QAction *m_highlightMatchesMenuEntry = nullptr; }; #endif /* _SEARCHBAR_H */ diff --git a/lib/Session.cpp b/lib/Session.cpp index 4891e4ee..d18e7d3a 100644 --- a/lib/Session.cpp +++ b/lib/Session.cpp @@ -49,28 +49,10 @@ using namespace Konsole; int Session::lastSessionId = 0; Session::Session(QObject* parent) : - QObject(parent), - _shellProcess(nullptr) - , _emulation(nullptr) - , _monitorActivity(false) - , _monitorSilence(false) - , _notifiedActivity(false) - , _autoClose(true) - , _wantedClose(false) - , _silenceSeconds(10) - , _isTitleChanged(false) - , _addToUtmp(false) // disabled by default because of a bug encountered on certain systems - // which caused Konsole to hang when closing a tab and then opening a new - // one. A 'QProcess destroyed while still running' warning was being - // printed to the terminal. Likely a problem in KPty::logout() - // or KPty::login() which uses a QProcess to start /usr/bin/utempter - , _flowControl(true) - , _fullScripting(false) - , _sessionId(0) -// , _zmodemBusy(false) -// , _zmodemProc(0) -// , _zmodemProgress(0) - , _hasDarkBackground(false) + QObject(parent) + , _shellProcess (new Pty()) + , _emulation (new Vt102Emulation()) + , _monitorTimer (new QTimer(this)) { //prepare DBus communication // new SessionAdaptor(this); @@ -78,47 +60,35 @@ Session::Session(QObject* parent) : // QDBusConnection::sessionBus().registerObject(QLatin1String("/Sessions/")+QString::number(_sessionId), this); //create teletype for I/O with shell process - _shellProcess = new Pty(); ptySlaveFd = _shellProcess->pty()->slaveFd(); - //create emulation backend - _emulation = new Vt102Emulation(); - - connect( _emulation, SIGNAL( titleChanged( int, const QString & ) ), - this, SLOT( setUserTitle( int, const QString & ) ) ); - connect( _emulation, SIGNAL( stateSet(int) ), - this, SLOT( activityStateSet(int) ) ); + connect( _emulation, &Emulation::titleChanged, this, &Session::setUserTitle); + connect( _emulation, &Emulation::stateSet, this, &Session::activityStateSet); // connect( _emulation, SIGNAL( zmodemDetected() ), this , // SLOT( fireZModemDetected() ) ); - connect( _emulation, SIGNAL( changeTabTextColorRequest( int ) ), - this, SIGNAL( changeTabTextColorRequest( int ) ) ); - connect( _emulation, SIGNAL(profileChangeCommandReceived(const QString &)), - this, SIGNAL( profileChangeCommandReceived(const QString &)) ); - - connect(_emulation, SIGNAL(imageResizeRequest(QSize)), - this, SLOT(onEmulationSizeChange(QSize))); - connect(_emulation, SIGNAL(imageSizeChanged(int, int)), - this, SLOT(onViewSizeChange(int, int))); - connect(_emulation, &Vt102Emulation::cursorChanged, + connect( _emulation, &Emulation::changeTabTextColorRequest, this, &Session::changeTabTextColorRequest); + connect( _emulation, &Emulation::profileChangeCommandReceived, this, &Session::profileChangeCommandReceived); + + connect(_emulation, &Emulation::imageResizeRequest, this, &Session::onEmulationSizeChange); + connect(_emulation, &Emulation::imageSizeChanged, this, &Session::onViewSizeChange); + connect(_emulation, &Emulation::cursorChanged, this, &Session::cursorChanged); //connect teletype to emulation backend _shellProcess->setUtf8Mode(_emulation->utf8()); - connect( _shellProcess,SIGNAL(receivedData(const char *,int)),this, - SLOT(onReceiveBlock(const char *,int)) ); - connect( _emulation,SIGNAL(sendData(const char *,int)),_shellProcess, - SLOT(sendData(const char *,int)) ); - connect( _emulation,SIGNAL(lockPtyRequest(bool)),_shellProcess,SLOT(lockPty(bool)) ); - connect( _emulation,SIGNAL(useUtf8Request(bool)),_shellProcess,SLOT(setUtf8Mode(bool)) ); + connect( _shellProcess, &Pty::receivedData, this, &Session::onReceiveBlock); + connect( _emulation, &Emulation::sendData, _shellProcess, &Pty::sendData); + connect( _emulation,&Emulation::lockPtyRequest, _shellProcess, &Pty::lockPty); + connect( _emulation,&Emulation::useUtf8Request, _shellProcess, &Pty::setUtf8Mode); + // Not moved to the new connect way for now to avoid to use qoverload connect( _shellProcess,SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(done(int)) ); // not in kprocess anymore connect( _shellProcess,SIGNAL(done(int)), this, SLOT(done(int)) ); //setup timer for monitoring session activity - _monitorTimer = new QTimer(this); _monitorTimer->setSingleShot(true); - connect(_monitorTimer, SIGNAL(timeout()), this, SLOT(monitorTimerDone())); + connect(_monitorTimer, &QTimer::timeout, this, &Session::monitorTimerDone); } WId Session::windowId() const @@ -174,22 +144,18 @@ void Session::addView(TerminalDisplay * widget) if ( _emulation != nullptr ) { // connect emulation - view signals and slots - connect( widget , &TerminalDisplay::keyPressedSignal, _emulation , - &Emulation::sendKeyEvent); - connect( widget , SIGNAL(mouseSignal(int,int,int,int)) , _emulation , - SLOT(sendMouseEvent(int,int,int,int)) ); + connect(widget, &TerminalDisplay::keyPressedSignal, _emulation, &Emulation::sendKeyEvent); + connect(widget, &TerminalDisplay::mouseSignal, _emulation, &Emulation::sendMouseEvent); connect( widget , SIGNAL(sendStringToEmu(const char *)) , _emulation , - SLOT(sendString(const char *)) ); + SLOT(sendString(const char *)) ); // allow emulation to notify view when the foreground process // indicates whether or not it is interested in mouse signals - connect( _emulation , SIGNAL(programUsesMouseChanged(bool)) , widget , - SLOT(setUsesMouse(bool)) ); + connect(_emulation, &Emulation::programUsesMouseChanged, widget, &TerminalDisplay::setUsesMouse); widget->setUsesMouse( _emulation->programUsesMouse() ); - connect( _emulation , SIGNAL(programBracketedPasteModeChanged(bool)) , - widget , SLOT(setBracketedPasteMode(bool)) ); + connect(_emulation , &Emulation::programBracketedPasteModeChanged, widget , &TerminalDisplay::setBracketedPasteMode); widget->setBracketedPasteMode(_emulation->programBracketedPasteMode()); @@ -197,13 +163,9 @@ void Session::addView(TerminalDisplay * widget) } //connect view signals and slots - QObject::connect( widget ,SIGNAL(changedContentSizeSignal(int,int)),this, - SLOT(onViewSizeChange(int,int))); - - QObject::connect( widget ,SIGNAL(destroyed(QObject *)) , this , - SLOT(viewDestroyed(QObject *)) ); -//slot for close - QObject::connect(this, SIGNAL(finished()), widget, SLOT(close())); + connect(widget, &TerminalDisplay::changedContentSizeSignal, this, &Session::onViewSizeChange); + connect(widget, &TerminalDisplay::destroyed, this , &Session::viewDestroyed); + connect(this, &Session::finished, widget, &TerminalDisplay::close); } @@ -539,15 +501,15 @@ void Session::refresh() bool Session::sendSignal(int signal) { - int result = ::kill(static_cast(_shellProcess->processId()),signal); + const auto result = ::kill(static_cast(_shellProcess->processId()),signal); - if ( result == 0 ) - { - _shellProcess->waitForFinished(); - return true; - } - else - return false; + if ( result == 0 ) + { + _shellProcess->waitForFinished(); + return true; + } + + return false; } void Session::close() @@ -556,7 +518,7 @@ void Session::close() _wantedClose = true; if (!_shellProcess->isRunning() || !sendSignal(SIGHUP)) { // Forced close. - QTimer::singleShot(1, this, SIGNAL(finished())); + QTimer::singleShot(1, this, &Session::finished); } } @@ -1041,8 +1003,7 @@ void SessionGroup::connectPair(Session * master , Session * other) const if ( _masterMode & CopyInputToAll ) { qDebug() << "Connection session " << master->nameTitle() << "to" << other->nameTitle(); - connect( master->emulation() , SIGNAL(sendData(const char *,int)) , other->emulation() , - SLOT(sendString(const char *,int)) ); + connect(master->emulation(), &Emulation::sendData, other->emulation(), &Emulation::sendString); } } void SessionGroup::disconnectPair(Session * master , Session * other) const @@ -1052,8 +1013,7 @@ void SessionGroup::disconnectPair(Session * master , Session * other) const if ( _masterMode & CopyInputToAll ) { qDebug() << "Disconnecting session " << master->nameTitle() << "from" << other->nameTitle(); - disconnect( master->emulation() , SIGNAL(sendData(const char *,int)) , other->emulation() , - SLOT(sendString(const char *,int)) ); + disconnect(master->emulation(), &Emulation::sendData, other->emulation(), &Emulation::sendString); } } diff --git a/lib/Session.h b/lib/Session.h index b2a4d6ad..b559381f 100644 --- a/lib/Session.h +++ b/lib/Session.h @@ -491,7 +491,11 @@ public slots: private slots: void done(int); -// void fireZModemDetected(); +private: + + void updateTerminalSize(); + WId windowId() const; + // void fireZModemDetected(); void onReceiveBlock( const char * buffer, int len ); void monitorTimerDone(); @@ -504,32 +508,28 @@ private slots: //automatically detach views from sessions when view is destroyed void viewDestroyed(QObject * view); -// void zmodemReadStatus(); -// void zmodemReadAndSendBlock(); -// void zmodemRcvBlock(const char *data, int len); -// void zmodemFinished(); - -private: + // void zmodemReadStatus(); + // void zmodemReadAndSendBlock(); + // void zmodemRcvBlock(const char *data, int len); + // void zmodemFinished(); - void updateTerminalSize(); - WId windowId() const; int _uniqueIdentifier; - Pty *_shellProcess; - Emulation * _emulation; + Pty *_shellProcess = nullptr; + Emulation * _emulation = nullptr; QList _views; - bool _monitorActivity; - bool _monitorSilence; - bool _notifiedActivity; + bool _monitorActivity = false; + bool _monitorSilence = false; + bool _notifiedActivity = false; bool _masterMode; - bool _autoClose; - bool _wantedClose; + bool _autoClose = true; + bool _wantedClose = true; QTimer * _monitorTimer; - int _silenceSeconds; + int _silenceSeconds = 10; QString _nameTitle; QString _displayTitle; @@ -540,8 +540,15 @@ private slots: QString _iconName; QString _iconText; // as set by: echo -en '\033]1;IconText\007 - bool _isTitleChanged; ///< flag if the title/icon was changed by user - bool _addToUtmp; + bool _isTitleChanged = false; ///< flag if the title/icon was changed by user + + /* Disabled by default because of a bug encountered on certain systems + * which caused Konsole to hang when closing a tab and then opening a new + * one. A 'QProcess destroyed while still running' warning was being + * printed to the terminal. Likely a problem in KPty::logout() + * or KPty::login() which uses a QProcess to start /usr/bin/utempter + */ + bool _addToUtmp = false; bool _flowControl; bool _fullScripting; diff --git a/lib/TerminalDisplay.cpp b/lib/TerminalDisplay.cpp index a36d3914..993ae506 100644 --- a/lib/TerminalDisplay.cpp +++ b/lib/TerminalDisplay.cpp @@ -141,11 +141,11 @@ void TerminalDisplay::setScreenWindow(ScreenWindow* window) // TODO: Determine if this is an issue. //#warning "The order here is not specified - does it matter whether updateImage or updateLineProperties comes first?" - connect( _screenWindow , SIGNAL(outputChanged()) , this , SLOT(updateLineProperties()) ); - connect( _screenWindow , SIGNAL(outputChanged()) , this , SLOT(updateImage()) ); - connect( _screenWindow , SIGNAL(outputChanged()) , this , SLOT(updateFilters()) ); - connect( _screenWindow , SIGNAL(scrolled(int)) , this , SLOT(updateFilters()) ); - connect( _screenWindow , &ScreenWindow::scrollToEnd , this , &TerminalDisplay::scrollToEnd ); + connect(_screenWindow, &ScreenWindow::outputChanged, this, &TerminalDisplay::updateLineProperties); + connect(_screenWindow, &ScreenWindow::outputChanged, this, &TerminalDisplay::updateImage); + connect(_screenWindow, &ScreenWindow::outputChanged, this, &TerminalDisplay::updateFilters); + connect(_screenWindow, &ScreenWindow::scrolled, this, &TerminalDisplay::updateFilters); + connect(_screenWindow, &ScreenWindow::scrollToEnd, this, &TerminalDisplay::scrollToEnd); window->setWindowLines(_lines); } } @@ -258,15 +258,15 @@ void TerminalDisplay::fontChange(const QFont&) void TerminalDisplay::calDrawTextAdditionHeight(QPainter& painter) { QRect test_rect, feedback_rect; - test_rect.setRect(1, 1, _fontWidth * 4, _fontHeight); + test_rect.setRect(1, 1, _fontWidth * 4, _fontHeight); painter.drawText(test_rect, Qt::AlignBottom, LTR_OVERRIDE_CHAR + QLatin1String("Mq"), &feedback_rect); - //qDebug() << "test_rect:" << test_rect << "feeback_rect:" << feedback_rect; + //qDebug() << "test_rect:" << test_rect << "feeback_rect:" << feedback_rect; - _drawTextAdditionHeight = (feedback_rect.height() - _fontHeight) / 2; - if(_drawTextAdditionHeight < 0) { - _drawTextAdditionHeight = 0; - } + _drawTextAdditionHeight = (feedback_rect.height() - _fontHeight) / 2; + if(_drawTextAdditionHeight < 0) { + _drawTextAdditionHeight = 0; + } _drawTextTestFlag = false; } @@ -314,63 +314,12 @@ void TerminalDisplay::setFont(const QFont &) TerminalDisplay::TerminalDisplay(QWidget *parent) :QWidget(parent) -,_screenWindow(nullptr) -,_allowBell(true) -,_gridLayout(nullptr) -,_fontHeight(1) -,_fontWidth(1) -,_fontAscent(1) -,_boldIntense(true) -,_lines(1) -,_columns(1) -,_usedLines(1) -,_usedColumns(1) -,_contentHeight(1) -,_contentWidth(1) -,_image(nullptr) -,_randomSeed(0) -,_resizing(false) -,_terminalSizeHint(false) -,_terminalSizeStartup(true) -,_bidiEnabled(false) -,_mouseMarks(false) -,_disabledBracketedPasteMode(false) -,_actSel(0) -,_wordSelectionMode(false) -,_lineSelectionMode(false) -,_preserveLineBreaks(false) -,_columnSelectionMode(false) -,_scrollbarLocation(QTermWidget::NoScrollBar) -,_wordCharacters(QLatin1String(":@-./_~")) -,_bellMode(SystemBeepBell) -,_blinking(false) -,_hasBlinker(false) -,_cursorBlinking(false) -,_hasBlinkingCursor(false) -,_allowBlinkingText(true) -,_ctrlDrag(false) -,_tripleClickMode(SelectWholeLine) -,_isFixedSize(false) -,_possibleTripleClick(false) -,_resizeWidget(nullptr) -,_resizeTimer(nullptr) -,_flowControlWarningEnabled(false) -,_outputSuspendedLabel(nullptr) -,_lineSpacing(0) -,_colorsInverted(false) -,_opacity(static_cast(1)) -,_backgroundMode(None) +, _gridLayout (new QGridLayout()) +, _scrollBar(new QScrollBar(this)) +, _blinkTimer(new QTimer(this)) +, _blinkCursorTimer(new QTimer(this)) ,_filterChain(new TerminalImageFilterChain()) -,_cursorShape(Emulation::KeyboardCursorShape::BlockCursor) -,mMotionAfterPasting(NoMoveScreenWindow) -,_leftBaseMargin(1) -,_topBaseMargin(1) -,_drawLineChars(true) -{ - // variables for draw text - _drawTextAdditionHeight = 0; - _drawTextTestFlag = false; - +{ // terminal applications are not designed with Right-To-Left in mind, // so the layout is forced to Left-To-Right setLayoutDirection(Qt::LeftToRight); @@ -383,24 +332,20 @@ TerminalDisplay::TerminalDisplay(QWidget *parent) // create scroll bar for scrolling output up and down // set the scroll bar's slider to occupy the whole area of the scroll bar initially - _scrollBar = new QScrollBar(this); // since the contrast with the terminal background may not be enough, // the scrollbar should be auto-filled if not transient if (!_scrollBar->style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, _scrollBar)) _scrollBar->setAutoFillBackground(true); setScroll(0,0); _scrollBar->setCursor( Qt::ArrowCursor ); - connect(_scrollBar, SIGNAL(valueChanged(int)), this, - SLOT(scrollBarPositionChanged(int))); + connect(_scrollBar, &QScrollBar::valueChanged, this, &TerminalDisplay::scrollBarPositionChanged); // qtermwidget: we have to hide it here due the _scrollbarLocation==NoScrollBar // check in TerminalDisplay::setScrollBarPosition(ScrollBarPosition position) _scrollBar->hide(); // setup timers for blinking cursor and text - _blinkTimer = new QTimer(this); - connect(_blinkTimer, SIGNAL(timeout()), this, SLOT(blinkEvent())); - _blinkCursorTimer = new QTimer(this); - connect(_blinkCursorTimer, SIGNAL(timeout()), this, SLOT(blinkCursorEvent())); + connect(_blinkTimer, &QTimer::timeout, this, &TerminalDisplay::blinkEvent); + connect(_blinkCursorTimer, &QTimer::timeout, this, &TerminalDisplay::blinkCursorEvent); // KCursor::setAutoHideCursor( this, true ); @@ -422,7 +367,6 @@ TerminalDisplay::TerminalDisplay(QWidget *parent) // that TerminalDisplay will handle repainting its entire area. setAttribute(Qt::WA_OpaquePaintEvent); - _gridLayout = new QGridLayout(this); _gridLayout->setContentsMargins(0, 0, 0, 0); setLayout( _gridLayout ); diff --git a/lib/TerminalDisplay.h b/lib/TerminalDisplay.h index af9cd176..3249b8fa 100644 --- a/lib/TerminalDisplay.h +++ b/lib/TerminalDisplay.h @@ -569,9 +569,9 @@ public slots: void sendStringToEmu(const char*); // qtermwidget signals - void copyAvailable(bool); - void termGetFocus(); - void termLostFocus(); + void copyAvailable(bool); + void termGetFocus(); + void termLostFocus(); void notifyBell(const QString&); void usesMouseChanged(); @@ -725,118 +725,118 @@ private slots: // is currently showing. QPointer _screenWindow; - bool _allowBell; + bool _allowBell = true; - QGridLayout* _gridLayout; + QGridLayout* _gridLayout = nullptr; bool _fixedFont; // has fixed pitch - int _fontHeight; // height - int _fontWidth; // width - int _fontAscent; // ascend - bool _boldIntense; // Whether intense colors should be rendered with bold font - int _drawTextAdditionHeight; // additional height to prevent font trancation - bool _drawTextTestFlag; // indicate it is a testing or not + int _fontHeight = 1; // height + int _fontWidth = 1; // width + int _fontAscent = 1; // ascend + bool _boldIntense = true; // Whether intense colors should be rendered with bold font + int _drawTextAdditionHeight = 0; // additional height to prevent font trancation + bool _drawTextTestFlag = false; // indicate it is a testing or not int _leftMargin; // offset int _topMargin; // offset - int _lines; // the number of lines that can be displayed in the widget - int _columns; // the number of columns that can be displayed in the widget + int _lines = 1; // the number of lines that can be displayed in the widget + int _columns = 1; // the number of columns that can be displayed in the widget - int _usedLines; // the number of lines that are actually being used, this will be less + int _usedLines = 1; // the number of lines that are actually being used, this will be less // than 'lines' if the character image provided with setImage() is smaller // than the maximum image size which can be displayed - int _usedColumns; // the number of columns that are actually being used, this will be less + int _usedColumns = 1; // the number of columns that are actually being used, this will be less // than 'columns' if the character image provided with setImage() is smaller // than the maximum image size which can be displayed - int _contentHeight; - int _contentWidth; - Character* _image; // [lines][columns] + int _contentHeight = 1; + int _contentWidth = 1; + Character* _image = nullptr; // [lines][columns] // only the area [usedLines][usedColumns] in the image contains valid data int _imageSize; QVector _lineProperties; ColorEntry _colorTable[TABLE_COLORS]; - uint _randomSeed; + uint _randomSeed = 0U; - bool _resizing; - bool _terminalSizeHint; - bool _terminalSizeStartup; - bool _bidiEnabled; - bool _mouseMarks; + bool _resizing = false; + bool _terminalSizeHint = false; + bool _terminalSizeStartup = true; + bool _bidiEnabled = false; + bool _mouseMarks = false; bool _bracketedPasteMode; - bool _disabledBracketedPasteMode; + bool _disabledBracketedPasteMode = false; QPoint _iPntSel; // initial selection point QPoint _pntSel; // current selection point QPoint _tripleSelBegin; // help avoid flicker - int _actSel; // selection state - bool _wordSelectionMode; - bool _lineSelectionMode; - bool _preserveLineBreaks; - bool _columnSelectionMode; + int _actSel = 0; // selection state + bool _wordSelectionMode = false; + bool _lineSelectionMode = false; + bool _preserveLineBreaks = false; + bool _columnSelectionMode = false; QClipboard* _clipboard; QScrollBar* _scrollBar; - QTermWidget::ScrollBarPosition _scrollbarLocation; - QString _wordCharacters; - int _bellMode; - - bool _blinking; // hide text in paintEvent - bool _hasBlinker; // has characters to blink - bool _cursorBlinking; // hide cursor in paintEvent - bool _hasBlinkingCursor; // has blinking cursor enabled - bool _allowBlinkingText; // allow text to blink - bool _ctrlDrag; // require Ctrl key for drag - TripleClickMode _tripleClickMode; - bool _isFixedSize; //Columns / lines are locked. - QTimer* _blinkTimer; // active when hasBlinker - QTimer* _blinkCursorTimer; // active when hasBlinkingCursor + QTermWidget::ScrollBarPosition _scrollbarLocation = QTermWidget::ScrollBarPosition::NoScrollBar; + QString _wordCharacters = QLatin1String(":@-./_~"); + int _bellMode = SystemBeepBell; + + bool _blinking = false; // hide text in paintEvent + bool _hasBlinker = false; // has characters to blink + bool _cursorBlinking = false; // hide cursor in paintEvent + bool _hasBlinkingCursor = false; // has blinking cursor enabled + bool _allowBlinkingText = true; // allow text to blink + bool _ctrlDrag = false; // require Ctrl key for drag + TripleClickMode _tripleClickMode = SelectWholeLine; + bool _isFixedSize = false; //Columns / lines are locked. + QTimer* _blinkTimer = nullptr; // active when hasBlinker + QTimer* _blinkCursorTimer = nullptr; // active when hasBlinkingCursor //QMenu* _drop; QString _dropText; int _dndFileCount; - bool _possibleTripleClick; // is set in mouseDoubleClickEvent and deleted + bool _possibleTripleClick = false; // is set in mouseDoubleClickEvent and deleted // after QApplication::doubleClickInterval() delay - QLabel* _resizeWidget; - QTimer* _resizeTimer; + QLabel* _resizeWidget = nullptr; + QTimer* _resizeTimer = nullptr; - bool _flowControlWarningEnabled; + bool _flowControlWarningEnabled = false; //widgets related to the warning message that appears when the user presses Ctrl+S to suspend //terminal output - informing them what has happened and how to resume output - QLabel* _outputSuspendedLabel; + QLabel* _outputSuspendedLabel = nullptr; - uint _lineSpacing; + uint _lineSpacing = 0U; - bool _colorsInverted; // true during visual bell + bool _colorsInverted = false; // true during visual bell QSize _size; - qreal _opacity; + qreal _opacity = 1; QPixmap _backgroundImage; - BackgroundMode _backgroundMode; + BackgroundMode _backgroundMode = None; // list of filters currently applied to the display. used for links and // search highlight - TerminalImageFilterChain* _filterChain; + TerminalImageFilterChain* _filterChain = nullptr; QRegion _mouseOverHotspotArea; - QTermWidget::KeyboardCursorShape _cursorShape; + QTermWidget::KeyboardCursorShape _cursorShape = Emulation::KeyboardCursorShape::BlockCursor; // custom cursor color. if this is invalid then the foreground // color of the character under the cursor is used QColor _cursorColor; - MotionAfterPasting mMotionAfterPasting; + MotionAfterPasting mMotionAfterPasting = NoMoveScreenWindow; bool _confirmMultilinePaste; bool _trimPastedTrailingNewlines; @@ -852,10 +852,10 @@ private slots: //the delay in milliseconds between redrawing blinking text static const int TEXT_BLINK_DELAY = 500; - int _leftBaseMargin; - int _topBaseMargin; + int _leftBaseMargin = 1; + int _topBaseMargin = 1; - bool _drawLineChars; + bool _drawLineChars = true; public: static void setTransparencyEnabled(bool enable) diff --git a/lib/Vt102Emulation.cpp b/lib/Vt102Emulation.cpp index 3105cca4..439dff73 100644 --- a/lib/Vt102Emulation.cpp +++ b/lib/Vt102Emulation.cpp @@ -61,20 +61,15 @@ using namespace Konsole; Vt102Emulation::Vt102Emulation() : Emulation(), - prevCC(0), - _titleUpdateTimer(new QTimer(this)), - _reportFocusEvents(false) + _titleUpdateTimer(new QTimer(this)) { _titleUpdateTimer->setSingleShot(true); - QObject::connect(_titleUpdateTimer , SIGNAL(timeout()) , this , SLOT(updateTitle())); + connect(_titleUpdateTimer, &QTimer::timeout, this, &Vt102Emulation::updateTitle); initTokenizer(); - reset(); + Vt102Emulation::reset(); } -Vt102Emulation::~Vt102Emulation() -{} - void Vt102Emulation::clearEntireScreen() { _currentScreen->clearEntireScreen(); diff --git a/lib/Vt102Emulation.h b/lib/Vt102Emulation.h index 214e50cc..7758408e 100644 --- a/lib/Vt102Emulation.h +++ b/lib/Vt102Emulation.h @@ -82,7 +82,7 @@ Q_OBJECT public: /** Constructs a new emulation */ Vt102Emulation(); - ~Vt102Emulation() override; + ~Vt102Emulation() override = default; // reimplemented from Emulation void clearEntireScreen() override; @@ -143,7 +143,7 @@ private slots: int argv[MAXARGS]; int argc; void initTokenizer(); - int prevCC; + int prevCC = 0; // Set of flags for each of the ASCII characters which indicates // what category they fall into (printable character, control, digit etc.) @@ -191,9 +191,9 @@ private slots: //these calls occur when certain escape sequences are seen in the //output from the terminal QHash _pendingTitleUpdates; - QTimer* _titleUpdateTimer; + QTimer* _titleUpdateTimer = nullptr; - bool _reportFocusEvents; + bool _reportFocusEvents = false; }; } diff --git a/lib/kptydevice.cpp b/lib/kptydevice.cpp index 9af1545d..7f85f7d5 100644 --- a/lib/kptydevice.cpp +++ b/lib/kptydevice.cpp @@ -294,7 +294,7 @@ KPtyDevice::KPtyDevice(QObject *parent) : KPtyDevice::~KPtyDevice() { - close(); + KPtyDevice::close(); } bool KPtyDevice::open(OpenMode mode) diff --git a/lib/qtermwidget.cpp b/lib/qtermwidget.cpp index aea5157d..6bcaa70a 100644 --- a/lib/qtermwidget.cpp +++ b/lib/qtermwidget.cpp @@ -63,8 +63,8 @@ class TermWidgetImpl { TermWidgetImpl::TermWidgetImpl(QWidget* parent) { - this->m_session = createSession(parent); - this->m_terminalDisplay = createTerminalDisplay(this->m_session, parent); + m_session = createSession(parent); + m_terminalDisplay = createTerminalDisplay(m_session, parent); } @@ -104,14 +104,12 @@ Session *TermWidgetImpl::createSession(QWidget* parent) TerminalDisplay *TermWidgetImpl::createTerminalDisplay(Session *session, QWidget* parent) { -// TerminalDisplay* display = new TerminalDisplay(this); TerminalDisplay* display = new TerminalDisplay(parent); display->setBellMode(TerminalDisplay::NotifyBell); display->setTerminalSizeHint(true); display->setTripleClickMode(TerminalDisplay::SelectWholeLine); display->setTerminalSizeStartup(true); - display->setRandomSeed(session->sessionId() * 31); return display; @@ -125,9 +123,8 @@ QTermWidget::QTermWidget(int startnow, QWidget *parent) } QTermWidget::QTermWidget(QWidget *parent) - : QWidget(parent) + : QTermWidget(1, parent) { - init(1); } void QTermWidget::selectionChanged(bool textSelected) @@ -171,11 +168,11 @@ void QTermWidget::search(bool forwards, bool next) regExp.setPatternSyntax(m_searchBar->useRegularExpression() ? QRegExp::RegExp : QRegExp::FixedString); regExp.setCaseSensitivity(m_searchBar->matchCase() ? Qt::CaseSensitive : Qt::CaseInsensitive); - HistorySearch *historySearch = + const auto historySearch = new HistorySearch(m_impl->m_session->emulation(), regExp, forwards, startColumn, startLine, this); - connect(historySearch, SIGNAL(matchFound(int, int, int, int)), this, SLOT(matchFound(int, int, int, int))); - connect(historySearch, SIGNAL(noMatchFound()), this, SLOT(noMatchFound())); - connect(historySearch, SIGNAL(noMatchFound()), m_searchBar, SLOT(noMatchFound())); + connect(historySearch, &HistorySearch::matchFound, this, &QTermWidget::matchFound); + connect(historySearch, &HistorySearch::noMatchFound, this, &QTermWidget::noMatchFound); + connect(historySearch, &HistorySearch::noMatchFound, m_searchBar, &SearchBar::noMatchFound); historySearch->search(); } @@ -254,8 +251,7 @@ void QTermWidget::startTerminalTeletype() m_impl->m_session->runEmptyPTY(); // redirect data from TTY to external recipient - connect( m_impl->m_session->emulation(), SIGNAL(sendData(const char *,int)), - this, SIGNAL(sendData(const char *,int)) ); + connect(m_impl->m_session->emulation(), &Emulation::sendData, this, &QTermWidget::sendData); } void QTermWidget::init(int startnow) @@ -288,11 +284,11 @@ void QTermWidget::init(int startnow) m_impl = new TermWidgetImpl(this); m_layout->addWidget(m_impl->m_terminalDisplay); - connect(m_impl->m_session, SIGNAL(bellRequest(QString)), m_impl->m_terminalDisplay, SLOT(bell(QString))); - connect(m_impl->m_terminalDisplay, SIGNAL(notifyBell(QString)), this, SIGNAL(bell(QString))); + connect(m_impl->m_session, &Session::bellRequest, m_impl->m_terminalDisplay, &TerminalDisplay::bell); + connect(m_impl->m_terminalDisplay, &TerminalDisplay::notifyBell, this, &QTermWidget::bell); - connect(m_impl->m_session, SIGNAL(activity()), this, SIGNAL(activity())); - connect(m_impl->m_session, SIGNAL(silence()), this, SIGNAL(silence())); + connect(m_impl->m_session, &Session::activity, this, &QTermWidget::activity); + connect(m_impl->m_session, &Session::silence, this, &QTermWidget::silence); connect(m_impl->m_session, &Session::profileChangeCommandReceived, this, &QTermWidget::profileChanged); connect(m_impl->m_session, &Session::receivedData, this, &QTermWidget::receivedData); @@ -303,9 +299,9 @@ void QTermWidget::init(int startnow) m_searchBar = new SearchBar(this); m_searchBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum); - connect(m_searchBar, SIGNAL(searchCriteriaChanged()), this, SLOT(find())); - connect(m_searchBar, SIGNAL(findNext()), this, SLOT(findNext())); - connect(m_searchBar, SIGNAL(findPrevious()), this, SLOT(findPrevious())); + connect(m_searchBar, &SearchBar::searchCriteriaChanged, this, &QTermWidget::find); + connect(m_searchBar, &SearchBar::findNext, this, &QTermWidget::findNext); + connect(m_searchBar, &SearchBar::findPrevious, this, &QTermWidget::findPrevious); m_layout->addWidget(m_searchBar); m_searchBar->hide(); @@ -313,19 +309,17 @@ void QTermWidget::init(int startnow) m_impl->m_session->run(); } - this->setFocus( Qt::OtherFocusReason ); - this->setFocusPolicy( Qt::WheelFocus ); + setFocus( Qt::OtherFocusReason ); + setFocusPolicy( Qt::WheelFocus ); m_impl->m_terminalDisplay->resize(this->size()); - this->setFocusProxy(m_impl->m_terminalDisplay); - connect(m_impl->m_terminalDisplay, SIGNAL(copyAvailable(bool)), - this, SLOT(selectionChanged(bool))); - connect(m_impl->m_terminalDisplay, SIGNAL(termGetFocus()), - this, SIGNAL(termGetFocus())); - connect(m_impl->m_terminalDisplay, SIGNAL(termLostFocus()), - this, SIGNAL(termLostFocus())); + setFocusProxy(m_impl->m_terminalDisplay); + connect(m_impl->m_terminalDisplay, &TerminalDisplay::copyAvailable, + this, &QTermWidget::selectionChanged); + connect(m_impl->m_terminalDisplay, &TerminalDisplay::termGetFocus, this, &QTermWidget::termGetFocus); + connect(m_impl->m_terminalDisplay, &TerminalDisplay::termLostFocus, this, &QTermWidget::termLostFocus); connect(m_impl->m_terminalDisplay, &TerminalDisplay::keyPressedSignal, this, - [this] (QKeyEvent* e, bool) { Q_EMIT termKeyPressed(e); }); + [this] (QKeyEvent* e, bool) { emit termKeyPressed(e); }); // m_impl->m_terminalDisplay->setSize(80, 40); QFont font = QApplication::font(); @@ -340,10 +334,10 @@ void QTermWidget::init(int startnow) m_impl->m_session->addView(m_impl->m_terminalDisplay); - connect(m_impl->m_session, SIGNAL(resizeRequest(QSize)), this, SLOT(setSize(QSize))); - connect(m_impl->m_session, SIGNAL(finished()), this, SLOT(sessionFinished())); + connect(m_impl->m_session, &Session::resizeRequest, this, &QTermWidget::setSize); + connect(m_impl->m_session, &Session::finished, this, &QTermWidget::sessionFinished); connect(m_impl->m_session, &Session::titleChanged, this, &QTermWidget::titleChanged); - connect(m_impl->m_session, &Session::cursorChanged, this, &QTermWidget::cursorChanged); + connect(m_impl->m_session, &Session::cursorChanged, this, &QTermWidget::onCursorChanged); } @@ -772,7 +766,7 @@ void QTermWidget::setAutoClose(bool enabled) m_impl->m_session->setAutoClose(enabled); } -void QTermWidget::cursorChanged(Konsole::Emulation::KeyboardCursorShape cursorShape, bool blinkingCursorEnabled) +void QTermWidget::onCursorChanged(Konsole::Emulation::KeyboardCursorShape cursorShape, bool blinkingCursorEnabled) { // TODO: A switch to enable/disable DECSCUSR? setKeyboardCursorShape(cursorShape); diff --git a/lib/qtermwidget.h b/lib/qtermwidget.h index dd9be66f..5b82d03f 100644 --- a/lib/qtermwidget.h +++ b/lib/qtermwidget.h @@ -314,31 +314,29 @@ public slots: void saveHistory(QIODevice *device); protected: void resizeEvent(QResizeEvent *) override; - -protected slots: void sessionFinished(); void selectionChanged(bool textSelected); -private slots: +private: + void search(bool forwards, bool next); + void setZoom(int step); + void init(int startnow); void find(); void findNext(); void findPrevious(); void matchFound(int startColumn, int startLine, int endColumn, int endLine); void noMatchFound(); + /** * Emulation::cursorChanged() signal propogates to here and QTermWidget * sends the specified cursor states to the terminal display */ - void cursorChanged(Konsole::Emulation::KeyboardCursorShape cursorShape, bool blinkingCursorEnabled); + void onCursorChanged(Konsole::Emulation::KeyboardCursorShape cursorShape, bool blinkingCursorEnabled); -private: - void search(bool forwards, bool next); - void setZoom(int step); - void init(int startnow); - TermWidgetImpl * m_impl; - SearchBar* m_searchBar; - QVBoxLayout *m_layout; - QTranslator *m_translator; + TermWidgetImpl * m_impl = nullptr; + SearchBar* m_searchBar = nullptr; + QVBoxLayout *m_layout = nullptr; + QTranslator *m_translator = nullptr; };