First bit of group sharing permissions

- Added icons for share flags
- added new class to handle sharing permission widget
- Updated share manager
to be continued...



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-FileSharingPermissions@5701 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-10-21 14:06:33 +00:00
parent 4f8fd59a16
commit 56e26ba00a
13 changed files with 163 additions and 77 deletions

View File

@ -73,8 +73,12 @@ const uint32_t RS_FILE_HINTS_DOWNLOAD = 0x00000010;
const uint32_t RS_FILE_HINTS_UPLOAD = 0x00000020;
const uint32_t RS_FILE_HINTS_NETWORK_WIDE = 0x00000080; // anonymously shared over network
const uint32_t RS_FILE_HINTS_BROWSABLE = 0x00000100; // browsable by friends
const uint32_t RS_FILE_HINTS_BROWSABLE = 0x00000100; // browsable by friends
const uint32_t RS_FILE_HINTS_NETWORK_WIDE_OTHERS = 0x00000080; // anonymously shared over network
const uint32_t RS_FILE_HINTS_BROWSABLE_OTHERS = 0x00000100; // browsable by friends
const uint32_t RS_FILE_HINTS_ASSUME_AVAILABILITY = 0x00000200; // Assume full source availability. Used for cache files.
const uint32_t RS_FILE_HINTS_NETWORK_WIDE_GROUPS = 0x00000400; // anonymously shared over network
const uint32_t RS_FILE_HINTS_BROWSABLE_GROUPS = 0x00000800; // browsable by friends
const uint32_t RS_FILE_HINTS_MEDIA = 0x00001000;
const uint32_t RS_FILE_HINTS_BACKGROUND = 0x00002000; // To download slowly.

View File

