Commit e9c4c9cc authored by Robert Knight's avatar Robert Knight
Browse files

Cleanup the Session class's API. Remove redundant and unused methods, give...

Cleanup the Session class's API.  Remove redundant and unused methods, give better names to others, reorganise the order in the header file.  Add checks in the view to behave properly when it is not attached to a session.  Make the Konsole part's behaviour compliant with the TerminalInterface API documentation.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=663705
parent 2b75ba06
......@@ -175,6 +175,10 @@ void Emulation::setScreen(int n)
}
}
void Emulation::clearHistory()
{
_screen[0]->setScroll( _screen[0]->getScroll() , false );
}
void Emulation::setHistory(const HistoryType& t)
{
_screen[0]->setScroll(t);
......
......@@ -77,6 +77,9 @@ public:
/** Returns the size of the screen image which the emulation produces */
QSize imageSize();
/** Clears the history scroll. */
void clearHistory();
/**
* Sets the history store used by this emulation. When new lines
* are added to the output, older lines at the top of the screen are transferred to a history
......
......@@ -113,6 +113,11 @@ public:
virtual void addLine(bool previousWrapped=false) = 0;
//
// FIXME: Passing around constant references to HistoryType instances
// is very unsafe, because those references will no longer
// be valid if the history scroll is deleted.
//
const HistoryType& getType() { return *m_histType; }
protected:
......
......@@ -84,7 +84,8 @@ void ManageProfilesDialog::updateTableModel()
// setup session table
_sessionModel = new QStandardItemModel(this);
_sessionModel->setHorizontalHeaderLabels( QStringList() << "Name"
<< "Show in Menu" );
<< "Show in Menu"
<< "Shortcut" );
QListIterator<QString> keyIter( SessionManager::instance()->availableProfiles() );
while ( keyIter.hasNext() )
{
......
......@@ -73,17 +73,16 @@ Part::Part(QObject* parent)
KeyTrans::loadAll();
// create window and session for part
// create view widget
_viewManager = new ViewManager(this,actionCollection());
//MainWindow* window = new MainWindow();
//window->menuBar()->setVisible(false);
// _viewManager = window->viewManager();
connect( _viewManager , SIGNAL(activeViewChanged(SessionController*)) , this ,
SLOT(activeViewChanged(SessionController*)) );
createSession( QString() );
setWidget(_viewManager->widget());
// create basic session
createSession(QString());
}
Part::~Part()
{
......@@ -92,23 +91,37 @@ bool Part::openFile()
{
return false;
}
Session* Part::activeSession() const
{
// for now, just return the first available session
QList<Session*> list = SessionManager::instance()->sessions();
Q_ASSERT( !list.isEmpty() );
return list.first();
}
void Part::startProgram( const QString& program,
const QStringList& arguments )
{
Session* session = createSession(QString());
if ( !activeSession()->running() )
{
if ( !program.isEmpty() && !arguments.isEmpty() )
{
activeSession()->setProgram(program);
activeSession()->setArguments(arguments);
}
session->setProgram(program);
session->setArguments(arguments);
session->run();
activeSession()->run();
}
}
void Part::showShellInDir( const QString& dir )
{
Session* session = createSession(QString());
session->setInitialWorkingDirectory(dir);
session->run();
if ( !activeSession()->running() )
{
if ( !dir.isEmpty() )
activeSession()->setInitialWorkingDirectory(dir);
activeSession()->run();
}
}
void Part::sendInput( const QString& text )
{
......
......@@ -80,6 +80,8 @@ private slots:
void activeViewChanged(SessionController* controller);
private:
Session* activeSession() const;
ViewManager* _viewManager;
SessionController* _pluggedController;
};
......
......@@ -1568,10 +1568,18 @@ int Screen::getHistLines()
return hist->getLines();
}
void Screen::setScroll(const HistoryType& t)
void Screen::setScroll(const HistoryType& t , bool copyPreviousScroll)
{
clearSelection();
hist = t.scroll(hist);
if ( copyPreviousScroll )
hist = t.scroll(hist);
else
{
HistoryScroll* oldScroll = hist;
hist = t.scroll(0);
delete oldScroll;
}
}
bool Screen::hasScroll()
......
......@@ -208,7 +208,7 @@ public: // these are all `Screen' operations
int getColumns() { return columns; }
int getHistLines ();
void setScroll(const HistoryType&);
void setScroll(const HistoryType& , bool copyPreviousScroll = true);
const HistoryType& getScroll();
bool hasScroll();
......
......@@ -68,7 +68,6 @@ Session::Session() :
, _monitorActivity(false)
, _monitorSilence(false)
, _notifiedActivity(false)
, _masterMode(false)
, _autoClose(true)
, _wantedClose(false)
, _silenceSeconds(10)
......@@ -98,10 +97,11 @@ Session::Session() :
connect( _emulation, SIGNAL( changeTitle( int, const QString & ) ),
this, SLOT( setUserTitle( int, const QString & ) ) );
connect( _emulation, SIGNAL( notifySessionState(int) ),
this, SLOT( notifySessionState(int) ) );
connect( _emulation, SIGNAL( zmodemDetected() ), this, SLOT(slotZModemDetected()));
this, SLOT( activityStateChanged(int) ) );
connect( _emulation, SIGNAL( zmodemDetected() ), this ,
SLOT( fireZModemDetected() ) );
connect( _emulation, SIGNAL( changeTabTextColor( int ) ),
this, SLOT( changeTabTextColor( int ) ) );
this, SIGNAL( changeTabTextColor( int ) ) );
//connect teletype to emulation backend
......@@ -126,6 +126,11 @@ Session::Session() :
QTimer::singleShot(0, this, SLOT(ptyError()));
}
bool Session::running() const
{
return _shellProcess->isRunning();
}
void Session::setType(const QString& type) { _type = type; }
QString Session::type() const { return _type; }
......@@ -154,7 +159,7 @@ void Session::ptyError()
else
KMessageBox::error(QApplication::activeWindow(), _shellProcess->error());
emit done(this);
emit finished();
}
QList<TerminalDisplay*> Session::views() const
......@@ -249,7 +254,7 @@ void Session::run()
QString pexec = KGlobal::dirs()->findExe(exec);
if ( pexec.isEmpty() ) {
kError()<<"can not execute "<<exec<<endl;
QTimer::singleShot(1, this, SLOT(done()));
QTimer::singleShot(1, this, SIGNAL(finished()));
return;
}
......@@ -283,11 +288,6 @@ void Session::run()
}
void Session::changeTabTextColor( int color )
{
emit changeTabTextColor( this, color );
}
void Session::setUserTitle( int what, const QString &caption )
{
//set to true if anything is actually changed (eg. old _title != new _title )
......@@ -314,19 +314,23 @@ void Session::setUserTitle( int what, const QString &caption )
kDebug() << __FILE__ << __LINE__ << ": setting background colour to " << colorString << endl;
QColor backColor = QColor(colorString);
if (backColor.isValid()){// change color via \033]11;Color\007
if (backColor != _modifiedBackground) {
if (backColor != _modifiedBackground)
{
_modifiedBackground = backColor;
QListIterator<TerminalDisplay*> viewIter(_views);
while (viewIter.hasNext())
viewIter.next()->setDefaultBackColor(backColor);
// bail out here until the code to connect the terminal display
// to the changeBackgroundColor() signal has been written
// and tested - just so we don't forget to do this.
Q_ASSERT( 0 );
emit changeBackgroundColor(backColor);
}
}
}
if (what == 30) {
if ( _title != caption ) {
renameSession(caption);
setTitle(caption);
return;
}
}
......@@ -341,9 +345,6 @@ void Session::setUserTitle( int what, const QString &caption )
if ( _iconName != caption ) {
_iconName = caption;
QListIterator< TerminalDisplay* > viewIter(_views);
while (viewIter.hasNext())
viewIter.next()->update();
modified = true;
}
}
......@@ -384,17 +385,17 @@ void Session::monitorTimerDone()
KNotification::event("Silence", i18n("Silence in session '%1'", _title), QPixmap(),
QApplication::activeWindow(),
KNotification::CloseWhenWidgetActivated);
emit notifySessionState(this,NOTIFYSILENCE);
emit notifySessionState(NOTIFYSILENCE);
}
else
{
emit notifySessionState(this,NOTIFYNORMAL);
emit notifySessionState(NOTIFYNORMAL);
}
_notifiedActivity=false;
}
void Session::notifySessionState(int state)
void Session::activityStateChanged(int state)
{
if (state==NOTIFYBELL)
{
......@@ -423,7 +424,7 @@ void Session::notifySessionState(int state)
if ( state==NOTIFYSILENCE && !_monitorSilence )
state = NOTIFYNORMAL;
emit notifySessionState(this, state);
emit notifySessionState(state);
}
void Session::onContentSizeChange(int /*height*/, int /*width*/)
......@@ -469,29 +470,14 @@ bool Session::closeSession()
if (!_shellProcess->isRunning() || !sendSignal(SIGHUP))
{
// Forced close.
QTimer::singleShot(1, this, SLOT(done()));
QTimer::singleShot(1, this, SIGNAL(finished()));
}
return true;
}
void Session::feedSession(const QString &text)
void Session::sendText(const QString &text) const
{
emit disableMasterModeConnections();
_emulation->sendText(text);
emit enableMasterModeConnections();
}
void Session::sendSession(const QString &text)
{
QString newtext=text;
newtext.append("\r");
feedSession(newtext);
}
void Session::renameSession(const QString &name)
{
_title=name;
emit renameSession(this,name);
}
Session::~Session()
......@@ -501,11 +487,6 @@ Session::~Session()
delete _zmodemProc;
}
void Session::done() {
emit processExited();
emit done(this);
}
void Session::done(int exitStatus)
{
if (!_autoClose)
......@@ -535,8 +516,7 @@ void Session::done(int exitStatus)
QApplication::activeWindow(),
KNotification::CloseWhenWidgetActivated);
}
emit processExited();
emit done(this);
emit finished();
}
Emulation* Session::emulation() const
......@@ -544,7 +524,7 @@ Emulation* Session::emulation() const
return _emulation;
}
QString Session::keymap() const
QString Session::keyBindings() const
{
return _emulation->keymap();
}
......@@ -564,7 +544,7 @@ int Session::sessionId() const
return _sessionId;
}
void Session::setKeymap(const QString &id)
void Session::setKeyBindings(const QString &id)
{
_emulation->setKeymap(id);
}
......@@ -578,7 +558,7 @@ void Session::setTitle(const QString& title)
}
}
const QString& Session::title() const
QString Session::title() const
{
return _title;
}
......@@ -598,46 +578,29 @@ void Session::setIconText(const QString& iconText)
//kDebug(1211)<<"Session setIconText " << _iconText <<endl;
}
const QString& Session::iconName() const
QString Session::iconName() const
{
return _iconName;
}
const QString& Session::iconText() const
QString Session::iconText() const
{
return _iconText;
}
bool Session::testAndSetStateIconName (const QString& newname)
{
if (newname != _stateIconName)
{
_stateIconName = newname;
return true;
}
return false;
}
void Session::setHistory(const HistoryType &hType)
void Session::setHistoryType(const HistoryType &hType)
{
_emulation->setHistory(hType);
}
const HistoryType& Session::history()
const HistoryType& Session::historyType() const
{
return _emulation->history();
}
void Session::clearHistory()
{
if (history().isEnabled()) {
int histSize = history().maximumLineCount();
setHistory(HistoryTypeNone());
if (histSize)
setHistory(HistoryTypeBuffer(histSize));
else
setHistory(HistoryTypeFile());
}
_emulation->clearHistory();
}
QStringList Session::arguments() const
......@@ -652,14 +615,13 @@ QString Session::program() const
bool Session::isMonitorActivity() const { return _monitorActivity; }
bool Session::isMonitorSilence() const { return _monitorSilence; }
bool Session::isMasterMode() const { return _masterMode; }
void Session::setMonitorActivity(bool _monitor)
{
_monitorActivity=_monitor;
_notifiedActivity=false;
notifySessionState(NOTIFYNORMAL);
activityStateChanged(NOTIFYNORMAL);
}
void Session::setMonitorSilence(bool _monitor)
......@@ -676,7 +638,7 @@ void Session::setMonitorSilence(bool _monitor)
else
_monitorTimer->stop();
notifySessionState(NOTIFYNORMAL);
activityStateChanged(NOTIFYNORMAL);
}
void Session::setMonitorSilenceSeconds(int seconds)
......@@ -688,35 +650,25 @@ void Session::setMonitorSilenceSeconds(int seconds)
}
}
void Session::setMasterMode(bool _master)
{
_masterMode=_master;
}
void Session::setAddToUtmp(bool set)
{
_addToUtmp = set;
}
void Session::setXonXoff(bool set)
void Session::setFlowControlEnabled(bool enabled)
{
_flowControl = set;
_flowControl = enabled;
}
void Session::slotZModemDetected()
void Session::fireZModemDetected()
{
if (!_zmodemBusy)
{
QTimer::singleShot(10, this, SLOT(emitZModemDetected()));
QTimer::singleShot(10, this, SIGNAL(zmodemDetected()));
_zmodemBusy = true;
}
}
void Session::emitZModemDetected()
{
emit zmodemDetected(this);
}
void Session::cancelZModem()
{
_shellProcess->send_bytes("\030\030\030\030", 4); // Abort
......@@ -831,42 +783,12 @@ void Session::zmodemDone()
}
}
void Session::enableFullScripting(bool b)
{
assert( 0 );
// TODO Re-add adaptors
// assert(!(_fullScripting && !b) && "_fullScripting can't be disabled");
// if (!_fullScripting && b)
// (void)new SessionScriptingAdaptor(this);
}
void Session::onReceiveBlock( const char* buf, int len )
{
_emulation->onReceiveBlock( buf, len );
emit receivedData( QString::fromLatin1( buf, len ) );
}
QString Session::encoding()
{
return _emulation->codec()->name();
}
void Session::setEncoding(const QString &encoding)
{
emit setSessionEncoding(this, encoding);
}
QString Session::keytab()
{
return keymap();
}
void Session::setKeytab(const QString &keytab)
{
setKeymap(keytab);
emit updateSessionConfig(this);
}
QSize Session::size()
{
return _emulation->imageSize();
......@@ -877,13 +799,13 @@ void Session::setSize(QSize size)
if ((size.width() <= 1) || (size.height() <= 1))
return;
emit resizeSession(this, size);
emit resizeSession(size);
}
int Session::foregroundPid() const
int Session::foregroundProcessId() const
{
return _shellProcess->foregroundProcessGroup();
}
int Session::sessionPid() const
int Session::sessionProcessId() const
{
return _shellProcess->pid();
}
......
......@@ -29,6 +29,9 @@
#include <KApplication>
#include <KMainWindow>
// Konsole
#include "History.h"
class K3ProcIO;
class K3Process;
......@@ -37,15 +40,14 @@ namespace Konsole
class ColorScheme;
class Emulation;
class HistoryType;
class Pty;
class TerminalDisplay;
class ZModemDialog;
/**
* Session represents a Konsole session.
* This consists of a pseudo-teletype (or PTY) which handles I/O between the terminal
* process and Konsole, and a terminal emulation ( Emulation and subclasses ) which
* Represents a terminal session consisting of a pseudo-teletype (or PTY) which
* handles I/O between the terminal process and Konsole, and a terminal
* emulation ( Emulation and subclasses ) which
* processes the output stream from the PTY and produces a character image which
* is then shown on displays which are connected to the session.
*
......@@ -60,14 +62,26 @@ Q_OBJECT
public:
Q_PROPERTY(QString sessionName READ title)
Q_PROPERTY(QString encoding READ encoding WRITE setEncoding)
Q_PROPERTY(int sessionPid READ sessionPid)
Q_PROPERTY(QString keytab READ keytab WRITE setKeytab)
Q_PROPERTY(int sessionProcessId READ sessionProcessId)
Q_PROPERTY(QString keytab READ keyBindings WRITE setKeyBindings)
Q_PROPERTY(QSize size READ size WRITE setSize)
/**
* Constructs a new session.
*
* To start the terminal process, call the run() method,
* after specifying the program and arguments
* using setProgram() and setArguments()
*/
Session();
~Session();
/**
* Returns true if the session is currently running. This will be true
* after run() has been called.
*/
bool running() const;
/**
* Sets the type of this session.
* TODO: More documentation
......@@ -109,12 +123,8 @@ public:
* Returns the terminal emulation instance being used to encode / decode
* characters to / from the process.
*/
Emulation* emulation() const; // to control emulation
bool isSecure() const;
bool isMonitorActivity() const;
bool isMonitorSilence() const;
bool isMasterMode() const;
Emulation* emulation() const;
/**
* Returns the value of the TERM environment variable which will
* be used in the session's environment when it is started using
......@@ -132,26 +142,42 @@ public:
*/
void setTerminalType(const QString& terminalType);
/** Returns the unique ID for this session. */
int sessionId() const;
const QString& title() const;
const QString& iconName() const;
const QString& iconText() const;
/**
* Return the session title set by the user (ie. the program running
* in the terminal), or an empty string if the user has not set a custom title
*/
QString userTitle() const;
/**
* This enum describes the contexts for which separate
* tab title formats may be specified.
*/
enum TabTitleContext
{