diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index e53bc8e9a..49ae0aa0c 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -224,7 +224,7 @@ int p3FileDatabase::tick() mLastRemoteDirSweepTS = now; - // This is a hash to make loaded directories show up in the GUI, because the GUI generally isn't ready at the time they are actually loaded up, + // This is a hack to make loaded directories show up in the GUI, because the GUI generally isn't ready at the time they are actually loaded up, // so the first notify is ignored, and no other notify will happen next. RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_FRIENDS, 0); diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index 036dd96e2..db2129b62 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -256,13 +256,14 @@ void SharedFilesDialog::showEvent(QShowEvent *) { if(model!=NULL) { - std::set expanded_indexes ; - saveExpandedPaths(expanded_indexes); + std::set expanded_indexes,selected_indexes ; + + saveExpandedPathsAndSelection(expanded_indexes,selected_indexes); model->setVisible(true) ; model->update() ; - restoreExpandedPaths(expanded_indexes); + restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes); } } RemoteSharedFilesDialog::~RemoteSharedFilesDialog() @@ -359,8 +360,9 @@ void SharedFilesDialog::changeCurrentViewModel(int viewTypeIndex) showProperColumns() ; - std::set expanded_indexes ; - saveExpandedPaths(expanded_indexes); + std::set expanded_indexes,selected_indexes ; + + saveExpandedPathsAndSelection(expanded_indexes,selected_indexes); if(isVisible()) { @@ -374,7 +376,7 @@ void SharedFilesDialog::changeCurrentViewModel(int viewTypeIndex) ui.dirTreeView->setModel(proxyModel); ui.dirTreeView->update(); - restoreExpandedPaths(expanded_indexes); + restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes); QHeaderView * header = ui.dirTreeView->header () ; QHeaderView_setSectionResizeModeColumn(header, COLUMN_NAME, QHeaderView::Interactive); @@ -851,7 +853,7 @@ void SharedFilesDialog::preModDirectories(bool local) flat_model->preMods(); } -void SharedFilesDialog::saveExpandedPaths(std::set& expanded_indexes) +void SharedFilesDialog::saveExpandedPathsAndSelection(std::set& expanded_indexes, std::set& selected_indexes) { if(ui.dirTreeView->model() == NULL) return ; @@ -862,11 +864,12 @@ void SharedFilesDialog::saveExpandedPaths(std::set& expanded_indexe for(int row = 0; row < ui.dirTreeView->model()->rowCount(); ++row) { std::string path = ui.dirTreeView->model()->index(row,0).data(Qt::DisplayRole).toString().toStdString(); - recursSaveExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes); + + recursSaveExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,selected_indexes); } } -void SharedFilesDialog::restoreExpandedPaths(const std::set& expanded_indexes) +void SharedFilesDialog::restoreExpandedPathsAndSelection(const std::set& expanded_indexes, const std::set& selected_indexes) { if(ui.dirTreeView->model() == NULL) return ; @@ -881,18 +884,23 @@ void SharedFilesDialog::restoreExpandedPaths(const std::set& expand for(int row = 0; row < ui.dirTreeView->model()->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); + recursRestoreExpandedItems(ui.dirTreeView->model()->index(row,0),path,expanded_indexes,selected_indexes); } + QItemSelection selection ; + ui.dirTreeView->blockSignals(false) ; } -void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const std::string& path,std::set& exp) +void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const std::string& path,std::set& exp,std::set& sel) { std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString(); #ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "at index " << index.row() << ". data[1]=" << local_path << std::endl; #endif + if(ui.dirTreeView->selectionModel()->selection().contains(index)) + sel.insert(local_path) ; + if(ui.dirTreeView->isExpanded(index)) { #ifdef DEBUG_SHARED_FILES_DIALOG @@ -902,7 +910,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) ; + recursSaveExpandedItems(index.child(row,0),local_path,exp,sel) ; } #ifdef DEBUG_SHARED_FILES_DIALOG else @@ -910,12 +918,14 @@ void SharedFilesDialog::recursSaveExpandedItems(const QModelIndex& index,const s #endif } -void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, const std::string &path, const std::set& exp) +void SharedFilesDialog::recursRestoreExpandedItems(const QModelIndex& index, const std::string &path, const std::set& exp, const std::set &sel) { std::string local_path = path+"/"+index.data(Qt::DisplayRole).toString().toStdString(); #ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "at index " << index.row() << ". data[1]=" << local_path << std::endl; #endif + if(sel.find(local_path) != sel.end()) + ui.dirTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); if(exp.find(local_path) != exp.end()) { @@ -925,7 +935,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) ; + recursRestoreExpandedItems(index.child(row,0),local_path,exp,sel) ; } } @@ -935,8 +945,9 @@ void SharedFilesDialog::postModDirectories(bool local) if (isRemote() == local) { return; } - std::set expanded_indexes; - saveExpandedPaths(expanded_indexes) ; + std::set expanded_indexes,selected_indexes; + + saveExpandedPathsAndSelection(expanded_indexes,selected_indexes) ; #ifdef DEBUG_SHARED_FILES_DIALOG std::cerr << "Saving expanded items. " << expanded_indexes.size() << " items found" << std::endl; #endif @@ -946,7 +957,7 @@ void SharedFilesDialog::postModDirectories(bool local) flat_model->postMods(); ui.dirTreeView->update() ; - restoreExpandedPaths(expanded_indexes) ; + restoreExpandedPathsAndSelection(expanded_indexes,selected_indexes) ; if (ui.filterPatternLineEdit->text().isEmpty() == false) FilterItems(); diff --git a/retroshare-gui/src/gui/SharedFilesDialog.h b/retroshare-gui/src/gui/SharedFilesDialog.h index 594df6fab..3d199fe98 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.h +++ b/retroshare-gui/src/gui/SharedFilesDialog.h @@ -94,10 +94,10 @@ protected: Ui::SharedFilesDialog ui; virtual void processSettings(bool bLoad) = 0; - void recursRestoreExpandedItems(const QModelIndex& index,const std::string& path,const std::set& exp); - void recursSaveExpandedItems(const QModelIndex& index, const std::string &path, std::set &exp); - void saveExpandedPaths(std::set& paths) ; - void restoreExpandedPaths(const std::set& paths) ; + 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) ; protected: //now context menu are created again every time theu are called ( in some