Added filter for files in SharedFilesDialog.

It is hidden for the release version (RS_RELEASE_VERSION), because the RemoteDirModel is slow with many files.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3882 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-11-30 12:29:04 +00:00
parent 73f22ad897
commit bd319d2357
5 changed files with 1122 additions and 905 deletions

View File

@ -149,6 +149,11 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
connect( localModel, SIGNAL( layoutAboutToBeChanged() ), ui.localDirTreeView, SLOT( reset() ) );
connect( localModel, SIGNAL( layoutChanged() ), ui.localDirTreeView, SLOT( update() ) );
connect(ui.filterClearButton, SIGNAL(clicked()), this, SLOT(clearFilter()));
connect(ui.filterStartButton, SIGNAL(clicked()), this, SLOT(startFilter()));
connect(ui.filterPatternLineEdit, SIGNAL(returnPressed()), this, SLOT(startFilter()));
connect(ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged()));
/* Set header resize modes and initial section sizes */
QHeaderView * l_header = ui.localDirTreeView->header () ;
// l_header->setResizeMode (0, QHeaderView::Interactive);
@ -189,6 +194,13 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
ui.remoteDirTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
ui.localDirTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
#ifdef RS_RELEASE_VERSION
ui.filterLabel->hide();
ui.filterPatternLineEdit->hide();
#endif
ui.filterStartButton->hide();
ui.filterClearButton->hide();
// load settings
processSettings(true);
@ -631,6 +643,10 @@ void SharedFilesDialog::postModDirectories(bool update_local)
{
model->postMods();
ui.remoteDirTreeView->update() ;
if (ui.filterPatternLineEdit->text().isEmpty() == false) {
FilterItems();
}
}
QCoreApplication::flush();
@ -817,3 +833,84 @@ void SharedFilesDialog::indicatorChanged(int index)
updateDisplay() ;
}
void SharedFilesDialog::filterRegExpChanged()
{
QString text = ui.filterPatternLineEdit->text();
if (text.isEmpty()) {
ui.filterClearButton->hide();
} else {
ui.filterClearButton->show();
}
if (text == lastFilterString) {
ui.filterStartButton->hide();
} else {
ui.filterStartButton->show();
}
}
/* clear Filter */
void SharedFilesDialog::clearFilter()
{
ui.filterPatternLineEdit->clear();
ui.filterPatternLineEdit->setFocus();
startFilter();
}
/* clear Filter */
void SharedFilesDialog::startFilter()
{
ui.filterStartButton->hide();
lastFilterString = ui.filterPatternLineEdit->text();
FilterItems();
}
void SharedFilesDialog::FilterItems()
{
QString text = ui.filterPatternLineEdit->text();
setCursor(Qt::WaitCursor);
int rowCount = ui.remoteDirTreeView->model()->rowCount();
for (int row = 0; row < rowCount; row++) {
/* Filter name */
FilterItem(ui.remoteDirTreeView->model()->index(row, 0), text, 0);
}
setCursor(Qt::ArrowCursor);
}
bool SharedFilesDialog::FilterItem(const QModelIndex &index, const QString &text, int level)
{
bool visible = true;
if (text.isEmpty() == false) {
// better use RemoteDirModel::getType, but its slow enough
if (/*index.parent().isValid()*/ level >= 1) {
if (index.data(RemoteDirModel::FileNameRole).toString().contains(text, Qt::CaseInsensitive) == false) {
visible = false;
}
} else {
visible = false;
}
}
int visibleChildCount = 0;
int rowCount = ui.remoteDirTreeView->model()->rowCount(index);
for (int row = 0; row < rowCount; row++) {
if (FilterItem(ui.remoteDirTreeView->model()->index(row, index.column(), index), text, level + 1)) {
visibleChildCount++;
}
}
if (visible || visibleChildCount) {
ui.remoteDirTreeView->setRowHidden(index.row(), index.parent(), false);
} else {
ui.remoteDirTreeView->setRowHidden(index.row(), index.parent(), true);
}
return (visible || visibleChildCount);
}

View File

