2012-10-21 10:06:33 -04:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QSizePolicy>
|
|
|
|
#include "GroupFlagsWidget.h"
|
|
|
|
#include <retroshare/rsfiles.h>
|
|
|
|
|
2016-10-31 09:26:01 -04:00
|
|
|
#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"
|
|
|
|
|
2016-10-31 18:24:35 -04:00
|
|
|
#define INDEX_ANON_SEARCH 0
|
|
|
|
#define INDEX_ANON_DL 1
|
|
|
|
#define INDEX_BROWSABLE 2
|
2012-10-21 10:06:33 -04:00
|
|
|
|
2013-04-19 17:09:05 -04:00
|
|
|
/*QString GroupFlagsWidget::_tooltips_on[4] = {
|
2016-10-31 09:26:01 -04:00
|
|
|
QObject::tr("Directory is visible to friends"),
|
|
|
|
QObject::tr("Directory can be search anonymously"),
|
|
|
|
QObject::tr("Directory is accessible by anonymous tunnels")
|
2012-10-21 15:39:56 -04:00
|
|
|
};
|
|
|
|
QString GroupFlagsWidget::_tooltips_off[4] = {
|
2016-10-31 09:26:01 -04:00
|
|
|
QObject::tr("Directory is not visible to friends"),
|
|
|
|
QObject::tr("Directory cannot be searched anonymously"),
|
|
|
|
QObject::tr("Directory is NOT accessible by anonymous tunnels")
|
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) ;
|
|
|
|
|
2016-09-18 15:41:18 -04:00
|
|
|
setMinimumSize(128 * QFontMetricsF(font()).height()/14.0,32 * QFontMetricsF(font()).height()/14.0) ;
|
|
|
|
setMaximumSize(128 * QFontMetricsF(font()).height()/14.0,32 * QFontMetricsF(font()).height()/14.0) ;
|
2012-10-21 15:39:56 -04:00
|
|
|
setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
|
|
|
|
|
2016-10-31 09:26:01 -04:00
|
|
|
_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) ;
|
2012-10-21 10:06:33 -04:00
|
|
|
|
|
|
|
setLayout(_layout) ;
|
|
|
|
|
2016-10-31 09:26:01 -04:00
|
|
|
_flags[INDEX_BROWSABLE ] = DIR_FLAGS_BROWSABLE ;
|
|
|
|
_flags[INDEX_ANON_SEARCH] = DIR_FLAGS_ANONYMOUS_SEARCH ;
|
|
|
|
_flags[INDEX_ANON_DL ] = DIR_FLAGS_ANONYMOUS_DOWNLOAD ;
|
2012-10-21 10:06:33 -04:00
|
|
|
|
2016-10-31 09:26:01 -04:00
|
|
|
for(int i=0;i<3;++i)
|
2012-10-21 10:06:33 -04:00
|
|
|
{
|
|
|
|
_buttons[i] = new QPushButton(this) ;
|
|
|
|
_buttons[i]->setCheckable(true) ;
|
|
|
|
_buttons[i]->setChecked(flags & _flags[i]) ;
|
2016-09-18 15:41:18 -04:00
|
|
|
_buttons[i]->setIconSize(QSize(32 * QFontMetricsF(font()).height()/14.0,32 * QFontMetricsF(font()).height()/14.0));
|
2016-10-31 09:26:01 -04:00
|
|
|
|
2012-10-21 10:06:33 -04:00
|
|
|
update_button_state(_buttons[i]->isChecked(),i) ;
|
|
|
|
_layout->addWidget(_buttons[i]) ;
|
|
|
|
}
|
|
|
|
|
2016-10-31 09:26:01 -04:00
|
|
|
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))) ;
|
2012-10-21 10:06:33 -04:00
|
|
|
|
|
|
|
_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
|
|
|
|
2016-10-31 09:26:01 -04:00
|
|
|
for(int i=0;i<3;++i)
|
2012-10-21 10:06:33 -04:00
|
|
|
if(_buttons[i]->isChecked()) flags |= _flags[i] ;
|
|
|
|
|
|
|
|
return flags ;
|
|
|
|
}
|
|
|
|
|
2012-11-02 13:26:20 -04:00
|
|
|
void GroupFlagsWidget::setFlags(FileStorageFlags flags)
|
|
|
|
{
|
2016-10-31 09:26:01 -04:00
|
|
|
for(int i=0;i<3;++i)
|
2012-11-02 13:26:20 -04:00
|
|
|
{
|
|
|
|
_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) {
|
2016-11-02 16:31:14 -04:00
|
|
|
case INDEX_BROWSABLE:
|
|
|
|
tip_on = tr("Directory content is visible to friend nodes (see list at right)");
|
|
|
|
tip_off = tr("Directory content is NOT visible to friend nodes");
|
2013-04-19 17:09:05 -04:00
|
|
|
break;
|
2016-11-02 16:31:14 -04:00
|
|
|
case INDEX_ANON_SEARCH:
|
2016-10-31 09:26:01 -04:00
|
|
|
tip_on = tr("Directory can be searched anonymously");
|
|
|
|
tip_off = tr("Directory cannot be searched anonymously");
|
2013-04-19 17:09:05 -04:00
|
|
|
break;
|
2016-11-02 16:31:14 -04:00
|
|
|
case INDEX_ANON_DL:
|
|
|
|
if(_buttons[INDEX_ANON_SEARCH]->isChecked())
|
|
|
|
tip_on = tr("Files can be accessed using anonymous tunnels");
|
|
|
|
else
|
|
|
|
tip_on = tr("Files can be accessed using anonymous & end-to-end encrypted tunnels");
|
|
|
|
|
2016-10-31 09:26:01 -04:00
|
|
|
tip_off = tr("Files cannot be downloaded anonymously");
|
2013-04-19 17:09:05 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tip_on = "";
|
|
|
|
tip_off = "";
|
|
|
|
}
|
2016-10-31 09:26:01 -04:00
|
|
|
_buttons[button_id]->setIcon(*_icons[2*button_id+(int)b]) ;
|
|
|
|
_buttons[button_id]->setToolTip(b?tip_on:tip_off) ;
|
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
|
|
|
}
|
|
|
|
|
2016-10-31 09:26:01 -04:00
|
|
|
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_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.") ;
|
2012-11-03 13:15:47 -04:00
|
|
|
|
2016-10-22 17:48:19 -04:00
|
|
|
return res ;
|
2012-11-03 13:15:47 -04:00
|
|
|
}
|
|
|
|
|
2016-10-31 09:26:01 -04:00
|
|
|
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() ; }
|
2012-10-21 10:06:33 -04:00
|
|
|
|
|
|
|
GroupFlagsWidget::~GroupFlagsWidget()
|
|
|
|
{
|
2016-10-31 09:26:01 -04:00
|
|
|
for(int i=0;i<3;++i)
|
2012-10-21 10:06:33 -04:00
|
|
|
{
|
|
|
|
delete _buttons[i] ;
|
2016-10-31 09:26:01 -04:00
|
|
|
delete _icons[2*i+0] ;
|
|
|
|
delete _icons[2*i+1] ;
|
|
|
|
}
|
2012-10-21 10:06:33 -04:00
|
|
|
}
|
|
|
|
|