Implemented DBus methods for copying input to other sessions

Implemented methods which allow input to be copied to no other
session and to all sessions. In addition, users can also select
exactly which sessions to copy input to by passing a list of
Session ids. Calling supporting method copyingSessions() on a
session lists other sessions which are copying input from it.
Calling supporting method feederSessions() on a session lists
other sessions it is copying input from.

BUG: 307089
This commit is contained in:
Theodore Wang
2023-12-03 23:37:18 +08:00
committed by Kurt Hindenburg
parent 1cad74b367
commit cd2330c4fc
4 changed files with 155 additions and 17 deletions

View File

@@ -850,6 +850,7 @@ void SessionController::setupExtraActions()
copyInputActions->addAction(copyInputToSelectedTabsAction);
copyInputActions->addAction(copyInputToNoneAction);
connect(copyInputActions, &KSelectAction::actionTriggered, this, &Konsole::SessionController::copyInputActionsTriggered);
_copyInputActions = copyInputActions;
action = collection->addAction(QStringLiteral("zmodem-upload"), this, &SessionController::zmodemUpload);
action->setText(i18n("&ZModem Upload..."));
@@ -1314,7 +1315,7 @@ void SessionController::copyInputToAllTabs()
Q_EMIT copyInputChanged(this);
}
void SessionController::copyInputToSelectedTabs()
void SessionController::copyInputToSelectedTabs(QList<Session *> *sessions)
{
if (_copyToGroup == nullptr) {
_copyToGroup = new SessionGroup(this);
@@ -1323,22 +1324,12 @@ void SessionController::copyInputToSelectedTabs()
_copyToGroup->setMasterMode(SessionGroup::CopyInputToAll);
}
auto *dialog = new CopyInputDialog(view());
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModal(true);
dialog->setMasterSession(session());
const QList<Session *> sessionsList = _copyToGroup->sessions();
QSet<Session *> currentGroup(sessionsList.begin(), sessionsList.end());
currentGroup.remove(session());
dialog->setChosenSessions(currentGroup);
connect(dialog, &QDialog::accepted, this, [=]() {
QSet<Session *> newGroup = dialog->chosenSessions();
newGroup.remove(session());
auto update = [this](QSet<Session *> newGroup, QSet<Session *> currentGroup) {
const QSet<Session *> completeGroup = newGroup | currentGroup;
for (Session *session : completeGroup) {
if (newGroup.contains(session) && !currentGroup.contains(session)) {
@@ -1352,9 +1343,27 @@ void SessionController::copyInputToSelectedTabs()
_copyToGroup->setMasterMode(SessionGroup::CopyInputToAll);
snapshot();
Q_EMIT copyInputChanged(this);
});
};
dialog->show();
if (sessions != nullptr) {
QSet<Session *> newGroup(sessions->begin(), sessions->end());
newGroup.remove(session());
update(newGroup, currentGroup);
} else {
auto *dialog = new CopyInputDialog(view());
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModal(true);
dialog->setMasterSession(session());
dialog->setChosenSessions(currentGroup);
connect(dialog, &QDialog::accepted, this, [=]() {
QSet<Session *> newGroup = dialog->chosenSessions();
newGroup.remove(session());
update(newGroup, currentGroup);
});
dialog->show();
}
}
void SessionController::copyInputToNone()
@@ -2131,4 +2140,9 @@ void SessionController::setVisible(QString name, bool visible)
actionCollection()->action(name)->setVisible(visible);
}
KSelectAction *SessionController::copyInputActions()
{
return _copyInputActions;
}
#include "moc_SessionController.cpp"