From 59ed165c8159b171a13ef2e88875362fff43a41c Mon Sep 17 00:00:00 2001 From: thunder2 Date: Fri, 9 Nov 2012 00:46:41 +0000 Subject: [PATCH] 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 --- retroshare-gui/src/gui/ShareDialog.cpp | 8 +- retroshare-gui/src/gui/ShareManager.cpp | 50 ++++++++--- retroshare-gui/src/gui/ShareManager.h | 1 + .../src/gui/common/GroupFlagsWidget.cpp | 10 +-- .../src/gui/common/GroupFlagsWidget.h | 3 +- .../src/gui/common/GroupSelectionBox.cpp | 83 ++++++++++++++----- .../src/gui/common/GroupSelectionBox.h | 14 +++- 7 files changed, 122 insertions(+), 47 deletions(-) diff --git a/retroshare-gui/src/gui/ShareDialog.cpp b/retroshare-gui/src/gui/ShareDialog.cpp index 39c5c31e7..d35deca0c 100644 --- a/retroshare-gui/src/gui/ShareDialog.cpp +++ b/retroshare-gui/src/gui/ShareDialog.cpp @@ -97,7 +97,7 @@ ShareDialog::ShareDialog(std::string filename, QWidget *parent) ui.virtualpath_lineEdit->setText(QString::fromUtf8(it->virtualname.c_str())); groupflagsbox->setFlags(it->shareflags) ; - groupselectionbox->setSelectedGroups(it->parent_groups) ; + groupselectionbox->setSelectedGroupIds(it->parent_groups) ; break; } @@ -107,7 +107,9 @@ ShareDialog::ShareDialog(std::string filename, QWidget *parent) void ShareDialog::updateInfoMessage() { - messageBox->setText(GroupFlagsWidget::groupInfoString(groupflagsbox->flags(),groupselectionbox->selectedGroups())) ; + QList selectedGroupNames; + groupselectionbox->selectedGroupNames(selectedGroupNames); + messageBox->setText(GroupFlagsWidget::groupInfoString(groupflagsbox->flags(), selectedGroupNames)) ; } void ShareDialog::browseDirectory() @@ -130,7 +132,7 @@ void ShareDialog::addDirectory() sdi.filename = ui.localpath_lineEdit->text().toUtf8().constData(); sdi.virtualname = ui.virtualpath_lineEdit->text().toUtf8().constData(); sdi.shareflags = groupflagsbox->flags() ; - sdi.parent_groups = groupselectionbox->selectedGroups() ; + groupselectionbox->selectedGroupIds(sdi.parent_groups); if (ui.localpath_lineEdit->isEnabled()) { diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index 8e5734571..509e8bcb7 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -28,11 +28,14 @@ #include #include +#include #include "ShareManager.h" #include "ShareDialog.h" #include "settings/rsharesettings.h" #include +#include "gui/common/GroupDefs.h" +#include "gui/notifyqt.h" /* Images for context menu icons */ #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(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.removeButton->setEnabled(false); @@ -133,17 +138,7 @@ void ShareManager::load() listWidget->setRowHeight(row, 32); listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget); - QString group_string ; - int n=0; - for(std::list::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->setItem(row, COLUMN_GROUPS, new QTableWidgetItem()) ; listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ; connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ; @@ -157,6 +152,7 @@ void ShareManager::load() update(); isLoading = false ; + updateGroups(); } void ShareManager::showYourself() @@ -206,6 +202,38 @@ void ShareManager::updateFlags() } } +void ShareManager::updateGroups() +{ + if(isLoading) + return ; + + std::cerr << "Updating groups" << std::endl; + + std::list::iterator it; + std::list 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::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() { /* id current dir */ diff --git a/retroshare-gui/src/gui/ShareManager.h b/retroshare-gui/src/gui/ShareManager.h index 0dc9d8c6e..79f284e58 100644 --- a/retroshare-gui/src/gui/ShareManager.h +++ b/retroshare-gui/src/gui/ShareManager.h @@ -60,6 +60,7 @@ private slots: void editShareDirectory(); void removeShareDirectory(); void updateFlags(); + void updateGroups(); private: static ShareManager *_instance; diff --git a/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp b/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp index 999f67842..fee63c69e 100644 --- a/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp +++ b/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp @@ -119,24 +119,24 @@ void GroupFlagsWidget::update_button_state(bool b,int button_id) } } -QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags,const std::list& groups) +QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags, const QList& groupNames) { // makes a string that explains how files are shared / visible. QString res ; QString groups_string ; - for(std::list::const_iterator it(groups.begin());it!=groups.end();++it) + for(QList::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") ; diff --git a/retroshare-gui/src/gui/common/GroupFlagsWidget.h b/retroshare-gui/src/gui/common/GroupFlagsWidget.h index 1aa288833..35d54ecce 100644 --- a/retroshare-gui/src/gui/common/GroupFlagsWidget.h +++ b/retroshare-gui/src/gui/common/GroupFlagsWidget.h @@ -16,7 +16,8 @@ class GroupFlagsWidget: public QWidget FileStorageFlags flags() const ; void setFlags(FileStorageFlags flags) ; - static QString groupInfoString(FileStorageFlags flags,const std::list& groups) ; + static QString groupInfoString(FileStorageFlags flags, const QList &groupNames) ; + public slots: void updated() ; diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.cpp b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp index 4f01bd065..55317115d 100644 --- a/retroshare-gui/src/gui/common/GroupSelectionBox.cpp +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp @@ -1,43 +1,80 @@ #include #include "GroupSelectionBox.h" +#include "GroupDefs.h" +#include "gui/notifyqt.h" + +#include + +#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 lst ; - rsPeers->getGroupInfoList(lst) ; - - for(std::list::const_iterator it(lst.begin());it!=lst.end();++it) - addItem(QString::fromStdString(it->id)) ; - - for(int i=0;isetBackgroundColor(QColor(183,236,181)) ; + fillGroups(); } -std::list GroupSelectionBox::selectedGroups() const +void GroupSelectionBox::fillGroups() { - QList selected_items = selectedItems() ; - std::list out ; + std::list selectedIds; + selectedGroupIds(selectedIds); - for(QList::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 groupIds; + rsPeers->getGroupInfoList(groupIds); + + for (std::list::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& group_ids) +void GroupSelectionBox::selectedGroupIds(std::list &groupIds) const { - for(std::list::const_iterator it(group_ids.begin());it!=group_ids.end();++it) - { - QList 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& 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 &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; + } } } diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.h b/retroshare-gui/src/gui/common/GroupSelectionBox.h index 48deeee98..f8e8477fb 100644 --- a/retroshare-gui/src/gui/common/GroupSelectionBox.h +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.h @@ -2,10 +2,16 @@ class GroupSelectionBox: public QListWidget { - public: - GroupSelectionBox(QWidget *parent) ; + Q_OBJECT - std::list selectedGroups() const ; +public: + GroupSelectionBox(QWidget *parent); - void setSelectedGroups(const std::list& selected_group_ids) ; + void selectedGroupIds(std::list &groupIds) const; + void selectedGroupNames(QList &groupNames) const; + + void setSelectedGroupIds(const std::list &groupIds); + +private slots: + void fillGroups(); };