mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Saved group ids instead of group names for the group-based file permissions.
Translated group names in Share Manager. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5796 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
786177eaf0
commit
59ed165c81
@ -97,7 +97,7 @@ ShareDialog::ShareDialog(std::string filename, QWidget *parent)
|
|||||||
ui.virtualpath_lineEdit->setText(QString::fromUtf8(it->virtualname.c_str()));
|
ui.virtualpath_lineEdit->setText(QString::fromUtf8(it->virtualname.c_str()));
|
||||||
|
|
||||||
groupflagsbox->setFlags(it->shareflags) ;
|
groupflagsbox->setFlags(it->shareflags) ;
|
||||||
groupselectionbox->setSelectedGroups(it->parent_groups) ;
|
groupselectionbox->setSelectedGroupIds(it->parent_groups) ;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -107,7 +107,9 @@ ShareDialog::ShareDialog(std::string filename, QWidget *parent)
|
|||||||
|
|
||||||
void ShareDialog::updateInfoMessage()
|
void ShareDialog::updateInfoMessage()
|
||||||
{
|
{
|
||||||
messageBox->setText(GroupFlagsWidget::groupInfoString(groupflagsbox->flags(),groupselectionbox->selectedGroups())) ;
|
QList<QString> selectedGroupNames;
|
||||||
|
groupselectionbox->selectedGroupNames(selectedGroupNames);
|
||||||
|
messageBox->setText(GroupFlagsWidget::groupInfoString(groupflagsbox->flags(), selectedGroupNames)) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShareDialog::browseDirectory()
|
void ShareDialog::browseDirectory()
|
||||||
@ -130,7 +132,7 @@ void ShareDialog::addDirectory()
|
|||||||
sdi.filename = ui.localpath_lineEdit->text().toUtf8().constData();
|
sdi.filename = ui.localpath_lineEdit->text().toUtf8().constData();
|
||||||
sdi.virtualname = ui.virtualpath_lineEdit->text().toUtf8().constData();
|
sdi.virtualname = ui.virtualpath_lineEdit->text().toUtf8().constData();
|
||||||
sdi.shareflags = groupflagsbox->flags() ;
|
sdi.shareflags = groupflagsbox->flags() ;
|
||||||
sdi.parent_groups = groupselectionbox->selectedGroups() ;
|
groupselectionbox->selectedGroupIds(sdi.parent_groups);
|
||||||
|
|
||||||
if (ui.localpath_lineEdit->isEnabled())
|
if (ui.localpath_lineEdit->isEnabled())
|
||||||
{
|
{
|
||||||
|
@ -28,11 +28,14 @@
|
|||||||
|
|
||||||
#include <retroshare/rsfiles.h>
|
#include <retroshare/rsfiles.h>
|
||||||
#include <retroshare/rstypes.h>
|
#include <retroshare/rstypes.h>
|
||||||
|
#include <retroshare/rspeers.h>
|
||||||
|
|
||||||
#include "ShareManager.h"
|
#include "ShareManager.h"
|
||||||
#include "ShareDialog.h"
|
#include "ShareDialog.h"
|
||||||
#include "settings/rsharesettings.h"
|
#include "settings/rsharesettings.h"
|
||||||
#include <gui/common/GroupFlagsWidget.h>
|
#include <gui/common/GroupFlagsWidget.h>
|
||||||
|
#include "gui/common/GroupDefs.h"
|
||||||
|
#include "gui/notifyqt.h"
|
||||||
|
|
||||||
/* Images for context menu icons */
|
/* Images for context menu icons */
|
||||||
#define IMAGE_CANCEL ":/images/delete.png"
|
#define IMAGE_CANCEL ":/images/delete.png"
|
||||||
@ -68,6 +71,8 @@ ShareManager::ShareManager()
|
|||||||
connect(ui.shareddirList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(shareddirListCostumPopupMenu(QPoint)));
|
connect(ui.shareddirList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(shareddirListCostumPopupMenu(QPoint)));
|
||||||
connect(ui.shareddirList, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(shareddirListCurrentCellChanged(int,int,int,int)));
|
connect(ui.shareddirList, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(shareddirListCurrentCellChanged(int,int,int,int)));
|
||||||
|
|
||||||
|
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(updateGroups()));
|
||||||
|
|
||||||
ui.editButton->setEnabled(false);
|
ui.editButton->setEnabled(false);
|
||||||
ui.removeButton->setEnabled(false);
|
ui.removeButton->setEnabled(false);
|
||||||
|
|
||||||
@ -133,17 +138,7 @@ void ShareManager::load()
|
|||||||
listWidget->setRowHeight(row, 32);
|
listWidget->setRowHeight(row, 32);
|
||||||
listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget);
|
listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget);
|
||||||
|
|
||||||
QString group_string ;
|
listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem()) ;
|
||||||
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 += ", " ;
|
|
||||||
|
|
||||||
group_string += QString::fromStdString(*it2) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem(group_string)) ;
|
|
||||||
listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ;
|
listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ;
|
||||||
|
|
||||||
connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ;
|
connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ;
|
||||||
@ -157,6 +152,7 @@ void ShareManager::load()
|
|||||||
update();
|
update();
|
||||||
|
|
||||||
isLoading = false ;
|
isLoading = false ;
|
||||||
|
updateGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShareManager::showYourself()
|
void ShareManager::showYourself()
|
||||||
@ -206,6 +202,38 @@ void ShareManager::updateFlags()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShareManager::updateGroups()
|
||||||
|
{
|
||||||
|
if(isLoading)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
std::cerr << "Updating groups" << std::endl;
|
||||||
|
|
||||||
|
std::list<SharedDirInfo>::iterator it;
|
||||||
|
std::list<SharedDirInfo> dirs;
|
||||||
|
rsFiles->getSharedDirectories(dirs);
|
||||||
|
|
||||||
|
int row=0 ;
|
||||||
|
for(it = dirs.begin(); it != dirs.end(); it++,++row)
|
||||||
|
{
|
||||||
|
QTableWidgetItem *item = ui.shareddirList->item(row, COLUMN_GROUPS);
|
||||||
|
|
||||||
|
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 += ", " ;
|
||||||
|
|
||||||
|
RsGroupInfo groupInfo;
|
||||||
|
rsPeers->getGroupInfo(*it2, groupInfo);
|
||||||
|
group_string += GroupDefs::name(groupInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
item->setText(group_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ShareManager::editShareDirectory()
|
void ShareManager::editShareDirectory()
|
||||||
{
|
{
|
||||||
/* id current dir */
|
/* id current dir */
|
||||||
|
@ -60,6 +60,7 @@ private slots:
|
|||||||
void editShareDirectory();
|
void editShareDirectory();
|
||||||
void removeShareDirectory();
|
void removeShareDirectory();
|
||||||
void updateFlags();
|
void updateFlags();
|
||||||
|
void updateGroups();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static ShareManager *_instance;
|
static ShareManager *_instance;
|
||||||
|
@ -119,24 +119,24 @@ void GroupFlagsWidget::update_button_state(bool b,int button_id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags,const std::list<std::string>& groups)
|
QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags, const QList<QString>& groupNames)
|
||||||
{
|
{
|
||||||
// makes a string that explains how files are shared / visible.
|
// makes a string that explains how files are shared / visible.
|
||||||
|
|
||||||
QString res ;
|
QString res ;
|
||||||
QString groups_string ;
|
QString groups_string ;
|
||||||
|
|
||||||
for(std::list<std::string>::const_iterator it(groups.begin());it!=groups.end();++it)
|
for(QList<QString>::const_iterator it(groupNames.begin());it!=groupNames.end();++it)
|
||||||
{
|
{
|
||||||
if(it != groups.begin())
|
if(it != groupNames.begin())
|
||||||
groups_string += ", " ;
|
groups_string += ", " ;
|
||||||
groups_string += QString::fromStdString(*it) ;
|
groups_string += *it ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flags & DIR_FLAGS_BROWSABLE_OTHERS)
|
if(flags & DIR_FLAGS_BROWSABLE_OTHERS)
|
||||||
res += tr("All your friends can browse this directory\n") ;
|
res += tr("All your friends can browse this directory\n") ;
|
||||||
else if(flags & DIR_FLAGS_BROWSABLE_GROUPS)
|
else if(flags & DIR_FLAGS_BROWSABLE_GROUPS)
|
||||||
if(!groups.empty())
|
if(!groupNames.empty())
|
||||||
res += tr("Only friends in groups ") + groups_string + tr(" can browse this directory\n") ;
|
res += tr("Only friends in groups ") + groups_string + tr(" can browse this directory\n") ;
|
||||||
else
|
else
|
||||||
res += tr("No one can browse this directory\n") ;
|
res += tr("No one can browse this directory\n") ;
|
||||||
|
@ -16,7 +16,8 @@ class GroupFlagsWidget: public QWidget
|
|||||||
FileStorageFlags flags() const ;
|
FileStorageFlags flags() const ;
|
||||||
void setFlags(FileStorageFlags flags) ;
|
void setFlags(FileStorageFlags flags) ;
|
||||||
|
|
||||||
static QString groupInfoString(FileStorageFlags flags,const std::list<std::string>& groups) ;
|
static QString groupInfoString(FileStorageFlags flags, const QList<QString> &groupNames) ;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updated() ;
|
void updated() ;
|
||||||
|
|
||||||
|
@ -1,43 +1,80 @@
|
|||||||
#include <retroshare/rspeers.h>
|
#include <retroshare/rspeers.h>
|
||||||
#include "GroupSelectionBox.h"
|
#include "GroupSelectionBox.h"
|
||||||
|
#include "GroupDefs.h"
|
||||||
|
#include "gui/notifyqt.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#define ROLE_ID Qt::UserRole
|
||||||
|
|
||||||
GroupSelectionBox::GroupSelectionBox(QWidget *parent)
|
GroupSelectionBox::GroupSelectionBox(QWidget *parent)
|
||||||
: QListWidget(parent)
|
: QListWidget(parent)
|
||||||
{
|
{
|
||||||
setSelectionMode(QAbstractItemView::ExtendedSelection) ;
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
|
||||||
|
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(fillGroups()));
|
||||||
|
|
||||||
// Fill with available groups
|
// Fill with available groups
|
||||||
|
fillGroups();
|
||||||
std::list<RsGroupInfo> lst ;
|
|
||||||
rsPeers->getGroupInfoList(lst) ;
|
|
||||||
|
|
||||||
for(std::list<RsGroupInfo>::const_iterator it(lst.begin());it!=lst.end();++it)
|
|
||||||
addItem(QString::fromStdString(it->id)) ;
|
|
||||||
|
|
||||||
for(int i=0;i<count();++i)
|
|
||||||
item(i)->setBackgroundColor(QColor(183,236,181)) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<std::string> GroupSelectionBox::selectedGroups() const
|
void GroupSelectionBox::fillGroups()
|
||||||
{
|
{
|
||||||
QList<QListWidgetItem*> selected_items = selectedItems() ;
|
std::list<std::string> selectedIds;
|
||||||
std::list<std::string> out ;
|
selectedGroupIds(selectedIds);
|
||||||
|
|
||||||
for(QList<QListWidgetItem*>::const_iterator it(selected_items.begin());it!=selected_items.end();++it)
|
clear();
|
||||||
|
|
||||||
|
std::list<RsGroupInfo> groupIds;
|
||||||
|
rsPeers->getGroupInfoList(groupIds);
|
||||||
|
|
||||||
|
for (std::list<RsGroupInfo>::const_iterator it(groupIds.begin()); it != groupIds.end(); ++it) {
|
||||||
|
QListWidgetItem *item = new QListWidgetItem(GroupDefs::name(*it));
|
||||||
|
item->setData(ROLE_ID, QString::fromStdString(it->id));
|
||||||
|
item->setBackgroundColor(QColor(183,236,181));
|
||||||
|
addItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedGroupIds(selectedIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroupSelectionBox::selectedGroupIds(std::list<std::string> &groupIds) const
|
||||||
{
|
{
|
||||||
out.push_back((*it)->text().toStdString()) ;
|
int itemCount = count();
|
||||||
std::cerr << "Addign selected item " << out.back() << std::endl;
|
|
||||||
|
for (int i = 0; i < itemCount; ++i) {
|
||||||
|
QListWidgetItem *listItem = item(i);
|
||||||
|
if (listItem->checkState() == Qt::Checked) {
|
||||||
|
groupIds.push_back(item(i)->data(ROLE_ID).toString().toStdString());
|
||||||
|
std::cerr << "Addign selected item " << groupIds.back() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out ;
|
void GroupSelectionBox::setSelectedGroupIds(const std::list<std::string>& groupIds)
|
||||||
}
|
|
||||||
|
|
||||||
void GroupSelectionBox::setSelectedGroups(const std::list<std::string>& group_ids)
|
|
||||||
{
|
{
|
||||||
for(std::list<std::string>::const_iterator it(group_ids.begin());it!=group_ids.end();++it)
|
int itemCount = count();
|
||||||
{
|
|
||||||
QList<QListWidgetItem*> lst = findItems(QString::fromStdString(*it),Qt::MatchExactly) ;
|
|
||||||
|
|
||||||
setCurrentItem(*lst.begin(),QItemSelectionModel::Select) ;
|
for (int i = 0; i < itemCount; ++i) {
|
||||||
|
QListWidgetItem *listItem = item(i);
|
||||||
|
|
||||||
|
if (std::find(groupIds.begin(), groupIds.end(), listItem->data(ROLE_ID).toString().toStdString()) != groupIds.end()) {
|
||||||
|
listItem->setCheckState(Qt::Checked);
|
||||||
|
} else {
|
||||||
|
listItem->setCheckState(Qt::Unchecked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GroupSelectionBox::selectedGroupNames(QList<QString> &groupNames) const
|
||||||
|
{
|
||||||
|
int itemCount = count();
|
||||||
|
|
||||||
|
for (int i = 0; i < itemCount; ++i) {
|
||||||
|
QListWidgetItem *listItem = item(i);
|
||||||
|
if (listItem->checkState() == Qt::Checked) {
|
||||||
|
groupNames.push_back(item(i)->text());
|
||||||
|
std::cerr << "Addign selected item " << groupNames.back().toUtf8().constData() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,16 @@
|
|||||||
|
|
||||||
class GroupSelectionBox: public QListWidget
|
class GroupSelectionBox: public QListWidget
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GroupSelectionBox(QWidget *parent);
|
GroupSelectionBox(QWidget *parent);
|
||||||
|
|
||||||
std::list<std::string> selectedGroups() const ;
|
void selectedGroupIds(std::list<std::string> &groupIds) const;
|
||||||
|
void selectedGroupNames(QList<QString> &groupNames) const;
|
||||||
|
|
||||||
void setSelectedGroups(const std::list<std::string>& selected_group_ids) ;
|
void setSelectedGroupIds(const std::list<std::string> &groupIds);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void fillGroups();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user