File indexing completed on 2024-04-21 05:51:22
0001 #ifndef ESCAPE_SEQUENCE_URL_EXTRACTOR_H 0002 #define ESCAPE_SEQUENCE_URL_EXTRACTOR_H 0003 0004 /* 0005 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 0006 SPDX-FileCopyrightText: 1997, 1998 Lars Doelle <lars.doelle@on-line.de> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include <QObject> 0012 0013 #include "konsoleprivate_export.h" 0014 0015 namespace Konsole 0016 { 0017 class Screen; 0018 /* Like QPoint, but with Row / Col 0019 * easier to read than x / y 0020 */ 0021 struct Coordinate { 0022 int row; 0023 int col; 0024 }; 0025 0026 /* Represents a URL on the visual part of konsole, that has been escaped. 0027 * like a html url tag with a text value. 0028 */ 0029 struct ExtractedUrl { 0030 QString url; 0031 QString text; 0032 Coordinate begin; 0033 Coordinate end; 0034 }; 0035 0036 /* Stored in Screen, but used in V10Emulation to 0037 * store extracted URL's. Perhaps this should be a Model? 0038 */ 0039 class KONSOLEPRIVATE_EXPORT EscapeSequenceUrlExtractor : public QObject 0040 { 0041 Q_OBJECT 0042 0043 private: 0044 /* Tell us if we are currently reading or not a URL. */ 0045 bool _reading = false; 0046 0047 /* If we abort reading a URL input we enter in a invalid state, 0048 * and we need to ignore the next toggle. 0049 */ 0050 bool _ignoreNextUrlInput = false; 0051 0052 /* The url / text pair being extracted currently */ 0053 ExtractedUrl _currentUrl; 0054 0055 /* The maximum size of url to prevent a bomb 0056 * that will take over the history file. 0057 * TODO: make it configurable. 0058 */ 0059 // Not used ATM const int _maximumUrlHistory = 200; 0060 0061 /* All of the extracted URL's. */ 0062 QVector<ExtractedUrl> _history; 0063 0064 /* The URI schema format that's accepted */ 0065 QStringList _allowedUriSchemas; 0066 0067 /* Pointer to the Screen, that actually holds the text data. */ 0068 Screen *_screen = nullptr; 0069 0070 void appendUrlText_impl(QChar c); 0071 0072 public: 0073 /* This needs to have access to the Session 0074 * calculate the row / col of the current URL. 0075 */ 0076 EscapeSequenceUrlExtractor(); 0077 0078 /* This is a list of URI schemas that are going to be supported, separated by semicolon. 0079 * like https://;file:// 0080 */ 0081 void setAllowedLinkSchema(const QStringList &allowedSchemas); 0082 0083 void setScreen(Screen *screen); 0084 0085 /* If we are parsing a URL */ 0086 bool reading() const 0087 { 0088 return _reading; 0089 } 0090 0091 /* We found an URL, starting to parse */ 0092 void beginUrlInput(); 0093 0094 /* We received the end byte to finish the Url. */ 0095 void endUrlInput(); 0096 0097 /* We are not saving this URL, it's bogus. */ 0098 void abortUrlInput(); 0099 0100 /* The URL is parsed at once, but not the text. We received 0101 * one character per time until we hit the end byte. */ 0102 void appendUrlText(QChar c) 0103 { 0104 if (!reading()) { 0105 return; 0106 } 0107 appendUrlText_impl(c); 0108 } 0109 0110 /* The URL is parsed at once, store it at once. */ 0111 void setUrl(const QString &url); 0112 0113 /* All of the parsedURL's, used by TerminalDisplay to paint them 0114 * on screen. */ 0115 QVector<ExtractedUrl> history() const; 0116 0117 /* Clear all the URL's, this is triggered when the Screen is cleared. */ 0118 void clear(); 0119 0120 /* Iterates through all the URL's and remove the ones that are currently 0121 * out of bounds because we removed lines in the History 0122 */ 0123 void historyLinesRemoved(int lines); 0124 0125 /* starts / stops URL Processing */ 0126 0127 public Q_SLOTS: 0128 void toggleUrlInput(); 0129 }; 0130 0131 } 0132 0133 #endif