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