diff --git a/retroshare-gui/src/gui/ShareDialog.cpp b/retroshare-gui/src/gui/ShareDialog.cpp index 0323e4537..3ab34823b 100644 --- a/retroshare-gui/src/gui/ShareDialog.cpp +++ b/retroshare-gui/src/gui/ShareDialog.cpp @@ -27,6 +27,10 @@ #include #include #include +#include + +#include +#include /** 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 dirs; rsFiles->getSharedDirectories(dirs); std::list::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; diff --git a/retroshare-gui/src/gui/ShareDialog.h b/retroshare-gui/src/gui/ShareDialog.h index 349684728..9b3613a14 100644 --- a/retroshare-gui/src/gui/ShareDialog.h +++ b/retroshare-gui/src/gui/ShareDialog.h @@ -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 diff --git a/retroshare-gui/src/gui/ShareDialog.ui b/retroshare-gui/src/gui/ShareDialog.ui index e4d04c5c4..492c8a2f0 100644 --- a/retroshare-gui/src/gui/ShareDialog.ui +++ b/retroshare-gui/src/gui/ShareDialog.ui @@ -109,45 +109,11 @@ - + Share Flags - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Browseable by Friends - - - Browsable - - - - - - - Anonymous shared Network Wide - - - Network Wide - - - - + diff --git a/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp b/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp index 796d23841..377d5fdec 100644 --- a/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp +++ b/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp @@ -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) diff --git a/retroshare-gui/src/gui/common/GroupFlagsWidget.h b/retroshare-gui/src/gui/common/GroupFlagsWidget.h index b178a473c..d7d991ca8 100644 --- a/retroshare-gui/src/gui/common/GroupFlagsWidget.h +++ b/retroshare-gui/src/gui/common/GroupFlagsWidget.h @@ -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() ; diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.cpp b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp new file mode 100644 index 000000000..443a255eb --- /dev/null +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp @@ -0,0 +1,37 @@ +#include +#include "GroupSelectionBox.h" + +GroupSelectionBox::GroupSelectionBox(QWidget *parent) + : QListWidget(parent) +{ + setSelectionMode(QAbstractItemView::ExtendedSelection) ; + + // 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)) ; +} + +std::list GroupSelectionBox::selectedGroups() const +{ + QList selected_items = selectedItems() ; + std::list out ; + + for(QList::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& group_ids) +{ + for(std::list::const_iterator it(group_ids.begin());it!=group_ids.end();++it) + { + QList lst = findItems(QString::fromStdString(*it),Qt::MatchExactly) ; + + setCurrentItem(*lst.begin(),QItemSelectionModel::Select) ; + } +} diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.h b/retroshare-gui/src/gui/common/GroupSelectionBox.h new file mode 100644 index 000000000..48deeee98 --- /dev/null +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.h @@ -0,0 +1,11 @@ +#include + +class GroupSelectionBox: public QListWidget +{ + public: + GroupSelectionBox(QWidget *parent) ; + + std::list selectedGroups() const ; + + void setSelectedGroups(const std::list& selected_group_ids) ; +}; diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index b11b3283e..a001c34da 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -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 \