mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-22 06:05:08 -05:00
made the age indicator functional, by recursively changing color of directory/files
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2244 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
38b0c578bb
commit
024e7f4b44
@ -195,7 +195,8 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
|
|||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
fiMutex.lock(); { /* LOCKED DIRS */
|
fiMutex.lock();
|
||||||
|
{ /* LOCKED DIRS */
|
||||||
|
|
||||||
//fi.root->name = data.pid;
|
//fi.root->name = data.pid;
|
||||||
|
|
||||||
@ -221,6 +222,8 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fi.updateMaxModTime() ;
|
||||||
|
|
||||||
} fiMutex.unlock(); /* UNLOCKED DIRS */
|
} fiMutex.unlock(); /* UNLOCKED DIRS */
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
@ -1026,6 +1029,7 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t
|
|||||||
details.path = "root";
|
details.path = "root";
|
||||||
details.age = 0;
|
details.age = 0;
|
||||||
details.flags = 0;
|
details.flags = 0;
|
||||||
|
details.min_age = 0 ;
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
@ -559,6 +559,24 @@ int FileIndex::setRootDirectories(std::list<std::string> inlist, time_t updtime)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileIndex::updateMaxModTime()
|
||||||
|
{
|
||||||
|
RecursUpdateMaxModTime(root) ;
|
||||||
|
}
|
||||||
|
void FileIndex::RecursUpdateMaxModTime(DirEntry *dir)
|
||||||
|
{
|
||||||
|
time_t max_mod_t = 0 ;
|
||||||
|
|
||||||
|
for(std::map<std::string,DirEntry*>::iterator it(dir->subdirs.begin());it!=dir->subdirs.end();++it)
|
||||||
|
{
|
||||||
|
RecursUpdateMaxModTime(it->second) ;
|
||||||
|
max_mod_t = std::max(max_mod_t, it->second->most_recent_time) ;
|
||||||
|
}
|
||||||
|
for(std::map<std::string,FileEntry*>::iterator it(dir->files.begin());it!=dir->files.end();++it)
|
||||||
|
max_mod_t = std::max(max_mod_t, it->second->modtime) ;
|
||||||
|
|
||||||
|
dir->most_recent_time = max_mod_t ;
|
||||||
|
}
|
||||||
|
|
||||||
int FileIndex::getRootDirectories(std::list<std::string> &outlist)
|
int FileIndex::getRootDirectories(std::list<std::string> &outlist)
|
||||||
{
|
{
|
||||||
@ -571,7 +589,7 @@ int FileIndex::getRootDirectories(std::list<std::string> &outlist)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update (index building) */
|
/* update (index building) */
|
||||||
DirEntry *FileIndex::updateDirEntry(std::string fpath, FileEntry fe, time_t utime)
|
DirEntry *FileIndex::updateDirEntry(std::string fpath, FileEntry fe, time_t utime)
|
||||||
{
|
{
|
||||||
/* path is to parent */
|
/* path is to parent */
|
||||||
@ -1183,7 +1201,7 @@ bool FileIndex::extractData(void *ref,DirDetails& details)
|
|||||||
if(!isValid(ref))
|
if(!isValid(ref))
|
||||||
{
|
{
|
||||||
#ifdef FI_DEBUG
|
#ifdef FI_DEBUG
|
||||||
std::cerr << "FileIndex::RequestDirDetails() asked for an invalid pointer " << (void*)ref << std::endl;
|
std::cerr << "FileIndex::extractData() asked for an invalid pointer " << (void*)ref << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
@ -1192,11 +1210,12 @@ bool FileIndex::extractData(void *ref,DirDetails& details)
|
|||||||
DirEntry *dir = dynamic_cast<DirEntry *>(file);
|
DirEntry *dir = dynamic_cast<DirEntry *>(file);
|
||||||
|
|
||||||
details.children = std::list<DirStub>() ;
|
details.children = std::list<DirStub>() ;
|
||||||
|
time_t now = time(NULL) ;
|
||||||
|
|
||||||
if (dir!=NULL) /* has children --- fill */
|
if (dir!=NULL) /* has children --- fill */
|
||||||
{
|
{
|
||||||
#ifdef FI_DEBUG
|
#ifdef FI_DEBUG
|
||||||
std::cerr << "FileIndex::RequestDirDetails() ref=dir" << std::endl;
|
std::cerr << "FileIndex::extractData() ref=dir" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
/* extract all the entries */
|
/* extract all the entries */
|
||||||
for(std::map<std::string,DirEntry*>::const_iterator dit(dir->subdirs.begin()); dit != dir->subdirs.end(); ++dit)
|
for(std::map<std::string,DirEntry*>::const_iterator dit(dir->subdirs.begin()); dit != dir->subdirs.end(); ++dit)
|
||||||
@ -1225,22 +1244,24 @@ bool FileIndex::extractData(void *ref,DirDetails& details)
|
|||||||
details.type = DIR_TYPE_DIR;
|
details.type = DIR_TYPE_DIR;
|
||||||
details.hash = "";
|
details.hash = "";
|
||||||
details.count = dir->subdirs.size() + dir->files.size();
|
details.count = dir->subdirs.size() + dir->files.size();
|
||||||
|
details.min_age = now - dir->most_recent_time ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef FI_DEBUG
|
#ifdef FI_DEBUG
|
||||||
std::cerr << "FileIndexStore::RequestDirDetails() ref=file" << std::endl;
|
std::cerr << "FileIndexStore::extractData() ref=file" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
details.type = DIR_TYPE_FILE;
|
details.type = DIR_TYPE_FILE;
|
||||||
details.count = file->size;
|
details.count = file->size;
|
||||||
|
details.min_age = now - file->modtime ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FI_DEBUG
|
#ifdef FI_DEBUG
|
||||||
std::cerr << "FileIndexStore::RequestDirDetails() name: " << file->name << std::endl;
|
std::cerr << "FileIndexStore::extractData() name: " << file->name << std::endl;
|
||||||
#endif
|
#endif
|
||||||
details.ref = file;
|
details.ref = file;
|
||||||
details.hash = file->hash;
|
details.hash = file->hash;
|
||||||
details.age = time(NULL) - file->modtime;
|
details.age = now - file->modtime;
|
||||||
details.flags = 0;//file->pop;
|
details.flags = 0;//file->pop;
|
||||||
|
|
||||||
/* find parent pointer, and row */
|
/* find parent pointer, and row */
|
||||||
|
@ -144,6 +144,8 @@ void writeFileInfo(std::ostringstream&);
|
|||||||
std::map<std::string, DirEntry *> subdirs;
|
std::map<std::string, DirEntry *> subdirs;
|
||||||
std::map<std::string, FileEntry *> files;
|
std::map<std::string, FileEntry *> files;
|
||||||
|
|
||||||
|
time_t most_recent_time; /* last updated */
|
||||||
|
|
||||||
/* Inherited members from FileEntry:
|
/* Inherited members from FileEntry:
|
||||||
int size - count for dirs
|
int size - count for dirs
|
||||||
std::string name; - directory name
|
std::string name; - directory name
|
||||||
@ -226,6 +228,12 @@ class FileIndex
|
|||||||
int searchHash(std::string hash, std::list<FileEntry *> &results) const;
|
int searchHash(std::string hash, std::list<FileEntry *> &results) const;
|
||||||
int searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const;
|
int searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const;
|
||||||
|
|
||||||
|
/// Recursively compute the maximum modification time of children.
|
||||||
|
/// Used to easily retrieve mose recent files.
|
||||||
|
//
|
||||||
|
void updateMaxModTime() ;
|
||||||
|
void RecursUpdateMaxModTime(DirEntry *) ;
|
||||||
|
|
||||||
PersonEntry *root;
|
PersonEntry *root;
|
||||||
|
|
||||||
static std::set<void*> _pointers ;
|
static std::set<void*> _pointers ;
|
||||||
|
@ -126,10 +126,12 @@ int FileIndexStore::loadCache(const CacheData &data)
|
|||||||
for(it = indices.begin(); it != indices.end(); it++)
|
for(it = indices.begin(); it != indices.end(); it++)
|
||||||
{
|
{
|
||||||
(it->second)->root->row = i++;
|
(it->second)->root->row = i++;
|
||||||
|
it->second->FileIndex::updateMaxModTime() ;
|
||||||
}
|
}
|
||||||
if (localindex)
|
if (localindex)
|
||||||
{
|
{
|
||||||
localindex->root->row = 0;
|
localindex->root->row = 0;
|
||||||
|
localindex->updateMaxModTime() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlockData();
|
unlockData();
|
||||||
@ -220,6 +222,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
|
|||||||
details.count = indices.size();
|
details.count = indices.size();
|
||||||
details.age = 0;
|
details.age = 0;
|
||||||
details.flags = 0;
|
details.flags = 0;
|
||||||
|
details.min_age = 0;
|
||||||
|
|
||||||
unlockData();
|
unlockData();
|
||||||
return true ;
|
return true ;
|
||||||
|
@ -244,6 +244,7 @@ class DirDetails
|
|||||||
uint64_t count;
|
uint64_t count;
|
||||||
uint32_t age;
|
uint32_t age;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
|
uint32_t min_age ; // minimum age of files in this subtree
|
||||||
|
|
||||||
std::list<DirStub> children;
|
std::list<DirStub> children;
|
||||||
};
|
};
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
RemoteDirModel::RemoteDirModel(bool mode, QObject *parent)
|
RemoteDirModel::RemoteDirModel(bool mode, QObject *parent)
|
||||||
: QAbstractItemModel(parent),
|
: QAbstractItemModel(parent),
|
||||||
RemoteMode(mode), nIndex(1), indexSet(1) /* ass zero index cant be used */,
|
RemoteMode(mode), nIndex(1), indexSet(1) /* ass zero index cant be used */,
|
||||||
ageIndicator(0)
|
ageIndicator(IND_ALWAYS)
|
||||||
{
|
{
|
||||||
setSupportedDragActions(Qt::CopyAction);
|
setSupportedDragActions(Qt::CopyAction);
|
||||||
treeStyle();
|
treeStyle();
|
||||||
@ -147,7 +147,6 @@ void RemoteDirModel::treeStyle()
|
|||||||
std::cerr << "lookup PER/DIR #" << details.count;
|
std::cerr << "lookup PER/DIR #" << details.count;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return details.count;
|
return details.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,10 +183,10 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
|||||||
case IND_LAST_MONTH:
|
case IND_LAST_MONTH:
|
||||||
if (age < 30 * 24 * 60 * 60) return nind;
|
if (age < 30 * 24 * 60 * 60) return nind;
|
||||||
break;
|
break;
|
||||||
case IND_OLDER:
|
// case IND_OLDER:
|
||||||
if (age >= 30 * 24 * 60 * 60) return oind;
|
// if (age >= 30 * 24 * 60 * 60) return oind;
|
||||||
break;
|
// break;
|
||||||
case IND_DEFAULT:
|
case IND_ALWAYS:
|
||||||
return ret;
|
return ret;
|
||||||
default:
|
default:
|
||||||
return ret;
|
return ret;
|
||||||
@ -232,6 +231,18 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
|||||||
return QString::fromStdString(finfo.path) ;
|
return QString::fromStdString(finfo.path) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (role == Qt::TextColorRole)
|
||||||
|
{
|
||||||
|
FileInfo finfo;
|
||||||
|
rsFiles->FileDetails(details.hash, 0, finfo);
|
||||||
|
|
||||||
|
if(details.min_age > ageIndicator)
|
||||||
|
return Qt::gray ;
|
||||||
|
else
|
||||||
|
return Qt::black ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (role == Qt::DecorationRole)
|
if (role == Qt::DecorationRole)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -404,7 +415,7 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
|||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
QString ind("");
|
QString ind("");
|
||||||
if (ageIndicator != IND_DEFAULT)
|
if (ageIndicator != IND_ALWAYS)
|
||||||
ind = getAgeIndicatorString(details);
|
ind = getAgeIndicatorString(details);
|
||||||
return ind;
|
return ind;
|
||||||
}
|
}
|
||||||
@ -577,13 +588,14 @@ QModelIndex RemoteDirModel::index(int row, int column, const QModelIndex & paren
|
|||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* now iterate through the details to
|
/* now iterate through the details to
|
||||||
* get the reference number
|
* get the reference number
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::list<DirStub>::iterator it;
|
std::list<DirStub>::iterator it;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(it = details.children.begin(); ((i < row) && (it != details.children.end())); ++it, ++i) ;
|
for(it = details.children.begin(); ((i < row) && (it != details.children.end())); ++it,++i) ;
|
||||||
|
|
||||||
if (it == details.children.end())
|
if (it == details.children.end())
|
||||||
{
|
{
|
||||||
@ -715,14 +727,14 @@ Qt::ItemFlags RemoteDirModel::flags( const QModelIndex & index ) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RemoteDirModel::update (const QModelIndex &index )
|
//void RemoteDirModel::update (const QModelIndex &index )
|
||||||
{
|
//{
|
||||||
#ifdef RDM_DEBUG
|
//#ifdef RDM_DEBUG
|
||||||
//std::cerr << "Directory Request(" << id << ") : ";
|
// //std::cerr << "Directory Request(" << id << ") : ";
|
||||||
//std::cerr << path << std::endl;
|
// //std::cerr << path << std::endl;
|
||||||
#endif
|
//#endif
|
||||||
//rsFiles -> RequestDirectories(id, path, 1);
|
// //rsFiles -> RequestDirectories(id, path, 1);
|
||||||
}
|
//}
|
||||||
|
|
||||||
void RemoteDirModel::downloadSelected(QModelIndexList list)
|
void RemoteDirModel::downloadSelected(QModelIndexList list)
|
||||||
{
|
{
|
||||||
|
@ -30,11 +30,10 @@
|
|||||||
#include "util/misc.h"
|
#include "util/misc.h"
|
||||||
#include "rsiface/rstypes.h"
|
#include "rsiface/rstypes.h"
|
||||||
|
|
||||||
#define IND_DEFAULT 0
|
static const uint32_t IND_LAST_DAY = 3600*24 ;
|
||||||
#define IND_LAST_DAY 1
|
static const uint32_t IND_LAST_WEEK = 3600*24*7 ;
|
||||||
#define IND_LAST_WEEK 2
|
static const uint32_t IND_LAST_MONTH = 3600*24*31 ; // I know, this is approximate
|
||||||
#define IND_LAST_MONTH 3
|
static const uint32_t IND_ALWAYS = ~(uint32_t)0 ;
|
||||||
#define IND_OLDER 4
|
|
||||||
|
|
||||||
class RemoteDirModel : public QAbstractItemModel
|
class RemoteDirModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
@ -82,13 +81,13 @@ class RemoteDirModel : public QAbstractItemModel
|
|||||||
|
|
||||||
void getFilePaths(QModelIndexList list, std::list<std::string> &fullpaths);
|
void getFilePaths(QModelIndexList list, std::list<std::string> &fullpaths);
|
||||||
|
|
||||||
void changeAgeIndicator(int indicator) { ageIndicator = indicator; }
|
void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; }
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void collapsed ( const QModelIndex & index ) { update(index); }
|
// void collapsed ( const QModelIndex & index ) { update(index); }
|
||||||
void expanded ( const QModelIndex & index ) { update(index); }
|
// void expanded ( const QModelIndex & index ) { update(index); }
|
||||||
|
|
||||||
/* Drag and Drop Functionality */
|
/* Drag and Drop Functionality */
|
||||||
public:
|
public:
|
||||||
@ -97,14 +96,14 @@ class RemoteDirModel : public QAbstractItemModel
|
|||||||
virtual QStringList mimeTypes () const;
|
virtual QStringList mimeTypes () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void update (const QModelIndex &index );
|
// void update (const QModelIndex &index );
|
||||||
void treeStyle();
|
void treeStyle();
|
||||||
void downloadDirectory(const DirDetails & details, int prefixLen);
|
void downloadDirectory(const DirDetails & details, int prefixLen);
|
||||||
static QString getFlagsString(uint32_t) ;
|
static QString getFlagsString(uint32_t) ;
|
||||||
QString getAgeIndicatorString(const DirDetails &) const;
|
QString getAgeIndicatorString(const DirDetails &) const;
|
||||||
void getAgeIndicatorRec(DirDetails &details, QString &ret) const;
|
void getAgeIndicatorRec(DirDetails &details, QString &ret) const;
|
||||||
|
|
||||||
int ageIndicator;
|
uint32_t ageIndicator;
|
||||||
|
|
||||||
QIcon categoryIcon;
|
QIcon categoryIcon;
|
||||||
QIcon peerIcon;
|
QIcon peerIcon;
|
||||||
|
@ -846,7 +846,12 @@ void SharedFilesDialog::showFrameSplitted(bool show)
|
|||||||
|
|
||||||
void SharedFilesDialog::indicatorChanged(int index)
|
void SharedFilesDialog::indicatorChanged(int index)
|
||||||
{
|
{
|
||||||
model->changeAgeIndicator(index);
|
static uint32_t correct_indicator[4] = { IND_ALWAYS,IND_LAST_DAY,IND_LAST_WEEK,IND_LAST_MONTH } ;
|
||||||
localModel->changeAgeIndicator(index);
|
|
||||||
|
model->changeAgeIndicator(correct_indicator[index]);
|
||||||
|
localModel->changeAgeIndicator(correct_indicator[index]);
|
||||||
|
|
||||||
|
ui.remoteDirTreeView->update(ui.remoteDirTreeView->rootIndex());
|
||||||
|
ui.localDirTreeView->update(ui.localDirTreeView->rootIndex()) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,27 +669,22 @@ p, li { white-space: pre-wrap; }
|
|||||||
<widget class="QComboBox" name="indicatorCBox">
|
<widget class="QComboBox" name="indicatorCBox">
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>No indicator</string>
|
<string>Always</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Last day</string>
|
<string>One day old</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Last week</string>
|
<string>One Week old</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Last month</string>
|
<string>One month old</string>
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Older</string>
|
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -763,7 +763,9 @@ void TransfersDialog::insertTransfers()
|
|||||||
FileInfo info;
|
FileInfo info;
|
||||||
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue;
|
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue;
|
||||||
//if file transfer is a cache file index file, don't show it
|
//if file transfer is a cache file index file, don't show it
|
||||||
if (info.flags & CB_CODE_CACHE) continue;
|
//
|
||||||
|
if (/*(!_show_cache_transfers) &&*/ (info.flags & CB_CODE_CACHE))
|
||||||
|
continue;
|
||||||
|
|
||||||
symbol = "";
|
symbol = "";
|
||||||
name = QString::fromUtf8(info.fname.c_str());
|
name = QString::fromUtf8(info.fname.c_str());
|
||||||
@ -978,6 +980,8 @@ void TransfersDialog::insertTransfers()
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (/*(!_show_cache_transfers) &&*/ (info.flags & CB_CODE_CACHE))
|
||||||
|
continue ;
|
||||||
|
|
||||||
std::list<TransferInfo>::iterator pit;
|
std::list<TransferInfo>::iterator pit;
|
||||||
for(pit = info.peers.begin(); pit != info.peers.end(); pit++)
|
for(pit = info.peers.begin(); pit != info.peers.end(); pit++)
|
||||||
|
Loading…
Reference in New Issue
Block a user