loginView added

pull/23/head
JuanJakobo 2020-08-26 17:26:21 +02:00
parent ef842c94f1
commit 0408821e46
8 changed files with 446 additions and 173 deletions

View File

@ -57,6 +57,7 @@ set(SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp
${CMAKE_SOURCE_DIR}/src/util/item.cpp ${CMAKE_SOURCE_DIR}/src/util/item.cpp
${CMAKE_SOURCE_DIR}/src/ui/listView.cpp ${CMAKE_SOURCE_DIR}/src/ui/listView.cpp
${CMAKE_SOURCE_DIR}/src/ui/listViewEntry.cpp ${CMAKE_SOURCE_DIR}/src/ui/listViewEntry.cpp
${CMAKE_SOURCE_DIR}/src/ui/loginView.cpp
${CMAKE_SOURCE_DIR}/src/util/util.cpp ${CMAKE_SOURCE_DIR}/src/util/util.cpp
${CMAKE_SOURCE_DIR}/src/util/log.cpp ${CMAKE_SOURCE_DIR}/src/util/log.cpp

View File

@ -13,51 +13,71 @@
#include "item.h" #include "item.h"
#include <string> #include <string>
#include <memory>
EventHandler * EventHandler::eventHandlerStatic; using std::string;
EventHandler *EventHandler::_eventHandlerStatic;
EventHandler::EventHandler() EventHandler::EventHandler()
{ {
//create a event to create handlers //create a event to create handlers
eventHandlerStatic = this; _eventHandlerStatic = this;
menu = new MenuHandler("Nextcloud"); _menu = new MenuHandler("nextcloud");
_nextcloud = new Nextcloud();
_loginView = nullptr;
_listView = nullptr;
nextcloud = new Nextcloud(); if (iv_access(NEXTCLOUD_CONFIG_PATH.c_str(), W_OK) == 0)
//TODO SET USER, PASSWORD {
nextcloud->login("USER", "PASSWORD"); if (_nextcloud->login())
{
listView = new ListView(menu->getContentRect(),nextcloud->getItems()); _listView = new ListView(_menu->getContentRect(), _nextcloud->getItems());
FullUpdate();
return;
}
}
_loginView = new LoginView(_menu->getContentRect());
_loginView->drawLoginView();
FullUpdate(); FullUpdate();
} }
EventHandler::~EventHandler() EventHandler::~EventHandler()
{ {
delete nextcloud; delete _nextcloud;
delete menu; delete _listView;
delete listView; delete _menu;
} }
int EventHandler::eventDistributor(int type, int par1, int par2) int EventHandler::eventDistributor(const int type, const int par1, const int par2)
{ {
if (ISPOINTEREVENT(type)) if (ISPOINTEREVENT(type))
return EventHandler::pointerHandler(type,par1,par2); return EventHandler::pointerHandler(type, par1, par2);
return 0; return 0;
} }
void EventHandler::mainMenuHandlerStatic(int index) void EventHandler::mainMenuHandlerStatic(const int index)
{ {
eventHandlerStatic->mainMenuHandler(index); _eventHandlerStatic->mainMenuHandler(index);
} }
void EventHandler::mainMenuHandler(int index) void EventHandler::mainMenuHandler(const int index)
{ {
switch(index) switch (index)
{ {
//Exit //Logout
case 101: case 101:
_nextcloud->logout();
delete _listView;
_listView = nullptr;
_loginView = new LoginView(_menu->getContentRect());
_loginView->drawLoginView();
FullUpdate();
break;
//Exit
case 102:
CloseApp(); CloseApp();
break; break;
default: default:
@ -65,33 +85,45 @@ void EventHandler::mainMenuHandler(int index)
} }
} }
int EventHandler::pointerHandler(int type, int par1, int par2) int EventHandler::pointerHandler(const int type, const int par1, const int par2)
{ {
if (type == EVT_POINTERDOWN)
if(type==EVT_POINTERDOWN)
{ {
if(IsInRect(par1,par2,menu->getMenuButtonRect())==1) if (IsInRect(par1, par2, _menu->getMenuButtonRect()) == 1)
{ {
return menu->createMenu(true,EventHandler::mainMenuHandlerStatic); return _menu->createMenu(_nextcloud->isLoggedIn(), EventHandler::mainMenuHandlerStatic);
} }
else if(listView!= NULL) else if (_listView != nullptr)
{ {
int itemID = listView->listClicked(par1,par2); int itemID = _listView->listClicked(par1, par2);
if(itemID!=-1) if (itemID != -1)
{ {
string tempPath = nextcloud->getItems()[itemID].isClicked(); string tempPath = _nextcloud->getItems()[itemID].isClicked();
if(!tempPath.empty()) if (!tempPath.empty())
nextcloud->getDataStructure(tempPath); _nextcloud->getDataStructure(tempPath);
delete listView; delete _listView;
listView = new ListView(menu->getContentRect(),nextcloud->getItems()); _listView = new ListView(_menu->getContentRect(), _nextcloud->getItems());
listView->drawHeader(tempPath.substr(NEXTCLOUD_ROOT_PATH.length())); _listView->drawHeader(tempPath.substr(NEXTCLOUD_ROOT_PATH.length()));
} }
PartialUpdate(menu->getContentRect()->x,menu->getContentRect()->y,menu->getContentRect()->w,menu->getContentRect()->h); PartialUpdate(_menu->getContentRect()->x, _menu->getContentRect()->y, _menu->getContentRect()->w, _menu->getContentRect()->h);
return 1; return 1;
} }
else if (_loginView != nullptr)
{
if (_loginView->logginClicked(par1, par2) == 2)
{
if (_nextcloud->login(_loginView->getURL(), _loginView->getUsername(), _loginView->getPassword()))
{
_listView = new ListView(_menu->getContentRect(), _nextcloud->getItems());
delete _loginView;
FullUpdate();
}
return 1;
}
}
} }
return 0; return 0;
} }

View File

@ -12,13 +12,13 @@
#include "menuHandler.h" #include "menuHandler.h"
#include "nextcloud.h" #include "nextcloud.h"
#include "listView.h" #include "listView.h"
#include "loginView.h"
const string CONFIG_PATH = "/mnt/ext1/system/config/nextcloud"; const string CONFIG_PATH = "/mnt/ext1/system/config/nextcloud";
class EventHandler class EventHandler
{ {
public: public:
/** /**
* Defines fonds, sets global Event Handler and starts new content * Defines fonds, sets global Event Handler and starts new content
*/ */
@ -37,14 +37,15 @@ class EventHandler
* @param par2 second argument of the event * @param par2 second argument of the event
* @return int returns if the event was handled * @return int returns if the event was handled
*/ */
int eventDistributor(int type, int par1, int par2); int eventDistributor(const int type, const int par1, const int par2);
private: private:
static EventHandler *_eventHandlerStatic;
MenuHandler *_menu;
Nextcloud *_nextcloud;
ListView *_listView;
LoginView *_loginView;
static EventHandler *eventHandlerStatic;
MenuHandler *menu;
Nextcloud *nextcloud;
ListView* listView;
/** /**
* Functions needed to call C function, redirects to real function * Functions needed to call C function, redirects to real function
@ -54,7 +55,7 @@ class EventHandler
* @param par2 second argument of the event * @param par2 second argument of the event
* @return int returns if the event was handled * @return int returns if the event was handled
*/ */
static void mainMenuHandlerStatic(int index); static void mainMenuHandlerStatic(const int index);
/** /**
* Handles menu events and redirects them * Handles menu events and redirects them
* *
@ -63,7 +64,7 @@ class EventHandler
* @param par2 second argument of the event * @param par2 second argument of the event
* @return int returns if the event was handled * @return int returns if the event was handled
*/ */
void mainMenuHandler(int index); void mainMenuHandler(const int index);
/** /**
* Handles pointer Events * Handles pointer Events
@ -73,6 +74,6 @@ class EventHandler
* @param par2 second argument of the event * @param par2 second argument of the event
* @return int returns if the event was handled * @return int returns if the event was handled
*/ */
int pointerHandler(int type, int par1, int par2); int pointerHandler(const int type, const int par1, const int par2);
}; };
#endif #endif

View File

