added widget for group selection. Used it in share dialog

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-FileSharingPermissions@5761 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-11-02 17:26:20 +00:00
parent bd37e78884
commit ccd08df35d
8 changed files with 99 additions and 55 deletions

View File

@ -27,6 +27,10 @@
#include <QFileDialog>
#include <QMessageBox>
#include <QComboBox>
#include <QGroupBox>
#include <gui/common/GroupSelectionBox.h>
#include <gui/common/GroupFlagsWidget.h>
/** Default constructor */
ShareDialog::ShareDialog(std::string filename, QWidget *parent, Qt::WFlags flags)
@ -44,16 +48,26 @@ ShareDialog::ShareDialog(std::string filename, QWidget *parent, Qt::WFlags flags
ui.okButton->setEnabled(false);
if (filename.empty()) {
ui.networkwideCheckBox->setChecked(true);
} else {
/* edit exisiting share */
QHBoxLayout *hbox = new QHBoxLayout ;
ui.shareflags_GB->setLayout(hbox) ;
groupselectionbox = new GroupSelectionBox(ui.shareflags_GB) ;
groupflagsbox = new GroupFlagsWidget(ui.shareflags_GB) ;
hbox->addWidget(groupselectionbox) ;
hbox->addWidget(groupflagsbox) ;
update() ;
if (!filename.empty())
{
std::list<SharedDirInfo> dirs;
rsFiles->getSharedDirectories(dirs);
std::list<SharedDirInfo>::const_iterator it;
for (it = dirs.begin(); it != dirs.end(); it++) {
if (it->filename == filename) {
if (it->filename == filename)
{
/* fill dialog */
ui.okButton->setEnabled(true);
@ -62,8 +76,9 @@ ShareDialog::ShareDialog(std::string filename, QWidget *parent, Qt::WFlags flags
ui.browseButton->setDisabled(true);
ui.virtualpath_lineEdit->setText(QString::fromUtf8(it->virtualname.c_str()));
ui.browsableCheckBox->setChecked(it->shareflags & DIR_FLAGS_BROWSABLE_OTHERS);
ui.networkwideCheckBox->setChecked(it->shareflags & DIR_FLAGS_NETWORK_WIDE_OTHERS);
groupflagsbox->setFlags(it->shareflags) ;
groupselectionbox->setSelectedGroups(it->parent_groups) ;
break;
}
}
@ -89,20 +104,16 @@ void ShareDialog::addDirectory()
SharedDirInfo sdi ;
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() ;
sdi.shareflags.clear() ;
if (ui.browsableCheckBox->isChecked()) {
sdi.shareflags |= DIR_FLAGS_BROWSABLE_OTHERS ;
}
if (ui.networkwideCheckBox->isChecked()) {
sdi.shareflags |= DIR_FLAGS_NETWORK_WIDE_OTHERS;
}
if (ui.localpath_lineEdit->isEnabled()) {
if (ui.localpath_lineEdit->isEnabled())
{
/* add new share */
rsFiles->addSharedDirectory(sdi);
} else {
}
else
{
/* edit exisiting share */
bool found = false;
@ -116,6 +127,7 @@ void ShareDialog::addDirectory()
if (it->virtualname != sdi.virtualname) {
/* virtual name changed, remove shared directory and add it again */
rsFiles->removeSharedDirectory(it->filename);
rsFiles->addSharedDirectory(sdi);
break;

View File

@ -26,6 +26,9 @@
#include "ui_ShareDialog.h"
class GroupFlagsWidget ;
class GroupSelectionBox ;
class ShareDialog : public QDialog
{
Q_OBJECT
@ -42,6 +45,9 @@ private slots:
private:
/** Qt Designer generated object */
Ui::ShareDialog ui;
GroupSelectionBox *groupselectionbox ;
GroupFlagsWidget *groupflagsbox ;
};
#endif

View File

@ -109,45 +109,11 @@
</layout>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_2">
<widget class="QGroupBox" name="shareflags_GB">
<property name="title">
<string>Share Flags</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="browsableCheckBox">
<property name="toolTip">
<string>Browseable by Friends</string>
</property>
<property name="text">
<string>Browsable</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="networkwideCheckBox">
<property name="toolTip">
<string>Anonymous shared Network Wide</string>
</property>
<property name="text">
<string>Network Wide</string>
</property>
</widget>
</item>
</layout>
<layout class="QGridLayout" name="gridLayout_5"/>
</widget>
</item>
</layout>

View File

@ -89,6 +89,15 @@ FileStorageFlags GroupFlagsWidget::flags() const
return flags ;
}
void GroupFlagsWidget::setFlags(FileStorageFlags flags)
{
for(int i=0;i<4;++i)
{
_buttons[i]->setChecked(flags & _flags[i]) ;
update_button_state(_buttons[i]->isChecked(),i) ;
}
}
void GroupFlagsWidget::update_button_state(bool b,int button_id)
{
if(b)

View File

@ -10,10 +10,11 @@ class GroupFlagsWidget: public QWidget
Q_OBJECT
public:
GroupFlagsWidget(QWidget *parent,FileStorageFlags flags) ;
GroupFlagsWidget(QWidget *parent,FileStorageFlags flags = FileStorageFlags(0u)) ;
virtual ~GroupFlagsWidget() ;
FileStorageFlags flags() const ;
void setFlags(FileStorageFlags flags) ;
public slots:
void updated() ;

View File

@ -0,0 +1,37 @@
#include <retroshare/rspeers.h>
#include "GroupSelectionBox.h"
GroupSelectionBox::GroupSelectionBox(QWidget *parent)
: QListWidget(parent)
{
setSelectionMode(QAbstractItemView::ExtendedSelection) ;
// 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)) ;
}
std::list<std::string> GroupSelectionBox::selectedGroups() const
{
QList<QListWidgetItem*> selected_items = selectedItems() ;
std::list<std::string> out ;
for(QList<QListWidgetItem*>::const_iterator it(selected_items.begin());it!=selected_items.end();++it)
out.push_back((*it)->text().toStdString()) ;
return out ;
}
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)
{
QList<QListWidgetItem*> lst = findItems(QString::fromStdString(*it),Qt::MatchExactly) ;
setCurrentItem(*lst.begin(),QItemSelectionModel::Select) ;
}
}

View File

@ -0,0 +1,11 @@
#include <QListWidget>
class GroupSelectionBox: public QListWidget
{
public:
GroupSelectionBox(QWidget *parent) ;
std::list<std::string> selectedGroups() const ;
void setSelectedGroups(const std::list<std::string>& selected_group_ids) ;
};

View File

@ -357,6 +357,7 @@ HEADERS += rshare.h \
gui/common/html.h \
gui/common/AvatarDefs.h \
gui/common/GroupFlagsWidget.h \
gui/common/GroupSelectionBox.h \
gui/common/StatusDefs.h \
gui/common/TagDefs.h \
gui/common/GroupDefs.h \
@ -620,6 +621,7 @@ SOURCES += main.cpp \
gui/common/html.cpp \
gui/common/AvatarDefs.cpp \
gui/common/GroupFlagsWidget.cpp \
gui/common/GroupSelectionBox.cpp \
gui/common/StatusDefs.cpp \
gui/common/TagDefs.cpp \
gui/common/GroupDefs.cpp \