- implemented an optional flat view for shared files that allows sorting by date/peer/name

- restored the search for flat view only (very slow for tree view)
- cleaned the code a bit: made two subclasses of RetroshareDirModel: TreeStyle_RDM and FlatStyle_RDM



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4117 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-04-01 21:46:06 +00:00
parent c22a0c79e7
commit f634331442
5 changed files with 693 additions and 448 deletions

View file

@ -28,6 +28,7 @@
#include "RemoteDirModel.h" #include "RemoteDirModel.h"
#include <retroshare/rsfiles.h> #include <retroshare/rsfiles.h>
#include <retroshare/rstypes.h> #include <retroshare/rstypes.h>
#include <retroshare/rspeers.h>
#include "util/misc.h" #include "util/misc.h"
#include <set> #include <set>
@ -38,7 +39,7 @@
* #define RDM_DEBUG * #define RDM_DEBUG
****/ ****/
RemoteDirModel::RemoteDirModel(bool mode, QObject *parent) RetroshareDirModel::RetroshareDirModel(bool mode, QObject *parent)
: QAbstractItemModel(parent), : QAbstractItemModel(parent),
ageIndicator(IND_ALWAYS), ageIndicator(IND_ALWAYS),
RemoteMode(mode), nIndex(1), indexSet(1) /* ass zero index cant be used */ RemoteMode(mode), nIndex(1), indexSet(1) /* ass zero index cant be used */
@ -47,7 +48,7 @@ RemoteDirModel::RemoteDirModel(bool mode, QObject *parent)
treeStyle(); treeStyle();
} }
void RemoteDirModel::treeStyle() void RetroshareDirModel::treeStyle()
{ {
categoryIcon.addPixmap(QPixmap(":/images/folder16.png"), categoryIcon.addPixmap(QPixmap(":/images/folder16.png"),
QIcon::Normal, QIcon::Off); QIcon::Normal, QIcon::Off);
@ -56,11 +57,11 @@ void RemoteDirModel::treeStyle()
peerIcon = QIcon(":/images/user/identity16.png"); peerIcon = QIcon(":/images/user/identity16.png");
} }
bool RemoteDirModel::hasChildren(const QModelIndex &parent) const bool TreeStyle_RDM::hasChildren(const QModelIndex &parent) const
{ {
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::hasChildren() :" << parent.internalPointer(); std::cerr << "RetroshareDirModel::hasChildren() :" << parent.internalPointer();
std::cerr << ": "; std::cerr << ": ";
#endif #endif
@ -106,13 +107,31 @@ void RemoteDirModel::treeStyle()
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return (details.count > 0); /* do we have children? */ return (details.count > 0); /* do we have children? */
} }
bool FlatStyle_RDM::hasChildren(const QModelIndex &parent) const
{
#ifdef RDM_DEBUG
std::cerr << "RetroshareDirModel::hasChildren() :" << parent.internalPointer();
std::cerr << ": ";
#endif
int RemoteDirModel::rowCount(const QModelIndex &parent) const if (!parent.isValid())
{ {
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::rowCount(): " << parent.internalPointer(); std::cerr << "root -> true ";
std::cerr << std::endl;
#endif
return true;
}
else
return false ;
}
int TreeStyle_RDM::rowCount(const QModelIndex &parent) const
{
#ifdef RDM_DEBUG
std::cerr << "RetroshareDirModel::rowCount(): " << parent.internalPointer();
std::cerr << ": "; std::cerr << ": ";
#endif #endif
@ -148,13 +167,26 @@ void RemoteDirModel::treeStyle()
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return details.count; return details.count;
} }
int RemoteDirModel::columnCount(const QModelIndex &parent) const int FlatStyle_RDM::rowCount(const QModelIndex &parent) const
{ {
#ifdef RDM_DEBUG
std::cerr << "RetroshareDirModel::rowCount(): " << parent.internalPointer();
std::cerr << ": ";
#endif
return _ref_entries.size() ;
}
int TreeStyle_RDM::columnCount(const QModelIndex &parent) const
{
return 5; return 5;
} }
QString RemoteDirModel::getFlagsString(uint32_t flags) int FlatStyle_RDM::columnCount(const QModelIndex &parent) const
{
return 5;
}
QString RetroshareDirModel::getFlagsString(uint32_t flags)
{ {
switch(flags & (DIR_FLAGS_NETWORK_WIDE|DIR_FLAGS_BROWSABLE)) switch(flags & (DIR_FLAGS_NETWORK_WIDE|DIR_FLAGS_BROWSABLE))
{ {
@ -166,7 +198,7 @@ QString RemoteDirModel::getFlagsString(uint32_t flags)
} }
} }
QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const QString RetroshareDirModel::getAgeIndicatorString(const DirDetails &details) const
{ {
QString ret(""); QString ret("");
QString nind = tr("NEW"); QString nind = tr("NEW");
@ -195,193 +227,76 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
return ret; return ret;
} }
QVariant RemoteDirModel::data(const QModelIndex &index, int role) const QVariant RetroshareDirModel::decorationRole(const DirDetails& details,int coln) const
{ {
#ifdef RDM_DEBUG if(coln > 0)
std::cerr << "RemoteDirModel::data(): " << index.internalPointer(); return QVariant() ;
std::cerr << ": ";
std::cerr << std::endl;
#endif
if (!index.isValid())
return QVariant();
/* get the data from the index */
void *ref = index.internalPointer();
int coln = index.column();
DirDetails details;
uint32_t flags = DIR_FLAGS_DETAILS;
if (RemoteMode)
flags |= DIR_FLAGS_REMOTE;
else
flags |= DIR_FLAGS_LOCAL;
if (!rsFiles->RequestDirDetails(ref, details, flags))
{
return QVariant();
}
if (role == RemoteDirModel::FileNameRole)
{
return QString::fromUtf8(details.name.c_str());
} /* end of FileNameRole */
if (role == Qt::TextColorRole)
{
if(details.min_age > ageIndicator)
return Qt::gray ;
else
return Qt::black ;
} /* end of TextColorRole */
if (role == Qt::DecorationRole)
{
if (details.type == DIR_TYPE_PERSON) if (details.type == DIR_TYPE_PERSON)
{ {
switch(coln)
{
case 0:
if(details.min_age > ageIndicator) if(details.min_age > ageIndicator)
{
return QIcon(":/images/folder_grey.png"); return QIcon(":/images/folder_grey.png");
}
else if (ageIndicator == IND_LAST_DAY ) else if (ageIndicator == IND_LAST_DAY )
{
return QIcon(":/images/folder_green.png"); return QIcon(":/images/folder_green.png");
}
else if (ageIndicator == IND_LAST_WEEK ) else if (ageIndicator == IND_LAST_WEEK )
{
return QIcon(":/images/folder_yellow.png"); return QIcon(":/images/folder_yellow.png");
}
else if (ageIndicator == IND_LAST_MONTH ) else if (ageIndicator == IND_LAST_MONTH )
{
return QIcon(":/images/folder_red.png"); return QIcon(":/images/folder_red.png");
}
else else
{
return (QIcon(peerIcon)); return (QIcon(peerIcon));
} }
break;
}
}
else if (details.type == DIR_TYPE_DIR) else if (details.type == DIR_TYPE_DIR)
{ {
switch(coln)
{
case 0:
if(details.min_age > ageIndicator) if(details.min_age > ageIndicator)
{
return QIcon(":/images/folder_grey.png"); return QIcon(":/images/folder_grey.png");
}
else if (ageIndicator == IND_LAST_DAY ) else if (ageIndicator == IND_LAST_DAY )
{
return QIcon(":/images/folder_green.png"); return QIcon(":/images/folder_green.png");
}
else if (ageIndicator == IND_LAST_WEEK ) else if (ageIndicator == IND_LAST_WEEK )
{
return QIcon(":/images/folder_yellow.png"); return QIcon(":/images/folder_yellow.png");
}
else if (ageIndicator == IND_LAST_MONTH ) else if (ageIndicator == IND_LAST_MONTH )
{
return QIcon(":/images/folder_red.png"); return QIcon(":/images/folder_red.png");
}
else else
{
return QIcon(categoryIcon); return QIcon(categoryIcon);
} }
break;
}
}
else if (details.type == DIR_TYPE_FILE) /* File */ else if (details.type == DIR_TYPE_FILE) /* File */
{ {
// extensions predefined // extensions predefined
switch(coln)
{
case 0:
QString ext = QFileInfo(QString::fromUtf8(details.name.c_str())).suffix(); QString ext = QFileInfo(QString::fromUtf8(details.name.c_str())).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")
{
return QIcon(":/images/FileTypePicture.png"); return QIcon(":/images/FileTypePicture.png");
}
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")
{
return QIcon(":/images/FileTypeVideo.png"); return QIcon(":/images/FileTypeVideo.png");
}
else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma" || ext == "xpm") else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma" || ext == "xpm")
{
return QIcon(":/images/FileTypeAudio.png"); return QIcon(":/images/FileTypeAudio.png");
}
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")
{
return QIcon(":/images/FileTypeArchive.png"); return QIcon(":/images/FileTypeArchive.png");
}
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" )
{
return QIcon(":/images/FileTypeCDImage.png"); return QIcon(":/images/FileTypeCDImage.png");
}
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h") else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
{
return QIcon(":/images/FileTypeDocument.png"); return QIcon(":/images/FileTypeDocument.png");
}
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")
{
return QIcon(":/images/FileTypeDocument.png"); return QIcon(":/images/FileTypeDocument.png");
}
else if (ext == "html" || ext == "htm" || ext == "php") else if (ext == "html" || ext == "htm" || ext == "php")
{
return QIcon(":/images/FileTypeDocument.png"); return QIcon(":/images/FileTypeDocument.png");
}
else else
{
return QIcon(":/images/FileTypeAny.png"); return QIcon(":/images/FileTypeAny.png");
} }
break;
}
}
else else
{
return QVariant(); return QVariant();
}
} /* end of DecorationRole */
/***************** } /* end of DecorationRole */
Qt::EditRole
Qt::ToolTipRole
Qt::StatusTipRole
Qt::WhatsThisRole
Qt::SizeHintRole
****************/
if (role == Qt::SizeHintRole) QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const
{ {
return QSize(18, 18);
} /* end of SizeHintRole */
if (role == Qt::TextAlignmentRole)
{
if(coln == 1)
{
return int( Qt::AlignRight | Qt::AlignVCenter);
}
return QVariant();
} /* end of TextAlignmentRole */
if (role == Qt::DisplayRole)
{
/* /*
* Person: name, id, 0, 0; * Person: name, id, 0, 0;
@ -447,18 +362,32 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
} }
} }
return QVariant(); return QVariant();
} /* end of DisplayRole */ } /* end of DisplayRole */
if (role == SortRole) QVariant FlatStyle_RDM::displayRole(const DirDetails& details,int coln) const
{
if (details.type == DIR_TYPE_FILE) /* File */
switch(coln)
{ {
case 0: return QString::fromUtf8(details.name.c_str());
case 1: return misc::friendlyUnit(details.count);
case 2: return misc::userFriendlyDuration(details.age);
case 3: return QString::fromStdString(rsPeers->getPeerName(details.id));
default:
return QVariant() ;
}
return QVariant();
} /* end of DisplayRole */
QVariant RetroshareDirModel::sortRole(const DirDetails& details,int coln) const
{
/* /*
* Person: name, id, 0, 0; * Person: name, id, 0, 0;
* File : name, size, rank, (0) ts * File : name, size, rank, (0) ts
* Dir : name, (0) count, (0) path, (0) ts * Dir : name, (0) count, (0) path, (0) ts
*/ */
if (details.type == DIR_TYPE_PERSON) /* Person */ if (details.type == DIR_TYPE_PERSON) /* Person */
{ {
switch(coln) switch(coln)
@ -511,12 +440,83 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
} }
} }
return QVariant(); return QVariant();
} /* end of SortRole */ } /* end of SortRole */
QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const
{
#ifdef RDM_DEBUG
std::cerr << "RetroshareDirModel::data(): " << index.internalPointer();
std::cerr << ": ";
std::cerr << std::endl;
#endif
if (!index.isValid())
return QVariant();
/* get the data from the index */
void *ref = index.internalPointer();
int coln = index.column();
DirDetails details;
uint32_t flags = DIR_FLAGS_DETAILS;
if (RemoteMode)
flags |= DIR_FLAGS_REMOTE;
else
flags |= DIR_FLAGS_LOCAL;
if (!rsFiles->RequestDirDetails(ref, details, flags))
return QVariant();
if (role == RetroshareDirModel::FileNameRole) /* end of FileNameRole */
return QString::fromUtf8(details.name.c_str());
if (role == Qt::TextColorRole)
{
if(details.min_age > ageIndicator)
return Qt::gray ;
else
return Qt::black ;
} /* end of TextColorRole */
if(role == Qt::DecorationRole)
return decorationRole(details,coln) ;
/*****************
Qt::EditRole
Qt::ToolTipRole
Qt::StatusTipRole
Qt::WhatsThisRole
Qt::SizeHintRole
****************/
if (role == Qt::SizeHintRole)
{
return QSize(18, 18);
} /* end of SizeHintRole */
if (role == Qt::TextAlignmentRole)
{
if(coln == 1)
{
return int( Qt::AlignRight | Qt::AlignVCenter);
}
return QVariant();
} /* end of TextAlignmentRole */
if (role == Qt::DisplayRole)
return displayRole(details,coln) ;
if (role == SortRole)
return sortRole(details,coln) ;
return QVariant(); return QVariant();
} }
void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const { void RetroshareDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const {
if (details.type == DIR_TYPE_FILE) { if (details.type == DIR_TYPE_FILE) {
ret = getAgeIndicatorString(details); ret = getAgeIndicatorString(details);
return; return;
@ -538,8 +538,49 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
} }
} }
QVariant RemoteDirModel::headerData(int section, Qt::Orientation orientation, QVariant TreeStyle_RDM::headerData(int section, Qt::Orientation orientation, int role) const
int role) const {
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:
if (RemoteMode)
return tr("Friends Directories");
else
return tr("My Directories");
case 1:
return tr("Size");
case 2:
return tr("Age");
case 3:
if (RemoteMode)
return tr("Friend");
else
return tr("Share Type");
case 4:
return tr("What's new");
}
return QString("Column %1").arg(section);
}
else
return QString("Row %1").arg(section);
}
QVariant FlatStyle_RDM::headerData(int section, Qt::Orientation orientation, int role) const
{ {
if (role == Qt::SizeHintRole) if (role == Qt::SizeHintRole)
{ {
@ -570,6 +611,9 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
case 2: case 2:
return tr("Age"); return tr("Age");
case 3: case 3:
if(RemoteMode)
return tr("Friend");
else
return tr("Share Type"); return tr("Share Type");
case 4: case 4:
return tr("What's new"); return tr("What's new");
@ -580,10 +624,10 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
return QString("Row %1").arg(section); return QString("Row %1").arg(section);
} }
QModelIndex RemoteDirModel::index(int row, int column, const QModelIndex & parent) const QModelIndex TreeStyle_RDM::index(int row, int column, const QModelIndex & parent) const
{ {
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::index(): " << parent.internalPointer(); std::cerr << "RetroshareDirModel::index(): " << parent.internalPointer();
std::cerr << ": row:" << row << " col:" << column << " "; std::cerr << ": row:" << row << " col:" << column << " ";
#endif #endif
@ -642,12 +686,30 @@ QModelIndex RemoteDirModel::index(int row, int column, const QModelIndex & paren
return createIndex(row, column, it->ref); return createIndex(row, column, it->ref);
} }
QModelIndex FlatStyle_RDM::index(int row, int column, const QModelIndex & parent) const
QModelIndex RemoteDirModel::parent( const QModelIndex & index ) const
{ {
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::parent(): " << index.internalPointer(); std::cerr << "RetroshareDirModel::index(): " << parent.internalPointer();
std::cerr << ": row:" << row << " col:" << column << " ";
#endif
if(row < 0)
return QModelIndex() ;
if(row < _ref_entries.size())
{
void *ref = _ref_entries[row] ;
return createIndex(row, column, ref);
}
else
return QModelIndex();
}
QModelIndex TreeStyle_RDM::parent( const QModelIndex & index ) const
{
#ifdef RDM_DEBUG
std::cerr << "RetroshareDirModel::parent(): " << index.internalPointer();
std::cerr << ": "; std::cerr << ": ";
#endif #endif
@ -691,11 +753,19 @@ QModelIndex RemoteDirModel::parent( const QModelIndex & index ) const
#endif #endif
return createIndex(details.prow, 0, details.parent); return createIndex(details.prow, 0, details.parent);
} }
QModelIndex FlatStyle_RDM::parent( const QModelIndex & index ) const
Qt::ItemFlags RemoteDirModel::flags( const QModelIndex & index ) const
{ {
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::flags()"; std::cerr << "RetroshareDirModel::parent(): " << index.internalPointer();
std::cerr << ": ";
#endif
return QModelIndex();
}
Qt::ItemFlags RetroshareDirModel::flags( const QModelIndex & index ) const
{
#ifdef RDM_DEBUG
std::cerr << "RetroshareDirModel::flags()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -733,10 +803,10 @@ Qt::ItemFlags RemoteDirModel::flags( const QModelIndex & index ) const
/* Callback from */ /* Callback from */
void RemoteDirModel::preMods() void RetroshareDirModel::preMods()
{ {
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::preMods()" << std::endl; std::cerr << "RetroshareDirModel::preMods()" << std::endl;
#endif #endif
//modelAboutToBeReset(); //modelAboutToBeReset();
// reset(); // reset();
@ -747,21 +817,20 @@ Qt::ItemFlags RemoteDirModel::flags( const QModelIndex & index ) const
} }
/* Callback from */ /* Callback from */
void RemoteDirModel::postMods() void RetroshareDirModel::postMods()
{ {
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::postMods()" << std::endl; std::cerr << "RetroshareDirModel::postMods()" << std::endl;
#endif #endif
//modelReset(); //modelReset();
layoutChanged(); layoutChanged();
//reset();
#if QT_VERSION >= 0x040600 #if QT_VERSION >= 0x040600
endResetModel(); endResetModel();
#endif #endif
} }
//void RemoteDirModel::update (const QModelIndex &index ) //void RetroshareDirModel::update (const QModelIndex &index )
//{ //{
//#ifdef RDM_DEBUG //#ifdef RDM_DEBUG
// //std::cerr << "Directory Request(" << id << ") : "; // //std::cerr << "Directory Request(" << id << ") : ";
@ -770,7 +839,7 @@ Qt::ItemFlags RemoteDirModel::flags( const QModelIndex & index ) const
// //rsFiles -> RequestDirectories(id, path, 1); // //rsFiles -> RequestDirectories(id, path, 1);
//} //}
void RemoteDirModel::downloadSelected(const QModelIndexList &list) void RetroshareDirModel::downloadSelected(const QModelIndexList &list)
{ {
if (!RemoteMode) if (!RemoteMode)
{ {
@ -800,7 +869,7 @@ void RemoteDirModel::downloadSelected(const QModelIndexList &list)
/* if it is a file */ /* if it is a file */
if (details.type == DIR_TYPE_FILE) if (details.type == DIR_TYPE_FILE)
{ {
std::cerr << "RemoteDirModel::downloadSelected() Calling File Request"; std::cerr << "RetroshareDirModel::downloadSelected() Calling File Request";
std::cerr << std::endl; std::cerr << std::endl;
std::list<std::string> srcIds; std::list<std::string> srcIds;
srcIds.push_back(details.id); srcIds.push_back(details.id);
@ -818,7 +887,7 @@ void RemoteDirModel::downloadSelected(const QModelIndexList &list)
} }
/* recursively download a directory */ /* recursively download a directory */
void RemoteDirModel::downloadDirectory(const DirDetails & dirDetails, int prefixLen) void RetroshareDirModel::downloadDirectory(const DirDetails & dirDetails, int prefixLen)
{ {
if (dirDetails.type & DIR_TYPE_FILE) if (dirDetails.type & DIR_TYPE_FILE)
{ {
@ -850,7 +919,7 @@ void RemoteDirModel::downloadDirectory(const DirDetails & dirDetails, int prefix
} }
} }
void RemoteDirModel::getDirDetailsFromSelect (const QModelIndexList &list, std::vector <DirDetails>& dirVec) void RetroshareDirModel::getDirDetailsFromSelect (const QModelIndexList &list, std::vector <DirDetails>& dirVec)
{ {
dirVec.clear(); dirVec.clear();
@ -888,7 +957,7 @@ void RemoteDirModel::getDirDetailsFromSelect (const QModelIndexList &list, std::
* *
*/ */
void RemoteDirModel::getFileInfoFromIndexList(const QModelIndexList& list, std::list<DirDetails>& file_details) void RetroshareDirModel::getFileInfoFromIndexList(const QModelIndexList& list, std::list<DirDetails>& file_details)
{ {
file_details.clear() ; file_details.clear() ;
@ -949,10 +1018,10 @@ void RemoteDirModel::getFileInfoFromIndexList(const QModelIndexList& list, std::
* OLD RECOMMEND SYSTEM - DISABLED * OLD RECOMMEND SYSTEM - DISABLED
******/ ******/
void RemoteDirModel::openSelected(const QModelIndexList &qmil) void RetroshareDirModel::openSelected(const QModelIndexList &qmil)
{ {
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::openSelected()" << std::endl; std::cerr << "RetroshareDirModel::openSelected()" << std::endl;
#endif #endif
if (RemoteMode) { if (RemoteMode) {
@ -989,14 +1058,14 @@ void RemoteDirModel::openSelected(const QModelIndexList &qmil)
} }
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "::::::::::::Done RemoteDirModel::openSelected()" << std::endl; std::cerr << "::::::::::::Done RetroshareDirModel::openSelected()" << std::endl;
#endif #endif
} }
void RemoteDirModel::getFilePaths(const QModelIndexList &list, std::list<std::string> &fullpaths) void RetroshareDirModel::getFilePaths(const QModelIndexList &list, std::list<std::string> &fullpaths)
{ {
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::getFilePaths()" << std::endl; std::cerr << "RetroshareDirModel::getFilePaths()" << std::endl;
#endif #endif
if (RemoteMode) if (RemoteMode)
{ {
@ -1056,7 +1125,7 @@ void RemoteDirModel::getFilePaths(const QModelIndexList &list, std::list<std::st
} }
/* Drag and Drop Functionality */ /* Drag and Drop Functionality */
QMimeData * RemoteDirModel::mimeData ( const QModelIndexList & indexes ) const QMimeData * RetroshareDirModel::mimeData ( const QModelIndexList & indexes ) const
{ {
/* extract from each the member text */ /* extract from each the member text */
std::string text; std::string text;
@ -1095,7 +1164,7 @@ QMimeData * RemoteDirModel::mimeData ( const QModelIndexList & indexes ) const
if (details.type != DIR_TYPE_FILE) if (details.type != DIR_TYPE_FILE)
{ {
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::mimeData() Not File" << std::endl; std::cerr << "RetroshareDirModel::mimeData() Not File" << std::endl;
#endif #endif
continue; /* not file! */ continue; /* not file! */
} }
@ -1103,7 +1172,7 @@ QMimeData * RemoteDirModel::mimeData ( const QModelIndexList & indexes ) const
if (drags.end() != (dit = drags.find(details.hash))) if (drags.end() != (dit = drags.find(details.hash)))
{ {
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::mimeData() Duplicate" << std::endl; std::cerr << "RetroshareDirModel::mimeData() Duplicate" << std::endl;
#endif #endif
continue; /* duplicate */ continue; /* duplicate */
} }
@ -1151,7 +1220,7 @@ QMimeData * RemoteDirModel::mimeData ( const QModelIndexList & indexes ) const
} }
QStringList RemoteDirModel::mimeTypes () const QStringList RetroshareDirModel::mimeTypes () const
{ {
QStringList list; QStringList list;
list.push_back("application/x-rsfilelist"); list.push_back("application/x-rsfilelist");
@ -1161,7 +1230,7 @@ QStringList RemoteDirModel::mimeTypes () const
//============================================================================ //============================================================================
int RemoteDirModel::getType ( const QModelIndex & index ) const int RetroshareDirModel::getType ( const QModelIndex & index ) const
{ {
//if (RemoteMode) // only local files can be opened //if (RemoteMode) // only local files can be opened
// return ; // return ;
@ -1183,3 +1252,45 @@ int RemoteDirModel::getType ( const QModelIndex & index ) const
return details.type; return details.type;
} }
FlatStyle_RDM::~FlatStyle_RDM()
{
}
TreeStyle_RDM::~TreeStyle_RDM()
{
}
void FlatStyle_RDM::postMods()
{
_ref_entries.clear() ;
std::cerr << "FlatStyle_RDM::postMods(): cleared ref entries" << std::endl;
std::vector<void *> stack(1,(void *)NULL) ;
while(!stack.empty())
{
void *ref = stack.back() ;
#ifdef RDM_DEBUG
std::cerr << "FlatStyle_RDM::postMods(): poped ref " << ref << std::endl;
#endif
stack.pop_back() ;
uint32_t flags = DIR_FLAGS_DETAILS;
DirDetails details ;
if (rsFiles->RequestDirDetails(ref, details, flags))
{
if(details.type == DIR_TYPE_FILE) // only push files, not directories nor persons.
_ref_entries.push_back(ref);
#ifdef RDM_DEBUG
std::cerr << "FlatStyle_RDM::postMods(): addign ref " << ref << std::endl;
#endif
for(std::list<DirStub>::iterator it = details.children.begin(); it != details.children.end(); it++)
stack.push_back(it->ref) ;
}
}
std::cerr << "reference tab contains " << _ref_entries.size() << " files" << std::endl;
RetroshareDirModel::postMods() ;
}

View file

@ -34,33 +34,21 @@ static const uint32_t IND_LAST_WEEK = 3600*24*7 ;
static const uint32_t IND_LAST_MONTH = 3600*24*31 ; // I know, this is approximate static const uint32_t IND_LAST_MONTH = 3600*24*31 ; // I know, this is approximate
static const uint32_t IND_ALWAYS = ~(uint32_t)0 ; static const uint32_t IND_ALWAYS = ~(uint32_t)0 ;
class RemoteDirModel : public QAbstractItemModel class RetroshareDirModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
public: public:
enum Roles{ FileNameRole = Qt::UserRole+1, SortRole = Qt::UserRole+2 }; enum Roles{ FileNameRole = Qt::UserRole+1, SortRole = Qt::UserRole+2 };
RemoteDirModel(bool mode, QObject *parent = 0); RetroshareDirModel(bool mode, QObject *parent = 0);
virtual ~RetroshareDirModel() {}
/* These are all overloaded Virtual Functions */
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column,
const QModelIndex & parent = QModelIndex() ) const;
QModelIndex parent ( const QModelIndex & index ) const;
Qt::ItemFlags flags ( const QModelIndex & index ) const; Qt::ItemFlags flags ( const QModelIndex & index ) const;
bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
/* Callback from Core */ /* Callback from Core */
void preMods(); virtual void preMods();
void postMods(); virtual void postMods();
/* Callback from GUI */ /* Callback from GUI */
void downloadSelected(const QModelIndexList &list); void downloadSelected(const QModelIndexList &list);
@ -68,36 +56,29 @@ class RemoteDirModel : public QAbstractItemModel
void getDirDetailsFromSelect (const QModelIndexList &list, std::vector <DirDetails>& dirVec); void getDirDetailsFromSelect (const QModelIndexList &list, std::vector <DirDetails>& dirVec);
int getType ( const QModelIndex & index ) const ; int getType ( const QModelIndex & index ) const ;
//void openFile(QModelIndex fileIndex, const QString command);
void getFileInfoFromIndexList(const QModelIndexList& list, std::list<DirDetails>& files_info) ; void getFileInfoFromIndexList(const QModelIndexList& list, std::list<DirDetails>& files_info) ;
void openSelected(const QModelIndexList &list); void openSelected(const QModelIndexList &list);
void getFilePaths(const QModelIndexList &list, std::list<std::string> &fullpaths); void getFilePaths(const QModelIndexList &list, std::list<std::string> &fullpaths);
void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; } void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; }
public slots:
// void collapsed ( const QModelIndex & index ) { update(index); }
// void expanded ( const QModelIndex & index ) { update(index); }
/* Drag and Drop Functionality */
public: public:
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const; virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
virtual QStringList mimeTypes () const; virtual QStringList mimeTypes () const;
virtual QVariant data(const QModelIndex &index, int role) const;
private: protected:
// 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;
virtual QVariant displayRole(const DirDetails&,int) const = 0 ;
QVariant decorationRole(const DirDetails&,int) const ;
QVariant sortRole(const DirDetails&,int) const ;
uint32_t ageIndicator; uint32_t ageIndicator;
QIcon categoryIcon; QIcon categoryIcon;
@ -146,4 +127,62 @@ class RemoteDirModel : public QAbstractItemModel
}; };
// This class shows the classical hierarchical directory view of shared files
// Columns are:
// file name | Size | Age
//
class TreeStyle_RDM: public RetroshareDirModel
{
public:
TreeStyle_RDM(bool mode)
: RetroshareDirModel(mode)
{
}
virtual ~TreeStyle_RDM() ;
protected:
/* These are all overloaded Virtual Functions */
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual QVariant displayRole(const DirDetails&,int) const ;
virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex() ) const;
virtual QModelIndex parent ( const QModelIndex & index ) const;
virtual bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
};
// This class shows a flat list of all shared files
// Columns are:
// file name | Owner | Size | Age
//
class FlatStyle_RDM: public RetroshareDirModel
{
public:
FlatStyle_RDM(bool mode)
: RetroshareDirModel(mode)
{
}
virtual ~FlatStyle_RDM() ;
protected:
virtual void postMods();
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual QVariant displayRole(const DirDetails&,int) const ;
virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex() ) const;
virtual QModelIndex parent ( const QModelIndex & index ) const;
virtual bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
std::vector<void *> _ref_entries ;
};
#endif #endif

View file

@ -60,7 +60,7 @@ const QString Image_AddNewAssotiationForFile = ":/images/kcmsystem24.png";
class SFDSortFilterProxyModel : public QSortFilterProxyModel class SFDSortFilterProxyModel : public QSortFilterProxyModel
{ {
public: public:
SFDSortFilterProxyModel(RemoteDirModel *dirModel, QObject *parent) : QSortFilterProxyModel(parent) SFDSortFilterProxyModel(RetroshareDirModel *dirModel, QObject *parent) : QSortFilterProxyModel(parent)
{ {
m_dirModel = dirModel; m_dirModel = dirModel;
}; };
@ -79,7 +79,7 @@ protected:
} }
private: private:
RemoteDirModel *m_dirModel; RetroshareDirModel *m_dirModel;
}; };
/** Constructor */ /** Constructor */
@ -89,13 +89,11 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this); ui.setupUi(this);
connect(ui.checkButton, SIGNAL(clicked()), this, SLOT(forceCheck())); connect(ui.checkButton, SIGNAL(clicked()), this, SLOT(forceCheck()));
connect(ui.localButton, SIGNAL(toggled(bool)), this, SLOT(showFrame(bool))); connect(ui.localButton, SIGNAL(toggled(bool)), this, SLOT(showFrame(bool)));
connect(ui.remoteButton, SIGNAL(toggled(bool)), this, SLOT(showFrameRemote(bool))); connect(ui.remoteButton, SIGNAL(toggled(bool)), this, SLOT(showFrameRemote(bool)));
connect(ui.splittedButton, SIGNAL(toggled(bool)), this, SLOT(showFrameSplitted(bool))); connect(ui.splittedButton, SIGNAL(toggled(bool)), this, SLOT(showFrameSplitted(bool)));
connect(ui.viewType_CB, SIGNAL(currentIndexChanged(int)), this, SLOT(changeCurrentViewModel(int)));
connect( ui.localDirTreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( sharedDirTreeWidgetContextMenu( QPoint ) ) ); connect( ui.localDirTreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( sharedDirTreeWidgetContextMenu( QPoint ) ) );
connect( ui.remoteDirTreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( shareddirtreeviewCostumPopupMenu( QPoint ) ) ); connect( ui.remoteDirTreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( shareddirtreeviewCostumPopupMenu( QPoint ) ) );
@ -114,35 +112,34 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
*/ */
model = new RemoteDirModel(true); tree_model = new TreeStyle_RDM(true);
flat_model = new FlatStyle_RDM(true);
proxyModel = new SFDSortFilterProxyModel(model, this); tree_proxyModel = new SFDSortFilterProxyModel(tree_model, this);
proxyModel->setDynamicSortFilter(true); tree_proxyModel->setDynamicSortFilter(true);
proxyModel->setSourceModel(model); tree_proxyModel->setSourceModel(tree_model);
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); tree_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
proxyModel->setSortRole(RemoteDirModel::SortRole); tree_proxyModel->setSortRole(RetroshareDirModel::SortRole);
proxyModel->sort(0); tree_proxyModel->sort(0);
ui.remoteDirTreeView->setModel(proxyModel); flat_proxyModel = new SFDSortFilterProxyModel(flat_model, this);
flat_proxyModel->setDynamicSortFilter(true);
flat_proxyModel->setSourceModel(flat_model);
flat_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
flat_proxyModel->setSortRole(RetroshareDirModel::SortRole);
flat_proxyModel->sort(0);
localModel = new RemoteDirModel(false); localModel = new TreeStyle_RDM(false);
localProxyModel = new SFDSortFilterProxyModel(localModel, this); localProxyModel = new SFDSortFilterProxyModel(localModel, this);
localProxyModel->setDynamicSortFilter(true); localProxyModel->setDynamicSortFilter(true);
localProxyModel->setSourceModel(localModel); localProxyModel->setSourceModel(localModel);
localProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); localProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
localProxyModel->setSortRole(RemoteDirModel::SortRole); localProxyModel->setSortRole(RetroshareDirModel::SortRole);
localProxyModel->sort(0); localProxyModel->sort(0);
ui.localDirTreeView->setModel(localProxyModel); ui.localDirTreeView->setModel(localProxyModel);
ui.remoteDirTreeView->setColumnHidden(3,true) ;
ui.remoteDirTreeView->setColumnHidden(4,true) ;
ui.localDirTreeView->setColumnHidden(4,true) ;
connect( ui.remoteDirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), model, SLOT( collapsed(const QModelIndex & ) ) );
connect( ui.remoteDirTreeView, SIGNAL( expanded(const QModelIndex & ) ), model, SLOT( expanded(const QModelIndex & ) ) );
connect( ui.localDirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), localModel, SLOT( collapsed(const QModelIndex & ) ) ); connect( ui.localDirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), localModel, SLOT( collapsed(const QModelIndex & ) ) );
connect( ui.localDirTreeView, SIGNAL( expanded(const QModelIndex & ) ), localModel, SLOT( expanded(const QModelIndex & ) ) ); connect( ui.localDirTreeView, SIGNAL( expanded(const QModelIndex & ) ), localModel, SLOT( expanded(const QModelIndex & ) ) );
@ -154,6 +151,13 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
connect(ui.filterPatternLineEdit, SIGNAL(returnPressed()), this, SLOT(startFilter())); connect(ui.filterPatternLineEdit, SIGNAL(returnPressed()), this, SLOT(startFilter()));
connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged())); connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged()));
// load settings
processSettings(true);
ui.remoteDirTreeView->setColumnHidden(3,false) ;
ui.remoteDirTreeView->setColumnHidden(4,true) ;
ui.localDirTreeView->setColumnHidden(4,true) ;
/* Set header resize modes and initial section sizes */ /* Set header resize modes and initial section sizes */
QHeaderView * l_header = ui.localDirTreeView->header () ; QHeaderView * l_header = ui.localDirTreeView->header () ;
// l_header->setResizeMode (0, QHeaderView::Interactive); // l_header->setResizeMode (0, QHeaderView::Interactive);
@ -173,6 +177,7 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
r_header->setResizeMode (0, QHeaderView::Interactive); r_header->setResizeMode (0, QHeaderView::Interactive);
r_header->setStretchLastSection(false); r_header->setStretchLastSection(false);
l_header->setStretchLastSection(false);
// r_header->setResizeMode (1, QHeaderView::Fixed); // r_header->setResizeMode (1, QHeaderView::Fixed);
// // r_header->setResizeMode (2, QHeaderView::Interactive); // // r_header->setResizeMode (2, QHeaderView::Interactive);
@ -182,28 +187,30 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
r_header->resizeSection ( 0, 490 ); r_header->resizeSection ( 0, 490 );
r_header->resizeSection ( 1, 70 ); r_header->resizeSection ( 1, 70 );
// r_header->resizeSection ( 2, 0 ); r_header->resizeSection ( 2, 80 );
r_header->resizeSection ( 3, 100 ); r_header->resizeSection ( 3, 100 );
// r_header->resizeSection ( 4, 0 ); r_header->resizeSection ( 4, 80 );
l_header->setHighlightSections(false); // l_header->setHighlightSections(false);
r_header->setHighlightSections(false); // r_header->setHighlightSections(false);
/* Set Multi Selection */ /* Set Multi Selection */
ui.remoteDirTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection); ui.remoteDirTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
ui.localDirTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection); ui.localDirTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
#ifdef RS_RELEASE_VERSION //#ifdef RS_RELEASE_VERSION
ui.filterLabel->hide(); // ui.filterLabel->hide();
ui.filterPatternLineEdit->hide(); // ui.filterPatternLineEdit->hide();
#endif //#endif
// Setup the current view model.
//
changeCurrentViewModel(ui.viewType_CB->currentIndex()) ;
ui.filterStartButton->hide(); ui.filterStartButton->hide();
ui.filterClearButton->hide(); ui.filterClearButton->hide();
// load settings
processSettings(true);
/* Hide platform specific features */ /* Hide platform specific features */
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
@ -261,6 +268,43 @@ void SharedFilesDialog::processSettings(bool bLoad)
Settings->endGroup(); Settings->endGroup();
} }
void SharedFilesDialog::changeCurrentViewModel(int c)
{
disconnect( ui.remoteDirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), 0, 0 );
disconnect( ui.remoteDirTreeView, SIGNAL( expanded(const QModelIndex & ) ), 0, 0 );
if(c == 0)
{
model = tree_model ;
proxyModel = tree_proxyModel ;
ui.remoteDirTreeView->setColumnHidden(3,true) ;
ui.filterLabel->hide();
ui.filterPatternLineEdit->hide();
}
else
{
model = flat_model ;
proxyModel = flat_proxyModel ;
ui.remoteDirTreeView->setColumnHidden(3,false) ;
ui.filterLabel->show();
ui.filterPatternLineEdit->show();
}
model->preMods();
model->postMods();
connect( ui.remoteDirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), model, SLOT( collapsed(const QModelIndex & ) ) );
connect( ui.remoteDirTreeView, SIGNAL( expanded(const QModelIndex & ) ), model, SLOT( expanded(const QModelIndex & ) ) );
ui.remoteDirTreeView->setModel(proxyModel);
ui.remoteDirTreeView->update();
ui.remoteDirTreeView->header()->headerDataChanged(Qt::Horizontal,0,4) ;
if(c == 1)
FilterItems();
}
void SharedFilesDialog::checkUpdate() void SharedFilesDialog::checkUpdate()
{ {
/* update */ /* update */
@ -667,7 +711,7 @@ void SharedFilesDialog::sharedDirTreeWidgetContextMenu( QPoint point )
if (!midx.isValid()) if (!midx.isValid())
return; return;
currentFile = localModel->data(midx, RemoteDirModel::FileNameRole).toString(); currentFile = localModel->data(midx, RetroshareDirModel::FileNameRole).toString();
int type = localModel->getType(midx); int type = localModel->getType(midx);
@ -873,24 +917,40 @@ void SharedFilesDialog::FilterItems()
QString text = ui.filterPatternLineEdit->text(); QString text = ui.filterPatternLineEdit->text();
setCursor(Qt::WaitCursor); setCursor(Qt::WaitCursor);
QCoreApplication::processEvents() ;
int rowCount = ui.remoteDirTreeView->model()->rowCount(); int rowCount = ui.remoteDirTreeView->model()->rowCount();
for (int row = 0; row < rowCount; row++) { for (int row = 0; row < rowCount; row++)
/* Filter name */ if(proxyModel == tree_proxyModel)
FilterItem(ui.remoteDirTreeView->model()->index(row, 0), text, 0); tree_FilterItem(ui.remoteDirTreeView->model()->index(row, 0), text, 0);
} else
flat_FilterItem(ui.remoteDirTreeView->model()->index(row, 0), text, 0);
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
} }
bool SharedFilesDialog::FilterItem(const QModelIndex &index, const QString &text, int level) bool SharedFilesDialog::flat_FilterItem(const QModelIndex &index, const QString &text, int level)
{
if(index.data(RetroshareDirModel::FileNameRole).toString().contains(text, Qt::CaseInsensitive))
{
ui.remoteDirTreeView->setRowHidden(index.row(), index.parent(), false);
return false ;
}
else
{
ui.remoteDirTreeView->setRowHidden(index.row(), index.parent(), true);
return true ;
}
}
bool SharedFilesDialog::tree_FilterItem(const QModelIndex &index, const QString &text, int level)
{ {
bool visible = true; bool visible = true;
if (text.isEmpty() == false) { if (text.isEmpty() == false) {
// better use RemoteDirModel::getType, but its slow enough // better use RetroshareDirModel::getType, but its slow enough
if (/*index.parent().isValid()*/ level >= 1) { if (/*index.parent().isValid()*/ level >= 1) {
if (index.data(RemoteDirModel::FileNameRole).toString().contains(text, Qt::CaseInsensitive) == false) { if (index.data(RetroshareDirModel::FileNameRole).toString().contains(text, Qt::CaseInsensitive) == false) {
visible = false; visible = false;
} }
} else { } else {
@ -901,7 +961,7 @@ bool SharedFilesDialog::FilterItem(const QModelIndex &index, const QString &text
int visibleChildCount = 0; int visibleChildCount = 0;
int rowCount = ui.remoteDirTreeView->model()->rowCount(index); int rowCount = ui.remoteDirTreeView->model()->rowCount(index);
for (int row = 0; row < rowCount; row++) { for (int row = 0; row < rowCount; row++) {
if (FilterItem(ui.remoteDirTreeView->model()->index(row, index.column(), index), text, level + 1)) { if (tree_FilterItem(ui.remoteDirTreeView->model()->index(row, index.column(), index), text, level + 1)) {
visibleChildCount++; visibleChildCount++;
} }
} }
@ -914,3 +974,4 @@ bool SharedFilesDialog::FilterItem(const QModelIndex &index, const QString &text
return (visible || visibleChildCount); return (visible || visibleChildCount);
} }

View file

@ -25,7 +25,7 @@
#include "RsAutoUpdatePage.h" #include "RsAutoUpdatePage.h"
#include "ui_SharedFilesDialog.h" #include "ui_SharedFilesDialog.h"
class RemoteDirModel; class RetroshareDirModel;
class QSortFilterProxyModel; class QSortFilterProxyModel;
class SharedFilesDialog : public RsAutoUpdatePage class SharedFilesDialog : public RsAutoUpdatePage
@ -87,6 +87,8 @@ private slots:
void clearFilter(); void clearFilter();
void startFilter(); void startFilter();
public slots:
void changeCurrentViewModel(int) ;
signals: signals:
void playFiles(QStringList files); void playFiles(QStringList files);
@ -103,7 +105,8 @@ private:
void copyLink (const QModelIndexList& lst, bool remote); void copyLink (const QModelIndexList& lst, bool remote);
void FilterItems(); void FilterItems();
bool FilterItem(const QModelIndex &index, const QString &text, int level); bool tree_FilterItem(const QModelIndex &index, const QString &text, int level);
bool flat_FilterItem(const QModelIndex &index, const QString &text, int level);
QModelIndexList getRemoteSelected(); QModelIndexList getRemoteSelected();
QModelIndexList getLocalSelected(); QModelIndexList getLocalSelected();
@ -125,10 +128,15 @@ private:
/** Qt Designer generated object */ /** Qt Designer generated object */
Ui::SharedFilesDialog ui; Ui::SharedFilesDialog ui;
/* RemoteDirModel */ /* RetroshareDirModel */
RemoteDirModel *model; RetroshareDirModel *tree_model;
RetroshareDirModel *flat_model;
RetroshareDirModel *model;
QSortFilterProxyModel *tree_proxyModel;
QSortFilterProxyModel *flat_proxyModel;
QSortFilterProxyModel *proxyModel; QSortFilterProxyModel *proxyModel;
RemoteDirModel *localModel;
RetroshareDirModel *localModel;
QSortFilterProxyModel *localProxyModel; QSortFilterProxyModel *localProxyModel;
QString currentCommand; QString currentCommand;

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>525</width> <width>934</width>
<height>297</height> <height>402</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -584,7 +584,7 @@ p, li { white-space: pre-wrap; }
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="5"> <item row="0" column="6">
<widget class="QPushButton" name="splittedButton"> <widget class="QPushButton" name="splittedButton">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
@ -616,7 +616,7 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="6"> <item row="0" column="7">
<widget class="QPushButton" name="remoteButton"> <widget class="QPushButton" name="remoteButton">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
@ -648,7 +648,7 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="7"> <item row="0" column="8">
<widget class="QPushButton" name="localButton"> <widget class="QPushButton" name="localButton">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
@ -680,7 +680,7 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="4"> <item row="0" column="5">
<widget class="QComboBox" name="indicatorCBox"> <widget class="QComboBox" name="indicatorCBox">
<item> <item>
<property name="text"> <property name="text">
@ -823,6 +823,20 @@ border-image: url(:/images/closepressed.png)
</item> </item>
</layout> </layout>
</item> </item>
<item row="0" column="4">
<widget class="QComboBox" name="viewType_CB">
<item>
<property name="text">
<string>Tree view</string>
</property>
</item>
<item>
<property name="text">
<string>Flat view</string>
</property>
</item>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -878,6 +892,12 @@ background: white;}</string>
<property name="sortingEnabled"> <property name="sortingEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -926,6 +946,12 @@ background: white;}</string>
<property name="sortingEnabled"> <property name="sortingEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
</widget> </widget>
</item> </item>
</layout> </layout>