2012-10-21 10:06:33 -04:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QSizePolicy>
|
|
|
|
#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 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
|
|
|
|
|
2013-04-19 17:09:05 -04:00
|
|
|
/*QString GroupFlagsWidget::_tooltips_on[4] = {
|
2013-02-27 05:00:35 -05:00
|
|
|
QObject::tr("Directory is browsable for friends from groups"),
|
|
|
|
QObject::tr("Directory is accessible by anonymous tunnels from friends from groups"),
|
2012-10-21 15:39:56 -04:00
|
|
|
QObject::tr("Directory is browsable for any friend"),
|
|
|
|
QObject::tr("Directory is accessible by anonymous tunnels from any friend")
|
|
|
|
};
|
|
|
|
QString GroupFlagsWidget::_tooltips_off[4] = {
|
2013-02-27 05:00:35 -05:00
|
|
|
QObject::tr("Directory is NOT browsable for friends from groups"),
|
|
|
|
QObject::tr("Directory is NOT accessible by anonymous tunnels from friends from groups"),
|
2013-01-19 17:04:02 -05:00
|
|
|
QObject::tr("Directory is NOT browsable for any friend"),
|
|
|
|
QObject::tr("Directory is NOT accessible by anonymous tunnels from any friend")
|
2012-10-21 15:39:56 -04:00
|
|
|
};
|
2013-04-19 17:09:05 -04:00
|
|
|
*/
|
2012-11-02 09:52:29 -04:00
|
|
|
GroupFlagsWidget::GroupFlagsWidget(QWidget *parent,FileStorageFlags flags)
|
2012-10-21 10:06:33 -04:00
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
_layout = new QHBoxLayout(this) ;
|
|
|
|
|
2012-10-21 15:39:56 -04:00
|
|
|
setMinimumSize(128,32) ;
|
|
|
|
setMaximumSize(128,32) ;
|
|
|
|
setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
|
|
|
|
|
2012-10-21 10:06:33 -04:00
|
|
|
_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) ;
|
|
|
|
|
|
|
|
setLayout(_layout) ;
|
|
|
|
|
2012-11-01 06:06:12 -04:00
|
|
|
_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 ;
|
2012-10-21 10:06:33 -04:00
|
|
|
|
|
|
|
for(int i=0;i<4;++i)
|
|
|
|
{
|
|
|
|
_buttons[i] = new QPushButton(this) ;
|
|
|
|
_buttons[i]->setCheckable(true) ;
|
|
|
|
_buttons[i]->setChecked(flags & _flags[i]) ;
|
2012-10-21 15:39:56 -04:00
|
|
|
_buttons[i]->setIconSize(QSize(32,32));
|
2012-10-21 10:06:33 -04:00
|
|
|
update_button_state(_buttons[i]->isChecked(),i) ;
|
|
|
|
_layout->addWidget(_buttons[i]) ;
|
|
|
|
}
|
2012-11-06 15:46:56 -05:00
|
|
|
_buttons[INDEX_GROUP_NETWORK_W]->setHidden(true);
|
2012-10-21 10:06:33 -04:00
|
|
|
|
|
|
|
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))) ;
|
|
|
|
|
|
|
|
_layout->setSpacing(0);
|
2012-11-06 16:24:49 -05:00
|
|
|
_layout->setContentsMargins(0, 0, 0, 0);
|
2012-10-21 10:06:33 -04:00
|
|
|
|
|
|
|
_layout->update() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupFlagsWidget::updated()
|
|
|
|
{
|
|
|
|
emit flagsChanged(flags()) ;
|
|
|
|
}
|
|
|
|
|
2012-11-02 09:52:29 -04:00
|
|
|
FileStorageFlags GroupFlagsWidget::flags() const
|
2012-10-21 10:06:33 -04:00
|
|
|
{
|
2012-11-02 09:52:29 -04:00
|
|
|
FileStorageFlags flags ;
|
2012-10-21 10:06:33 -04:00
|
|
|
|
|
|
|
for(int i=0;i<4;++i)
|
|
|
|
if(_buttons[i]->isChecked()) flags |= _flags[i] ;
|
|
|
|
|
2012-11-06 15:46:56 -05:00
|
|
|
flags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ;
|
2012-10-21 10:06:33 -04:00
|
|
|
return flags ;
|
|
|
|
}
|
|
|
|
|
2012-11-02 13:26:20 -04:00
|
|
|
void GroupFlagsWidget::setFlags(FileStorageFlags flags)
|
|
|
|
{
|
|
|
|
for(int i=0;i<4;++i)
|
|
|
|
{
|
|
|
|
_buttons[i]->setChecked(flags & _flags[i]) ;
|
|
|
|
update_button_state(_buttons[i]->isChecked(),i) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-21 10:06:33 -04:00
|
|
|
void GroupFlagsWidget::update_button_state(bool b,int button_id)
|
|
|
|
{
|
2013-04-19 17:09:05 -04:00
|
|
|
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");
|
|
|
|
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");
|
|
|
|
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");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tip_on = "";
|
|
|
|
tip_off = "";
|
|
|
|
}
|
2012-10-21 10:06:33 -04:00
|
|
|
if(b)
|
2012-10-21 15:39:56 -04:00
|
|
|
{
|
2012-10-21 10:06:33 -04:00
|
|
|
_buttons[button_id]->setIcon(*_icons[button_id]) ;
|
2013-04-19 17:09:05 -04:00
|
|
|
_buttons[button_id]->setToolTip(tip_on) ;
|
2012-10-21 15:39:56 -04:00
|
|
|
}
|
2012-10-21 10:06:33 -04:00
|
|
|
else if(button_id == INDEX_GROUP_NETWORK_W || button_id == INDEX_GROUP_BROWSABLE)
|
2012-10-21 15:39:56 -04:00
|
|
|
{
|
2012-10-21 10:06:33 -04:00
|
|
|
_buttons[button_id]->setIcon(*_icons[INDEX_GROUP_UNCHECKED]) ;
|
2013-04-19 17:09:05 -04:00
|
|
|
_buttons[button_id]->setToolTip(tip_off) ;
|
2012-10-21 15:39:56 -04:00
|
|
|
}
|
2012-10-21 10:06:33 -04:00
|
|
|
else
|
2012-10-21 15:39:56 -04:00
|
|
|
{
|
2012-10-21 10:06:33 -04:00
|
|
|
_buttons[button_id]->setIcon(*_icons[INDEX_OTHER_UNCHECKED]) ;
|
2013-04-19 17:09:05 -04:00
|
|
|
_buttons[button_id]->setToolTip(tip_off) ;
|
2012-10-21 15:39:56 -04:00
|
|
|
}
|
2012-10-21 10:06:33 -04:00
|
|
|
}
|
|
|
|
|
2012-11-08 19:46:41 -05:00
|
|
|
QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags, const QList<QString>& groupNames)
|
2012-11-03 13:15:47 -04:00
|
|
|
{
|
|
|
|
// makes a string that explains how files are shared / visible.
|
|
|
|
|
|
|
|
QString res ;
|
|
|
|
QString groups_string ;
|
|
|
|
|
2012-11-08 19:46:41 -05:00
|
|
|
for(QList<QString>::const_iterator it(groupNames.begin());it!=groupNames.end();++it)
|
2012-11-03 13:15:47 -04:00
|
|
|
{
|
2012-11-08 19:46:41 -05:00
|
|
|
if(it != groupNames.begin())
|
2012-11-03 13:15:47 -04:00
|
|
|
groups_string += ", " ;
|
2012-11-08 19:46:41 -05:00
|
|
|
groups_string += *it ;
|
2012-11-03 13:15:47 -04:00
|
|
|
}
|
|
|
|
|
2012-11-06 16:24:49 -05:00
|
|
|
if(flags & DIR_FLAGS_BROWSABLE_OTHERS)
|
2015-03-19 16:39:59 -04:00
|
|
|
res += tr("All friend nodes can browse this directory") + "\n" ;
|
2012-11-06 16:24:49 -05:00
|
|
|
else if(flags & DIR_FLAGS_BROWSABLE_GROUPS)
|
2012-11-08 19:46:41 -05:00
|
|
|
if(!groupNames.empty())
|
2015-06-01 10:20:26 -04:00
|
|
|
res += tr("Only friend nodes in groups %1 can browse this directory").arg(groups_string) + "\n" ;
|
2012-11-06 16:24:49 -05:00
|
|
|
else
|
2012-12-11 19:04:01 -05:00
|
|
|
res += tr("No one can browse this directory") + "\n" ;
|
2012-11-06 16:24:49 -05:00
|
|
|
else
|
2012-12-11 19:04:01 -05:00
|
|
|
res += tr("No one can browse this directory") + "\n" ;
|
2012-11-03 13:15:47 -04:00
|
|
|
|
|
|
|
if(flags & DIR_FLAGS_NETWORK_WIDE_OTHERS)
|
2015-06-01 10:20:26 -04:00
|
|
|
res += tr("All friend nodes can relay anonymous tunnels to this directory") ;
|
2012-11-03 13:15:47 -04:00
|
|
|
else if(flags & DIR_FLAGS_NETWORK_WIDE_GROUPS)
|
2015-06-01 10:20:26 -04:00
|
|
|
res += tr("Only friend nodes in groups ") + groups_string + tr(" can relay anonymous tunnels to this directory") ;
|
2012-11-06 16:24:49 -05:00
|
|
|
else
|
|
|
|
res += tr("No one can anonymously access this directory.") ;
|
2012-11-03 13:15:47 -04:00
|
|
|
|
2012-11-06 16:24:49 -05:00
|
|
|
//if(flags.toUInt32() == 0)
|
|
|
|
// res += tr("No friends can access nor see this directory.") ;
|
2012-11-03 13:15:47 -04:00
|
|
|
|
|
|
|
return res ;
|
|
|
|
}
|
|
|
|
|
2012-10-21 10:06:33 -04:00
|
|
|
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() ; }
|
|
|
|
|
|
|
|
GroupFlagsWidget::~GroupFlagsWidget()
|
|
|
|
{
|
|
|
|
for(int i=0;i<4;++i)
|
|
|
|
{
|
|
|
|
delete _buttons[i] ;
|
|
|
|
delete _icons[i] ;
|
|
|
|
}
|
|
|
|
delete _icons[INDEX_GROUP_UNCHECKED] ;
|
|
|
|
delete _icons[INDEX_OTHER_UNCHECKED] ;
|
|
|
|
}
|
|
|
|
|