addednew flag for anonymous search. Merged the two browsable flags in one single flag.

This commit is contained in:
mr-alice 2016-10-31 14:26:01 +01:00
parent 5b9ef04358
commit e8e054eeae
14 changed files with 99 additions and 128 deletions

View file

@ -3,31 +3,26 @@
#include "GroupFlagsWidget.h"
#include <retroshare/rsfiles.h>
#define FLAGS_GROUP_NETWORK_WIDE_ICON ":images/anonymous_128_green.png"
#define FLAGS_GROUP_BROWSABLE_ICON ":images/browsable_128_green.png"
#define FLAGS_GROUP_UNCHECKED ":images/blank_128_green.png"
#define FLAGS_OTHER_NETWORK_WIDE_ICON ":images/anonymous_128_blue.png"
#define FLAGS_OTHER_BROWSABLE_ICON ":images/browsable_128_blue.png"
#define FLAGS_OTHER_UNCHECKED ":images/blank_128_blue.png"
#define FLAGS_ANONYMOUS_SEARCH_ON ":icons/search_red_128.png"
#define FLAGS_ANONYMOUS_SEARCH_OFF ":icons/blank_red_128.png"
#define FLAGS_BROWSABLE_ON ":icons/browsable_green_128.png"
#define FLAGS_BROWSABLE_OFF ":icons/blank_green_128.png"
#define FLAGS_ANONYMOUS_DL_ON ":icons/anonymous_blue_128.png"
#define FLAGS_ANONYMOUS_DL_OFF ":icons/blank_blue_128.png"
#define INDEX_GROUP_BROWSABLE 0
#define INDEX_GROUP_NETWORK_W 1
#define INDEX_OTHER_BROWSABLE 2
#define INDEX_OTHER_NETWORK_W 3
#define INDEX_GROUP_UNCHECKED 4
#define INDEX_OTHER_UNCHECKED 5
#define INDEX_BROWSABLE 0
#define INDEX_ANON_SEARCH 1
#define INDEX_ANON_DL 2
/*QString GroupFlagsWidget::_tooltips_on[4] = {
QObject::tr("Directory is browsable for friends from groups"),
QObject::tr("Directory is accessible by anonymous tunnels from friends from groups"),
QObject::tr("Directory is browsable for any friend"),
QObject::tr("Directory is accessible by anonymous tunnels from any friend")
QObject::tr("Directory is visible to friends"),
QObject::tr("Directory can be search anonymously"),
QObject::tr("Directory is accessible by anonymous tunnels")
};
QString GroupFlagsWidget::_tooltips_off[4] = {
QObject::tr("Directory is NOT browsable for friends from groups"),
QObject::tr("Directory is NOT accessible by anonymous tunnels from friends from groups"),
QObject::tr("Directory is NOT browsable for any friend"),
QObject::tr("Directory is NOT accessible by anonymous tunnels from any friend")
QObject::tr("Directory is not visible to friends"),
QObject::tr("Directory cannot be searched anonymously"),
QObject::tr("Directory is NOT accessible by anonymous tunnels")
};
*/
GroupFlagsWidget::GroupFlagsWidget(QWidget *parent,FileStorageFlags flags)
@ -39,35 +34,33 @@ GroupFlagsWidget::GroupFlagsWidget(QWidget *parent,FileStorageFlags flags)
setMaximumSize(128 * QFontMetricsF(font()).height()/14.0,32 * QFontMetricsF(font()).height()/14.0) ;
setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
_icons[INDEX_GROUP_BROWSABLE] = new QIcon(FLAGS_GROUP_BROWSABLE_ICON) ;
_icons[INDEX_GROUP_NETWORK_W] = new QIcon(FLAGS_GROUP_NETWORK_WIDE_ICON) ;
_icons[INDEX_OTHER_BROWSABLE] = new QIcon(FLAGS_OTHER_BROWSABLE_ICON) ;
_icons[INDEX_OTHER_NETWORK_W] = new QIcon(FLAGS_OTHER_NETWORK_WIDE_ICON) ;
_icons[INDEX_GROUP_UNCHECKED] = new QIcon(FLAGS_GROUP_UNCHECKED) ;
_icons[INDEX_OTHER_UNCHECKED] = new QIcon(FLAGS_OTHER_UNCHECKED) ;
_icons[2*INDEX_BROWSABLE+0] = new QIcon(FLAGS_BROWSABLE_OFF) ;
_icons[2*INDEX_BROWSABLE+1] = new QIcon(FLAGS_BROWSABLE_ON) ;
_icons[2*INDEX_ANON_SEARCH+0] = new QIcon(FLAGS_ANONYMOUS_SEARCH_OFF) ;
_icons[2*INDEX_ANON_SEARCH+1] = new QIcon(FLAGS_ANONYMOUS_SEARCH_ON) ;
_icons[2*INDEX_ANON_DL+0] = new QIcon(FLAGS_ANONYMOUS_DL_OFF) ;
_icons[2*INDEX_ANON_DL+1] = new QIcon(FLAGS_ANONYMOUS_DL_ON) ;
setLayout(_layout) ;
_flags[0] = DIR_FLAGS_BROWSABLE_GROUPS ;
_flags[1] = DIR_FLAGS_NETWORK_WIDE_GROUPS ;
_flags[2] = DIR_FLAGS_BROWSABLE_OTHERS ;
_flags[3] = DIR_FLAGS_NETWORK_WIDE_OTHERS ;
_flags[INDEX_BROWSABLE ] = DIR_FLAGS_BROWSABLE ;
_flags[INDEX_ANON_SEARCH] = DIR_FLAGS_ANONYMOUS_SEARCH ;
_flags[INDEX_ANON_DL ] = DIR_FLAGS_ANONYMOUS_DOWNLOAD ;
for(int i=0;i<4;++i)
for(int i=0;i<3;++i)
{
_buttons[i] = new QPushButton(this) ;
_buttons[i]->setCheckable(true) ;
_buttons[i]->setChecked(flags & _flags[i]) ;
_buttons[i]->setIconSize(QSize(32 * QFontMetricsF(font()).height()/14.0,32 * QFontMetricsF(font()).height()/14.0));
update_button_state(_buttons[i]->isChecked(),i) ;
_layout->addWidget(_buttons[i]) ;
}
_buttons[INDEX_GROUP_NETWORK_W]->setHidden(true);
connect(_buttons[INDEX_GROUP_NETWORK_W],SIGNAL(toggled(bool)),this,SLOT(update_GN_button(bool))) ;
connect(_buttons[INDEX_OTHER_NETWORK_W],SIGNAL(toggled(bool)),this,SLOT(update_ON_button(bool))) ;
connect(_buttons[INDEX_GROUP_BROWSABLE],SIGNAL(toggled(bool)),this,SLOT(update_GB_button(bool))) ;
connect(_buttons[INDEX_OTHER_BROWSABLE],SIGNAL(toggled(bool)),this,SLOT(update_OB_button(bool))) ;
connect(_buttons[INDEX_ANON_DL ],SIGNAL(toggled(bool)),this,SLOT(update_DL_button(bool))) ;
connect(_buttons[INDEX_ANON_SEARCH],SIGNAL(toggled(bool)),this,SLOT(update_SR_button(bool))) ;
connect(_buttons[INDEX_BROWSABLE ],SIGNAL(toggled(bool)),this,SLOT(update_BR_button(bool))) ;
_layout->setSpacing(0);
_layout->setContentsMargins(0, 0, 0, 0);
@ -84,16 +77,15 @@ FileStorageFlags GroupFlagsWidget::flags() const
{
FileStorageFlags flags ;
for(int i=0;i<4;++i)
for(int i=0;i<3;++i)
if(_buttons[i]->isChecked()) flags |= _flags[i] ;
flags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ;
return flags ;
}
void GroupFlagsWidget::setFlags(FileStorageFlags flags)
{
for(int i=0;i<4;++i)
for(int i=0;i<3;++i)
{
_buttons[i]->setChecked(flags & _flags[i]) ;
update_button_state(_buttons[i]->isChecked(),i) ;
@ -105,40 +97,23 @@ void GroupFlagsWidget::update_button_state(bool b,int button_id)
QString tip_on, tip_off;
switch (button_id) {
case 0:
tip_on = tr("Directory is browsable for friends from groups");
tip_off = tr("Directory is NOT browsable for friends from groups");
tip_on = tr("Directory is visible to friends");
tip_off = tr("Directory is NOT visible to friends");
break;
case 1:
tip_on = tr("Directory is accessible by anonymous tunnels from friends from groups");
tip_off = tr("Directory is NOT accessible by anonymous tunnels from friends from groups");
tip_on = tr("Directory can be searched anonymously");
tip_off = tr("Directory cannot be searched anonymously");
break;
case 2:
tip_on = tr("Directory is browsable for any friend");
tip_off = tr("Directory is NOT browsable for any friend");
break;
case 3:
tip_on = tr("Directory is accessible by anonymous tunnels from any friend");
tip_off = tr("Directory is NOT accessible by anonymous tunnels from any friend");
tip_on = tr("Files can be downloaded anonymously");
tip_off = tr("Files cannot be downloaded anonymously");
break;
default:
tip_on = "";
tip_off = "";
}
if(b)
{
_buttons[button_id]->setIcon(*_icons[button_id]) ;
_buttons[button_id]->setToolTip(tip_on) ;
}
else if(button_id == INDEX_GROUP_NETWORK_W || button_id == INDEX_GROUP_BROWSABLE)
{
_buttons[button_id]->setIcon(*_icons[INDEX_GROUP_UNCHECKED]) ;
_buttons[button_id]->setToolTip(tip_off) ;
}
else
{
_buttons[button_id]->setIcon(*_icons[INDEX_OTHER_UNCHECKED]) ;
_buttons[button_id]->setToolTip(tip_off) ;
}
_buttons[button_id]->setIcon(*_icons[2*button_id+(int)b]) ;
_buttons[button_id]->setToolTip(b?tip_on:tip_off) ;
}
QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags, const QList<QString>& groupNames)
@ -155,42 +130,39 @@ QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags, const QList<QS
groups_string += *it ;
}
if(flags & DIR_FLAGS_BROWSABLE_OTHERS)
res += tr("All friend nodes can browse this directory") + "\n" ;
else if(flags & DIR_FLAGS_BROWSABLE_GROUPS)
if(!groupNames.empty())
res += tr("Only friend nodes in groups %1 can browse this directory").arg(groups_string) + "\n" ;
else
res += tr("No one can browse this directory") + "\n" ;
else
res += tr("No one can browse this directory") + "\n" ;
if(flags & DIR_FLAGS_BROWSABLE)
{
if(groupNames.empty())
res += tr("All friend nodes can see this directory") + "\n" ;
else
res += tr("Only visible to friend nodes in groups: %1").arg(groups_string) + "\n" ;
}
else
res += tr("Not visible to friend nodes") + "\n" ;
if(flags & DIR_FLAGS_NETWORK_WIDE_OTHERS)
res += tr("All friend nodes can relay anonymous tunnels to this directory") ;
else if(flags & DIR_FLAGS_NETWORK_WIDE_GROUPS)
res += tr("Only friend nodes in groups")+" " + groups_string +" "+ tr("can relay anonymous tunnels to this directory") ;
else
res += tr("No one can anonymously access this directory.") ;
//if(flags.toUInt32() == 0)
// res += tr("No friends can access nor see this directory.") ;
if((flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) && !(flags & DIR_FLAGS_ANONYMOUS_SEARCH))
res += tr("Files can be downloaded (but not searched) anonymously") ;
else if((flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) && (flags & DIR_FLAGS_ANONYMOUS_SEARCH))
res += tr("Files can be downloaded and searched anonymously") ;
else if(!(flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) && (flags & DIR_FLAGS_ANONYMOUS_SEARCH))
res += tr("Files can be searched (but not downloaded) anonymously") ;
else
res += tr("No one can anonymously access/search these files.") ;
return res ;
}
void GroupFlagsWidget::update_GN_button(bool b) { update_button_state(b,INDEX_GROUP_NETWORK_W) ; updated() ; }
void GroupFlagsWidget::update_GB_button(bool b) { update_button_state(b,INDEX_GROUP_BROWSABLE) ; updated() ; }
void GroupFlagsWidget::update_ON_button(bool b) { update_button_state(b,INDEX_OTHER_NETWORK_W) ; updated() ; }
void GroupFlagsWidget::update_OB_button(bool b) { update_button_state(b,INDEX_OTHER_BROWSABLE) ; updated() ; }
void GroupFlagsWidget::update_DL_button(bool b) { update_button_state(b,INDEX_ANON_DL ) ; updated() ; }
void GroupFlagsWidget::update_SR_button(bool b) { update_button_state(b,INDEX_ANON_SEARCH) ; updated() ; }
void GroupFlagsWidget::update_BR_button(bool b) { update_button_state(b,INDEX_BROWSABLE ) ; updated() ; }
GroupFlagsWidget::~GroupFlagsWidget()
{
for(int i=0;i<4;++i)
for(int i=0;i<3;++i)
{
delete _buttons[i] ;
delete _icons[i] ;
}
delete _icons[INDEX_GROUP_UNCHECKED] ;
delete _icons[INDEX_OTHER_UNCHECKED] ;
delete _icons[2*i+0] ;
delete _icons[2*i+1] ;
}
}

View file

@ -22,10 +22,9 @@ class GroupFlagsWidget: public QWidget
void updated() ;
protected slots:
void update_GN_button(bool) ;
void update_GB_button(bool) ;
void update_ON_button(bool) ;
void update_OB_button(bool) ;
void update_DL_button(bool) ;
void update_SR_button(bool) ;
void update_BR_button(bool) ;
signals:
void flagsChanged(FileStorageFlags) const ;