mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
simplified a bit the code in Flat_Model, and tried to fix the crash when sorting items
This commit is contained in:
parent
53c65fff9f
commit
93818f6088
@ -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"
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include <util/rsversioninfo.h>
|
||||
#include <util/folderiterator.h>
|
||||
#include <ft/ftserver.h>
|
||||
#include <dbase/cachestrapper.h>
|
||||
#include <retroshare/rsplugin.h>
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include <pqi/pqiservice.h>
|
||||
|
@ -805,7 +805,6 @@ bool RsInit::SetHiddenLocation(const std::string& hiddenaddress, uint16_t port)
|
||||
#include <unistd.h>
|
||||
//#include <getopt.h>
|
||||
|
||||
#include "dbase/cachestrapper.h"
|
||||
#include "ft/ftserver.h"
|
||||
#include "ft/ftcontroller.h"
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "dbase/findex.h"
|
||||
#include "retroshare/rsexpr.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include <algorithm>
|
||||
|
@ -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<void*,QString>(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<details.children.size();++i)
|
||||
_ref_stack.push_back(details.children[i].ref) ;
|
||||
}
|
||||
if(++nb_treated_refs > 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<details.children.size();++i)
|
||||
_ref_stack.push_back(details.children[i].ref) ;
|
||||
}
|
||||
if(++nb_treated_refs > 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() ;
|
||||
}
|
||||
|
||||
|
@ -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<std::pair<void *,QString> > _ref_entries ;// used to store the refs to display
|
||||
mutable RsMutex _ref_mutex ;
|
||||
std::vector<void *> _ref_entries ;// used to store the refs to display
|
||||
std::vector<void *> _ref_stack ; // used to store the refs to update
|
||||
bool _needs_update ;
|
||||
};
|
||||
|
@ -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() ;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user