Feature: Show last modified since now and not complete date

master
JuanJakobo 2022-09-08 12:22:41 +02:00
parent 945013e0a6
commit fc030fa284
1 changed files with 62 additions and 14 deletions

View File

@ -8,7 +8,9 @@
#include "webDAVViewEntry.h" #include "webDAVViewEntry.h"
#include "webDAVModel.h" #include "webDAVModel.h"
#include "util.h"
#include <time.h>
#include <string> #include <string>
WebDAVViewEntry::WebDAVViewEntry(int page, const irect &position, const WebDAVItem &entry) : ListViewEntry(page, position), _entry(entry) WebDAVViewEntry::WebDAVViewEntry(int page, const irect &position, const WebDAVItem &entry) : ListViewEntry(page, position), _entry(entry)
@ -25,55 +27,101 @@ void WebDAVViewEntry::draw(const ifont *entryFont, const ifont *entryFontBold, i
else else
{ {
DrawTextRect(_position.x, _position.y, _position.w, heightOfTitle, _entry.title.c_str(), ALIGN_LEFT); DrawTextRect(_position.x, _position.y, _position.w, heightOfTitle, _entry.title.c_str(), ALIGN_LEFT);
SetFont(entryFont, BLACK); SetFont(entryFont, BLACK);
if (_entry.state == FileState::ILOCAL) if (_entry.state == FileState::ILOCAL)
{ {
DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, "Local", ALIGN_RIGHT); DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, "Local", ALIGN_RIGHT);
} }
else else
{ {
int height = 0;
std::string text = {};
if (_entry.type == Itemtype::IFILE) if (_entry.type == Itemtype::IFILE)
{ {
DrawTextRect(_position.x, _position.y + heightOfTitle, _position.w, fontHeight, _entry.fileType.c_str(), ALIGN_LEFT); height = fontHeight;
DrawTextRect(_position.x, _position.y + heightOfTitle + height, _position.w, fontHeight, _entry.fileType.c_str(), ALIGN_LEFT);
switch(_entry.state) switch(_entry.state)
{ {
case FileState::ISYNCED: case FileState::ISYNCED:
DrawTextRect(_position.x, _position.y + heightOfTitle + 2 * fontHeight, _position.w, fontHeight, "Synced", ALIGN_RIGHT); text = "Synced";
break; break;
case FileState::IOUTSYNCED: case FileState::IOUTSYNCED:
DrawTextRect(_position.x, _position.y + heightOfTitle + 2 * fontHeight, _position.w, fontHeight, "Out of sync", ALIGN_RIGHT); text = "Out of sync";
break; break;
default: default:
DrawTextRect(_position.x, _position.y + heightOfTitle + 2 * fontHeight, _position.w, fontHeight, "Click to Download", ALIGN_RIGHT); text = "Click to download";
} }
DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, _entry.lastEditDate.c_str(), ALIGN_LEFT);
DrawTextRect(_position.x, _position.y + heightOfTitle + 2 * fontHeight, _position.w, fontHeight, _entry.size.c_str(), ALIGN_LEFT);
} }
else else
{ {
switch(_entry.state) switch(_entry.state)
{ {
case FileState::ISYNCED: case FileState::ISYNCED:
DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, "Structure synced", ALIGN_RIGHT); text = "Structure synced";
break; break;
case FileState::IOUTSYNCED: case FileState::IOUTSYNCED:
DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, "Structure out of sync", ALIGN_RIGHT); text = "Structure of out sync";
break; break;
case FileState::ICLOUD: case FileState::ICLOUD:
DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, "Cloud", ALIGN_RIGHT); text = "Cloud";
break; break;
default: default:
break; text = {};
} }
DrawTextRect(_position.x, _position.y + heightOfTitle, _position.w, fontHeight, _entry.lastEditDate.c_str(), ALIGN_LEFT);
DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, _entry.size.c_str(), ALIGN_LEFT);
} }
DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight + height, _position.w, fontHeight, text.c_str(), ALIGN_RIGHT);
DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight + height, _position.w, fontHeight, _entry.size.c_str(), ALIGN_LEFT);
time_t now;
time(&now);
auto seconds = difftime(now,mktime(&_entry.lastEditDate) - timezone);
int sec;
std::string time;
//minutes
if(seconds > 60){
seconds = seconds/60;
sec = seconds;
time = std::to_string(sec) + " minutes ago";
//hours
if(seconds > 60){
seconds = seconds/60;
sec = seconds;
time = std::to_string(sec) + " hours ago";
//days
if(seconds > 24){
seconds = seconds/24;
sec = seconds;
time = std::to_string(sec) + " days ago";
//month
if(seconds > 30){
seconds = seconds/30;
sec = seconds;
time = std::to_string(sec) + " months ago";
//years
if(seconds > 12){
seconds = seconds/12;
sec = seconds;
time = std::to_string(sec) + " years ago";
if(seconds > 1){
time = "at " + Util::webDAVTmToString(_entry.lastEditDate);
}
}
}
}
}
}
//seconds
else
{
sec = seconds;
time = std::to_string(sec) + " seconds ago";
}
time = "Modified " + time;
DrawTextRect(_position.x, _position.y + heightOfTitle, _position.w, fontHeight, time.c_str(), ALIGN_LEFT);
} }
} }