Share Flags

- 1st attempt at displaying share properties in the SharedFlagsDialog.
	- added share flags in DirDetails structure in place of Rank, that is not used anymore.


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1509 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-08-10 18:55:49 +00:00
parent 2380b0c793
commit a808ab9173
8 changed files with 225 additions and 179 deletions

View file

@ -932,7 +932,39 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t
fi.root->checkParentPointers(); fi.root->checkParentPointers();
#endif #endif
return fi.RequestDirDetails(ref,details,flags) ; // return details as reported by the FileIndex
bool b = fi.RequestDirDetails(ref,details,flags) ;
// look for the top level and setup flags accordingly
FileEntry *file = (FileEntry *) ref;
DirEntry *dir = dynamic_cast<DirEntry *>(file);
DirEntry *last_dir = NULL ;
if(dir != NULL)
while(dir->parent != NULL)
{
last_dir = dir ;
dir = dir->parent ;
}
if(last_dir != NULL)
{
std::cerr << "FileIndexMonitor::RequestDirDetails: parent->name=" << last_dir->name << std::endl ;
std::map<std::string,SharedDirInfo>::const_iterator it = directoryMap.find(last_dir->name) ;
if(it == directoryMap.end())
std::cerr << "*********** ERROR *********** In " << __PRETTY_FUNCTION__ << std::endl ;
else
{
details.flags |= (( (it->second.shareflags & RS_FILE_HINTS_BROWSABLE)>0)?DIR_FLAGS_BROWSABLE:0) ;
details.flags |= (( (it->second.shareflags & RS_FILE_HINTS_NETWORK_WIDE)>0)?DIR_FLAGS_NETWORK_WIDE:0) ;
std::cerr << "flags = " << details.flags << std::endl ;
}
}
return b ;
} }

View file

@ -1120,7 +1120,7 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
if (!ref) if (!ref)
{ {
#ifdef FI_DEBUG #ifdef FI_DEBUG
std::cerr << "FileIndexMonitor::RequestDirDetails() ref=NULL (root)" << std::endl; std::cerr << "FileIndex::RequestDirDetails() ref=NULL (root)" << std::endl;
#endif #endif
/* local only */ /* local only */
DirStub stub; DirStub stub;
@ -1138,14 +1138,14 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
details.hash = ""; details.hash = "";
details.path = ""; details.path = "";
details.age = 0; details.age = 0;
details.rank = 0; details.flags = 0;
} }
else else
{ {
if (dir) /* has children --- fill */ if (dir) /* has children --- fill */
{ {
#ifdef FI_DEBUG #ifdef FI_DEBUG
std::cerr << "FileIndexStore::RequestDirDetails() ref=dir" << std::endl; std::cerr << "FileIndex::RequestDirDetails() ref=dir" << std::endl;
#endif #endif
std::map<std::string, FileEntry *>::iterator fit; std::map<std::string, FileEntry *>::iterator fit;
std::map<std::string, DirEntry *>::iterator dit; std::map<std::string, DirEntry *>::iterator dit;
@ -1190,7 +1190,7 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
details.name = file->name; details.name = file->name;
details.hash = file->hash; details.hash = file->hash;
details.age = time(NULL) - file->modtime; details.age = time(NULL) - file->modtime;
details.rank = file->pop; details.flags = 0;//file->pop;
/* find parent pointer, and row */ /* find parent pointer, and row */
DirEntry *parent = file->parent; DirEntry *parent = file->parent;

View file

@ -219,7 +219,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
details.hash = ""; details.hash = "";
details.path = ""; details.path = "";
details.age = 0; details.age = 0;
details.rank = 0; details.flags = 0;
} }
else else
{ {
@ -244,7 +244,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
details.path = ""; details.path = "";
details.count = indices.size(); details.count = indices.size();
details.age = 0; details.age = 0;
details.rank = 0; details.flags = 0;
} }
} }
else else
@ -300,7 +300,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
details.name = file->name; details.name = file->name;
details.hash = file->hash; details.hash = file->hash;
details.age = time(NULL) - file->modtime; details.age = time(NULL) - file->modtime;
details.rank = file->pop; details.flags = 0;//file->pop;
/* find parent pointer, and row */ /* find parent pointer, and row */
DirEntry *parent = file->parent; DirEntry *parent = file->parent;

