From a337941555b26bd67c07d93ff103130a9d832df8 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 14 Apr 2011 21:58:15 +0000 Subject: [PATCH] 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 --- retroshare-gui/src/gui/RemoteDirModel.cpp | 45 +++++++++++++++++--- retroshare-gui/src/gui/RemoteDirModel.h | 7 +++ retroshare-gui/src/gui/SearchDialog.cpp | 10 +++++ retroshare-gui/src/gui/SharedFilesDialog.cpp | 30 ++++++++++--- retroshare-gui/src/gui/SharedFilesDialog.h | 2 + 5 files changed, 82 insertions(+), 12 deletions(-) diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index b4cb2c2cc..df06f3bbb 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -26,6 +26,7 @@ #include #include +#include #include "RemoteDirModel.h" #include #include @@ -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() ; } diff --git a/retroshare-gui/src/gui/RemoteDirModel.h b/retroshare-gui/src/gui/RemoteDirModel.h index f77553bc2..54f944e00 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.h +++ b/retroshare-gui/src/gui/RemoteDirModel.h @@ -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) ; diff --git a/retroshare-gui/src/gui/SearchDialog.cpp b/retroshare-gui/src/gui/SearchDialog.cpp index f100364dd..c86e7bfc5 100644 --- a/retroshare-gui/src/gui/SearchDialog.cpp +++ b/retroshare-gui/src/gui/SearchDialog.cpp @@ -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) diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index c5cf2de97..9abe95367 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -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 diff --git a/retroshare-gui/src/gui/SharedFilesDialog.h b/retroshare-gui/src/gui/SharedFilesDialog.h index 8097ca36c..05a3f48e2 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.h +++ b/retroshare-gui/src/gui/SharedFilesDialog.h @@ -39,6 +39,8 @@ public: ~SharedFilesDialog(); virtual void updatePage() { checkUpdate() ; } + virtual void hideEvent(QHideEvent *) ; + virtual void showEvent(QShowEvent *) ; private slots: