Merge pull request #1008 from PhenomRetroShare/Add_FilterInDownloadList

Add a filter to DownLoad list
This commit is contained in:
csoler 2017-09-05 20:46:05 +02:00 committed by GitHub
commit 671b418c81
3 changed files with 146 additions and 126 deletions

View file

@ -19,19 +19,21 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
****************************************************************/ ****************************************************************/
#include <QMenu>
#include <QInputDialog>
#include <QFileDialog>
#include <QStandardItemModel>
#include <QTreeView>
#include <QShortcut>
#include <QFileInfo>
#include <QDateTime> #include <QDateTime>
#include <QDir> #include <QDir>
#include <QFileDialog>
#include <QFileInfo>
#include <QHeaderView>
#include <QInputDialog>
#include <QMenu>
#include <QMessageBox> #include <QMessageBox>
#include <gui/common/RsUrlHandler.h> #include <QShortcut>
#include <gui/common/RsCollectionFile.h> #include <QStandardItemModel>
#include <gui/common/FilesDefs.h> #include <gui/common/FilesDefs.h>
#include <gui/common/RsCollectionFile.h>
#include <gui/common/RsUrlHandler.h>
#include <gui/common/RSTreeView.h>
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>
@ -204,7 +206,12 @@ TransfersDialog::TransfersDialog(QWidget *parent)
DLListModel->setHeaderData(COLUMN_ID, Qt::Horizontal, tr("Hash")); DLListModel->setHeaderData(COLUMN_ID, Qt::Horizontal, tr("Hash"));
DLListModel->setHeaderData(COLUMN_LASTDL, Qt::Horizontal, tr("Last Time Seen", "i.e: Last Time Receiced Data")); DLListModel->setHeaderData(COLUMN_LASTDL, Qt::Horizontal, tr("Last Time Seen", "i.e: Last Time Receiced Data"));
DLListModel->setHeaderData(COLUMN_PATH, Qt::Horizontal, tr("Path", "i.e: Where file is saved")); DLListModel->setHeaderData(COLUMN_PATH, Qt::Horizontal, tr("Path", "i.e: Where file is saved"));
ui.downloadList->setModel(DLListModel);
DLLFilterModel = new QSortFilterProxyModel(this);
DLLFilterModel->setSourceModel( DLListModel);
DLLFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui.downloadList->setModel(DLLFilterModel);
//ui.downloadList->hideColumn(ID); //ui.downloadList->hideColumn(ID);
DLDelegate = new DLListDelegate(); DLDelegate = new DLListDelegate();
ui.downloadList->setItemDelegate(DLDelegate); ui.downloadList->setItemDelegate(DLDelegate);
@ -262,7 +269,14 @@ TransfersDialog::TransfersDialog(QWidget *parent)
// set default column and sort order for download // set default column and sort order for download
ui.downloadList->sortByColumn(COLUMN_NAME, Qt::AscendingOrder); ui.downloadList->sortByColumn(COLUMN_NAME, Qt::AscendingOrder);
connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
/* Add filter actions */
QString headerName = DLListModel->headerData(COLUMN_NAME, Qt::Horizontal).toString();
ui.filterLineEdit->addFilter(QIcon(), headerName, COLUMN_NAME , QString("%1 %2").arg(tr("Search"), headerName));
QString headerID = DLListModel->headerData(COLUMN_ID, Qt::Horizontal).toString();
ui.filterLineEdit->addFilter(QIcon(), headerID, COLUMN_ID , QString("%1 %2").arg(tr("Search"), headerID));
connect( ui.uploadsList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( uploadsListCustomPopupMenu( QPoint ) ) ); connect( ui.uploadsList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( uploadsListCustomPopupMenu( QPoint ) ) );
// Set Upload list model // Set Upload list model
@ -649,15 +663,16 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ )
{ {
add_CopyLink = true ; add_CopyLink = true ;
QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes ();
//Look for all selected items //Look for all selected items
for (int i = 0; i < lst.count(); ++i) { std::set<RsFileHash>::const_iterator it = items.begin();
std::set<RsFileHash>::const_iterator end = items.end();
for (; it != end ; ++it) {
RsFileHash fileHash = *it;
//Look only for first column == File List //Look only for first column == File List
if ( lst[i].column() == 0) { //Get Info for current item
//Get Info for current item if (rsFiles->FileDetails(fileHash
if (rsFiles->FileDetails(RsFileHash(getID(lst[i].row(), DLListModel).toStdString()) , RS_FILE_HINTS_DOWNLOAD, info)) {
, RS_FILE_HINTS_DOWNLOAD, info)) {
/*const uint32_t FT_STATE_FAILED = 0x0000; /*const uint32_t FT_STATE_FAILED = 0x0000;
*const uint32_t FT_STATE_OKAY = 0x0001; *const uint32_t FT_STATE_OKAY = 0x0001;
*const uint32_t FT_STATE_WAITING = 0x0002; *const uint32_t FT_STATE_WAITING = 0x0002;
@ -697,9 +712,8 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ )
}//if (RsCollectionFile::ExtensionString == info }//if (RsCollectionFile::ExtensionString == info
}// if(pos != std::string::npos) }// if(pos != std::string::npos)
}// if (rsFiles->FileDetails(lst[i].data(COLUMN_ID), RS_FILE_HINTS_DOWNLOAD, info)) }// if FileDetails
}// if (lst[i].column() == 0) }// for items iterate
}// for (int i = 0; i < lst.count(); ++i)
}// if (!items.empty()) }// if (!items.empty())
if (atLeastOne_Waiting || atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Paused) { if (atLeastOne_Waiting || atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Paused) {
@ -779,7 +793,7 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ )
contextMnu.addSeparator() ;//-------------------------------------------- contextMnu.addSeparator() ;//--------------------------------------------
}//if (add_CopyLink || add_PasteLink) }//if (add_CopyLink || add_PasteLink)
if (DLListModel->rowCount()>0 ) { if (DLLFilterModel->rowCount()>0 ) {
contextMnu.addAction( expandAllAct ) ; contextMnu.addAction( expandAllAct ) ;
contextMnu.addAction( collapseAllAct ) ; contextMnu.addAction( collapseAllAct ) ;
} }
@ -1372,10 +1386,10 @@ void TransfersDialog::insertTransfers()
ui.uploadsList->setSortingEnabled(true); ui.uploadsList->setSortingEnabled(true);
downloads = tr("Downloads") + " (" + QString::number(DLListModel->rowCount()) + ")"; downloads = tr("Downloads") + " (" + QString::number(DLListModel->rowCount()) + ")";
uploads = tr("Uploads") + " (" + QString::number(ULListModel->rowCount()) + ")" ; uploads = tr("Uploads") + " (" + QString::number(ULListModel->rowCount()) + ")" ;
ui.tabWidget->setTabText(0, downloads); ui.tabWidget->setTabText(0, downloads);
ui.tabWidget_2->setTabText(0, uploads); ui.tabWidget_UL->setTabText(0, uploads);
} }
@ -1512,18 +1526,11 @@ void TransfersDialog::showDetailsDialog()
void TransfersDialog::updateDetailsDialog() void TransfersDialog::updateDetailsDialog()
{ {
RsFileHash file_hash ; std::set<RsFileHash> items;
std::set<int> rows; getSelectedItems(&items, NULL);
std::set<int>::iterator it;
getSelectedItems(NULL, &rows);
if (rows.size()) { if (!items.empty())
int row = *rows.begin(); detailsDialog()->setFileHash(*items.begin());
file_hash = RsFileHash(getID(row, DLListModel).toStdString());
}
detailsDialog()->setFileHash(file_hash);
} }
void TransfersDialog::pasteLink() void TransfersDialog::pasteLink()
@ -1540,39 +1547,23 @@ void TransfersDialog::getSelectedItems(std::set<RsFileHash> *ids, std::set<int>
if (ids) ids->clear(); if (ids) ids->clear();
if (rows) rows->clear(); if (rows) rows->clear();
int i, imax = DLListModel->rowCount(); QModelIndexList selectedRows = selection->selectedRows(COLUMN_ID);
int i, imax = selectedRows.count();
for (i = 0; i < imax; ++i) { for (i = 0; i < imax; ++i) {
bool isParentSelected = false; QModelIndex index = selectedRows.at(i);
bool isChildSelected = false; if (index.parent().isValid())
index = index.model()->index(index.parent().row(), COLUMN_ID);
QStandardItem *parent = DLListModel->item(i); if (ids) {
if (!parent) continue; ids->insert(RsFileHash(index.data(Qt::DisplayRole).toString().toStdString()));
QModelIndex pindex = parent->index(); ids->insert(RsFileHash(index.data(Qt::UserRole ).toString().toStdString()));
if (selection->isSelected(pindex)) {
isParentSelected = true;
} else {
int j, jmax = parent->rowCount();
for (j = 0; j < jmax && !isChildSelected; ++j) {
QStandardItem *child = parent->child(j);
if (!child) continue;
QModelIndex cindex = child->index();
if (selection->isSelected(cindex)) {
isChildSelected = true;
}
}
} }
/* if transfered file or it's peers are selected control it*/ if (rows) {
if (isParentSelected || isChildSelected) { rows->insert(index.row());
if (ids) {
QStandardItem *id = DLListModel->item(i, COLUMN_ID);
ids->insert(RsFileHash(id->data(Qt::DisplayRole).toString().toStdString()));
ids->insert(RsFileHash(id->data(Qt::UserRole ).toString().toStdString()));
}
if (rows) {
rows->insert(i);
}
} }
} }
} }
@ -1945,20 +1936,13 @@ void TransfersDialog::clearcompleted()
void TransfersDialog::showFileDetails() void TransfersDialog::showFileDetails()
{ {
RsFileHash file_hash ; std::set<RsFileHash> items ;
int nb_select = 0 ; getSelectedItems(&items, NULL) ;
if(items.size() != 1)
for(int i = 0; i <= DLListModel->rowCount(); ++i) detailsDialog()->setFileHash(RsFileHash());
if(selection->isRowSelected(i, QModelIndex()))
{
file_hash = RsFileHash(getID(i, DLListModel).toStdString());
++nb_select ;
}
if(nb_select != 1)
detailsDialog()->setFileHash(RsFileHash()) ;
else else
detailsDialog()->setFileHash(file_hash) ; detailsDialog()->setFileHash(*items.begin()) ;
updateDetailsDialog (); updateDetailsDialog ();
} }
@ -1988,6 +1972,13 @@ QString TransfersDialog::getID(int row, QStandardItemModel *model)
return model->data(model->index(row, COLUMN_ID), Qt::UserRole).toString().left(40); // gets only the "hash" part of the name return model->data(model->index(row, COLUMN_ID), Qt::UserRole).toString().left(40); // gets only the "hash" part of the name
} }
QString TransfersDialog::getID(int row, QSortFilterProxyModel *filter)
{
QModelIndex index = filter->mapToSource(filter->index(row, COLUMN_ID));
return filter->sourceModel()->data(index, Qt::UserRole).toString().left(40); // gets only the "hash" part of the name
}
QString TransfersDialog::getPriority(int row, QStandardItemModel *model) QString TransfersDialog::getPriority(int row, QStandardItemModel *model)
{ {
return model->data(model->index(row, COLUMN_PRIORITY), Qt::DisplayRole).toString(); return model->data(model->index(row, COLUMN_PRIORITY), Qt::DisplayRole).toString();
@ -2250,3 +2241,11 @@ void TransfersDialog::collapseAll()
{ {
ui.downloadList->collapseAll(); ui.downloadList->collapseAll();
} }
void TransfersDialog::filterChanged(const QString& /*text*/)
{
int filterColumn = ui.filterLineEdit->currentFilter();
QString text = ui.filterLineEdit->text();
DLLFilterModel->setFilterKeyColumn(filterColumn);
DLLFilterModel->setFilterRegExp(text);
}

View file

@ -29,6 +29,9 @@
#include "ui_TransfersDialog.h" #include "ui_TransfersDialog.h"
#include <QItemSelectionModel>
#include <QSortFilterProxyModel>
#define IMAGE_TRANSFERS ":/icons/ktorrent_128.png" #define IMAGE_TRANSFERS ":/icons/ktorrent_128.png"
class QShortcut; class QShortcut;
@ -153,6 +156,8 @@ private slots:
void setShowDLLastDLColumn(bool show); void setShowDLLastDLColumn(bool show);
void setShowDLPath(bool show); void setShowDLPath(bool show);
void filterChanged(const QString &text);
signals: signals:
void playFiles(QStringList files); void playFiles(QStringList files);
@ -160,6 +165,7 @@ private:
QString getPeerName(const RsPeerId &peer_id) const ; QString getPeerName(const RsPeerId &peer_id) const ;
QStandardItemModel *DLListModel; QStandardItemModel *DLListModel;
QSortFilterProxyModel *DLLFilterModel;
QStandardItemModel *ULListModel; QStandardItemModel *ULListModel;
QItemSelectionModel *selection; QItemSelectionModel *selection;
QItemSelectionModel *selectionUp; QItemSelectionModel *selectionUp;
@ -263,6 +269,7 @@ public slots:
QString getFileName(int row, QStandardItemModel *model); QString getFileName(int row, QStandardItemModel *model);
QString getStatus(int row, QStandardItemModel *model); QString getStatus(int row, QStandardItemModel *model);
QString getID(int row, QStandardItemModel *model); QString getID(int row, QStandardItemModel *model);
QString getID(int row, QSortFilterProxyModel *filter);
QString getPriority(int row, QStandardItemModel *model); QString getPriority(int row, QStandardItemModel *model);
qlonglong getFileSize(int row, QStandardItemModel *model); qlonglong getFileSize(int row, QStandardItemModel *model);
qlonglong getTransfered(int row, QStandardItemModel *model); qlonglong getTransfered(int row, QStandardItemModel *model);

View file

@ -10,7 +10,7 @@
<height>353</height> <height>353</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="TransfersDialogVLayout">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -37,7 +37,7 @@
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Sunken</enum> <enum>QFrame::Sunken</enum>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="titleBarFrameHLayout">
<property name="leftMargin"> <property name="leftMargin">
<number>2</number> <number>2</number>
</property> </property>
@ -77,7 +77,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<spacer> <spacer name="titleBarHSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -137,7 +137,7 @@
<attribute name="title"> <attribute name="title">
<string>Downloads</string> <string>Downloads</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="tabGLayout">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -173,51 +173,60 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<widget class="QTreeView" name="downloadList"> <widget class="QWidget" name="dwloadsTab">
<property name="mouseTracking"> <layout class="QGridLayout" name="dwloadsTabGLayout">
<bool>true</bool> <item row="0" column="0">
</property> <widget class="LineEditClear" name="filterLineEdit"/>
<property name="contextMenuPolicy"> </item>
<enum>Qt::CustomContextMenu</enum> <item row="1" column="0">
</property> <widget class="QTreeView" name="downloadList">
<property name="editTriggers"> <property name="mouseTracking">
<set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set> <bool>true</bool>
</property> </property>
<property name="tabKeyNavigation"> <property name="contextMenuPolicy">
<bool>false</bool> <enum>Qt::CustomContextMenu</enum>
</property> </property>
<property name="showDropIndicator" stdset="0"> <property name="editTriggers">
<bool>false</bool> <set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
</property> </property>
<property name="dragEnabled"> <property name="tabKeyNavigation">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="dragDropMode"> <property name="showDropIndicator" stdset="0">
<enum>QAbstractItemView::NoDragDrop</enum> <bool>false</bool>
</property> </property>
<property name="alternatingRowColors"> <property name="dragEnabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="rootIsDecorated"> <property name="dragDropMode">
<bool>true</bool> <enum>QAbstractItemView::NoDragDrop</enum>
</property> </property>
<property name="uniformRowHeights"> <property name="alternatingRowColors">
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="sortingEnabled"> <property name="rootIsDecorated">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="allColumnsShowFocus"> <property name="uniformRowHeights">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="wordWrap"> <property name="sortingEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<attribute name="headerStretchLastSection"> <property name="allColumnsShowFocus">
<bool>false</bool> <bool>false</bool>
</attribute> </property>
<property name="wordWrap">
<bool>true</bool>
</property>
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget> </widget>
<widget class="QTabWidget" name="tabWidget_2"> <widget class="QTabWidget" name="tabWidget_UL">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
@ -250,7 +259,7 @@
<attribute name="title"> <attribute name="title">
<string>Uploads</string> <string>Uploads</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="uploadsTabGLayout">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -290,6 +299,11 @@
<extends>QLabel</extends> <extends>QLabel</extends>
<header>gui/common/StyledLabel.h</header> <header>gui/common/StyledLabel.h</header>
</customwidget> </customwidget>
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header location="global">gui/common/LineEditClear.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../images.qrc"/> <include location="../images.qrc"/>