View file

@ -203,6 +203,8 @@ class SearchRequest
#define DIR_FLAGS_PARENT 0x0001 #define DIR_FLAGS_PARENT 0x0001
#define DIR_FLAGS_DETAILS 0x0002 #define DIR_FLAGS_DETAILS 0x0002
#define DIR_FLAGS_CHILDREN 0x0004 #define DIR_FLAGS_CHILDREN 0x0004
#define DIR_FLAGS_NETWORK_WIDE 0x0008
#define DIR_FLAGS_BROWSABLE 0x0010
class DirStub class DirStub
{ {
@ -226,7 +228,7 @@ class DirDetails
std::string path; std::string path;
uint64_t count; uint64_t count;
uint32_t age; uint32_t age;
uint32_t rank; uint32_t flags;
std::list<DirStub> children; std::list<DirStub> children;
}; };

View file

@ -459,7 +459,7 @@ void ChanMsgDialog::insertFileList(const std::list<DirDetails>& files_info)
FileInfo info ; FileInfo info ;
info.fname = it->name ; info.fname = it->name ;
info.hash = it->hash ; info.hash = it->hash ;
info.rank = it->rank ; info.rank = 0;//it->rank ;
info.size = it->count ; info.size = it->count ;
_recList.push_back(info) ; _recList.push_back(info) ;
@ -468,7 +468,7 @@ void ChanMsgDialog::insertFileList(const std::list<DirDetails>& files_info)
item->setText(0, QString::fromStdString(it->name)); /* (0) Filename */ item->setText(0, QString::fromStdString(it->name)); /* (0) Filename */
item->setText(1, misc::friendlyUnit(it->count)); /* (1) Size */ item->setText(1, misc::friendlyUnit(it->count)); /* (1) Size */
item->setText(2, QString::number(it->rank)); item->setText(2, QString::number(0)) ;//it->rank));
item->setText(3, QString::fromStdString(it->hash)); item->setText(3, QString::fromStdString(it->hash));
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item->setCheckState(0, Qt::Checked); item->setCheckState(0, Qt::Checked);

View file

