MCPcopy Create free account
hub / github.com/KikoPlayProject/KikoPlay / processDirectory

Method processDirectory

LANServer/filehandler.cpp:51–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51void FileHandler::processDirectory(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response, const QString &path)
52{
53 Q_UNUSED(request)
54 // Add entries for each of the files
55 QString listing;
56 for(QFileInfo info : QDir(path).entryInfoList(QDir::NoFilter, QDir::Name | QDir::DirsFirst | QDir::IgnoreCase))
57 {
58 listing.append(QString("<li><a href=\"%1%2\">%1%2</a></li>")
59 .arg(info.fileName().toHtmlEscaped())
60 .arg(info.isDir() ? "/" : ""));
61 }
62
63 static const QString ListTemplate =
64 "<!DOCTYPE html>"
65 "<html>"
66 "<head>"
67 "<meta charset=\"utf-8\">"
68 "<title>%1</title>"
69 "</head>"
70 "<body>"
71 "<h1>%1</h1>"
72 "<p>Directory listing:</p>"
73 "<ul>%2</ul>"
74 "<hr>"
75 "<p><em>KikoPlay</em></p>"
76 "</body>"
77 "</html>";
78
79 // Build the response and convert the string to UTF-8
80 QByteArray data = ListTemplate
81 .arg("/" + path.toHtmlEscaped())
82 .arg(listing)
83 .toUtf8();
84
85 // Set the headers and write the content
86 response.setHeader("Content-Type", "text/html");
87 response.write(data, true);
88}
89
90void FileHandler::processFile(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response, const QString &path)
91{

Callers

nothing calls this directly

Calls 5

QStringClass · 0.85
isDirMethod · 0.80
setHeaderMethod · 0.80
appendMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected