Commit 5e1b0068 authored by Robert Knight's avatar Robert Knight

API cleanup in Session class. Remove un-needed methods and duplicates. Avoid...

API cleanup in Session class.  Remove un-needed methods and duplicates.  Avoid need to call setListenToKeyPress on new Session instances before they can receive input.

svn path=/branches/work/konsole-split-view/; revision=658772
parent 8225fd14
...@@ -147,8 +147,6 @@ void Application::detachView(Session* session) ...@@ -147,8 +147,6 @@ void Application::detachView(Session* session)
void Application::createSession(const QString& key , ViewManager* view) void Application::createSession(const QString& key , ViewManager* view)
{ {
Session* session = SessionManager::instance()->createSession(key); Session* session = SessionManager::instance()->createSession(key);
session->setListenToKeyPress(true);
//session->setConnect(true);
// create view before starting the session process so that the session doesn't suffer // create view before starting the session process so that the session doesn't suffer
// a change in terminal size right after the session starts. some applications such as GNU Screen // a change in terminal size right after the session starts. some applications such as GNU Screen
......
...@@ -105,7 +105,6 @@ using namespace Konsole; ...@@ -105,7 +105,6 @@ using namespace Konsole;
Emulation::Emulation() : Emulation::Emulation() :
currentScreen(0), currentScreen(0),
listenToKeyPress(false),
m_codec(0), m_codec(0),
decoder(0), decoder(0),
keytrans(0) keytrans(0)
...@@ -188,6 +187,8 @@ const HistoryType& Emulation::history() ...@@ -188,6 +187,8 @@ const HistoryType& Emulation::history()
void Emulation::setCodec(const QTextCodec * qtc) void Emulation::setCodec(const QTextCodec * qtc)
{ {
Q_ASSERT( qtc );
m_codec = qtc; m_codec = qtc;
delete decoder; delete decoder;
decoder = m_codec->makeDecoder(); decoder = m_codec->makeDecoder();
...@@ -195,15 +196,12 @@ void Emulation::setCodec(const QTextCodec * qtc) ...@@ -195,15 +196,12 @@ void Emulation::setCodec(const QTextCodec * qtc)
emit useUtf8(utf8()); emit useUtf8(utf8());
} }
void Emulation::setCodec(int c) void Emulation::setCodec(EmulationCodec codec)
{ {
setCodec(c ? QTextCodec::codecForName("utf8") if ( codec == Utf8Codec )
: QTextCodec::codecForLocale()); setCodec( QTextCodec::codecForName("utf8") );
} else if ( codec == LocaleCodec )
setCodec( QTextCodec::codecForLocale() );
void Emulation::setKeymap(int no)
{
keytrans = KeyTrans::find(no);
} }
void Emulation::setKeymap(const QString &id) void Emulation::setKeymap(const QString &id)
...@@ -216,10 +214,6 @@ QString Emulation::keymap() ...@@ -216,10 +214,6 @@ QString Emulation::keymap()
return keytrans->id(); return keytrans->id();
} }
int Emulation::keymapNo()
{
return keytrans->numb();
}
// Interpreting Codes --------------------------------------------------------- // Interpreting Codes ---------------------------------------------------------
...@@ -261,7 +255,6 @@ void Emulation::onReceiveChar(int c) ...@@ -261,7 +255,6 @@ void Emulation::onReceiveChar(int c)
void Emulation::onKeyPress( QKeyEvent* ev ) void Emulation::onKeyPress( QKeyEvent* ev )
{ {
if (!listenToKeyPress) return; // someone else gets the keys
emit notifySessionState(NOTIFYNORMAL); emit notifySessionState(NOTIFYNORMAL);
if (!ev->text().isEmpty()) if (!ev->text().isEmpty())
...@@ -460,11 +453,6 @@ char Emulation::getErase() ...@@ -460,11 +453,6 @@ char Emulation::getErase()
return '\b'; return '\b';
} }
void Emulation::setListenToKeyPress(bool l)
{
listenToKeyPress=l;
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/*! triggered by image size change of the TerminalDisplay `gui'. /*! triggered by image size change of the TerminalDisplay `gui'.
......
...@@ -196,16 +196,13 @@ public: ...@@ -196,16 +196,13 @@ public:
//virtual void setConnect(bool r); //virtual void setConnect(bool r);
//bool isConnected() { return connected; } //bool isConnected() { return connected; }
bool utf8() { return m_codec->mibEnum() == 106; } bool utf8() { Q_ASSERT(m_codec); return m_codec->mibEnum() == 106; }
virtual char getErase(); virtual char getErase();
virtual void setListenToKeyPress(bool l);
void setColumns(int columns); void setColumns(int columns);
void setKeymap(int no);
void setKeymap(const QString &id); void setKeymap(const QString &id);
int keymapNo();
QString keymap(); QString keymap();
virtual void clearEntireScreen() =0; virtual void clearEntireScreen() =0;
...@@ -230,9 +227,12 @@ protected: ...@@ -230,9 +227,12 @@ protected:
*/ */
void setScreen(int index); void setScreen(int index);
bool listenToKeyPress; // listen to input enum EmulationCodec
{
void setCodec(int c); // codec number, 0 = locale, 1=utf8 LocaleCodec = 0,
Utf8Codec = 1
};
void setCodec(EmulationCodec codec); // codec number, 0 = locale, 1=utf8
//decodes an incoming C-style character stream into a unicode QString using //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.) //the current text codec. (this allows for rendering of non-ASCII characters in text files etc.)
......
...@@ -114,7 +114,6 @@ void Part::sendInput( const QString& text ) ...@@ -114,7 +114,6 @@ void Part::sendInput( const QString& text )
Session* Part::createSession(const QString& key) Session* Part::createSession(const QString& key)
{ {
Session* session = SessionManager::instance()->createSession(key); Session* session = SessionManager::instance()->createSession(key);
session->setListenToKeyPress(true);
_viewManager->createView(session); _viewManager->createView(session);
......
...@@ -68,8 +68,6 @@ Session::Session() : ...@@ -68,8 +68,6 @@ Session::Session() :
, masterMode(false) , masterMode(false)
, autoClose(true) , autoClose(true)
, wantedClose(false) , wantedClose(false)
//, schema_no(0)
, _fontNo(3)
, _silenceSeconds(10) , _silenceSeconds(10)
, _addToUtmp(true) , _addToUtmp(true)
, _flowControl(true) , _flowControl(true)
...@@ -79,7 +77,6 @@ Session::Session() : ...@@ -79,7 +77,6 @@ Session::Session() :
, _zmodemBusy(false) , _zmodemBusy(false)
, _zmodemProc(0) , _zmodemProc(0)
, _zmodemProgress(0) , _zmodemProgress(0)
, _encoding_no(0)
{ {
//prepare DBus communication //prepare DBus communication
//TODO - Re-add Session adaptor //TODO - Re-add Session adaptor
...@@ -280,7 +277,8 @@ void Session::changeTabTextColor( int color ) ...@@ -280,7 +277,8 @@ void Session::changeTabTextColor( int color )
void Session::setUserTitle( int what, const QString &caption ) void Session::setUserTitle( int what, const QString &caption )
{ {
bool modified = false; //set to true if anything is actually changed (eg. old _title != new _title ) //set to true if anything is actually changed (eg. old _title != new _title )
bool modified = false;
// (btw: what=0 changes _title and icon, what=1 only icon, what=2 only _title // (btw: what=0 changes _title and icon, what=1 only icon, what=2 only _title
if ((what == 0) || (what == 2)) { if ((what == 0) || (what == 2)) {
...@@ -458,9 +456,7 @@ bool Session::closeSession() ...@@ -458,9 +456,7 @@ bool Session::closeSession()
void Session::feedSession(const QString &text) void Session::feedSession(const QString &text)
{ {
emit disableMasterModeConnections(); emit disableMasterModeConnections();
setListenToKeyPress(true);
_emulation->sendText(text); _emulation->sendText(text);
setListenToKeyPress(false);
emit enableMasterModeConnections(); emit enableMasterModeConnections();
} }
...@@ -482,22 +478,6 @@ Session::~Session() ...@@ -482,22 +478,6 @@ Session::~Session()
delete _emulation; delete _emulation;
delete _shellProcess; delete _shellProcess;
delete _zmodemProc; delete _zmodemProc;
QListIterator<TerminalDisplay*> viewIter(_views);
while (viewIter.hasNext())
viewIter.next()->deleteLater();
}
/*void Session::setConnect(bool c)
{
connected=c;
_emulation->setConnect(c);
setListenToKeyPress(c);
}*/
void Session::setListenToKeyPress(bool l)
{
_emulation->setListenToKeyPress(l);
} }
void Session::done() { void Session::done() {
...@@ -538,38 +518,16 @@ void Session::done(int exitStatus) ...@@ -538,38 +518,16 @@ void Session::done(int exitStatus)
emit done(this); emit done(this);
} }
void Session::terminate()
{
delete this;
}
Emulation* Session::emulation() const Emulation* Session::emulation() const
{ {
return _emulation; return _emulation;
} }
// following interfaces might be misplaced ///
int Session::encodingNo() const
{
return _encoding_no;
}
int Session::keymapNo() const
{
return _emulation->keymapNo();
}
QString Session::keymap() const QString Session::keymap() const
{ {
return _emulation->keymap(); return _emulation->keymap();
} }
int Session::fontNo() const
{
return _fontNo;
}
const QString& Session::terminalType() const const QString& Session::terminalType() const
{ {
return _term; return _term;
...@@ -585,26 +543,11 @@ int Session::sessionId() const ...@@ -585,26 +543,11 @@ int Session::sessionId() const
return _sessionId; return _sessionId;
} }
void Session::setEncodingNo(int index)
{
_encoding_no = index;
}
void Session::setKeymapNo(int kn)
{
_emulation->setKeymap(kn);
}
void Session::setKeymap(const QString &id) void Session::setKeymap(const QString &id)
{ {
_emulation->setKeymap(id); _emulation->setKeymap(id);
} }
void Session::setFontNo(int fn)
{
_fontNo = fn;
}
void Session::setTitle(const QString& title) void Session::setTitle(const QString& title)
{ {
if ( title != _title ) if ( title != _title )
...@@ -676,23 +619,16 @@ void Session::clearHistory() ...@@ -676,23 +619,16 @@ void Session::clearHistory()
} }
} }
QStringList Session::getArgs() QStringList Session::arguments() const
{ {
return _arguments; return _arguments;
} }
QString Session::getPgm() QString Session::program() const
{ {
return _program; return _program;
} }
QString Session::currentWorkingDirectory()
{
Q_ASSERT(false);
return QString();
}
bool Session::isMonitorActivity() const { return monitorActivity; } bool Session::isMonitorActivity() const { return monitorActivity; }
bool Session::isMonitorSilence() const { return monitorSilence; } bool Session::isMonitorSilence() const { return monitorSilence; }
bool Session::isMasterMode() const { return masterMode; } bool Session::isMasterMode() const { return masterMode; }
......
...@@ -57,10 +57,11 @@ class ColorScheme; ...@@ -57,10 +57,11 @@ class ColorScheme;
* activity. * activity.
*/ */
class Session : public QObject class Session : public QObject
{ Q_OBJECT {
Q_OBJECT
public: public:
Q_PROPERTY(QString sessionName READ sessionName) Q_PROPERTY(QString sessionName READ title)
Q_PROPERTY(QString encoding READ encoding WRITE setEncoding) Q_PROPERTY(QString encoding READ encoding WRITE setEncoding)
Q_PROPERTY(int sessionPid READ sessionPid) Q_PROPERTY(int sessionPid READ sessionPid)
Q_PROPERTY(QString keytab READ keytab WRITE setKeytab) Q_PROPERTY(QString keytab READ keytab WRITE setKeytab)
...@@ -91,8 +92,6 @@ public: ...@@ -91,8 +92,6 @@ public:
* all views of a session will display the same number of lines and * all views of a session will display the same number of lines and
* columns. * columns.
* *
* When the Session instance is destroyed, any views which are still
* attached will also be deleted.
*/ */
void addView(TerminalDisplay* widget); void addView(TerminalDisplay* widget);
/** /**
...@@ -108,8 +107,6 @@ public: ...@@ -108,8 +107,6 @@ public:
*/ */
QList<TerminalDisplay*> views() const; QList<TerminalDisplay*> views() const;
void setListenToKeyPress(bool l);
/** /**
* Returns the terminal emulation instance being used to encode / decode * Returns the terminal emulation instance being used to encode / decode
* characters to / from the process. * characters to / from the process.
...@@ -119,8 +116,6 @@ public: ...@@ -119,8 +116,6 @@ public:
bool isMonitorActivity() const; bool isMonitorActivity() const;
bool isMonitorSilence() const; bool isMonitorSilence() const;
bool isMasterMode() const; bool isMasterMode() const;
int encodingNo() const;
int fontNo() const;
/** /**
* Returns the value of the TERM environment variable which will * Returns the value of the TERM environment variable which will
...@@ -155,10 +150,12 @@ public: ...@@ -155,10 +150,12 @@ public:
*/ */
QString displayTitle() const; QString displayTitle() const;
int keymapNo() const;
QString keymap() const; QString keymap() const;
QStringList getArgs();
QString getPgm(); /** Returns the arguments passed to the shell process when run() is called. */
QStringList arguments() const;
/** Returns the program name of the shell process started when run() is called. */
QString program() const;
/** /**
* Sets the command line arguments which the session's program will be passed when * Sets the command line arguments which the session's program will be passed when
...@@ -169,7 +166,6 @@ public: ...@@ -169,7 +166,6 @@ public:
void setProgram(const QString& program); void setProgram(const QString& program);
/** Returns the session's current working directory. */ /** Returns the session's current working directory. */
QString currentWorkingDirectory();
QString initialWorkingDirectory() { return _initial_cwd; } QString initialWorkingDirectory() { return _initial_cwd; }
/** /**
...@@ -180,20 +176,13 @@ public: ...@@ -180,20 +176,13 @@ public:
void setHistory(const HistoryType&); void setHistory(const HistoryType&);
const HistoryType& history(); const HistoryType& history();
void clearHistory();
void setMonitorActivity(bool); void setMonitorActivity(bool);
void setMonitorSilence(bool); void setMonitorSilence(bool);
void setMonitorSilenceSeconds(int seconds); void setMonitorSilenceSeconds(int seconds);
void setMasterMode(bool); void setMasterMode(bool);
//TODO - Remove these functions which use indicies to reference keyboard layouts,
// encodings etc. and replace them either with methods that
// use pointers or references to the font object / keyboard
// layout object etc. or a QString key
void setEncodingNo(int index);
void setKeymapNo(int kn);
void setFontNo(int fn);
void setKeymap(const QString& _id); void setKeymap(const QString& _id);
void setTitle(const QString& _title); void setTitle(const QString& _title);
void setIconName(const QString& _iconName); void setIconName(const QString& _iconName);
...@@ -206,11 +195,9 @@ public: ...@@ -206,11 +195,9 @@ public:
void setAutoClose(bool b) { autoClose = b; } void setAutoClose(bool b) { autoClose = b; }
void renameSession(const QString &name); void renameSession(const QString &name);
bool closeSession();
void clearHistory();
void feedSession(const QString &text); void feedSession(const QString &text);
void sendSession(const QString &text); void sendSession(const QString &text);
QString sessionName() { return _title; }
/** /**
* Returns the process id of the terminal process. * Returns the process id of the terminal process.
...@@ -227,18 +214,29 @@ public: ...@@ -227,18 +214,29 @@ public:
void setEncoding(const QString &encoding); void setEncoding(const QString &encoding);
QString keytab(); QString keytab();
void setKeytab(const QString &keytab); void setKeytab(const QString &keytab);
/** Returns the terminal session's window size in lines and columns. */
QSize size(); QSize size();
/**
* Emits a request to resize the session to accomodate
* the specified window size.
*
* @param size The size in lines and columns to request.
*/
void setSize(QSize size); void setSize(QSize size);
public Q_SLOTS: public slots:
void run(); void run();
void done(); void done();
void done(int); void done(int);
void terminate(); bool closeSession();
void setUserTitle( int, const QString &caption ); void setUserTitle( int, const QString &caption );
void changeTabTextColor( int ); void changeTabTextColor( int );
void ptyError(); void ptyError();
void slotZModemDetected(); void slotZModemDetected();
void emitZModemDetected(); void emitZModemDetected();
...@@ -248,7 +246,7 @@ public Q_SLOTS: ...@@ -248,7 +246,7 @@ public Q_SLOTS:
void zmodemDone(); void zmodemDone();
void zmodemContinue(); void zmodemContinue();
Q_SIGNALS: signals:
void processExited(); void processExited();
void receivedData( const QString& text ); void receivedData( const QString& text );
...@@ -266,15 +264,16 @@ Q_SIGNALS: ...@@ -266,15 +264,16 @@ Q_SIGNALS:
void openUrlRequest(const QString &cwd); void openUrlRequest(const QString &cwd);
void zmodemDetected(Session *); void zmodemDetected(Session *);
void updateSessionConfig(Session *); void updateSessionConfig(Session*);
void resizeSession(Session *session, QSize size); void resizeSession(Session *session, QSize size);
void setSessionEncoding(Session *session, const QString &encoding); void setSessionEncoding(Session *session, const QString &encoding);
private Q_SLOTS: private slots:
void onReceiveBlock( const char* buf, int len ); void onReceiveBlock( const char* buffer, int len );
void monitorTimerDone(); void monitorTimerDone();
void notifySessionState(int state); void notifySessionState(int state);
void onContentSizeChange(int height, int width); void onContentSizeChange(int height, int width);
//automatically detach views from sessions when view is destroyed //automatically detach views from sessions when view is destroyed
void viewDestroyed(QObject* view); void viewDestroyed(QObject* view);
...@@ -284,7 +283,7 @@ private: ...@@ -284,7 +283,7 @@ private:
int _uniqueIdentifier; int _uniqueIdentifier;
Pty* _shellProcess; Pty* _shellProcess;
Emulation* _emulation; Emulation* _emulation;
QList<TerminalDisplay*> _views; QList<TerminalDisplay*> _views;
...@@ -298,11 +297,6 @@ private: ...@@ -298,11 +297,6 @@ private:
bool wantedClose; bool wantedClose;
QTimer* monitorTimer; QTimer* monitorTimer;
//FIXME: using the indices here
// is propably very bad. We should
// use a persistent reference instead.
//
int _fontNo;
int _silenceSeconds; int _silenceSeconds;
QString _title; QString _title;
...@@ -333,7 +327,6 @@ private: ...@@ -333,7 +327,6 @@ private:
// Color/Font Changes by ESC Sequences // Color/Font Changes by ESC Sequences
QColor _modifiedBackground; // as set by: echo -en '\033]11;Color\007 QColor _modifiedBackground; // as set by: echo -en '\033]11;Color\007
int _encoding_no;
QString _type; QString _type;
......
...@@ -170,7 +170,7 @@ void Vt102Emulation::reset() ...@@ -170,7 +170,7 @@ void Vt102Emulation::reset()
//kDebug(1211)<<"Vt102Emulation::reset() reset screen 1"<<endl; //kDebug(1211)<<"Vt102Emulation::reset() reset screen 1"<<endl;
screen[1]->reset(); screen[1]->reset();
//kDebug(1211)<<"Vt102Emulation::reset() setCodec()"<<endl; //kDebug(1211)<<"Vt102Emulation::reset() setCodec()"<<endl;
setCodec(0); setCodec(LocaleCodec);
//kDebug(1211)<<"Vt102Emulation::reset() done"<<endl; //kDebug(1211)<<"Vt102Emulation::reset() done"<<endl;
bufferedUpdate(); bufferedUpdate();