Feature: also shown local files

pull/23/head
JuanJakobo 2020-11-10 10:27:00 +01:00
parent 62c2dae3dd
commit f2b34d08b4
6 changed files with 86 additions and 59 deletions

View File

@ -151,7 +151,7 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
else else
{ {
int dialogResult = 2; int dialogResult = 2;
if (_nextcloud.getItems()->at(itemID).isDownloaded()) if (_nextcloud.getItems()->at(itemID).getState() != FileState::ICLOUD)
{ {
dialogResult = DialogSynchro(ICON_QUESTION, "Action", "What do you want to do?", "Open", "Sync", "Remove"); dialogResult = DialogSynchro(ICON_QUESTION, "Action", "What do you want to do?", "Open", "Sync", "Remove");
} }

View File

@ -23,20 +23,29 @@ void ListViewEntry::draw(const Item &item)
DrawTextRect(_position.x, _position.y, _position.w, _fontHeight, item.getTitle().c_str(), ALIGN_LEFT); DrawTextRect(_position.x, _position.y, _position.w, _fontHeight, item.getTitle().c_str(), ALIGN_LEFT);
SetFont(_entryFont.get(), BLACK); SetFont(_entryFont.get(), BLACK);
if (item.getType() == IFILE)
if (item.getState() == FileState::ILOCAL)
{ {
DrawTextRect(_position.x, _position.y + _fontHeight, _position.w, _fontHeight, item.getFiletype().c_str(), ALIGN_LEFT); DrawTextRect(_position.x, _position.y + 3 * _fontHeight, _position.w, _fontHeight, "Local", ALIGN_RIGHT);
if (item.isDownloaded()) }
{ else
DrawTextRect(_position.x, _position.y + 3 * _fontHeight, _position.w, _fontHeight, "Synced", ALIGN_RIGHT); {
} if (item.getType() == IFILE)
else {
{ DrawTextRect(_position.x, _position.y + _fontHeight, _position.w, _fontHeight, item.getFiletype().c_str(), ALIGN_LEFT);
DrawTextRect(_position.x, _position.y + 3 * _fontHeight, _position.w, _fontHeight, "Click to Download", ALIGN_RIGHT);
} if (item.getState() == FileState::ISYNCED)
{
DrawTextRect(_position.x, _position.y + 3 * _fontHeight, _position.w, _fontHeight, "Synced", ALIGN_RIGHT);
}
else
{
DrawTextRect(_position.x, _position.y + 3 * _fontHeight, _position.w, _fontHeight, "Click to Download", 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.getSize().c_str(), ALIGN_LEFT);
} }
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.getSize().c_str(), ALIGN_LEFT);
int line = (_position.y + _position.h) - 1; int line = (_position.y + _position.h) - 1;
DrawLine(0, line, ScreenWidth(), line, BLACK); DrawLine(0, line, ScreenWidth(), line, BLACK);

View File

@ -45,11 +45,11 @@ Item::Item(const string &xmlItem)
if (iv_access(_localPath.c_str(), W_OK) != 0) if (iv_access(_localPath.c_str(), W_OK) != 0)
{ {
_downloaded = false; _state = FileState::ICLOUD;
} }
else else
{ {
_downloaded = true; _state = FileState::ISYNCED;
} }
} }
@ -57,7 +57,7 @@ Item::Item(const string &xmlItem)
Util::decodeUrl(_title); Util::decodeUrl(_title);
} }
Item::Item(const string &localPath, bool downloaded) : _localPath(localPath), _downloaded(downloaded) Item::Item(const string &localPath, FileState state) : _localPath(localPath), _state(state)
{ {
_title = _localPath; _title = _localPath;
_title = _title.substr(_title.find_last_of("/") + 1, _title.length()); _title = _title.substr(_title.find_last_of("/") + 1, _title.length());

View File

@ -21,12 +21,19 @@ enum Itemtype
IFOLDER IFOLDER
}; };
enum FileState
{
ICLOUD,
ISYNCED,
ILOCAL
};
class Item class Item
{ {
public: public:
Item(const string &xmlItem); Item(const string &xmlItem);
Item(const string &localPath, bool downloaded); Item(const string &localPath, FileState state);
void setPath(const string &path) { _path = path; }; void setPath(const string &path) { _path = path; };
string getPath() const { return _path; }; string getPath() const { return _path; };
@ -38,11 +45,11 @@ public:
void setTitle(const string &title) { _title = title; }; void setTitle(const string &title) { _title = title; };
string getTitle() const { return _title; }; string getTitle() const { return _title; };
void setDownloaded(bool downloaded) { _downloaded = downloaded; }; void setState(FileState state) { _state = state; };
bool isDownloaded() const { return _downloaded; }; FileState getState() const { return _state; };
string getLastEditDate() const { return _lastEditDate; }; string getLastEditDate() const { return _lastEditDate; };
void setLastEditDate(const string &date){ _lastEditDate = date;}; void setLastEditDate(const string &date) { _lastEditDate = date; };
string getSize() const { return _size; }; string getSize() const { return _size; };
@ -56,7 +63,7 @@ private:
string _path; string _path;
Itemtype _type; Itemtype _type;
string _title; string _title;
bool _downloaded{false}; FileState _state{FileState::ICLOUD};
string _localPath; string _localPath;
string _lastEditDate{"Error"}; string _lastEditDate{"Error"};
string _size{"Error"}; string _size{"Error"};

View File

@ -166,7 +166,7 @@ void Nextcloud::downloadItem(int itemID)
{ {
case 200: case 200:
Log::writeLog("finished download of " + _items->at(itemID).getPath() + " to " + _items->at(itemID).getLocalPath()); Log::writeLog("finished download of " + _items->at(itemID).getPath() + " to " + _items->at(itemID).getLocalPath());
_items->at(itemID).setDownloaded(true); _items->at(itemID).setState(FileState::ISYNCED);
break; break;
case 401: case 401:
Message(ICON_ERROR, "Error", "Username/password incorrect.", 1200); Message(ICON_ERROR, "Error", "Username/password incorrect.", 1200);
@ -256,43 +256,7 @@ bool Nextcloud::getDataStructure(const string &pathUrl, const string &Username,
//TODO if has files that are not online, add to _items //TODO if has files that are not online, add to _items
} }
//get local files, https://stackoverflow.com/questions/306533/how-do-i-get-a-list-of-files-in-a-directory-in-c getLocalFileStructure(localPath);
DIR *dir;
class dirent *ent;
class stat st;
dir = opendir(localPath.c_str());
while ((ent = readdir(dir)) != NULL)
{
const string file_name = ent->d_name;
const string full_file_name = localPath + file_name;
if (file_name[0] == '.')
continue;
if (stat(full_file_name.c_str(), &st) == -1)
continue;
const bool is_directory = (st.st_mode & S_IFDIR) != 0;
if (is_directory)
continue;
bool found = false;
for (auto i = 0; i < _items->size(); i++)
{
//TODO compare last edit local and in cloud and display to user
if (_items->at(i).getLocalPath().compare(full_file_name) == 0)
{
found = true;
break;
}
}
if (!found)
{
_items->push_back(Item(full_file_name, true));
}
}
closedir(dir);
} }
//TODO structure as CSV? //TODO structure as CSV?
@ -434,6 +398,8 @@ bool Nextcloud::getOfflineStructure(const string &pathUrl)
if (!readInXML(buffer.str())) if (!readInXML(buffer.str()))
return false; return false;
getLocalFileStructure(this->getLocalPath(pathUrl));
} }
else else
{ {
@ -451,3 +417,46 @@ bool Nextcloud::getOfflineStructure(const string &pathUrl)
return false; return false;
} }
void Nextcloud::getLocalFileStructure(const string &localPath)
{
//TODO also get folders
//get local files, https://stackoverflow.com/questions/306533/how-do-i-get-a-list-of-files-in-a-directory-in-c
DIR *dir;
class dirent *ent;
class stat st;
dir = opendir(localPath.c_str());
while ((ent = readdir(dir)) != NULL)
{
const string file_name = ent->d_name;
const string full_file_name = localPath + file_name;
if (file_name[0] == '.')
continue;
if (stat(full_file_name.c_str(), &st) == -1)
continue;
//also include directory
const bool is_directory = (st.st_mode & S_IFDIR) != 0;
if (is_directory)
continue;
bool found = false;
for (auto i = 0; i < _items->size(); i++)
{
//TODO compare last edit local and in cloud and display to user
if (_items->at(i).getLocalPath().compare(full_file_name) == 0)
{
found = true;
break;
}
}
if (!found)
{
_items->push_back(Item(full_file_name, FileState::ILOCAL));
}
}
closedir(dir);
}

View File

@ -67,6 +67,8 @@ public:
static string getLocalPath(string path); static string getLocalPath(string path);
void getLocalFileStructure(const string &localPath);
private: private:
static Nextcloud *nextcloudStatic; static Nextcloud *nextcloudStatic;