diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 62d24a8d9..38efb452e 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -700,7 +700,7 @@ bool ftServer::getSharedDirectories(std::list &dirs) return true; } -bool ftServer::setSharedDirectories(std::list &dirs) +bool ftServer::setSharedDirectories(const std::list& dirs) { mFileDatabase->setSharedDirectories(dirs); return true; diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 76b030cb5..29be7aa90 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -202,7 +202,7 @@ public: virtual std::string getPartialsDirectory(); virtual bool getSharedDirectories(std::list &dirs); - virtual bool setSharedDirectories(std::list &dirs); + virtual bool setSharedDirectories(const std::list &dirs); virtual bool addSharedDirectory(const SharedDirInfo& dir); virtual bool updateShareFlags(const SharedDirInfo& dir); // updates the flags. The directory should already exist ! virtual bool removeSharedDirectory(std::string dir); diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 5b888d1c3..c40ce9d54 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -101,7 +101,7 @@ struct SharedDirInfo { std::string filename ; std::string virtualname ; - FileStorageFlags shareflags ; // DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | ... + FileStorageFlags shareflags ; // combnation of DIR_FLAGS_ANONYMOUS_DOWNLOAD | DIR_FLAGS_BROWSABLE | ... std::list parent_groups ; }; @@ -217,8 +217,9 @@ class RsFiles virtual std::string getDownloadDirectory() = 0; virtual std::string getPartialsDirectory() = 0; - virtual bool getSharedDirectories(std::list &dirs) = 0; - virtual bool addSharedDirectory(const SharedDirInfo& dir) = 0; + virtual bool getSharedDirectories(std::list& dirs) = 0; + virtual bool setSharedDirectories(const std::list& dirs) = 0; + virtual bool addSharedDirectory(const SharedDirInfo& dir) = 0; virtual bool updateShareFlags(const SharedDirInfo& dir) = 0; // updates the flags. The directory should already exist ! virtual bool removeSharedDirectory(std::string dir) = 0; diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index 61aadefb4..878a54e30 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -34,7 +34,8 @@ #include "ShareManager.h" #include "ShareDialog.h" #include "settings/rsharesettings.h" -#include +#include "gui/common/GroupFlagsWidget.h" +#include "gui/common/GroupSelectionBox.h" #include "gui/common/GroupDefs.h" #include "gui/notifyqt.h" #include "util/QtVersion.h" @@ -65,18 +66,16 @@ ShareManager::ShareManager() Settings->loadWidgetInformation(this); - connect(ui.addButton, SIGNAL(clicked( bool ) ), this , SLOT( showShareDialog() ) ); - connect(ui.editButton, SIGNAL(clicked( bool ) ), this , SLOT( editShareDirectory() ) ); - connect(ui.removeButton, SIGNAL(clicked( bool ) ), this , SLOT( removeShareDirectory() ) ); + connect(ui.addButton, SIGNAL(clicked( bool ) ), this , SLOT( addShare() ) ); connect(ui.closeButton, SIGNAL(clicked()), this, SLOT(applyAndClose())); + connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); 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())); + connect(ui.shareddirList, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(doubleClickedCell(int,int))); - ui.editButton->setEnabled(false); - ui.removeButton->setEnabled(false); + connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(reload())); QHeaderView* header = ui.shareddirList->horizontalHeader(); QHeaderView_setSectionResizeModeColumn(header, COLUMN_PATH, QHeaderView::Stretch); @@ -90,6 +89,33 @@ ShareManager::ShareManager() setAttribute(Qt::WA_DeleteOnClose, true); } +void ShareManager::doubleClickedCell(int row,int column) +{ + if(column == COLUMN_PATH) + { + QString dirname = QFileDialog::getExistingDirectory(NULL,tr("Choose directory"),QString(),QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly); + + if(!dirname.isNull()) + { + std::string new_name( dirname.toUtf8() ); + + for(uint32_t i=0;i selected_groups = GroupSelectionDialog::selectGroups(std::list()) ; + + mDirInfos[row].parent_groups = selected_groups ; + load(); + } +} + ShareManager::~ShareManager() { _instance = NULL; @@ -97,11 +123,21 @@ ShareManager::~ShareManager() Settings->saveWidgetInformation(this); } +void ShareManager::cancel() +{ + close(); +} void ShareManager::applyAndClose() { -// std::cerr << "ShareManager:::close(): updating!" << std::endl; + // This is the only place where we change things. + + std::list infos ; + + for(uint32_t i=0;isetSharedDirectories(infos) ; - updateFlags() ; close() ; } @@ -121,6 +157,17 @@ void ShareManager::shareddirListCostumPopupMenu( QPoint /*point*/ ) contextMnu.exec(QCursor::pos()); } +void ShareManager::reload() +{ + std::list dirs ; + rsFiles->getSharedDirectories(dirs) ; + + for(std::list::const_iterator it(dirs.begin());it!=dirs.end();++it) + mDirInfos.push_back(*it) ; + + load(); +} + /** Loads the settings for this page */ void ShareManager::load() { @@ -128,44 +175,40 @@ void ShareManager::load() return ; isLoading = true; -// std::cerr << "ShareManager:: In load !!!!!" << std::endl ; - - std::list::const_iterator it; - std::list dirs; - rsFiles->getSharedDirectories(dirs); /* get a link to the table */ QTableWidget *listWidget = ui.shareddirList; /* set new row count */ - listWidget->setRowCount(dirs.size()); + listWidget->setRowCount(mDirInfos.size()); - int row=0 ; - for(it = dirs.begin(); it != dirs.end(); ++it,++row) + for(uint32_t row=0;rowsetItem(row, COLUMN_PATH, new QTableWidgetItem(QString::fromUtf8((*it).filename.c_str()))); - listWidget->setItem(row, COLUMN_VIRTUALNAME, new QTableWidgetItem(QString::fromUtf8((*it).virtualname.c_str()))); + listWidget->setItem(row, COLUMN_PATH, new QTableWidgetItem(QString::fromUtf8(mDirInfos[row].filename.c_str()))); + listWidget->setItem(row, COLUMN_VIRTUALNAME, new QTableWidgetItem(QString::fromUtf8(mDirInfos[row].virtualname.c_str()))); - GroupFlagsWidget *widget = new GroupFlagsWidget(NULL,(*it).shareflags); + GroupFlagsWidget *widget = new GroupFlagsWidget(NULL,mDirInfos[row].shareflags); - listWidget->setRowHeight(row, 32 * QFontMetricsF(font()).height()/14.0); - listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget); + listWidget->setRowHeight(row, 32 * QFontMetricsF(font()).height()/14.0); + listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget); - listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem()) ; - listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ; + listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem()) ; + listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ; + listWidget->item(row,COLUMN_GROUPS)->setText(getGroupString(mDirInfos[row].parent_groups)); - //connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ; + connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ; + + listWidget->item(row,COLUMN_PATH)->setToolTip(tr("Double click to change shared directory path")) ; + listWidget->item(row,COLUMN_GROUPS)->setToolTip(tr("Double click to select which groups of friends can see the files")) ; + listWidget->item(row,COLUMN_VIRTUALNAME)->setToolTip(tr("Double click to change the cirtual file name")) ; } - listWidget->setColumnWidth(COLUMN_SHARE_FLAGS,132 * QFontMetricsF(font()).height()/14.0) ; - - //ui.incomingDir->setText(QString::fromStdString(rsFiles->getDownloadDirectory())); + listWidget->setColumnWidth(COLUMN_SHARE_FLAGS,132 * QFontMetricsF(font()).height()/14.0) ; listWidget->update(); /* update display */ update(); isLoading = false ; - updateGroups(); } void ShareManager::showYourself() @@ -173,6 +216,7 @@ void ShareManager::showYourself() if(_instance == NULL) _instance = new ShareManager() ; + _instance->reload() ; _instance->show() ; _instance->activateWindow(); } @@ -184,7 +228,7 @@ void ShareManager::showYourself() } if (update_local) { - _instance->load(); + _instance->reload(); } } @@ -193,101 +237,77 @@ void ShareManager::updateFlags() if(isLoading) return ; - isLoading = true ; // stops GUI update. Otherwise each call to rsFiles->updateShareFlags() modifies the GUI that we count on to check - // what has changed => fail! + isLoading = true ; // stops GUI update. Otherwise each call to rsFiles->updateShareFlags() modifies the GUI that we count on to check + // what has changed => fail! - // std::cerr << "Updating flags" << std::endl; + for(int row=0;rowrowCount();++row) + { + FileStorageFlags flags = (dynamic_cast(ui.shareddirList->cellWidget(row,COLUMN_SHARE_FLAGS)))->flags() ; - std::list::iterator it; - std::list dirs; - rsFiles->getSharedDirectories(dirs); - - std::map mapped_flags ; - - for(int row=0;rowrowCount();++row) - { - QString dirpath = ui.shareddirList->item(row,COLUMN_PATH)->text() ; - FileStorageFlags flags = (dynamic_cast(ui.shareddirList->cellWidget(row,COLUMN_SHARE_FLAGS)))->flags() ; - - mapped_flags[dirpath] = flags ; - -// std::cerr << "Getting new flags " << flags << " for path " << dirpath.toStdString() << std::endl; - } - - for(std::list::iterator it(dirs.begin());it!=dirs.end();++it) - { - FileStorageFlags newf = mapped_flags[QString::fromUtf8((*it).filename.c_str())] ; - - if( (*it).shareflags != newf ) - { - (*it).shareflags = newf ; - rsFiles->updateShareFlags(*it) ; // modifies the flags - -// std::cerr << "Updating flags to " << newf << " for dir " << (*it).filename << std::endl ; - } - } + mDirInfos[row].shareflags = flags ; + } isLoading = false ; // re-enable GUI load - load() ; // update the GUI. + load() ; // update the GUI. } -void ShareManager::updateGroups() +// void ShareManager::updateFromWidget() +// { +// mDirInfos.clear(); +// +// for(uint32_t i=0;iitem(i,COLUMN_PATH)->text().toUtf8() ; +// sdi.virtualname = ui.shareddirList->item(i,COLUMN_VIRTUALNAME)->text().toUtf8() ; +// sdi.shareflags = dynamic_cast(ui.shareddirList->item(i,COLUMN_SHARE_FLAGS))->flags(); +// sdi.parent_groups = std::list();//ui.shareddirList->item(i,COLUMN_GROUPS)->text(); +// } +// } + +QString ShareManager::getGroupString(const std::list& groups) { - if(isLoading) - return ; + int n = 0; + QString group_string ; -// 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) + for (std::list::const_iterator it(groups.begin());it!=groups.end();++it,++n) { - QTableWidgetItem *item = ui.shareddirList->item(row, COLUMN_GROUPS); + if (n>0) + group_string += ", " ; - 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); + RsGroupInfo groupInfo; + rsPeers->getGroupInfo(*it, groupInfo); + group_string += GroupDefs::name(groupInfo); } + + return group_string ; } -void ShareManager::editShareDirectory() -{ - /* id current dir */ - int row = ui.shareddirList->currentRow(); - QTableWidgetItem *item = ui.shareddirList->item(row, COLUMN_PATH); - - if (item) { - std::string filename = item->text().toUtf8().constData(); - - std::list dirs; - rsFiles->getSharedDirectories(dirs); - - std::list::const_iterator it; - for (it = dirs.begin(); it != dirs.end(); ++it) { - if (it->filename == filename) { - /* file name found, show dialog */ - ShareDialog sharedlg (it->filename, this); - sharedlg.setWindowTitle(tr("Edit Shared Folder")); - sharedlg.exec(); - load(); - break; - } - } - } -} +// void ShareManager::editShareDirectory() +// { +// /* id current dir */ +// int row = ui.shareddirList->currentRow(); +// QTableWidgetItem *item = ui.shareddirList->item(row, COLUMN_PATH); +// +// if (item) { +// std::string filename = item->text().toUtf8().constData(); +// +// std::list dirs; +// rsFiles->getSharedDirectories(dirs); +// +// std::list::const_iterator it; +// for (it = dirs.begin(); it != dirs.end(); ++it) { +// if (it->filename == filename) { +// /* file name found, show dialog */ +// ShareDialog sharedlg (it->filename, this); +// sharedlg.setWindowTitle(tr("Edit Shared Folder")); +// sharedlg.exec(); +// load(); +// break; +// } +// } +// } +// } void ShareManager::removeShareDirectory() { @@ -301,7 +321,9 @@ void ShareManager::removeShareDirectory() { if ((QMessageBox::question(this, tr("Warning!"),tr("Do you really want to stop sharing this directory ?"),QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes))== QMessageBox::Yes) { - rsFiles->removeSharedDirectory( qdir->text().toUtf8().constData()); + for(uint32_t i=row;i+1= 0) { - ui.editButton->setEnabled(true); - ui.removeButton->setEnabled(true); - } else { - ui.editButton->setEnabled(false); - ui.removeButton->setEnabled(false); - } } void ShareManager::dragEnterEvent(QDragEnterEvent *event) diff --git a/retroshare-gui/src/gui/ShareManager.h b/retroshare-gui/src/gui/ShareManager.h index 93cce9aee..c0b4a7474 100644 --- a/retroshare-gui/src/gui/ShareManager.h +++ b/retroshare-gui/src/gui/ShareManager.h @@ -26,6 +26,7 @@ #include #include +#include #include "ui_ShareManager.h" class ShareManager : public QDialog @@ -55,14 +56,18 @@ private slots: /** Create the context popup menu and it's submenus */ void shareddirListCurrentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn); void shareddirListCostumPopupMenu( QPoint point ); + void addShare(); + void doubleClickedCell(int,int); void showShareDialog(); - void editShareDirectory(); + //void editShareDirectory(); void removeShareDirectory(); void updateFlags(); - void updateGroups(); - void applyAndClose() ; + void applyAndClose() ; + void cancel() ; + void reload() ; + static QString getGroupString(const std::list& groups); private: static ShareManager *_instance; bool isLoading; @@ -72,6 +77,8 @@ private: /** Qt Designer generated object */ Ui::ShareManager ui; + + std::vector mDirInfos ; }; #endif diff --git a/retroshare-gui/src/gui/ShareManager.ui b/retroshare-gui/src/gui/ShareManager.ui index 5bb73fd18..63b1a980b 100644 --- a/retroshare-gui/src/gui/ShareManager.ui +++ b/retroshare-gui/src/gui/ShareManager.ui @@ -18,7 +18,16 @@ :/images/logo/logo_16.png:/images/logo/logo_16.png - + + 0 + + + 0 + + + 0 + + 0 @@ -49,7 +58,7 @@ 6 - + Shared Folder Manager @@ -64,7 +73,7 @@ Qt::CustomContextMenu - QAbstractItemView::NoEditTriggers + QAbstractItemView::DoubleClicked true @@ -92,12 +101,12 @@ - Directory + Shared directory - Virtual Folder + Visible name @@ -139,7 +148,7 @@ Add a Share Directory - Add + Add new @@ -149,35 +158,7 @@ - - - - - 0 - 0 - - - - - 200 - 200 - - - - Stop sharing selected Directory - - - Remove - - - - 16 - 16 - - - - - + Qt::Horizontal @@ -190,24 +171,14 @@ - + Apply and close - - - - Edit selected Shared Directory - - - Edit - - - - + @@ -290,6 +261,13 @@ + + + + Cancel + + + diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.cpp b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp index 2e0cc9c32..6ee32a64d 100644 --- a/retroshare-gui/src/gui/common/GroupSelectionBox.cpp +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include "GroupSelectionBox.h" #include "GroupDefs.h" @@ -17,7 +19,6 @@ GroupSelectionBox::GroupSelectionBox(QWidget *parent) // Fill with available groups fillGroups(); } - void GroupSelectionBox::fillGroups() { std::list selectedIds; @@ -78,3 +79,39 @@ void GroupSelectionBox::selectedGroupNames(QList &groupNames) const } } } + +std::list GroupSelectionDialog::selectGroups(const std::list& default_groups) +{ + GroupSelectionDialog gsd(NULL) ; + + gsd.mBox->setSelectedGroupIds(default_groups) ; + + gsd.exec(); + + std::list selected_groups ; + gsd.mBox->selectedGroupIds(selected_groups); + + return selected_groups ; +} + +GroupSelectionDialog::~GroupSelectionDialog() +{ + delete mBox ; +} +GroupSelectionDialog::GroupSelectionDialog(QWidget *parent) +{ + mBox = new GroupSelectionBox(this) ; + + QLayout *l = new QVBoxLayout ; + setLayout(l) ; + + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + l->addWidget(mBox) ; + l->addWidget(buttonBox) ; + l->update() ; +} + diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.h b/retroshare-gui/src/gui/common/GroupSelectionBox.h index 4afc9cc94..70ad69fc4 100644 --- a/retroshare-gui/src/gui/common/GroupSelectionBox.h +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.h @@ -1,4 +1,5 @@ #include +#include #include class GroupSelectionBox: public QListWidget @@ -8,6 +9,8 @@ class GroupSelectionBox: public QListWidget public: GroupSelectionBox(QWidget *parent); + static void selectGroups(const std::list& default_groups) ; + void selectedGroupIds(std::list &groupIds) const; void selectedGroupNames(QList &groupNames) const; @@ -16,3 +19,17 @@ public: private slots: void fillGroups(); }; + +class GroupSelectionDialog: public QDialog +{ + Q_OBJECT + +public: + GroupSelectionDialog(QWidget *parent) ; + virtual ~GroupSelectionDialog() ; + + static std::list selectGroups(const std::list& default_groups) ; + +private: + GroupSelectionBox *mBox ; +}; diff --git a/retroshare-gui/src/gui/icons/blank_red_128.png b/retroshare-gui/src/gui/icons/blank_red_128.png new file mode 100644 index 000000000..19057766a Binary files /dev/null and b/retroshare-gui/src/gui/icons/blank_red_128.png differ diff --git a/retroshare-gui/src/gui/icons/search_red_128.png b/retroshare-gui/src/gui/icons/search_red_128.png new file mode 100644 index 000000000..f0fa88e22 Binary files /dev/null and b/retroshare-gui/src/gui/icons/search_red_128.png differ