mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 07:59:35 -05:00
implemented dedicated widget for service permission matrix. Permissions are not saved yet, and we also need a default switch
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7898 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
67c98187b6
commit
b2c2b7fc85
@ -1239,6 +1239,29 @@ bool RsServicePermissions::peerHasPermission(const RsPeerId &peerId) const
|
||||
}
|
||||
}
|
||||
|
||||
void RsServicePermissions::setPermission(const RsPeerId& peerId)
|
||||
{
|
||||
std::set<RsPeerId>::const_iterator it;
|
||||
if (mDefaultAllowed)
|
||||
{
|
||||
it = mPeersDenied.find(peerId);
|
||||
mPeersDenied.erase(it) ;
|
||||
}
|
||||
else
|
||||
mPeersAllowed.insert(peerId);
|
||||
}
|
||||
void RsServicePermissions::resetPermission(const RsPeerId& peerId)
|
||||
{
|
||||
std::set<RsPeerId>::const_iterator it;
|
||||
if (!mDefaultAllowed)
|
||||
{
|
||||
it = mPeersAllowed.find(peerId);
|
||||
mPeersAllowed.erase(it) ;
|
||||
}
|
||||
else
|
||||
mPeersDenied.insert(peerId);
|
||||
}
|
||||
|
||||
RsServiceInfo::RsServiceInfo(
|
||||
const uint16_t service_type,
|
||||
const std::string service_name,
|
||||
|
@ -84,7 +84,10 @@ class RsServicePermissions
|
||||
public:
|
||||
RsServicePermissions();
|
||||
|
||||
bool peerHasPermission(const RsPeerId &peerId) const;
|
||||
bool peerHasPermission(const RsPeerId &peerId) const;
|
||||
|
||||
void setPermission(const RsPeerId& peerId) ;
|
||||
void resetPermission(const RsPeerId& peerId) ;
|
||||
|
||||
uint32_t mServiceId;
|
||||
std::string mServiceName;
|
||||
|
@ -1,5 +1,10 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>images/switch.png</file>
|
||||
<file>images/switch00.png</file>
|
||||
<file>images/switch01.png</file>
|
||||
<file>images/switch10.png</file>
|
||||
<file>images/switch11.png</file>
|
||||
<file>images/add_chat24.png</file>
|
||||
<file>images/RSS_004_32.png</file>
|
||||
<file>images/mail-encrypted-full.png</file>
|
||||
|
BIN
retroshare-gui/src/gui/images/switch.png
Normal file
BIN
retroshare-gui/src/gui/images/switch.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
BIN
retroshare-gui/src/gui/images/switch00.png
Normal file
BIN
retroshare-gui/src/gui/images/switch00.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
BIN
retroshare-gui/src/gui/images/switch01.png
Normal file
BIN
retroshare-gui/src/gui/images/switch01.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
BIN
retroshare-gui/src/gui/images/switch10.png
Normal file
BIN
retroshare-gui/src/gui/images/switch10.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
BIN
retroshare-gui/src/gui/images/switch11.png
Normal file
BIN
retroshare-gui/src/gui/images/switch11.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
445
retroshare-gui/src/gui/settings/RSPermissionMatrixWidget.cpp
Normal file
445
retroshare-gui/src/gui/settings/RSPermissionMatrixWidget.cpp
Normal file
@ -0,0 +1,445 @@
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2014 RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef WINDOWS_SYS
|
||||
#include <sys/times.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <QtGlobal>
|
||||
#include <QPainter>
|
||||
#include <QDateTime>
|
||||
#include <QTimer>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "RSPermissionMatrixWidget.h"
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsservicecontrol.h>
|
||||
|
||||
#define NOT_IMPLEMENTED std::cerr << __PRETTY_FUNCTION__ << ": not yet implemented." << std::endl;
|
||||
|
||||
// The behavior of the widget is the following:
|
||||
// - when default is changed, switch all icons to the default position. Then every icon switch back by the user will be
|
||||
// in the white list.
|
||||
// - each peer/service slot has a switch. If the peer doesn't allow the service, the switch is shown with some
|
||||
// indication. When both the current and adverse permissions are granted, the switch should show it as well.
|
||||
// - we should use tooltips
|
||||
|
||||
const int RSPermissionMatrixWidget::ICON_SIZE_X = 40 ;
|
||||
const int RSPermissionMatrixWidget::ICON_SIZE_Y = 40 ;
|
||||
const int RSPermissionMatrixWidget::ROW_SIZE = 42 ;
|
||||
const int RSPermissionMatrixWidget::COL_SIZE = 42 ;
|
||||
const int RSPermissionMatrixWidget::MATRIX_START_X = 5 ;
|
||||
const int RSPermissionMatrixWidget::MATRIX_START_Y = 55 ;
|
||||
|
||||
/** Default contructor */
|
||||
RSPermissionMatrixWidget::RSPermissionMatrixWidget(QWidget *parent)
|
||||
:QFrame(parent)
|
||||
{
|
||||
_painter = new QPainter();
|
||||
|
||||
setMouseTracking(true) ;
|
||||
|
||||
//_timer = new QTimer ;
|
||||
//QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(update())) ;
|
||||
//_timer->start(1000);
|
||||
}
|
||||
|
||||
void RSPermissionMatrixWidget::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
std::cerr << "mouse pressed at x=" << e->x() << ", y=" << e->y() << std::endl;
|
||||
|
||||
uint32_t service_id ;
|
||||
RsPeerId peer_id ;
|
||||
|
||||
if(!computeServiceAndPeer(e->x(),e->y(),service_id,peer_id))
|
||||
{
|
||||
QFrame::mousePressEvent(e) ;
|
||||
return ;
|
||||
}
|
||||
|
||||
std::cerr << "Peer id: " << peer_id << ", service: " << service_id << std::endl;
|
||||
|
||||
switchPermission(service_id,peer_id) ;
|
||||
|
||||
update() ;
|
||||
}
|
||||
|
||||
void RSPermissionMatrixWidget::switchPermission(uint32_t service,const RsPeerId& pid)
|
||||
{
|
||||
RsServicePermissions serv_perms ;
|
||||
|
||||
if(!rsServiceControl->getServicePermissions(service,serv_perms))
|
||||
return ;
|
||||
|
||||
if(serv_perms.peerHasPermission(pid))
|
||||
serv_perms.resetPermission(pid) ;
|
||||
else
|
||||
serv_perms.setPermission(pid) ;
|
||||
|
||||
rsServiceControl->updateServicePermissions(service,serv_perms);
|
||||
}
|
||||
|
||||
void RSPermissionMatrixWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
uint32_t service_id ;
|
||||
RsPeerId peer_id ;
|
||||
|
||||
if(!computeServiceAndPeer(e->x(),e->y(),service_id,peer_id))
|
||||
{
|
||||
service_id = ~0 ;
|
||||
peer_id.clear() ;
|
||||
}
|
||||
|
||||
if(_current_service_id != service_id || _current_peer_id != peer_id)
|
||||
{
|
||||
_current_service_id = service_id ;
|
||||
_current_peer_id = peer_id ;
|
||||
|
||||
// redraw!
|
||||
update() ;
|
||||
}
|
||||
}
|
||||
|
||||
/** Default destructor */
|
||||
RSPermissionMatrixWidget::~RSPermissionMatrixWidget()
|
||||
{
|
||||
delete _painter;
|
||||
}
|
||||
|
||||
/** Overloads default QWidget::paintEvent. Draws the actual
|
||||
* bandwidth graph. */
|
||||
void RSPermissionMatrixWidget::paintEvent(QPaintEvent *)
|
||||
{
|
||||
//std::cerr << "In paint event!" << std::endl;
|
||||
|
||||
/* Set current graph dimensions */
|
||||
_rec = this->frameRect();
|
||||
|
||||
/* Start the painter */
|
||||
_painter->begin(this);
|
||||
|
||||
/* We want antialiased lines and text */
|
||||
_painter->setRenderHint(QPainter::Antialiasing);
|
||||
_painter->setRenderHint(QPainter::TextAntialiasing);
|
||||
|
||||
/* Fill in the background */
|
||||
_painter->fillRect(_rec, QBrush(BACK_COLOR));
|
||||
_painter->drawRect(_rec);
|
||||
|
||||
// draw one line per friend.
|
||||
std::list<RsPeerId> ssllist ;
|
||||
rsPeers->getFriendList(ssllist) ;
|
||||
|
||||
RsPeerServiceInfo ownServices;
|
||||
rsServiceControl->getOwnServices(ownServices);
|
||||
|
||||
// Display friend names at the beginning of each column
|
||||
|
||||
const QFont& font(_painter->font()) ;
|
||||
QFontMetrics fm(font);
|
||||
int peer_name_size = 0 ;
|
||||
float line_height = 2 + fm.height() ;
|
||||
|
||||
std::vector<QString> names ;
|
||||
|
||||
for(std::list<RsPeerId>::const_iterator it(ssllist.begin());it!=ssllist.end();++it)
|
||||
{
|
||||
RsPeerDetails details ;
|
||||
rsPeers->getPeerDetails(*it,details) ;
|
||||
|
||||
QString name = QString::fromUtf8(details.name.c_str());
|
||||
peer_name_size = std::max(peer_name_size, fm.width(name)) ;
|
||||
names.push_back(name) ;
|
||||
}
|
||||
|
||||
QPen pen ;
|
||||
pen.setWidth(2) ;
|
||||
pen.setBrush(Qt::black) ;
|
||||
|
||||
_painter->setPen(pen) ;
|
||||
int i=0;
|
||||
int x=5 ;
|
||||
int y=MATRIX_START_Y ;
|
||||
|
||||
for(std::list<RsPeerId>::const_iterator it(ssllist.begin());it!=ssllist.end();++it,++i)
|
||||
{
|
||||
float X = MATRIX_START_X + peer_name_size - fm.width(names[i]) ;
|
||||
float Y = MATRIX_START_Y + (i+0.5)*ROW_SIZE + line_height/2.0f-2 ;
|
||||
|
||||
_painter->drawText(QPointF(X,Y),names[i]) ;
|
||||
|
||||
if(*it == _current_peer_id)
|
||||
_painter->drawLine(QPointF(X,Y+3),QPointF(X+fm.width(names[i]),Y+3)) ;
|
||||
|
||||
y += line_height ;
|
||||
}
|
||||
|
||||
matrix_start_x = 5 + MATRIX_START_X + peer_name_size ;
|
||||
|
||||
// now draw the service names
|
||||
|
||||
i=0 ;
|
||||
std::vector<int> last_width(10,0) ;
|
||||
|
||||
for(std::map<uint32_t, RsServiceInfo>::const_iterator it(ownServices.mServiceList.begin());it!=ownServices.mServiceList.end();++it,++i)
|
||||
{
|
||||
QString name = QString::fromUtf8(it->second.mServiceName.c_str()) ;
|
||||
int text_width = fm.width(name) ;
|
||||
|
||||
int X = matrix_start_x + COL_SIZE/2 - 2 + i*COL_SIZE - text_width/2;
|
||||
|
||||
int height_index = 0 ;
|
||||
while(last_width[height_index] > X-5 && height_index < last_width.size()-1)
|
||||
++height_index ;
|
||||
|
||||
int Y = MATRIX_START_Y - 2 - line_height * height_index;
|
||||
|
||||
last_width[height_index] = X + text_width ;
|
||||
// draw a half-transparent rectangle
|
||||
|
||||
QBrush brush ;
|
||||
brush.setColor(QColor::fromHsvF(0.0f,0.0f,1.0f,0.8f));
|
||||
brush.setStyle(Qt::SolidPattern) ;
|
||||
|
||||
QPen pen ;
|
||||
pen.setWidth(2) ;
|
||||
|
||||
if(_current_service_id == it->second.mServiceType)
|
||||
pen.setBrush(Qt::black) ;
|
||||
else
|
||||
pen.setBrush(Qt::gray) ;
|
||||
|
||||
_painter->setPen(pen) ;
|
||||
|
||||
QRect info_pos( X-5,Y-line_height-2, text_width + 10, line_height + 5) ;
|
||||
|
||||
//_painter->fillRect(info_pos,brush) ;
|
||||
//_painter->drawRect(info_pos) ;
|
||||
|
||||
_painter->drawLine(QPointF(X,Y+3),QPointF(X+text_width,Y+3)) ;
|
||||
_painter->drawLine(QPointF(X+text_width/2, Y+3), QPointF(X+text_width/2,MATRIX_START_Y+5)) ;
|
||||
|
||||
pen.setBrush(Qt::black) ;
|
||||
_painter->setPen(pen) ;
|
||||
|
||||
_painter->drawText(QPointF(X,Y),name);
|
||||
}
|
||||
|
||||
// Now draw the switches.
|
||||
|
||||
peer_ids.clear() ;
|
||||
for(std::list<RsPeerId>::const_iterator it(ssllist.begin());it!=ssllist.end();++it)
|
||||
peer_ids.push_back(*it) ;
|
||||
service_ids.clear() ;
|
||||
for(std::map<uint32_t, RsServiceInfo>::const_iterator sit(ownServices.mServiceList.begin());sit!=ownServices.mServiceList.end();++sit)
|
||||
service_ids.push_back(sit->first) ;
|
||||
|
||||
// We draw for each service.
|
||||
|
||||
static const std::string pixmap_names[4] = { ":/images/switch00.png",
|
||||
":/images/switch01.png",
|
||||
":/images/switch10.png",
|
||||
":/images/switch11.png" } ;
|
||||
|
||||
int n_col = 0 ;
|
||||
int n_col_selected = -1 ;
|
||||
int n_row_selected = -1 ;
|
||||
|
||||
for(std::map<uint32_t, RsServiceInfo>::const_iterator sit(ownServices.mServiceList.begin());sit!=ownServices.mServiceList.end();++sit,++n_col)
|
||||
{
|
||||
RsServicePermissions service_perms ;
|
||||
|
||||
rsServiceControl->getServicePermissions(sit->first,service_perms) ;
|
||||
|
||||
// draw the default switch.
|
||||
|
||||
|
||||
// draw one switch per friend.
|
||||
|
||||
int n_row = 0 ;
|
||||
|
||||
for(std::list<RsPeerId>::const_iterator it(ssllist.begin());it!=ssllist.end();++it,++n_row)
|
||||
{
|
||||
RsPeerServiceInfo local_service_perms ;
|
||||
RsPeerServiceInfo remote_service_perms ;
|
||||
|
||||
rsServiceControl->getServicesAllowed (*it, local_service_perms) ;
|
||||
rsServiceControl->getServicesProvided(*it,remote_service_perms) ;
|
||||
|
||||
bool local_allowed = local_service_perms.mServiceList.find(sit->first) != local_service_perms.mServiceList.end() ;
|
||||
bool remote_allowed = remote_service_perms.mServiceList.find(sit->first) != remote_service_perms.mServiceList.end() ;
|
||||
|
||||
QPixmap pix(pixmap_names[(local_allowed << 1) + remote_allowed].c_str()) ;
|
||||
|
||||
bool selected = (sit->first == _current_service_id && *it == _current_peer_id) ;
|
||||
QRect position = computeNodePosition(n_row,n_col,selected) ;
|
||||
|
||||
if(selected)
|
||||
{
|
||||
n_row_selected = n_row ;
|
||||
n_col_selected = n_col ;
|
||||
}
|
||||
_painter->drawPixmap(position,pix,QRect(0,0,ICON_SIZE_X,ICON_SIZE_Y)) ;
|
||||
}
|
||||
}
|
||||
|
||||
// now display some info about current node.
|
||||
|
||||
if(n_row_selected < peer_ids.size() && n_col_selected < service_ids.size())
|
||||
{
|
||||
QRect position = computeNodePosition(n_row_selected,n_col_selected,false) ;
|
||||
|
||||
// draw text info
|
||||
|
||||
RsServicePermissions service_perms ;
|
||||
|
||||
rsServiceControl->getServicePermissions(service_ids[n_col_selected],service_perms) ;
|
||||
|
||||
QString service_name = tr("Service name: ")+QString::fromUtf8(service_perms.mServiceName.c_str()) ;
|
||||
QString service_default = service_perms.mDefaultAllowed?tr("Allowed by default"):tr("Denied by default");
|
||||
QString peer_name = tr("Peer name: ") + names[n_row_selected] ;
|
||||
QString peer_id = tr("Peer Id: ")+QString::fromStdString(_current_peer_id.toStdString()) ;
|
||||
|
||||
RsPeerServiceInfo pserv_info ;
|
||||
rsServiceControl->getServicesAllowed(_current_peer_id,pserv_info) ;
|
||||
|
||||
QString local_status = (pserv_info.mServiceList.find(_current_service_id) != pserv_info.mServiceList.end())?tr("Locally enabled"):tr("Locally disabled") ;
|
||||
|
||||
rsServiceControl->getServicesProvided(_current_peer_id,pserv_info) ;
|
||||
|
||||
QString remote_status = (pserv_info.mServiceList.find(_current_service_id) != pserv_info.mServiceList.end())?tr("Enabled by remote peer"):tr("Disabled by remote peer") ;
|
||||
|
||||
const QFont& font(_painter->font()) ;
|
||||
QFontMetrics fm(font);
|
||||
|
||||
int text_size_x = 0 ;
|
||||
text_size_x = std::max(text_size_x,fm.width(service_name));
|
||||
text_size_x = std::max(text_size_x,fm.width(peer_name));
|
||||
text_size_x = std::max(text_size_x,fm.width(peer_id));
|
||||
text_size_x = std::max(text_size_x,fm.width(local_status));
|
||||
text_size_x = std::max(text_size_x,fm.width(remote_status));
|
||||
|
||||
// draw a half-transparent rectangle
|
||||
|
||||
QBrush brush ;
|
||||
brush.setColor(QColor::fromHsvF(0.0f,0.0f,1.0f,0.8f));
|
||||
brush.setStyle(Qt::SolidPattern) ;
|
||||
|
||||
QPen pen ;
|
||||
pen.setWidth(2) ;
|
||||
pen.setBrush(Qt::black) ;
|
||||
|
||||
_painter->setPen(pen) ;
|
||||
|
||||
QRect info_pos( position.x() + 50, position.y() - 10, text_size_x + 10, line_height * 5 + 5) ;
|
||||
|
||||
_painter->fillRect(info_pos,brush) ;
|
||||
_painter->drawRect(info_pos) ;
|
||||
|
||||
// draw the text
|
||||
|
||||
float x = info_pos.x() + 5 ;
|
||||
float y = info_pos.y() + line_height + 1 ;
|
||||
|
||||
_painter->drawText(QPointF(x,y), service_name) ; y += line_height ;
|
||||
_painter->drawText(QPointF(x,y), peer_name) ; y += line_height ;
|
||||
_painter->drawText(QPointF(x,y), peer_id) ; y += line_height ;
|
||||
_painter->drawText(QPointF(x,y), remote_status) ; y += line_height ;
|
||||
_painter->drawText(QPointF(x,y), local_status) ; y += line_height ;
|
||||
}
|
||||
|
||||
/* Stop the painter */
|
||||
_painter->end();
|
||||
}
|
||||
|
||||
QRect RSPermissionMatrixWidget::computeNodePosition(int n_row,int n_col,bool selected) const
|
||||
{
|
||||
float fact = selected?1.2f:1.0f;
|
||||
|
||||
return QRect(matrix_start_x + n_col * COL_SIZE + (COL_SIZE-ICON_SIZE_X*fact)/2,
|
||||
MATRIX_START_Y + n_row * ROW_SIZE + (ROW_SIZE-ICON_SIZE_Y*fact)/2,
|
||||
ICON_SIZE_X*fact,
|
||||
ICON_SIZE_Y*fact) ;
|
||||
}
|
||||
|
||||
// This function is the inverse of the previous function. Given a mouse position, it
|
||||
// computes the peer/service switch that is under the mouse. The zoom factor is not
|
||||
// accounted for, on purpose.
|
||||
|
||||
bool RSPermissionMatrixWidget::computeServiceAndPeer(int x,int y,uint32_t& service_id,RsPeerId& peer_id) const
|
||||
{
|
||||
// 1 - make sure that x and y are on a widget
|
||||
|
||||
x -= matrix_start_x ;
|
||||
y -= MATRIX_START_Y ;
|
||||
|
||||
if(x < 0 || x >= service_ids.size() * COL_SIZE) return false ;
|
||||
if(y < 0 || y >= peer_ids.size() * ROW_SIZE) return false ;
|
||||
|
||||
if( (x % COL_SIZE) < (COL_SIZE - ICON_SIZE_X)/2) return false ;
|
||||
if( (x % COL_SIZE) > (COL_SIZE + ICON_SIZE_X)/2) return false ;
|
||||
|
||||
if( (y % ROW_SIZE) < (ROW_SIZE - ICON_SIZE_Y)/2) return false ;
|
||||
if( (y % ROW_SIZE) > (ROW_SIZE + ICON_SIZE_Y)/2) return false ;
|
||||
|
||||
// 2 - find which widget, by looking into the service perm matrix
|
||||
|
||||
service_id = service_ids[x / COL_SIZE] ;
|
||||
peer_id = peer_ids[y / COL_SIZE] ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
void RSPermissionMatrixWidget::defaultPermissionSwitched(uint32_t ServiceId,bool b)
|
||||
{
|
||||
NOT_IMPLEMENTED ;
|
||||
}
|
||||
|
||||
void RSPermissionMatrixWidget::userPermissionSwitched(uint32_t ServiceId,const RsPeerId& friend_id,bool b)
|
||||
{
|
||||
NOT_IMPLEMENTED ;
|
||||
}
|
||||
|
||||
// void RSGraphWidget::paintLegend()
|
||||
// {
|
||||
// int bottom = _rec.height();
|
||||
//
|
||||
// std::vector<float> vals ;
|
||||
// _source->getCurrentValues(vals) ;
|
||||
//
|
||||
// for(uint i=0;i<vals.size();++i)
|
||||
// {
|
||||
// qreal paintStep = 4+FONT_SIZE;
|
||||
// qreal pos = 20+i*paintStep;
|
||||
// QString text = _source->legend(i,vals[i]) ;
|
||||
//
|
||||
// QPen oldPen = _painter->pen();
|
||||
// _painter->setPen(QPen(getColor(i), Qt::SolidLine));
|
||||
// _painter->drawLine(QPointF(SCALE_WIDTH+10.0, pos), QPointF(SCALE_WIDTH+30.0, pos));
|
||||
// _painter->setPen(oldPen);
|
||||
//
|
||||
// _painter->setPen(SCALE_COLOR);
|
||||
// _painter->drawText(QPointF(SCALE_WIDTH + 40,pos + 0.5*FONT_SIZE), text) ;
|
||||
// }
|
||||
// }
|
||||
|
103
retroshare-gui/src/gui/settings/RSPermissionMatrixWidget.h
Normal file
103
retroshare-gui/src/gui/settings/RSPermissionMatrixWidget.h
Normal file
@ -0,0 +1,103 @@
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2014 RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QFrame>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
|
||||
#define HOR_SPC 2 /** Space between data points */
|
||||
#define SCALE_WIDTH 75 /** Width of the scale */
|
||||
|
||||
#define BACK_COLOR Qt::white
|
||||
#define SCALE_COLOR Qt::black
|
||||
#define GRID_COLOR Qt::lightGray
|
||||
#define RSDHT_COLOR Qt::magenta
|
||||
#define ALLDHT_COLOR Qt::yellow
|
||||
|
||||
#define FONT_SIZE 11
|
||||
|
||||
// This class provides a widget to represent an edit a matrix of permissions
|
||||
// for services and friends. The widget allows to:
|
||||
// - set permission for each friend/service combination
|
||||
// - set permissions for a given service all friends at once
|
||||
// - set permissions for a given friend, all services at once
|
||||
//
|
||||
// The code can also be used to display bandwidth for each (friend,service) combination.
|
||||
// Maybe we should in the future make a base class with the matrix structure and use it for
|
||||
// various display usages.
|
||||
//
|
||||
class RSPermissionMatrixWidget: public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RSPermissionMatrixWidget(QWidget *parent=NULL);
|
||||
virtual ~RSPermissionMatrixWidget() ;
|
||||
|
||||
protected slots:
|
||||
// Calls the internal source for a new data points; called by the timer. You might want to overload this
|
||||
// if the collection system needs it. Otherwise, the default method will call getValues()
|
||||
void updateDisplay() {}
|
||||
|
||||
void defaultPermissionSwitched(uint32_t ServiceId,bool b);
|
||||
void userPermissionSwitched(uint32_t ServiceId,const RsPeerId& friend_id,bool b);
|
||||
|
||||
virtual void mousePressEvent(QMouseEvent *e) ;
|
||||
virtual void mouseMoveEvent(QMouseEvent *e) ;
|
||||
protected:
|
||||
/** Overloaded QWidget::paintEvent() */
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
bool computeServiceAndPeer(int x,int y,uint32_t& service_id,RsPeerId& peer_id) const ;
|
||||
QRect computeNodePosition(int row,int col,bool selected) const ;
|
||||
|
||||
void switchPermission(uint32_t service_id,const RsPeerId& peer_id) ;
|
||||
|
||||
std::vector<RsPeerId> peer_ids ;
|
||||
std::vector<uint32_t> service_ids ;
|
||||
|
||||
uint32_t _current_service_id ;
|
||||
RsPeerId _current_peer_id ;
|
||||
int matrix_start_x ;
|
||||
|
||||
/** A QPainter object that handles drawing the various graph elements. */
|
||||
QPainter* _painter;
|
||||
/** The current dimensions of the graph. */
|
||||
QRect _rec;
|
||||
|
||||
static const int ROW_SIZE ;
|
||||
static const int COL_SIZE ;
|
||||
static const int ICON_SIZE_X ;
|
||||
static const int ICON_SIZE_Y ;
|
||||
static const int MATRIX_START_X ;
|
||||
static const int MATRIX_START_Y ;
|
||||
};
|
||||
|
||||
|
@ -40,8 +40,7 @@ ServicePermissionsPage::ServicePermissionsPage(QWidget * parent, Qt::WindowFlags
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
ui.setupUi(this);
|
||||
|
||||
QObject::connect(ui.tableWidget,SIGNAL(itemChanged(QTableWidgetItem *)),
|
||||
this, SLOT(tableItemChanged(QTableWidgetItem *)));
|
||||
//QObject::connect(ui.tableWidget,SIGNAL(itemChanged(QTableWidgetItem *)), this, SLOT(tableItemChanged(QTableWidgetItem *)));
|
||||
|
||||
/* Hide platform specific features */
|
||||
#ifdef Q_WS_WIN
|
||||
@ -58,6 +57,7 @@ QString ServicePermissionsPage::helpText() const
|
||||
/** Saves the changes on this page */
|
||||
bool ServicePermissionsPage::save(QString &/*errmsg*/)
|
||||
{
|
||||
#ifdef SUSPENDED
|
||||
std::cerr << "ServicePermissionsPage::save()";
|
||||
std::cerr << std::endl;
|
||||
size_t row, column;
|
||||
@ -142,8 +142,9 @@ bool ServicePermissionsPage::save(QString &/*errmsg*/)
|
||||
}
|
||||
rsServiceControl->updateServicePermissions(serviceId, permissions);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -183,6 +184,7 @@ void ServicePermissionsPage::load()
|
||||
std::map<uint32_t, RsServiceInfo>::const_iterator sit;
|
||||
rsServiceControl->getOwnServices(ownServices);
|
||||
|
||||
#ifdef SUSPENDED
|
||||
mStdRowCount = ownServices.mServiceList.size();
|
||||
mStdColumnCount = peerList.size() + 1;
|
||||
ui.tableWidget->setRowCount(mStdRowCount);
|
||||
@ -363,11 +365,13 @@ void ServicePermissionsPage::load()
|
||||
}
|
||||
|
||||
ui.tableWidget->setHorizontalHeaderLabels(columnHeaders);
|
||||
ui.tableWidget->setVerticalHeaderLabels(rowHeaders);
|
||||
ui.tableWidget->setVerticalHeaderLabels(rowHeaders);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ServicePermissionsPage::tableItemChanged ( QTableWidgetItem * item )
|
||||
void ServicePermissionsPage::tableItemChanged ( int row, int col )
|
||||
{
|
||||
#ifdef SUSPENDED
|
||||
std::cerr << "ServicePermissionsPage::tableItemChanged()";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\t Node: Row: " << item->row() << " Column: " << item->column();
|
||||
@ -397,7 +401,8 @@ void ServicePermissionsPage::tableItemChanged ( QTableWidgetItem * item )
|
||||
bool defaultOn = (Qt::Checked == defitem->checkState());
|
||||
item->setBackground(getColor(defaultOn, item->checkState()));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,28 +29,28 @@
|
||||
|
||||
class ServicePermissionsPage: public ConfigPage
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ServicePermissionsPage(QWidget * parent = 0, Qt::WindowFlags flags = 0);
|
||||
~ServicePermissionsPage() {}
|
||||
public:
|
||||
ServicePermissionsPage(QWidget * parent = 0, Qt::WindowFlags flags = 0);
|
||||
~ServicePermissionsPage() {}
|
||||
|
||||
/** Saves the changes on this page */
|
||||
virtual bool save(QString &/*errmsg*/);
|
||||
/** Loads the settings for this page */
|
||||
virtual void load();
|
||||
/** Saves the changes on this page */
|
||||
virtual bool save(QString &/*errmsg*/);
|
||||
/** Loads the settings for this page */
|
||||
virtual void load();
|
||||
|
||||
virtual QPixmap iconPixmap() const { return QPixmap(":/images/admin-24.png") ; }
|
||||
virtual QString pageName() const { return tr("Permissions") ; }
|
||||
virtual QString helpText() const ;
|
||||
virtual QPixmap iconPixmap() const { return QPixmap(":/images/admin-24.png") ; }
|
||||
virtual QString pageName() const { return tr("Permissions") ; }
|
||||
virtual QString helpText() const ;
|
||||
|
||||
public slots:
|
||||
void tableItemChanged ( QTableWidgetItem * item );
|
||||
private:
|
||||
public slots:
|
||||
void tableItemChanged(int row,int col);
|
||||
private:
|
||||
|
||||
size_t mStdRowCount;
|
||||
size_t mStdColumnCount;
|
||||
Ui::ServicePermissionsPage ui;
|
||||
size_t mStdRowCount;
|
||||
size_t mStdColumnCount;
|
||||
Ui::ServicePermissionsPage ui;
|
||||
};
|
||||
|
||||
#endif //SERVICEPERMISSIONSPAGE_H
|
||||
|
@ -58,59 +58,13 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Permission changes are not saved permanently. (TODO)</string>
|
||||
<widget class="RSPermissionMatrixWidget" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Chat</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Row2</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Shares</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Channels</string>
|
||||
</property>
|
||||
</row>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Default</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Joe</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Sally</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Anne</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Jacki</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -119,6 +73,14 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>RSPermissionMatrixWidget</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>gui/settings/RSPermissionMatrixWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -398,6 +398,7 @@ HEADERS += rshare.h \
|
||||
gui/msgs/textformat.h \
|
||||
gui/msgs/MessageUserNotify.h \
|
||||
gui/images/retroshare_win.rc.h \
|
||||
gui/settings/RSPermissionMatrixWidget.h \
|
||||
gui/settings/rsharesettings.h \
|
||||
gui/settings/RsharePeerSettings.h \
|
||||
gui/settings/rsettings.h \
|
||||
@ -780,6 +781,7 @@ SOURCES += main.cpp \
|
||||
gui/common/StyledElidedLabel.cpp \
|
||||
gui/style/RSStyle.cpp \
|
||||
gui/style/StyleDialog.cpp \
|
||||
gui/settings/RSPermissionMatrixWidget.cpp \
|
||||
gui/settings/rsharesettings.cpp \
|
||||
gui/settings/RsharePeerSettings.cpp \
|
||||
gui/settings/rsettings.cpp \
|
||||
|
Loading…
Reference in New Issue
Block a user