@ -31,6 +31,7 @@
#include "ShareManager.h"
#include "ShareDialog.h"
#include "settings/rsharesettings.h"
#include <gui/common/GroupFlagsWidget.h>
/* Images for context menu icons */
#define IMAGE_CANCEL ":/images/delete.png"
@ -38,9 +39,8 @@
#define COLUMN_PATH 0
#define COLUMN_VIRTUALNAME 1
#define COLUMN_NETWORKWIDE 2
#define COLUMN_BROWSABLE 3
#define COLUMN_COUNT 3
#define COLUMN_SHARE_FLAGS 2
#define COLUMN_GROUPS 3
ShareManager *ShareManager::_instance = NULL ;
@ -73,15 +73,12 @@ ShareManager::ShareManager(QWidget *parent, Qt::WFlags flags)
QHeaderView* header = ui.shareddirList->horizontalHeader();
header->setResizeMode( COLUMN_PATH, QHeaderView::Stretch);
header->setResizeMode(COLUMN_NETWORKWIDE, QHeaderView::Fixed);
header->setResizeMode(COLUMN_BROWSABLE, QHeaderView::Fixed);
//header->setResizeMode(COLUMN_NETWORKWIDE, QHeaderView::Fixed);
//header->setResizeMode(COLUMN_BROWSABLE, QHeaderView::Fixed);
header->setHighlightSections(false);
ui.shareddirList->setRangeSelected(QTableWidgetSelectionRange(0, 0, 0, COLUMN_COUNT), true);
setAcceptDrops(true);
setAttribute(Qt::WA_DeleteOnClose, true);
}
@ -126,75 +123,16 @@ void ShareManager::load()
connect(this,SIGNAL(itemClicked(QTableWidgetItem*)),this,SLOT(updateFlags(QTableWidgetItem*))) ;
#ifndef USE_COMBOBOX
QString ToolTips [2] = { tr("If checked, the share is anonymously shared to anybody."),
tr("If checked, the share is browsable by your friends.") };
int Flags [2] = { RS_FILE_HINTS_NETWORK_WIDE, RS_FILE_HINTS_BROWSABLE };
#endif
int row=0 ;
for(it = dirs.begin(); it != dirs.end(); it++,++row)
{
listWidget->setItem(row, COLUMN_PATH, new QTableWidgetItem(QString::fromUtf8((*it).filename.c_str())));
listWidget->setItem(row, COLUMN_VIRTUALNAME, new QTableWidgetItem(QString::fromUtf8((*it).virtualname.c_str())));
#ifdef USE_COMBOBOX
QComboBox *cb = new QComboBox ;
cb->addItem(QString("Network Wide")) ;
cb->addItem(QString("Browsable")) ;
cb->addItem(QString("Universal")) ;
QWidget* widget = new GroupFlagsWidget(NULL,(*it).shareflags);
cb->setToolTip(QString("Decide here whether this directory is\n* Network Wide: \tanonymously shared over the network (including your friends)\n* Browsable: \tbrowsable by your friends\n* Universal: \t\tboth")) ;
// TODO
// - set combobox current value depending on what rsFiles reports.
// - use a signal mapper to get the correct row that contains the combo box sending the signal:
// mapper = new SignalMapper(this) ;
//
// for(all cb)
// {
// signalMapper->setMapping(cb,...)
// }
//
int index = 0 ;
index += ((*it).shareflags & RS_FILE_HINTS_NETWORK_WIDE) > 0 ;
index += (((*it).shareflags & RS_FILE_HINTS_BROWSABLE) > 0) * 2 ;
listWidget->setCellWidget(row,1,cb);
if(index < 1 || index > 3)
std::cerr << "******* ERROR IN FILE SHARING FLAGS. Flags = " << (*it).shareflags << " ***********" << std::endl ;
else
index-- ;
cb->setCurrentIndex(index) ;
#else
int col;
for (col = 0; col <= 1; col++) {
QModelIndex index = listWidget->model()->index(row, col + COLUMN_NETWORKWIDE, QModelIndex());
QWidget* widget = dynamic_cast<QWidget*>(listWidget->indexWidget(index));
QCheckBox* cb = NULL;
if (widget) {
cb = dynamic_cast<QCheckBox*>(widget->children().front());
}
if (cb == NULL) {
QWidget* widget = new QWidget;
cb = new QCheckBox(widget);
cb->setToolTip(ToolTips [col]);
QHBoxLayout* layout = new QHBoxLayout(widget);
layout->addWidget(cb, 0, Qt::AlignCenter);
layout->setSpacing(0);
layout->setContentsMargins(10, 0, 0, 0); // to be centered
widget->setLayout(layout);
listWidget->setCellWidget(row, col + COLUMN_NETWORKWIDE, widget);
QObject::connect(cb, SIGNAL(toggled(bool)), this, SLOT(updateFlags(bool))) ;
}
cb->setChecked((*it).shareflags & Flags [col]);
}
#endif
//listWidget->setRowHeight(row, 32);
listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget);
}
//ui.incomingDir->setText(QString::fromStdString(rsFiles->getDownloadDirectory()));
@ -240,16 +178,14 @@ void ShareManager::updateFlags(bool b)
for(it = dirs.begin(); it != dirs.end(); it++,++row)
{
std::cerr << "Looking for row=" << row << ", file=" << (*it).filename << ", flags=" << (*it).shareflags << std::endl ;
uint32_t current_flags = 0 ;
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,COLUMN_NETWORKWIDE)->children().front()))->isChecked()? RS_FILE_HINTS_NETWORK_WIDE:0 ;
current_flags |= (dynamic_cast<QCheckBox*>(ui.shareddirList->cellWidget(row,COLUMN_BROWSABLE)->children().front()))->isChecked()? RS_FILE_HINTS_BROWSABLE:0 ;
uint32_t current_flags = (dynamic_cast<GroupFlagsWidget*>(ui.shareddirList->cellWidget(row,COLUMN_SHARE_FLAGS)->children().front()))->flags() ;
if( (*it).shareflags ^ current_flags )
{
(*it).shareflags = current_flags ;
rsFiles->updateShareFlags(*it) ; // modifies the flags
std::cout << "Updating share flags for directory " << (*it).filename << std::endl ;
std::cout << "Updating share flags for directory " << (*it).filename << " to " << current_flags << std::endl ;
}
}
}

View File

@ -108,7 +108,7 @@ p, li { white-space: pre-wrap; }
</column>
<column>
<property name="text">
<string>Network Wide</string>
<string>Share flags</string>
</property>
<property name="toolTip">
<string comment="If activated, the share is anonymously accessible to anybody"/>
@ -116,7 +116,7 @@ p, li { white-space: pre-wrap; }
</column>
<column>
<property name="text">
<string>Browsable</string>
<string>Parent groups</string>
</property>
<property name="toolTip">
<string comment="If checked, the share is browsable by your friends"/>

