Feature: also shown local files
parent
62c2dae3dd
commit
f2b34d08b4
|
@ -151,7 +151,7 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
|||
else
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
|
|
@ -23,10 +23,18 @@ void ListViewEntry::draw(const Item &item)
|
|||
DrawTextRect(_position.x, _position.y, _position.w, _fontHeight, item.getTitle().c_str(), ALIGN_LEFT);
|
||||
|
||||
SetFont(_entryFont.get(), BLACK);
|
||||
|
||||
if (item.getState() == FileState::ILOCAL)
|
||||
{
|
||||
DrawTextRect(_position.x, _position.y + 3 * _fontHeight, _position.w, _fontHeight, "Local", ALIGN_RIGHT);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.getType() == IFILE)
|
||||
{
|
||||
DrawTextRect(_position.x, _position.y + _fontHeight, _position.w, _fontHeight, item.getFiletype().c_str(), ALIGN_LEFT);
|
||||
if (item.isDownloaded())
|
||||
|
||||
if (item.getState() == FileState::ISYNCED)
|
||||
{
|
||||
DrawTextRect(_position.x, _position.y + 3 * _fontHeight, _position.w, _fontHeight, "Synced", ALIGN_RIGHT);
|
||||
}
|
||||
|
@ -37,6 +45,7 @@ void ListViewEntry::draw(const Item &item)
|
|||
}
|
||||
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;
|
||||
DrawLine(0, line, ScreenWidth(), line, BLACK);
|
||||
|
|
|
@ -45,11 +45,11 @@ Item::Item(const string &xmlItem)
|
|||
|
||||
if (iv_access(_localPath.c_str(), W_OK) != 0)
|
||||
{
|
||||
_downloaded = false;
|
||||
_state = FileState::ICLOUD;
|
||||
}
|
||||
else
|
||||
{
|
||||
_downloaded = true;
|
||||
_state = FileState::ISYNCED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ Item::Item(const string &xmlItem)
|
|||
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 = _title.substr(_title.find_last_of("/") + 1, _title.length());
|
||||
|
|
|
@ -21,12 +21,19 @@ enum Itemtype
|
|||
IFOLDER
|
||||
};
|
||||
|
||||
enum FileState
|
||||
{
|
||||
ICLOUD,
|
||||
ISYNCED,
|
||||
ILOCAL
|
||||
};
|
||||
|
||||
class Item
|
||||
{
|
||||
public:
|
||||
Item(const string &xmlItem);
|
||||
|
||||
Item(const string &localPath, bool downloaded);
|
||||
Item(const string &localPath, FileState state);
|
||||
|
||||
void setPath(const string &path) { _path = path; };
|
||||
string getPath() const { return _path; };
|
||||
|
@ -38,8 +45,8 @@ public:
|
|||
void setTitle(const string &title) { _title = title; };
|
||||
string getTitle() const { return _title; };
|
||||
|
||||
void setDownloaded(bool downloaded) { _downloaded = downloaded; };
|
||||
bool isDownloaded() const { return _downloaded; };
|
||||
void setState(FileState state) { _state = state; };
|
||||
FileState getState() const { return _state; };
|
||||
|
||||
string getLastEditDate() const { return _lastEditDate; };
|
||||
void setLastEditDate(const string &date) { _lastEditDate = date; };
|
||||
|
@ -56,7 +63,7 @@ private:
|
|||
string _path;
|
||||
Itemtype _type;
|
||||
string _title;
|
||||
bool _downloaded{false};
|
||||
FileState _state{FileState::ICLOUD};
|
||||
string _localPath;
|
||||
string _lastEditDate{"Error"};
|
||||
string _size{"Error"};
|
||||
|
|
|
@ -166,7 +166,7 @@ void Nextcloud::downloadItem(int itemID)
|
|||
{
|
||||
case 200:
|
||||
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;
|
||||
case 401:
|
||||
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
|
||||
}
|
||||
|
||||
//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;
|
||||
|
||||
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);
|
||||
getLocalFileStructure(localPath);
|
||||
}
|
||||
|
||||
//TODO structure as CSV?
|
||||
|
@ -434,6 +398,8 @@ bool Nextcloud::getOfflineStructure(const string &pathUrl)
|
|||
|
||||
if (!readInXML(buffer.str()))
|
||||
return false;
|
||||
|
||||
getLocalFileStructure(this->getLocalPath(pathUrl));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -451,3 +417,46 @@ bool Nextcloud::getOfflineStructure(const string &pathUrl)
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -67,6 +67,8 @@ public:
|
|||
|
||||
static string getLocalPath(string path);
|
||||
|
||||
void getLocalFileStructure(const string &localPath);
|
||||
|
||||
private:
|
||||
static Nextcloud *nextcloudStatic;
|
||||
|
||||
|
|
Loading…
Reference in New Issue