added checkbox to hide offline peers in permission matrix (modified patch from sehraf)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8180 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
electron128 2015-04-28 13:57:02 +00:00
parent f659ba71e5
commit bb2f131464
4 changed files with 48 additions and 29 deletions

View File

@ -32,6 +32,7 @@
#include <QMouseEvent>
#include "RSPermissionMatrixWidget.h"
#include "gui/settings/ServicePermissionsPage.h"
#include <retroshare/rsstatus.h>
#include <retroshare/rspeers.h>
#include <retroshare/rsservicecontrol.h>
@ -176,37 +177,13 @@ RSPermissionMatrixWidget::~RSPermissionMatrixWidget()
delete _painter;
}
bool sortRsPeerIdByStatusNameLocation(const RsPeerId &a, const RsPeerId &b)
bool sortRsPeerIdByNameLocation(const RsPeerId &a, const RsPeerId &b)
{
RsPeerDetails detailsA, detailsB;
rsPeers->getPeerDetails(a, detailsA);
rsPeers->getPeerDetails(b, detailsB);
QString stringA, stringB;
// connection state
switch (detailsA.connectState) {
case RS_PEER_CONNECTSTATE_CONNECTED_TCP:
case RS_PEER_CONNECTSTATE_CONNECTED_TOR:
case RS_PEER_CONNECTSTATE_CONNECTED_UDP:
case RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN:
stringA = "a";
break;
default:
stringA = "b";
break;
}
switch (detailsB.connectState) {
case RS_PEER_CONNECTSTATE_CONNECTED_TCP:
case RS_PEER_CONNECTSTATE_CONNECTED_TOR:
case RS_PEER_CONNECTSTATE_CONNECTED_UDP:
case RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN:
stringB = "a";
break;
default:
stringB = "b";
break;
}
// name
stringA += QString::fromUtf8(detailsA.name.c_str());
stringB += QString::fromUtf8(detailsB.name.c_str());
@ -241,7 +218,35 @@ void RSPermissionMatrixWidget::paintEvent(QPaintEvent *)
// draw one line per friend.
std::list<RsPeerId> ssllist ;
rsPeers->getFriendList(ssllist) ;
ssllist.sort(sortRsPeerIdByStatusNameLocation);
// sort list
{
// RSPermissionMatrixWidgets parent is ServicePermissionsPage which holds the checkbox
ServicePermissionsPage *spp = dynamic_cast<ServicePermissionsPage*>(parentWidget());
if(spp != NULL) {
// sort out offline peers
if(spp->isHideOfflineChecked()) {
RsPeerDetails peerDetails;
for(std::list<RsPeerId>::iterator it = ssllist.begin(); it != ssllist.end();) {
rsPeers->getPeerDetails(*it, peerDetails);
switch (peerDetails.connectState) {
case RS_PEER_CONNECTSTATE_OFFLINE:
case RS_PEER_CONNECTSTATE_TRYING_TCP:
case RS_PEER_CONNECTSTATE_TRYING_UDP:
it = ssllist.erase(it);
break;
default:
it++;
break;
}
}
}
}
// sort by name
ssllist.sort(sortRsPeerIdByNameLocation);
}
RsPeerServiceInfo ownServices;
rsServiceControl->getOwnServices(ownServices);

View File

@ -25,8 +25,6 @@
#include <retroshare/rspeers.h>
#include <retroshare/rsservicecontrol.h>
//#include <retroshare/rsservicecontrol.h>
#include <iostream>
#include <QTimer>
@ -34,7 +32,7 @@
#define ServiceIdUserRole (Qt::UserRole + 1)
#define PeerIdUserRole (Qt::UserRole + 2)
ServicePermissionsPage::ServicePermissionsPage(QWidget * parent, Qt::WindowFlags flags)
ServicePermissionsPage::ServicePermissionsPage(QWidget * parent, Qt::WindowFlags /*flags*/)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
@ -60,5 +58,9 @@ QString ServicePermissionsPage::helpText() const
stop all anonymous transfer, distant chat and distant messaging.</p>");
}
bool ServicePermissionsPage::isHideOfflineChecked()
{
return ui.cb_hideOffline->checkState() == Qt::Checked;
}

View File

@ -44,6 +44,8 @@ public:
virtual QString pageName() const { return tr("Permissions") ; }
virtual QString helpText() const ;
bool isHideOfflineChecked();
private:
Ui::ServicePermissionsPage ui;

View File

@ -20,6 +20,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_hideOffline">
<property name="text">
<string>hide offline</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">