Commit c227b186 authored by Kurt Hindenburg's avatar Kurt Hindenburg

Fix issue where 'Copy Input To' doesn't work for multiple windows.

Patch by Thomas Dreibholz

BUG: 218616

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=1067166
parent be02eab1
......@@ -1225,8 +1225,6 @@ SessionGroup::SessionGroup(QObject* parent)
}
SessionGroup::~SessionGroup()
{
// disconnect all
connectAll(false);
}
int SessionGroup::masterMode() const { return _masterMode; }
QList<Session*> SessionGroup::sessions() const { return _sessions.keys(); }
......@@ -1235,25 +1233,12 @@ bool SessionGroup::masterStatus(Session* session) const { return _sessions[sessi
void SessionGroup::addSession(Session* session)
{
connect(session,SIGNAL(finished()),this,SLOT(sessionFinished()));
_sessions.insert(session,false);
QListIterator<Session*> masterIter(masters());
while ( masterIter.hasNext() )
connectPair(masterIter.next());
}
void SessionGroup::removeSession(Session* session)
{
disconnect(session,SIGNAL(finished()),this,SLOT(sessionFinished()));
setMasterStatus(session,false);
QListIterator<Session*> masterIter(masters());
while ( masterIter.hasNext() )
disconnectPair(masterIter.next());
_sessions.remove(session);
}
void SessionGroup::sessionFinished()
......@@ -1265,77 +1250,28 @@ void SessionGroup::sessionFinished()
void SessionGroup::setMasterMode(int mode)
{
_masterMode = mode;
connectAll(false);
connectAll(true);
}
QList<Session*> SessionGroup::masters() const
{
return _sessions.keys(true);
}
void SessionGroup::connectAll(bool connect)
void SessionGroup::setMasterStatus(Session* session , bool master)
{
QListIterator<Session*> masterIter(masters());
const bool wasMaster = _sessions[session];
while ( masterIter.hasNext() )
{
Session* master = masterIter.next();
QListIterator<Session*> otherIter(_sessions.keys());
while ( otherIter.hasNext() )
{
Session* other = otherIter.next();
if ( other != master )
{
if ( connect )
connectPair(master);
else
disconnectPair(master);
}
}
if (wasMaster == master) {
// No status change -> nothing to do.
return;
}
}
void SessionGroup::setMasterStatus(Session* session , bool master)
{
bool wasMaster = _sessions[session];
_sessions[session] = master;
if ( ( !wasMaster && !master )
|| ( wasMaster && master ) )
return;
QListIterator<Session*> iter(_sessions.keys());
while ( iter.hasNext() )
{
Session* other = iter.next();
if ( other != session )
{
if ( master )
connectPair(session);
else
disconnectPair(session);
}
}
}
void SessionGroup::connectPair(Session* master)
{
if ( _masterMode & CopyInputToAll )
{
// It is not possible to connect directly to other->emulation()'s
// sendString() here, since this would cause an infinite loop when
// the destination session is also the master of another group!
connect( master->emulation() , SIGNAL(sendData(const char*,int)) , this,
if(master) {
connect( session->emulation() , SIGNAL(sendData(const char*,int)) , this,
SLOT(forwardData(const char*,int)) );
}
}
void SessionGroup::disconnectPair(Session* master)
{
if ( _masterMode & CopyInputToAll )
{
disconnect( master->emulation() , SIGNAL(sendData(const char*,int)) , this,
SLOT(forwardData(const char*,int)) );
else {
disconnect( session->emulation() , SIGNAL(sendData(const char*,int)) , this,
SLOT(forwardData(const char*,int)) );
}
}
void SessionGroup::forwardData(const char* data, int size)
......
......@@ -710,9 +710,6 @@ private slots:
void forwardData(const char* data, int size);
private:
void connectPair(Session* master);
void disconnectPair(Session* master);
void connectAll(bool connect);
QList<Session*> masters() const;
// maps sessions to their master status
......
......@@ -694,9 +694,6 @@ void SessionController::copyInputToAllTabs()
{
if(!_copyToGroup) {
_copyToGroup = new SessionGroup(this);
_copyToGroup->addSession(_session);
_copyToGroup->setMasterStatus(_session, true);
_copyToGroup->setMasterMode(SessionGroup::CopyInputToAll);
}
// Find our window ...
......@@ -708,17 +705,18 @@ void SessionController::copyInputToAllTabs()
iterator != group.end(); ++iterator) {
Session* session = *iterator;
if(session != _session) {
// First, ensure that the session is removed
// (necessary to avoid duplicates on addSession()!)
_copyToGroup->removeSession(session);
// First, ensure that the session is removed
// (necessary to avoid duplicates on addSession()!)
_copyToGroup->removeSession(session);
// Add current session if it is displayed our window
if(hasTerminalDisplayInSameWindow(session, myWindow)) {
_copyToGroup->addSession(session);
}
// Add current session if it is displayed our window
if(hasTerminalDisplayInSameWindow(session, myWindow)) {
_copyToGroup->addSession(session);
}
}
_copyToGroup->setMasterStatus(_session, true);
_copyToGroup->setMasterMode(SessionGroup::CopyInputToAll);
snapshot();
_copyToAllTabsAction->setChecked(true);
_copyToSelectedAction->setChecked(false);
......@@ -762,6 +760,8 @@ void SessionController::copyInputToSelectedTabs()
_copyToGroup->removeSession(session);
}
_copyToGroup->setMasterStatus(_session, true);
_copyToGroup->setMasterMode(SessionGroup::CopyInputToAll);
snapshot();
}
......@@ -783,7 +783,10 @@ void SessionController::copyInputToNone()
_copyToGroup->removeSession(*iterator);
}
}
delete _copyToGroup;
_copyToGroup = NULL;
snapshot();
_copyToAllTabsAction->setChecked(false);
_copyToSelectedAction->setChecked(false);
_copyToNoneAction->setChecked(true);
......
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