diff --git a/src/handler/eventHandler.cpp b/src/handler/eventHandler.cpp index 05b9bef..728988f 100644 --- a/src/handler/eventHandler.cpp +++ b/src/handler/eventHandler.cpp @@ -10,7 +10,6 @@ #include "eventHandler.h" #include "menuHandler.h" #include "listView.h" -#include "item.h" #include "util.h" #include @@ -25,6 +24,7 @@ EventHandler::EventHandler() //create a event to create handlers _eventHandlerStatic = this; + //TODO use pointer for menu? _menu = std::unique_ptr(new MenuHandler("Nextcloud")); _nextcloud = std::unique_ptr(new Nextcloud()); _loginView = nullptr; @@ -141,15 +141,11 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2) } else { - int dialogResult = 4; + int dialogResult = 2; if (_nextcloud->getItems()[itemID].isDownloaded()) { dialogResult = DialogSynchro(ICON_QUESTION, "Action", "What do you want to do?", "Open", "Sync", "Remove"); } - else - { - dialogResult = 2; - } switch (dialogResult) { @@ -171,12 +167,16 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2) } break; case 3: - _nextcloud->getItems()[itemID].removeFile(); + _nextcloud->removeFile(itemID); break; default: break; } + //TODO pass items only as ref, so this is not necessary and items exist only once + _listView.reset(new ListView(_menu->getContentRect(), _nextcloud->getItems())); + //_listView->drawEntry(itemID); + } } @@ -203,5 +203,6 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2) void EventHandler::DialogHandlerStatic(const int clicked) { + //TODO cannot interact with it //CloseProgressbar(); } diff --git a/src/ui/listView.cpp b/src/ui/listView.cpp index c0139e3..91d7cd9 100644 --- a/src/ui/listView.cpp +++ b/src/ui/listView.cpp @@ -28,10 +28,7 @@ ListView::ListView(irect *contentRect, const vector &items) : _contentRect _entries.clear(); - int itemCount = 7; - _footerHeight = 100; - _headerHeight = 40; - int entrySize = (_contentRect->h - _footerHeight - _headerHeight) / itemCount; + int entrySize = (_contentRect->h - _footerHeight - _headerHeight) / _itemCount; _shownPage = 1; _page = 1; @@ -43,7 +40,7 @@ ListView::ListView(irect *contentRect, const vector &items) : _contentRect while (i > 0) { - if (z >= itemCount) + if (z >= _itemCount) { _page++; z = 0; @@ -83,6 +80,12 @@ void ListView::drawFooter() DrawTextRect2(&_pageButton, footer.c_str()); } +void ListView::drawEntry(int itemID) +{ + FillAreaRect(_entries[itemID].getPosition(),WHITE); + _entries[itemID].draw(_items[itemID]); +} + void ListView::drawEntries() { for (auto i = 0; i < _entries.size(); i++) diff --git a/src/ui/listView.h b/src/ui/listView.h index 37ac107..bf816d4 100644 --- a/src/ui/listView.h +++ b/src/ui/listView.h @@ -48,6 +48,8 @@ public: */ void drawFooter(); + void drawEntry(int itemID); + /** * iterates through the items and sends them to the listViewEntry Class for drawing * @@ -66,13 +68,14 @@ public: private: irect *_contentRect; const vector _items; + vector _entries; std::unique_ptr _titleFont; std::unique_ptr _footerFont; - vector _entries; int _page; int _shownPage; irect _pageButton; - int _footerHeight; - int _headerHeight; + int _footerHeight = 100; + int _headerHeight = 40; + int _itemCount = 7; }; #endif \ No newline at end of file diff --git a/src/ui/listViewEntry.cpp b/src/ui/listViewEntry.cpp index 4f8cc26..7829e3a 100644 --- a/src/ui/listViewEntry.cpp +++ b/src/ui/listViewEntry.cpp @@ -15,9 +15,6 @@ ListViewEntry::ListViewEntry(int page, irect rect) : _page(page), _position(rect) { - _fontHeight = 30; - _entryFont = std::unique_ptr(OpenFont("LiberationMono", _fontHeight, 1)); - _entryFontBold = std::unique_ptr(OpenFont("LiberationMono-Bold", _fontHeight, 1)); } void ListViewEntry::draw(const Item &item) diff --git a/src/ui/listViewEntry.h b/src/ui/listViewEntry.h index 60b6a2e..ce2c9f8 100644 --- a/src/ui/listViewEntry.h +++ b/src/ui/listViewEntry.h @@ -37,9 +37,10 @@ public: private: int _page; - int _fontHeight; - std::unique_ptr _entryFont; - std::unique_ptr _entryFontBold; + //TODO in central class? + int _fontHeight = 30; + std::unique_ptr _entryFont = std::unique_ptr(OpenFont("LiberationMono", _fontHeight, 1));; + std::unique_ptr _entryFontBold = std::unique_ptr(OpenFont("LiberationMono-Bold", _fontHeight, 1)); irect _position; }; #endif \ No newline at end of file diff --git a/src/util/nextcloud.cpp b/src/util/nextcloud.cpp index 502f1fb..20bfeef 100644 --- a/src/util/nextcloud.cpp +++ b/src/util/nextcloud.cpp @@ -157,6 +157,13 @@ bool Nextcloud::downloadItem(int itemID) return false; } + +bool Nextcloud::removeFile(int itemID) +{ + remove(_items[itemID].getLocalPath().c_str()); + _items[itemID].setDownloaded(false); +} + bool Nextcloud::getDataStructure(string &pathUrl) { return getDataStructure(pathUrl, this->getUsername(), this->getPassword()); diff --git a/src/util/nextcloud.h b/src/util/nextcloud.h index 9d3beb0..b444f1b 100644 --- a/src/util/nextcloud.h +++ b/src/util/nextcloud.h @@ -45,6 +45,9 @@ public: bool downloadItem(int itemID); + bool removeFile(int itemID); + + /** * gets the dataStructure of the given URL and writes its WEBDAV items to the items vector, reads Userdata from configfile *