Mercurial > octave-libgccjit
view libqterminal/SessionModel.cpp @ 15645:f3ec6627e00d
removed obsolete code.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Wed, 25 Jan 2012 02:21:43 +0100 |
parents | 5c841498bf30 |
children | f570d3baa6fb |
line wrap: on
line source
/* This file is part of Konsole Copyright (C) 2006-2007 by Robert Knight <robertknight@gmail.com> Copyright (C) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ // Own #include "SessionModel.h" // Standard #include <assert.h> #include <stdlib.h> // Qt #include <QtGui/QApplication> #include <QtCore/QByteRef> #include <QtCore/QDir> #include <QtCore/QFile> #include <QtCore/QRegExp> #include <QtCore/QStringList> #include <QtCore> #include "SessionView.h" #include "ShellCommand.h" #include "Vt102Emulation.h" int SessionModel::lastSessionId = 0; SessionModel::SessionModel(KPty *kpty) : _shellProcess(0) , _emulation(0) , _monitorActivity(false) , _monitorSilence(false) , _notifiedActivity(false) , _autoClose(true) , _wantedClose(false) , _silenceSeconds(10) , _addToUtmp(false) , _flowControl(true) , _fullScripting(false) , _sessionId(0) , _hasDarkBackground(false) { _kpty = kpty; //create emulation backend _emulation = new Vt102Emulation(); connect( _emulation, SIGNAL( titleChanged( int, const QString & ) ), this, SLOT( setUserTitle( int, const QString & ) ) ); connect( _emulation, SIGNAL( stateSet(int) ), this, SLOT( activityStateSet(int) ) ); // connect( _emulation, SIGNAL( zmodemDetected() ), this , // SLOT( fireZModemDetected() ) ); connect( _emulation, SIGNAL( changeTabTextColorRequest( int ) ), this, SIGNAL( changeTabTextColorRequest( int ) ) ); connect( _emulation, SIGNAL(profileChangeCommandReceived(const QString&)), this, SIGNAL( profileChangeCommandReceived(const QString&)) ); // TODO // connect( _emulation,SIGNAL(imageSizeChanged(int,int)) , this , // SLOT(onEmulationSizeChange(int,int)) ); //connect teletype to emulation backend //_shellProcess->setUtf8Mode(_emulation->utf8()); //connect( _shellProcess,SIGNAL(receivedData(const char*,int)),this, // SLOT(onReceiveBlock(const char*,int)) ); _selfListener = new SelfListener(kpty->masterFd()); _selfListener->start(); connect( _selfListener, SIGNAL(recvData(const char*,int)), this, SLOT(onReceiveBlock(const char*,int)), Qt::BlockingQueuedConnection); connect( _emulation, SIGNAL(sendData(const char*,int)) ,this,SLOT(sendData(const char*,int))); //connect( _emulation,SIGNAL(lockPtyRequest(bool)),_shellProcess,SLOT(lockPty(bool)) ); //connect( _emulation,SIGNAL(useUtf8Request(bool)),_shellProcess,SLOT(setUtf8Mode(bool)) ); //connect( _shellProcess,SIGNAL(done(int)), this, SLOT(done(int)) ); //setup timer for monitoring session activity _monitorTimer = new QTimer(this); _monitorTimer->setSingleShot(true); connect(_monitorTimer, SIGNAL(timeout()), this, SLOT(monitorTimerDone())); } void SessionModel::setDarkBackground(bool darkBackground) { _hasDarkBackground = darkBackground; } bool SessionModel::hasDarkBackground() const { return _hasDarkBackground; } bool SessionModel::isRunning() const { return true; //_shellProcess->isRunning(); } void SessionModel::setCodec(QTextCodec* codec) { emulation()->setCodec(codec); } void SessionModel::setProgram(const QString& program) { _program = ShellCommand::expand(program); } void SessionModel::setInitialWorkingDirectory(const QString& dir) { _initialWorkingDir = ShellCommand::expand(dir); } void SessionModel::setArguments(const QStringList& arguments) { _arguments = ShellCommand::expand(arguments); } QList<SessionView*> SessionModel::views() const { return _views; } void SessionModel::addView(SessionView* widget) { Q_ASSERT( !_views.contains(widget) ); _views.append(widget); if ( _emulation != 0 ) { // connect emulation - view signals and slots connect( widget , SIGNAL(keyPressedSignal(QKeyEvent*)) , _emulation , SLOT(sendKeyEvent(QKeyEvent*)) ); connect( widget , SIGNAL(mouseSignal(int,int,int,int)) , _emulation , SLOT(sendMouseEvent(int,int,int,int)) ); connect( widget , SIGNAL(sendStringToEmu(const char*)) , _emulation , SLOT(sendString(const char*)) ); // allow emulation to notify view when the foreground process // indicates whether or not it is interested in mouse signals connect( _emulation , SIGNAL(programUsesMouseChanged(bool)) , widget , SLOT(setUsesMouse(bool)) ); widget->setUsesMouse( _emulation->programUsesMouse() ); widget->setScreenWindow(_emulation->createWindow()); } //connect view signals and slots QObject::connect( widget ,SIGNAL(changedContentSizeSignal(int,int)),this, SLOT(onViewSizeChange(int,int))); QObject::connect( widget ,SIGNAL(destroyed(QObject*)) , this , SLOT(viewDestroyed(QObject*)) ); //slot for close //QObject::connect(this, SIGNAL(finished()), widget, SLOT(close())); } void SessionModel::viewDestroyed(QObject* view) { SessionView* display = (SessionView*)view; Q_ASSERT( _views.contains(display) ); removeView(display); } void SessionModel::sendData(const char *buf, int len) { ssize_t bytesWritten = ::write(_kpty->masterFd(), buf, len); (void)bytesWritten; } void SessionModel::removeView(SessionView* widget) { _views.removeAll(widget); disconnect(widget,0,this,0); if ( _emulation != 0 ) { // disconnect // - key presses signals from widget // - mouse activity signals from widget // - string sending signals from widget // // ... and any other signals connected in addView() disconnect( widget, 0, _emulation, 0); // disconnect state change signals emitted by emulation disconnect( _emulation , 0 , widget , 0); } // close the session automatically when the last view is removed if ( _views.count() == 0 ) { close(); } } void SessionModel::run() { emit started(); } void SessionModel::setUserTitle( int what, const QString &caption ) { //set to true if anything is actually changed (eg. old _nameTitle != new _nameTitle ) bool modified = false; // (btw: what=0 changes _userTitle and icon, what=1 only icon, what=2 only _nameTitle if ((what == 0) || (what == 2)) { if ( _userTitle != caption ) { _userTitle = caption; modified = true; } } if ((what == 0) || (what == 1)) { if ( _iconText != caption ) { _iconText = caption; modified = true; } } if (what == 11) { QString colorString = caption.section(';',0,0); qDebug() << __FILE__ << __LINE__ << ": setting background colour to " << colorString; QColor backColor = QColor(colorString); if (backColor.isValid()){// change color via \033]11;Color\007 if (backColor != _modifiedBackground) { _modifiedBackground = 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 changeBackgroundColorRequest(backColor); } } } if (what == 30) { if ( _nameTitle != caption ) { setTitle(SessionModel::NameRole,caption); return; } } if (what == 31) { QString cwd=caption; cwd=cwd.replace( QRegExp("^~"), QDir::homePath() ); emit openUrlRequest(cwd); } // change icon via \033]32;Icon\007 if (what == 32) { if ( _iconName != caption ) { _iconName = caption; modified = true; } } if (what == 50) { emit profileChangeCommandReceived(caption); return; } if ( modified ) emit titleChanged(); } QString SessionModel::userTitle() const { return _userTitle; } void SessionModel::setTabTitleFormat(TabTitleContext context , const QString& format) { if ( context == LocalTabTitle ) _localTabTitleFormat = format; else if ( context == RemoteTabTitle ) _remoteTabTitleFormat = format; } QString SessionModel::tabTitleFormat(TabTitleContext context) const { if ( context == LocalTabTitle ) return _localTabTitleFormat; else if ( context == RemoteTabTitle ) return _remoteTabTitleFormat; return QString(); } void SessionModel::monitorTimerDone() { //FIXME: The idea here is that the notification popup will appear to tell the user than output from //the terminal has stopped and the popup will disappear when the user activates the session. // //This breaks with the addition of multiple views of a session. The popup should disappear //when any of the views of the session becomes active //FIXME: Make message text for this notification and the activity notification more descriptive. if (_monitorSilence) { // KNotification::event("Silence", ("Silence in session '%1'", _nameTitle), QPixmap(), // QApplication::activeWindow(), // KNotification::CloseWhenWidgetActivated); emit stateChanged(NOTIFYSILENCE); } else { emit stateChanged(NOTIFYNORMAL); } _notifiedActivity=false; } void SessionModel::activityStateSet(int state) { if (state==NOTIFYBELL) { QString s; s.sprintf("Bell in session '%s'",_nameTitle.toAscii().data()); emit bellRequest( s ); } else if (state==NOTIFYACTIVITY) { if (_monitorSilence) { _monitorTimer->start(_silenceSeconds*1000); } if ( _monitorActivity ) { //FIXME: See comments in Session::monitorTimerDone() if (!_notifiedActivity) { // KNotification::event("Activity", ("Activity in session '%1'", _nameTitle), QPixmap(), // QApplication::activeWindow(), // KNotification::CloseWhenWidgetActivated); _notifiedActivity=true; } } } if ( state==NOTIFYACTIVITY && !_monitorActivity ) state = NOTIFYNORMAL; if ( state==NOTIFYSILENCE && !_monitorSilence ) state = NOTIFYNORMAL; emit stateChanged(state); } void SessionModel::onViewSizeChange(int /*height*/, int /*width*/) { updateTerminalSize(); } void SessionModel::onEmulationSizeChange(int lines , int columns) { setSize( QSize(lines,columns) ); } void SessionModel::updateTerminalSize() { QListIterator<SessionView*> viewIter(_views); int minLines = -1; int minColumns = -1; // minimum number of lines and columns that views require for // their size to be taken into consideration ( to avoid problems // with new view widgets which haven't yet been set to their correct size ) const int VIEW_LINES_THRESHOLD = 2; const int VIEW_COLUMNS_THRESHOLD = 2; //select largest number of lines and columns that will fit in all visible views while ( viewIter.hasNext() ) { SessionView* view = viewIter.next(); if ( view->isHidden() == false && view->lines() >= VIEW_LINES_THRESHOLD && view->columns() >= VIEW_COLUMNS_THRESHOLD ) { minLines = (minLines == -1) ? view->lines() : qMin( minLines , view->lines() ); minColumns = (minColumns == -1) ? view->columns() : qMin( minColumns , view->columns() ); } } // backend emulation must have a _terminal of at least 1 column x 1 line in size if ( minLines > 0 && minColumns > 0 ) { _emulation->setImageSize( minLines , minColumns ); //_shellProcess->setWindowSize( minLines , minColumns ); } } void SessionModel::refresh() { } void SessionModel::close() { _autoClose = true; _wantedClose = true; } void SessionModel::sendText(const QString &text) const { _emulation->sendText(text); } SessionModel::~SessionModel() { delete _emulation; } void SessionModel::setProfileKey(const QString& key) { _profileKey = key; emit profileChanged(key); } QString SessionModel::profileKey() const { return _profileKey; } void SessionModel::done(int) { emit finished(); } Emulation* SessionModel::emulation() const { return _emulation; } QString SessionModel::keyBindings() const { return _emulation->keyBindings(); } QStringList SessionModel::environment() const { return _environment; } void SessionModel::setEnvironment(const QStringList& environment) { _environment = environment; } int SessionModel::sessionId() const { return _sessionId; } void SessionModel::setKeyBindings(const QString &id) { _emulation->setKeyBindings(id); } void SessionModel::setTitle(TitleRole role , const QString& newTitle) { if ( title(role) != newTitle ) { if ( role == NameRole ) _nameTitle = newTitle; else if ( role == DisplayedTitleRole ) _displayTitle = newTitle; emit titleChanged(); } } QString SessionModel::title(TitleRole role) const { if ( role == NameRole ) return _nameTitle; else if ( role == DisplayedTitleRole ) return _displayTitle; else return QString(); } void SessionModel::setIconName(const QString& iconName) { if ( iconName != _iconName ) { _iconName = iconName; emit titleChanged(); } } void SessionModel::setIconText(const QString& iconText) { _iconText = iconText; } QString SessionModel::iconName() const { return _iconName; } QString SessionModel::iconText() const { return _iconText; } void SessionModel::setHistoryType(const HistoryType &hType) { _emulation->setHistory(hType); } const HistoryType& SessionModel::historyType() const { return _emulation->history(); } void SessionModel::clearHistory() { _emulation->clearHistory(); } QStringList SessionModel::arguments() const { return _arguments; } QString SessionModel::program() const { return _program; } // unused currently bool SessionModel::isMonitorActivity() const { return _monitorActivity; } // unused currently bool SessionModel::isMonitorSilence() const { return _monitorSilence; } void SessionModel::setMonitorActivity(bool _monitor) { _monitorActivity=_monitor; _notifiedActivity=false; activityStateSet(NOTIFYNORMAL); } void SessionModel::setMonitorSilence(bool _monitor) { if (_monitorSilence==_monitor) return; _monitorSilence=_monitor; if (_monitorSilence) { _monitorTimer->start(_silenceSeconds*1000); } else _monitorTimer->stop(); activityStateSet(NOTIFYNORMAL); } void SessionModel::setMonitorSilenceSeconds(int seconds) { _silenceSeconds=seconds; if (_monitorSilence) { _monitorTimer->start(_silenceSeconds*1000); } } void SessionModel::setAddToUtmp(bool set) { _addToUtmp = set; } void SessionModel::setFlowControlEnabled(bool enabled) { if (_flowControl == enabled) return; _flowControl = enabled; //if (_shellProcess) // _shellProcess->setXonXoff(_flowControl); emit flowControlEnabledChanged(enabled); } bool SessionModel::flowControlEnabled() const { return _flowControl; } void SessionModel::onReceiveBlock( const char* buf, int len ) { _emulation->receiveData( buf, len ); emit receivedData( QString::fromLatin1( buf, len ) ); } QSize SessionModel::size() { return _emulation->imageSize(); } void SessionModel::setSize(const QSize& size) { if ((size.width() <= 1) || (size.height() <= 1)) return; emit resizeRequest(size); }