Commit 33b3a1a7 authored by Ahmad Samir's avatar Ahmad Samir Committed by Tomaz Canabrava
Browse files

Port away from using QObject::sender()

By passing the sender object as an arg to the signal/slot.
parent d2ca202a
......@@ -122,7 +122,13 @@ MainWindow *Application::newMainWindow()
auto window = new MainWindow();
connect(window, &Konsole::MainWindow::newWindowRequest, this, &Konsole::Application::createWindow);
connect(window, &Konsole::MainWindow::terminalsDetached, this, &Konsole::Application::detachTerminals);
connect(window,
&Konsole::MainWindow::terminalsDetached,
this,
[this, window](ViewSplitter *splitter, const QHash<TerminalDisplay *, Session *> &sessionsMap) {
detachTerminals(window, splitter, sessionsMap);
});
m_pluginManager.registerMainWindow(window);
......@@ -136,9 +142,8 @@ void Application::createWindow(const Profile::Ptr &profile, const QString &direc
window->show();
}
void Application::detachTerminals(ViewSplitter *splitter, const QHash<TerminalDisplay *, Session *> &sessionsMap)
void Application::detachTerminals(MainWindow *currentWindow, ViewSplitter *splitter, const QHash<TerminalDisplay *, Session *> &sessionsMap)
{
auto *currentWindow = qobject_cast<MainWindow *>(sender());
MainWindow *window = newMainWindow();
ViewManager *manager = window->viewManager();
......
......@@ -60,7 +60,7 @@ public:
private Q_SLOTS:
void createWindow(const QExplicitlySharedDataPointer<Profile> &profile, const QString &directory);
void detachTerminals(ViewSplitter *splitter, const QHash<TerminalDisplay *, Session *> &sessionsMap);
void detachTerminals(MainWindow *currentWindow, ViewSplitter *splitter, const QHash<TerminalDisplay *, Session *> &sessionsMap);
void toggleBackgroundInstance();
......
......@@ -507,7 +507,7 @@ Session *ViewManager::createSession(const Profile::Ptr &profile, const QString &
return session;
}
void ViewManager::sessionFinished()
void ViewManager::sessionFinished(Session *session)
{
// if this slot is called after the view manager's main widget
// has been destroyed, do nothing
......@@ -524,7 +524,6 @@ void ViewManager::sessionFinished()
}
}
auto *session = qobject_cast<Session *>(sender());
Q_ASSERT(session);
auto view = _sessionMap.key(session);
......@@ -690,9 +689,8 @@ SessionController *ViewManager::createController(Session *session, TerminalDispl
return controller;
}
void ViewManager::forgetController()
void ViewManager::forgetController(SessionController *controller)
{
auto controller = static_cast<SessionController *>(sender());
Q_ASSERT(controller->session() != nullptr && controller->view() != nullptr);
forgetTerminal(controller->view());
......
......@@ -326,7 +326,7 @@ private Q_SLOTS:
// called when a session terminates - the view manager will delete any
// views associated with the session
void sessionFinished();
void sessionFinished(Session *session);
// called when one view has been destroyed
void viewDestroyed(QWidget *view);
......@@ -388,11 +388,11 @@ private Q_SLOTS:
void controllerChanged(SessionController *controller);
/**
* Disconnect this ViewManager and MainWindow from SessionController
* sender() and its associated view/session pair such as after a
* split-view has been drag-and-dropped to a new window.
* Disconnect this ViewManager and MainWindow from @p controller
* and its associated view/session pair such as after a split-view
* has been drag-and-dropped to a new window.
*/
void forgetController();
void forgetController(SessionController *controller);
/* Detaches the tab at index tabIdx */
void detachTab(int tabIdx);
......
......@@ -858,7 +858,9 @@ void Session::close()
}
} else {
// terminal process has finished, just close the session
QTimer::singleShot(1, this, &Konsole::Session::finished);
QTimer::singleShot(1, this, [this]() {
Q_EMIT finished(this);
});
}
}
......@@ -874,7 +876,7 @@ bool Session::closeInNormalWay()
// 3). the user closes the tab explicitly
//
if (!isRunning()) {
Q_EMIT finished();
Q_EMIT finished(this);
return true;
}
......@@ -969,7 +971,7 @@ void Session::done(int exitCode, QProcess::ExitStatus exitStatus)
}
if (_closePerUserRequest) {
Q_EMIT finished();
Q_EMIT finished(this);
return;
}
......@@ -991,7 +993,7 @@ void Session::done(int exitCode, QProcess::ExitStatus exitStatus)
message = i18n("Program '%1' crashed.", _program);
terminalWarning(message);
} else {
Q_EMIT finished();
Q_EMIT finished(this);
}
}
......
......@@ -649,7 +649,7 @@ Q_SIGNALS:
/**
* Emitted when the terminal process exits.
*/
void finished();
void finished(Session *session);
/**
* Emitted when one of certain session attributes has been changed.
......
......@@ -513,7 +513,9 @@ void SessionController::updateWebSearchMenu()
action = new QAction(searchProvider, _webSearchMenu);
action->setIcon(QIcon::fromTheme(filterData.iconNameForPreferredSearchProvider(searchProvider)));
action->setData(filterData.queryForPreferredSearchProvider(searchProvider));
connect(action, &QAction::triggered, this, &Konsole::SessionController::handleWebShortcutAction);
connect(action, &QAction::triggered, this, [this, action]() {
handleWebShortcutAction(action);
});
_webSearchMenu->addAction(action);
}
......@@ -529,9 +531,8 @@ void SessionController::updateWebSearchMenu()
}
}
void SessionController::handleWebShortcutAction()
void SessionController::handleWebShortcutAction(QAction *action)
{
auto *action = qobject_cast<QAction *>(sender());
if (action == nullptr) {
return;
}
......@@ -571,19 +572,16 @@ void Konsole::SessionController::sendBackgroundColor(uint terminator)
session()->reportBackgroundColor(c, terminator);
}
void SessionController::toggleReadOnly()
void SessionController::toggleReadOnly(QAction *action)
{
auto *action = qobject_cast<QAction *>(sender());
if (action != nullptr) {
bool readonly = !isReadOnly();
session()->setReadOnly(readonly);
}
}
void SessionController::toggleAllowMouseTracking()
void SessionController::toggleAllowMouseTracking(QAction *action)
{
QAction *action = qobject_cast<QAction*>(sender());
if (action == nullptr) {
// Crash if running in debug build (aka. someone developing)
Q_ASSERT(false && "Invalid function called toggleAllowMouseTracking");
......@@ -764,12 +762,18 @@ void SessionController::setupCommonActions()
&Konsole::SessionController::changeCodec);
// Mouse tracking enabled
action = collection->addAction(QStringLiteral("allow-mouse-tracking"), this, &SessionController::toggleAllowMouseTracking);
action = collection->addAction(QStringLiteral("allow-mouse-tracking"), this);
connect(action, &QAction::toggled, this, [this, action]() {
toggleAllowMouseTracking(action);
});
action->setText(i18nc("@item:inmenu Allows terminal applications to request mouse tracking", "Allow mouse tracking"));
action->setCheckable(true);
// Read-only
action = collection->addAction(QStringLiteral("view-readonly"), this, &SessionController::toggleReadOnly);
action = collection->addAction(QStringLiteral("view-readonly"), this);
connect(action, &QAction::toggled, this, [this, action]() {
toggleReadOnly(action);
});
action->setText(i18nc("@item:inmenu A read only (locked) session", "Read-only"));
action->setCheckable(true);
updateReadOnlyActionStates();
......
......@@ -177,7 +177,7 @@ Q_SIGNALS:
/**
* Emitted when the TerminalDisplay is drag-and-dropped to a new window.
*/
void viewDragAndDropped();
void viewDragAndDropped(SessionController *controller);
public Q_SLOTS:
/**
......@@ -250,15 +250,16 @@ private Q_SLOTS:
void monitorProcessFinish(bool monitor);
void renameSession();
void switchProfile(const QExplicitlySharedDataPointer<Profile> &profile);
// Set the action text to either "Edit" or "Create New" Profile
void setEditProfileActionText(const QExplicitlySharedDataPointer<Profile> &profile);
void handleWebShortcutAction();
void handleWebShortcutAction(QAction *action);
void configureWebShortcuts();
void sendSignal(QAction *action);
void sendForegroundColor(uint terminator);
void sendBackgroundColor(uint terminator);
void toggleReadOnly();
void toggleAllowMouseTracking();
void toggleReadOnly(QAction *action);
void toggleAllowMouseTracking(QAction *action);
// other
void setupSearchBar();
......
......@@ -40,9 +40,8 @@ void SessionGroup::removeSession(Session *session)
_sessions.remove(session);
}
void SessionGroup::sessionFinished()
void SessionGroup::sessionFinished(Session *session)
{
auto *session = qobject_cast<Session *>(sender());
Q_ASSERT(session);
removeSession(session);
}
......
......@@ -73,7 +73,7 @@ public:
void setMasterMode(int mode);
private Q_SLOTS:
void sessionFinished();
void sessionFinished(Session *session);
void forwardData(const QByteArray &data);
private:
......
......@@ -110,9 +110,8 @@ QModelIndex SessionListModel::parent(const QModelIndex &) const
return {};
}
void SessionListModel::sessionFinished()
void SessionListModel::sessionFinished(Session *session)
{
auto *session = qobject_cast<Session *>(sender());
int row = _sessions.indexOf(session);
if (row != -1) {
......
......@@ -54,7 +54,7 @@ protected:
}
private Q_SLOTS:
void sessionFinished();
void sessionFinished(Session *session);
private:
QList<Session *> _sessions;
......
......@@ -105,12 +105,12 @@ Session *SessionManager::createSession(Profile::Ptr profile)
Q_ASSERT(session);
applyProfile(session, profile, false);
connect(session, &Konsole::Session::profileChangeCommandReceived, this, &Konsole::SessionManager::sessionProfileCommandReceived);
connect(session, &Konsole::Session::profileChangeCommandReceived, this, [this, session](const QString &text) {
sessionProfileCommandReceived(session, text);
});
// ask for notification when session dies
connect(session, &Konsole::Session::finished, this, [this, session]() {
sessionTerminated(session);
});
connect(session, &Konsole::Session::finished, this, &SessionManager::sessionTerminated);
// add session to active list
_sessions << session;
......@@ -292,9 +292,8 @@ void SessionManager::applyProfile(Session *session, const Profile::Ptr &profile,
}
}
void SessionManager::sessionProfileCommandReceived(const QString &text)
void SessionManager::sessionProfileCommandReceived(Session *session, const QString &text)
{
auto *session = qobject_cast<Session *>(sender());
Q_ASSERT(session);
// store the font for each view if zoom was applied so that they can
......
......@@ -101,7 +101,7 @@ protected Q_SLOTS:
void sessionTerminated(Session *session);
private Q_SLOTS:
void sessionProfileCommandReceived(const QString &text);
void sessionProfileCommandReceived(Session *session, const QString &text);
void profileChanged(const QExplicitlySharedDataPointer<Profile> &profile);
......
......@@ -1046,7 +1046,7 @@ void EditProfileDialog::delayedPreview(int property, const QVariant &value)
void EditProfileDialog::delayedPreviewActivate()
{
Q_ASSERT(qobject_cast<QTimer *>(sender()));
Q_ASSERT(_delayedPreviewTimer);
QMutableHashIterator<int, QVariant> iter(_delayedPreviewProperties);
if (iter.hasNext()) {
......
......@@ -258,7 +258,7 @@ void TabbedViewContainer::terminalDisplayDropped(TerminalDisplay *terminalDispla
// Terminal from another window - recreate SessionController for current ViewManager
disconnectTerminalDisplay(terminalDisplay);
Session *terminalSession = terminalDisplay->sessionController()->session();
Q_EMIT terminalDisplay->sessionController()->viewDragAndDropped();
Q_EMIT terminalDisplay->sessionController()->viewDragAndDropped(terminalDisplay->sessionController());
connectedViewManager()->attachView(terminalDisplay, terminalSession);
connectTerminalDisplay(terminalDisplay);
}
......
Supports Markdown
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