mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-28 10:32:22 -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
7 changed files with 122 additions and 47 deletions
|
@ -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.
|
||||
|
||||
QString res ;
|
||||
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 += QString::fromStdString(*it) ;
|
||||
groups_string += *it ;
|
||||
}
|
||||
|
||||
if(flags & DIR_FLAGS_BROWSABLE_OTHERS)
|
||||
res += tr("All your friends can browse this directory\n") ;
|
||||
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") ;
|
||||
else
|
||||
res += tr("No one can browse this directory\n") ;
|
||||
|
|
|
@ -16,7 +16,8 @@ class GroupFlagsWidget: public QWidget
|
|||
FileStorageFlags flags() const ;
|
||||
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:
|
||||
void updated() ;
|
||||
|
||||
|
|
|
@ -1,43 +1,80 @@
|
|||
#include <retroshare/rspeers.h>
|
||||
#include "GroupSelectionBox.h"
|
||||
#include "GroupDefs.h"
|
||||
#include "gui/notifyqt.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#define ROLE_ID Qt::UserRole
|
||||
|
||||
GroupSelectionBox::GroupSelectionBox(QWidget *parent)
|
||||
: QListWidget(parent)
|
||||
{
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection) ;
|
||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(fillGroups()));
|
||||
|
||||
// Fill with available groups
|
||||
|
||||
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)) ;
|
||||
fillGroups();
|
||||
}
|
||||
|
||||
std::list<std::string> GroupSelectionBox::selectedGroups() const
|
||||
void GroupSelectionBox::fillGroups()
|
||||
{
|
||||
QList<QListWidgetItem*> selected_items = selectedItems() ;
|
||||
std::list<std::string> out ;
|
||||
std::list<std::string> selectedIds;
|
||||
selectedGroupIds(selectedIds);
|
||||
|
||||
for(QList<QListWidgetItem*>::const_iterator it(selected_items.begin());it!=selected_items.end();++it)
|
||||
{
|
||||
out.push_back((*it)->text().toStdString()) ;
|
||||
std::cerr << "Addign selected item " << out.back() << std::endl;
|
||||
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);
|
||||
}
|
||||
|
||||
return out ;
|
||||
setSelectedGroupIds(selectedIds);
|
||||
}
|
||||
|
||||
void GroupSelectionBox::setSelectedGroups(const std::list<std::string>& group_ids)
|
||||
void GroupSelectionBox::selectedGroupIds(std::list<std::string> &groupIds) const
|
||||
{
|
||||
for(std::list<std::string>::const_iterator it(group_ids.begin());it!=group_ids.end();++it)
|
||||
{
|
||||
QList<QListWidgetItem*> lst = findItems(QString::fromStdString(*it),Qt::MatchExactly) ;
|
||||
int itemCount = count();
|
||||
|
||||
setCurrentItem(*lst.begin(),QItemSelectionModel::Select) ;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GroupSelectionBox::setSelectedGroupIds(const std::list<std::string>& groupIds)
|
||||
{
|
||||
int itemCount = count();
|
||||
|
||||
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
|
||||
{
|
||||
public:
|
||||
GroupSelectionBox(QWidget *parent) ;
|
||||
Q_OBJECT
|
||||
|
||||
std::list<std::string> selectedGroups() const ;
|
||||
public:
|
||||
GroupSelectionBox(QWidget *parent);
|
||||
|
||||
void setSelectedGroups(const std::list<std::string>& selected_group_ids) ;
|
||||
void selectedGroupIds(std::list<std::string> &groupIds) const;
|
||||
void selectedGroupNames(QList<QString> &groupNames) const;
|
||||
|
||||
void setSelectedGroupIds(const std::list<std::string> &groupIds);
|
||||
|
||||
private slots:
|
||||
void fillGroups();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue