Skip to content

Commit

Permalink
bugfix: didnt change downloaded state of file
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanJakobo committed Nov 4, 2020
1 parent 659955c commit 78606e4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 21 deletions.
15 changes: 8 additions & 7 deletions src/handler/eventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "eventHandler.h"
#include "menuHandler.h"
#include "listView.h"
#include "item.h"
#include "util.h"

#include <string>
Expand All @@ -25,6 +24,7 @@ EventHandler::EventHandler()
//create a event to create handlers
_eventHandlerStatic = this;

//TODO use pointer for menu?
_menu = std::unique_ptr<MenuHandler>(new MenuHandler("Nextcloud"));
_nextcloud = std::unique_ptr<Nextcloud>(new Nextcloud());
_loginView = nullptr;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);

}
}

Expand All @@ -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();
}
13 changes: 8 additions & 5 deletions src/ui/listView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ ListView::ListView(irect *contentRect, const vector<Item> &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;
Expand All @@ -43,7 +40,7 @@ ListView::ListView(irect *contentRect, const vector<Item> &items) : _contentRect

while (i > 0)
{
if (z >= itemCount)
if (z >= _itemCount)
{
_page++;
z = 0;
Expand Down Expand Up @@ -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++)
Expand Down
9 changes: 6 additions & 3 deletions src/ui/listView.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class ListView
*/
void drawFooter();

void drawEntry(int itemID);

/**
* iterates through the items and sends them to the listViewEntry Class for drawing
*
Expand All @@ -66,13 +68,14 @@ class ListView
private:
irect *_contentRect;
const vector<Item> _items;
vector<ListViewEntry> _entries;
std::unique_ptr<ifont> _titleFont;
std::unique_ptr<ifont> _footerFont;
vector<ListViewEntry> _entries;
int _page;
int _shownPage;
irect _pageButton;
int _footerHeight;
int _headerHeight;
int _footerHeight = 100;
int _headerHeight = 40;
int _itemCount = 7;
};
#endif
3 changes: 0 additions & 3 deletions src/ui/listViewEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

ListViewEntry::ListViewEntry(int page, irect rect) : _page(page), _position(rect)
{
_fontHeight = 30;
_entryFont = std::unique_ptr<ifont>(OpenFont("LiberationMono", _fontHeight, 1));
_entryFontBold = std::unique_ptr<ifont>(OpenFont("LiberationMono-Bold", _fontHeight, 1));
}

void ListViewEntry::draw(const Item &item)
Expand Down
7 changes: 4 additions & 3 deletions src/ui/listViewEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class ListViewEntry

private:
int _page;
int _fontHeight;
std::unique_ptr<ifont> _entryFont;
std::unique_ptr<ifont> _entryFontBold;
//TODO in central class?
int _fontHeight = 30;
std::unique_ptr<ifont> _entryFont = std::unique_ptr<ifont>(OpenFont("LiberationMono", _fontHeight, 1));;
std::unique_ptr<ifont> _entryFontBold = std::unique_ptr<ifont>(OpenFont("LiberationMono-Bold", _fontHeight, 1));
irect _position;
};
#endif
7 changes: 7 additions & 0 deletions src/util/nextcloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions src/util/nextcloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class Nextcloud

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
*
Expand Down

0 comments on commit 78606e4

Please sign in to comment.