Merged branch that provide group-based file permissions.

Now users can sort peers into groups in the friend list, and attribute flags and parent groups to the
directories in the share manager.

Flags are B-B-N, meaning in order:
- browsable for peers in the parent groups
- browsable for everyone
- network wide for everyone
Backward compatibility makes previously BN flags been interpreted as -BN, meaning browsable/network wide for everyone.

Be careful with this new feature. It has been tested, but it's a bit early to rely on it for highly sensitive data.

The merge also includes a significant improvement of the naming of flags with incompatible types
which should sort out some existing bugs as well, since inconsistencies in flag usage have been
found during the process.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5787 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-11-07 20:03:16 +00:00
commit 6edb9eb4f8
64 changed files with 1389 additions and 824 deletions

View file

@ -27,10 +27,12 @@
#include <QUrl>
#include <retroshare/rsfiles.h>
#include <retroshare/rstypes.h>
#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 +40,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 +74,12 @@ ShareManager::ShareManager()
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);
}
@ -124,79 +122,35 @@ void ShareManager::load()
/* set new row count */
listWidget->setRowCount(dirs.size());
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")) ;
GroupFlagsWidget *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")) ;
listWidget->setRowHeight(row, 32);
listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget);
// 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);
QString group_string ;
int n=0;
for(std::list<std::string>::const_iterator it2((*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2,++n)
{
if(n>0)
group_string += ", " ;
if(index < 1 || index > 3)
std::cerr << "******* ERROR IN FILE SHARING FLAGS. Flags = " << (*it).shareflags << " ***********" << std::endl ;
else
index-- ;
group_string += QString::fromStdString(*it2) ;
}
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;
listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem(group_string)) ;
listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ;
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
connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ;
}
listWidget->setColumnWidth(COLUMN_SHARE_FLAGS,132) ;
//ui.incomingDir->setText(QString::fromStdString(rsFiles->getDownloadDirectory()));
listWidget->update(); /* update display */
@ -225,12 +179,12 @@ void ShareManager::showYourself()
}
}
void ShareManager::updateFlags(bool b)
void ShareManager::updateFlags()
{
if(isLoading)
return ;
std::cerr << "Updating flags (b=" << b << ") !!!" << std::endl ;
std::cerr << "Updating flags" << std::endl;
std::list<SharedDirInfo>::iterator it;
std::list<SharedDirInfo> dirs;
@ -239,17 +193,15 @@ void ShareManager::updateFlags(bool b)
int row=0 ;
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 ;
//std::cerr << "Looking for row=" << row << ", file=" << (*it).filename << ", flags=" << (*it).shareflags << std::endl ;
FileStorageFlags current_flags = (dynamic_cast<GroupFlagsWidget*>(ui.shareddirList->cellWidget(row,COLUMN_SHARE_FLAGS)))->flags() ;
if( (*it).shareflags ^ current_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 ;
}
}
}
@ -357,7 +309,7 @@ void ShareManager::dropEvent(QDropEvent *event)
sdi.filename = localpath.toUtf8().constData();
sdi.virtualname.clear();
sdi.shareflags = 0;
sdi.shareflags.clear() ;
/* add new share */
rsFiles->addSharedDirectory(sdi);