From a89ab8ffa3f491b43fcf01a627f744122b59df7e Mon Sep 17 00:00:00 2001 From: Phenom Date: Sat, 24 Feb 2018 14:07:32 +0100 Subject: [PATCH] Add ShowEmpty sub menu in Tree Remote SharedFilesDialog. --- .../gui/FileTransfer/SharedFilesDialog.cpp | 111 ++++++----- .../src/gui/FileTransfer/SharedFilesDialog.h | 2 +- retroshare-gui/src/gui/RemoteDirModel.cpp | 185 +++++++++++------- retroshare-gui/src/gui/RemoteDirModel.h | 156 ++++++++------- 4 files changed, 263 insertions(+), 191 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index 30da45723..ae6377120 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -146,7 +146,7 @@ public: /** Constructor */ SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareDirModel *_flat_model,QWidget *parent) -: RsAutoUpdatePage(1000,parent),model(NULL) + : RsAutoUpdatePage(1000,parent), model(NULL) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); @@ -410,7 +410,7 @@ void SharedFilesDialog::changeCurrentViewModel(int viewTypeIndex) ui.dirTreeView->header()->headerDataChanged(Qt::Horizontal, COLUMN_NAME, COLUMN_WN_VISU_DIR) ; // recursRestoreExpandedItems(ui.dirTreeView->rootIndex(),expanded_indexes); - FilterItems(); + FilterItems(); } void LocalSharedFilesDialog::showProperColumns() @@ -491,53 +491,63 @@ void RemoteSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) { if (!rsPeers) return; /* not ready yet! */ + QMenu *contextMenu = new QMenu(this); + QModelIndex idx = ui.dirTreeView->indexAt(point) ; - if (!idx.isValid()) return; - - QModelIndex midx = proxyModel->mapToSource(idx) ; - if (!midx.isValid()) return; - - currentFile = model->data(midx, RetroshareDirModel::FileNameRole).toString() ; - int type = model->getType(midx) ; - if (type != DIR_TYPE_DIR && type != DIR_TYPE_FILE) return; - - - QMenu contextMnu( this ) ; - - collCreateAct->setEnabled(true); - collOpenAct->setEnabled(true); - - QMenu collectionMenu(tr("Collection"), this); - collectionMenu.setIcon(QIcon(IMAGE_LIBRARY)); - collectionMenu.addAction(collCreateAct); - collectionMenu.addAction(collOpenAct); - - QModelIndexList list = ui.dirTreeView->selectionModel()->selectedRows() ; - - if(type == DIR_TYPE_DIR || list.size() > 1) + if (idx.isValid()) { - QAction *downloadActI = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download..." ), &contextMnu ) ; - connect( downloadActI , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelectedInteractive() ) ) ; - contextMnu.addAction( downloadActI) ; - } - else - { - QAction *downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), &contextMnu ) ; - connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) ) ; - contextMnu.addAction( downloadAct) ; + + QModelIndex midx = proxyModel->mapToSource(idx) ; + if (midx.isValid()) + { + + currentFile = model->data(midx, RetroshareDirModel::FileNameRole).toString() ; + int type = model->getType(midx) ; + if ( (type == DIR_TYPE_DIR) || (type == DIR_TYPE_FILE) ) + { + collCreateAct->setEnabled(true); + collOpenAct->setEnabled(true); + + QModelIndexList list = ui.dirTreeView->selectionModel()->selectedRows() ; + + if(type == DIR_TYPE_DIR || list.size() > 1) + { + QAction *downloadActI = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download..." ), contextMenu ) ; + connect( downloadActI , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelectedInteractive() ) ) ; + contextMenu->addAction( downloadActI) ; + } + else + { + QAction *downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), contextMenu ) ; + connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) ) ; + contextMenu->addAction( downloadAct) ; + } + + contextMenu->addSeparator() ;//------------------------------------ + contextMenu->addAction( copylinkAct) ; + contextMenu->addAction( sendlinkAct) ; + contextMenu->addSeparator() ;//------------------------------------ + contextMenu->addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to..."), this, SLOT(recommendFilesToMsg())) ; + + contextMenu->addSeparator() ;//------------------------------------ + + QMenu collectionMenu(tr("Collection"), this); + collectionMenu.setIcon(QIcon(IMAGE_LIBRARY)); + collectionMenu.addAction(collCreateAct); + collectionMenu.addAction(collOpenAct); + contextMenu->addMenu(&collectionMenu) ; + + } + + } } - contextMnu.addSeparator() ;//------------------------------------ - contextMnu.addAction( copylinkAct) ; - contextMnu.addAction( sendlinkAct) ; - contextMnu.addSeparator() ;//------------------------------------ - contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to..."), this, SLOT(recommendFilesToMsg())) ; + contextMenu = model->getContextMenu(contextMenu); + if (!contextMenu->children().isEmpty()) + contextMenu->exec(QCursor::pos()) ; - contextMnu.addSeparator() ;//------------------------------------ - contextMnu.addMenu(&collectionMenu) ; - - contextMnu.exec(QCursor::pos()) ; + delete contextMenu; } QModelIndexList SharedFilesDialog::getSelected() @@ -908,7 +918,7 @@ void SharedFilesDialog::restoreExpandedPathsAndSelection(const std::setmodel()->index(row,0).data(Qt::DisplayRole).toString().toStdString(); recursRestoreExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,hidden_indexes,selected_indexes); } - QItemSelection selection ; + //QItemSelection selection ; ui.dirTreeView->blockSignals(false) ; } @@ -997,12 +1007,12 @@ void SharedFilesDialog::postModDirectories(bool local) flat_model->postMods(); ui.dirTreeView->update() ; - if (ui.filterPatternLineEdit->text().isEmpty() == false) + if (ui.filterPatternLineEdit->text().isEmpty() == false) FilterItems(); - ui.dirTreeView->setSortingEnabled(true); + ui.dirTreeView->setSortingEnabled(true); - restoreExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes) ; + restoreExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes) ; #ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "****** updated directories! Re-enabling sorting ******" << std::endl; @@ -1320,10 +1330,10 @@ void SharedFilesDialog::clearFilter() /* clear Filter */ void SharedFilesDialog::startFilter() { - ui.filterStartButton->hide(); - lastFilterString = ui.filterPatternLineEdit->text(); + ui.filterStartButton->hide(); + lastFilterString = ui.filterPatternLineEdit->text(); - FilterItems(); + FilterItems(); } void SharedFilesDialog::updateDirTreeView() @@ -1603,4 +1613,3 @@ bool SharedFilesDialog::tree_FilterItem(const QModelIndex &index, const QString return (visible || visibleChildCount); } - diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h index 6c48ea4c0..982abd275 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h @@ -195,7 +195,7 @@ class RemoteSharedFilesDialog : public SharedFilesDialog private slots: void downloadRemoteSelected(); void downloadRemoteSelectedInteractive(); - void expanded(const QModelIndex& indx); + void expanded(const QModelIndex& indx); }; #endif diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 94cf7c6bf..f6d0df88f 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -50,21 +50,40 @@ static const size_t FLAT_VIEW_MAX_REFS_TABLE_SIZE = 10000 ; // static const uint32_t FLAT_VIEW_MIN_DELAY_BETWEEN_UPDATES = 120 ; // dont rebuild ref list more than every 2 mins. RetroshareDirModel::RetroshareDirModel(bool mode, QObject *parent) - : QAbstractItemModel(parent), - ageIndicator(IND_ALWAYS), - RemoteMode(mode), nIndex(1), indexSet(1) /* ass zero index cant be used */ + : QAbstractItemModel(parent), _visible(false) + , ageIndicator(IND_ALWAYS) + , RemoteMode(mode)//, nIndex(1), indexSet(1) /* ass zero index cant be used */ + , mLastRemote(false), mLastReq(0), mUpdating(false) { - _visible = false ; #if QT_VERSION < QT_VERSION_CHECK (5, 0, 0) setSupportedDragActions(Qt::CopyAction); #endif treeStyle(); - mDirDetails.ref = (void*)intptr_t(0xffffffff) ; - mLastRemote = false ; - mUpdating = false; + mDirDetails.ref = (void*)intptr_t(0xffffffff) ; } +TreeStyle_RDM::TreeStyle_RDM(bool mode) + : RetroshareDirModel(mode), _showEmpty(false) +{ + _showEmptyAct = new QAction(QIcon(), tr("Show Empty"), this); + _showEmptyAct->setCheckable(true); + _showEmptyAct->setChecked(_showEmpty); + connect(_showEmptyAct, SIGNAL(toggled(bool)), this, SLOT(showEmpty(bool))); +} + +FlatStyle_RDM::FlatStyle_RDM(bool mode) + : RetroshareDirModel(mode), _ref_mutex("Flat file list") +{ + _needs_update = true ; + + { + RS_STACK_MUTEX(_ref_mutex) ; + _last_update = 0 ; + } +} + + // QAbstractItemModel::setSupportedDragActions() was replaced by virtual QAbstractItemModel::supportedDragActions() #if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0) Qt::DropActions RetroshareDirModel::supportedDragActions() const @@ -78,7 +97,6 @@ static bool isNewerThanEpoque(uint32_t ts) return ts > 0 ; // this should be conservative enough } - void RetroshareDirModel::treeStyle() { categoryIcon.addPixmap(QPixmap(":/images/folder16.png"), @@ -97,6 +115,21 @@ void TreeStyle_RDM::updateRef(const QModelIndex& indx) const rsFiles->requestDirUpdate(indx.internalPointer()) ; } +QMenu* TreeStyle_RDM::getContextMenu(QMenu* contextMenu) +{ + if (!contextMenu){ + contextMenu = new QMenu(); + } else { + if (RemoteMode) + contextMenu->addSeparator(); + } + + if (RemoteMode) + contextMenu->addAction( _showEmptyAct) ; + + return contextMenu; +} + bool TreeStyle_RDM::hasChildren(const QModelIndex &parent) const { @@ -171,9 +204,13 @@ int TreeStyle_RDM::rowCount(const QModelIndex &parent) const void *ref = (parent.isValid())? parent.internalPointer() : NULL ; - DirDetails details ; + if ((!ref) && RemoteMode) + _parentRow.clear(); //Only clear it when asking root child number and in remote mode. - if (! requestDirDetails(ref, RemoteMode,details)) + + DirDetails details ; + + if (! requestDirDetails(ref, RemoteMode,details)) { #ifdef RDM_DEBUG std::cerr << "lookup failed -> 0"; @@ -181,7 +218,7 @@ int TreeStyle_RDM::rowCount(const QModelIndex &parent) const #endif return 0; } - if (details.type == DIR_TYPE_FILE) + if (details.type == DIR_TYPE_FILE) { #ifdef RDM_DEBUG std::cerr << "lookup FILE: 0"; @@ -195,9 +232,21 @@ int TreeStyle_RDM::rowCount(const QModelIndex &parent) const std::cerr << "lookup PER/DIR #" << details->count; std::cerr << std::endl; #endif - return details.count; + if ((details.type == DIR_TYPE_ROOT) && !_showEmpty && RemoteMode) + { + DirDetails childDetails; + //Scan all children to know if they are empty. + //And save their real row index + //Prefer do like that than modify requestDirDetails with a new flag (rsFiles->RequestDirDetails) + for(uint64_t i = 0; i < details.count; ++i) + { + if (requestDirDetails(details.children[i].ref, RemoteMode,childDetails) && (childDetails.count > 0)) + _parentRow.push_back(i); + } + return _parentRow.size(); + } + return details.count; } - int FlatStyle_RDM::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); @@ -210,6 +259,7 @@ int FlatStyle_RDM::rowCount(const QModelIndex &parent) const return _ref_entries.size() ; } + int TreeStyle_RDM::columnCount(const QModelIndex &/*parent*/) const { return COLUMN_COUNT; @@ -218,6 +268,7 @@ int FlatStyle_RDM::columnCount(const QModelIndex &/*parent*/) const { return COLUMN_COUNT; } + QString RetroshareDirModel::getFlagsString(FileStorageFlags flags) { char str[11] = "- - -" ; @@ -253,7 +304,6 @@ QString RetroshareDirModel::getGroupsString(FileStorageFlags flags,const std::li return groups_str ; } - QString RetroshareDirModel::getAgeIndicatorString(const DirDetails &details) const { QString ret(""); @@ -496,17 +546,6 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const return QVariant(); } /* end of DisplayRole */ -FlatStyle_RDM::FlatStyle_RDM(bool mode) - : RetroshareDirModel(mode), _ref_mutex("Flat file list") -{ - _needs_update = true ; - - { - RS_STACK_MUTEX(_ref_mutex) ; - _last_update = 0 ; - } -} - void FlatStyle_RDM::update() { if(_needs_update) @@ -650,7 +689,6 @@ QVariant TreeStyle_RDM::sortRole(const QModelIndex& /*index*/,const DirDetails& } return QVariant(); } - QVariant FlatStyle_RDM::sortRole(const QModelIndex& /*index*/,const DirDetails& details,int coln) const { /* @@ -678,9 +716,6 @@ QVariant FlatStyle_RDM::sortRole(const QModelIndex& /*index*/,const DirDetails& return QVariant(); } /* end of SortRole */ - - - QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const { #ifdef RDM_DEBUG @@ -771,6 +806,7 @@ QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const return QVariant(); } +/**** //void RetroshareDirModel::getAgeIndicatorRec(const DirDetails &details, QString &ret) const { // if (details.type == DIR_TYPE_FILE) { // ret = getAgeIndicatorString(details); @@ -786,6 +822,7 @@ QVariant RetroshareDirModel::data(const QModelIndex &index, int role) const // } // } //} +****/ QVariant TreeStyle_RDM::headerData(int section, Qt::Orientation orientation, int role) const { @@ -895,8 +932,8 @@ QModelIndex TreeStyle_RDM::index(int row, int column, const QModelIndex & parent std::cerr << ": row:" << row << " col:" << column << " "; #endif - // This function is used extensively. There's no way we can use requestDirDetails() in it, which would - // cause far too much overhead. So we use a dedicated function that only grabs the required information. + // This function is used extensively. There's no way we can use requestDirDetails() in it, which would + // cause far too much overhead. So we use a dedicated function that only grabs the required information. if(row < 0) return QModelIndex() ; @@ -910,15 +947,19 @@ QModelIndex TreeStyle_RDM::index(int row, int column, const QModelIndex & parent } ********/ + //If on root and don't show empty child, get real parent row + if ((!ref) && (!_showEmpty) && RemoteMode && ((size_t)row >= _parentRow.size())) + return QModelIndex(); - void *result ; + int parentRow = ((!ref) && (!_showEmpty) && RemoteMode) ? _parentRow[row] : row ; - if(rsFiles->findChildPointer(ref, row, result, ((RemoteMode) ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL))) - return createIndex(row, column, result) ; - else + void *result ; + + if(rsFiles->findChildPointer(ref, parentRow, result, ((RemoteMode) ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL))) + return createIndex(row, column, result) ; + else return QModelIndex(); } - QModelIndex FlatStyle_RDM::index(int row, int column, const QModelIndex & parent) const { Q_UNUSED(parent); @@ -964,10 +1005,10 @@ QModelIndex TreeStyle_RDM::parent( const QModelIndex & index ) const } void *ref = index.internalPointer(); - DirDetails details ; + DirDetails details ; - if (! requestDirDetails(ref, RemoteMode,details)) - { + if (! requestDirDetails(ref, RemoteMode,details)) + { #ifdef RDM_DEBUG std::cerr << "Failed Lookup -> invalid"; std::cerr << std::endl; @@ -975,7 +1016,7 @@ QModelIndex TreeStyle_RDM::parent( const QModelIndex & index ) const return QModelIndex(); } - if (!(details.parent)) + if (!(details.parent)) { #ifdef RDM_DEBUG std::cerr << "success. parent is Root/NULL --> invalid"; @@ -988,9 +1029,10 @@ QModelIndex TreeStyle_RDM::parent( const QModelIndex & index ) const std::cerr << "success index(" << details->prow << ",0," << details->parent << ")"; std::cerr << std::endl; - std::cerr << "Creating index 3 row=" << details.prow << ", column=" << 0 << ", ref=" << (void*)details.parent << std::endl; + std::cerr << "Creating index 3 row=" << details.prow << ", column=" << 0 << ", ref=" << (void*)details.parent << std::endl; #endif - return createIndex(details.prow, COLUMN_NAME, details.parent); + + return createIndex(details.prow, COLUMN_NAME, details.parent); } QModelIndex FlatStyle_RDM::parent( const QModelIndex & index ) const { @@ -1039,7 +1081,7 @@ Qt::ItemFlags RetroshareDirModel::flags( const QModelIndex & index ) const -/* Callback from */ +/* Callback from Core*/ void RetroshareDirModel::preMods() { emit layoutAboutToBeChanged(); @@ -1056,7 +1098,7 @@ void RetroshareDirModel::preMods() #endif } -/* Callback from */ +/* Callback from Core*/ void RetroshareDirModel::postMods() { // emit layoutAboutToBeChanged(); @@ -1075,6 +1117,30 @@ void RetroshareDirModel::postMods() emit layoutChanged(); } +void FlatStyle_RDM::postMods() +{ + time_t now = time(NULL); + + if(_last_update + FLAT_VIEW_MIN_DELAY_BETWEEN_UPDATES > now) + return ; + + if(visible()) + { + emit layoutAboutToBeChanged(); + + { + RS_STACK_MUTEX(_ref_mutex) ; + _ref_stack.clear() ; + _ref_stack.push_back(NULL) ; // init the stack with the topmost parent directory + _ref_entries.clear(); + _last_update = now; + } + QTimer::singleShot(100,this,SLOT(updateRefs())) ; + } + else + _needs_update = true ; +} + bool RetroshareDirModel::requestDirDetails(void *ref, bool remote,DirDetails& d) const { #ifdef RDM_DEBUG @@ -1475,35 +1541,11 @@ int RetroshareDirModel::getType ( const QModelIndex & index ) const return rsFiles->getType(index.internalPointer(),flags); } -FlatStyle_RDM::~FlatStyle_RDM() -{ -} - TreeStyle_RDM::~TreeStyle_RDM() { } -void FlatStyle_RDM::postMods() +FlatStyle_RDM::~FlatStyle_RDM() { - time_t now = time(NULL); - - if(_last_update + FLAT_VIEW_MIN_DELAY_BETWEEN_UPDATES > now) - return ; - - if(visible()) - { - emit layoutAboutToBeChanged(); - - { - RS_STACK_MUTEX(_ref_mutex) ; - _ref_stack.clear() ; - _ref_stack.push_back(NULL) ; // init the stack with the topmost parent directory - _ref_entries.clear(); - _last_update = now; - } - QTimer::singleShot(100,this,SLOT(updateRefs())) ; - } - else - _needs_update = true ; } void FlatStyle_RDM::updateRefs() @@ -1563,3 +1605,8 @@ void FlatStyle_RDM::updateRefs() RetroshareDirModel::postMods() ; } +void TreeStyle_RDM::showEmpty(const bool value) +{ + _showEmpty = value; + update(); +} diff --git a/retroshare-gui/src/gui/RemoteDirModel.h b/retroshare-gui/src/gui/RemoteDirModel.h index fb0272ae3..6b4fe8967 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.h +++ b/retroshare-gui/src/gui/RemoteDirModel.h @@ -25,7 +25,9 @@ #include #include +#include #include +#include #include #include @@ -63,7 +65,7 @@ class RetroshareDirModel : public QAbstractItemModel RetroshareDirModel(bool mode, QObject *parent = 0); virtual ~RetroshareDirModel() {} - Qt::ItemFlags flags ( const QModelIndex & index ) const; + virtual Qt::ItemFlags flags ( const QModelIndex & index ) const; /* Callback from Core */ virtual void preMods(); @@ -82,18 +84,21 @@ class RetroshareDirModel : public QAbstractItemModel void getFileInfoFromIndexList(const QModelIndexList& list, std::list& files_info) ; void openSelected(const QModelIndexList &list); void getFilePaths(const QModelIndexList &list, std::list &fullpaths); - void getFilePath(const QModelIndex& index, std::string& fullpath); - void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; } + void getFilePath(const QModelIndex& index, std::string& fullpath); + void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; } + + bool requestDirDetails(void *ref, bool remote,DirDetails& d) const; - bool requestDirDetails(void *ref, bool remote,DirDetails& d) const; virtual void update() {} + virtual void updateRef(const QModelIndex&) const =0; - virtual void updateRef(const QModelIndex&) const =0; + virtual QMenu* getContextMenu(QMenu* contextMenu) {return contextMenu;} public: - virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const; + //Overloaded from QAbstractItemModel + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; virtual QStringList mimeTypes () const; - virtual QVariant data(const QModelIndex &index, int role) const; + virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const; #if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0) virtual Qt::DropActions supportedDragActions() const; #endif @@ -104,10 +109,10 @@ class RetroshareDirModel : public QAbstractItemModel void treeStyle(); void downloadDirectory(const DirDetails & details, int prefixLen); static QString getFlagsString(FileStorageFlags f) ; - static QString getGroupsString(FileStorageFlags flags, const std::list &) ; + static QString getGroupsString(FileStorageFlags flags, const std::list &) ; QString getAgeIndicatorString(const DirDetails &) const; // void getAgeIndicatorRec(const DirDetails &details, QString &ret) const; - static const QIcon& getFlagsIcon(FileStorageFlags flags) ; + static const QIcon& getFlagsIcon(FileStorageFlags flags) ; virtual QVariant displayRole(const DirDetails&,int) const = 0 ; virtual QVariant sortRole(const QModelIndex&,const DirDetails&,int) const =0; @@ -119,46 +124,46 @@ class RetroshareDirModel : public QAbstractItemModel QIcon categoryIcon; QIcon peerIcon; - class RemoteIndex - { - public: - RemoteIndex() {} - RemoteIndex(std::string in_person, - std::string in_path, - int in_idx, - int in_row, - int in_column, - std::string in_name, - int in_size, - int in_type, - int in_ts, int in_rank) - :id(in_person), path(in_path), parent(in_idx), - row(in_row), column(in_column), - name(in_name), size(in_size), - type(in_type), timestamp(in_ts), rank(in_rank) - { - return; - } - - std::string id; - std::string path; - int parent; - int row; - int column; - - /* display info */ - std::string name; - int size; - int type; - int timestamp; - int rank; - - }; + //class RemoteIndex + //{ + // public: + // RemoteIndex() {} + // RemoteIndex(std::string in_person, + // std::string in_path, + // int in_idx, + // int in_row, + // int in_column, + // std::string in_name, + // int in_size, + // int in_type, + // int in_ts, int in_rank) + // :id(in_person), path(in_path), parent(in_idx), + // row(in_row), column(in_column), + // name(in_name), size(in_size), + // type(in_type), timestamp(in_ts), rank(in_rank) + // { + // return; + // } + // + // std::string id; + // std::string path; + // int parent; + // int row; + // int column; + // + // /* display info */ + // std::string name; + // int size; + // int type; + // int timestamp; + // int rank; + // + //}; bool RemoteMode; - mutable int nIndex; - mutable std::vector indexSet; + //mutable int nIndex; + //mutable std::vector indexSet; // This material attempts to keep last request in cache, with no search cost. @@ -178,28 +183,36 @@ class TreeStyle_RDM: public RetroshareDirModel Q_OBJECT public: - TreeStyle_RDM(bool mode) - : RetroshareDirModel(mode) - { - } - + TreeStyle_RDM(bool mode); virtual ~TreeStyle_RDM() ; protected: - virtual void updateRef(const QModelIndex&) const ; + + //Overloaded from RetroshareDirModel virtual void update() ; - - /* 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 void updateRef(const QModelIndex&) const ; + virtual QMenu* getContextMenu(QMenu* contextMenu) ; virtual QVariant displayRole(const DirDetails&,int) const ; virtual QVariant sortRole(const QModelIndex&,const DirDetails&,int) const ; + //Overloaded from QAbstractItemModel virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex() ) const; virtual QModelIndex parent ( const QModelIndex & index ) const; + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; virtual bool hasChildren(const QModelIndex & parent = QModelIndex()) const; + + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + + private slots: + void showEmpty(const bool value); + + private: + QAction *_showEmptyAct; + bool _showEmpty; + protected: + mutable std::vector _parentRow ; // used to store the real parent row for non empty child }; // This class shows a flat list of all shared files @@ -212,9 +225,9 @@ class FlatStyle_RDM: public RetroshareDirModel public: FlatStyle_RDM(bool mode); - virtual ~FlatStyle_RDM() ; + //Overloaded from RetroshareDirModel virtual void update() ; bool isMaxRefsTableSize(size_t* maxSize = NULL); @@ -223,27 +236,30 @@ class FlatStyle_RDM: public RetroshareDirModel void updateRefs() ; protected: - virtual void updateRef(const QModelIndex&) const {} - 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; + //Overloaded from RetroshareDirModel + virtual void postMods();/* Callback from Core */ + virtual void updateRef(const QModelIndex&) const {} virtual QVariant displayRole(const DirDetails&,int) const ; virtual QVariant sortRole(const QModelIndex&,const DirDetails&,int) const ; + //Overloaded from QAbstractItemModel virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex() ) const; virtual QModelIndex parent ( const QModelIndex & index ) const; + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; virtual bool hasChildren(const QModelIndex & parent = QModelIndex()) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + + QString computeDirectoryPath(const DirDetails& details) const ; - mutable RsMutex _ref_mutex ; - std::vector _ref_entries ;// used to store the refs to display - std::vector _ref_stack ; // used to store the refs to update + mutable RsMutex _ref_mutex ; + std::vector _ref_entries ; // used to store the refs to display + std::vector _ref_stack ; // used to store the refs to update bool _needs_update ; - time_t _last_update ; + time_t _last_update ; };