@ -52,13 +52,15 @@ int MenuHandler::createMenu(bool loggedIn, iv_menuhandler handler)
imenu mainMenu[] = imenu mainMenu[] =
{ {
{ITEM_HEADER, 0, "Menu", NULL}, {ITEM_HEADER, 0, "Menu", NULL},
//show logged in
{loggedIn ? ITEM_ACTIVE : ITEM_HIDDEN, 101, "Logout", NULL},
//show always //show always
{ITEM_ACTIVE, 101, "Exit"}, {ITEM_ACTIVE, 102, "Exit"},
{0, 0, NULL, NULL}}; {0, 0, NULL, NULL}};
if (loggedIn) if (loggedIn)
{ {
mainMenu[1].type = ITEM_ACTIVE; mainMenu[2].type = ITEM_ACTIVE;
} }
else else
{ {

View File

@ -0,0 +1,135 @@
//------------------------------------------------------------------
// loginView.cpp
//
// Author: JuanJakobo
// Date: 26.08.2020
//
//-------------------------------------------------------------------
#include "inkview.h"
#include "loginView.h"
#include "eventHandler.h"
#include <string>
using std::string;
LoginView *LoginView::_loginViewStatic;
LoginView::LoginView(irect *contentRect) : _contentRect(contentRect)
{
_loginViewStatic = this;
_loginFont = OpenFont("LiberationMono", 40, 1);
}
LoginView::~LoginView()
{
CloseFont(_loginFont);
}
void LoginView::drawLoginView()
{
FillAreaRect(_contentRect, WHITE);
_urlButton = iRect(50, 200, (ScreenWidth() - 50), 75, ALIGN_CENTER);
DrawLine(20, 275, (ScreenWidth() - 20), 275, BLACK);
SetFont(_loginFont, BLACK);
DrawTextRect2(&_urlButton, "Url");
_usernameButton = iRect(50, 400, ScreenWidth() - 50, 75, ALIGN_CENTER);
DrawLine(20, 475, (ScreenWidth() - 20), 475, BLACK);
SetFont(_loginFont, BLACK);
DrawTextRect2(&_usernameButton, "Username");
_passwordButton = iRect(50, 600, (ScreenWidth() - 50), 75, ALIGN_CENTER);
DrawLine(20, 675, (ScreenWidth() - 20), 675, BLACK);
SetFont(_loginFont, BLACK);
DrawTextRect2(&_passwordButton, "Password");
_loginButton = iRect(ScreenWidth() / 2 - (200 / 2), 700, 200, 50, ALIGN_CENTER);
FillAreaRect(&_loginButton, BLACK);
SetFont(_loginFont, WHITE);
DrawTextRect2(&_loginButton, "Login");
}
void LoginView::keyboardHandlerStatic(char *text)
{
_loginViewStatic->keyboardHandler(text);
}
void LoginView::keyboardHandler(char *text)
{
if (!text)
return;
string s(text);
if (s.empty())
return;
if (_test == 1)
{
_url = s.c_str();
FillAreaRect(&_urlButton, WHITE);
DrawTextRect2(&_urlButton, s.c_str());
}
else if (_test == 2)
{
_username = s.c_str();
FillAreaRect(&_usernameButton, WHITE);
DrawTextRect2(&_usernameButton, s.c_str());
}
else
{
_password = s.c_str();
FillAreaRect(&_passwordButton, WHITE);
string pass;
for (auto i = 0; i < s.length(); i++)
{
pass += "*";
}
DrawTextRect2(&_passwordButton, pass.c_str());
}
_charBuffer = NULL;
}
int LoginView::logginClicked(int x, int y)
{
_charBuffer = new char[4 * MAX_CHAR_BUFF_LENGHT + 1];
if (IsInRect(x, y, &_urlButton))
{
_test = 1;
OpenKeyboard("Url", _charBuffer, MAX_CHAR_BUFF_LENGHT - 1, KBD_NORMAL, &keyboardHandlerStatic);
return 1;
}
else if (IsInRect(x, y, &_usernameButton))
{
_test = 2;
OpenKeyboard("Username", _charBuffer, MAX_CHAR_BUFF_LENGHT - 1, KBD_NORMAL, &keyboardHandlerStatic);
return 1;
}
else if (IsInRect(x, y, &_passwordButton))
{
_test = 3;
OpenKeyboard("Password", _charBuffer, MAX_CHAR_BUFF_LENGHT - 1, KBD_PASSWORD, &keyboardHandlerStatic);
return 1;
}
else if (IsInRect(x, y, &_loginButton))
{
if (_username.empty() || _password.empty() || _url.empty())
{
Message(ICON_ERROR, "Error", "Please set url, username and password.", 600);
return 1;
}
return 2;
}
return 0;
}

57
src/ui/loginView.h 100644
View File

@ -0,0 +1,57 @@
//------------------------------------------------------------------
// loginView.h
//
// Author: JuanJakobo
// Date: 26.08.2020
// Description:
//-------------------------------------------------------------------
#ifndef LOGIN_SCREEN
#define LOGIN_SCREEN
#include "inkview.h"
#include <string>
using std::string;
const int MAX_CHAR_BUFF_LENGHT = 256;
class LoginView
{
public:
LoginView(irect *contentRect);
~LoginView();
void drawLoginView();
int logginClicked(int x, int y);
string getUsername() { return _username; };
string getPassword() { return _password; };
string getURL() { return _url; };
private:
static LoginView *_loginViewStatic;
ifont *_loginFont;
irect *_contentRect;
irect _urlButton;
irect _loginButton;
irect _usernameButton;
irect _passwordButton;
int _test;
string _username;
string _password;
string _url;
char *_charBuffer;
/**
* Functions needed to call C function, handles the panel
*
* @return void
*/
static void keyboardHandlerStatic(char *text);
void keyboardHandler(char *text);
};
#endif

View File

@ -14,98 +14,110 @@
#include <string> #include <string>
#include <curl/curl.h> #include <curl/curl.h>
using namespace std; using std::string;
Nextcloud::Nextcloud() Nextcloud::Nextcloud()
{ {
loggedIn = false; _loggedIn = false;
if(iv_access(NEXTCLOUD_PATH.c_str(), W_OK)!=0) if (iv_access(NEXTCLOUD_PATH.c_str(), W_OK) != 0)
iv_mkdir(NEXTCLOUD_PATH.c_str(),0777); iv_mkdir(NEXTCLOUD_PATH.c_str(), 0777);
if(iv_access(NEXTCLOUD_FILE_PATH.c_str(),W_OK)!=0) if (iv_access(NEXTCLOUD_FILE_PATH.c_str(), W_OK) != 0)
iv_mkdir(NEXTCLOUD_FILE_PATH.c_str(),0777); iv_mkdir(NEXTCLOUD_FILE_PATH.c_str(), 0777);
} }
void Nextcloud::setUsername(const string& Username) void Nextcloud::setURL(const string &Url)
{ {
iconfigedit *temp = nullptr; iconfigedit *temp = nullptr;
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(),temp); iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(), temp);
WriteString(nextcloudConfig,"username",Username.c_str()); WriteString(nextcloudConfig, "url", Url.c_str());
CloseConfig(nextcloudConfig); CloseConfig(nextcloudConfig);
} }
void Nextcloud::setPassword(const string& Pass) void Nextcloud::setUsername(const string &Username)
{ {
iconfigedit *temp = nullptr; iconfigedit *temp = nullptr;
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(),temp); iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(), temp);
WriteSecret(nextcloudConfig,"password",Pass.c_str()); WriteString(nextcloudConfig, "username", Username.c_str());
CloseConfig(nextcloudConfig); CloseConfig(nextcloudConfig);
} }
string Nextcloud::getUsername() void Nextcloud::setPassword(const string &Pass)
{ {
iconfigedit *temp = nullptr; iconfigedit *temp = nullptr;
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(),temp); iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(), temp);
string user = ReadString(nextcloudConfig,"username",""); WriteSecret(nextcloudConfig, "password", Pass.c_str());
CloseConfigNoSave(nextcloudConfig); CloseConfig(nextcloudConfig);
return user;
} }
string Nextcloud::getPassword() bool Nextcloud::login()
{ {
iconfigedit *temp = nullptr; if (getDataStructure(NEXTCLOUD_ROOT_PATH + this->getUsername() + "/", this->getUsername(), this->getPassword()))
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(),temp);
string pass = ReadSecret(nextcloudConfig,"password","");
CloseConfigNoSave(nextcloudConfig);
return pass;
}
bool Nextcloud::login(const string& Username, const string& Pass)
{
if(getDataStructure(NEXTCLOUD_ROOT_PATH + Username + "/",Username,Pass))
{ {
if(iv_access(NEXTCLOUD_CONFIG_PATH.c_str(), W_OK)!=0) _loggedIn = true;
return true;
}
return false;
}
bool Nextcloud::login(const string &Url, const string &Username, const string &Pass)
{
_url = Url;
if (getDataStructure(NEXTCLOUD_ROOT_PATH + Username + "/", Username, Pass))
{
if (iv_access(NEXTCLOUD_CONFIG_PATH.c_str(), W_OK) != 0)
iv_buildpath(NEXTCLOUD_CONFIG_PATH.c_str()); iv_buildpath(NEXTCLOUD_CONFIG_PATH.c_str());
this->setUsername(Username); this->setUsername(Username);
this->setPassword(Pass); this->setPassword(Pass);
loggedIn = true; this->setURL(_url);
_loggedIn = true;
return true; return true;
} }
return false; return false;
} }
bool Nextcloud::getDataStructure(string& pathUrl) void Nextcloud::logout()
{ {
return getDataStructure(pathUrl,this->getUsername(),this->getPassword()); remove(NEXTCLOUD_CONFIG_PATH.c_str());
_url.clear();
_loggedIn = false;
} }
bool Nextcloud::getDataStructure(string &pathUrl)
bool Nextcloud::getDataStructure(const string& pathUrl, const string& Username, const string& Pass)
{ {
if(!Util::connectToNetwork()) return getDataStructure(pathUrl, this->getUsername(), this->getPassword());
}
bool Nextcloud::getDataStructure(const string &pathUrl, const string &Username, const string &Pass)
{
if (!Util::connectToNetwork())
return false; return false;
if(Username.empty() || Pass.empty()) if (_url.empty())
_url = this->getUrl();
if (Username.empty() || Pass.empty())
{ {
Message(ICON_ERROR, "Error", "Username/password not set.", 1200); Message(ICON_ERROR, "Error", "Username/password not set.", 1200);
return false; return false;
} }
items.clear(); _items.clear();
string readBuffer; string readBuffer;
CURLcode res; CURLcode res;
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
if(curl) if (curl)
{ {
string post = Username + ":" + Pass; string post = Username + ":" + Pass;
struct curl_slist *headers = NULL; struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Depth: 1"); headers = curl_slist_append(headers, "Depth: 1");
curl_easy_setopt(curl, CURLOPT_URL, (NEXTCLOUD_URL + pathUrl).c_str()); curl_easy_setopt(curl, CURLOPT_URL, (_url + pathUrl).c_str());
curl_easy_setopt(curl, CURLOPT_USERPWD, post.c_str()); curl_easy_setopt(curl, CURLOPT_USERPWD, post.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER,headers); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PROPFIND"); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PROPFIND");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Util::writeCallback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Util::writeCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
@ -113,7 +125,7 @@ bool Nextcloud::getDataStructure(const string& pathUrl, const string& Username,
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
if(res == CURLE_OK) if (res == CURLE_OK)
{ {
long response_code; long response_code;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
@ -129,40 +141,67 @@ bool Nextcloud::getDataStructure(const string& pathUrl, const string& Username,
begin = readBuffer.find(beginItem); begin = readBuffer.find(beginItem);
while(begin!=std::string::npos) while (begin != std::string::npos)
{ {
end = readBuffer.find(endItem); end = readBuffer.find(endItem);
this->items.push_back(Item(readBuffer.substr(begin,end))); this->_items.push_back(Item(readBuffer.substr(begin, end)));
readBuffer = readBuffer.substr(end+endItem.length()); readBuffer = readBuffer.substr(end + endItem.length());
begin = readBuffer.find(beginItem); begin = readBuffer.find(beginItem);
} }
if(items.size() < 1) if (_items.size() < 1)
return false; return false;
string tes = items[0].getPath(); string tes = _items[0].getPath();
tes = tes.substr(0,tes.find_last_of("/")); tes = tes.substr(0, tes.find_last_of("/"));
tes = tes.substr(0,tes.find_last_of("/")+1); tes = tes.substr(0, tes.find_last_of("/") + 1);
items[0].setPath(tes); _items[0].setPath(tes);
items[0].setTitle("..."); _items[0].setTitle("...");
if(items[0].getPath().compare(NEXTCLOUD_ROOT_PATH) == 0) if (_items[0].getPath().compare(NEXTCLOUD_ROOT_PATH) == 0)
items.erase(items.begin()); _items.erase(_items.begin());
return true; return true;
break; break;
} }
case 401: case 401:
Message(ICON_ERROR, "Error","Username/password incorrect.", 1200); Message(ICON_ERROR, "Error", "Username/password incorrect.", 1200);
break; break;
default: default:
Message(ICON_ERROR,"Error","An unknown error occured." + response_code,1200); Message(ICON_ERROR, "Error", "An unknown error occured." + response_code, 1200);
break; break;
} }
} }
} }
return false; return false;
} }
string Nextcloud::getUrl()
{
iconfigedit *temp = nullptr;
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(), temp);
string url = ReadString(nextcloudConfig, "url", "");
CloseConfigNoSave(nextcloudConfig);
return url;
}
string Nextcloud::getUsername()
{
iconfigedit *temp = nullptr;
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(), temp);
string user = ReadString(nextcloudConfig, "username", "");
CloseConfigNoSave(nextcloudConfig);
return user;
}
string Nextcloud::getPassword()
{
iconfigedit *temp = nullptr;
iconfig *nextcloudConfig = OpenConfig(NEXTCLOUD_CONFIG_PATH.c_str(), temp);
string pass = ReadSecret(nextcloudConfig, "password", "");
CloseConfigNoSave(nextcloudConfig);
return pass;
}

