- 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

File diff suppressed because it is too large Load Diff

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_ALWAYS = ~(uint32_t)0 ;
class RemoteDirModel : public QAbstractItemModel
class RetroshareDirModel : public QAbstractItemModel
{
Q_OBJECT
public:
enum Roles{ FileNameRole = Qt::UserRole+1, SortRole = Qt::UserRole+2 };
RemoteDirModel(bool mode, QObject *parent = 0);
/* 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;
RetroshareDirModel(bool mode, QObject *parent = 0);
virtual ~RetroshareDirModel() {}
Qt::ItemFlags flags ( const QModelIndex & index ) const;
bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
/* Callback from Core */
void preMods();
void postMods();
virtual void preMods();
virtual void postMods();
/* Callback from GUI */
void downloadSelected(const QModelIndexList &list);
@ -68,36 +56,29 @@ class RemoteDirModel : public QAbstractItemModel
void getDirDetailsFromSelect (const QModelIndexList &list, std::vector <DirDetails>& dirVec);
int getType ( const QModelIndex & index ) const ;
//void openFile(QModelIndex fileIndex, const QString command);
void getFileInfoFromIndexList(const QModelIndexList& list, std::list<DirDetails>& files_info) ;
void openSelected(const QModelIndexList &list);
void getFilePaths(const QModelIndexList &list, std::list<std::string> &fullpaths);
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:
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
virtual QStringList mimeTypes () const;
virtual QVariant data(const QModelIndex &index, int role) const;
private:
// void update (const QModelIndex &index );
protected:
void treeStyle();
void downloadDirectory(const DirDetails & details, int prefixLen);
static QString getFlagsString(uint32_t) ;
QString getAgeIndicatorString(const DirDetails &) 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;
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

View File

@ -60,7 +60,7 @@ const QString Image_AddNewAssotiationForFile = ":/images/kcmsystem24.png";
class SFDSortFilterProxyModel : public QSortFilterProxyModel
{
public:
SFDSortFilterProxyModel(RemoteDirModel *dirModel, QObject *parent) : QSortFilterProxyModel(parent)
SFDSortFilterProxyModel(RetroshareDirModel *dirModel, QObject *parent) : QSortFilterProxyModel(parent)
{
m_dirModel = dirModel;
};
@ -79,7 +79,7 @@ protected:
}
private:
RemoteDirModel *m_dirModel;
RetroshareDirModel *m_dirModel;
};
/** Constructor */
@ -89,13 +89,11 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
connect(ui.checkButton, SIGNAL(clicked()), this, SLOT(forceCheck()));
connect(ui.localButton, SIGNAL(toggled(bool)), this, SLOT(showFrame(bool)));
connect(ui.remoteButton, SIGNAL(toggled(bool)), this, SLOT(showFrameRemote(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.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);
proxyModel->setDynamicSortFilter(true);
proxyModel->setSourceModel(model);
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
proxyModel->setSortRole(RemoteDirModel::SortRole);
proxyModel->sort(0);
tree_proxyModel = new SFDSortFilterProxyModel(tree_model, this);
tree_proxyModel->setDynamicSortFilter(true);
tree_proxyModel->setSourceModel(tree_model);
tree_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
tree_proxyModel->setSortRole(RetroshareDirModel::SortRole);
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->setDynamicSortFilter(true);
localProxyModel->setSourceModel(localModel);
localProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
localProxyModel->setSortRole(RemoteDirModel::SortRole);
localProxyModel->setSortRole(RetroshareDirModel::SortRole);
localProxyModel->sort(0);
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( 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(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 */
QHeaderView * l_header = ui.localDirTreeView->header () ;
// l_header->setResizeMode (0, QHeaderView::Interactive);
@ -173,6 +177,7 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
r_header->setResizeMode (0, QHeaderView::Interactive);
r_header->setStretchLastSection(false);
l_header->setStretchLastSection(false);
// r_header->setResizeMode (1, QHeaderView::Fixed);
// // r_header->setResizeMode (2, QHeaderView::Interactive);
@ -182,28 +187,30 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
r_header->resizeSection ( 0, 490 );
r_header->resizeSection ( 1, 70 );
// r_header->resizeSection ( 2, 0 );
r_header->resizeSection ( 2, 80 );
r_header->resizeSection ( 3, 100 );
// r_header->resizeSection ( 4, 0 );
r_header->resizeSection ( 4, 80 );
l_header->setHighlightSections(false);
r_header->setHighlightSections(false);
// l_header->setHighlightSections(false);
// r_header->setHighlightSections(false);
/* Set Multi Selection */
ui.remoteDirTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
ui.localDirTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
#ifdef RS_RELEASE_VERSION
ui.filterLabel->hide();
ui.filterPatternLineEdit->hide();
#endif
//#ifdef RS_RELEASE_VERSION
// ui.filterLabel->hide();
// ui.filterPatternLineEdit->hide();
//#endif
// Setup the current view model.
//
changeCurrentViewModel(ui.viewType_CB->currentIndex()) ;
ui.filterStartButton->hide();
ui.filterClearButton->hide();
// load settings
processSettings(true);
/* Hide platform specific features */
#ifdef Q_WS_WIN
@ -261,6 +268,43 @@ void SharedFilesDialog::processSettings(bool bLoad)
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()
{
/* update */
@ -667,7 +711,7 @@ void SharedFilesDialog::sharedDirTreeWidgetContextMenu( QPoint point )
if (!midx.isValid())
return;
currentFile = localModel->data(midx, RemoteDirModel::FileNameRole).toString();
currentFile = localModel->data(midx, RetroshareDirModel::FileNameRole).toString();
int type = localModel->getType(midx);
@ -873,24 +917,40 @@ void SharedFilesDialog::FilterItems()
QString text = ui.filterPatternLineEdit->text();
setCursor(Qt::WaitCursor);
QCoreApplication::processEvents() ;
int rowCount = ui.remoteDirTreeView->model()->rowCount();
for (int row = 0; row < rowCount; row++) {
/* Filter name */
FilterItem(ui.remoteDirTreeView->model()->index(row, 0), text, 0);
}
for (int row = 0; row < rowCount; row++)
if(proxyModel == tree_proxyModel)
tree_FilterItem(ui.remoteDirTreeView->model()->index(row, 0), text, 0);
else
flat_FilterItem(ui.remoteDirTreeView->model()->index(row, 0), text, 0);
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;
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.data(RemoteDirModel::FileNameRole).toString().contains(text, Qt::CaseInsensitive) == false) {
if (index.data(RetroshareDirModel::FileNameRole).toString().contains(text, Qt::CaseInsensitive) == false) {
visible = false;
}
} else {
@ -901,7 +961,7 @@ bool SharedFilesDialog::FilterItem(const QModelIndex &index, const QString &text
int visibleChildCount = 0;
int rowCount = ui.remoteDirTreeView->model()->rowCount(index);
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++;
}
}
@ -914,3 +974,4 @@ bool SharedFilesDialog::FilterItem(const QModelIndex &index, const QString &text
return (visible || visibleChildCount);
}

View File

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

View File

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