@ -137,6 +137,17 @@ void RemoteDirModel::treeStyle()
{ {
return 4; return 4;
} }
QString RemoteDirModel::getFlagsString(uint32_t flags)
{
switch(flags & (DIR_FLAGS_NETWORK_WIDE|DIR_FLAGS_BROWSABLE))
{
case DIR_FLAGS_NETWORK_WIDE: return QString("Anonymous") ;
case DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE: return QString("Anonymous and browsable by friends") ;
case DIR_FLAGS_BROWSABLE: return QString("Only browsable by friends") ;
default:
return QString() ;
}
}
QVariant RemoteDirModel::data(const QModelIndex &index, int role) const QVariant RemoteDirModel::data(const QModelIndex &index, int role) const
{ {
@ -160,6 +171,7 @@ void RemoteDirModel::treeStyle()
else else
flags |= DIR_FLAGS_LOCAL; flags |= DIR_FLAGS_LOCAL;
if (!rsFiles->RequestDirDetails(ref, details, flags)) if (!rsFiles->RequestDirDetails(ref, details, flags))
{ {
return QVariant(); return QVariant();
@ -250,115 +262,115 @@ void RemoteDirModel::treeStyle()
} }
if (role == Qt::DecorationRole) if (role == Qt::DecorationRole)
{ {
if (details.type == DIR_TYPE_PERSON) if (details.type == DIR_TYPE_PERSON)
{ {
switch(coln) switch(coln)
{ {
case 0: case 0:
return (QIcon(peerIcon)); return (QIcon(peerIcon));
break; break;
} }
} }
else if (details.type == DIR_TYPE_DIR) else if (details.type == DIR_TYPE_DIR)
{ {
switch(coln) switch(coln)
{ {
case 0: case 0:
QString ext = QFileInfo(QString::fromStdString(details.name)).suffix(); QString ext = QFileInfo(QString::fromStdString(details.name)).suffix();
if (ext == "avi" || ext == "mpg" || ext == "movie") if (ext == "avi" || ext == "mpg" || ext == "movie")
{ {
QIcon icon(":/images/folder_video.png"); QIcon icon(":/images/folder_video.png");
return icon; return icon;
} }
else else
{ {
return(QIcon(categoryIcon)); return(QIcon(categoryIcon));
} }
break; break;
} }
} }
else if (details.type == DIR_TYPE_FILE) /* File */ else if (details.type == DIR_TYPE_FILE) /* File */
{ {
// extensions predefined // extensions predefined
//QString name; //QString name;
switch(coln) switch(coln)
{ {
case 0: case 0:
QString ext = QFileInfo(QString::fromStdString(details.name)).suffix(); QString ext = QFileInfo(QString::fromStdString(details.name)).suffix();
if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif"
|| ext == "bmp" || ext == "ico" || ext == "svg") || ext == "bmp" || ext == "ico" || ext == "svg")
{ {
//setIcon(0, QIcon(":/images/FileTypePicture.png")); //setIcon(0, QIcon(":/images/FileTypePicture.png"));
QIcon icon(":/images/FileTypePicture.png"); QIcon icon(":/images/FileTypePicture.png");
return icon; return icon;
} }
else if (ext == "avi" || ext == "AVI" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "ogm" else if (ext == "avi" || ext == "AVI" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "ogm"
|| ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov" || ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov"
|| ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp") || ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp")
{ {
//setIcon(0, QIcon(":/images/videofile.png")); //setIcon(0, QIcon(":/images/videofile.png"));
QIcon icon(":/images/FileTypeVideo.png"); QIcon icon(":/images/FileTypeVideo.png");
return icon; return icon;
} }
else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma" || ext == "xpm") else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma" || ext == "xpm")
{ {
//setIcon(0, QIcon(":/images/soundfile.png")); //setIcon(0, QIcon(":/images/soundfile.png"));
QIcon icon(":/images/FileTypeAudio.png"); QIcon icon(":/images/FileTypeAudio.png");
return icon; return icon;
} }
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z" else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z"
|| ext == "rar" || ext == "rpm" || ext == "deb") || ext == "rar" || ext == "rpm" || ext == "deb")
{ {
//setIcon(0, QIcon(":/images/compressedfile.png")); //setIcon(0, QIcon(":/images/compressedfile.png"));
QIcon icon(":/images/FileTypeArchive.png"); QIcon icon(":/images/FileTypeArchive.png");
return icon; return icon;
} }
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com" else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com"
|| ext == "bin" || ext == "exe" || ext == "js" || ext == "pif" || ext == "bin" || ext == "exe" || ext == "js" || ext == "pif"
|| ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws") || ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
{ {
return(QIcon(":/images/FileTypeProgram.png")); return(QIcon(":/images/FileTypeProgram.png"));
} }
else if (ext == "iso" || ext == "nrg" || ext == "mdf" ) else if (ext == "iso" || ext == "nrg" || ext == "mdf" )
{ {
//setIcon(0, QIcon(":/images/txtfile.png")); //setIcon(0, QIcon(":/images/txtfile.png"));
QIcon icon(":/images/FileTypeCDImage.png"); QIcon icon(":/images/FileTypeCDImage.png");
return icon; return icon;
} }
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h") else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
{ {
//setIcon(0, QIcon(":/images/txtfile.png")); //setIcon(0, QIcon(":/images/txtfile.png"));
QIcon icon(":/images/FileTypeDocument.png"); QIcon icon(":/images/FileTypeDocument.png");
return icon; return icon;
} }
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls" else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls"
|| ext == "sxc" || ext == "odt" || ext == "ods") || ext == "sxc" || ext == "odt" || ext == "ods")
{ {
//setIcon(0, QIcon(":/images/docfile.png")); //setIcon(0, QIcon(":/images/docfile.png"));
QIcon icon(":/images/FileTypeDocument.png"); QIcon icon(":/images/FileTypeDocument.png");
return icon; return icon;
} }
else if (ext == "html" || ext == "htm" || ext == "php") else if (ext == "html" || ext == "htm" || ext == "php")
{ {
//setIcon(0, QIcon(":/images/netfile.png")); //setIcon(0, QIcon(":/images/netfile.png"));
QIcon icon(":/images/FileTypeDocument.png"); QIcon icon(":/images/FileTypeDocument.png");
return icon; return icon;
} }
else else
{ {
//setIcon(0, QIcon(":/images/file.png")); //setIcon(0, QIcon(":/images/file.png"));
QIcon icon(":/images/FileTypeAny.png"); QIcon icon(":/images/FileTypeAny.png");
return icon; return icon;
} }
break; break;
} }
} }
else else
{ {
return QVariant(); return QVariant();
} }
} }
/************* /*************
@ -413,9 +425,7 @@ void RemoteDirModel::treeStyle()
break; break;
case 2: case 2:
{ {
std::ostringstream out; return getFlagsString(details.flags);
out << details.rank;
return QString::fromStdString(out.str());
} }
break; break;
case 3: case 3:
@ -435,24 +445,23 @@ void RemoteDirModel::treeStyle()
switch(coln) switch(coln)
{ {
case 0: case 0:
return QString::fromStdString(details.name); return QString::fromStdString(details.name);
break; break;
case 1: case 1:
//return QString(""); //return QString("");
{ {
std::ostringstream out; std::ostringstream out;
out << details.count; out << details.count;
return QString::fromStdString(out.str()); return QString::fromStdString(out.str());
} }
break; break;
case 2: case 2:
return QString(""); return getFlagsString(details.flags);
//return QString::fromStdString(details.path); break;
break;
default: default:
return QString(tr("DIR")); return QString(tr("DIR"));
break; break;
} }
} }
} /* end of DisplayRole */ } /* end of DisplayRole */
@ -474,50 +483,50 @@ void RemoteDirModel::treeStyle()
QVariant RemoteDirModel::headerData(int section, Qt::Orientation orientation, QVariant RemoteDirModel::headerData(int section, Qt::Orientation orientation,
int role) const int role) const
{ {
if (role == Qt::SizeHintRole) if (role == Qt::SizeHintRole)
{
int defw = 50;
int defh = 21;
if (section < 2)
{
defw = 200;
}
return QSize(defw, defh);
}
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal)
{
switch(section)
{ {
case 0: int defw = 50;
if (RemoteMode) int defh = 21;
{ if (section < 2)
return QString(tr("Friends Directories")); {
} defw = 200;
else }
{ return QSize(defw, defh);
return QString(tr("My Directories"));
}
break;
case 1:
return QString(tr("Size"));
break;
case 2:
return QString(tr("Rank"));
break;
case 3:
return QString(tr("Age"));
break;
} }
return QString("Column %1").arg(section);
} if (role != Qt::DisplayRole)
else return QVariant();
return QString("Row %1").arg(section);
} if (orientation == Qt::Horizontal)
{
switch(section)
{
case 0:
if (RemoteMode)
{
return QString(tr("Friends Directories"));
}
else
{
return QString(tr("My Directories"));
}
break;
case 1:
return QString(tr("Size"));
break;
case 2:
return QString(tr("Share type"));
break;
case 3:
return QString(tr("Age"));
break;
}
return QString("Column %1").arg(section);
}
else
return QString("Row %1").arg(section);
}
QModelIndex RemoteDirModel::index(int row, int column, QModelIndex RemoteDirModel::index(int row, int column,
const QModelIndex & parent) const const QModelIndex & parent) const

View file

@ -70,6 +70,7 @@ virtual QStringList mimeTypes () const;
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) ;
QIcon categoryIcon; QIcon categoryIcon;
QIcon peerIcon; QIcon peerIcon;

View file

@ -203,6 +203,8 @@ class SearchRequest
#define DIR_FLAGS_PARENT 0x0001 #define DIR_FLAGS_PARENT 0x0001
#define DIR_FLAGS_DETAILS 0x0002 #define DIR_FLAGS_DETAILS 0x0002
#define DIR_FLAGS_CHILDREN 0x0004 #define DIR_FLAGS_CHILDREN 0x0004
#define DIR_FLAGS_NETWORK_WIDE 0x0008
#define DIR_FLAGS_BROWSABLE 0x0010
class DirStub class DirStub
{ {
@ -226,7 +228,7 @@ class DirDetails
std::string path; std::string path;
uint64_t count; uint64_t count;
uint32_t age; uint32_t age;
uint32_t rank; uint32_t flags;
std::list<DirStub> children; std::list<DirStub> children;
}; };