Konsole
Session.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef SESSION_H
00024 #define SESSION_H
00025
00026
00027 #include <QtCore/QStringList>
00028 #include <QtCore/QByteRef>
00029
00030
00031 #include <KApplication>
00032 #include <KMainWindow>
00033 #include <kdemacros.h>
00034
00035
00036 #include "History.h"
00037
00038 class KProcess;
00039
00040 namespace Konsole
00041 {
00042
00043 class Emulation;
00044 class Pty;
00045 class TerminalDisplay;
00046 class ZModemDialog;
00047
00059 class KDE_EXPORT Session : public QObject
00060 {
00061 Q_OBJECT
00062
00063 public:
00064 Q_PROPERTY(QString name READ nameTitle)
00065 Q_PROPERTY(int processId READ processId)
00066 Q_PROPERTY(QString keyBindings READ keyBindings WRITE setKeyBindings)
00067 Q_PROPERTY(QSize size READ size WRITE setSize)
00068
00080 explicit Session(QObject* parent = 0);
00081 ~Session();
00082
00093 void openTeletype(int masterFd);
00094
00099 bool isRunning() const;
00100
00111 void addView(TerminalDisplay* widget);
00119 void removeView(TerminalDisplay* widget);
00120
00124 QList<TerminalDisplay*> views() const;
00125
00130 Emulation* emulation() const;
00131
00136 QStringList environment() const;
00142 void setEnvironment(const QStringList& environment);
00143
00145 int sessionId() const;
00146
00151 QString userTitle() const;
00152
00157 enum TabTitleContext
00158 {
00160 LocalTabTitle,
00165 RemoteTabTitle
00166 };
00176 void setTabTitleFormat(TabTitleContext context , const QString& format);
00178 QString tabTitleFormat(TabTitleContext context) const;
00179
00180
00182 QStringList arguments() const;
00184 QString program() const;
00185
00190 void setArguments(const QStringList& arguments);
00192 void setProgram(const QString& program);
00193
00195 QString initialWorkingDirectory() { return _initialWorkingDir; }
00196
00201 void setInitialWorkingDirectory( const QString& dir );
00202
00211 void setHistoryType(const HistoryType& type);
00215 const HistoryType& historyType() const;
00219 void clearHistory();
00220
00227 void setMonitorActivity(bool);
00229 bool isMonitorActivity() const;
00230
00238 void setMonitorSilence(bool);
00243 bool isMonitorSilence() const;
00245 void setMonitorSilenceSeconds(int seconds);
00246
00256 void setKeyBindings(const QString& id);
00258 QString keyBindings() const;
00259
00263 enum TitleRole
00264 {
00266 NameRole,
00268 DisplayedTitleRole
00269 };
00270
00272 void setTitle(TitleRole role , const QString& title);
00274 QString title(TitleRole role) const;
00276 QString nameTitle() const { return title(Session::NameRole); }
00277
00279 void setIconName(const QString& iconName);
00281 QString iconName() const;
00282
00284 void setIconText(const QString& iconText);
00286 QString iconText() const;
00287
00292 void setAddToUtmp(bool);
00293
00298 void setAutoClose(bool b) { _autoClose = b; }
00299
00304 void setFlowControlEnabled(bool enabled);
00305
00307 bool flowControlEnabled() const;
00308
00312 void sendText(const QString& text) const;
00313
00318 int processId() const;
00319
00325 int foregroundProcessId() const;
00326
00328 QSize size();
00335 void setSize(const QSize& size);
00336
00338 void setCodec(QTextCodec* codec);
00339
00348 void setDarkBackground(bool darkBackground);
00353 bool hasDarkBackground() const;
00354
00360 void refresh();
00361
00362 void startZModem(const QString &rz, const QString &dir, const QStringList &list);
00363 void cancelZModem();
00364 bool isZModemBusy() { return _zmodemBusy; }
00365
00370 enum UserTitleChange
00371 {
00372 IconNameAndWindowTitle = 0,
00373 IconName = 1,
00374 WindowTitle = 2,
00375 TextColor = 10,
00376 BackgroundColor = 11,
00377 SessionName = 30,
00378 ProfileChange = 50
00379 };
00380
00381 public slots:
00382
00388 void run();
00389
00395 void close();
00396
00405 void setUserTitle( int what , const QString &caption );
00406
00407 signals:
00408
00410 void started();
00411
00415 void finished();
00416
00420 void receivedData( const QString& text );
00421
00423 void titleChanged();
00424
00431 void stateChanged(int state);
00432
00434 void bellRequest( const QString& message );
00435
00442 void changeTabTextColorRequest(int);
00443
00448 void changeBackgroundColorRequest(const QColor&);
00453 void changeForegroundColorRequest(const QColor&);
00454
00456 void openUrlRequest(const QString& url);
00457
00459 void zmodemDetected();
00460
00467 void resizeRequest(const QSize& size);
00468
00475 void profileChangeCommandReceived(const QString& text);
00476
00482 void flowControlEnabledChanged(bool enabled);
00483
00484 private slots:
00485 void done(int);
00486
00487 void fireZModemDetected();
00488
00489 void onReceiveBlock( const char* buffer, int len );
00490 void monitorTimerDone();
00491
00492 void onViewSizeChange(int height, int width);
00493
00494 void activityStateSet(int);
00495
00496
00497 void viewDestroyed(QObject* view);
00498
00499 void zmodemReadStatus();
00500 void zmodemReadAndSendBlock();
00501 void zmodemRcvBlock(const char *data, int len);
00502 void zmodemFinished();
00503
00504 void updateFlowControlState(bool suspended);
00505 void updateWindowSize(int lines, int columns);
00506 private:
00507
00508 void updateTerminalSize();
00509 WId windowId() const;
00510 bool kill(int signal);
00511
00512
00513
00514 void terminalWarning(const QString& message);
00515
00516
00517 QString checkProgram(const QString& program) const;
00518
00519 int _uniqueIdentifier;
00520
00521 Pty* _shellProcess;
00522 Emulation* _emulation;
00523
00524 QList<TerminalDisplay*> _views;
00525
00526 bool _monitorActivity;
00527 bool _monitorSilence;
00528 bool _notifiedActivity;
00529 bool _masterMode;
00530 bool _autoClose;
00531 bool _wantedClose;
00532 QTimer* _monitorTimer;
00533
00534 int _silenceSeconds;
00535
00536 QString _nameTitle;
00537 QString _displayTitle;
00538 QString _userTitle;
00539
00540 QString _localTabTitleFormat;
00541 QString _remoteTabTitleFormat;
00542
00543 QString _iconName;
00544 QString _iconText;
00545 bool _addToUtmp;
00546 bool _flowControl;
00547 bool _fullScripting;
00548
00549 QString _program;
00550 QStringList _arguments;
00551
00552 QStringList _environment;
00553 int _sessionId;
00554
00555 QString _initialWorkingDir;
00556
00557
00558 bool _zmodemBusy;
00559 KProcess* _zmodemProc;
00560 ZModemDialog* _zmodemProgress;
00561
00562
00563
00564 QColor _modifiedBackground;
00565
00566 QString _profileKey;
00567
00568 bool _hasDarkBackground;
00569
00570 static int lastSessionId;
00571
00572 };
00573
00580 class SessionGroup : public QObject
00581 {
00582 Q_OBJECT
00583
00584 public:
00586 SessionGroup(QObject* parent);
00588 ~SessionGroup();
00589
00591 void addSession( Session* session );
00593 void removeSession( Session* session );
00594
00596 QList<Session*> sessions() const;
00597
00606 void setMasterStatus( Session* session , bool master );
00608 bool masterStatus( Session* session ) const;
00609
00614 enum MasterMode
00615 {
00620 CopyInputToAll = 1
00621 };
00622
00629 void setMasterMode( int mode );
00634 int masterMode() const;
00635
00636 private slots:
00637 void sessionFinished();
00638
00639 private:
00640 void connectPair(Session* master , Session* other);
00641 void disconnectPair(Session* master , Session* other);
00642 void connectAll(bool connect);
00643 QList<Session*> masters() const;
00644
00645
00646 QHash<Session*,bool> _sessions;
00647
00648 int _masterMode;
00649 };
00650
00651 }
00652
00653 #endif