@ -83,6 +83,10 @@ private slots:
void indicatorChanged(int index);
void filterRegExpChanged();
void clearFilter();
void startFilter();
signals:
void playFiles(QStringList files);
@ -96,7 +100,10 @@ private:
void processSettings(bool bLoad);
void copyLink (const QModelIndexList& lst, bool remote);
void copyLink (const QModelIndexList& lst, bool remote);
void FilterItems();
bool FilterItem(const QModelIndex &index, const QString &text, int level);
QModelIndexList getRemoteSelected();
QModelIndexList getLocalSelected();
@ -115,7 +122,6 @@ private:
QAction* sendchatlinkAct;
QAction* copylinklocalhtmlAct;
/** Qt Designer generated object */
Ui::SharedFilesDialog ui;
@ -128,6 +134,8 @@ private:
QString currentCommand;
QString currentFile;
QString lastFilterString;
QAction* fileAssotiationAction(const QString fileName);
};

File diff suppressed because it is too large Load Diff

View File

@ -2290,7 +2290,7 @@ p, li { white-space: pre-wrap; }
<translation>Zusätzlich eine Datei hinzufügen</translation>
</message>
<message>
<location line="+26"/>
<location line="+29"/>
<location line="+202"/>
<source>RetroShare</source>
<translation></translation>
@ -8329,7 +8329,7 @@ Do you want to send them a Message instead</source>
<context>
<name>ProfileView</name>
<message>
<location filename="../gui/profile/ProfileView.cpp" line="+72"/>
<location filename="../gui/profile/ProfileView.cpp" line="+70"/>
<source>Clear Photo</source>
<translation>Photo entfernen</translation>
</message>
@ -9981,13 +9981,13 @@ p, li { white-space: pre-wrap; }
<context>
<name>SharedFilesDialog</name>
<message>
<location filename="../gui/SharedFilesDialog.ui" line="+846"/>
<location filename="../gui/SharedFilesDialog.cpp" line="+293"/>
<location filename="../gui/SharedFilesDialog.ui" line="+943"/>
<location filename="../gui/SharedFilesDialog.cpp" line="+305"/>
<source>Download</source>
<translation>Herunterladen</translation>
</message>
<message>
<location line="-250"/>
<location line="-347"/>
<source>Splitted View</source>
<translation>Geteiltes Fenster</translation>
</message>
@ -10035,28 +10035,43 @@ p, li { white-space: pre-wrap; }
<translation>Einen Monat alt</translation>
</message>
<message>
<location line="+165"/>
<location line="+27"/>
<source>Search files</source>
<translation>Suche Dateien</translation>
</message>
<message>
<location line="+24"/>
<source>Start Search</source>
<translation>Starte Suche</translation>
</message>
<message>
<location line="+31"/>
<source>Reset</source>
<translation>Zurücksetzen</translation>
</message>
<message>
<location line="+180"/>
<source>check files</source>
<translation>Prüfe Dateien</translation>
</message>
<message>
<location filename="../gui/SharedFilesDialog.cpp" line="-80"/>
<location line="+492"/>
<location line="+496"/>
<source>Open File</source>
<translation>Datei öffnen</translation>
</message>
<message>
<location line="-490"/>
<location line="-494"/>
<source>Open Folder</source>
<translation>Ordner öffnen</translation>
</message>
<message>
<location line="+499"/>
<location line="+503"/>
<source>Set command for opening this file</source>
<translation>Setze eine Regel zum Öffnen dieser Datei</translation>
</message>
<message>
<location line="-416"/>
<location line="-420"/>
<source>Copy retroshare Link</source>
<translation>Kopiere RetroShare Link</translation>
</message>
@ -10107,12 +10122,12 @@ p, li { white-space: pre-wrap; }
</message>
<message>
<location line="+98"/>
<location line="+376"/>
<location line="+380"/>
<source>Recommend in a message to</source>
<translation>Empfehle in einer Nachricht an</translation>
</message>
<message>
<location line="-250"/>
<location line="-254"/>
<location line="+23"/>
<location line="+24"/>
<source>RetroShare Link</source>
@ -10127,7 +10142,7 @@ p, li { white-space: pre-wrap; }
<translation>Empfehlung(en)</translation>
</message>
<message>
<location line="+188"/>
<location line="+192"/>
<source>&lt;strong&gt;My Shared Files&lt;/strong&gt;</source>
<translation>&lt;strong&gt;Meine Dateien&lt;/strong&gt;</translation>
</message>
@ -10672,7 +10687,7 @@ p, li { white-space: pre-wrap; }
</message>
<message>
<location line="+26"/>
<location filename="../gui/feeds/SubFileItem.cpp" line="+578"/>
<location filename="../gui/feeds/SubFileItem.cpp" line="+576"/>
<location line="+6"/>
<source>Play File</source>
<translation>Datei abspielen</translation>