optimized visualisation of storage sizes

pull/23/head
JuanJakobo 2020-10-23 17:04:22 +02:00
parent 2028adf22f
commit 8731980d85
3 changed files with 44 additions and 6 deletions

View File

@ -45,7 +45,7 @@ void ListViewEntry::draw(const Item &item)
DrawTextRect(pageButton.w, _position.y, _position.w, fontHeight, item.getTitle().c_str(), ALIGN_LEFT);
DrawTextRect(pageButton.w, _position.y + 2 * fontHeight, _position.w, fontHeight, item.getLastEditDate().c_str(), ALIGN_LEFT);
DrawTextRect(pageButton.w, _position.y + 3 * fontHeight, _position.w, fontHeight, Util::intToString(item.getSize()).c_str(), ALIGN_LEFT);
DrawTextRect(pageButton.w, _position.y + 3 * fontHeight, _position.w, fontHeight, item.getSize().c_str(), ALIGN_LEFT);
int line = (_position.y + _position.h) - 1;

View File

@ -12,6 +12,7 @@
#include "nextcloud.h"
#include "log.h"
#include <math.h>
#include <string>
#include <curl/curl.h>
@ -27,12 +28,13 @@ Item::Item(const string &xmlItem)
{
_type = IFOLDER;
_title = _title.substr(0, _path.length() - 1);
_size = atoi(Util::getXMLAttribute(xmlItem, "d:quota-used-bytes").c_str());
//TODO whatfor do i need the size as double?
setSize(atof(Util::getXMLAttribute(xmlItem, "d:quota-used-bytes").c_str()));
}
else
{
_type = IFILE;
_size = atoi(Util::getXMLAttribute(xmlItem, "d:getcontentlength").c_str());
setSize(atof(Util::getXMLAttribute(xmlItem, "d:getcontentlength").c_str()));
_fileType = Util::getXMLAttribute(xmlItem, "d:getcontenttype");
//set local path and test if exists
@ -49,7 +51,7 @@ Item::Item(const string &xmlItem)
}
_title = _title.substr(_title.find_last_of("/") + 1, _title.length());
_title = Util::replaceString(_title,"%20"," ");
_title = Util::replaceString(_title, "%20", " ");
}
void Item::open() const
@ -79,4 +81,38 @@ void Item::removeFile()
{
remove(_localPath.c_str());
_downloaded = false;
}
void Item::setSize(double tempSize)
{
if (tempSize < 1024)
{
_size = "< 1 KB";
return;
}
double departBy;
string unit;
if (tempSize < 1048576)
{
departBy = 1024;
unit = "KB";
}
else if (tempSize < 1073741824)
{
departBy = 1048576;
unit = "MB";
}
else
{
departBy = 1073741824;
unit = "GB";
}
tempSize = round((tempSize / departBy) * 10.0) / 10.0;
_size = Util::valueToString(tempSize) + " " + unit;
}

View File

@ -42,7 +42,7 @@ public:
string getLastEditDate() const { return _lastEditDate; };
void setLastEditDate(const string &date){ _lastEditDate = date;};
int getSize() const { return _size; };
string getSize() const { return _size; };
string getFiletype() const { return _fileType; };
@ -57,7 +57,9 @@ private:
bool _downloaded;
string _localPath;
string _lastEditDate;
int _size;
string _size;
string _fileType;
void setSize(double tempSize);
};
#endif