diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-10 01:24:39 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-10 01:24:39 +0200 |
| commit | 9b93c4d7c5a450607eca0174b1899e56d6a09a48 (patch) | |
| tree | a4cd5ac75ad9a3cd3f3a69ecbb25c53bf43fd3e8 /src | |
| parent | e32d4644034f0a6df8dd06c985ccfe74e7dd48f4 (diff) | |
| download | kristall-9b93c4d7c5a450607eca0174b1899e56d6a09a48.tar.gz | |
Improves gophermaps: Now handle '+' correctly, improves gopher protocol such that it now respects *the lone dot*.
Diffstat (limited to 'src')
| -rw-r--r-- | src/gopherclient.cpp | 12 | ||||
| -rw-r--r-- | src/gopherclient.hpp | 1 | ||||
| -rw-r--r-- | src/gophermaprenderer.cpp | 17 | ||||
| -rw-r--r-- | src/settingsdialog.ui | 10 |
4 files changed, 29 insertions, 11 deletions
diff --git a/src/gopherclient.cpp b/src/gopherclient.cpp index 17faceb..2c2cdf5 100644 --- a/src/gopherclient.cpp +++ b/src/gopherclient.cpp @@ -34,7 +34,7 @@ bool GopherClient::startRequest(const QUrl &url) else if(type == "h") mime = "text/html"; else if(type == "s") mime = "audio/unknown"; - qDebug() << url << "→" << mime; + is_processing_binary = (type == "5") or (type == "9") or (type == "I") or (type == "g"); this->requested_url = url; this->was_cancelled = false; @@ -66,6 +66,15 @@ void GopherClient::on_connected() void GopherClient::on_readRead() { body.append(socket.readAll()); + + if(not is_processing_binary) { + // Strip the "lone dot" from gopher data + if(int index = body.indexOf(".\r\n"); index >= 0) { + body.resize(index); + socket.close(); + } + } + emit this->requestProgress(body.size()); } @@ -74,7 +83,6 @@ void GopherClient::on_finished() if(not was_cancelled) { emit this->requestComplete(this->body, mime); - was_cancelled = true; } body.clear(); diff --git a/src/gopherclient.hpp b/src/gopherclient.hpp index a2beb0c..f9913c5 100644 --- a/src/gopherclient.hpp +++ b/src/gopherclient.hpp @@ -37,6 +37,7 @@ private: QUrl requested_url; bool was_cancelled; QString mime; + bool is_processing_binary; }; #endif // GOPHERCLIENT_HPP diff --git a/src/gophermaprenderer.cpp b/src/gophermaprenderer.cpp index c705883..89f3905 100644 --- a/src/gophermaprenderer.cpp +++ b/src/gophermaprenderer.cpp @@ -51,6 +51,8 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input QTextBlockFormat non_list_format = cursor.blockFormat(); + char last_type = '1'; + QList<QByteArray> lines = input.split('\n'); for (auto const &line : lines) { @@ -66,7 +68,9 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input QString icon; QString scheme = "gopher"; - switch (line.at(0)) + + auto type = line.at(0); + switch (type) { case '0': // Text File icon = "text"; @@ -125,12 +129,17 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input default: // unknown continue; } + if(type == '+') { + type = last_type; + } else { + last_type = type; + } QString title = items.at(0); // 1Phlog /phlog octotherp.org 70 + - if (line.at(0) == 'i') + if (type == 'i') { cursor.insertText(title + "\n", standard); } @@ -147,10 +156,10 @@ std::unique_ptr<QTextDocument> GophermapRenderer::render(const QByteArray &input dst_url = root_url.resolved(QUrl(items.at(1))).toString(); break; case 3: - dst_url = scheme + "://" + items.at(2) + "/" + line.mid(0, 1) + items.at(1); + dst_url = scheme + "://" + items.at(2) + "/" + QString(type) + items.at(1); break; default: - dst_url = scheme + "://" + items.at(2) + ":" + items.at(3) + "/" + line.mid(0, 1) + items.at(1); + dst_url = scheme + "://" + items.at(2) + ":" + items.at(3) + "/" + QString(type) + items.at(1); break; } diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 75b84fe..23d1bc8 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -212,9 +212,9 @@ <item row="6" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_7"> <item> - <widget class="QRadioButton" name="scheme_error"> + <widget class="QRadioButton" name="scheme_os_default"> <property name="text"> - <string>Display error message</string> + <string>Use OS default handler</string> </property> <attribute name="buttonGroup"> <string notr="true">buttonGroup</string> @@ -222,9 +222,9 @@ </widget> </item> <item> - <widget class="QRadioButton" name="scheme_os_default"> + <widget class="QRadioButton" name="scheme_error"> <property name="text"> - <string>Use OS default handler</string> + <string>Display error message</string> </property> <attribute name="buttonGroup"> <string notr="true">buttonGroup</string> @@ -842,9 +842,9 @@ </connection> </connections> <buttongroups> + <buttongroup name="buttonGroup"/> <buttongroup name="gophermapBtnGroup"/> <buttongroup name="textHighlightsBtnGroup"/> <buttongroup name="textRenderingBtnGroup"/> - <buttongroup name="buttonGroup"/> </buttongroups> </ui> |
