File indexing completed on 2025-01-19 04:23:28
0001 /* 0002 * This file is part of Konsole QML plugin, 0003 * which is a terminal emulator from KDE. 0004 * 0005 * Copyright 2013 by Dmitry Zagnoyko <hiroshidi@gmail.com> 0006 * 0007 * This program is free software; you can redistribute it and/or modify 0008 * it under the terms of the GNU General Public License as published by 0009 * the Free Software Foundation; either version 2 of the License, or 0010 * (at your option) any later version. 0011 * 0012 * This program is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU General Public License 0018 * along with this program; if not, write to the Free Software 0019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0020 * 02110-1301 USA. 0021 */ 0022 0023 #ifndef KSESSION_H 0024 #define KSESSION_H 0025 0026 #include <QObject> 0027 0028 // Konsole 0029 #include "Session.h" 0030 //#include "TerminalDisplay.h" 0031 0032 using namespace Konsole; 0033 0034 class KSession : public QObject 0035 { 0036 Q_OBJECT 0037 Q_PROPERTY(QString kbScheme READ getKeyBindings WRITE setKeyBindings NOTIFY changedKeyBindings) 0038 Q_PROPERTY(QString initialWorkingDirectory READ getInitialWorkingDirectory WRITE setInitialWorkingDirectory NOTIFY initialWorkingDirectoryChanged) 0039 Q_PROPERTY(QString title READ getTitle WRITE setTitle NOTIFY titleChanged) 0040 Q_PROPERTY(QString shellProgram WRITE setShellProgram) 0041 Q_PROPERTY(QStringList shellProgramArgs WRITE setArgs) 0042 Q_PROPERTY(QString history READ getHistory) 0043 Q_PROPERTY(bool hasActiveProcess READ hasActiveProcess NOTIFY hasActiveProcessChanged) 0044 Q_PROPERTY(QString foregroundProcessName READ foregroundProcessName NOTIFY foregroundProcessNameChanged) 0045 Q_PROPERTY(QString currentDir READ currentDir NOTIFY currentDirChanged) 0046 Q_PROPERTY(int historySize READ historySize WRITE setHistorySize NOTIFY historySizeChanged) 0047 Q_PROPERTY(bool monitorSilence READ monitorSilence WRITE setMonitorSilence NOTIFY monitorSilenceChanged) 0048 0049 public: 0050 KSession(QObject *parent = 0); 0051 ~KSession(); 0052 0053 public: 0054 //bool setup(); 0055 void addView(TerminalDisplay *display); 0056 void removeView(TerminalDisplay *display); 0057 0058 int getRandomSeed(); 0059 QString getKeyBindings(); 0060 0061 //look-n-feel, if you don`t like defaults 0062 0063 //environment 0064 void setEnvironment(const QStringList & environment); 0065 0066 //Initial working directory 0067 void setInitialWorkingDirectory(const QString & dir); 0068 QString getInitialWorkingDirectory(); 0069 0070 //Text codec, default is UTF-8 0071 void setTextCodec(QTextCodec * codec); 0072 0073 // History size for scrolling 0074 void setHistorySize(int lines); //infinite if lines < 0 0075 int historySize() const; 0076 0077 QString getHistory() const; 0078 0079 // Sets whether flow control is enabled 0080 void setFlowControlEnabled(bool enabled); 0081 0082 // Returns whether flow control is enabled 0083 bool flowControlEnabled(void); 0084 0085 /** 0086 * Sets whether the flow control warning box should be shown 0087 * when the flow control stop key (Ctrl+S) is pressed. 0088 */ 0089 //void setFlowControlWarningEnabled(bool enabled); 0090 0091 /*! Get all available keyboard bindings 0092 */ 0093 static QStringList availableKeyBindings(); 0094 0095 //! Return current key bindings 0096 QString keyBindings(); 0097 0098 QString getTitle(); 0099 0100 /** 0101 * Returns \c true if the session has an active subprocess running in it 0102 * spawned from the initial shell. 0103 */ 0104 bool hasActiveProcess() const; 0105 0106 /** 0107 * Returns the name of the terminal's foreground process. 0108 */ 0109 QString foregroundProcessName(); 0110 0111 /** 0112 * Returns the current working directory of the process. 0113 */ 0114 QString currentDir(); 0115 0116 void setMonitorSilence(bool value); 0117 bool monitorSilence() const; 0118 0119 Q_SIGNALS: 0120 void started(); 0121 void finished(); 0122 void copyAvailable(bool); 0123 0124 void termGetFocus(); 0125 void termLostFocus(); 0126 0127 void termKeyPressed(QKeyEvent *); 0128 0129 void changedKeyBindings(QString kb); 0130 0131 void titleChanged(); 0132 0133 void historySizeChanged(); 0134 0135 void initialWorkingDirectoryChanged(); 0136 0137 void matchFound(int startColumn, int startLine, int endColumn, int endLine); 0138 void noMatchFound(); 0139 void hasActiveProcessChanged(); 0140 void foregroundProcessNameChanged(); 0141 0142 void processHasSilent(bool value); 0143 void bellRequest(QString message); 0144 void monitorSilenceChanged(); 0145 void currentDirChanged(); 0146 0147 public Q_SLOTS: 0148 /*! Set named key binding for given widget 0149 */ 0150 void setKeyBindings(const QString & kb); 0151 void setTitle(QString name); 0152 0153 void startShellProgram(); 0154 0155 bool sendSignal(int signal); 0156 0157 // Shell program, default is /bin/bash 0158 void setShellProgram(const QString & progname); 0159 0160 // Shell program args, default is none 0161 void setArgs(const QStringList &args); 0162 0163 int getShellPID(); 0164 void changeDir(const QString & dir); 0165 0166 // Send some text to terminal 0167 void sendText(QString text); 0168 // Send some text to terminal 0169 void sendKey(int rep, int key, int mod) const; 0170 0171 void clearScreen(); 0172 0173 // Search history 0174 void search(const QString ®exp, int startLine = 0, int startColumn = 0, bool forwards = true ); 0175 0176 protected Q_SLOTS: 0177 void sessionFinished(); 0178 void selectionChanged(bool textSelected); 0179 0180 private Q_SLOTS: 0181 Session* createSession(QString name); 0182 //Konsole::KTerminalDisplay* createTerminalDisplay(Konsole::Session *session, QQuickItem* parent); 0183 0184 0185 private: 0186 //Konsole::KTerminalDisplay *m_terminalDisplay; 0187 QString _initialWorkingDirectory; 0188 Session *m_session; 0189 QString m_processName; 0190 0191 }; 0192 0193 #endif // KSESSION_H