added download function
parent
0408821e46
commit
b212608bcd
|
@ -98,7 +98,14 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
|||
int itemID = _listView->listClicked(par1, par2);
|
||||
if (itemID != -1)
|
||||
{
|
||||
string tempPath = _nextcloud->getItems()[itemID].isClicked();
|
||||
if (_nextcloud->getItems()[itemID].getType() == Itemtype::IFOLDER)
|
||||
{
|
||||
FillAreaRect(_menu->getContentRect(), WHITE);
|
||||
irect loadingScreenRect = iRect(_menu->getContentRect()->w / 2 - 100, _menu->getContentRect()->h / 2 - 50, 200, 100, ALIGN_CENTER);
|
||||
DrawTextRect2(&loadingScreenRect, "Loading...");
|
||||
PartialUpdate(loadingScreenRect.x, loadingScreenRect.y, loadingScreenRect.w, loadingScreenRect.h);
|
||||
|
||||
string tempPath = _nextcloud->getItems()[itemID].getPath();
|
||||
|
||||
if (!tempPath.empty())
|
||||
_nextcloud->getDataStructure(tempPath);
|
||||
|
@ -106,9 +113,17 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
|||
delete _listView;
|
||||
_listView = new ListView(_menu->getContentRect(), _nextcloud->getItems());
|
||||
_listView->drawHeader(tempPath.substr(NEXTCLOUD_ROOT_PATH.length()));
|
||||
}
|
||||
|
||||
PartialUpdate(_menu->getContentRect()->x, _menu->getContentRect()->y, _menu->getContentRect()->w, _menu->getContentRect()->h);
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO --> download in new thread and show progress and when back on the site show progress... pop up if not on site and download finshed
|
||||
//warning if downloading and leaving programm
|
||||
_nextcloud->downloadItem(itemID);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if (_loginView != nullptr)
|
||||
|
|
|
@ -20,7 +20,6 @@ using std::vector;
|
|||
|
||||
ListView::ListView(irect *contentRect, const vector<Item> &items) : _contentRect(contentRect), _items(items)
|
||||
{
|
||||
_loadingScreenRect = iRect(_contentRect->w / 2 - 100, _contentRect->h / 2 - 50, 200, 100, ALIGN_CENTER);
|
||||
_font = OpenFont("LiberationMono", 30, 1);
|
||||
SetFont(_font, BLACK);
|
||||
FillAreaRect(_contentRect, WHITE);
|
||||
|
@ -118,14 +117,10 @@ int ListView::listClicked(int x, int y)
|
|||
}
|
||||
else
|
||||
{
|
||||
FillAreaRect(_contentRect, WHITE);
|
||||
|
||||
for (unsigned int i = 0; i < _entries.size(); i++)
|
||||
{
|
||||
if (_entries[i].getPage() == _shownPage && IsInRect(x, y, _entries[i].getPosition()) == 1)
|
||||
{
|
||||
DrawTextRect2(&_loadingScreenRect, "Loading...");
|
||||
PartialUpdate(_loadingScreenRect.x, _loadingScreenRect.y, _loadingScreenRect.w, _loadingScreenRect.h);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,6 @@ private:
|
|||
irect *_contentRect;
|
||||
const vector<Item> _items;
|
||||
|
||||
irect _loadingScreenRect;
|
||||
ifont *_font;
|
||||
|
||||
vector<ListViewEntry> _entries;
|
||||
|
|
|
@ -34,22 +34,23 @@ Item::Item(const string &xmlItem)
|
|||
_type = IFILE;
|
||||
_size = atoi(Util::getXMLAttribute(xmlItem, "d:getcontentlength").c_str());
|
||||
_fileType = Util::getXMLAttribute(xmlItem, "d:getcontenttype");
|
||||
|
||||
//set local path and test if exists
|
||||
_localPath = _path;
|
||||
if (_localPath.find(NEXTCLOUD_ROOT_PATH) != string::npos)
|
||||
_localPath = _localPath.substr(NEXTCLOUD_ROOT_PATH.length());
|
||||
|
||||
_localPath = NEXTCLOUD_FILE_PATH + "/" + _localPath;
|
||||
|
||||
if (iv_access(_localPath.c_str(), W_OK) != 0)
|
||||
{
|
||||
_downloaded = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_downloaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
_title = _title.substr(_title.find_last_of("/") + 1, _title.length());
|
||||
}
|
||||
|
||||
string Item::isClicked()
|
||||
{
|
||||
if (_type == IFILE)
|
||||
{
|
||||
//downloadFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
|
@ -29,11 +29,14 @@ public:
|
|||
void setPath(const string &path) { _path = path; };
|
||||
string getPath() const { return _path; };
|
||||
|
||||
string getLocalPath() const { return _localPath; };
|
||||
|
||||
Itemtype getType() const { return _type; };
|
||||
|
||||
void setTitle(const string &title) { _title = title; };
|
||||
string getTitle() const { return _title; };
|
||||
|
||||
void setDownloaded(bool downloaded) { _downloaded = downloaded; };
|
||||
bool isDownloaded() const { return _downloaded; };
|
||||
|
||||
string getLastEditDate() const { return _lastEditDate; };
|
||||
|
@ -42,18 +45,12 @@ public:
|
|||
|
||||
string getFiletype() const { return _fileType; };
|
||||
|
||||
/**
|
||||
* downloads a file from WEBDAV and saves it
|
||||
*
|
||||
* @return true - sucessfull, false - error
|
||||
*/
|
||||
string isClicked();
|
||||
|
||||
private:
|
||||
string _path;
|
||||
Itemtype _type;
|
||||
string _title;
|
||||
bool _downloaded;
|
||||
string _localPath;
|
||||
string _lastEditDate;
|
||||
int _size;
|
||||
string _fileType;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "nextcloud.h"
|
||||
#include "util.h"
|
||||
#include "item.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <string>
|
||||
#include <curl/curl.h>
|
||||
|
@ -83,6 +84,68 @@ void Nextcloud::logout()
|
|||
remove(NEXTCLOUD_CONFIG_PATH.c_str());
|
||||
_url.clear();
|
||||
_loggedIn = false;
|
||||
//TODO remove files
|
||||
}
|
||||
|
||||
bool Nextcloud::downloadItem(int itemID)
|
||||
{
|
||||
Log::writeLog("started download of " + _items[itemID].getPath() + " to " + _items[itemID].getLocalPath());
|
||||
|
||||
if (!Util::connectToNetwork())
|
||||
return false;
|
||||
|
||||
//create neccesary subfolders
|
||||
|
||||
if (iv_access(_items[itemID].getLocalPath().c_str(), W_OK) != 0)
|
||||
{
|
||||
iv_buildpath(_items[itemID].getLocalPath().c_str());
|
||||
Log::writeLog("Created new path " + _items[itemID].getLocalPath());
|
||||
}
|
||||
|
||||
CURLcode res;
|
||||
CURL *curl = curl_easy_init();
|
||||
|
||||
if (curl)
|
||||
{
|
||||
string post = this->getUsername() + std::string(":") + this->getPassword();
|
||||
|
||||
FILE *fp;
|
||||
fp = iv_fopen(_items[itemID].getLocalPath().c_str(), "wb");
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, (_url + _items[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);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, Util::progress_callback);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
iv_fclose(fp);
|
||||
|
||||
if (res == CURLE_OK)
|
||||
{
|
||||
long response_code;
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
|
||||
|
||||
switch (response_code)
|
||||
{
|
||||
case 200:
|
||||
//TEMP
|
||||
Message(ICON_INFORMATION, "Information", ("finished download of " + _items[itemID].getPath() + " to " + _items[itemID].getLocalPath()).c_str(), 1200);
|
||||
Log::writeLog("finished download of " + _items[itemID].getPath() + " to " + _items[itemID].getLocalPath());
|
||||
_items[itemID].setDownloaded(true);
|
||||
return true;
|
||||
case 401:
|
||||
Message(ICON_ERROR, "Error", "Username/password incorrect.", 1200);
|
||||
break;
|
||||
default:
|
||||
Message(ICON_ERROR, "Error", "An unknown error occured.", 1200);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Nextcloud::getDataStructure(string &pathUrl)
|
||||
|
|
|
@ -21,7 +21,7 @@ using std::vector;
|
|||
|
||||
const string NEXTCLOUD_PATH = "/mnt/ext1/system/config/nextcloud";
|
||||
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_ROOT_PATH = "/remote.php/dav/files/";
|
||||
|
||||
class Nextcloud
|
||||
|
@ -42,6 +42,8 @@ public:
|
|||
|
||||
void logout();
|
||||
|
||||
bool downloadItem(int itemID);
|
||||
|
||||
/**
|
||||
* gets the dataStructure of the given URL and writes its WEBDAV items to the items vector, reads Userdata from configfile
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue