From 93818f6088db01ee36fd22ca2f7477634c4a44e9 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Tue, 13 Sep 2016 21:23:27 +0200 Subject: [PATCH] simplified a bit the code in Flat_Model, and tried to fix the crash when sorting items --- libretroshare/src/ft/ftcontroller.h | 1 - libretroshare/src/plugins/pluginmanager.cc | 1 - libretroshare/src/rsserver/rsinit.cc | 1 - libretroshare/src/util/rsexpr.cc | 1 - retroshare-gui/src/gui/RemoteDirModel.cpp | 104 +++++++++++-------- retroshare-gui/src/gui/RemoteDirModel.h | 5 +- retroshare-gui/src/gui/SharedFilesDialog.cpp | 23 ++-- 7 files changed, 77 insertions(+), 59 deletions(-) diff --git a/libretroshare/src/ft/ftcontroller.h b/libretroshare/src/ft/ftcontroller.h index 5ee84623b..516b07050 100644 --- a/libretroshare/src/ft/ftcontroller.h +++ b/libretroshare/src/ft/ftcontroller.h @@ -48,7 +48,6 @@ class ftDataMultiplex; class p3turtle ; class p3ServiceControl; -#include "dbase/cachestrapper.h" #include "util/rsthreads.h" #include "pqi/pqiservicemonitor.h" #include "pqi/p3cfgmgr.h" diff --git a/libretroshare/src/plugins/pluginmanager.cc b/libretroshare/src/plugins/pluginmanager.cc index 688cc0bb0..98335ea5a 100644 --- a/libretroshare/src/plugins/pluginmanager.cc +++ b/libretroshare/src/plugins/pluginmanager.cc @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index 82c5168f9..6726c1656 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -805,7 +805,6 @@ bool RsInit::SetHiddenLocation(const std::string& hiddenaddress, uint16_t port) #include //#include -#include "dbase/cachestrapper.h" #include "ft/ftserver.h" #include "ft/ftcontroller.h" diff --git a/libretroshare/src/util/rsexpr.cc b/libretroshare/src/util/rsexpr.cc index 6b4d7ce20..7e35a1873 100644 --- a/libretroshare/src/util/rsexpr.cc +++ b/libretroshare/src/util/rsexpr.cc @@ -24,7 +24,6 @@ */ -#include "dbase/findex.h" #include "retroshare/rsexpr.h" #include "retroshare/rstypes.h" #include diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 2153f255d..1afdc94ef 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -194,6 +194,7 @@ int FlatStyle_RDM::rowCount(const QModelIndex &parent) const std::cerr << "RetroshareDirModel::rowCount(): " << parent.internalPointer(); std::cerr << ": "; #endif + RS_STACK_MUTEX(_ref_mutex) ; return _ref_entries.size() ; } @@ -501,7 +502,12 @@ QVariant FlatStyle_RDM::sortRole(const QModelIndex& index,const DirDetails& deta case 1: return (qulonglong) details.count; case 2: return details.age; case 3: return QString::fromUtf8(rsPeers->getPeerName(details.id).c_str()); - case 4: return _ref_entries[index.row()].second ; + + case 4: { + RS_STACK_MUTEX(_ref_mutex) ; + + return computeDirectoryPath(details); + } } } return QVariant(); @@ -765,9 +771,11 @@ QModelIndex FlatStyle_RDM::index(int row, int column, const QModelIndex & parent if(row < 0) return QModelIndex() ; - if(row < (int) _ref_entries.size()) + RS_STACK_MUTEX(_ref_mutex) ; + + if(row < (int) _ref_entries.size()) { - void *ref = _ref_entries[row].first ; + void *ref = _ref_entries[row]; #ifdef RDM_DEBUG std::cerr << "Creating index 2 row=" << row << ", column=" << column << ", ref=" << (void*)ref << std::endl; @@ -903,7 +911,7 @@ void RetroshareDirModel::postMods() // changePersistentIndexList(piList, empty); /* Clear caches */ - mCache.clear(); + //mCache.clear(); #ifdef RDM_DEBUG std::cerr << "RetroshareDirModel::postMods()" << std::endl; @@ -1316,17 +1324,18 @@ TreeStyle_RDM::~TreeStyle_RDM() } void FlatStyle_RDM::postMods() { - if(visible()) + if(visible()) { - _ref_entries.clear() ; - _ref_stack.clear() ; + emit layoutAboutToBeChanged(); - _ref_stack.push_back(NULL) ; // init the stack with the topmost parent directory - - std::cerr << "FlatStyle_RDM::postMods(): cleared ref entries" << std::endl; - _needs_update = false ; - updateRefs() ; - } + { + RS_STACK_MUTEX(_ref_mutex) ; + _ref_stack.clear() ; + _ref_stack.push_back(NULL) ; // init the stack with the topmost parent directory + _needs_update = false ; + } + QTimer::singleShot(100,this,SLOT(updateRefs())) ; + } else _needs_update = true ; } @@ -1339,47 +1348,56 @@ void FlatStyle_RDM::updateRefs() return ; } - RetroshareDirModel::preMods() ; + RetroshareDirModel::preMods() ; - static const uint32_t MAX_REFS_PER_SECOND = 2000 ; + + static const uint32_t MAX_REFS_PER_SECOND = 2000 ; uint32_t nb_treated_refs = 0 ; - while(!_ref_stack.empty()) - { - void *ref = _ref_stack.back() ; + { + RS_STACK_MUTEX(_ref_mutex) ; + + _ref_entries.clear() ; + + std::cerr << "FlatStyle_RDM::postMods(): cleared ref entries" << std::endl; + + while(!_ref_stack.empty()) + { + void *ref = _ref_stack.back() ; #ifdef RDM_DEBUG - std::cerr << "FlatStyle_RDM::postMods(): poped ref " << ref << std::endl; + std::cerr << "FlatStyle_RDM::postMods(): poped ref " << ref << std::endl; #endif - _ref_stack.pop_back() ; + _ref_stack.pop_back() ; - DirDetails details ; + DirDetails details ; - if (requestDirDetails(ref, RemoteMode,details)) - { - if(details.type == DIR_TYPE_FILE) // only push files, not directories nor persons. - _ref_entries.push_back(std::pair(ref,computeDirectoryPath(details))); + if (requestDirDetails(ref, RemoteMode,details)) + { + 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(): adding ref " << ref << std::endl; + std::cerr << "FlatStyle_RDM::postMods(): adding ref " << ref << std::endl; #endif - for(uint32_t i=0;i MAX_REFS_PER_SECOND) // we've done enough, let's give back hand to - { // the user and setup a timer to finish the job later. - _needs_update = true ; + for(uint32_t i=0;i MAX_REFS_PER_SECOND) // we've done enough, let's give back hand to + { // the user and setup a timer to finish the job later. + _needs_update = true ; - if(visible()) - QTimer::singleShot(2000,this,SLOT(updateRefs())) ; - else - std::cerr << "Not visible: suspending update"<< std::endl; - break ; - } - } - std::cerr << "reference tab contains " << _ref_entries.size() << " files" << std::endl; + if(visible()) + QTimer::singleShot(2000,this,SLOT(updateRefs())) ; + else + std::cerr << "Not visible: suspending update"<< std::endl; + break ; + } + } + std::cerr << "reference tab contains " << _ref_entries.size() << " files" << std::endl; - if(_ref_stack.empty()) - _needs_update = false ; + if(_ref_stack.empty()) + _needs_update = false ; + } - RetroshareDirModel::postMods() ; + RetroshareDirModel::postMods() ; } diff --git a/retroshare-gui/src/gui/RemoteDirModel.h b/retroshare-gui/src/gui/RemoteDirModel.h index 54f60ffad..72a3fad7c 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.h +++ b/retroshare-gui/src/gui/RemoteDirModel.h @@ -194,7 +194,7 @@ class FlatStyle_RDM: public RetroshareDirModel public: FlatStyle_RDM(bool mode) - : RetroshareDirModel(mode) + : RetroshareDirModel(mode), _ref_mutex("Flat file list") { _needs_update = true ; } @@ -223,7 +223,8 @@ class FlatStyle_RDM: public RetroshareDirModel QString computeDirectoryPath(const DirDetails& details) const ; - std::vector > _ref_entries ;// used to store the refs to display + 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 ; }; diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index aaaa79284..80cbfa856 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -144,14 +144,17 @@ SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareD tree_proxyModel->setSortRole(RetroshareDirModel::SortRole); tree_proxyModel->sort(COLUMN_NAME); - 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(COLUMN_NAME); + flat_proxyModel = new SFDSortFilterProxyModel(flat_model, this); + flat_proxyModel->setSourceModel(flat_model); + flat_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); + flat_proxyModel->setSortRole(RetroshareDirModel::SortRole); + flat_proxyModel->sort(COLUMN_NAME); - connect(ui.filterClearButton, SIGNAL(clicked()), this, SLOT(clearFilter())); + // Mr.Alice: I removed this because it causes a crash for some obscur reason. Apparently when the model is changed, the proxy model cannot + // deal with the change by itself. Should I call something specific? I've no idea. Removing this does not seem to cause any harm either. + //flat_proxyModel->setDynamicSortFilter(true); + + connect(ui.filterClearButton, SIGNAL(clicked()), this, SLOT(clearFilter())); connect(ui.filterStartButton, SIGNAL(clicked()), this, SLOT(startFilter())); connect(ui.filterPatternLineEdit, SIGNAL(returnPressed()), this, SLOT(startFilter())); connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged())); @@ -346,13 +349,13 @@ void SharedFilesDialog::changeCurrentViewModel(int viewTypeIndex) if(viewTypeIndex==VIEW_TYPE_TREE) { model = tree_model ; - proxyModel = tree_proxyModel ; + proxyModel = tree_proxyModel ; } else { model = flat_model ; - proxyModel = flat_proxyModel ; - } + proxyModel = flat_proxyModel ; + } showProperColumns() ;