View File

@ -0,0 +1,101 @@
#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
GroupFlagsWidget::GroupFlagsWidget(QWidget *parent,uint32_t flags)
: QWidget(parent)
{
_layout = new QHBoxLayout(this) ;
_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) ;
_flags[0] = RS_FILE_HINTS_BROWSABLE_GROUPS ;
_flags[1] = RS_FILE_HINTS_NETWORK_WIDE_GROUPS ;
_flags[2] = RS_FILE_HINTS_BROWSABLE_OTHERS ;
_flags[3] = RS_FILE_HINTS_NETWORK_WIDE_OTHERS ;
for(int i=0;i<4;++i)
{
_buttons[i] = new QPushButton(this) ;
_buttons[i]->setCheckable(true) ;
_buttons[i]->setChecked(flags & _flags[i]) ;
//_buttons[i]->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
//_buttons[i]->setMinimumSize(32,32);
update_button_state(_buttons[i]->isChecked(),i) ;
_layout->addWidget(_buttons[i]) ;
}
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);
_layout->setContentsMargins(10, 0, 0, 0);
_layout->update() ;
}
void GroupFlagsWidget::updated()
{
emit flagsChanged(flags()) ;
}
uint32_t GroupFlagsWidget::flags() const
{
uint32_t flags = 0x0 ;
for(int i=0;i<4;++i)
if(_buttons[i]->isChecked()) flags |= _flags[i] ;
return flags ;
}
void GroupFlagsWidget::update_button_state(bool b,int button_id)
{
if(b)
_buttons[button_id]->setIcon(*_icons[button_id]) ;
else if(button_id == INDEX_GROUP_NETWORK_W || button_id == INDEX_GROUP_BROWSABLE)
_buttons[button_id]->setIcon(*_icons[INDEX_GROUP_UNCHECKED]) ;
else
_buttons[button_id]->setIcon(*_icons[INDEX_OTHER_UNCHECKED]) ;
}
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] ;
}

View File

@ -0,0 +1,37 @@
#pragma once
#include <stdint.h>
#include <QPushButton>
#include <QWidget>
class GroupFlagsWidget: public QWidget
{
Q_OBJECT
public:
GroupFlagsWidget(QWidget *parent,uint32_t flags) ;
virtual ~GroupFlagsWidget() ;
uint32_t flags() const ;
public slots:
void updated() ;
protected slots:
void update_GN_button(bool) ;
void update_GB_button(bool) ;
void update_ON_button(bool) ;
void update_OB_button(bool) ;
signals:
void flagsChanged(uint32_t) const ;
private:
void update_button_state(bool b,int id) ;
QPushButton *_buttons[4] ;
QLayout *_layout ;
QIcon *_icons[6] ;
uint32_t _flags[4] ;
};

View File

@ -1,5 +1,11 @@
<RCC>
<qresource prefix="/" >
<file>images/anonymous_128_green.png</file>
<file>images/anonymous_128_blue.png</file>
<file>images/browsable_128_green.png</file>
<file>images/browsable_128_blue.png</file>
<file>images/blank_128_green.png</file>
<file>images/blank_128_blue.png</file>
<file>images/splash.png</file>
<file>images/help/addafriend.png</file>
<file>images/help/addfriendkey.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -356,6 +356,7 @@ HEADERS += rshare.h \
gui/common/rwindow.h \
gui/common/html.h \
gui/common/AvatarDefs.h \
gui/common/GroupFlagsWidget.h \
gui/common/StatusDefs.h \
gui/common/TagDefs.h \
gui/common/GroupDefs.h \
@ -618,6 +619,7 @@ SOURCES += main.cpp \
gui/common/rwindow.cpp \
gui/common/html.cpp \
gui/common/AvatarDefs.cpp \
gui/common/GroupFlagsWidget.cpp \
gui/common/StatusDefs.cpp \
gui/common/TagDefs.cpp \
gui/common/GroupDefs.cpp \