2
This file is part of Konsole QML plugin,
3
which is a terminal emulator from KDE.
5
Copyright 2013 by Dmitry Zagnoyko <hiroshidi@gmail.com>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30
#include "KeyboardTranslator.h"
31
#include "TerminalDisplay.h"
34
KSession::KSession(QObject *parent) :
35
QObject(parent), m_session(createSession("KSession"))
37
connect(m_session, SIGNAL(finished()), this, SLOT(sessionFinished()));
46
m_session->disconnect();
51
void KSession::setTitle(QString name)
53
m_session->setTitle(Session::NameRole, name);
57
Session *KSession::createSession(QString name)
59
Session *session = new Session();
61
session->setTitle(Session::NameRole, name);
63
/* Thats a freaking bad idea!!!!
64
* /bin/bash is not there on every system
65
* better set it to the current $SHELL
66
* Maybe you can also make a list available and then let the widget-owner decide what to use.
67
* By setting it to $SHELL right away we actually make the first filecheck obsolete.
68
* But as iam not sure if you want to do anything else ill just let both checks in and set this to $SHELL anyway.
70
session->setProgram("/bin/bash");
72
//session->setProgram(getenv("SHELL"));
75
session->setArguments(args);
76
session->setAutoClose(true);
78
session->setCodec(QTextCodec::codecForName("UTF-8"));
80
session->setFlowControlEnabled(true);
81
session->setHistoryType(HistoryTypeBuffer(1000));
83
session->setDarkBackground(true);
85
session->setKeyBindings("");
90
/////////////////////////////////////////////////////////////////////////////////////
91
/////////////////////////////////////////////////////////////////////////////////////
94
int KSession::getRandomSeed()
96
return m_session->sessionId() * 31;
99
void KSession::addView(KTerminalDisplay *displa)
101
m_session->addView(displa);
104
void KSession::sessionFinished()
109
void KSession::selectionChanged(bool textSelected)
111
Q_UNUSED(textSelected)
114
void KSession::startShellProgram()
116
if ( m_session->isRunning() ) {
123
int KSession::getShellPID()
125
return m_session->processId();
128
void KSession::changeDir(const QString &dir)
131
this is a very hackish way of trying to determine if the shell is in
132
the foreground before attempting to change the directory. It may not
133
be portable to anything other than Linux.
136
strCmd.setNum(getShellPID());
137
strCmd.prepend("ps -j ");
138
strCmd.append(" | tail -1 | awk '{ print $5 }' | grep -q \\+");
139
int retval = system(strCmd.toStdString().c_str());
142
QString cmd = "cd " + dir + "\n";
147
void KSession::setEnvironment(const QStringList &environment)
149
m_session->setEnvironment(environment);
153
void KSession::setShellProgram(const QString &progname)
158
m_session->setProgram(progname);
161
void KSession::setWorkingDirectory(const QString &dir)
166
m_session->setInitialWorkingDirectory(dir);
169
void KSession::setArgs(QStringList &args)
174
m_session->setArguments(args);
177
void KSession::setTextCodec(QTextCodec *codec)
182
m_session->setCodec(codec);
185
void KSession::setHistorySize(int lines)
188
m_session->setHistoryType(HistoryTypeFile());
190
m_session->setHistoryType(HistoryTypeBuffer(lines));
193
void KSession::sendText(QString text)
195
m_session->sendText(text);
198
void KSession::sendKey(int rep, int key, int mod) const
200
Qt::KeyboardModifier kbm = Qt::KeyboardModifier(mod);
202
QKeyEvent qkey(QEvent::KeyPress, key, kbm);
205
m_session->sendKey(&qkey);
210
void KSession::setFlowControlEnabled(bool enabled)
212
m_session->setFlowControlEnabled(enabled);
215
bool KSession::flowControlEnabled()
217
return m_session->flowControlEnabled();
220
void KSession::setKeyBindings(const QString &kb)
222
m_session->setKeyBindings(kb);
223
emit changedKeyBindings(kb);
226
QString KSession::getKeyBindings()
228
return m_session->keyBindings();
232
QStringList KSession::availableKeyBindings()
234
return KeyboardTranslatorManager::instance()->allTranslators();
237
QString KSession::keyBindings()
239
return m_session->keyBindings();