added global switch on/off per service

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7900 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-02-01 20:34:30 +00:00
parent 2a9551a41a
commit 63a3051d3c
5 changed files with 81 additions and 13 deletions

View File

@ -1,6 +1,7 @@
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>images/switch.png</file> <file>images/global_switch_on.png</file>
<file>images/global_switch_off.png</file>
<file>images/switch00.png</file> <file>images/switch00.png</file>
<file>images/switch01.png</file> <file>images/switch01.png</file>
<file>images/switch10.png</file> <file>images/switch10.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -49,7 +49,7 @@ const int RSPermissionMatrixWidget::ICON_SIZE_Y = 40 ;
const int RSPermissionMatrixWidget::ROW_SIZE = 42 ; const int RSPermissionMatrixWidget::ROW_SIZE = 42 ;
const int RSPermissionMatrixWidget::COL_SIZE = 42 ; const int RSPermissionMatrixWidget::COL_SIZE = 42 ;
const int RSPermissionMatrixWidget::MATRIX_START_X = 5 ; const int RSPermissionMatrixWidget::MATRIX_START_X = 5 ;
const int RSPermissionMatrixWidget::MATRIX_START_Y = 55 ; const int RSPermissionMatrixWidget::MATRIX_START_Y =100 ;
/** Default contructor */ /** Default contructor */
RSPermissionMatrixWidget::RSPermissionMatrixWidget(QWidget *parent) RSPermissionMatrixWidget::RSPermissionMatrixWidget(QWidget *parent)
@ -79,17 +79,20 @@ void RSPermissionMatrixWidget::mousePressEvent(QMouseEvent *e)
uint32_t service_id ; uint32_t service_id ;
RsPeerId peer_id ; RsPeerId peer_id ;
if(!computeServiceAndPeer(e->x(),e->y(),service_id,peer_id)) if(computeServiceAndPeer(e->x(),e->y(),service_id,peer_id))
{ {
QFrame::mousePressEvent(e) ; std::cerr << "Peer id: " << peer_id << ", service: " << service_id << std::endl;
return ;
switchPermission(service_id,peer_id) ;
update() ;
} }
else if(computeServiceGlobalSwitch(e->x(),e->y(),service_id))
std::cerr << "Peer id: " << peer_id << ", service: " << service_id << std::endl; {
switchPermission(service_id) ;
switchPermission(service_id,peer_id) ; update();
}
update() ; else
QFrame::mousePressEvent(e) ;
} }
void RSPermissionMatrixWidget::switchPermission(uint32_t service,const RsPeerId& pid) void RSPermissionMatrixWidget::switchPermission(uint32_t service,const RsPeerId& pid)
@ -106,7 +109,26 @@ void RSPermissionMatrixWidget::switchPermission(uint32_t service,const RsPeerId&
rsServiceControl->updateServicePermissions(service,serv_perms); rsServiceControl->updateServicePermissions(service,serv_perms);
} }
void RSPermissionMatrixWidget::switchPermission(uint32_t service)
{
RsServicePermissions serv_perms ;
if(!rsServiceControl->getServicePermissions(service,serv_perms))
return ;
if(serv_perms.mDefaultAllowed)
{
serv_perms.mPeersAllowed.clear() ;
serv_perms.mDefaultAllowed = false ;
}
else
{
serv_perms.mDefaultAllowed = true ;
serv_perms.mPeersDenied.clear() ;
}
rsServiceControl->updateServicePermissions(service,serv_perms);
}
void RSPermissionMatrixWidget::mouseMoveEvent(QMouseEvent *e) void RSPermissionMatrixWidget::mouseMoveEvent(QMouseEvent *e)
{ {
uint32_t service_id ; uint32_t service_id ;
@ -179,6 +201,9 @@ void RSPermissionMatrixWidget::paintEvent(QPaintEvent *)
rsPeers->getPeerDetails(*it,details) ; rsPeers->getPeerDetails(*it,details) ;
QString name = QString::fromUtf8(details.name.c_str()) + " (" + QString::fromUtf8(details.location.c_str()) + ")"; QString name = QString::fromUtf8(details.name.c_str()) + " (" + QString::fromUtf8(details.location.c_str()) + ")";
if(name.length() > 20)
name = name.left(20)+"..." ;
peer_name_size = std::max(peer_name_size, fm.width(name)) ; peer_name_size = std::max(peer_name_size, fm.width(name)) ;
names.push_back(name) ; names.push_back(name) ;
} }
@ -223,7 +248,7 @@ void RSPermissionMatrixWidget::paintEvent(QPaintEvent *)
while(last_width[height_index] > X-5 && height_index < last_width.size()-1) while(last_width[height_index] > X-5 && height_index < last_width.size()-1)
++height_index ; ++height_index ;
int Y = MATRIX_START_Y - 2 - line_height * height_index; int Y = MATRIX_START_Y - ICON_SIZE_Y - 2 - line_height * height_index;
last_width[height_index] = X + text_width ; last_width[height_index] = X + text_width ;
// draw a half-transparent rectangle // draw a half-transparent rectangle
@ -256,7 +281,7 @@ void RSPermissionMatrixWidget::paintEvent(QPaintEvent *)
_painter->drawText(QPointF(X,Y),name); _painter->drawText(QPointF(X,Y),name);
} }
// Now draw the switches. // Now draw the global switches.
peer_ids.clear() ; peer_ids.clear() ;
for(std::list<RsPeerId>::const_iterator it(ssllist.begin());it!=ssllist.end();++it) for(std::list<RsPeerId>::const_iterator it(ssllist.begin());it!=ssllist.end();++it)
@ -265,6 +290,25 @@ void RSPermissionMatrixWidget::paintEvent(QPaintEvent *)
for(std::map<uint32_t, RsServiceInfo>::const_iterator sit(ownServices.mServiceList.begin());sit!=ownServices.mServiceList.end();++sit) for(std::map<uint32_t, RsServiceInfo>::const_iterator sit(ownServices.mServiceList.begin());sit!=ownServices.mServiceList.end();++sit)
service_ids.push_back(sit->first) ; service_ids.push_back(sit->first) ;
static const std::string global_switch[2] = { ":/images/global_switch_off.png",
":/images/global_switch_on.png" } ;
for(int i=0;i<service_ids.size();++i)
{
RsServicePermissions serv_perm ;
rsServiceControl->getServicePermissions(service_ids[i],serv_perm) ;
QPixmap pix(global_switch[serv_perm.mDefaultAllowed].c_str()) ;
QRect position = computeNodePosition(0,i,false) ;
position.setY(position.y() - ICON_SIZE_Y + 8) ;
position.setX(position.x() + 3) ;
position.setHeight(30) ;
position.setWidth(30) ;
_painter->drawPixmap(position,pix,QRect(0,0,30,30)) ;
}
// We draw for each service. // We draw for each service.
static const std::string pixmap_names[4] = { ":/images/switch00.png", static const std::string pixmap_names[4] = { ":/images/switch00.png",
@ -420,7 +464,27 @@ bool RSPermissionMatrixWidget::computeServiceAndPeer(int x,int y,uint32_t& servi
return true ; return true ;
} }
bool RSPermissionMatrixWidget::computeServiceGlobalSwitch(int x,int y,uint32_t& service_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( (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 ) return false ;
if( y > 0 ) return false ;
// 2 - find which widget, by looking into the service perm matrix
service_id = service_ids[x / COL_SIZE] ;
return true ;
}
void RSPermissionMatrixWidget::defaultPermissionSwitched(uint32_t ServiceId,bool b) void RSPermissionMatrixWidget::defaultPermissionSwitched(uint32_t ServiceId,bool b)
{ {
NOT_IMPLEMENTED ; NOT_IMPLEMENTED ;

View File

@ -77,9 +77,12 @@ protected:
private: private:
bool computeServiceAndPeer(int x,int y,uint32_t& service_id,RsPeerId& peer_id) const ; bool computeServiceAndPeer(int x,int y,uint32_t& service_id,RsPeerId& peer_id) const ;
bool computeServiceGlobalSwitch(int x,int y,uint32_t& service_id) const ;
QRect computeNodePosition(int row,int col,bool selected) const ; QRect computeNodePosition(int row,int col,bool selected) const ;
void switchPermission(uint32_t service_id,const RsPeerId& peer_id) ; void switchPermission(uint32_t service_id,const RsPeerId& peer_id) ;
void switchPermission(uint32_t service_id) ;
std::vector<RsPeerId> peer_ids ; std::vector<RsPeerId> peer_ids ;
std::vector<uint32_t> service_ids ; std::vector<uint32_t> service_ids ;