diff --git a/README.md b/README.md index 856546d..a5d344b 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,6 @@ Download and unzip the file from releases and place the nextcloud.app into the " To login type the servername (e.g. https://domainname) or the WebDAV URL (e.g. htts://domainname/remote.php/dav/files/UUID) (You can look up the WebDAV URL in the files app->seetings.), Username and Password. You then will be redirected to the root file folder of your nextcloud instance. To download a file, click on it. A synced file can be either opened, synced or removed. -### Known issues -* The main menu of the PB shows new books only if it turns into sleep modus. Otherwise the new books can only be opened from the nextcloud applicaton. - ## How to build First you need to install the basic build tools for linux. diff --git a/src/handler/eventHandler.cpp b/src/handler/eventHandler.cpp index 8fa6df6..9383adc 100644 --- a/src/handler/eventHandler.cpp +++ b/src/handler/eventHandler.cpp @@ -53,6 +53,8 @@ int EventHandler::eventDistributor(const int type, const int par1, const int par { if (ISPOINTEREVENT(type)) return EventHandler::pointerHandler(type, par1, par2); + else if (ISKEYEVENT(type)) + return EventHandler::keyHandler(type, par1, par2); return 0; } @@ -189,7 +191,24 @@ void EventHandler::contextMenuHandler(const int index) int EventHandler::pointerHandler(const int type, const int par1, const int par2) { - if (type == EVT_POINTERDOWN) + //long press to open up context menu + if (type == EVT_POINTERLONG) + { + if (_listView != nullptr) + { + tempItemID = _listView->listClicked(par1, par2); + _listView->invertEntryColor(tempItemID); + if (tempItemID != -1) + { + if (_nextcloud.getItems().at(tempItemID).getTitle().compare("...") != 0) + { + _contextMenu = std::unique_ptr(new ContextMenu()); + _contextMenu->createMenu(par2, _nextcloud.getItems().at(tempItemID).getState(), EventHandler::contextMenuHandlerStatic); + } + } + } + } + else if (type == EVT_POINTERUP) { //menu is clicked if (IsInRect(par1, par2, _menu.getMenuButtonRect()) == 1) @@ -199,88 +218,99 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2) //if listView is shown else if (_listView != nullptr) { - int itemID = _listView->listClicked(par1, par2); - if (itemID != -1) + tempItemID = _listView->listClicked(par1, par2); + _listView->invertEntryColor(tempItemID); + if (tempItemID != -1) { - int dialogResult = 0; - if (_nextcloud.getItems().at(itemID).getType() == Itemtype::IFOLDER) + if (_nextcloud.getItems().at(tempItemID).getType() == Itemtype::IFOLDER) { - if (_nextcloud.getItems().at(itemID).getTitle().compare("...") == 0) - { - dialogResult = 1; - } - else - { - dialogResult = DialogSynchro(ICON_QUESTION, "Action", "What do you want to to do?", "Open folder", "Sync Folder", "Cancel"); - } - - switch (dialogResult) - { - case 1: - FillAreaRect(_menu.getContentRect(), WHITE); - _menu.drawLoadingScreen(); - - _tempPath = _nextcloud.getItems().at(itemID).getPath(); - if (!_tempPath.empty()) - _nextcloud.setItems(_nextcloud.getDataStructure(_tempPath)); - _listView.release(); - _listView = std::unique_ptr(new ListView(_menu.getContentRect(), _nextcloud.getItems())); - _listView->drawHeader(_tempPath.substr(NEXTCLOUD_ROOT_PATH.length())); - break; - case 2: - dialogResult = 0; - default: - break; - } + openFolder(); } else { - if (_nextcloud.getItems().at(itemID).getState() == FileState::ISYNCED || (_nextcloud.isWorkOffline() && _nextcloud.getItems().at(itemID).getState() == FileState::IOUTSYNCED)) + if (_nextcloud.getItems().at(tempItemID).getState() == FileState::ISYNCED || (_nextcloud.isWorkOffline() && _nextcloud.getItems().at(tempItemID).getState() == FileState::IOUTSYNCED)) { - dialogResult = DialogSynchro(ICON_QUESTION, "Action", "What do you want to do?", "Open", "Remove", "Cancel"); - - switch (dialogResult) - { - case 1: - _nextcloud.getItems().at(itemID).open(); - break; - case 2: - if (!_nextcloud.removeItem(itemID)) - Message(ICON_WARNING, "Warning", "Could not delete the file, please try again.", 1200); - _listView->drawEntry(itemID); - break; - default: - break; - } + openItem(); } - } - - if (dialogResult == 0) - { - if (_nextcloud.isWorkOffline()) + else { - int dialogResult = DialogSynchro(ICON_QUESTION, "Action", "You are in offline modus. Go back online?", "Yes", "No", "Cancel"); - if (dialogResult == 2 || dialogResult == 3) - return 1; - _nextcloud.switchWorkOffline(); + startDownload(); } - OpenProgressbar(1, "Downloading...", "Check network connection", 0, EventHandler::DialogHandlerStatic); - try - { - _nextcloud.download(itemID); - } - catch (const std::exception &e) - { - Log::writeLog(e.what()); - Message(ICON_ERROR, "Error", "Something has gone wrong. Please check the logs. (/system/config/nextcloud/)", 1200); - - } - CloseProgressbar(); - _listView->drawEntry(itemID); } } - PartialUpdate(_menu.getContentRect()->x, _menu.getContentRect()->y, _menu.getContentRect()->w, _menu.getContentRect()->h); + return 1; + } + //if loginView is shown + else if (_loginView != nullptr) + { + if (_loginView->logginClicked(par1, par2) == 2) + { + ShowHourglassForce(); + + if (_nextcloud.login(_loginView->getURL(), _loginView->getUsername(), _loginView->getPassword())) + { + _listView = std::unique_ptr(new ListView(_menu.getContentRect(), _nextcloud.getItems())); + _loginView.reset(); + + FullUpdate(); + } + else + { + HideHourglass(); + Log::writeLog("login failed."); + } + return 1; + } + } + } + return 0; +} + +void EventHandler::startDownload() +{ + if (_nextcloud.isWorkOffline()) + { + int dialogResult = DialogSynchro(ICON_QUESTION, "Action", "You are in offline modus. Go back online?", "Yes", "No", "Cancel"); + if (dialogResult == 2 || dialogResult == 3) + return; // 1; + _nextcloud.switchWorkOffline(); + } + OpenProgressbar(1, "Downloading...", "Check network connection", 0, EventHandler::DialogHandlerStatic); + try + { + _nextcloud.download(tempItemID); + } + catch (const std::exception &e) + { + Log::writeLog(e.what()); + Message(ICON_ERROR, "Error", "Something has gone wrong. Please check the logs. (/system/config/nextcloud/)", 1200); + } + Util::updatePBLibrary(); + + CloseProgressbar(); + _listView->drawEntry(tempItemID); +} + +void EventHandler::openItem() +{ + _listView->invertEntryColor(tempItemID); + _nextcloud.getItems().at(tempItemID).open(); +} + +void EventHandler::openFolder() +{ + FillAreaRect(_menu.getContentRect(), WHITE); + ShowHourglassForce(); + + _tempPath = _nextcloud.getItems().at(tempItemID).getPath(); + if (!_tempPath.empty()) + _nextcloud.setItems(_nextcloud.getDataStructure(_tempPath)); + _listView.release(); + _listView = std::unique_ptr(new ListView(_menu.getContentRect(), _nextcloud.getItems())); + _listView->drawHeader(_tempPath.substr(NEXTCLOUD_ROOT_PATH.length())); + PartialUpdate(_menu.getContentRect()->x, _menu.getContentRect()->y, _menu.getContentRect()->w, _menu.getContentRect()->h); +} int EventHandler::keyHandler(const int type, const int par1, const int par2) { diff --git a/src/handler/eventHandler.h b/src/handler/eventHandler.h index de33fb3..e8592b4 100644 --- a/src/handler/eventHandler.h +++ b/src/handler/eventHandler.h @@ -45,6 +45,7 @@ private: MainMenu _menu = MainMenu("Nextcloud"); Nextcloud _nextcloud = Nextcloud(); std::string _tempPath; + int tempItemID; /** * Function needed to call C function, redirects to real function @@ -85,6 +86,25 @@ private: */ int pointerHandler(const int type, const int par1, const int par2); + /** + * Starts the download of an item + * + */ + void startDownload(); + + /** + * Open a folder + * + */ + void openFolder(); + + + /** + * Open a item + * + */ + void openItem(); + /** * Handles key Events * diff --git a/src/util/util.cpp b/src/util/util.cpp index b500a33..693de78 100644 --- a/src/util/util.cpp +++ b/src/util/util.cpp @@ -13,6 +13,11 @@ #include #include +#include + +pid_t child_pid = -1; //Global + + using std::string; size_t Util::writeCallback(void *contents, size_t size, size_t nmemb, void *userp) @@ -89,4 +94,31 @@ void Util::decodeUrl(string &text) curl_free(buffer); curl_easy_cleanup(curl); +} + +void kill_child(int sig) +{ + //SIGKILL + kill(child_pid, SIGTERM); +} + +void Util::updatePBLibrary() +{ + //TODO how determine time? + UpdateProgressbar("Updating PB library", 50); + //https://stackoverflow.com/questions/6501522/how-to-kill-a-child-process-by-the-parent-process + signal(SIGALRM, (void (*)(int))kill_child); + child_pid = fork(); + if (child_pid > 0) + { + //parent + alarm(5); + wait(NULL); + } + else if (child_pid == 0) + { + //child + string cmd = "/ebrmain/bin/scanner.app"; + execlp(cmd.c_str(), cmd.c_str(), (char *)NULL); + } } \ No newline at end of file diff --git a/src/util/util.h b/src/util/util.h index a43458e..4e8379c 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -53,6 +53,11 @@ public: */ static void decodeUrl(std::string &text); + /** + * Updates the library of the Pocketbook + * + */ + static void updatePBLibrary(); private: Util() {}