attempt at making remoteDirModel less CPU intentive. Remove potential deadlock source in SearchDialog.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4155 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-04-14 21:58:15 +00:00
parent 2dbd6f4380
commit a337941555
5 changed files with 82 additions and 12 deletions

View File

@ -26,6 +26,7 @@
#include <QMimeData> #include <QMimeData>
#include <QTimer> #include <QTimer>
#include <gui/RsAutoUpdatePage.h>
#include "RemoteDirModel.h" #include "RemoteDirModel.h"
#include <retroshare/rsfiles.h> #include <retroshare/rsfiles.h>
#include <retroshare/rstypes.h> #include <retroshare/rstypes.h>
@ -45,10 +46,20 @@ RetroshareDirModel::RetroshareDirModel(bool mode, QObject *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 */
{ {
_visible = false ;
_needs_update = true ;
setSupportedDragActions(Qt::CopyAction); setSupportedDragActions(Qt::CopyAction);
treeStyle(); treeStyle();
} }
void RetroshareDirModel::update()
{
if(_needs_update)
{
preMods() ;
postMods() ;
}
}
void RetroshareDirModel::treeStyle() void RetroshareDirModel::treeStyle()
{ {
categoryIcon.addPixmap(QPixmap(":/images/folder16.png"), categoryIcon.addPixmap(QPixmap(":/images/folder16.png"),
@ -1294,17 +1305,29 @@ TreeStyle_RDM::~TreeStyle_RDM()
} }
void FlatStyle_RDM::postMods() void FlatStyle_RDM::postMods()
{ {
_ref_entries.clear() ; if(visible())
_ref_stack.clear() ; {
_ref_entries.clear() ;
_ref_stack.push_back(NULL) ; // init the stack with the topmost parent directory _ref_stack.clear() ;
std::cerr << "FlatStyle_RDM::postMods(): cleared ref entries" << std::endl; _ref_stack.push_back(NULL) ; // init the stack with the topmost parent directory
updateRefs() ;
std::cerr << "FlatStyle_RDM::postMods(): cleared ref entries" << std::endl;
_needs_update = false ;
updateRefs() ;
}
else
_needs_update = true ;
} }
void FlatStyle_RDM::updateRefs() void FlatStyle_RDM::updateRefs()
{ {
if(RsAutoUpdatePage::eventsLocked())
{
_needs_update = true ;
return ;
}
RetroshareDirModel::preMods() ; RetroshareDirModel::preMods() ;
static const uint32_t MAX_REFS_PER_SECOND = 2000 ; static const uint32_t MAX_REFS_PER_SECOND = 2000 ;
@ -1332,12 +1355,20 @@ void FlatStyle_RDM::updateRefs()
} }
if(++nb_treated_refs > MAX_REFS_PER_SECOND) // we've done enough, let's give back hand to 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. { // the user and setup a timer to finish the job later.
QTimer::singleShot(500,this,SLOT(updateRefs())) ; _needs_update = true ;
if(visible())
QTimer::singleShot(2000,this,SLOT(updateRefs())) ;
else
std::cerr << "Not visible: suspending update"<< std::endl;
break ; break ;
} }
} }
std::cerr << "reference tab contains " << _ref_entries.size() << " files" << std::endl; std::cerr << "reference tab contains " << _ref_entries.size() << " files" << std::endl;
if(_ref_stack.empty())
_needs_update = false ;
RetroshareDirModel::postMods() ; RetroshareDirModel::postMods() ;
} }

View File

@ -50,6 +50,9 @@ class RetroshareDirModel : public QAbstractItemModel
virtual void preMods(); virtual void preMods();
virtual void postMods(); virtual void postMods();
void setVisible(bool b) { _visible = b ; }
bool visible() { return _visible ;}
/* Callback from GUI */ /* Callback from GUI */
void downloadSelected(const QModelIndexList &list); void downloadSelected(const QModelIndexList &list);
@ -62,6 +65,7 @@ class RetroshareDirModel : public QAbstractItemModel
void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; } void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; }
bool requestDirDetails(void *ref,DirDetails& details,uint32_t flags) const; bool requestDirDetails(void *ref,DirDetails& details,uint32_t flags) const;
void update() ;
public: public:
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const; virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
@ -69,6 +73,9 @@ class RetroshareDirModel : public QAbstractItemModel
virtual QVariant data(const QModelIndex &index, int role) const; virtual QVariant data(const QModelIndex &index, int role) const;
protected: protected:
bool _visible ;
bool _needs_update ;
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) ;

