1 | /* Copyright (C) 2008 e_k (e_k@users.sourceforge.net) |
---|
2 | |
---|
3 | This library is free software; you can redistribute it and/or |
---|
4 | modify it under the terms of the GNU Library General Public |
---|
5 | License as published by the Free Software Foundation; either |
---|
6 | version 2 of the License, or (at your option) any later version. |
---|
7 | |
---|
8 | This library is distributed in the hope that it will be useful, |
---|
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
11 | Library General Public License for more details. |
---|
12 | |
---|
13 | You should have received a copy of the GNU Library General Public License |
---|
14 | along with this library; see the file COPYING.LIB. If not, write to |
---|
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
---|
16 | Boston, MA 02110-1301, USA. |
---|
17 | */ |
---|
18 | |
---|
19 | #include <QLayout> |
---|
20 | #include <QBoxLayout> |
---|
21 | #include <QtDebug> |
---|
22 | #include <QDir> |
---|
23 | #include <QMessageBox> |
---|
24 | #if QT_VERSION >= 0x060000 |
---|
25 | #include <QRegularExpression> |
---|
26 | #endif |
---|
27 | |
---|
28 | #include "ColorTables.h" |
---|
29 | #include "Session.h" |
---|
30 | #include "Screen.h" |
---|
31 | #include "ScreenWindow.h" |
---|
32 | #include "Emulation.h" |
---|
33 | #include "TerminalDisplay.h" |
---|
34 | #include "KeyboardTranslator.h" |
---|
35 | #include "ColorScheme.h" |
---|
36 | #include "SearchBar.h" |
---|
37 | #include "qtermwidget.h" |
---|
38 | |
---|
39 | #ifdef Q_OS_MACOS |
---|
40 | // Qt does not support fontconfig on macOS, so we need to use a "real" font name. |
---|
41 | #define DEFAULT_FONT_FAMILY "Menlo" |
---|
42 | #else |
---|
43 | #define DEFAULT_FONT_FAMILY "Monospace" |
---|
44 | #endif |
---|
45 | |
---|
46 | #define STEP_ZOOM 1 |
---|
47 | |
---|
48 | using namespace Konsole; |
---|
49 | |
---|
50 | void *createTermWidget(int startnow, void *parent) |
---|
51 | { |
---|
52 | return (void*) new QTermWidget(startnow, (QWidget*)parent); |
---|
53 | } |
---|
54 | |
---|
55 | class TermWidgetImpl { |
---|
56 | |
---|
57 | public: |
---|
58 | TermWidgetImpl(QWidget* parent = nullptr); |
---|
59 | |
---|
60 | TerminalDisplay *m_terminalDisplay; |
---|
61 | Session *m_session; |
---|
62 | |
---|
63 | Session* createSession(QWidget* parent); |
---|
64 | TerminalDisplay* createTerminalDisplay(Session *session, QWidget* parent); |
---|
65 | }; |
---|
66 | |
---|
67 | TermWidgetImpl::TermWidgetImpl(QWidget* parent) |
---|
68 | { |
---|
69 | this->m_session = createSession(parent); |
---|
70 | this->m_terminalDisplay = createTerminalDisplay(this->m_session, parent); |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | Session *TermWidgetImpl::createSession(QWidget* parent) |
---|
75 | { |
---|
76 | Session *session = new Session(parent); |
---|
77 | |
---|
78 | session->setTitle(Session::NameRole, QLatin1String("QTermWidget")); |
---|
79 | |
---|
80 | /* That's a freaking bad idea!!!! |
---|
81 | * /bin/bash is not there on every system |
---|
82 | * better set it to the current $SHELL |
---|
83 | * Maybe you can also make a list available and then let the widget-owner decide what to use. |
---|
84 | * By setting it to $SHELL right away we actually make the first filecheck obsolete. |
---|
85 | * But as I'm not sure if you want to do anything else I'll just let both checks in and set this to $SHELL anyway. |
---|
86 | */ |
---|
87 | //session->setProgram("/bin/bash"); |
---|
88 | |
---|
89 | session->setProgram(QString::fromLocal8Bit(qgetenv("SHELL"))); |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | QStringList args = QStringList(QString()); |
---|
94 | session->setArguments(args); |
---|
95 | session->setAutoClose(true); |
---|
96 | |
---|
97 | session->setCodec(QTextCodec::codecForName("UTF-8")); |
---|
98 | |
---|
99 | session->setFlowControlEnabled(true); |
---|
100 | session->setHistoryType(HistoryTypeBuffer(1000)); |
---|
101 | |
---|
102 | session->setDarkBackground(true); |
---|
103 | |
---|
104 | session->setKeyBindings(QString()); |
---|
105 | return session; |
---|
106 | } |
---|
107 | |
---|
108 | TerminalDisplay *TermWidgetImpl::createTerminalDisplay(Session *session, QWidget* parent) |
---|
109 | { |
---|
110 | // TerminalDisplay* display = new TerminalDisplay(this); |
---|
111 | TerminalDisplay* display = new TerminalDisplay(parent); |
---|
112 | |
---|
113 | display->setBellMode(TerminalDisplay::NotifyBell); |
---|
114 | display->setTerminalSizeHint(true); |
---|
115 | display->setTripleClickMode(TerminalDisplay::SelectWholeLine); |
---|
116 | display->setTerminalSizeStartup(true); |
---|
117 | |
---|
118 | display->setRandomSeed(session->sessionId() * 31); |
---|
119 | |
---|
120 | return display; |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | QTermWidget::QTermWidget(int startnow, QWidget *parent) |
---|
125 | : QWidget(parent) |
---|
126 | { |
---|
127 | init(startnow); |
---|
128 | } |
---|
129 | |
---|
130 | QTermWidget::QTermWidget(QWidget *parent) |
---|
131 | : QWidget(parent) |
---|
132 | { |
---|
133 | init(1); |
---|
134 | } |
---|
135 | |
---|
136 | void QTermWidget::selectionChanged(bool textSelected) |
---|
137 | { |
---|
138 | emit copyAvailable(textSelected); |
---|
139 | } |
---|
140 | |
---|
141 | void QTermWidget::find() |
---|
142 | { |
---|
143 | search(true, false); |
---|
144 | } |
---|
145 | |
---|
146 | void QTermWidget::findNext() |
---|
147 | { |
---|
148 | search(true, true); |
---|
149 | } |
---|
150 | |
---|
151 | void QTermWidget::findPrevious() |
---|
152 | { |
---|
153 | search(false, false); |
---|
154 | } |
---|
155 | |
---|
156 | void QTermWidget::search(bool forwards, bool next) |
---|
157 | { |
---|
158 | int startColumn, startLine; |
---|
159 | |
---|
160 | if (next) // search from just after current selection |
---|
161 | { |
---|
162 | m_impl->m_terminalDisplay->screenWindow()->screen()->getSelectionEnd(startColumn, startLine); |
---|
163 | startColumn++; |
---|
164 | } |
---|
165 | else // search from start of current selection |
---|
166 | { |
---|
167 | m_impl->m_terminalDisplay->screenWindow()->screen()->getSelectionStart(startColumn, startLine); |
---|
168 | } |
---|
169 | |
---|
170 | //qDebug() << "current selection starts at: " << startColumn << startLine; |
---|
171 | //qDebug() << "current cursor position: " << m_impl->m_terminalDisplay->screenWindow()->cursorPosition(); |
---|
172 | |
---|
173 | #if QT_VERSION < 0x060000 |
---|
174 | QRegExp regExp(m_searchBar->searchText()); |
---|
175 | regExp.setPatternSyntax(m_searchBar->useRegularExpression() ? QRegExp::RegExp : QRegExp::FixedString); |
---|
176 | regExp.setCaseSensitivity(m_searchBar->matchCase() ? Qt::CaseSensitive : Qt::CaseInsensitive); |
---|
177 | #else |
---|
178 | QRegularExpression regExp(m_searchBar->searchText(), |
---|
179 | m_searchBar->matchCase() ? QRegularExpression::CaseInsensitiveOption| |
---|
180 | QRegularExpression::UseUnicodePropertiesOption |
---|
181 | : QRegularExpression::UseUnicodePropertiesOption); |
---|
182 | #endif |
---|
183 | HistorySearch *historySearch = |
---|
184 | new HistorySearch(m_impl->m_session->emulation(), regExp, forwards, startColumn, startLine, this); |
---|
185 | connect(historySearch, SIGNAL(matchFound(int, int, int, int)), this, SLOT(matchFound(int, int, int, int))); |
---|
186 | connect(historySearch, SIGNAL(noMatchFound()), this, SLOT(noMatchFound())); |
---|
187 | connect(historySearch, SIGNAL(noMatchFound()), m_searchBar, SLOT(noMatchFound())); |
---|
188 | historySearch->search(); |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | void QTermWidget::matchFound(int startColumn, int startLine, int endColumn, int endLine) |
---|
193 | { |
---|
194 | ScreenWindow* sw = m_impl->m_terminalDisplay->screenWindow(); |
---|
195 | //qDebug() << "Scroll to" << startLine; |
---|
196 | sw->scrollTo(startLine); |
---|
197 | sw->setTrackOutput(false); |
---|
198 | sw->notifyOutputChanged(); |
---|
199 | sw->setSelectionStart(startColumn, startLine - sw->currentLine(), false); |
---|
200 | sw->setSelectionEnd(endColumn, endLine - sw->currentLine()); |
---|
201 | } |
---|
202 | |
---|
203 | void QTermWidget::noMatchFound() |
---|
204 | { |
---|
205 | m_impl->m_terminalDisplay->screenWindow()->clearSelection(); |
---|
206 | } |
---|
207 | |
---|
208 | int QTermWidget::getShellPID() |
---|
209 | { |
---|
210 | return m_impl->m_session->processId(); |
---|
211 | } |
---|
212 | |
---|
213 | int QTermWidget::getForegroundProcessId() |
---|
214 | { |
---|
215 | return m_impl->m_session->foregroundProcessId(); |
---|
216 | } |
---|
217 | |
---|
218 | void QTermWidget::changeDir(const QString & dir) |
---|
219 | { |
---|
220 | /* |
---|
221 | this is a very hackish way of trying to determine if the shell is in |
---|
222 | the foreground before attempting to change the directory. It may not |
---|
223 | be portable to anything other than Linux. |
---|
224 | */ |
---|
225 | QString strCmd; |
---|
226 | strCmd.setNum(getShellPID()); |
---|
227 | strCmd.prepend(QLatin1String("ps -j ")); |
---|
228 | strCmd.append(QLatin1String(" | tail -1 | awk '{ print $5 }' | grep -q \\+")); |
---|
229 | int retval = system(strCmd.toStdString().c_str()); |
---|
230 | |
---|
231 | if (!retval) { |
---|
232 | QString cmd = QLatin1String("cd ") + dir + QLatin1Char('\n'); |
---|
233 | sendText(cmd); |
---|
234 | } |
---|
235 | } |
---|
236 | |
---|
237 | QSize QTermWidget::sizeHint() const |
---|
238 | { |
---|
239 | QSize size = m_impl->m_terminalDisplay->sizeHint(); |
---|
240 | size.rheight() = 150; |
---|
241 | return size; |
---|
242 | } |
---|
243 | |
---|
244 | void QTermWidget::setTerminalSizeHint(bool enabled) |
---|
245 | { |
---|
246 | m_impl->m_terminalDisplay->setTerminalSizeHint(enabled); |
---|
247 | } |
---|
248 | |
---|
249 | bool QTermWidget::terminalSizeHint() |
---|
250 | { |
---|
251 | return m_impl->m_terminalDisplay->terminalSizeHint(); |
---|
252 | } |
---|
253 | |
---|
254 | void QTermWidget::startShellProgram() |
---|
255 | { |
---|
256 | if ( m_impl->m_session->isRunning() ) { |
---|
257 | return; |
---|
258 | } |
---|
259 | |
---|
260 | m_impl->m_session->run(); |
---|
261 | } |
---|
262 | |
---|
263 | void QTermWidget::startTerminalTeletype() |
---|
264 | { |
---|
265 | if ( m_impl->m_session->isRunning() ) { |
---|
266 | return; |
---|
267 | } |
---|
268 | |
---|
269 | m_impl->m_session->runEmptyPTY(); |
---|
270 | // redirect data from TTY to external recipient |
---|
271 | connect( m_impl->m_session->emulation(), SIGNAL(sendData(const char *,int)), |
---|
272 | this, SIGNAL(sendData(const char *,int)) ); |
---|
273 | } |
---|
274 | |
---|
275 | void QTermWidget::init(int startnow) |
---|
276 | { |
---|
277 | m_layout = new QVBoxLayout(); |
---|
278 | #if QT_VERSION < 0x060000 |
---|
279 | m_layout->setMargin(0); |
---|
280 | #else |
---|
281 | m_layout->setContentsMargins(0,0,0,0); |
---|
282 | #endif |
---|
283 | setLayout(m_layout); |
---|
284 | |
---|
285 | // translations |
---|
286 | // First check $XDG_DATA_DIRS. This follows the implementation in libqtxdg |
---|
287 | QString d = QFile::decodeName(qgetenv("XDG_DATA_DIRS")); |
---|
288 | QStringList dirs = d.split(QLatin1Char(':'), Qt::SkipEmptyParts); |
---|
289 | if (dirs.isEmpty()) { |
---|
290 | dirs.append(QString::fromLatin1("/usr/local/share")); |
---|
291 | dirs.append(QString::fromLatin1("/usr/share")); |
---|
292 | } |
---|
293 | dirs.append(QFile::decodeName(TRANSLATIONS_DIR)); |
---|
294 | |
---|
295 | m_translator = new QTranslator(this); |
---|
296 | |
---|
297 | for (const QString& dir : qAsConst(dirs)) { |
---|
298 | //qDebug() << "Trying to load translation file from dir" << dir; |
---|
299 | if (m_translator->load(QLocale::system(), QLatin1String("qtermwidget"), QLatin1String(QLatin1String("_")), dir)) { |
---|
300 | qApp->installTranslator(m_translator); |
---|
301 | //qDebug() << "Translations found in" << dir; |
---|
302 | break; |
---|
303 | } |
---|
304 | } |
---|
305 | |
---|
306 | m_impl = new TermWidgetImpl(this); |
---|
307 | m_layout->addWidget(m_impl->m_terminalDisplay); |
---|
308 | |
---|
309 | connect(m_impl->m_session, SIGNAL(bellRequest(QString)), m_impl->m_terminalDisplay, SLOT(bell(QString))); |
---|
310 | connect(m_impl->m_terminalDisplay, SIGNAL(notifyBell(QString)), this, SIGNAL(bell(QString))); |
---|
311 | |
---|
312 | connect(m_impl->m_session, SIGNAL(activity()), this, SIGNAL(activity())); |
---|
313 | connect(m_impl->m_session, SIGNAL(silence()), this, SIGNAL(silence())); |
---|
314 | connect(m_impl->m_session, &Session::profileChangeCommandReceived, this, &QTermWidget::profileChanged); |
---|
315 | connect(m_impl->m_session, &Session::receivedData, this, &QTermWidget::receivedData); |
---|
316 | |
---|
317 | // That's OK, FilterChain's dtor takes care of UrlFilter. |
---|
318 | UrlFilter *urlFilter = new UrlFilter(); |
---|
319 | connect(urlFilter, &UrlFilter::activated, this, &QTermWidget::urlActivated); |
---|
320 | m_impl->m_terminalDisplay->filterChain()->addFilter(urlFilter); |
---|
321 | |
---|
322 | m_searchBar = new SearchBar(this); |
---|
323 | m_searchBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum); |
---|
324 | connect(m_searchBar, SIGNAL(searchCriteriaChanged()), this, SLOT(find())); |
---|
325 | connect(m_searchBar, SIGNAL(findNext()), this, SLOT(findNext())); |
---|
326 | connect(m_searchBar, SIGNAL(findPrevious()), this, SLOT(findPrevious())); |
---|
327 | m_layout->addWidget(m_searchBar); |
---|
328 | m_searchBar->hide(); |
---|
329 | |
---|
330 | if (startnow && m_impl->m_session) { |
---|
331 | m_impl->m_session->run(); |
---|
332 | } |
---|
333 | |
---|
334 | this->setFocus( Qt::OtherFocusReason ); |
---|
335 | this->setFocusPolicy( Qt::WheelFocus ); |
---|
336 | m_impl->m_terminalDisplay->resize(this->size()); |
---|
337 | |
---|
338 | this->setFocusProxy(m_impl->m_terminalDisplay); |
---|
339 | connect(m_impl->m_terminalDisplay, SIGNAL(copyAvailable(bool)), |
---|
340 | this, SLOT(selectionChanged(bool))); |
---|
341 | connect(m_impl->m_terminalDisplay, SIGNAL(termGetFocus()), |
---|
342 | this, SIGNAL(termGetFocus())); |
---|
343 | connect(m_impl->m_terminalDisplay, SIGNAL(termLostFocus()), |
---|
344 | this, SIGNAL(termLostFocus())); |
---|
345 | connect(m_impl->m_terminalDisplay, &TerminalDisplay::keyPressedSignal, this, |
---|
346 | [this] (QKeyEvent* e, bool) { Q_EMIT termKeyPressed(e); }); |
---|
347 | // m_impl->m_terminalDisplay->setSize(80, 40); |
---|
348 | |
---|
349 | QFont font = QApplication::font(); |
---|
350 | font.setFamily(QLatin1String(DEFAULT_FONT_FAMILY)); |
---|
351 | font.setPointSize(10); |
---|
352 | font.setStyleHint(QFont::TypeWriter); |
---|
353 | setTerminalFont(font); |
---|
354 | m_searchBar->setFont(font); |
---|
355 | |
---|
356 | setScrollBarPosition(NoScrollBar); |
---|
357 | setKeyboardCursorShape(Emulation::KeyboardCursorShape::BlockCursor); |
---|
358 | |
---|
359 | m_impl->m_session->addView(m_impl->m_terminalDisplay); |
---|
360 | |
---|
361 | connect(m_impl->m_session, SIGNAL(resizeRequest(QSize)), this, SLOT(setSize(QSize))); |
---|
362 | connect(m_impl->m_session, SIGNAL(finished()), this, SLOT(sessionFinished())); |
---|
363 | connect(m_impl->m_session, &Session::titleChanged, this, &QTermWidget::titleChanged); |
---|
364 | connect(m_impl->m_session, &Session::cursorChanged, this, &QTermWidget::cursorChanged); |
---|
365 | } |
---|
366 | |
---|
367 | |
---|
368 | QTermWidget::~QTermWidget() |
---|
369 | { |
---|
370 | delete m_impl; |
---|
371 | emit destroyed(); |
---|
372 | } |
---|
373 | |
---|
374 | |
---|
375 | void QTermWidget::setTerminalFont(const QFont &font) |
---|
376 | { |
---|
377 | m_impl->m_terminalDisplay->setVTFont(font); |
---|
378 | } |
---|
379 | |
---|
380 | QFont QTermWidget::getTerminalFont() |
---|
381 | { |
---|
382 | return m_impl->m_terminalDisplay->getVTFont(); |
---|
383 | } |
---|
384 | |
---|
385 | void QTermWidget::setTerminalOpacity(qreal level) |
---|
386 | { |
---|
387 | m_impl->m_terminalDisplay->setOpacity(level); |
---|
388 | } |
---|
389 | |
---|
390 | void QTermWidget::setTerminalBackgroundImage(const QString& backgroundImage) |
---|
391 | { |
---|
392 | m_impl->m_terminalDisplay->setBackgroundImage(backgroundImage); |
---|
393 | } |
---|
394 | |
---|
395 | void QTermWidget::setTerminalBackgroundMode(int mode) |
---|
396 | { |
---|
397 | m_impl->m_terminalDisplay->setBackgroundMode((Konsole::BackgroundMode)mode); |
---|
398 | } |
---|
399 | |
---|
400 | void QTermWidget::setShellProgram(const QString &program) |
---|
401 | { |
---|
402 | if (!m_impl->m_session) |
---|
403 | return; |
---|
404 | m_impl->m_session->setProgram(program); |
---|
405 | } |
---|
406 | |
---|
407 | void QTermWidget::setWorkingDirectory(const QString& dir) |
---|
408 | { |
---|
409 | if (!m_impl->m_session) |
---|
410 | return; |
---|
411 | m_impl->m_session->setInitialWorkingDirectory(dir); |
---|
412 | } |
---|
413 | |
---|
414 | QString QTermWidget::workingDirectory() |
---|
415 | { |
---|
416 | if (!m_impl->m_session) |
---|
417 | return QString(); |
---|
418 | |
---|
419 | #ifdef Q_OS_LINUX |
---|
420 | // Christian Surlykke: On linux we could look at /proc/<pid>/cwd which should be a link to current |
---|
421 | // working directory (<pid>: process id of the shell). I don't know about BSD. |
---|
422 | // Maybe we could just offer it when running linux, for a start. |
---|
423 | QDir d(QString::fromLatin1("/proc/%1/cwd").arg(getShellPID())); |
---|
424 | if (!d.exists()) |
---|
425 | { |
---|
426 | qDebug() << "Cannot find" << d.dirName(); |
---|
427 | goto fallback; |
---|
428 | } |
---|
429 | return d.canonicalPath(); |
---|
430 | #endif |
---|
431 | |
---|
432 | fallback: |
---|
433 | // fallback, initial WD |
---|
434 | return m_impl->m_session->initialWorkingDirectory(); |
---|
435 | } |
---|
436 | |
---|
437 | void QTermWidget::setArgs(const QStringList &args) |
---|
438 | { |
---|
439 | if (!m_impl->m_session) |
---|
440 | return; |
---|
441 | m_impl->m_session->setArguments(args); |
---|
442 | } |
---|
443 | |
---|
444 | void QTermWidget::setTextCodec(QTextCodec *codec) |
---|
445 | { |
---|
446 | if (!m_impl->m_session) |
---|
447 | return; |
---|
448 | m_impl->m_session->setCodec(codec); |
---|
449 | } |
---|
450 | |
---|
451 | void QTermWidget::setColorScheme(const QString& origName) |
---|
452 | { |
---|
453 | const ColorScheme *cs = nullptr; |
---|
454 | |
---|
455 | const bool isFile = QFile::exists(origName); |
---|
456 | const QString& name = isFile ? |
---|
457 | QFileInfo(origName).baseName() : |
---|
458 | origName; |
---|
459 | |
---|
460 | // avoid legacy (int) solution |
---|
461 | if (!availableColorSchemes().contains(name)) |
---|
462 | { |
---|
463 | if (isFile) |
---|
464 | { |
---|
465 | if (ColorSchemeManager::instance()->loadCustomColorScheme(origName)) |
---|
466 | cs = ColorSchemeManager::instance()->findColorScheme(name); |
---|
467 | else |
---|
468 | qWarning () << Q_FUNC_INFO |
---|
469 | << "cannot load color scheme from" |
---|
470 | << origName; |
---|
471 | } |
---|
472 | |
---|
473 | if (!cs) |
---|
474 | cs = ColorSchemeManager::instance()->defaultColorScheme(); |
---|
475 | } |
---|
476 | else |
---|
477 | cs = ColorSchemeManager::instance()->findColorScheme(name); |
---|
478 | |
---|
479 | if (! cs) |
---|
480 | { |
---|
481 | QMessageBox::information(this, |
---|
482 | tr("Color Scheme Error"), |
---|
483 | tr("Cannot load color scheme: %1").arg(name)); |
---|
484 | return; |
---|
485 | } |
---|
486 | ColorEntry table[TABLE_COLORS]; |
---|
487 | cs->getColorTable(table); |
---|
488 | m_impl->m_terminalDisplay->setColorTable(table); |
---|
489 | m_impl->m_session->setDarkBackground(cs->hasDarkBackground()); |
---|
490 | } |
---|
491 | |
---|
492 | QStringList QTermWidget::getAvailableColorSchemes() |
---|
493 | { |
---|
494 | return QTermWidget::availableColorSchemes(); |
---|
495 | } |
---|
496 | |
---|
497 | QStringList QTermWidget::availableColorSchemes() |
---|
498 | { |
---|
499 | QStringList ret; |
---|
500 | const auto allColorSchemes = ColorSchemeManager::instance()->allColorSchemes(); |
---|
501 | for (const ColorScheme* cs : allColorSchemes) |
---|
502 | ret.append(cs->name()); |
---|
503 | return ret; |
---|
504 | } |
---|
505 | |
---|
506 | void QTermWidget::addCustomColorSchemeDir(const QString& custom_dir) |
---|
507 | { |
---|
508 | ColorSchemeManager::instance()->addCustomColorSchemeDir(custom_dir); |
---|
509 | } |
---|
510 | |
---|
511 | void QTermWidget::setBackgroundColor(const QColor &color) |
---|
512 | { |
---|
513 | m_impl->m_terminalDisplay->setBackgroundColor(color); |
---|
514 | } |
---|
515 | |
---|
516 | void QTermWidget::setForegroundColor(const QColor &color) |
---|
517 | { |
---|
518 | m_impl->m_terminalDisplay->setForegroundColor(color); |
---|
519 | } |
---|
520 | |
---|
521 | void QTermWidget::setANSIColor(const int ansiColorId, const QColor &color) |
---|
522 | { |
---|
523 | m_impl->m_terminalDisplay->setColorTableColor(ansiColorId, color); |
---|
524 | } |
---|
525 | |
---|
526 | void QTermWidget::setSize(const QSize &size) |
---|
527 | { |
---|
528 | m_impl->m_terminalDisplay->setSize(size.width(), size.height()); |
---|
529 | } |
---|
530 | |
---|
531 | void QTermWidget::setHistorySize(int lines) |
---|
532 | { |
---|
533 | if (lines < 0) |
---|
534 | m_impl->m_session->setHistoryType(HistoryTypeFile()); |
---|
535 | else if (lines == 0) |
---|
536 | m_impl->m_session->setHistoryType(HistoryTypeNone()); |
---|
537 | else |
---|
538 | m_impl->m_session->setHistoryType(HistoryTypeBuffer(lines)); |
---|
539 | } |
---|
540 | |
---|
541 | int QTermWidget::historySize() const |
---|
542 | { |
---|
543 | const HistoryType& currentHistory = m_impl->m_session->historyType(); |
---|
544 | |
---|
545 | if (currentHistory.isEnabled()) { |
---|
546 | if (currentHistory.isUnlimited()) { |
---|
547 | return -1; |
---|
548 | } else { |
---|
549 | return currentHistory.maximumLineCount(); |
---|
550 | } |
---|
551 | } else { |
---|
552 | return 0; |
---|
553 | } |
---|
554 | } |
---|
555 | |
---|
556 | void QTermWidget::setScrollBarPosition(ScrollBarPosition pos) |
---|
557 | { |
---|
558 | m_impl->m_terminalDisplay->setScrollBarPosition(pos); |
---|
559 | } |
---|
560 | |
---|
561 | void QTermWidget::scrollToEnd() |
---|
562 | { |
---|
563 | m_impl->m_terminalDisplay->scrollToEnd(); |
---|
564 | } |
---|
565 | |
---|
566 | void QTermWidget::sendText(const QString &text) |
---|
567 | { |
---|
568 | m_impl->m_session->sendText(text); |
---|
569 | } |
---|
570 | |
---|
571 | void QTermWidget::sendKeyEvent(QKeyEvent *e) |
---|
572 | { |
---|
573 | m_impl->m_session->sendKeyEvent(e); |
---|
574 | } |
---|
575 | |
---|
576 | void QTermWidget::resizeEvent(QResizeEvent*) |
---|
577 | { |
---|
578 | //qDebug("global window resizing...with %d %d", this->size().width(), this->size().height()); |
---|
579 | m_impl->m_terminalDisplay->resize(this->size()); |
---|
580 | } |
---|
581 | |
---|
582 | |
---|
583 | void QTermWidget::sessionFinished() |
---|
584 | { |
---|
585 | emit finished(); |
---|
586 | } |
---|
587 | |
---|
588 | void QTermWidget::bracketText(QString& text) |
---|
589 | { |
---|
590 | m_impl->m_terminalDisplay->bracketText(text); |
---|
591 | } |
---|
592 | |
---|
593 | void QTermWidget::disableBracketedPasteMode(bool disable) |
---|
594 | { |
---|
595 | m_impl->m_terminalDisplay->disableBracketedPasteMode(disable); |
---|
596 | } |
---|
597 | |
---|
598 | bool QTermWidget::bracketedPasteModeIsDisabled() const |
---|
599 | { |
---|
600 | return m_impl->m_terminalDisplay->bracketedPasteModeIsDisabled(); |
---|
601 | } |
---|
602 | |
---|
603 | void QTermWidget::copyClipboard() |
---|
604 | { |
---|
605 | m_impl->m_terminalDisplay->copyClipboard(); |
---|
606 | } |
---|
607 | |
---|
608 | void QTermWidget::pasteClipboard() |
---|
609 | { |
---|
610 | m_impl->m_terminalDisplay->pasteClipboard(); |
---|
611 | } |
---|
612 | |
---|
613 | void QTermWidget::pasteSelection() |
---|
614 | { |
---|
615 | m_impl->m_terminalDisplay->pasteSelection(); |
---|
616 | } |
---|
617 | |
---|
618 | void QTermWidget::setZoom(int step) |
---|
619 | { |
---|
620 | QFont font = m_impl->m_terminalDisplay->getVTFont(); |
---|
621 | |
---|
622 | font.setPointSize(font.pointSize() + step); |
---|
623 | setTerminalFont(font); |
---|
624 | } |
---|
625 | |
---|
626 | void QTermWidget::zoomIn() |
---|
627 | { |
---|
628 | setZoom(STEP_ZOOM); |
---|
629 | } |
---|
630 | |
---|
631 | void QTermWidget::zoomOut() |
---|
632 | { |
---|
633 | setZoom(-STEP_ZOOM); |
---|
634 | } |
---|
635 | |
---|
636 | void QTermWidget::setKeyBindings(const QString & kb) |
---|
637 | { |
---|
638 | m_impl->m_session->setKeyBindings(kb); |
---|
639 | } |
---|
640 | |
---|
641 | void QTermWidget::clear() |
---|
642 | { |
---|
643 | m_impl->m_session->emulation()->reset(); |
---|
644 | m_impl->m_session->refresh(); |
---|
645 | m_impl->m_session->clearHistory(); |
---|
646 | } |
---|
647 | |
---|
648 | void QTermWidget::setFlowControlEnabled(bool enabled) |
---|
649 | { |
---|
650 | m_impl->m_session->setFlowControlEnabled(enabled); |
---|
651 | } |
---|
652 | |
---|
653 | QStringList QTermWidget::availableKeyBindings() |
---|
654 | { |
---|
655 | return KeyboardTranslatorManager::instance()->allTranslators(); |
---|
656 | } |
---|
657 | |
---|
658 | QString QTermWidget::keyBindings() |
---|
659 | { |
---|
660 | return m_impl->m_session->keyBindings(); |
---|
661 | } |
---|
662 | |
---|
663 | void QTermWidget::toggleShowSearchBar() |
---|
664 | { |
---|
665 | m_searchBar->isHidden() ? m_searchBar->show() : m_searchBar->hide(); |
---|
666 | } |
---|
667 | |
---|
668 | bool QTermWidget::flowControlEnabled(void) |
---|
669 | { |
---|
670 | return m_impl->m_session->flowControlEnabled(); |
---|
671 | } |
---|
672 | |
---|
673 | void QTermWidget::setFlowControlWarningEnabled(bool enabled) |
---|
674 | { |
---|
675 | if (flowControlEnabled()) { |
---|
676 | // Do not show warning label if flow control is disabled |
---|
677 | m_impl->m_terminalDisplay->setFlowControlWarningEnabled(enabled); |
---|
678 | } |
---|
679 | } |
---|
680 | |
---|
681 | void QTermWidget::setEnvironment(const QStringList& environment) |
---|
682 | { |
---|
683 | m_impl->m_session->setEnvironment(environment); |
---|
684 | } |
---|
685 | |
---|
686 | void QTermWidget::setMotionAfterPasting(int action) |
---|
687 | { |
---|
688 | m_impl->m_terminalDisplay->setMotionAfterPasting((Konsole::MotionAfterPasting) action); |
---|
689 | } |
---|
690 | |
---|
691 | int QTermWidget::historyLinesCount() |
---|
692 | { |
---|
693 | return m_impl->m_terminalDisplay->screenWindow()->screen()->getHistLines(); |
---|
694 | } |
---|
695 | |
---|
696 | int QTermWidget::screenColumnsCount() |
---|
697 | { |
---|
698 | return m_impl->m_terminalDisplay->screenWindow()->screen()->getColumns(); |
---|
699 | } |
---|
700 | |
---|
701 | int QTermWidget::screenLinesCount() |
---|
702 | { |
---|
703 | return m_impl->m_terminalDisplay->screenWindow()->screen()->getLines(); |
---|
704 | } |
---|
705 | |
---|
706 | void QTermWidget::setSelectionStart(int row, int column) |
---|
707 | { |
---|
708 | m_impl->m_terminalDisplay->screenWindow()->screen()->setSelectionStart(column, row, true); |
---|
709 | } |
---|
710 | |
---|
711 | void QTermWidget::setSelectionEnd(int row, int column) |
---|
712 | { |
---|
713 | m_impl->m_terminalDisplay->screenWindow()->screen()->setSelectionEnd(column, row); |
---|
714 | } |
---|
715 | |
---|
716 | void QTermWidget::getSelectionStart(int& row, int& column) |
---|
717 | { |
---|
718 | m_impl->m_terminalDisplay->screenWindow()->screen()->getSelectionStart(column, row); |
---|
719 | } |
---|
720 | |
---|
721 | void QTermWidget::getSelectionEnd(int& row, int& column) |
---|
722 | { |
---|
723 | m_impl->m_terminalDisplay->screenWindow()->screen()->getSelectionEnd(column, row); |
---|
724 | } |
---|
725 | |
---|
726 | QString QTermWidget::selectedText(bool preserveLineBreaks) |
---|
727 | { |
---|
728 | return m_impl->m_terminalDisplay->screenWindow()->screen()->selectedText(preserveLineBreaks); |
---|
729 | } |
---|
730 | |
---|
731 | void QTermWidget::setMonitorActivity(bool enabled) |
---|
732 | { |
---|
733 | m_impl->m_session->setMonitorActivity(enabled); |
---|
734 | } |
---|
735 | |
---|
736 | void QTermWidget::setMonitorSilence(bool enabled) |
---|
737 | { |
---|
738 | m_impl->m_session->setMonitorSilence(enabled); |
---|
739 | } |
---|
740 | |
---|
741 | void QTermWidget::setSilenceTimeout(int seconds) |
---|
742 | { |
---|
743 | m_impl->m_session->setMonitorSilenceSeconds(seconds); |
---|
744 | } |
---|
745 | |
---|
746 | Filter::HotSpot* QTermWidget::getHotSpotAt(const QPoint &pos) const |
---|
747 | { |
---|
748 | int row = 0, column = 0; |
---|
749 | m_impl->m_terminalDisplay->getCharacterPosition(pos, row, column); |
---|
750 | return getHotSpotAt(row, column); |
---|
751 | } |
---|
752 | |
---|
753 | Filter::HotSpot* QTermWidget::getHotSpotAt(int row, int column) const |
---|
754 | { |
---|
755 | return m_impl->m_terminalDisplay->filterChain()->hotSpotAt(row, column); |
---|
756 | } |
---|
757 | |
---|
758 | QList<QAction*> QTermWidget::filterActions(const QPoint& position) |
---|
759 | { |
---|
760 | return m_impl->m_terminalDisplay->filterActions(position); |
---|
761 | } |
---|
762 | |
---|
763 | int QTermWidget::getPtySlaveFd() const |
---|
764 | { |
---|
765 | return m_impl->m_session->getPtySlaveFd(); |
---|
766 | } |
---|
767 | |
---|
768 | void QTermWidget::setKeyboardCursorShape(KeyboardCursorShape shape) |
---|
769 | { |
---|
770 | m_impl->m_terminalDisplay->setKeyboardCursorShape(shape); |
---|
771 | } |
---|
772 | |
---|
773 | void QTermWidget::setBlinkingCursor(bool blink) |
---|
774 | { |
---|
775 | m_impl->m_terminalDisplay->setBlinkingCursor(blink); |
---|
776 | } |
---|
777 | |
---|
778 | void QTermWidget::setBidiEnabled(bool enabled) |
---|
779 | { |
---|
780 | m_impl->m_terminalDisplay->setBidiEnabled(enabled); |
---|
781 | } |
---|
782 | |
---|
783 | bool QTermWidget::isBidiEnabled() |
---|
784 | { |
---|
785 | return m_impl->m_terminalDisplay->isBidiEnabled(); |
---|
786 | } |
---|
787 | |
---|
788 | QString QTermWidget::title() const |
---|
789 | { |
---|
790 | QString title = m_impl->m_session->userTitle(); |
---|
791 | if (title.isEmpty()) |
---|
792 | title = m_impl->m_session->title(Konsole::Session::NameRole); |
---|
793 | return title; |
---|
794 | } |
---|
795 | |
---|
796 | QString QTermWidget::icon() const |
---|
797 | { |
---|
798 | QString icon = m_impl->m_session->iconText(); |
---|
799 | if (icon.isEmpty()) |
---|
800 | icon = m_impl->m_session->iconName(); |
---|
801 | return icon; |
---|
802 | } |
---|
803 | |
---|
804 | bool QTermWidget::isTitleChanged() const |
---|
805 | { |
---|
806 | return m_impl->m_session->isTitleChanged(); |
---|
807 | } |
---|
808 | |
---|
809 | void QTermWidget::setAutoClose(bool enabled) |
---|
810 | { |
---|
811 | m_impl->m_session->setAutoClose(enabled); |
---|
812 | } |
---|
813 | |
---|
814 | void QTermWidget::cursorChanged(Konsole::Emulation::KeyboardCursorShape cursorShape, bool blinkingCursorEnabled) |
---|
815 | { |
---|
816 | // TODO: A switch to enable/disable DECSCUSR? |
---|
817 | setKeyboardCursorShape(cursorShape); |
---|
818 | setBlinkingCursor(blinkingCursorEnabled); |
---|
819 | } |
---|
820 | |
---|
821 | void QTermWidget::setMargin(int margin) |
---|
822 | { |
---|
823 | m_impl->m_terminalDisplay->setMargin(margin); |
---|
824 | } |
---|
825 | |
---|
826 | int QTermWidget::getMargin() const |
---|
827 | { |
---|
828 | return m_impl->m_terminalDisplay->margin(); |
---|
829 | } |
---|
830 | |
---|
831 | void QTermWidget::saveHistory(QIODevice *device) |
---|
832 | { |
---|
833 | QTextStream stream(device); |
---|
834 | PlainTextDecoder decoder; |
---|
835 | decoder.begin(&stream); |
---|
836 | m_impl->m_session->emulation()->writeToStream(&decoder, 0, m_impl->m_session->emulation()->lineCount()); |
---|
837 | } |
---|
838 | |
---|
839 | void QTermWidget::setDrawLineChars(bool drawLineChars) |
---|
840 | { |
---|
841 | m_impl->m_terminalDisplay->setDrawLineChars(drawLineChars); |
---|
842 | } |
---|
843 | |
---|
844 | void QTermWidget::setBoldIntense(bool boldIntense) |
---|
845 | { |
---|
846 | m_impl->m_terminalDisplay->setBoldIntense(boldIntense); |
---|
847 | } |
---|
848 | |
---|
849 | void QTermWidget::setConfirmMultilinePaste(bool confirmMultilinePaste) { |
---|
850 | m_impl->m_terminalDisplay->setConfirmMultilinePaste(confirmMultilinePaste); |
---|
851 | } |
---|
852 | |
---|
853 | void QTermWidget::setTrimPastedTrailingNewlines(bool trimPastedTrailingNewlines) { |
---|
854 | m_impl->m_terminalDisplay->setTrimPastedTrailingNewlines(trimPastedTrailingNewlines); |
---|
855 | } |
---|
856 | |
---|
857 | QTermWidgetInterface* QTermWidget::createWidget(int startnow) const |
---|
858 | { |
---|
859 | return new QTermWidget(startnow); |
---|
860 | } |
---|