use list framework over old method
parent
b5eba5346c
commit
673e15f164
|
@ -54,9 +54,11 @@ set(SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp
|
|||
${CMAKE_SOURCE_DIR}/src/handler/mainMenu.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/util/nextcloud.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/util/item.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/listView.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/listViewEntry.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/loginView.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/listView/listView.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/listView/listViewEntry.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/webDAVView/webDAVView.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/webDAVView/webDAVViewEntry.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/ui/loginView/loginView.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/util/util.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/util/log.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/api/webDAV.cpp
|
||||
|
@ -72,6 +74,9 @@ include_directories(
|
|||
${CMAKE_SOURCE_DIR}/src/handler/
|
||||
${CMAKE_SOURCE_DIR}/src/util/
|
||||
${CMAKE_SOURCE_DIR}/src/ui/
|
||||
${CMAKE_SOURCE_DIR}/src/ui/listView/
|
||||
${CMAKE_SOURCE_DIR}/src/ui/webDAVView/
|
||||
${CMAKE_SOURCE_DIR}/src/ui/loginView/
|
||||
${CMAKE_SOURCE_DIR}/src/api/
|
||||
)
|
||||
|
||||
|
|
|
@ -10,14 +10,17 @@
|
|||
#include "eventHandler.h"
|
||||
#include "mainMenu.h"
|
||||
#include "contextMenu.h"
|
||||
#include "listView.h"
|
||||
#include "webDAVView.h"
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
#include "webDAV.h"
|
||||
#include "webDAVModel.h"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
std::unique_ptr<EventHandler> EventHandler::_eventHandlerStatic;
|
||||
|
||||
|
@ -27,25 +30,34 @@ EventHandler::EventHandler()
|
|||
_eventHandlerStatic = std::unique_ptr<EventHandler>(this);
|
||||
|
||||
_loginView = nullptr;
|
||||
_listView = nullptr;
|
||||
_webDAVView = nullptr;
|
||||
|
||||
if (iv_access(NEXTCLOUD_CONFIG_PATH.c_str(), W_OK) == 0)
|
||||
{
|
||||
if (_nextcloud.login())
|
||||
{
|
||||
_listView = std::unique_ptr<ListView>(new ListView(_menu.getContentRect(), _nextcloud.getItems()));
|
||||
FullUpdate();
|
||||
return;
|
||||
}
|
||||
else
|
||||
//if (_nextcloud.login())
|
||||
//this one is always required --> if does not work -> say to the user that it did not work, to sync use
|
||||
//menubar
|
||||
//explanation on first login?
|
||||
//TODO here mark folders that are unsynced?
|
||||
//compare both datasets, if fromDB etag is different, mark as unsycned
|
||||
WebDAV test = WebDAV();
|
||||
_currentWebDAVItems = test.getDataStructure(Util::accessConfig(Action::IReadString,"UUID"));
|
||||
//vector<WebDAVItem> fromDB = _sqllite.getItemsChildren(_tempPath);
|
||||
if(_currentWebDAVItems.empty())
|
||||
{
|
||||
Message(ICON_ERROR, "Error", "Could not login, please try again.", 1200);
|
||||
_nextcloud.logout();
|
||||
}
|
||||
else
|
||||
{
|
||||
_webDAVView = std::unique_ptr<WebDAVView>(new WebDAVView(_menu.getContentRect(), _currentWebDAVItems,1));
|
||||
_sqllite.saveItemsChildren(_currentWebDAVItems);
|
||||
FullUpdate();
|
||||
//TODO avoid
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_loginView = std::unique_ptr<LoginView>(new LoginView(_menu.getContentRect()));
|
||||
|
||||
FullUpdate();
|
||||
}
|
||||
|
||||
|
@ -112,7 +124,7 @@ void EventHandler::mainMenuHandler(const int index)
|
|||
_nextcloud.logout();
|
||||
break;
|
||||
}
|
||||
_listView.release();
|
||||
_webDAVView.release();
|
||||
_loginView = std::unique_ptr<LoginView>(new LoginView(_menu.getContentRect()));
|
||||
FullUpdate();
|
||||
break;
|
||||
|
@ -171,7 +183,7 @@ void EventHandler::contextMenuHandler(const int index)
|
|||
{
|
||||
updatePBLibrary();
|
||||
CloseProgressbar();
|
||||
_listView->drawEntry(_tempItemID);
|
||||
_webDAVView->reDrawCurrentEntry();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -182,7 +194,7 @@ void EventHandler::contextMenuHandler(const int index)
|
|||
}
|
||||
default:
|
||||
{
|
||||
_listView->invertEntryColor(_tempItemID);
|
||||
_webDAVView->invertCurrentEntryColor();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -195,13 +207,13 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
|||
//long press to open up context menu
|
||||
if (type == EVT_POINTERLONG)
|
||||
{
|
||||
if (_listView != nullptr)
|
||||
if (_webDAVView != nullptr)
|
||||
{
|
||||
_tempItemID = _listView->listClicked(par1, par2);
|
||||
_listView->invertEntryColor(_tempItemID);
|
||||
_webDAVView->checkIfEntryClicked(par1, par2);
|
||||
_webDAVView->invertCurrentEntryColor();
|
||||
if (_tempItemID != -1)
|
||||
{
|
||||
if (_nextcloud.getItems().at(_tempItemID).getTitle().compare("...") != 0)
|
||||
if (_webDAVView->getCurrentEntry()->title.compare("...") != 0)
|
||||
{
|
||||
_contextMenu = std::unique_ptr<ContextMenu>(new ContextMenu());
|
||||
_contextMenu->createMenu(par2, _nextcloud.getItems().at(_tempItemID).getState(), EventHandler::contextMenuHandlerStatic);
|
||||
|
@ -216,21 +228,20 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
|||
{
|
||||
return _menu.createMenu(_nextcloud.isLoggedIn(), _nextcloud.isWorkOffline(), EventHandler::mainMenuHandlerStatic);
|
||||
}
|
||||
//if listView is shown
|
||||
else if (_listView != nullptr)
|
||||
//if webDAVView is shown
|
||||
else if (_webDAVView != nullptr)
|
||||
{
|
||||
_tempItemID = _listView->listClicked(par1, par2);
|
||||
if (_tempItemID != -1)
|
||||
if(_webDAVView->checkIfEntryClicked(par1, par2))
|
||||
{
|
||||
_listView->invertEntryColor(_tempItemID);
|
||||
_webDAVView->invertCurrentEntryColor();
|
||||
|
||||
if (_nextcloud.getItems().at(_tempItemID).getType() == Itemtype::IFOLDER)
|
||||
if (_webDAVView->getCurrentEntry()->type == Itemtype::IFOLDER)
|
||||
{
|
||||
openFolder();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_nextcloud.getItems().at(_tempItemID).getState() == FileState::ISYNCED || (_nextcloud.isWorkOffline() && _nextcloud.getItems().at(_tempItemID).getState() == FileState::IOUTSYNCED))
|
||||
if (_webDAVView->getCurrentEntry()->state == FileState::ISYNCED || (_nextcloud.isWorkOffline() && _nextcloud.getItems().at(_tempItemID).getState() == FileState::IOUTSYNCED))
|
||||
{
|
||||
openItem();
|
||||
}
|
||||
|
@ -250,9 +261,10 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
|||
{
|
||||
ShowHourglassForce();
|
||||
|
||||
//TODO replace
|
||||
if (_nextcloud.login(_loginView->getURL(), _loginView->getUsername(), _loginView->getPassword()))
|
||||
{
|
||||
_listView = std::unique_ptr<ListView>(new ListView(_menu.getContentRect(), _nextcloud.getItems()));
|
||||
_webDAVView = std::unique_ptr<WebDAVView>(new WebDAVView(_menu.getContentRect(), _currentWebDAVItems,1));
|
||||
_loginView.reset();
|
||||
|
||||
FullUpdate();
|
||||
|
@ -284,13 +296,6 @@ void EventHandler::updatePBLibrary()
|
|||
|
||||
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...", "Checking network connection", 0, NULL);
|
||||
try
|
||||
{
|
||||
|
@ -298,32 +303,45 @@ void EventHandler::startDownload()
|
|||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
Log::writeLog(e.what());
|
||||
Log::writeErrorLog(e.what());
|
||||
Message(ICON_ERROR, "Error", "Something has gone wrong. Please check the logs. (/system/config/nextcloud/)", 1200);
|
||||
}
|
||||
updatePBLibrary();
|
||||
|
||||
CloseProgressbar();
|
||||
_listView->drawEntry(_tempItemID);
|
||||
_webDAVView->reDrawCurrentEntry();
|
||||
}
|
||||
|
||||
void EventHandler::openItem()
|
||||
{
|
||||
_listView->invertEntryColor(_tempItemID);
|
||||
_webDAVView->invertCurrentEntryColor();
|
||||
_nextcloud.getItems().at(_tempItemID).open();
|
||||
}
|
||||
|
||||
void EventHandler::openFolder()
|
||||
{
|
||||
FillAreaRect(_menu.getContentRect(), WHITE);
|
||||
////TODO hourglass needed?
|
||||
ShowHourglassForce();
|
||||
|
||||
_tempPath = _nextcloud.getItems().at(_tempItemID).getPath();
|
||||
if (!_tempPath.empty())
|
||||
{
|
||||
_nextcloud.setItems(_nextcloud.getDataStructure(_tempPath));
|
||||
_listView.release();
|
||||
_listView = std::unique_ptr<ListView>(new ListView(_menu.getContentRect(), _nextcloud.getItems()));
|
||||
_listView->drawHeader(_tempPath.substr(NEXTCLOUD_ROOT_PATH.length()));
|
||||
//if folder is unsynced sync
|
||||
WebDAV test = WebDAV();
|
||||
vector<WebDAVItem> testitems = test.getDataStructure(_tempPath);
|
||||
_sqllite.saveItemsChildren(testitems);
|
||||
|
||||
//if folder is synced, get only from DB
|
||||
vector<WebDAVItem> fromDB = _sqllite.getItemsChildren(_tempPath);
|
||||
//get etags from DB, if etag for path is unchanged, stays the same, same for foldersjj
|
||||
}
|
||||
_webDAVView.release();
|
||||
_webDAVView = std::unique_ptr<WebDAVView>(new WebDAVView(_menu.getContentRect(), _currentWebDAVItems,1));
|
||||
//_sqllite.saveItemsChildren(_nextcloud.getItems());
|
||||
//TODO include the header (where am i currently aka)
|
||||
//_webDAVView->drawHeader(_tempPath.substr(NEXTCLOUD_ROOT_PATH.length()));
|
||||
PartialUpdate(_menu.getContentRect()->x, _menu.getContentRect()->y, _menu.getContentRect()->w, _menu.getContentRect()->h);
|
||||
}
|
||||
|
||||
|
@ -334,19 +352,19 @@ int EventHandler::keyHandler(const int type, const int par1, const int par2)
|
|||
//menu button
|
||||
if (par1 == 23)
|
||||
{
|
||||
_listView->firstPage();
|
||||
_webDAVView->firstPage();
|
||||
}
|
||||
else if (_listView != nullptr)
|
||||
else if (_webDAVView != nullptr)
|
||||
{
|
||||
//left button
|
||||
if (par1 == 24)
|
||||
{
|
||||
_listView->prevPage();
|
||||
_webDAVView->prevPage();
|
||||
}
|
||||
//right button
|
||||
else if (par1 == 25)
|
||||
{
|
||||
_listView->nextPage();
|
||||
_webDAVView->nextPage();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -12,12 +12,15 @@
|
|||
#include "contextMenu.h"
|
||||
#include "mainMenu.h"
|
||||
#include "nextcloud.h"
|
||||
#include "listView.h"
|
||||
#include "webDAVView.h"
|
||||
#include "loginView.h"
|
||||
#include "sqliteConnector.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
const std::string LOG_PATH = "/mnt/ext1/system/config/nextcloud";
|
||||
const std::string CONFIG_FOLDER = "/mnt/ext1/system/config/nextcloud";
|
||||
//TODO use folder of nextcloud conifg temp
|
||||
const std::string DB_PATH = CONFIG_FOLDER + "/data.db";
|
||||
|
||||
class EventHandler
|
||||
{
|
||||
|
@ -39,11 +42,13 @@ public:
|
|||
|
||||
private:
|
||||
static std::unique_ptr<EventHandler> _eventHandlerStatic;
|
||||
std::unique_ptr<ListView> _listView;
|
||||
std::unique_ptr<WebDAVView> _webDAVView;
|
||||
std::unique_ptr<LoginView> _loginView;
|
||||
std::unique_ptr<ContextMenu> _contextMenu;
|
||||
std::vector<WebDAVItem> _currentWebDAVItems;
|
||||
MainMenu _menu = MainMenu("Nextcloud");
|
||||
Nextcloud _nextcloud = Nextcloud();
|
||||
SqliteConnector _sqllite = SqliteConnector(DB_PATH);
|
||||
std::string _tempPath;
|
||||
int _tempItemID;
|
||||
|
||||
|
|
|
@ -1,186 +0,0 @@
|
|||
//------------------------------------------------------------------
|
||||
// listView.cpp
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 04.08.2020
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#include "inkview.h"
|
||||
#include "item.h"
|
||||
#include "util.h"
|
||||
#include "listView.h"
|
||||
#include "listViewEntry.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
ListView::ListView(const irect *contentRect, const vector<Item> &items) : _contentRect(contentRect), _items(&items)
|
||||
{
|
||||
FillAreaRect(_contentRect, WHITE);
|
||||
|
||||
_entries.clear();
|
||||
|
||||
int entrySize = _contentRect->h / (_itemCount + 1);
|
||||
|
||||
_headerHeight = 0.25 * entrySize;
|
||||
_footerHeight = 0.75 * entrySize;
|
||||
|
||||
_headerFontHeight = 0.8 * _headerHeight;
|
||||
_footerFontHeight = 0.3 * _footerHeight;
|
||||
_entryFontHeight = 0.2 * entrySize;
|
||||
|
||||
_headerFont = OpenFont("LiberationMono", _headerFontHeight, FONT_STD);
|
||||
_footerFont = OpenFont("LiberationMono", _footerFontHeight, FONT_STD);
|
||||
_entryFont = OpenFont("LiberationMono", _entryFontHeight, FONT_STD);
|
||||
_entryFontBold = OpenFont("LiberationMono-Bold", _entryFontHeight, FONT_BOLD);
|
||||
|
||||
_page = 1;
|
||||
_shownPage = _page;
|
||||
|
||||
auto i = _items->size();
|
||||
auto z = 0;
|
||||
|
||||
_entries.reserve(i);
|
||||
|
||||
while (i > 0)
|
||||
{
|
||||
if (z >= _itemCount)
|
||||
{
|
||||
_page++;
|
||||
z = 0;
|
||||
}
|
||||
|
||||
irect rect = iRect(_contentRect->x, z * entrySize + _headerHeight + _contentRect->y, _contentRect->w, entrySize, 0);
|
||||
this->_entries.emplace_back(_page, rect);
|
||||
i--;
|
||||
z++;
|
||||
}
|
||||
|
||||
_pageIcon = iRect(_contentRect->w - 100, _contentRect->h + _contentRect->y - _footerHeight, 100, _footerHeight, ALIGN_CENTER);
|
||||
|
||||
_firstPageButton = iRect(_contentRect->x, _contentRect->h + _contentRect->y - _footerHeight, 130, _footerHeight, ALIGN_CENTER);
|
||||
_prevPageButton = iRect(_contentRect->x + 150, _contentRect->h + _contentRect->y - _footerHeight, 130, _footerHeight, ALIGN_CENTER);
|
||||
_nextPageButton = iRect(_contentRect->x + 300, _contentRect->h + _contentRect->y - _footerHeight, 130, _footerHeight, ALIGN_CENTER);
|
||||
_lastPageButton = iRect(_contentRect->x + 450, _contentRect->h + _contentRect->y - _footerHeight, 130, _footerHeight, ALIGN_CENTER);
|
||||
|
||||
drawEntries();
|
||||
drawFooter();
|
||||
}
|
||||
|
||||
ListView::~ListView()
|
||||
{
|
||||
CloseFont(_entryFont);
|
||||
CloseFont(_entryFontBold);
|
||||
CloseFont(_headerFont);
|
||||
CloseFont(_footerFont);
|
||||
}
|
||||
|
||||
void ListView::drawHeader(string headerText)
|
||||
{
|
||||
SetFont(_headerFont, BLACK);
|
||||
Util::decodeUrl(headerText);
|
||||
DrawTextRect(_contentRect->x, _contentRect->y, _contentRect->w, _headerHeight - 1, headerText.c_str(), ALIGN_LEFT);
|
||||
|
||||
int line = (_contentRect->y + _headerHeight) - 2;
|
||||
DrawLine(0, line, ScreenWidth(), line, BLACK);
|
||||
}
|
||||
|
||||
void ListView::drawEntry(int itemID)
|
||||
{
|
||||
FillAreaRect(_entries[itemID].getPosition(), WHITE);
|
||||
_entries[itemID].draw(_items->at(itemID), _entryFont, _entryFontBold, _entryFontHeight);
|
||||
updateEntry(itemID);
|
||||
}
|
||||
|
||||
void ListView::invertEntryColor(int itemID)
|
||||
{
|
||||
InvertAreaBW(_entries[itemID].getPosition()->x, _entries[itemID].getPosition()->y, _entries[itemID].getPosition()->w, _entries[itemID].getPosition()->h);
|
||||
updateEntry(itemID);
|
||||
}
|
||||
|
||||
void ListView::drawEntries()
|
||||
{
|
||||
for (unsigned int i = 0; i < _entries.size(); i++)
|
||||
{
|
||||
if (_entries[i].getPage() == _shownPage)
|
||||
_entries[i].draw(_items->at(i), _entryFont, _entryFontBold, _entryFontHeight);
|
||||
}
|
||||
}
|
||||
|
||||
int ListView::listClicked(int x, int y)
|
||||
{
|
||||
if (IsInRect(x, y, &_firstPageButton))
|
||||
{
|
||||
firstPage();
|
||||
}
|
||||
else if (IsInRect(x, y, &_nextPageButton))
|
||||
{
|
||||
nextPage();
|
||||
}
|
||||
else if (IsInRect(x, y, &_prevPageButton))
|
||||
{
|
||||
prevPage();
|
||||
}
|
||||
else if (IsInRect(x, y, &_lastPageButton))
|
||||
{
|
||||
actualizePage(_page);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned int i = 0; i < _entries.size(); i++)
|
||||
{
|
||||
if (_entries[i].getPage() == _shownPage && IsInRect(x, y, _entries[i].getPosition()) == 1)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ListView::drawFooter()
|
||||
{
|
||||
SetFont(_footerFont, WHITE);
|
||||
string footer = std::to_string(_shownPage) + "/" + std::to_string(_page);
|
||||
FillAreaRect(&_pageIcon, BLACK);
|
||||
|
||||
DrawTextRect2(&_pageIcon, footer.c_str());
|
||||
FillAreaRect(&_firstPageButton, BLACK);
|
||||
DrawTextRect2(&_firstPageButton, "First");
|
||||
FillAreaRect(&_prevPageButton, BLACK);
|
||||
DrawTextRect2(&_prevPageButton, "Prev");
|
||||
FillAreaRect(&_nextPageButton, BLACK);
|
||||
DrawTextRect2(&_nextPageButton, "Next");
|
||||
FillAreaRect(&_lastPageButton, BLACK);
|
||||
DrawTextRect2(&_lastPageButton, "Last");
|
||||
}
|
||||
|
||||
void ListView::updateEntry(int itemID)
|
||||
{
|
||||
PartialUpdate(_entries[itemID].getPosition()->x, _entries[itemID].getPosition()->y, _entries[itemID].getPosition()->w, _entries[itemID].getPosition()->h);
|
||||
}
|
||||
|
||||
void ListView::actualizePage(int pageToShown)
|
||||
{
|
||||
if (pageToShown > _page)
|
||||
{
|
||||
Message(ICON_INFORMATION, "Info", "You have reached the last page, to return to the first, please click \"first.\"", 1200);
|
||||
}
|
||||
else if (pageToShown < 1)
|
||||
{
|
||||
Message(ICON_INFORMATION, "Info", "You are already on the first page.", 1200);
|
||||
}
|
||||
else
|
||||
{
|
||||
_shownPage = pageToShown;
|
||||
FillArea(_contentRect->x, _contentRect->y + _headerHeight, _contentRect->w, _contentRect->h, WHITE);
|
||||
drawEntries();
|
||||
drawFooter();
|
||||
PartialUpdate(_contentRect->x, _contentRect->y + _headerHeight, _contentRect->w, _contentRect->h);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
//------------------------------------------------------------------
|
||||
// listView.cpp
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 04.08.2020
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#include "inkview.h"
|
||||
#include "listView.h"
|
||||
#include "listViewEntry.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
ListView::ListView(const irect *contentRect, int page) : _contentRect(contentRect), _shownPage(page)
|
||||
{
|
||||
_entries.clear();
|
||||
|
||||
_footerHeight = _contentRect->h / 10;
|
||||
_footerFontHeight = 0.3 * _footerHeight;
|
||||
_entryFontHeight = 30; //0.2 * _footerFontHeight;//entrySize; //TODO how much?
|
||||
|
||||
_footerFont = OpenFont("LiberationMono", _footerFontHeight, 1);
|
||||
_entryFont = OpenFont("LiberationMono", _entryFontHeight, 1);
|
||||
_entryFontBold = OpenFont("LiberationMono-Bold", _entryFontHeight, 1);
|
||||
|
||||
SetFont(_entryFont, BLACK);
|
||||
|
||||
_pageIcon = iRect(_contentRect->w - 100, _contentRect->h - _footerHeight, 100, _footerHeight, ALIGN_CENTER);
|
||||
_firstPageButton = iRect(_contentRect->x, _contentRect->h - _footerHeight, 130, _footerHeight, ALIGN_CENTER);
|
||||
_prevPageButton = iRect(_contentRect->x + 150, _contentRect->h - _footerHeight, 130, _footerHeight, ALIGN_CENTER);
|
||||
_nextPageButton = iRect(_contentRect->x + 300, _contentRect->h - _footerHeight, 130, _footerHeight, ALIGN_CENTER);
|
||||
_lastPageButton = iRect(_contentRect->x + 450, _contentRect->h - _footerHeight, 130, _footerHeight, ALIGN_CENTER);
|
||||
}
|
||||
|
||||
ListView::~ListView()
|
||||
{
|
||||
CloseFont(_entryFont);
|
||||
CloseFont(_entryFontBold);
|
||||
CloseFont(_footerFont);
|
||||
}
|
||||
|
||||
void ListView::draw()
|
||||
{
|
||||
FillAreaRect(_contentRect, WHITE);
|
||||
drawEntries();
|
||||
drawFooter();
|
||||
PartialUpdate(_contentRect->x, _contentRect->y, _contentRect->w, _contentRect->h);
|
||||
}
|
||||
|
||||
void ListView::reDrawCurrentEntry()
|
||||
{
|
||||
FillAreaRect(_entries.at(_selectedEntry)->getPosition(), WHITE);
|
||||
_entries.at(_selectedEntry)->draw(_entryFont, _entryFontBold, _entryFontHeight);
|
||||
updateEntry(_selectedEntry);
|
||||
}
|
||||
|
||||
void ListView::invertCurrentEntryColor()
|
||||
{
|
||||
InvertAreaBW(_entries.at(_selectedEntry)->getPosition()->x, _entries.at(_selectedEntry)->getPosition()->y, _entries.at(_selectedEntry)->getPosition()->w, _entries.at(_selectedEntry)->getPosition()->h);
|
||||
updateEntry(_selectedEntry);
|
||||
}
|
||||
|
||||
void ListView::drawEntries()
|
||||
{
|
||||
for (unsigned int i = 0; i < _entries.size(); i++)
|
||||
{
|
||||
if (_entries.at(i)->getPage() == _shownPage)
|
||||
_entries.at(i)->draw(_entryFont, _entryFontBold, _entryFontHeight);
|
||||
}
|
||||
}
|
||||
|
||||
bool ListView::checkIfEntryClicked(int x, int y)
|
||||
{
|
||||
if (IsInRect(x, y, &_firstPageButton))
|
||||
{
|
||||
firstPage();
|
||||
}
|
||||
else if (IsInRect(x, y, &_nextPageButton))
|
||||
{
|
||||
nextPage();
|
||||
}
|
||||
else if (IsInRect(x, y, &_prevPageButton))
|
||||
{
|
||||
prevPage();
|
||||
}
|
||||
else if (IsInRect(x, y, &_lastPageButton))
|
||||
{
|
||||
actualizePage(_page);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned int i = 0; i < _entries.size(); i++)
|
||||
{
|
||||
if (_entries.at(i)->getPage() == _shownPage && IsInRect(x, y, _entries.at(i)->getPosition()) == 1)
|
||||
{
|
||||
_selectedEntry = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ListView::drawFooter()
|
||||
{
|
||||
SetFont(_footerFont, WHITE);
|
||||
string footer = std::to_string(_shownPage) + "/" + std::to_string(_page);
|
||||
FillAreaRect(&_pageIcon, BLACK);
|
||||
|
||||
DrawTextRect2(&_pageIcon, footer.c_str());
|
||||
FillAreaRect(&_firstPageButton, BLACK);
|
||||
DrawTextRect2(&_firstPageButton, "First");
|
||||
FillAreaRect(&_prevPageButton, BLACK);
|
||||
DrawTextRect2(&_prevPageButton, "Prev");
|
||||
FillAreaRect(&_nextPageButton, BLACK);
|
||||
DrawTextRect2(&_nextPageButton, "Next");
|
||||
FillAreaRect(&_lastPageButton, BLACK);
|
||||
DrawTextRect2(&_lastPageButton, "Last");
|
||||
}
|
||||
|
||||
void ListView::updateEntry(int entryID)
|
||||
{
|
||||
PartialUpdate(_entries.at(entryID)->getPosition()->x, _entries.at(entryID)->getPosition()->y, _entries.at(entryID)->getPosition()->w, _entries.at(entryID)->getPosition()->h);
|
||||
}
|
||||
|
||||
void ListView::actualizePage(int pageToShow)
|
||||
{
|
||||
if (pageToShow > _page)
|
||||
{
|
||||
Message(ICON_INFORMATION, "Info", "You have reached the last page, to return to the first, please click \"first.\"", 1200);
|
||||
}
|
||||
else if (pageToShow < 1)
|
||||
{
|
||||
Message(ICON_INFORMATION, "Info", "You are already on the first page.", 1200);
|
||||
}
|
||||
else
|
||||
{
|
||||
_shownPage = pageToShow;
|
||||
FillArea(_contentRect->x, _contentRect->y, _contentRect->w, _contentRect->h, WHITE);
|
||||
drawEntries();
|
||||
drawFooter();
|
||||
PartialUpdate(_contentRect->x, _contentRect->y, _contentRect->w, _contentRect->h);
|
||||
}
|
||||
}
|
|
@ -10,10 +10,9 @@
|
|||
#define LISTVIEW
|
||||
|
||||
#include "inkview.h"
|
||||
#include "item.h"
|
||||
#include "listViewEntry.h"
|
||||
#include "model.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
|
@ -21,41 +20,19 @@ class ListView
|
|||
{
|
||||
public:
|
||||
/**
|
||||
* Displays a list view
|
||||
*
|
||||
* Displays a list view
|
||||
*
|
||||
* @param ContentRect area of the screen where the list view is placed
|
||||
* @param Items items that shall be shown in the listview
|
||||
*/
|
||||
ListView(const irect *contentRect, const std::vector<Item> &items);
|
||||
ListView(const irect *contentRect, int page);
|
||||
|
||||
~ListView();
|
||||
virtual ~ListView();
|
||||
|
||||
/**
|
||||
* Draws the header
|
||||
*
|
||||
* @param headerText the text that shall be displayed in the header
|
||||
*
|
||||
*/
|
||||
void drawHeader(std::string headerText);
|
||||
virtual Entry *getCurrentEntry() = 0;
|
||||
virtual Entry *getEntry(int entryID) = 0;
|
||||
|
||||
/**
|
||||
* Draws an single entry to the screen
|
||||
*
|
||||
* @param itemID the id of the item that shall be drawn
|
||||
*/
|
||||
void drawEntry(int itemID);
|
||||
|
||||
/**
|
||||
* inverts the color of an entry
|
||||
*
|
||||
* @param itemID the id of the item that shall be inverted
|
||||
*/
|
||||
void invertEntryColor(int itemID);
|
||||
|
||||
/**
|
||||
* Iterates through the items and sends them to the listViewEntry Class for drawing
|
||||
*/
|
||||
void drawEntries();
|
||||
int getShownPage(){return _shownPage;};
|
||||
|
||||
/**
|
||||
* Navigates to the next page
|
||||
|
@ -72,36 +49,56 @@ public:
|
|||
*/
|
||||
void firstPage() { this->actualizePage(1); };
|
||||
|
||||
/**
|
||||
* Draws an single entry to the screen
|
||||
*/
|
||||
void reDrawCurrentEntry();
|
||||
|
||||
/**
|
||||
* inverts the color of the currently selected entry
|
||||
*/
|
||||
void invertCurrentEntryColor();
|
||||
|
||||
/**
|
||||
* Checkes if the listview has been clicked and either changes the page or returns item ID
|
||||
*
|
||||
* @param x x-coordinate
|
||||
* @param y y-coordinate
|
||||
* @return int Item ID that has been clicked, -1 if no Item was clicked
|
||||
* @return true if was clicked
|
||||
*/
|
||||
int listClicked(int x, int y);
|
||||
bool checkIfEntryClicked(int x, int y);
|
||||
|
||||
private:
|
||||
int getCurrentEntryItertator() const {return _selectedEntry;};
|
||||
|
||||
/**
|
||||
* Clears the screen and draws entries and footer
|
||||
*
|
||||
*/
|
||||
void draw();
|
||||
|
||||
protected:
|
||||
int _footerHeight;
|
||||
int _headerHeight;
|
||||
int _headerFontHeight;
|
||||
int _footerFontHeight;
|
||||
int _entryFontHeight;
|
||||
const irect *_contentRect;
|
||||
std::unique_ptr<const std::vector<Item>> _items;
|
||||
std::vector<ListViewEntry> _entries;
|
||||
ifont *_headerFont;
|
||||
std::vector<std::shared_ptr<ListViewEntry>> _entries;
|
||||
ifont *_footerFont;
|
||||
ifont *_entryFont;
|
||||
ifont *_entryFontBold;
|
||||
int _page;
|
||||
int _page = 1;
|
||||
int _shownPage;
|
||||
irect _pageIcon;
|
||||
irect _nextPageButton;
|
||||
irect _prevPageButton;
|
||||
irect _firstPageButton;
|
||||
irect _lastPageButton;
|
||||
int _itemCount = 7;
|
||||
int _selectedEntry;
|
||||
|
||||
|
||||
/**
|
||||
* Iterates through the items and sends them to the listViewEntry Class for drawing
|
||||
*/
|
||||
void drawEntries();
|
||||
|
||||
/**
|
||||
* Draws the footer including a page changer
|
||||
|
@ -111,15 +108,15 @@ private:
|
|||
/**
|
||||
* updates an entry
|
||||
*
|
||||
* @param itemID the id of the item that shall be inverted
|
||||
* @param entryID the id of the item that shall be inverted
|
||||
*/
|
||||
void updateEntry(int itemID);
|
||||
void updateEntry(int entryID);
|
||||
|
||||
/**
|
||||
* Navigates to the selected page
|
||||
*
|
||||
* @param pageToShown page that shall be shown
|
||||
* @param pageToShow page that shall be shown
|
||||
*/
|
||||
void actualizePage(int pageToShown);
|
||||
void actualizePage(int pageToShow);
|
||||
};
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,14 @@
|
|||
//------------------------------------------------------------------
|
||||
// hnCommentViewEntry.cpp
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 04.08.2020
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#include "inkview.h"
|
||||
#include "listViewEntry.h"
|
||||
|
||||
ListViewEntry::ListViewEntry(int page, const irect &rect) : _page(page), _position(rect)
|
||||
{
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
#define LISTVIEWENTRY
|
||||
|
||||
#include "inkview.h"
|
||||
#include "item.h"
|
||||
#include "model.h"
|
||||
|
||||
class ListViewEntry
|
||||
{
|
||||
|
@ -21,7 +21,9 @@ public:
|
|||
* @param Page site of the listView the Entry is shown
|
||||
* @param Rect area of the screen the item is positioned
|
||||
*/
|
||||
ListViewEntry(int page, irect position);
|
||||
ListViewEntry(int page, const irect &position);
|
||||
|
||||
virtual ~ListViewEntry(){};
|
||||
|
||||
irect *getPosition() { return &_position; }
|
||||
int getPage() const { return _page; }
|
||||
|
@ -29,14 +31,15 @@ public:
|
|||
/**
|
||||
* draws the listViewEntry to the screen
|
||||
*
|
||||
* @param item item that shall be drawn
|
||||
* @param entryFont font for the entry itself
|
||||
* @param entryFontBold bold font for the header
|
||||
* @param fontHeight height of the font
|
||||
*/
|
||||
void draw(const Item &item, ifont *entryFont, ifont *entryFontBold, int fontHeight);
|
||||
virtual void draw(const ifont *entryFont, const ifont *entryFontBold, int fontHeight) = 0;
|
||||
|
||||
virtual Entry* get() = 0;
|
||||
|
||||
private:
|
||||
protected:
|
||||
int _page;
|
||||
irect _position;
|
||||
};
|
|
@ -1,62 +0,0 @@
|
|||
//------------------------------------------------------------------
|
||||
// listViewEntry.cpp
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 04.08.2020
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#include "inkview.h"
|
||||
#include "item.h"
|
||||
#include "listViewEntry.h"
|
||||
#include "util.h"
|
||||
|
||||
ListViewEntry::ListViewEntry(int page, irect rect) : _page(page), _position(rect)
|
||||
{
|
||||
}
|
||||
|
||||
void ListViewEntry::draw(const Item &item, ifont *entryFont, ifont *entryFontBold, int fontHeight)
|
||||
{
|
||||
SetFont(entryFontBold, BLACK);
|
||||
DrawTextRect(_position.x, _position.y, _position.w, fontHeight, item.getTitle().c_str(), ALIGN_LEFT);
|
||||
|
||||
SetFont(entryFont, BLACK);
|
||||
|
||||
if (item.getState() == FileState::ILOCAL)
|
||||
{
|
||||
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, "Local", ALIGN_RIGHT);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.getType() == IFILE)
|
||||
{
|
||||
DrawTextRect(_position.x, _position.y + fontHeight, _position.w, fontHeight, item.getFiletype().c_str(), ALIGN_LEFT);
|
||||
|
||||
if (item.getState() == FileState::ISYNCED)
|
||||
{
|
||||
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, "Synced", ALIGN_RIGHT);
|
||||
}
|
||||
else if(item.getState() == FileState::IOUTSYNCED)
|
||||
{
|
||||
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, "Out of sync", ALIGN_RIGHT);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, "Click to Download", ALIGN_RIGHT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.getState() == FileState::ISYNCED)
|
||||
{
|
||||
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, "Folder synced", ALIGN_RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
DrawTextRect(_position.x, _position.y + 2 * fontHeight, _position.w, fontHeight, item.getLastEditDate().c_str(), ALIGN_LEFT);
|
||||
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, item.getSizeString().c_str(), ALIGN_LEFT);
|
||||
}
|
||||
|
||||
int line = (_position.y + _position.h) - 1;
|
||||
DrawLine(0, line, ScreenWidth(), line, BLACK);
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
//------------------------------------------------------------------
|
||||
// webDAVView.cpp
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 08.09.2021
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#include "webDAVView.h"
|
||||
#include "webDAVModel.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::vector;
|
||||
|
||||
WebDAVView::WebDAVView(const irect *contentRect, const vector<WebDAVItem> &items, int page) : ListView(contentRect, page)
|
||||
{
|
||||
auto pageHeight = 0;
|
||||
auto contentHeight = _contentRect->h - _footerHeight;
|
||||
auto entrycount = items.size();
|
||||
|
||||
_entries.reserve(entrycount);
|
||||
|
||||
auto i = 0;
|
||||
while (i < entrycount)
|
||||
{
|
||||
auto entrySize = TextRectHeight(contentRect->w, items.at(i).title.c_str(), 0) + 2.5 * _entryFontHeight;
|
||||
if ((pageHeight + entrySize) > contentHeight)
|
||||
{
|
||||
pageHeight = 0;
|
||||
_page++;
|
||||
}
|
||||
irect rect = iRect(_contentRect->x, _contentRect->y + pageHeight, _contentRect->w, entrySize, 0);
|
||||
|
||||
_entries.emplace_back(std::unique_ptr<WebDAVViewEntry>(new WebDAVViewEntry(_page, rect, items.at(i))));
|
||||
|
||||
i++;
|
||||
pageHeight = pageHeight + entrySize;
|
||||
}
|
||||
draw();
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
//------------------------------------------------------------------
|
||||
// webDAVView.h
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 08.09.2021
|
||||
// Description: An UI class to display items in a listview
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#ifndef WEBDAVVIEW
|
||||
#define WEBDAVVIEW
|
||||
|
||||
#include "webDAVModel.h"
|
||||
#include "listView.h"
|
||||
#include "webDAVViewEntry.h"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
class WebDAVView final : public ListView
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Displays a list view
|
||||
*
|
||||
* @param ContentRect area of the screen where the list view is placed
|
||||
* @param Items items that shall be shown in the listview
|
||||
* @param page page that is shown, default is 1
|
||||
*/
|
||||
WebDAVView(const irect *contentRect, const std::vector<WebDAVItem> &items, int page = 1);
|
||||
|
||||
//TODO make other pointer...
|
||||
WebDAVItem *getCurrentEntry() { return getEntry(_selectedEntry); };
|
||||
|
||||
WebDAVItem *getEntry(int entryID) { return std::dynamic_pointer_cast<WebDAVViewEntry>(_entries.at(entryID))->get(); };
|
||||
};
|
||||
#endif
|
|
@ -0,0 +1,35 @@
|
|||
//------------------------------------------------------------------
|
||||
// WebDAVViewEntry.cpp
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 08.09.2021
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#include "webDAVViewEntry.h"
|
||||
#include "webDAVModel.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
WebDAVViewEntry::WebDAVViewEntry(int page, const irect &position, const WebDAVItem &entry) : ListViewEntry(page, position), _entry(entry)
|
||||
{
|
||||
}
|
||||
|
||||
void WebDAVViewEntry::draw(const ifont *entryFont, const ifont *entryFontBold, int fontHeight)
|
||||
{
|
||||
SetFont(entryFontBold, BLACK);
|
||||
int heightOfTitle = TextRectHeight(_position.w, _entry.title.c_str(), 0);
|
||||
DrawTextRect(_position.x, _position.y, _position.w, heightOfTitle, _entry.title.c_str(), ALIGN_LEFT);
|
||||
|
||||
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 == Itemtype::FOLDER)
|
||||
//type = "Folder";
|
||||
DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, type.c_str(), ALIGN_RIGHT);
|
||||
|
||||
int line = (_position.y + _position.h) - 1;
|
||||
DrawLine(0, line, ScreenWidth(), line, BLACK);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
//------------------------------------------------------------------
|
||||
// webDAVViewEntry.h
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 08.09.2021
|
||||
// Description:
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#ifndef WEBDAVVIEWENTRY
|
||||
#define WEBDAVVIEWENTRY
|
||||
|
||||
#include "listViewEntry.h"
|
||||
#include "webDAVModel.h"
|
||||
|
||||
class WebDAVViewEntry : public ListViewEntry
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Creates an WebDAVViewEntry
|
||||
*
|
||||
* @param Page site of the listView the Entry is shown
|
||||
* @param Rect area of the screen the item is positioned
|
||||
* @param entry entry that shall be drawn
|
||||
*/
|
||||
WebDAVViewEntry(int page, const irect &position, const WebDAVItem &entry);
|
||||
|
||||
/**
|
||||
* draws the WebDAVViewEntry to the screen
|
||||
*
|
||||
* @param entryFont font for the entry itself
|
||||
* @param entryFontBold bold font for the header
|
||||
* @param fontHeight height of the font
|
||||
*/
|
||||
void draw(const ifont *entryFont, const ifont *entryFontBold, int fontHeight) override;
|
||||
|
||||
WebDAVItem *get() override { return &_entry; };
|
||||
|
||||
private:
|
||||
WebDAVItem _entry;
|
||||
};
|
||||
#endif
|
Loading…
Reference in New Issue