mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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:
parent
2dbd6f4380
commit
a337941555
@ -26,6 +26,7 @@
|
||||
#include <QMimeData>
|
||||
#include <QTimer>
|
||||
|
||||
#include <gui/RsAutoUpdatePage.h>
|
||||
#include "RemoteDirModel.h"
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include <retroshare/rstypes.h>
|
||||
@ -45,10 +46,20 @@ RetroshareDirModel::RetroshareDirModel(bool mode, QObject *parent)
|
||||
ageIndicator(IND_ALWAYS),
|
||||
RemoteMode(mode), nIndex(1), indexSet(1) /* ass zero index cant be used */
|
||||
{
|
||||
_visible = false ;
|
||||
_needs_update = true ;
|
||||
setSupportedDragActions(Qt::CopyAction);
|
||||
treeStyle();
|
||||
}
|
||||
|
||||
void RetroshareDirModel::update()
|
||||
{
|
||||
if(_needs_update)
|
||||
{
|
||||
preMods() ;
|
||||
postMods() ;
|
||||
}
|
||||
}
|
||||
void RetroshareDirModel::treeStyle()
|
||||
{
|
||||
categoryIcon.addPixmap(QPixmap(":/images/folder16.png"),
|
||||
@ -1294,17 +1305,29 @@ TreeStyle_RDM::~TreeStyle_RDM()
|
||||
}
|
||||
void FlatStyle_RDM::postMods()
|
||||
{
|
||||
_ref_entries.clear() ;
|
||||
_ref_stack.clear() ;
|
||||
|
||||
_ref_stack.push_back(NULL) ; // init the stack with the topmost parent directory
|
||||
if(visible())
|
||||
{
|
||||
_ref_entries.clear() ;
|
||||
_ref_stack.clear() ;
|
||||
|
||||
std::cerr << "FlatStyle_RDM::postMods(): cleared ref entries" << std::endl;
|
||||
updateRefs() ;
|
||||
_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() ;
|
||||
}
|
||||
else
|
||||
_needs_update = true ;
|
||||
}
|
||||
|
||||
void FlatStyle_RDM::updateRefs()
|
||||
{
|
||||
if(RsAutoUpdatePage::eventsLocked())
|
||||
{
|
||||
_needs_update = true ;
|
||||
return ;
|
||||
}
|
||||
|
||||
RetroshareDirModel::preMods() ;
|
||||
|
||||
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
|
||||
{ // 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 ;
|
||||
}
|
||||
}
|
||||
std::cerr << "reference tab contains " << _ref_entries.size() << " files" << std::endl;
|
||||
|
||||
if(_ref_stack.empty())
|
||||
_needs_update = false ;
|
||||
|
||||
RetroshareDirModel::postMods() ;
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,9 @@ class RetroshareDirModel : public QAbstractItemModel
|
||||
virtual void preMods();
|
||||
virtual void postMods();
|
||||
|
||||
void setVisible(bool b) { _visible = b ; }
|
||||
bool visible() { return _visible ;}
|
||||
|
||||
/* Callback from GUI */
|
||||
void downloadSelected(const QModelIndexList &list);
|
||||
|
||||
@ -62,6 +65,7 @@ class RetroshareDirModel : public QAbstractItemModel
|
||||
void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; }
|
||||
|
||||
bool requestDirDetails(void *ref,DirDetails& details,uint32_t flags) const;
|
||||
void update() ;
|
||||
public:
|
||||
|
||||
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
|
||||
@ -69,6 +73,9 @@ class RetroshareDirModel : public QAbstractItemModel
|
||||
virtual QVariant data(const QModelIndex &index, int role) const;
|
||||
|
||||
protected:
|
||||
bool _visible ;
|
||||
bool _needs_update ;
|
||||
|
||||
void treeStyle();
|
||||
void downloadDirectory(const DirDetails & details, int prefixLen);
|
||||
static QString getFlagsString(uint32_t) ;
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "RetroShareLink.h"
|
||||
#include "msgs/MessageComposer.h"
|
||||
#include "gui/RSHumanReadableDelegate.h"
|
||||
#include "gui/RsAutoUpdatePage.h"
|
||||
#include "settings/rsharesettings.h"
|
||||
#include "advsearch/advancedsearchdialog.h"
|
||||
|
||||
@ -672,6 +673,15 @@ void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
|
||||
|
||||
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 ;
|
||||
|
||||
while(!searchResultsQueue.empty() && nb_treated_elements++ < 500)
|
||||
|
@ -88,7 +88,7 @@ private:
|
||||
|
||||
/** Constructor */
|
||||
SharedFilesDialog::SharedFilesDialog(QWidget *parent)
|
||||
: RsAutoUpdatePage(1000,parent)
|
||||
: RsAutoUpdatePage(1000,parent),model(NULL)
|
||||
{
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
ui.setupUi(this);
|
||||
@ -235,6 +235,21 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
|
||||
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()
|
||||
{
|
||||
// save settings
|
||||
@ -279,6 +294,9 @@ void SharedFilesDialog::changeCurrentViewModel(int c)
|
||||
disconnect( ui.remoteDirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), 0, 0 );
|
||||
disconnect( ui.remoteDirTreeView, SIGNAL( expanded(const QModelIndex & ) ), 0, 0 );
|
||||
|
||||
if(model!=NULL)
|
||||
model->setVisible(false) ;
|
||||
|
||||
if(c == 0)
|
||||
{
|
||||
model = tree_model ;
|
||||
@ -304,8 +322,11 @@ void SharedFilesDialog::changeCurrentViewModel(int c)
|
||||
#endif
|
||||
}
|
||||
|
||||
model->preMods();
|
||||
model->postMods();
|
||||
if(isVisible())
|
||||
{
|
||||
model->setVisible(true) ;
|
||||
model->update() ;
|
||||
}
|
||||
|
||||
connect( ui.remoteDirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), model, SLOT( collapsed(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)
|
||||
{
|
||||
|
||||
//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)
|
||||
localModel->preMods();
|
||||
else
|
||||
|
@ -39,6 +39,8 @@ public:
|
||||
~SharedFilesDialog();
|
||||
|
||||
virtual void updatePage() { checkUpdate() ; }
|
||||
virtual void hideEvent(QHideEvent *) ;
|
||||
virtual void showEvent(QShowEvent *) ;
|
||||
|
||||
|
||||
private slots:
|
||||
|
Loading…
Reference in New Issue
Block a user