add filestate status outsync depending on filesize
parent
9816b37ebb
commit
ff27551524
|
@ -176,7 +176,7 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (_nextcloud.getItems().at(itemID).getState() != FileState::ICLOUD)
|
||||
if (_nextcloud.getItems().at(itemID).getState() == FileState::ISYNCED || _nextcloud.getItems().at(itemID).getState() == FileState::ILOCAL)
|
||||
{
|
||||
dialogResult = DialogSynchro(ICON_QUESTION, "Action", "What do you want to do?", "Open", "Remove", "Cancel");
|
||||
|
||||
|
|
|
@ -36,6 +36,10 @@ void ListViewEntry::draw(const Item &item, ifont *entryFont, ifont *entryFontBol
|
|||
{
|
||||
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, "Synced", ALIGN_RIGHT);
|
||||
}
|
||||
else if(item.getState() == FileState::IOUTSYNCED)
|
||||
{
|
||||
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, "Out of sync", ALIGN_RIGHT);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, "Click to Download", ALIGN_RIGHT);
|
||||
|
@ -50,7 +54,7 @@ void ListViewEntry::draw(const Item &item, ifont *entryFont, ifont *entryFontBol
|
|||
}
|
||||
|
||||
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 + 3 * fontHeight, _position.w, fontHeight, item.getSizeString().c_str(), ALIGN_LEFT);
|
||||
}
|
||||
|
||||
int line = (_position.y + _position.h) - 1;
|
||||
|
|
|
@ -31,12 +31,12 @@ Item::Item(const string &xmlItem)
|
|||
{
|
||||
_type = IFOLDER;
|
||||
_title = _title.substr(0, _path.length() - 1);
|
||||
setSize(atof(Util::getXMLAttribute(xmlItem, "d:quota-used-bytes").c_str()));
|
||||
_size = atof(Util::getXMLAttribute(xmlItem, "d:quota-used-bytes").c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
_type = IFILE;
|
||||
setSize(atof(Util::getXMLAttribute(xmlItem, "d:getcontentlength").c_str()));
|
||||
_size = atof(Util::getXMLAttribute(xmlItem, "d:getcontentlength").c_str());
|
||||
_fileType = Util::getXMLAttribute(xmlItem, "d:getcontenttype");
|
||||
|
||||
//set local path and test if exists
|
||||
|
@ -116,24 +116,22 @@ bool Item::removeFile()
|
|||
return true;
|
||||
}
|
||||
|
||||
void Item::setSize(double tempSize)
|
||||
string Item::getSizeString() const
|
||||
{
|
||||
|
||||
if (tempSize < 1024)
|
||||
{
|
||||
_size = "< 1 KB";
|
||||
return;
|
||||
}
|
||||
if (_size < 1024)
|
||||
return "< 1 KB";
|
||||
|
||||
double departBy;
|
||||
double tempSize;
|
||||
string unit;
|
||||
|
||||
if (tempSize < 1048576)
|
||||
if (_size < 1048576)
|
||||
{
|
||||
departBy = 1024;
|
||||
unit = "KB";
|
||||
}
|
||||
else if (tempSize < 1073741824)
|
||||
else if (_size < 1073741824)
|
||||
{
|
||||
departBy = 1048576;
|
||||
unit = "MB";
|
||||
|
@ -145,5 +143,5 @@ void Item::setSize(double tempSize)
|
|||
}
|
||||
|
||||
tempSize = round((tempSize / departBy) * 10.0) / 10.0;
|
||||
_size = Util::valueToString(tempSize) + " " + unit;
|
||||
return Util::valueToString(tempSize) + " " + unit;
|
||||
}
|
|
@ -25,6 +25,7 @@ enum FileState
|
|||
{
|
||||
ICLOUD,
|
||||
ISYNCED,
|
||||
IOUTSYNCED,
|
||||
ILOCAL
|
||||
};
|
||||
|
||||
|
@ -71,7 +72,8 @@ public:
|
|||
string getLastEditDate() const { return _lastEditDate; };
|
||||
void setLastEditDate(const string &date) { _lastEditDate = date; };
|
||||
|
||||
string getSize() const { return _size; };
|
||||
double getSize() const { return _size;};
|
||||
string getSizeString() const;
|
||||
|
||||
string getFiletype() const { return _fileType; };
|
||||
|
||||
|
@ -82,7 +84,7 @@ private:
|
|||
FileState _state{FileState::ICLOUD};
|
||||
string _localPath;
|
||||
string _lastEditDate{"Error"};
|
||||
string _size{"Error"};
|
||||
double _size;
|
||||
string _fileType;
|
||||
|
||||
/**
|
||||
|
|
|
@ -142,6 +142,12 @@ void Nextcloud::logout(bool deleteFiles)
|
|||
|
||||
void Nextcloud::downloadItem(vector<Item> &tempItems, int itemID)
|
||||
{
|
||||
if(tempItems.at(itemID).getState() == FileState::ISYNCED)
|
||||
{
|
||||
Message(ICON_INFORMATION, "INFO", ("The newest version of file " + tempItems.at(itemID).getPath() + " is already downloaded.").c_str(), 2000);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tempItems.at(itemID).getPath().empty())
|
||||
{
|
||||
Message(ICON_ERROR, "Error", "Download path is not set, therefore cannot download the file.", 2000);
|
||||
|
@ -215,7 +221,6 @@ bool Nextcloud::downloadFolder(vector<Item> &tempItems, int itemID)
|
|||
}
|
||||
else
|
||||
{
|
||||
//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);
|
||||
}
|
||||
|
@ -327,7 +332,7 @@ vector<Item> Nextcloud::getDataStructure(const string &pathUrl, const string &Us
|
|||
Log::writeLog("Local structure of " + localPath + " found.");
|
||||
}
|
||||
|
||||
getLocalFileStructure(localPath);
|
||||
getLocalFileStructure(tempItems, localPath);
|
||||
}
|
||||
|
||||
//update the .structure file acording to items in the folder
|
||||
|
@ -445,7 +450,7 @@ vector<Item> Nextcloud::getOfflineStructure(const string &pathUrl)
|
|||
if (tempItems.empty())
|
||||
return {};
|
||||
|
||||
getLocalFileStructure(this->getLocalPath(pathUrl));
|
||||
getLocalFileStructure(tempItems, this->getLocalPath(pathUrl));
|
||||
return tempItems;
|
||||
}
|
||||
else
|
||||
|
@ -464,9 +469,8 @@ vector<Item> Nextcloud::getOfflineStructure(const string &pathUrl)
|
|||
return {};
|
||||
}
|
||||
|
||||
void Nextcloud::getLocalFileStructure(const string &localPath)
|
||||
void Nextcloud::getLocalFileStructure(vector<Item> &tempItems, const string &localPath)
|
||||
{
|
||||
//TODO also show local folders that are not synced to the cloud yet
|
||||
//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;
|
||||
|
@ -475,33 +479,39 @@ void Nextcloud::getLocalFileStructure(const string &localPath)
|
|||
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;
|
||||
const string fileName = ent->d_name;
|
||||
const string fullFileName = localPath + fileName;
|
||||
|
||||
if (file_name[0] == '.')
|
||||
if (fileName[0] == '.')
|
||||
continue;
|
||||
|
||||
if (stat(full_file_name.c_str(), &st) == -1)
|
||||
if (stat(fullFileName.c_str(), &st) == -1)
|
||||
continue;
|
||||
|
||||
//also include directory
|
||||
const bool is_directory = (st.st_mode & S_IFDIR) != 0;
|
||||
if (is_directory)
|
||||
const bool isDirectory = (st.st_mode & S_IFDIR) != 0;
|
||||
if (isDirectory)
|
||||
continue;
|
||||
|
||||
bool found = false;
|
||||
for (auto i = 0; i < _items.size(); i++)
|
||||
for (auto i = 0; i < tempItems.size(); i++)
|
||||
{
|
||||
//TODO compare last edit local and in cloud and display to user
|
||||
if (_items.at(i).getLocalPath().compare(full_file_name) == 0)
|
||||
if (tempItems.at(i).getLocalPath().compare(fullFileName) == 0)
|
||||
{
|
||||
std::ifstream in(fullFileName, std::ifstream::binary | std::ifstream::ate );
|
||||
Log::writeLog(Util::valueToString(in.tellg()));
|
||||
Log::writeLog(Util::valueToString(tempItems.at(i).getSize()));
|
||||
if(in.tellg() != tempItems.at(i).getSize())
|
||||
{
|
||||
tempItems.at(i).setState(FileState::IOUTSYNCED);
|
||||
}
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
_items.push_back(Item(full_file_name, FileState::ILOCAL));
|
||||
//TODO push to different items list and then ask if shall be deleted later on? --> just in case of folder sync
|
||||
tempItems.push_back(Item(fullFileName, FileState::ILOCAL));
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
|
|
|
@ -90,7 +90,7 @@ public:
|
|||
|
||||
static string getLocalPath(string path);
|
||||
|
||||
void getLocalFileStructure(const string &localPath);
|
||||
void getLocalFileStructure(vector<Item> &tempItems, const string &localPath);
|
||||
|
||||
private:
|
||||
vector<Item> _items;
|
||||
|
|
Loading…
Reference in New Issue