From 63a3051d3cecd4a11ff80854f85e6efbb14b10e8 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 1 Feb 2015 20:34:30 +0000 Subject: [PATCH] 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 --- retroshare-gui/src/gui/images.qrc | 3 +- .../src/gui/images/global_switch_off.png | Bin 0 -> 1497 bytes .../src/gui/images/global_switch_on.png | Bin 0 -> 2583 bytes .../gui/settings/RSPermissionMatrixWidget.cpp | 88 +++++++++++++++--- .../gui/settings/RSPermissionMatrixWidget.h | 3 + 5 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 retroshare-gui/src/gui/images/global_switch_off.png create mode 100644 retroshare-gui/src/gui/images/global_switch_on.png diff --git a/retroshare-gui/src/gui/images.qrc b/retroshare-gui/src/gui/images.qrc index 1d61d0e71..8663beb41 100644 --- a/retroshare-gui/src/gui/images.qrc +++ b/retroshare-gui/src/gui/images.qrc @@ -1,6 +1,7 @@ - images/switch.png + images/global_switch_on.png + images/global_switch_off.png images/switch00.png images/switch01.png images/switch10.png diff --git a/retroshare-gui/src/gui/images/global_switch_off.png b/retroshare-gui/src/gui/images/global_switch_off.png new file mode 100644 index 0000000000000000000000000000000000000000..7828c1394ec035cc75e7a180ac5f412a5bacc8af GIT binary patch literal 1497 zcmV;~1t$85P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2j2n# z6dpR{qTQYV00mh|L_t(Y$BmawOjK7C$A5R`F$01!m?GgLlD4514WX$Clr}bmXl&5N z4F(%cqYK)u(4C9Ml`9urvS@YDCP>j@8UmWOaUpRb(qgn$Otd!m0Wy5efP%oh_f8k@ z&hyP>pnb`mbLZas?)m(mbDrY$Qwn@y!RHoKC{Un()}f*Y0ZQhY*znATAAnzh=fU?s z1-|_NO5X$C0HQzy$kj9&80r52%fM2At_0|^rZd28;HJm)OQ25yWx%b^pyVLPHc$mx zqOcyJ01eIsNCA$fc9!920meXn0@Vd^;C%}?PzNPn0Uzsw!QtxRXz3-eZU^?=z@B5Q z1H1(s1O9=MK{yZ!!Qnl?E>CKeGNg5kd2r1QFme9ly?IbE;6u-1hpi}Vt}!%2n^Wl# z((7S;#tLX?YAlAPa{)^&0>wZM6j>o1KxxU84j#qYkBUZ-NW}B=$_gwmXGA)I$ajGU zc#ciG2Q7StU&4AW24qxD4yvh%P(uT1#|~6knFpEiaol_Na0dsGt5?Cc{dd!}NMp!- z4Krn7n20QxWXl$EuU$iJ-HOW3UnP{)(t<25B99-l+}MarPOj40$>bqEV<+HW2}m1m zZf3*f%bp;PL+Z&BoV#~%$Hu&i%geE9YOu=7QPtJt#p5jQ+lPJSiZ7fK;E~pt4KQ*6 zBndJFG6RwTnFV>#+$^qbi-<^SVnSxy+hww#K&Cx z5(P}QwZYJkk4@RQ5fzO>ULI0d=;Kv}hKRSdc`mA~#ARDmBm`Vsm+}004oa%0OZuxuBtX>!FP?3Q(FuAjy2x(g3HMgd5NAL0AeRj zWG$7Zse=`%@c3~6l9w*6s$jmxvPM+To;!yC;i4kSE?&$i^lm7G3WZSNa7HOi0c961 zU~S%v05fOLX07cRa1ulMSA&C$cXtD@silRojt*AznVF#>l8+uSefu`aJ9lt(mr>f$ z!KQ-;0eIfs&8xw|3{8WjQ{}U=6rVZ6 zwj)Q#t*YYP;bB&uJ>%`EDX(EDE+$e@;rskSXD5>J+6rcY2Hh%mAJb5A)#kX;gndQOC&$Kxe(O=&q3x0m6=h^!D;+Z!ZI} z7@KzOqGPaKr2SdebR&Kk(gND6J2ePO`MIYt7f&djX69e|SCL7eK!< zKHB!?z)=e-*6D6D8^Qmv=fG1Nz6X9wf3*Dz@ggXB2Z>2U00000NkvXXu0mjfW&FFU literal 0 HcmV?d00001 diff --git a/retroshare-gui/src/gui/images/global_switch_on.png b/retroshare-gui/src/gui/images/global_switch_on.png new file mode 100644 index 0000000000000000000000000000000000000000..e13bf0c88bba353674c9a143ba8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19B+LbX6cJx42gp6TR87FvJG;noQNwCVDb^{??!?^Ud$rC&%$b>meyfg)i0PS}n{?I>mQb8vGNR z#SbxL2w%H5zcCbV{`0UXdg_a9Rw(6Ij|Dzy!@h?W) z#K^daY?H)q(eNgTRGUEU#gn4|)V7BbGr99+Ej((JERb>) zxDDLGau?$|)b0UJuHyU^_uji(;%k4^6K}n0mhztZViJ$P(jBat?O1GY=s%Vn?P;Mz zyb#6yw_0uKe)sdfd*zMP-5rkEu5G&9?Q)fyah02Kxtn%f*K~J>WA>FdQujNb_g$+k zT@?G@QX*d1(ViB+4C8+tVV*p3kPokRd`of4_w5CTIooVm`P4IlqjNAZArJyO9mfa% z1y|m2Y;H&k>h-#kUzJ3cjyy40{p8)7|Mv*<{|#-ElT#CAnJ<=Qeo`rUsMNX%5cvM4 tweCh3#+Sn|zS!wJSl>RVZP&G3{u@!i&Jn98YP|pe002ovPDHLkV1haZ{Ad6G literal 0 HcmV?d00001 diff --git a/retroshare-gui/src/gui/settings/RSPermissionMatrixWidget.cpp b/retroshare-gui/src/gui/settings/RSPermissionMatrixWidget.cpp index 0ca9e86b4..a11895403 100644 --- a/retroshare-gui/src/gui/settings/RSPermissionMatrixWidget.cpp +++ b/retroshare-gui/src/gui/settings/RSPermissionMatrixWidget.cpp @@ -49,7 +49,7 @@ 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 ; +const int RSPermissionMatrixWidget::MATRIX_START_Y =100 ; /** Default contructor */ RSPermissionMatrixWidget::RSPermissionMatrixWidget(QWidget *parent) @@ -79,17 +79,20 @@ void RSPermissionMatrixWidget::mousePressEvent(QMouseEvent *e) uint32_t service_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) ; - return ; + std::cerr << "Peer id: " << peer_id << ", service: " << service_id << std::endl; + + switchPermission(service_id,peer_id) ; + update() ; } - - std::cerr << "Peer id: " << peer_id << ", service: " << service_id << std::endl; - - switchPermission(service_id,peer_id) ; - - update() ; + else if(computeServiceGlobalSwitch(e->x(),e->y(),service_id)) + { + switchPermission(service_id) ; + update(); + } + else + QFrame::mousePressEvent(e) ; } 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); } +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) { uint32_t service_id ; @@ -179,6 +201,9 @@ void RSPermissionMatrixWidget::paintEvent(QPaintEvent *) rsPeers->getPeerDetails(*it,details) ; 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)) ; 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) ++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 ; // draw a half-transparent rectangle @@ -256,7 +281,7 @@ void RSPermissionMatrixWidget::paintEvent(QPaintEvent *) _painter->drawText(QPointF(X,Y),name); } - // Now draw the switches. + // Now draw the global switches. peer_ids.clear() ; for(std::list::const_iterator it(ssllist.begin());it!=ssllist.end();++it) @@ -265,6 +290,25 @@ void RSPermissionMatrixWidget::paintEvent(QPaintEvent *) for(std::map::const_iterator sit(ownServices.mServiceList.begin());sit!=ownServices.mServiceList.end();++sit) 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;igetServicePermissions(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. 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 ; } +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) { NOT_IMPLEMENTED ; diff --git a/retroshare-gui/src/gui/settings/RSPermissionMatrixWidget.h b/retroshare-gui/src/gui/settings/RSPermissionMatrixWidget.h index 2d3423dce..7f2d52f3e 100644 --- a/retroshare-gui/src/gui/settings/RSPermissionMatrixWidget.h +++ b/retroshare-gui/src/gui/settings/RSPermissionMatrixWidget.h @@ -77,9 +77,12 @@ protected: private: 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 ; void switchPermission(uint32_t service_id,const RsPeerId& peer_id) ; + void switchPermission(uint32_t service_id) ; std::vector peer_ids ; std::vector service_ids ;