Added Search Filter for Network

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3089 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2010-06-09 10:29:34 +00:00
parent 79010a15f7
commit 6d8c846726
3 changed files with 259 additions and 65 deletions

View File

@ -65,6 +65,20 @@
#define IMAGE_DENIED ":/images/denied16.png"
#define IMAGE_TRUSTED ":/images/rs-2.png"
#define COLUMN_PEERNAME 1
#define COLUMN_PEERID 4
static int FilterColumnFromComboBox(int nIndex)
{
switch (nIndex) {
case 0:
return COLUMN_PEERNAME;
case 1:
return COLUMN_PEERID;
}
return COLUMN_PEERNAME;
}
RsCertId getNeighRsCertId(QTreeWidgetItem *i);
@ -84,9 +98,13 @@ NetworkDialog::NetworkDialog(QWidget *parent)
connect( ui.unvalidGPGkeyWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( connecttreeWidgetCostumPopupMenu( QPoint ) ) );
connect( ui.unvalidGPGkeyWidget, SIGNAL( itemSelectionChanged()), ui.connecttreeWidget, SLOT( clearSelection() ) );
connect(ui.infoLog, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayInfoLogMenu(const QPoint&)));
connect( ui.infoLog, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayInfoLogMenu(const QPoint&)));
connect( ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged()));
connect( ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterColumnChanged()));
connect( ui.clearButton, SIGNAL(clicked()), this, SLOT(clearFilter()));
connect(ui.showUnvalidKeys, SIGNAL(clicked()), this, SLOT(insertConnect()));
connect( ui.showUnvalidKeys, SIGNAL(clicked()), this, SLOT(insertConnect()));
/* hide the Tree +/- */
@ -188,6 +206,8 @@ NetworkDialog::NetworkDialog(QWidget *parent)
ui.tabBottom->removeTab(0); //hide the logs tab
#endif
ui.clearButton->hide();
/* Hide platform specific features */
#ifdef Q_WS_WIN
@ -202,18 +222,18 @@ void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint point )
if (!wi)
return;
QMenu contextMnu( this );
QMenu contextMnu( this );
std::string peer_id = wi->text(4).toStdString() ;
std::string peer_id = wi->text(4).toStdString() ;
// That's what context menus are made for
// That's what context menus are made for
RsPeerDetails detail;
if(!rsPeers->getGPGDetails(peer_id, detail)) // that is not suppose to fail.
if(!rsPeers->getGPGDetails(peer_id, detail)) // that is not suppose to fail.
return ;
if(peer_id != rsPeers->getGPGOwnId())
if(peer_id != rsPeers->getGPGOwnId())
{
if(detail.accept_connection)
if(detail.accept_connection)
{
denyFriendAct = new QAction(QIcon(IMAGE_DENIED), tr( "Deny friend" ), this );
@ -237,7 +257,7 @@ void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint point )
#endif
}
}
if ( peer_id == rsPeers->getGPGOwnId())
if ( peer_id == rsPeers->getGPGOwnId())
{
exportcertAct = new QAction(QIcon(IMAGE_EXPIORT), tr( "Export my Cert" ), this );
connect( exportcertAct , SIGNAL( triggered() ), this, SLOT( on_actionExportKey_activated() ) );
@ -346,12 +366,14 @@ void NetworkDialog::insertConnect()
return;
}
std::list<std::string> neighs; //these are GPG ids
std::list<std::string> neighs; //these are GPG ids
std::list<std::string>::iterator it;
rsPeers->getGPGAllList(neighs);
rsPeers->getGPGAllList(neighs);
int nFilterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex());
/* get a link to the table */
QTreeWidget *connectWidget = ui.connecttreeWidget;
QTreeWidget *connectWidget = ui.connecttreeWidget;
//remove items
int index = 0;
@ -410,10 +432,10 @@ void NetworkDialog::insertConnect()
item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
/* (1) Person */
item -> setText(1, QString::fromStdString(detail.name));
item -> setText(COLUMN_PEERNAME, QString::fromStdString(detail.name));
/* (4) key id */
item -> setText(4, QString::fromStdString(detail.id));
item -> setText(COLUMN_PEERID, QString::fromStdString(detail.id));
}
}
@ -438,45 +460,53 @@ void NetworkDialog::insertConnect()
*/
QColor backgrndcolor;
if (detail.accept_connection)
if (detail.accept_connection)
{
if (detail.ownsign) {
item -> setText(0, "0");
item -> setIcon(0,(QIcon(IMAGE_AUTHED)));
backgrndcolor=QColor("#45ff45");//bright green
} else {
item -> setText(0, "0");
item -> setIcon(0,(QIcon(IMAGE_AUTHED)));
backgrndcolor=QColor("#43C043");//light green
}
} else {
item -> setText(0, "1");
if (detail.hasSignedMe)
if (detail.ownsign)
{
backgrndcolor=QColor("#42B2B2"); //kind of darkCyan
item -> setIcon(0,(QIcon(IMAGE_DENIED)));
item -> setText(0, "0");
item -> setIcon(0,(QIcon(IMAGE_AUTHED)));
backgrndcolor=QColor("#45ff45");//bright green
}
else
{
item -> setText(0, "0");
item -> setIcon(0,(QIcon(IMAGE_AUTHED)));
backgrndcolor=QColor("#43C043");//light green
}
}
else
{
item -> setText(0, "1");
if (detail.hasSignedMe)
{
backgrndcolor=QColor("#42B2B2"); //kind of darkCyan
item -> setIcon(0,(QIcon(IMAGE_DENIED)));
for(int k=0;k<8;++k)
item -> setToolTip(k,QString::fromStdString(detail.name) + QString(tr(" has authenticated you. \nRight-click and select 'make friend' to be able to connect."))) ;
item -> setToolTip(k,QString::fromStdString(detail.name) + QString(tr(" has authenticated you. \nRight-click and select 'make friend' to be able to connect."))) ;
}
else
{
backgrndcolor=Qt::lightGray;
backgrndcolor=Qt::lightGray;
item -> setIcon(0,(QIcon(IMAGE_DENIED)));
}
}
// Color each Background column in the Network Tab except the first one => 1-9
// whith the determinated color
for(int i = 0; i <10; i++)
for(int i = 0; i <10; i++)
item -> setBackground(i,QBrush(backgrndcolor));
/* add to the list */
if (detail.accept_connection || detail.validLvl >= 3) {
/* add gpg item to the list. If item is already in the list, it won't be duplicated thanks to Qt */
connectWidget->addTopLevelItem(item);
} else {
ui.unvalidGPGkeyWidget->addTopLevelItem(item);
}
if (detail.accept_connection || detail.validLvl >= 3)
{
/* add gpg item to the list. If item is already in the list, it won't be duplicated thanks to Qt */
connectWidget->addTopLevelItem(item);
}
else
{
ui.unvalidGPGkeyWidget->addTopLevelItem(item);
}
}
@ -494,9 +524,9 @@ void NetworkDialog::insertConnect()
}
self_item -> setText(0, "0");
self_item->setIcon(0,(QIcon(IMAGE_AUTHED)));
self_item->setText(1,QString::fromStdString(ownGPGDetails.name) + " (yourself)") ;
self_item->setText(COLUMN_PEERNAME,QString::fromStdString(ownGPGDetails.name) + " (yourself)") ;
self_item->setText(2,"N/A");
self_item->setText(4, QString::fromStdString(ownGPGDetails.id));
self_item->setText(COLUMN_PEERID, QString::fromStdString(ownGPGDetails.id));
// Color each Background column in the Network Tab except the first one => 1-9
for(int i=0;i<10;++i)
@ -512,6 +542,10 @@ void NetworkDialog::insertConnect()
}
connectWidget->update(); /* update display */
ui.unvalidGPGkeyWidget->update(); /* update display */
if (ui.filterPatternLineEdit->text().isEmpty() == false) {
FilterItems();
}
}
@ -873,3 +907,71 @@ void NetworkDialog::loadtabsettings()
Settings->endGroup();
}
/* clear Filter */
void NetworkDialog::clearFilter()
{
ui.filterPatternLineEdit->clear();
ui.filterPatternLineEdit->setFocus();
}
void NetworkDialog::filterRegExpChanged()
{
QString text = ui.filterPatternLineEdit->text();
if (text.isEmpty()) {
ui.clearButton->hide();
} else {
ui.clearButton->show();
}
FilterItems();
}
void NetworkDialog::filterColumnChanged()
{
int nFilterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex());
FilterItems();
}
void NetworkDialog::FilterItems()
{
QString sPattern = ui.filterPatternLineEdit->text();
int nFilterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex());
int nCount = ui.connecttreeWidget->topLevelItemCount ();
for (int nIndex = 0; nIndex < nCount; nIndex++) {
FilterItem(ui.connecttreeWidget->topLevelItem(nIndex), sPattern, nFilterColumn);
}
}
bool NetworkDialog::FilterItem(QTreeWidgetItem *pItem, QString &sPattern, int nFilterColumn)
{
bool bVisible = true;
if (sPattern.isEmpty() == false) {
if (pItem->text(nFilterColumn).contains(sPattern, Qt::CaseInsensitive) == false) {
bVisible = false;
}
}
int nVisibleChildCount = 0;
int nCount = pItem->childCount();
for (int nIndex = 0; nIndex < nCount; nIndex++) {
if (FilterItem(pItem->child(nIndex), sPattern, nFilterColumn)) {
nVisibleChildCount++;
}
}
if (bVisible || nVisibleChildCount) {
pItem->setHidden(false);
} else {
pItem->setHidden(true);
}
return (bVisible || nVisibleChildCount);
}

View File

@ -86,7 +86,10 @@ private slots:
void on_actionTabsRounded_activated();
void on_actionTabsTriangular_activated();
void filterColumnChanged();
void filterRegExpChanged();
void clearFilter();
private:
QTreeWidgetItem *getCurrentNeighbour();
@ -103,6 +106,9 @@ private:
QTreeWidget *connecttreeWidget;
class NetworkView *networkview;
void FilterItems();
bool FilterItem(QTreeWidgetItem *pItem, QString &sPattern, int nFilterColumn);
/** Qt Designer generated object */
Ui::NetworkDialog ui;

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>555</width>
<width>629</width>
<height>444</height>
</rect>
</property>
@ -146,14 +146,11 @@ stop:0 #FEFEFE, stop:1 #E8E8E8);
border: 1px solid #CCCCCC;}</string>
</property>
<layout class="QGridLayout">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="margin">
<number>1</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<item>
<widget class="QLabel" name="label">
<property name="maximumSize">
<size>
@ -172,7 +169,7 @@ border: 1px solid #CCCCCC;}</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
@ -185,24 +182,120 @@ border: 1px solid #CCCCCC;}</string>
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Arial'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Network:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Network&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="sizeHint" stdset="0">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="images.qrc">:/images/find-16.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="filterPatternLineEdit">
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;Search Network&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearButton">
<property name="minimumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="font">
<font>
<family>MS Shell Dlg 2</family>
</font>
</property>
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;Clear Filter&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="styleSheet">
<string notr="true">QPushButton
{
border-image: url(:/images/closenormal.png)
}
QPushButton:hover
{
border-image: url(:/images/closehover.png)
}
QPushButton:pressed {
border-image: url(:/images/closepressed.png)
}</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QComboBox" name="filterColumnComboBox">
<property name="minimumSize">
<size>
<width>40</width>
<height>20</height>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
<property name="font">
<font>
<family>MS Shell Dlg 2</family>
</font>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>Name</string>
</property>
</item>
<item>
<property name="text">
<string>Peer ID</string>
</property>
</item>
</widget>
</item>
<item row="0" column="4">
<item>
<widget class="QCheckBox" name="showUnvalidKeys">
<property name="text">
<string>Show keys that are not validated by the GPG web of trust</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="viewButton">
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
@ -234,13 +327,6 @@ subcontrol-position: bottom right;
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="showUnvalidKeys">
<property name="text">
<string>Show keys that are not validated by the GPG web of trust</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>