mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-02 11:16:34 -04:00
fixed problems with negative time shifts in DirDetails causing multiple GUI bugs in File Lists and Search
This commit is contained in:
parent
d433713bd0
commit
8c8cc88503
9 changed files with 56 additions and 40 deletions
|
@ -968,8 +968,8 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
|
|||
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash.toStdString()));
|
||||
child->setText(SR_SIZE_COL, QString::number(dir.count));
|
||||
child->setData(SR_SIZE_COL, ROLE_SORT, (qulonglong) dir.count);
|
||||
child->setText(SR_AGE_COL, QString::number(dir.age));
|
||||
child->setData(SR_AGE_COL, ROLE_SORT, dir.age);
|
||||
child->setText(SR_AGE_COL, QString::number(dir.mtime));
|
||||
child->setData(SR_AGE_COL, ROLE_SORT, dir.mtime);
|
||||
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
||||
|
||||
child->setText(SR_SOURCES_COL, QString::number(1));
|
||||
|
@ -994,8 +994,8 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
|
|||
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash.toStdString()));
|
||||
child->setText(SR_SIZE_COL, QString::number(dir.count));
|
||||
child->setData(SR_SIZE_COL, ROLE_SORT, (qulonglong) dir.count);
|
||||
child->setText(SR_AGE_COL, QString::number(dir.age));
|
||||
child->setData(SR_AGE_COL, ROLE_SORT, dir.age);
|
||||
child->setText(SR_AGE_COL, QString::number(dir.mtime));
|
||||
child->setData(SR_AGE_COL, ROLE_SORT, dir.mtime);
|
||||
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
||||
child->setText(SR_SOURCES_COL, QString::number(1));
|
||||
child->setData(SR_SOURCES_COL, ROLE_SORT, 1);
|
||||
|
@ -1063,8 +1063,8 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
|
|||
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash.toStdString()));
|
||||
child->setText(SR_SIZE_COL, QString::number(dir.count));
|
||||
child->setData(SR_SIZE_COL, ROLE_SORT, (qulonglong) dir.count);
|
||||
child->setText(SR_AGE_COL, QString::number(dir.min_age));
|
||||
child->setData(SR_AGE_COL, ROLE_SORT, dir.min_age);
|
||||
child->setText(SR_AGE_COL, QString::number(dir.max_mtime));
|
||||
child->setData(SR_AGE_COL, ROLE_SORT, dir.max_mtime);
|
||||
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
||||
child->setText(SR_SOURCES_COL, QString::number(1));
|
||||
child->setData(SR_SOURCES_COL, ROLE_SORT, 1);
|
||||
|
@ -1320,7 +1320,7 @@ void SearchDialog::resultsToTree(const QString& txt,qulonglong searchId, const s
|
|||
fd.hash = it->hash;
|
||||
fd.path = it->path;
|
||||
fd.size = it->count;
|
||||
fd.age = it->age;
|
||||
fd.age = it->mtime;
|
||||
fd.rank = 0;
|
||||
|
||||
insertFile(searchId,fd, FRIEND_SEARCH);
|
||||
|
|
|
@ -93,7 +93,7 @@ class RSHumanReadableAgeDelegate: public RSHumanReadableDelegate
|
|||
QStyleOptionViewItem opt(option) ;
|
||||
setPainterOptions(painter,opt,index) ;
|
||||
|
||||
painter->drawText(opt.rect, Qt::AlignCenter, misc::userFriendlyDuration(index.data().toLongLong())) ;
|
||||
painter->drawText(opt.rect, Qt::AlignCenter, misc::timeRelativeToNow(index.data().toLongLong())) ;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -68,9 +68,9 @@ Qt::DropActions RetroshareDirModel::supportedDragActions() const
|
|||
}
|
||||
#endif
|
||||
|
||||
static bool isNewerThanEpoque(uint32_t age)
|
||||
static bool isNewerThanEpoque(uint32_t ts)
|
||||
{
|
||||
return age < time(NULL) - 1000 ; // this should be conservative enough
|
||||
return ts > 0 ; // this should be conservative enough
|
||||
}
|
||||
|
||||
void FlatStyle_RDM::update()
|
||||
|
@ -251,12 +251,13 @@ QString RetroshareDirModel::getGroupsString(FileStorageFlags flags,const std::li
|
|||
return groups_str ;
|
||||
}
|
||||
|
||||
|
||||
QString RetroshareDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||
{
|
||||
QString ret("");
|
||||
QString nind = tr("NEW");
|
||||
// QString oind = tr("OLD");
|
||||
uint32_t age = details.min_age;
|
||||
int32_t age = time(NULL) - details.max_mtime;
|
||||
|
||||
switch (ageIndicator) {
|
||||
case IND_LAST_DAY:
|
||||
|
@ -334,7 +335,9 @@ QVariant RetroshareDirModel::decorationRole(const DirDetails& details,int coln)
|
|||
|
||||
if (details.type == DIR_TYPE_PERSON)
|
||||
{
|
||||
if(details.min_age > ageIndicator)
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
if(ageIndicator != IND_ALWAYS && now > details.max_mtime + ageIndicator)
|
||||
return QIcon(":/images/folder_grey.png");
|
||||
else if (ageIndicator == IND_LAST_DAY )
|
||||
return QIcon(":/images/folder_green.png");
|
||||
|
@ -347,7 +350,9 @@ QVariant RetroshareDirModel::decorationRole(const DirDetails& details,int coln)
|
|||
}
|
||||
else if (details.type == DIR_TYPE_DIR)
|
||||
{
|
||||
if(details.min_age > ageIndicator)
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
if(ageIndicator != IND_ALWAYS && now > details.max_mtime + ageIndicator)
|
||||
return QIcon(":/images/folder_grey.png");
|
||||
else if (ageIndicator == IND_LAST_DAY )
|
||||
return QIcon(":/images/folder_green.png");
|
||||
|
@ -408,10 +413,11 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const
|
|||
|
||||
case 1:
|
||||
return QString() ;
|
||||
case 2: if(!isNewerThanEpoque(details.min_age))
|
||||
case 2: if(!isNewerThanEpoque(details.max_mtime))
|
||||
return QString();
|
||||
else
|
||||
return misc::userFriendlyDuration(details.min_age);
|
||||
return misc::timeRelativeToNow(details.max_mtime);
|
||||
|
||||
default:
|
||||
return QString() ;
|
||||
}
|
||||
|
@ -425,7 +431,7 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const
|
|||
case 1:
|
||||
return misc::friendlyUnit(details.count);
|
||||
case 2:
|
||||
return misc::userFriendlyDuration(details.min_age);
|
||||
return misc::timeRelativeToNow(details.max_mtime);
|
||||
case 3:
|
||||
return QVariant();
|
||||
case 4:
|
||||
|
@ -449,7 +455,7 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const
|
|||
}
|
||||
return QString::number(details.count) + " " + tr("File");
|
||||
case 2:
|
||||
return misc::userFriendlyDuration(details.min_age);
|
||||
return misc::timeRelativeToNow(details.max_mtime);
|
||||
case 3:
|
||||
return QVariant();
|
||||
case 4:
|
||||
|
@ -493,7 +499,7 @@ QVariant FlatStyle_RDM::displayRole(const DirDetails& details,int coln) const
|
|||
{
|
||||
case 0: return QString::fromUtf8(details.name.c_str());
|
||||
case 1: return misc::friendlyUnit(details.count);
|
||||
case 2: return misc::userFriendlyDuration(details.min_age);
|
||||
case 2: return misc::timeRelativeToNow(details.max_mtime);
|
||||
case 3: return QString::fromUtf8(rsPeers->getPeerName(details.id).c_str());
|
||||
case 4: return computeDirectoryPath(details);
|
||||
default:
|
||||
|
@ -519,7 +525,7 @@ QVariant TreeStyle_RDM::sortRole(const QModelIndex& /*index*/,const DirDetails&
|
|||
case 1:
|
||||
return QString();
|
||||
case 2:
|
||||
return details.min_age;
|
||||
return details.max_mtime;
|
||||
default:
|
||||
return QString();
|
||||
}
|
||||
|
@ -533,7 +539,7 @@ QVariant TreeStyle_RDM::sortRole(const QModelIndex& /*index*/,const DirDetails&
|
|||
case 1:
|
||||
return (qulonglong) details.count;
|
||||
case 2:
|
||||
return details.min_age;
|
||||
return details.max_mtime;
|
||||
case 3:
|
||||
return getFlagsString(details.flags);
|
||||
case 4:
|
||||
|
@ -556,7 +562,7 @@ QVariant TreeStyle_RDM::sortRole(const QModelIndex& /*index*/,const DirDetails&
|
|||
case 1:
|
||||
return (qulonglong) details.count;
|
||||
case 2:
|
||||
return details.min_age;
|
||||
return details.max_mtime;
|
||||
case 3:
|
||||
return getFlagsString(details.flags);
|
||||
default:
|
||||
|
@ -579,7 +585,7 @@ QVariant FlatStyle_RDM::sortRole(const QModelIndex& /*index*/,const DirDetails&
|
|||
{
|
||||
case 0: return QString::fromUtf8(details.name.c_str());
|
||||
case 1: return (qulonglong) details.count;
|
||||
case 2: return details.min_age;
|
||||
case 2: return details.max_mtime;
|
||||
case 3: return QString::fromUtf8(rsPeers->getPeerName(details.id).c_str());
|
||||
|
||||
case 4: {
|
||||
|
@ -620,7 +626,7 @@ QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const
|
|||
{
|
||||
if(details.type == DIR_TYPE_FILE && details.hash.isNull())
|
||||
return QVariant(QColor(Qt::green)) ;
|
||||
else if(details.min_age > ageIndicator)
|
||||
else if(ageIndicator != IND_ALWAYS && details.max_mtime + ageIndicator < time(NULL))
|
||||
return QVariant(QColor(Qt::gray)) ;
|
||||
else if(RemoteMode)
|
||||
{
|
||||
|
@ -645,7 +651,7 @@ QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const
|
|||
return decorationRole(details,coln) ;
|
||||
|
||||
if(role == Qt::ToolTipRole)
|
||||
if(!isNewerThanEpoque(details.min_age))
|
||||
if(!isNewerThanEpoque(details.max_mtime))
|
||||
return tr("This node hasn't sent any directory information yet.") ;
|
||||
|
||||
/*****************
|
||||
|
@ -921,7 +927,7 @@ Qt::ItemFlags RetroshareDirModel::flags( const QModelIndex & index ) const
|
|||
switch(details.type)
|
||||
{
|
||||
// we grey out a person that has never been updated. It's easy to spot these, since the min age of the directory is approx equal to time(NULL), which exceeds 40 years.
|
||||
case DIR_TYPE_PERSON:return isNewerThanEpoque(details.min_age)? (Qt::ItemIsEnabled):(Qt::NoItemFlags) ;
|
||||
case DIR_TYPE_PERSON:return isNewerThanEpoque(details.max_mtime)? (Qt::ItemIsEnabled):(Qt::NoItemFlags) ;
|
||||
case DIR_TYPE_DIR: return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||
case DIR_TYPE_FILE: return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled;
|
||||
}
|
||||
|
|
|
@ -206,6 +206,15 @@ QString misc::userFriendlyDuration(qlonglong seconds)
|
|||
return tr("%1y %2d", "e.g: 2 years 2days ").arg(years).arg(days);
|
||||
}
|
||||
|
||||
QString misc::timeRelativeToNow(uint32_t mtime)
|
||||
{
|
||||
time_t now = time(NULL) ;
|
||||
if(mtime > now)
|
||||
return misc::userFriendlyDuration(mtime - (int)now) + " (ahead of now)";
|
||||
else
|
||||
return misc::userFriendlyDuration(now - (int)mtime) ;
|
||||
}
|
||||
|
||||
QString misc::userFriendlyUnit(double count, unsigned int decimal, double factor)
|
||||
{
|
||||
if (count <= 0.0) {
|
||||
|
|
|
@ -152,6 +152,9 @@ class misc : public QObject
|
|||
// time duration like "1d 2h 10m".
|
||||
static QString userFriendlyDuration(qlonglong seconds);
|
||||
|
||||
// Computes the time shift between now and the given time, and prints it in a friendly way, accounting for possible negative shifts (time from the future!)
|
||||
static QString timeRelativeToNow(uint32_t mtime);
|
||||
|
||||
static QString userFriendlyUnit(double count, unsigned int decimal, double factor = 1000);
|
||||
|
||||
static QString removeNewLine(const QString &text);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue