From b39ae2a8b4d2bddf054a45d52f9f52c0e971aaa1 Mon Sep 17 00:00:00 2001 From: Roland Stigge Date: Thu, 11 Jan 2018 20:18:29 +0100 Subject: Add logout, rename and ui improvements --- src/webbox.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 6 deletions(-) (limited to 'src/webbox.cpp') diff --git a/src/webbox.cpp b/src/webbox.cpp index d0cfebc..51b6436 100644 --- a/src/webbox.cpp +++ b/src/webbox.cpp @@ -343,12 +343,16 @@ class InfoCommand: public PostCommand { QFileInfo fileInfo(m_path + "/" + filename); qint64 size = fileInfo.size(); QString date = fileInfo.lastModified().toString(); - QString type = fileInfo.isDir() ? "directory" : "file"; - FCGX_PutS(QString("%1, %2 bytes, %3 (%4)
") - .arg(filename) - .arg(size) - .arg(date) - .arg(type).toUtf8().data(), p.request.out); + if (fileInfo.isDir()) { + FCGX_PutS(QString("%1, %2 (folder)
") + .arg(filename) + .arg(date).toUtf8().data(), p.request.out); + } else { + FCGX_PutS(QString("%1, %2 bytes, %3 (file)
") + .arg(filename) + .arg(size) + .arg(date).toUtf8().data(), p.request.out); + } } } } @@ -547,6 +551,51 @@ class MoveCommand: public PostCommand { } }; +class RenameCommand: public PostCommand { + public: + RenameCommand() { + m_commandName = "rename"; + m_isWriteCommand = true; + } + + protected: + virtual void start(CommandParameters& p) { + if (!readContent(p)) + return; + + QXmlStreamReader xml(m_content); + + QString oldname; + QString newname; + + while (!xml.atEnd()) { + while (xml.readNextStartElement()) { + if (xml.name() == "request") { + while (xml.readNextStartElement()) { + if (xml.name() == "oldname") { + oldname = xml.readElementText(); + } else + if (xml.name() == "newname") { + newname = xml.readElementText(); + } + } + } + } + } + + QDir dir(m_path); + QString response; + if (!dir.rename(oldname, newname)) { + response = QString("Error renaming %1 to %2
").arg(oldname).arg(newname); + } else { + response = "OK"; + } + + FCGX_PutS("Content-Type: text/plain\r\n\r\n", p.request.out); + FCGX_PutS(response.toUtf8().data(), p.request.out); + } +}; + class UploadCommand: public PostCommand { public: UploadCommand() { @@ -712,6 +761,9 @@ int main(int argc, char* argv[]) { MoveCommand moveCommand; commands.registerCommand(moveCommand); + RenameCommand renameCommand; + commands.registerCommand(renameCommand); + UploadCommand uploadCommand; commands.registerCommand(uploadCommand); -- cgit v1.2.3