closes #6 Sync of certain folders
parent
a3dc3a6b73
commit
ffb46fa47a
|
@ -109,7 +109,7 @@ void EventHandler::mainMenuHandler(const int index)
|
|||
_nextcloud.logout();
|
||||
break;
|
||||
}
|
||||
_listView.reset();
|
||||
_listView.release();
|
||||
_loginView = std::unique_ptr<LoginView>(new LoginView(_menu.getContentRect()));
|
||||
FullUpdate();
|
||||
break;
|
||||
|
@ -142,11 +142,18 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
|||
int itemID = _listView->listClicked(par1, par2);
|
||||
if (itemID != -1)
|
||||
{
|
||||
int dialogResult = 0;
|
||||
if (_nextcloud.getItems().at(itemID).getType() == Itemtype::IFOLDER)
|
||||
{
|
||||
//TODO temp solution --> remove solution
|
||||
//TODO if is the first option, go back and dont ask for sync
|
||||
int dialogResult = DialogSynchro(ICON_QUESTION, "Action", "What do you want to to do?", "Open folder", "Sync Folder", "Cancel");
|
||||
if (_nextcloud.getItems().at(itemID).getTitle().compare("...") == 0)
|
||||
{
|
||||
dialogResult = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dialogResult = DialogSynchro(ICON_QUESTION, "Action", "What do you want to to do?", "Open folder", "Sync Folder", "Cancel");
|
||||
}
|
||||
|
||||
switch (dialogResult)
|
||||
{
|
||||
case 1:
|
||||
|
@ -156,52 +163,52 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
|||
_tempPath = _nextcloud.getItems().at(itemID).getPath();
|
||||
if (!_tempPath.empty())
|
||||
_nextcloud.setItems(_nextcloud.getDataStructure(_tempPath));
|
||||
_listView.reset(new ListView(_menu.getContentRect(), _nextcloud.getItems()));
|
||||
_listView.release();
|
||||
_listView = std::unique_ptr<ListView>(new ListView(_menu.getContentRect(), _nextcloud.getItems()));
|
||||
_listView->drawHeader(_tempPath.substr(NEXTCLOUD_ROOT_PATH.length()));
|
||||
|
||||
break;
|
||||
case 2:
|
||||
//Sync folder
|
||||
_nextcloud.downloadFolder(_nextcloud.getItems(), itemID);
|
||||
//update the entry and say --> folder is synced
|
||||
//entries in visual and in nextlcoud are out of sync
|
||||
dialogResult = 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
int dialogResult = 0;
|
||||
if (_nextcloud.getItems().at(itemID).getState() != FileState::ICLOUD)
|
||||
{
|
||||
dialogResult = DialogSynchro(ICON_QUESTION, "Action", "What do you want to do?", "Open", "Remove", "Cancel");
|
||||
}
|
||||
|
||||
switch (dialogResult)
|
||||
{
|
||||
case 1:
|
||||
_nextcloud.getItems().at(itemID).open();
|
||||
break;
|
||||
case 2:
|
||||
if (!_nextcloud.getItems().at(itemID).removeFile())
|
||||
Message(ICON_WARNING, "Warning", "Could not delete the file, please try again.", 1200);
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
default:
|
||||
if (_nextcloud.isWorkOffline())
|
||||
switch (dialogResult)
|
||||
{
|
||||
int dialogResult = DialogSynchro(ICON_QUESTION, "Action", "You are in offline modus. Go back online?", "Yes", "No", "Cancel");
|
||||
if (dialogResult == 2 || dialogResult == 3)
|
||||
return 0;
|
||||
_nextcloud.switchWorkOffline();
|
||||
case 1:
|
||||
_nextcloud.getItems().at(itemID).open();
|
||||
break;
|
||||
case 2:
|
||||
if (!_nextcloud.removeItem(itemID))
|
||||
Message(ICON_WARNING, "Warning", "Could not delete the file, please try again.", 1200);
|
||||
_listView->drawEntry(itemID);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
OpenProgressbar(1, "Downloading...", "Check network connection", 0, EventHandler::DialogHandlerStatic);
|
||||
_nextcloud.downloadItem(itemID);
|
||||
CloseProgressbar();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (dialogResult == 0)
|
||||
{
|
||||
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...", "Check network connection", 0, EventHandler::DialogHandlerStatic);
|
||||
_nextcloud.download(itemID);
|
||||
CloseProgressbar();
|
||||
|
||||
//TODO Include Sync notice for folders
|
||||
_listView->drawEntry(itemID);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
ListView::ListView(const irect *contentRect, const vector<Item> items) : _contentRect(contentRect), _items(items)
|
||||
ListView::ListView(const irect *contentRect, const vector<Item> &items) : _contentRect(contentRect), _items(&items)
|
||||
{
|
||||
FillAreaRect(_contentRect, WHITE);
|
||||
|
||||
|
@ -42,7 +42,7 @@ ListView::ListView(const irect *contentRect, const vector<Item> items) : _conten
|
|||
_page = 1;
|
||||
_shownPage = _page;
|
||||
|
||||
auto i = _items.size();
|
||||
auto i = _items->size();
|
||||
auto z = 0;
|
||||
|
||||
_entries.reserve(i);
|
||||
|
@ -107,7 +107,7 @@ void ListView::drawFooter()
|
|||
void ListView::drawEntry(int itemID)
|
||||
{
|
||||
FillAreaRect(_entries[itemID].getPosition(), WHITE);
|
||||
_entries[itemID].draw(_items.at(itemID), _entryFont, _entryFontBold, _entryFontHeight);
|
||||
_entries[itemID].draw(_items->at(itemID), _entryFont, _entryFontBold, _entryFontHeight);
|
||||
}
|
||||
|
||||
void ListView::drawEntries()
|
||||
|
@ -115,7 +115,7 @@ void ListView::drawEntries()
|
|||
for (auto i = 0; i < _entries.size(); i++)
|
||||
{
|
||||
if (_entries[i].getPage() == _shownPage)
|
||||
_entries[i].draw(_items.at(i), _entryFont, _entryFontBold, _entryFontHeight);
|
||||
_entries[i].draw(_items->at(i), _entryFont, _entryFontBold, _entryFontHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
* @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 vector<Item> items);
|
||||
ListView(const irect *contentRect, const vector<Item> &items);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
|
@ -75,7 +75,7 @@ private:
|
|||
int _footerFontHeight;
|
||||
int _entryFontHeight;
|
||||
const irect *_contentRect;
|
||||
vector<Item> _items;
|
||||
std::unique_ptr<const vector<Item>> _items;
|
||||
vector<ListViewEntry> _entries;
|
||||
ifont *_headerFont;
|
||||
ifont *_footerFont;
|
||||
|
|
|
@ -21,11 +21,8 @@ using std::ifstream;
|
|||
using std::ofstream;
|
||||
using std::string;
|
||||
|
||||
//neccesary to use Dialog method
|
||||
std::unique_ptr<Nextcloud> Nextcloud::_nextcloudStatic;
|
||||
Nextcloud::Nextcloud()
|
||||
{
|
||||
_nextcloudStatic = std::unique_ptr<Nextcloud>(this);
|
||||
|
||||
if (iv_access(NEXTCLOUD_PATH.c_str(), W_OK) != 0)
|
||||
iv_mkdir(NEXTCLOUD_PATH.c_str(), 0777);
|
||||
|
@ -141,23 +138,15 @@ void Nextcloud::logout(bool deleteFiles)
|
|||
_loggedIn = false;
|
||||
}
|
||||
|
||||
void Nextcloud::downloadItem(int itemID)
|
||||
void Nextcloud::downloadItem(vector<Item> &tempItems, int itemID)
|
||||
{
|
||||
Log::writeLog("started download of " + _items.at(itemID).getPath() + " to " + _items.at(itemID).getLocalPath());
|
||||
|
||||
if (!Util::connectToNetwork())
|
||||
{
|
||||
Message(ICON_WARNING, "Warning", "Can not connect to the Internet. Switching to offline modus.", 1200);
|
||||
_workOffline = true;
|
||||
}
|
||||
|
||||
if (_items.at(itemID).getPath().empty())
|
||||
if (tempItems.at(itemID).getPath().empty())
|
||||
{
|
||||
Message(ICON_ERROR, "Error", "Download path is not set, therefore cannot download the file.", 1200);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateProgressbar("Starting Download", 0);
|
||||
UpdateProgressbar(("Starting Download of " + tempItems.at(itemID).getPath()).c_str(), 0);
|
||||
|
||||
CURLcode res;
|
||||
CURL *curl = curl_easy_init();
|
||||
|
@ -167,9 +156,9 @@ void Nextcloud::downloadItem(int itemID)
|
|||
string post = this->getUsername() + std::string(":") + this->getPassword();
|
||||
|
||||
FILE *fp;
|
||||
fp = iv_fopen(_items.at(itemID).getLocalPath().c_str(), "wb");
|
||||
fp = iv_fopen(tempItems.at(itemID).getLocalPath().c_str(), "wb");
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, (_url + _items.at(itemID).getPath()).c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_URL, (_url + tempItems.at(itemID).getPath()).c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_USERPWD, post.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Util::writeData);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
||||
|
@ -189,8 +178,8 @@ void Nextcloud::downloadItem(int itemID)
|
|||
switch (response_code)
|
||||
{
|
||||
case 200:
|
||||
Log::writeLog("finished download of " + _items.at(itemID).getPath() + " to " + _items.at(itemID).getLocalPath());
|
||||
_items.at(itemID).setState(FileState::ISYNCED);
|
||||
Log::writeLog("finished download of " + tempItems.at(itemID).getPath() + " to " + tempItems.at(itemID).getLocalPath());
|
||||
tempItems.at(itemID).setState(FileState::ISYNCED);
|
||||
break;
|
||||
case 401:
|
||||
Message(ICON_ERROR, "Error", "Username/password incorrect.", 1200);
|
||||
|
@ -203,40 +192,52 @@ void Nextcloud::downloadItem(int itemID)
|
|||
}
|
||||
}
|
||||
|
||||
bool Nextcloud::downloadFolder(const vector<Item> &tempItems, int itemId)
|
||||
bool Nextcloud::downloadFolder(vector<Item> &tempItems, int itemID)
|
||||
{
|
||||
|
||||
//also has to look at the previous items?
|
||||
|
||||
//do not change items oxml or use temp here?
|
||||
if (tempItems.at(itemId).getType() == Itemtype::IFOLDER)
|
||||
if (tempItems.at(itemID).getType() == Itemtype::IFOLDER)
|
||||
{
|
||||
string temp = tempItems.at(itemID).getPath();
|
||||
Log::writeLog("Path to look for " + temp);
|
||||
vector<Item> tempItems = getDataStructure(temp);
|
||||
|
||||
//get the data structure under the folder that is requested --> overrides items object and therefore will fail!
|
||||
|
||||
//should return items vector?
|
||||
string temp = tempItems.at(itemId).getPath();
|
||||
vector<Item> tempItemsNew = getDataStructure(temp);
|
||||
|
||||
//this will be the new item list --> where to switch to when this process is over --> open the folder that has t be synced?
|
||||
//get item id?
|
||||
for (auto i = 0; i < tempItemsNew.size(); i++)
|
||||
//first item of the vector is the root path itself
|
||||
for (auto i = 1; i < tempItems.size(); i++)
|
||||
{
|
||||
|
||||
downloadFolder(tempItemsNew,itemId);
|
||||
//overrides current item list and therefore nos possible!
|
||||
// has to be read in again?
|
||||
// call method again?
|
||||
Log::writeLog("Item: " + tempItems.at(i).getPath());
|
||||
downloadFolder(tempItems,i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
downloadItem(itemId);
|
||||
//TODO do only if file is newer --> check status
|
||||
Log::writeLog("started download of " + _items.at(itemID).getPath() + " to " + _items.at(itemID).getLocalPath());
|
||||
downloadItem(tempItems, itemID);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Nextcloud::download(int itemID)
|
||||
{
|
||||
if (!Util::connectToNetwork())
|
||||
{
|
||||
Message(ICON_WARNING, "Warning", "Can not connect to the Internet. Switching to offline modus.", 1200);
|
||||
_workOffline = true;
|
||||
return;
|
||||
}
|
||||
|
||||
this->downloadFolder(_items,itemID);
|
||||
}
|
||||
|
||||
bool Nextcloud::removeItem(int itemID)
|
||||
{
|
||||
Log::writeLog("removing file " + _items.at(itemID).getPath());
|
||||
if(!_items.at(itemID).removeFile())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
vector<Item> Nextcloud::getDataStructure(string &pathUrl)
|
||||
{
|
||||
return getDataStructure(pathUrl, this->getUsername(), this->getPassword());
|
||||
|
@ -382,14 +383,6 @@ string Nextcloud::getStartFolder()
|
|||
return startFolder;
|
||||
}
|
||||
|
||||
void Nextcloud::DialogHandlerStatic(int Button)
|
||||
{
|
||||
if (Button == 2)
|
||||
{
|
||||
_nextcloudStatic->_workOffline = true;
|
||||
}
|
||||
}
|
||||
|
||||
vector<Item> Nextcloud::readInXML(string xml)
|
||||
{
|
||||
size_t begin;
|
||||
|
|
|
@ -32,6 +32,18 @@ class Nextcloud
|
|||
public:
|
||||
explicit Nextcloud();
|
||||
|
||||
void setURL(const string &Url);
|
||||
void setUsername(const string &Username);
|
||||
void setPassword(const string &Pass);
|
||||
void setStartFolder(const string &Path);
|
||||
bool setItems(const vector<Item> &tempItems);
|
||||
|
||||
|
||||
const vector<Item> &getItems() const { return _items; };
|
||||
bool isLoggedIn() const { return _loggedIn; };
|
||||
bool isWorkOffline() const { return _workOffline; };
|
||||
void switchWorkOffline() { _workOffline = !_workOffline; };
|
||||
|
||||
/**
|
||||
* Handles first login to nextcloud, if sucessfull saves userdata
|
||||
*
|
||||
|
@ -56,14 +68,17 @@ public:
|
|||
* Downloads a certain item from the Nextcloud and saves it locally
|
||||
* @param itemID id of the item
|
||||
*/
|
||||
void downloadItem(int itemID);
|
||||
|
||||
void downloadItem(vector<Item> &tempItems, int itemID);
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
bool downloadFolder(const vector<Item> &tempItems, int itemId);
|
||||
bool downloadFolder(vector<Item> &tempItems, int itemId);
|
||||
|
||||
void download(int itemId);
|
||||
|
||||
bool removeItem(int itemID);
|
||||
|
||||
/**
|
||||
* gets the dataStructure of the given URL and writes its WEBDAV items to the items vector, reads Userdata from configfile
|
||||
|
@ -73,27 +88,11 @@ public:
|
|||
*/
|
||||
vector<Item> getDataStructure(string &pathUrl);
|
||||
|
||||
void setURL(const string &Url);
|
||||
void setUsername(const string &Username);
|
||||
void setPassword(const string &Pass);
|
||||
void setStartFolder(const string &Path);
|
||||
|
||||
vector<Item> getItems() const { return _items; };
|
||||
bool isLoggedIn() const { return _loggedIn; };
|
||||
bool isWorkOffline() const { return _workOffline; };
|
||||
void switchWorkOffline() { _workOffline = !_workOffline; };
|
||||
|
||||
static string getLocalPath(string path);
|
||||
|
||||
void getLocalFileStructure(const string &localPath);
|
||||
|
||||
|
||||
bool setItems(const vector<Item> &tempItems);
|
||||
|
||||
|
||||
private:
|
||||
static std::unique_ptr<Nextcloud> _nextcloudStatic;
|
||||
|
||||
vector<Item> _items;
|
||||
bool _loggedIn{false};
|
||||
string _url;
|
||||
|
|
Loading…
Reference in New Issue