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 class KUrl;
00040
00041 namespace Konsole
00042 {
00043
00044 class Emulation;
00045 class Pty;
00046 class ProcessInfo;
00047 class TerminalDisplay;
00048 class ZModemDialog;
00049
00061 class KDE_EXPORT Session : public QObject
00062 {
00063 Q_OBJECT
00064
00065 public:
00066 Q_PROPERTY(QString name READ nameTitle)
00067 Q_PROPERTY(int processId READ processId)
00068 Q_PROPERTY(QString keyBindings READ keyBindings WRITE setKeyBindings)
00069 Q_PROPERTY(QSize size READ size WRITE setSize)
00070
00082 explicit Session(QObject* parent = 0);
00083 ~Session();
00084
00095 void openTeletype(int masterFd);
00096
00101 bool isRunning() const;
00102
00113 void addView(TerminalDisplay* widget);
00121 void removeView(TerminalDisplay* widget);
00122
00126 QList<TerminalDisplay*> views() const;
00127
00132 Emulation* emulation() const;
00133
00138 QStringList environment() const;
00144 void setEnvironment(const QStringList& environment);
00145
00147 int sessionId() const;
00148
00153 QString userTitle() const;
00154
00159 enum TabTitleContext
00160 {
00162 LocalTabTitle,
00167 RemoteTabTitle
00168 };
00178 void setTabTitleFormat(TabTitleContext context , const QString& format);
00180 QString tabTitleFormat(TabTitleContext context) const;
00181
00182
00184 QStringList arguments() const;
00186 QString program() const;
00187
00192 void setArguments(const QStringList& arguments);
00194 void setProgram(const QString& program);
00195
00197 QString initialWorkingDirectory() { return _initialWorkingDir; }
00198
00203 void setInitialWorkingDirectory( const QString& dir );
00204
00208 QString currentWorkingDirectory();
00209
00218 void setHistoryType(const HistoryType& type);
00222 const HistoryType& historyType() const;
00226 void clearHistory();
00227
00234 void setMonitorActivity(bool);
00236 bool isMonitorActivity() const;
00237
00245 void setMonitorSilence(bool);
00250 bool isMonitorSilence() const;
00252 void setMonitorSilenceSeconds(int seconds);
00253
00263 void setKeyBindings(const QString& id);
00265 QString keyBindings() const;
00266
00270 enum TitleRole
00271 {
00273 NameRole,
00275 DisplayedTitleRole
00276 };
00277
00279 void setTitle(TitleRole role , const QString& title);
00281 QString title(TitleRole role) const;
00283 QString nameTitle() const { return title(Session::NameRole); }
00285 QString getDynamicTitle();
00286
00288 void setIconName(const QString& iconName);
00290 QString iconName() const;
00291
00293 KUrl getUrl();
00294
00296 void setIconText(const QString& iconText);
00298 QString iconText() const;
00299
00304 void setAddToUtmp(bool);
00305
00310 void setAutoClose(bool b) { _autoClose = b; }
00311
00316 void setFlowControlEnabled(bool enabled);
00317
00319 bool flowControlEnabled() const;
00320
00324 void sendText(const QString& text) const;
00325
00330 int processId() const;
00331
00333 bool isChildActive();
00334
00336 QString childName();
00337
00339 QSize size();
00346 void setSize(const QSize& size);
00347
00349 void setCodec(QTextCodec* codec);
00350
00359 void setDarkBackground(bool darkBackground);
00364 bool hasDarkBackground() const;
00365
00371 void refresh();
00372
00373 void startZModem(const QString &rz, const QString &dir, const QStringList &list);
00374 void cancelZModem();
00375 bool isZModemBusy() { return _zmodemBusy; }
00376
00381 enum UserTitleChange
00382 {
00383 IconNameAndWindowTitle = 0,
00384 IconName = 1,
00385 WindowTitle = 2,
00386 TextColor = 10,
00387 BackgroundColor = 11,
00388 SessionName = 30,
00389 ProfileChange = 50
00390 };
00391
00392
00393 void saveSession(KConfigGroup& group);
00394 void restoreSession(KConfigGroup& group);
00395
00396 public slots:
00397
00403 void run();
00404
00412 void close();
00413
00422 void setUserTitle( int what , const QString &caption );
00423
00424 signals:
00425
00427 void started();
00428
00432 void finished();
00433
00437 void receivedData( const QString& text );
00438
00440 void titleChanged();
00441
00448 void stateChanged(int state);
00449
00451 void bellRequest( const QString& message );
00452
00459 void changeTabTextColorRequest(int);
00460
00465 void changeBackgroundColorRequest(const QColor&);
00470 void changeForegroundColorRequest(const QColor&);
00471
00473 void openUrlRequest(const QString& url);
00474
00476 void zmodemDetected();
00477
00484 void resizeRequest(const QSize& size);
00485
00492 void profileChangeCommandReceived(const QString& text);
00493
00499 void flowControlEnabledChanged(bool enabled);
00500
00501 private slots:
00502 void done(int);
00503
00504 void fireZModemDetected();
00505
00506 void onReceiveBlock( const char* buffer, int len );
00507 void monitorTimerDone();
00508
00509 void onViewSizeChange(int height, int width);
00510
00511 void activityStateSet(int);
00512
00513
00514 void viewDestroyed(QObject* view);
00515
00516 void zmodemReadStatus();
00517 void zmodemReadAndSendBlock();
00518 void zmodemRcvBlock(const char *data, int len);
00519 void zmodemFinished();
00520
00521 void updateFlowControlState(bool suspended);
00522 void updateWindowSize(int lines, int columns);
00523 private:
00524
00525 void updateTerminalSize();
00526 WId windowId() const;
00527 bool kill(int signal);
00528
00529
00530
00531 void terminalWarning(const QString& message);
00532
00533
00534 QString checkProgram(const QString& program) const;
00535 ProcessInfo* getProcessInfo();
00536 void updateSessionProcessInfo();
00537 bool updateForegroundProcessInfo();
00538 ProcessInfo* updateWorkingDirectory();
00539
00540 int _uniqueIdentifier;
00541
00542 Pty* _shellProcess;
00543 Emulation* _emulation;
00544
00545 QList<TerminalDisplay*> _views;
00546
00547 bool _monitorActivity;
00548 bool _monitorSilence;
00549 bool _notifiedActivity;
00550 bool _masterMode;
00551 bool _autoClose;
00552 bool _wantedClose;
00553 QTimer* _monitorTimer;
00554
00555 int _silenceSeconds;
00556
00557 QString _nameTitle;
00558 QString _displayTitle;
00559 QString _userTitle;
00560
00561 QString _localTabTitleFormat;
00562 QString _remoteTabTitleFormat;
00563
00564 QString _iconName;
00565 QString _iconText;
00566 bool _addToUtmp;
00567 bool _flowControl;
00568 bool _fullScripting;
00569
00570 QString _program;
00571 QStringList _arguments;
00572
00573 QStringList _environment;
00574 int _sessionId;
00575
00576 QString _initialWorkingDir;
00577 QString _currentWorkingDir;
00578
00579 ProcessInfo* _sessionProcessInfo;
00580 ProcessInfo* _foregroundProcessInfo;
00581 int _foregroundPid;
00582
00583
00584 bool _zmodemBusy;
00585 KProcess* _zmodemProc;
00586 ZModemDialog* _zmodemProgress;
00587
00588
00589
00590 QColor _modifiedBackground;
00591
00592 QString _profileKey;
00593
00594 bool _hasDarkBackground;
00595
00596 static int lastSessionId;
00597
00598 };
00599
00606 class SessionGroup : public QObject
00607 {
00608 Q_OBJECT
00609
00610 public:
00612 SessionGroup(QObject* parent);
00614 ~SessionGroup();
00615
00617 void addSession( Session* session );
00619 void removeSession( Session* session );
00620
00622 QList<Session*> sessions() const;
00623
00632 void setMasterStatus( Session* session , bool master );
00634 bool masterStatus( Session* session ) const;
00635
00640 enum MasterMode
00641 {
00646 CopyInputToAll = 1
00647 };
00648
00655 void setMasterMode( int mode );
00660 int masterMode() const;
00661
00662 private slots:
00663 void sessionFinished();
00664
00665 private:
00666 void connectPair(Session* master , Session* other);
00667 void disconnectPair(Session* master , Session* other);
00668 void connectAll(bool connect);
00669 QList<Session*> masters() const;
00670
00671
00672 QHash<Session*,bool> _sessions;
00673
00674 int _masterMode;
00675 };
00676
00677 }
00678
00679 #endif
00680
00681
00682
00683
00684
00685
00686
00687
00688