Implement FilePicker in other classes

master
JuanJakobo 2022-07-29 17:34:22 +02:00
parent ea3ce81b3a
commit 3822d3197c
6 changed files with 136 additions and 41 deletions

View File

@ -29,9 +29,6 @@ WebDAV::WebDAV()
if (iv_access(NEXTCLOUD_PATH.c_str(), W_OK) != 0)
iv_mkdir(NEXTCLOUD_PATH.c_str(), 0777);
if (iv_access(NEXTCLOUD_FILE_PATH.c_str(), W_OK) != 0)
iv_mkdir(NEXTCLOUD_FILE_PATH.c_str(), 0777);
if (iv_access(CONFIG_PATH.c_str(), W_OK) == 0)
{
_username = Util::accessConfig(CONFIG_PATH,Action::IReadString,"username");
@ -59,6 +56,7 @@ std::vector<WebDAVItem> WebDAV::login(const string &Url, const string &Username,
uuid = Username;
}
auto tempPath = NEXTCLOUD_ROOT_PATH + uuid + "/";
Util::accessConfig(CONFIG_PATH, Action::IWriteString, "storageLocation", "/mnt/ext1/nextcloud");
std::vector<WebDAVItem> tempItems = getDataStructure(tempPath);
if (!tempItems.empty())
{
@ -82,8 +80,8 @@ void WebDAV::logout(bool deleteFiles)
{
if (deleteFiles)
{
//string cmd = "rm -rf " + NEXTCLOUD_FILE_PATH + "/" + getUUID() + "/";
//system(cmd.c_str());
string cmd = "rm -rf " + Util::accessConfig(CONFIG_PATH, Action::IReadString, "storageLocation") + "/" + Util::accessConfig(CONFIG_PATH, Action::IReadString,"UUID") + '/';
system(cmd.c_str());
}
remove(CONFIG_PATH.c_str());
remove((CONFIG_PATH + ".back.").c_str());
@ -151,7 +149,13 @@ vector<WebDAVItem> WebDAV::getDataStructure(const string &pathUrl)
tempItem.path.erase(0,tempItem.path.find(NEXTCLOUD_START_PATH));
tempItem.title = tempItem.path;
tempItem.localPath = getLocalPath(tempItem.path);
//TODO make lambda?
tempItem.localPath = tempItem.path;
Util::decodeUrl(tempItem.localPath);
if (tempItem.localPath.find(NEXTCLOUD_ROOT_PATH) != string::npos)
tempItem.localPath = tempItem.localPath.substr(NEXTCLOUD_ROOT_PATH.length());
tempItem.localPath = Util::accessConfig(CONFIG_PATH, Action::IReadString, "storageLocation") + "/" + tempItem.localPath;
if (tempItem.path.back() == '/')
{

View File

@ -15,8 +15,6 @@
#include <string>
#include <vector>
//TODO write into config
const std::string NEXTCLOUD_FILE_PATH = "/mnt/ext1/nextcloud";
const std::string NEXTCLOUD_ROOT_PATH = "/remote.php/dav/files/";
const std::string NEXTCLOUD_START_PATH = "/remote.php/";
const std::string CACERT_PATH = "/mnt/ext1/applications/cacert.pem";

View File

@ -15,6 +15,9 @@
#include "log.h"
#include "webDAV.h"
#include "webDAVModel.h"
#include "fileBrowser.h"
#include "fileView.h"
#include "fileModel.h"
#include <string>
#include <memory>
@ -168,18 +171,44 @@ void EventHandler::mainMenuHandler(const int index)
break;
}
_webDAVView.release();
_loginView = std::make_unique<LoginView>(LoginView(_menu->getContentRect()));
FullUpdate();
_loginView = std::unique_ptr<LoginView>(new LoginView(_menu->getContentRect()));
break;
}
//Select folder
case 103:
{
if(_currentPath.back() != '/')
_currentPath = _currentPath + "/nextcloud";
else
_currentPath = _currentPath + "nextcloud";
if(iv_mkdir(_currentPath.c_str(), 0777) != 0)
Message(ICON_ERROR, "Error", "The permissions are not sufficient.", 1000);
else
{
Util::accessConfig(CONFIG_PATH, Action::IWriteString, "storageLocation", _currentPath);
std::vector<WebDAVItem> currentWebDAVItems = _webDAV.getDataStructure(NEXTCLOUD_ROOT_PATH + Util::accessConfig(CONFIG_PATH, Action::IReadString,"UUID") + '/');
if(currentWebDAVItems.empty())
{
Message(ICON_ERROR, "Error", "Failed to get items. Please try again.", 1000);
}
else
{
updateItems(currentWebDAVItems);
drawWebDAVItems(currentWebDAVItems);
}
}
break;
}
//Info
case 103:
case 104:
{
Message(ICON_INFORMATION, "Information", "Version 0.98 \n For support please open a ticket at https://github.com/JuanJakobo/Pocketbook-Nextcloud-Client/issues", 1200);
Message(ICON_INFORMATION, "Info", "Version 0.98 \n For support please open a ticket at https://github.com/JuanJakobo/Pocketbook-Nextcloud-Client/issues", 1200);
break;
}
//Exit
case 104:
case 105:
CloseApp();
break;
default:
@ -268,7 +297,7 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
{
if (IsInRect(par1, par2, &_menu->getMenuButtonRect()) == 1)
{
return _menu->createMenu((_webDAVView != nullptr), EventHandler::mainMenuHandlerStatic);
return _menu->createMenu((_fileView != nullptr), (_webDAVView != nullptr), EventHandler::mainMenuHandlerStatic);
}
else if (_webDAVView != nullptr)
{
@ -305,18 +334,55 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
std::vector<WebDAVItem> currentWebDAVItems = _webDAV.login(_loginView->getURL(), _loginView->getUsername(), _loginView->getPassword());
if(currentWebDAVItems.empty())
{
Message(ICON_ERROR, "Error", "Login failed.", 1000);
HideHourglass();
Log::writeErrorLog("login failed.");
}
else
{
//TODO storagelocation picker
drawWebDAVItems(currentWebDAVItems);
_loginView.reset();
int dialogResult = DialogSynchro(ICON_QUESTION, "Action", "Do you want to choose your own storage path or use the default one. \n (/mnt/ext1/nextcloud/)", "Choose my own path", "Choose standard path", NULL);
auto path = "/mnt/ext1";
switch (dialogResult)
{
case 1:
{
FileBrowser fileBrowser = FileBrowser();
vector<FileItem> currentFolder = fileBrowser.getFileStructure(path);
_currentPath = path;
_loginView.reset();
FillAreaRect(&_menu->getContentRect(), WHITE);
_fileView = std::unique_ptr<FileView>(new FileView(_menu->getContentRect(), currentFolder,1));
}
break;
default:
updateItems(currentWebDAVItems);
drawWebDAVItems(currentWebDAVItems);
break;
}
}
return 0;
}
}
else if(_fileView != nullptr)
{
if(_fileView->checkIfEntryClicked(par1, par2))
{
_fileView->invertCurrentEntryColor();
if (_fileView->getCurrentEntry().type == Type::FFOLDER)
{
FileBrowser fileBrowser = FileBrowser();
_currentPath = _fileView->getCurrentEntry().path;
vector<FileItem> currentFolder = fileBrowser.getFileStructure(_currentPath);
//TODO use other method
_fileView.reset();
_fileView = std::unique_ptr<FileView>(new FileView(_menu->getContentRect(), currentFolder,1));
}
}
return 0;
}
}
return 1;
}
@ -377,31 +443,53 @@ void EventHandler::openFolder()
int EventHandler::keyHandler(const int type, const int par1, const int par2)
{
if (type == EVT_KEYPRESS)
if(_webDAVView != nullptr)
{
//menu button
if (par1 == 23)
if (type == EVT_KEYPRESS)
{
_webDAVView->firstPage();
}
else if (_webDAVView != nullptr)
{
//left button
if (par1 == 24)
switch(par1)
{
_webDAVView->prevPage();
}
//right button
else if (par1 == 25)
{
_webDAVView->nextPage();
//menu button
case 23:
_webDAVView->firstPage();
break;
//left button
case 24:
_webDAVView->prevPage();
break;
//right button
case 25:
_webDAVView->nextPage();
break;
default:
return 1;
}
return 0;
}
else
}
else if(_fileView != nullptr)
{
if (type == EVT_KEYPRESS)
{
return 1;
switch(par1)
{
//menu button
case 23:
_fileView->firstPage();
break;
//left button
case 24:
_fileView->prevPage();
break;
//right button
case 25:
_fileView->nextPage();
break;
default:
return 1;
}
return 0;
}
return 0;
}
return 1;

View File

@ -14,13 +14,13 @@
#include "webDAV.h"
#include "webDAVView.h"
#include "loginView.h"
#include "fileView.h"
#include "sqliteConnector.h"
#include <memory>
const std::string CONFIG_FOLDER = "/mnt/ext1/system/config/nextcloud";
const std::string CONFIG_PATH = CONFIG_FOLDER + "/nextcloud.cfg";
//TODO use folder of nextcloud conifg temp
const std::string DB_PATH = CONFIG_FOLDER + "/data.db";
class EventHandler
@ -45,6 +45,7 @@ private:
static std::unique_ptr<EventHandler> _eventHandlerStatic;
std::unique_ptr<WebDAVView> _webDAVView;
std::unique_ptr<LoginView> _loginView;
std::unique_ptr<FileView> _fileView;
std::unique_ptr<ContextMenu> _contextMenu;
std::unique_ptr<MainMenu> _menu;

View File

@ -43,6 +43,7 @@ MainMenu::~MainMenu()
free(_logout);
free(_info);
free(_exit);
free(_chooseFolder);
}
void MainMenu::panelHandlerStatic()
@ -51,7 +52,7 @@ void MainMenu::panelHandlerStatic()
SetHardTimer("PANELUPDATE", panelHandlerStatic, 110000);
}
int MainMenu::createMenu(bool loggedIn, iv_menuhandler handler)
int MainMenu::createMenu(bool filePicker, bool loggedIn, iv_menuhandler handler)
{
imenu mainMenu[] =
{
@ -59,9 +60,10 @@ int MainMenu::createMenu(bool loggedIn, iv_menuhandler handler)
//show logged in
{loggedIn ? (short)ITEM_ACTIVE : (short)ITEM_HIDDEN, 101, _syncFolder, NULL},
{loggedIn ? (short)ITEM_ACTIVE : (short)ITEM_HIDDEN, 102, _logout, NULL},
{filePicker ? (short)ITEM_ACTIVE : (short)ITEM_HIDDEN, 103, _chooseFolder, NULL},
//show always
{ITEM_ACTIVE, 103, _info, NULL},
{ITEM_ACTIVE, 104, _exit, NULL},
{ITEM_ACTIVE, 104, _info, NULL},
{ITEM_ACTIVE, 105, _exit, NULL},
{0, 0, NULL, NULL}};
OpenMenu(mainMenu, 0, _panelMenuBeginX, _panelMenuBeginY, handler);

View File

@ -31,11 +31,12 @@ public:
/**
* Shows the menu on the screen, lets the user choose menu options and then redirects the handler to the caller
*
* @param filePicker true if the filepicker is shown
* @param loogedIn the status if the user is logged in
* @param handler handles the clicks on the menu
* @return int returns if the event was handled
*/
int createMenu(bool loggedIn, iv_menuhandler handler);
int createMenu(bool filePicker, bool loggedIn, iv_menuhandler handler);
private:
ifont *_menuFont;
@ -52,6 +53,7 @@ private:
char *_menu = strdup("Menu");
char *_syncFolder = strdup("Actualize folder");
char *_logout = strdup("Logout");
char *_chooseFolder = strdup("Create here");
char *_info = strdup("Info");
char *_exit = strdup("Close App");