From 725abad777a05d47d03564c83854083734ff065b Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 23 Jan 2018 22:18:02 +0100 Subject: [PATCH 1/6] fixed a bug in filterItems that caused searched files to generate an error in the console --- libretroshare/src/file_sharing/p3filelists.cc | 65 ++++++++++--------- libretroshare/src/file_sharing/p3filelists.h | 2 +- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index bb5ba4e2f..3eaaa9d03 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -1155,6 +1155,8 @@ int p3FileDatabase::SearchKeywords(const std::list& keywords, std:: if(flags & RS_FILE_HINTS_LOCAL) { std::list firesults; + std::list pointers; + { RS_STACK_MUTEX(mFLSMtx) ; @@ -1164,16 +1166,16 @@ int p3FileDatabase::SearchKeywords(const std::list& keywords, std:: { void *p=NULL; convertEntryIndexToPointer(*it,0,p); - *it = (intptr_t)p ; + pointers.push_back(p) ; } } - filterResults(firesults,results,flags,client_peer_id) ; + filterResults(pointers,results,flags,client_peer_id) ; } if(flags & RS_FILE_HINTS_REMOTE) { - std::list firesults; + std::list pointers ; { RS_STACK_MUTEX(mFLSMtx) ; @@ -1188,21 +1190,21 @@ int p3FileDatabase::SearchKeywords(const std::list& keywords, std:: { void *p=NULL; convertEntryIndexToPointer(*it,i+1,p); - firesults.push_back((intptr_t)p) ; - } + + pointers.push_back(p) ; + } } } - for(std::list::const_iterator rit ( firesults.begin()); rit != firesults.end(); ++rit) - { - DirDetails dd; + for(auto it(pointers.begin());it!=pointers.end();++it) + { + DirDetails dd; - if(!RequestDirDetails ((void*)(intptr_t)*rit,dd,RS_FILE_HINTS_REMOTE)) - continue ; - - results.push_back(dd); - } + if(!RequestDirDetails (*it,dd,RS_FILE_HINTS_REMOTE)) + continue ; + results.push_back(dd); + } } return !results.empty() ; @@ -1213,6 +1215,7 @@ int p3FileDatabase::SearchBoolExp(RsRegularExpression::Expression *exp, std::lis if(flags & RS_FILE_HINTS_LOCAL) { std::list firesults; + std::list pointers; { RS_STACK_MUTEX(mFLSMtx) ; @@ -1222,17 +1225,16 @@ int p3FileDatabase::SearchBoolExp(RsRegularExpression::Expression *exp, std::lis { void *p=NULL; convertEntryIndexToPointer(*it,0,p); - *it = (intptr_t)p ; + pointers.push_back(p); } } - filterResults(firesults,results,flags,client_peer_id) ; + filterResults(pointers,results,flags,client_peer_id) ; } if(flags & RS_FILE_HINTS_REMOTE) { - std::list firesults; - + std::list pointers ; { RS_STACK_MUTEX(mFLSMtx) ; @@ -1246,21 +1248,20 @@ int p3FileDatabase::SearchBoolExp(RsRegularExpression::Expression *exp, std::lis { void *p=NULL; convertEntryIndexToPointer(*it,i+1,p); - firesults.push_back((intptr_t)p) ; - } - + pointers.push_back(p) ; + } } } - for(std::list::const_iterator rit ( firesults.begin()); rit != firesults.end(); ++rit) - { - DirDetails dd; + for(auto it(pointers.begin());it!=pointers.end();++it) + { + DirDetails dd; - if(!RequestDirDetails ((void*)(intptr_t)*rit,dd,RS_FILE_HINTS_REMOTE)) - continue ; + if(!RequestDirDetails (*it,dd,RS_FILE_HINTS_REMOTE)) + continue ; - results.push_back(dd); - } + results.push_back(dd); + } } return !results.empty() ; @@ -1312,7 +1313,7 @@ bool p3FileDatabase::search(const RsFileHash &hash, FileSearchFlags hintflags, F return false; } -int p3FileDatabase::filterResults(const std::list& firesults,std::list& results,FileSearchFlags flags,const RsPeerId& peer_id) const +int p3FileDatabase::filterResults(const std::list& firesults,std::list& results,FileSearchFlags flags,const RsPeerId& peer_id) const { results.clear(); @@ -1320,17 +1321,17 @@ int p3FileDatabase::filterResults(const std::list& firesults,std::li /* translate/filter results */ - for(std::list::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit) + for(std::list::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit) { DirDetails cdetails ; - if(!RequestDirDetails ((void*)(intptr_t)*rit,cdetails,RS_FILE_HINTS_LOCAL)) + if(!RequestDirDetails (*rit,cdetails,RS_FILE_HINTS_LOCAL)) { - P3FILELISTS_ERROR() << "(EE) Cannot get dir details for entry " << (void*)(intptr_t)*rit << std::endl; + P3FILELISTS_ERROR() << "(EE) Cannot get dir details for entry " << *rit << std::endl; continue ; } #ifdef DEBUG_P3FILELISTS - P3FILELISTS_DEBUG() << "Filtering candidate " << (void*)(intptr_t)(*rit) << ", flags=" << cdetails.flags << ", peer=" << peer_id ; + P3FILELISTS_DEBUG() << "Filtering candidate " << *rit << ", flags=" << cdetails.flags << ", peer=" << peer_id ; #endif if(!peer_id.isNull()) diff --git a/libretroshare/src/file_sharing/p3filelists.h b/libretroshare/src/file_sharing/p3filelists.h index 9eb5047da..4de5e24b3 100644 --- a/libretroshare/src/file_sharing/p3filelists.h +++ b/libretroshare/src/file_sharing/p3filelists.h @@ -159,7 +159,7 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub protected: - int filterResults(const std::list& firesults,std::list& results,FileSearchFlags flags,const RsPeerId& peer_id) const; + int filterResults(const std::list& firesults,std::list& results,FileSearchFlags flags,const RsPeerId& peer_id) const; std::string makeRemoteFileName(const RsPeerId& pid) const; // Derived from p3Config From 1ee353c5a737794daf01988430f415eab6323e7a Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 23 Jan 2018 22:18:35 +0100 Subject: [PATCH 2/6] improved efficiency of search in tree visualization mode. Re-enabled the search for testing purpose. --- .../gui/FileTransfer/SharedFilesDialog.cpp | 150 +++++++++++++++++- 1 file changed, 147 insertions(+), 3 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index ce67043a9..a162d898b 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -87,7 +87,7 @@ // Define to avoid using the search in treeview, because it is really slow for now. // -#define DONT_USE_SEARCH_IN_TREE_VIEW 1 +//#define DONT_USE_SEARCH_IN_TREE_VIEW 1 //#define DEBUG_SHARED_FILES_DIALOG 1 @@ -1246,6 +1246,73 @@ void SharedFilesDialog::startFilter() FilterItems(); } +// This macro make the search expand all items that contain the searched text. +// A bug however, makes RS expand everything when nothing is selected, which is a pain. + +#define EXPAND_WHILE_SEARCHING 1 + +static void recursMakeAllVisible(QTreeView *tree,const QModelIndex& indx) +{ + int rowCount = tree->model()->rowCount(indx); + + for (int row = 0; row < rowCount; ++row) + { + QModelIndex child_index = indx.child(row,0); + + tree->setRowHidden(child_index.row(), indx, false) ; + + recursMakeAllVisible(tree,child_index); + } +#ifdef EXPAND_WHILE_SEARCHING + tree->setExpanded(indx,false) ; +#endif +} + +//#define DEBUG_SHARED_FILES_DIALOG + +static void recursMakeVisible(QTreeView *tree,const QSortFilterProxyModel *proxyModel,const QModelIndex& indx,uint32_t depth,const std::vector >& pointers) +{ +#ifdef DEBUG_SHARED_FILES_DIALOG + for(uint32_t i=0;isetRowHidden(indx.row(), indx.parent(), false) ; +#ifdef EXPAND_WHILE_SEARCHING + tree->setExpanded(indx,true) ; +#endif + + for (int row = 0; row < rowCount; ++row) + { + QModelIndex child_index = indx.child(row,0); + + if(ptrs.find(proxyModel->mapToSource(child_index).internalPointer()) != ptrs.end()) + { +#ifdef DEBUG_SHARED_FILES_DIALOG + for(uint32_t i=0;imapToSource(child_index).internalPointer() << " visible" << std::endl; +#endif + recursMakeVisible(tree,proxyModel,child_index,depth+1,pointers) ; + } + else + { + tree->setRowHidden(child_index.row(), indx, true) ; +#ifdef EXPAND_WHILE_SEARCHING + tree->setExpanded(child_index,false) ; +#endif + +#ifdef DEBUG_SHARED_FILES_DIALOG + for(uint32_t i=0;imapToSource(child_index).internalPointer() << " hidden" << std::endl; +#endif + } + } +} + void SharedFilesDialog::FilterItems() { #ifdef DONT_USE_SEARCH_IN_TREE_VIEW @@ -1253,18 +1320,95 @@ void SharedFilesDialog::FilterItems() return; #endif + setCursor(Qt::WaitCursor); + ui.dirTreeView->blockSignals(true) ; + QString text = ui.filterPatternLineEdit->text(); - setCursor(Qt::WaitCursor); - QCoreApplication::processEvents() ; + if(proxyModel == tree_proxyModel) + { + QCoreApplication::processEvents() ; + std::list keywords ; + std::list result_list ; + + if(text.isNull()) + { + int rowCount = ui.dirTreeView->model()->rowCount(); + for (int row = 0; row < rowCount; ++row) + recursMakeAllVisible(ui.dirTreeView,ui.dirTreeView->model()->index(row, COLUMN_NAME)) ; + return ; + } + keywords.push_back(text.toStdString()); + FileSearchFlags flags = isRemote()?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; + + rsFiles->SearchKeywords(keywords,result_list, flags) ; + +#ifdef DEBUG_SHARED_FILES_DIALOG + std::cerr << "Found this result: " << std::endl; +#endif + std::vector > pointers(2,std::set()); // at least two levels need to be here. + + // Then show only the ones we need + for(auto it(result_list.begin());it!=result_list.end();++it) + { +#ifdef DEBUG_SHARED_FILES_DIALOG + std::cerr << (void*)(*it).ref << " parents: " ; +#endif + + DirDetails& det(*it) ; + void *p = NULL; + std::list lst ; + + lst.push_back(det.ref) ; + + while(det.type == DIR_TYPE_FILE || det.type == DIR_TYPE_DIR) + { + p = det.parent ; + rsFiles->RequestDirDetails( p, det, flags); + +#ifdef DEBUG_SHARED_FILES_DIALOG + std::cerr << " " << (void*)p << "(" << (int)det.type << ")"; +#endif + + lst.push_front(p) ; + } + +#ifdef DEBUG_SHARED_FILES_DIALOG + std::cerr << std::endl; +#endif + + uint32_t u=0; + for(auto it2(lst.begin());it2!=lst.end();++it2,++u) + { + if(pointers.size() <= u) + pointers.resize(u+5) ; + + pointers[u].insert(*it2) ; + } + } + + int rowCount = ui.dirTreeView->model()->rowCount(); + for (int row = 0; row < rowCount; ++row) + recursMakeVisible(ui.dirTreeView,proxyModel,ui.dirTreeView->model()->index(row, COLUMN_NAME),0,pointers); + } + else + { + int rowCount = ui.dirTreeView->model()->rowCount(); + for (int row = 0; row < rowCount; ++row) + flat_FilterItem(ui.dirTreeView->model()->index(row, COLUMN_NAME), text, 0); + } + +#ifdef DEPRECATED_CODE int rowCount = ui.dirTreeView->model()->rowCount(); for (int row = 0; row < rowCount; ++row) if(proxyModel == tree_proxyModel) tree_FilterItem(ui.dirTreeView->model()->index(row, COLUMN_NAME), text, 0); else flat_FilterItem(ui.dirTreeView->model()->index(row, COLUMN_NAME), text, 0); +#endif + ui.dirTreeView->blockSignals(false) ; setCursor(Qt::ArrowCursor); } From d93e259702729421317adf3c8ad0c3cce5fdefe6 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 24 Jan 2018 00:26:22 +0100 Subject: [PATCH 3/6] fixed expanding/collapsing of items on search --- retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index a162d898b..c0f6edb7b 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -1332,11 +1332,14 @@ void SharedFilesDialog::FilterItems() std::list keywords ; std::list result_list ; - if(text.isNull()) + if(text == "") { int rowCount = ui.dirTreeView->model()->rowCount(); + for (int row = 0; row < rowCount; ++row) recursMakeAllVisible(ui.dirTreeView,ui.dirTreeView->model()->index(row, COLUMN_NAME)) ; + + setCursor(Qt::ArrowCursor); return ; } keywords.push_back(text.toStdString()); From f139685438fdc61a0767bcf1bc556a2351b0fd27 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 24 Jan 2018 21:14:26 +0100 Subject: [PATCH 4/6] added a fair limit to search in FL in order to avoid crazy costs --- .../gui/FileTransfer/SharedFilesDialog.cpp | 82 ++++++++++++++++++- .../src/gui/FileTransfer/SharedFilesDialog.ui | 56 +++++++++---- 2 files changed, 121 insertions(+), 17 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index c0f6edb7b..86ca88cce 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -31,6 +31,7 @@ #include #include +#include "rshare.h" #include "SharedFilesDialog.h" #include "gui/notifyqt.h" #include "gui/MainWindow.h" @@ -49,6 +50,7 @@ #include #include +#include /* Images for context menu icons */ @@ -85,6 +87,8 @@ #define VIEW_TYPE_TREE 0 #define VIEW_TYPE_FLAT 1 +#define MAX_SEARCH_RESULTS 3000 + // Define to avoid using the search in treeview, because it is really slow for now. // //#define DONT_USE_SEARCH_IN_TREE_VIEW 1 @@ -1226,6 +1230,63 @@ void SharedFilesDialog::filterRegExpChanged() } else { ui.filterStartButton->show(); } + + bool valid = false ; + QColor color ; + + if(text.length() > 0 && text.length() < 3) + { + std::cout << "setting palette 1" << std::endl ; + valid = false; + //color = QApplication::palette().color(QPalette::Disabled, QPalette::Base); + + ui.filterStartButton->setEnabled(false) ; + ui.filterPatternFrame->setToolTip(tr("Search string should be at least 3 characters long.")) ; + return ; + } + + if(text.length() > 0 && proxyModel == tree_proxyModel) + { + std::list result_list ; + std::list keywords; + + QStringList lst = text.split(" ",QString::SkipEmptyParts) ; + + for(auto it(lst.begin());it!=lst.end();++it) + keywords.push_back((*it).toStdString()); + + FileSearchFlags flags = isRemote()?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; + + if(keywords.size() > 1) + { + RsRegularExpression::NameExpression exp(RsRegularExpression::ContainsAllStrings,keywords,true); + rsFiles->SearchBoolExp(&exp,result_list, flags) ; + } + else + rsFiles->SearchKeywords(keywords,result_list, flags) ; + + uint32_t nb_results = result_list.size(); + + if(nb_results > MAX_SEARCH_RESULTS) + { + ui.filterStartButton->setEnabled(false) ; + ui.filterPatternFrame->setToolTip(tr("More than 3000 results. Add more/longer search words to select less.")) ; + return ; + } + } + + ui.filterStartButton->setEnabled(true) ; + ui.filterPatternFrame->setToolTip(QString()); + + /* unpolish widget to clear the stylesheet's palette cache */ + // ui.filterPatternFrame->style()->unpolish(ui.filterPatternFrame); + + // QPalette palette = ui.filterPatternLineEdit->palette(); + // palette.setColor(ui.filterPatternLineEdit->backgroundRole(), color); + // ui.filterPatternLineEdit->setPalette(palette); + + // //ui.searchLineFrame->setProperty("valid", valid); + // Rshare::refreshStyleSheet(ui.filterPatternFrame, false); } /* clear Filter */ @@ -1342,11 +1403,28 @@ void SharedFilesDialog::FilterItems() setCursor(Qt::ArrowCursor); return ; } - keywords.push_back(text.toStdString()); + + if(text.length() < 3) + return ; + FileSearchFlags flags = isRemote()?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL; + QStringList lst = text.split(" ",QString::SkipEmptyParts) ; - rsFiles->SearchKeywords(keywords,result_list, flags) ; + for(auto it(lst.begin());it!=lst.end();++it) + keywords.push_back((*it).toStdString()); + if(keywords.size() > 1) + { + RsRegularExpression::NameExpression exp(RsRegularExpression::ContainsAllStrings,keywords,true); + rsFiles->SearchBoolExp(&exp,result_list, flags) ; + } + else + rsFiles->SearchKeywords(keywords,result_list, flags) ; + + std::cerr << "Found " << result_list.size() << " results" << std::endl; + + if(result_list.size() > MAX_SEARCH_RESULTS) + return ; #ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "Found this result: " << std::endl; #endif diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.ui b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.ui index f408098c5..68e3446b6 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.ui +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.ui @@ -6,7 +6,7 @@ 0 0 - 1156 + 1407 402 @@ -53,7 +53,7 @@ - :/icons/svg/folders.svg + :/icons/svg/folders.svg true @@ -89,7 +89,7 @@ Configure shared directories - + :/images/add-share24.png:/images/add-share24.png @@ -105,15 +105,41 @@ - :/images/find-16.png + :/images/find-16.png - - - Search files + + + + 50 + 0 + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + @@ -140,7 +166,7 @@ Start Search - + :/images/start.png:/images/start.png @@ -214,7 +240,7 @@ border-image: url(:/images/closepressed.png) All - + :/images/view_calendar_list.png:/images/view_calendar_list.png @@ -223,7 +249,7 @@ border-image: url(:/images/closepressed.png) One day old - + :/images/view_calendar_day.png:/images/view_calendar_day.png @@ -232,7 +258,7 @@ border-image: url(:/images/closepressed.png) One Week old - + :/images/view_calendar_week.png:/images/view_calendar_week.png @@ -241,7 +267,7 @@ border-image: url(:/images/closepressed.png) One month old - + :/images/view_calendar_month.png:/images/view_calendar_month.png @@ -282,7 +308,7 @@ border-image: url(:/images/closepressed.png) Download - + :/images/download16.png:/images/download16.png @@ -363,8 +389,8 @@ border-image: url(:/images/closepressed.png) - - + + From 1fbd9d16255e23567c92b6a7fd0b1522d9d0beb9 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 24 Jan 2018 21:26:35 +0100 Subject: [PATCH 5/6] fixed hiding of top level items when searching --- .../src/gui/FileTransfer/SharedFilesDialog.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index 86ca88cce..e9bf62bf2 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -1236,9 +1236,7 @@ void SharedFilesDialog::filterRegExpChanged() if(text.length() > 0 && text.length() < 3) { - std::cout << "setting palette 1" << std::endl ; valid = false; - //color = QApplication::palette().color(QPalette::Disabled, QPalette::Base); ui.filterStartButton->setEnabled(false) ; ui.filterPatternFrame->setToolTip(tr("Search string should be at least 3 characters long.")) ; @@ -1314,14 +1312,14 @@ void SharedFilesDialog::startFilter() static void recursMakeAllVisible(QTreeView *tree,const QModelIndex& indx) { + tree->setRowHidden(indx.row(), indx.parent(), false) ; + int rowCount = tree->model()->rowCount(indx); for (int row = 0; row < rowCount; ++row) { QModelIndex child_index = indx.child(row,0); - tree->setRowHidden(child_index.row(), indx, false) ; - recursMakeAllVisible(tree,child_index); } #ifdef EXPAND_WHILE_SEARCHING @@ -1349,6 +1347,8 @@ static void recursMakeVisible(QTreeView *tree,const QSortFilterProxyModel *proxy tree->setExpanded(indx,true) ; #endif + bool found = false ; + for (int row = 0; row < rowCount; ++row) { QModelIndex child_index = indx.child(row,0); @@ -1359,6 +1359,7 @@ static void recursMakeVisible(QTreeView *tree,const QSortFilterProxyModel *proxy for(uint32_t i=0;imapToSource(child_index).internalPointer() << " visible" << std::endl; #endif recursMakeVisible(tree,proxyModel,child_index,depth+1,pointers) ; + found = true ; } else { @@ -1372,6 +1373,9 @@ static void recursMakeVisible(QTreeView *tree,const QSortFilterProxyModel *proxy #endif } } + + if(!found && depth == 0) + tree->setRowHidden(indx.row(), indx.parent(), true) ; } void SharedFilesDialog::FilterItems() @@ -1421,7 +1425,9 @@ void SharedFilesDialog::FilterItems() else rsFiles->SearchKeywords(keywords,result_list, flags) ; +#ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "Found " << result_list.size() << " results" << std::endl; +#endif if(result_list.size() > MAX_SEARCH_RESULTS) return ; From 11eef05a1b0089b5aa9e9a3c4e66be52eaeb66ab Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 24 Jan 2018 22:02:49 +0100 Subject: [PATCH 6/6] fixed bug causing hidden/expanded items to be reset by show() event in SharedFilesDialog --- .../gui/FileTransfer/SharedFilesDialog.cpp | 55 ++++++++++++------- .../src/gui/FileTransfer/SharedFilesDialog.h | 8 +-- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp index e9bf62bf2..e6e015b5b 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.cpp @@ -287,14 +287,14 @@ void SharedFilesDialog::showEvent(QShowEvent *) { if(model!=NULL) { - std::set expanded_indexes,selected_indexes ; + std::set expanded_indexes,hidden_indexes,selected_indexes ; - saveExpandedPathsAndSelection(expanded_indexes,selected_indexes); + saveExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes); model->setVisible(true) ; model->update() ; - restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes); + restoreExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes); } } RemoteSharedFilesDialog::~RemoteSharedFilesDialog() @@ -391,9 +391,9 @@ void SharedFilesDialog::changeCurrentViewModel(int viewTypeIndex) showProperColumns() ; - std::set expanded_indexes,selected_indexes ; + std::set expanded_indexes,hidden_indexes,selected_indexes ; - saveExpandedPathsAndSelection(expanded_indexes,selected_indexes); + saveExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes); if(isVisible()) { @@ -407,7 +407,7 @@ void SharedFilesDialog::changeCurrentViewModel(int viewTypeIndex) ui.dirTreeView->setModel(proxyModel); ui.dirTreeView->update(); - restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes); + restoreExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes); QHeaderView * header = ui.dirTreeView->header () ; QHeaderView_setSectionResizeModeColumn(header, COLUMN_NAME, QHeaderView::Interactive); @@ -862,17 +862,19 @@ void SharedFilesDialog::preModDirectories(bool local) ui.dirTreeView->setSortingEnabled(false); - std::set expanded_indexes,selected_indexes; - saveExpandedPathsAndSelection(expanded_indexes,selected_indexes) ; + std::set expanded_indexes,hidden_indexes,selected_indexes; + saveExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes) ; /* Notify both models, only one is visible */ tree_model->preMods(); flat_model->preMods(); - restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes) ; + restoreExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes) ; } -void SharedFilesDialog::saveExpandedPathsAndSelection(std::set& expanded_indexes, std::set& selected_indexes) +void SharedFilesDialog::saveExpandedPathsAndSelection(std::set& expanded_indexes, + std::set& hidden_indexes, + std::set& selected_indexes) { if(ui.dirTreeView->model() == NULL) return ; @@ -884,11 +886,13 @@ void SharedFilesDialog::saveExpandedPathsAndSelection(std::set& exp { std::string path = ui.dirTreeView->model()->index(row,0).data(Qt::DisplayRole).toString().toStdString(); - recursSaveExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,selected_indexes); + recursSaveExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,hidden_indexes,selected_indexes); } } -void SharedFilesDialog::restoreExpandedPathsAndSelection(const std::set& expanded_indexes, const std::set& selected_indexes) +void SharedFilesDialog::restoreExpandedPathsAndSelection(const std::set& expanded_indexes, + const std::set& hidden_indexes, + const std::set& selected_indexes) { if(ui.dirTreeView->model() == NULL) return ; @@ -903,14 +907,17 @@ void SharedFilesDialog::restoreExpandedPathsAndSelection(const std::setmodel()->rowCount(); ++row) { std::string path = ui.dirTreeView->model()->index(row,0).data(Qt::DisplayRole).toString().toStdString(); - recursRestoreExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,selected_indexes); + recursRestoreExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,hidden_indexes,selected_indexes); } QItemSelection selection ; ui.dirTreeView->blockSignals(false) ; } -void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const std::string& path,std::set& exp,std::set& sel) +void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const std::string& path,std::set& exp, + std::set& vis, + std::set& sel + ) { std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString(); #ifdef DEBUG_SHARED_FILES_DIALOG @@ -920,6 +927,9 @@ void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const s if(ui.dirTreeView->selectionModel()->selection().contains(index)) sel.insert(local_path) ; + if(ui.dirTreeView->isRowHidden(index.row(),index.parent())) + vis.insert(local_path) ; + if(ui.dirTreeView->isExpanded(index)) { #ifdef DEBUG_SHARED_FILES_DIALOG @@ -929,7 +939,7 @@ void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const s exp.insert(local_path) ; for(int row=0;rowmodel()->rowCount(index);++row) - recursSaveExpandedItems(index.child(row,0),local_path,exp,sel) ; + recursSaveExpandedItems(index.child(row,0),local_path,exp,vis,sel) ; } #ifdef DEBUG_SHARED_FILES_DIALOG else @@ -937,7 +947,10 @@ void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const s #endif } -void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, const std::string &path, const std::set& exp, const std::set &sel) +void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, const std::string &path, + const std::set& exp, + const std::set& vis, + const std::set &sel) { std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString(); #ifdef DEBUG_SHARED_FILES_DIALOG @@ -946,6 +959,8 @@ void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, con if(sel.find(local_path) != sel.end()) ui.dirTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); + ui.dirTreeView->setRowHidden(index.row(),index.parent(), vis.find(local_path) != vis.end()) ; + if(exp.find(local_path) != exp.end()) { #ifdef DEBUG_SHARED_FILES_DIALOG @@ -954,7 +969,7 @@ void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, con ui.dirTreeView->setExpanded(index,true) ; for(int row=0;rowmodel()->rowCount(index);++row) - recursRestoreExpandedItems(index.child(row,0),local_path,exp,sel) ; + recursRestoreExpandedItems(index.child(row,0),local_path,exp,vis,sel) ; } } @@ -964,9 +979,9 @@ void SharedFilesDialog::postModDirectories(bool local) if (isRemote() == local) return; - std::set expanded_indexes,selected_indexes; + std::set expanded_indexes,selected_indexes,hidden_indexes; - saveExpandedPathsAndSelection(expanded_indexes,selected_indexes) ; + saveExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes) ; #ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "Saving expanded items. " << expanded_indexes.size() << " items found" << std::endl; #endif @@ -981,7 +996,7 @@ void SharedFilesDialog::postModDirectories(bool local) ui.dirTreeView->setSortingEnabled(true); - restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes) ; + restoreExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes) ; #ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "****** updated directories! Re-enabling sorting ******" << std::endl; diff --git a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h index 4fb18ab0c..6449da161 100644 --- a/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h +++ b/retroshare-gui/src/gui/FileTransfer/SharedFilesDialog.h @@ -87,10 +87,10 @@ protected: Ui::SharedFilesDialog ui; virtual void processSettings(bool bLoad) = 0; - void recursRestoreExpandedItems(const QModelIndex& index,const std::string& path,const std::set& exp,const std::set& sel); - void recursSaveExpandedItems(const QModelIndex& index, const std::string &path, std::set &exp, std::set& sel); - void saveExpandedPathsAndSelection(std::set& paths, std::set& selected_indexes) ; - void restoreExpandedPathsAndSelection(const std::set& paths, const std::set& selected_indexes) ; + void recursRestoreExpandedItems(const QModelIndex& index, const std::string& path, const std::set& exp, const std::set& vis, const std::set& sel); + void recursSaveExpandedItems(const QModelIndex& index, const std::string &path, std::set &exp,std::set& vis, std::set& sel); + void saveExpandedPathsAndSelection(std::set& paths,std::set& visible_indexes, std::set& selected_indexes) ; + void restoreExpandedPathsAndSelection(const std::set& paths,const std::set& visible_indexes, const std::set& selected_indexes) ; protected: //now context menu are created again every time theu are called ( in some