From 10e04c056d61d67da9e8ab4687a62ac28723584a Mon Sep 17 00:00:00 2001 From: JuanJakobo Date: Sun, 31 Jul 2022 13:38:04 +0200 Subject: [PATCH] Add Messaging of Failures and UI fixes --- src/api/webDAV.cpp | 7 ++++-- src/handler/eventHandler.cpp | 36 +++++++++++++++++++++------ src/ui/fileView/fileViewEntry.cpp | 7 ++---- src/ui/webDAVView/webDAVViewEntry.cpp | 2 +- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/api/webDAV.cpp b/src/api/webDAV.cpp index b22cc5d..ca77a11 100644 --- a/src/api/webDAV.cpp +++ b/src/api/webDAV.cpp @@ -198,6 +198,7 @@ string WebDAV::propfind(const string &pathUrl) if (!Util::connectToNetwork()) return ""; + ShowHourglassForce(); //TODO for upload //get etag from current and then send request with FT_ENC_TAG @@ -291,9 +292,11 @@ bool WebDAV::get(WebDAVItem &item) } if (!Util::connectToNetwork()) - return ""; + return false; - UpdateProgressbar(("Starting Download of " + item.localPath).c_str(), 0); + ShowHourglassForce(); + + UpdateProgressbar(("Starting Download of " + item.path).c_str(), 0); CURLcode res; CURL *curl = curl_easy_init(); diff --git a/src/handler/eventHandler.cpp b/src/handler/eventHandler.cpp index b48eea9..c221bb3 100644 --- a/src/handler/eventHandler.cpp +++ b/src/handler/eventHandler.cpp @@ -38,6 +38,10 @@ EventHandler::EventHandler() _menu = std::unique_ptr(new MainMenu("Nextcloud")); if (iv_access(CONFIG_PATH.c_str(), W_OK) == 0) { + //for backwards compatibilty + if (Util::accessConfig(CONFIG_PATH, Action::IReadString, "storageLocation").empty()) + Util::accessConfig(CONFIG_PATH, Action::IWriteString, "storageLocation", "/mnt/ext1/nextcloud"); + if (iv_access(Util::accessConfig(CONFIG_PATH, Action::IReadString, "storageLocation").c_str(), W_OK) != 0) iv_mkdir(Util::accessConfig(CONFIG_PATH, Action::IReadString, "storageLocation").c_str(), 0777); std::vector currentWebDAVItems; @@ -246,19 +250,32 @@ void EventHandler::contextMenuHandler(const int index) //Sync case 102: { - startDownload(); + if (_webDAVView->getCurrentEntry().state != FileState::ILOCAL) + { + startDownload(); + } + else + { + //TODO upload to cloud + Message(ICON_ERROR, "Error", "The File is local and upload to cloud is currently not supported.", 2000); + _webDAVView->invertCurrentEntryColor(); + } + break; } //remove case 103: { - ShowHourglassForce(); - if (_webDAVView->getCurrentEntry().state == FileState::ISYNCED || _webDAVView->getCurrentEntry().state == FileState::IOUTSYNCED) + if (_webDAVView->getCurrentEntry().state != FileState::ICLOUD) { if (_webDAVView->getCurrentEntry().type == Itemtype::IFOLDER) { - string cmd = "rm -rf " + _webDAVView->getCurrentEntry().localPath + "/"; - system(cmd.c_str()); + Message(ICON_ERROR, "Error", "Currently only files can be deleted.", 2000); + //string cmd = "rm -rf " + _webDAVView->getCurrentEntry().localPath + '/'; + //if (rmdir((_webDAVView->getCurrentEntry().localPath + '/').c_str()) == 0) + //Log::writeInfoLog("okay"); + //if (system(cmd.c_str()) == 0) + //Log::writeInfoLog("success"); } else { @@ -268,8 +285,11 @@ void EventHandler::contextMenuHandler(const int index) updateItems(currentWebDAVItems); drawWebDAVItems(currentWebDAVItems); } - - HideHourglass(); + else + { + Message(ICON_ERROR, "Error", "File is not available.", 1000); + _webDAVView->invertCurrentEntryColor(); + } break; } default: @@ -403,6 +423,7 @@ void EventHandler::openItem() _webDAVView->getCurrentEntry().fileType.find("text/plain") != string::npos || _webDAVView->getCurrentEntry().fileType.find("text/html") != string::npos || _webDAVView->getCurrentEntry().fileType.find("text/rtf") != string::npos || + _webDAVView->getCurrentEntry().fileType.find("text/markdown") != string::npos || _webDAVView->getCurrentEntry().fileType.find("application/msword") != string::npos || _webDAVView->getCurrentEntry().fileType.find("application/x-mobipocket-ebook") != string::npos || _webDAVView->getCurrentEntry().fileType.find("application/vnd.openxmlformats-officedocument.wordprocessingml.document") != string::npos || @@ -570,6 +591,7 @@ void EventHandler::downloadFolder(vector &items, int itemID) if (items.at(itemID).state == FileState::IOUTSYNCED || items.at(itemID).state == FileState::ICLOUD) { Log::writeInfoLog(path + "outsynced"); + UpdateProgressbar(("Syncing folder" + path).c_str(), 0); tempItems = _webDAV.getDataStructure(path); updateItems(tempItems); } diff --git a/src/ui/fileView/fileViewEntry.cpp b/src/ui/fileView/fileViewEntry.cpp index 9f43cec..17d3ad8 100644 --- a/src/ui/fileView/fileViewEntry.cpp +++ b/src/ui/fileView/fileViewEntry.cpp @@ -23,12 +23,9 @@ void FileViewEntry::draw(const ifont *entryFont, const ifont *entryFontBold, int SetFont(entryFont, BLACK); - //DrawTextRect(_position.x, _position.y + heightOfTitle, _position.w, fontHeight, _entry.name.c_str(), ALIGN_LEFT); DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, _entry.path.c_str(), ALIGN_LEFT); - std::string type = "File"; - if(_entry.type == Type::FFOLDER) - type = "Folder"; - DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, type.c_str(), ALIGN_RIGHT); + const char *type = _entry.type == Type::FFOLDER ? "Folder" : "File"; + DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, type, ALIGN_RIGHT); int line = (_position.y + _position.h) - 1; DrawLine(0, line, ScreenWidth(), line, BLACK); diff --git a/src/ui/webDAVView/webDAVViewEntry.cpp b/src/ui/webDAVView/webDAVViewEntry.cpp index c457bfe..bcd6289 100644 --- a/src/ui/webDAVView/webDAVViewEntry.cpp +++ b/src/ui/webDAVView/webDAVViewEntry.cpp @@ -31,7 +31,7 @@ void WebDAVViewEntry::draw(const ifont *entryFont, const ifont *entryFontBold, i if (_entry.state == FileState::ILOCAL) { - DrawTextRect(_position.x, _position.y + heightOfTitle + 2 * fontHeight, _position.w, fontHeight, "Local", ALIGN_RIGHT); + DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, "Local", ALIGN_RIGHT); } else {