View File

@ -27,6 +27,7 @@
#include "RetroShareLink.h" #include "RetroShareLink.h"
#include "msgs/MessageComposer.h" #include "msgs/MessageComposer.h"
#include "gui/RSHumanReadableDelegate.h" #include "gui/RSHumanReadableDelegate.h"
#include "gui/RsAutoUpdatePage.h"
#include "settings/rsharesettings.h" #include "settings/rsharesettings.h"
#include "advsearch/advancedsearchdialog.h" #include "advsearch/advancedsearchdialog.h"
@ -672,6 +673,15 @@ void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
void SearchDialog::processResultQueue() void SearchDialog::processResultQueue()
{ {
// This avoids a deadlock when gpg callback asks a passwd.
// Send again in 10 secs.
//
if(RsAutoUpdatePage::eventsLocked())
{
QTimer::singleShot(10000,this,SLOT(processResultQueue())) ;
return ;
}
int nb_treated_elements = 0 ; int nb_treated_elements = 0 ;
while(!searchResultsQueue.empty() && nb_treated_elements++ < 500) while(!searchResultsQueue.empty() && nb_treated_elements++ < 500)

View File

@ -88,7 +88,7 @@ private:
/** Constructor */ /** Constructor */
SharedFilesDialog::SharedFilesDialog(QWidget *parent) SharedFilesDialog::SharedFilesDialog(QWidget *parent)
: RsAutoUpdatePage(1000,parent) : RsAutoUpdatePage(1000,parent),model(NULL)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this); ui.setupUi(this);
@ -235,6 +235,21 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
connect(openfolderAct, SIGNAL(triggered()), this, SLOT(openfolder())); connect(openfolderAct, SIGNAL(triggered()), this, SLOT(openfolder()));
} }
void SharedFilesDialog::hideEvent(QHideEvent *)
{
if(model!=NULL)
model->setVisible(false) ;
//std::cerr << "Hidden!"<< std::endl;
}
void SharedFilesDialog::showEvent(QShowEvent *)
{
if(model!=NULL)
{
model->setVisible(true) ;
model->update() ;
}
//std::cerr << "Shown!"<< std::endl;
}
SharedFilesDialog::~SharedFilesDialog() SharedFilesDialog::~SharedFilesDialog()
{ {
// save settings // save settings
@ -279,6 +294,9 @@ void SharedFilesDialog::changeCurrentViewModel(int c)
disconnect( ui.remoteDirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), 0, 0 ); disconnect( ui.remoteDirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), 0, 0 );
disconnect( ui.remoteDirTreeView, SIGNAL( expanded(const QModelIndex & ) ), 0, 0 ); disconnect( ui.remoteDirTreeView, SIGNAL( expanded(const QModelIndex & ) ), 0, 0 );
if(model!=NULL)
model->setVisible(false) ;
if(c == 0) if(c == 0)
{ {
model = tree_model ; model = tree_model ;
@ -304,8 +322,11 @@ void SharedFilesDialog::changeCurrentViewModel(int c)
#endif #endif
} }
model->preMods(); if(isVisible())
model->postMods(); {
model->setVisible(true) ;
model->update() ;
}
connect( ui.remoteDirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), model, SLOT( collapsed(const QModelIndex & ) ) ); 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.remoteDirTreeView, SIGNAL( expanded(const QModelIndex & ) ), model, SLOT( expanded(const QModelIndex & ) ) );
@ -682,8 +703,7 @@ void SharedFilesDialog::openfolder()
void SharedFilesDialog::preModDirectories(bool update_local) void SharedFilesDialog::preModDirectories(bool update_local)
{ {
//std::cerr << "SharedFilesDialog::preModDirectories called with update_local = " << update_local << std::endl ;
//std::cerr << "SharedFilesDialog::preModDirectories called with update_local = " << update_local << std::endl ;
if (update_local) if (update_local)
localModel->preMods(); localModel->preMods();
else else

View File

@ -39,6 +39,8 @@ public:
~SharedFilesDialog(); ~SharedFilesDialog();
virtual void updatePage() { checkUpdate() ; } virtual void updatePage() { checkUpdate() ; }
virtual void hideEvent(QHideEvent *) ;
virtual void showEvent(QShowEvent *) ;
private slots: private slots: