blob: d8d26f2ca40149f9a0f9c4a2464cb5b45afef947 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include "abouthandler.hpp"
#include "kristall.hpp"
#include <QUrl>
#include <QFile>
AboutHandler::AboutHandler()
{
}
bool AboutHandler::supportsScheme(const QString &scheme) const
{
return (scheme == "about");
}
bool AboutHandler::startRequest(const QUrl &url, ProtocolHandler::RequestOptions options)
{
Q_UNUSED(options)
if (url.path() == "blank")
{
emit this->requestComplete("", "text/gemini");
}
else if (url.path() == "favourites")
{
QByteArray document;
document.append("# Favourites\n");
QString current_group;
for (auto const &fav : kristall::favourites.allFavourites())
{
if(current_group != fav.first) {
document.append("\n");
document.append(QString("## %1\n").arg(fav.first));
current_group = fav.first;
}
if(fav.second->title.isEmpty()) {
document.append("=> " + fav.second->destination.toString().toUtf8() + "\n");
} else {
document.append("=> " + fav.second->destination.toString().toUtf8() + " " + fav.second->title.toUtf8() + "\n");
}
}
this->requestComplete(document, "text/gemini");
}
else
{
QFile file(QString(":/about/%1.gemini").arg(url.path()));
if (file.open(QFile::ReadOnly))
{
emit this->requestComplete(file.readAll(), "text/gemini");
}
else
{
emit this->networkError(ResourceNotFound, "The requested resource does not exist.");
}
}
return true;
}
bool AboutHandler::isInProgress() const
{
return false;
}
bool AboutHandler::cancelRequest()
{
return true;
}
|