View File

@ -16,25 +16,19 @@
#include <string> #include <string>
#include <vector> #include <vector>
using namespace std; using std::string;
using std::vector;
const string NEXTCLOUD_PATH = "/mnt/ext1/system/config/nextcloud"; const string NEXTCLOUD_PATH = "/mnt/ext1/system/config/nextcloud";
const string NEXTCLOUD_CONFIG_PATH = NEXTCLOUD_PATH + "/nextcloud.cfg"; const string NEXTCLOUD_CONFIG_PATH = NEXTCLOUD_PATH + "/nextcloud.cfg";
const string NEXTCLOUD_FILE_PATH = "/mnt/ext1/nextcloud/"; const string NEXTCLOUD_FILE_PATH = "/mnt/ext1/nextcloud/";
const string NEXTCLOUD_URL = "https://cloud.jjohannssen.de";
const string NEXTCLOUD_ROOT_PATH = "/remote.php/dav/files/"; const string NEXTCLOUD_ROOT_PATH = "/remote.php/dav/files/";
class Nextcloud { class Nextcloud
public: {
public:
explicit Nextcloud(); explicit Nextcloud();
void setUsername(const string& Username);
void setPassword(const string& Pass);
vector<Item> &getItems(){return items;};
bool isLoggedIn(){return loggedIn;};
/** /**
* Handles first login to nextcloud, if sucessfull saves userdata * Handles first login to nextcloud, if sucessfull saves userdata
* *
@ -42,7 +36,11 @@ class Nextcloud {
* @param Pass the pass of the Nextcloud instance * @param Pass the pass of the Nextcloud instance
* @return true - sucessfull login, false - failed login * @return true - sucessfull login, false - failed login
*/ */
bool login(const string& Username, const string& Pass); bool login(const string &Url, const string &Username, const string &Pass);
bool login();
void logout();
/** /**
* gets the dataStructure of the given URL and writes its WEBDAV items to the items vector, reads Userdata from configfile * gets the dataStructure of the given URL and writes its WEBDAV items to the items vector, reads Userdata from configfile
@ -50,7 +48,20 @@ class Nextcloud {
* @param pathUrl URL to get the dataStructure of * @param pathUrl URL to get the dataStructure of
* @return true - sucessfull, false - error * @return true - sucessfull, false - error
*/ */
bool getDataStructure(string& pathUrl); bool getDataStructure(string &pathUrl);
void setURL(const string &Url);
void setUsername(const string &Username);
void setPassword(const string &Pass);
vector<Item> getItems() { return _items; };
bool isLoggedIn() { return _loggedIn; };
private:
vector<Item> _items;
bool _loggedIn;
string _url;
//make username and password local variables or get each time? --> it cant change during login??
/** /**
* gets the dataStructure of the given URL and writes its WEBDAV items to the items vector * gets the dataStructure of the given URL and writes its WEBDAV items to the items vector
@ -60,16 +71,11 @@ class Nextcloud {
* @param Pass the pass of the Nextcloud instance * @param Pass the pass of the Nextcloud instance
* @return true - sucessfull, false - error * @return true - sucessfull, false - error
*/ */
bool getDataStructure(const string& pathUrl, const string& Username, const string& Pass); bool getDataStructure(const string &pathUrl, const string &Username, const string &Pass);
private:
vector<Item> items;
bool loggedIn;
string getUsername(); string getUsername();
string getPassword(); string getPassword();
string getUrl();
}; };
#endif #endif