blob: 5192f0c133449a1d0949d7d1a5cf3365b408ba52 (
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
|
#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");
document.append("\n");
for (auto const &fav : kristall::favourites.allFavourites())
{
if(fav->title.isEmpty()) {
document.append("=> " + fav->destination.toString().toUtf8() + "\n");
} else {
document.append("=> " + fav->destination.toString().toUtf8() + " " + fav->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;
}
|