2010-04-08 12:33:10 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006- 2010 RetroShare Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
#include "ShareDialog.h"
|
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsfiles.h>
|
2012-11-02 09:52:29 -04:00
|
|
|
#include <retroshare/rstypes.h>
|
2010-04-08 12:33:10 -04:00
|
|
|
|
|
|
|
#include <QContextMenuEvent>
|
2010-09-17 14:27:30 -04:00
|
|
|
#include <QFileDialog>
|
2010-04-08 12:33:10 -04:00
|
|
|
#include <QMessageBox>
|
2012-11-03 13:15:47 -04:00
|
|
|
#include <QLayout>
|
|
|
|
#include <QTextEdit>
|
2010-04-08 12:33:10 -04:00
|
|
|
#include <QComboBox>
|
2012-11-03 13:15:47 -04:00
|
|
|
#include <QSizePolicy>
|
2012-11-02 13:26:20 -04:00
|
|
|
#include <QGroupBox>
|
|
|
|
|
|
|
|
#include <gui/common/GroupSelectionBox.h>
|
|
|
|
#include <gui/common/GroupFlagsWidget.h>
|
2010-04-08 12:33:10 -04:00
|
|
|
|
|
|
|
/** Default constructor */
|
2012-11-07 19:58:20 -05:00
|
|
|
ShareDialog::ShareDialog(std::string filename, QWidget *parent)
|
|
|
|
: QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
|
2010-04-08 12:33:10 -04:00
|
|
|
{
|
2010-09-17 14:27:30 -04:00
|
|
|
/* Invoke Qt Designer generated QObject setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
2012-12-05 05:27:54 -05:00
|
|
|
ui.headerFrame->setHeaderImage(QPixmap(":/images/fileshare64.png"));
|
2012-08-24 06:49:08 -04:00
|
|
|
ui.headerFrame->setHeaderText(tr("Share Folder"));
|
|
|
|
|
2010-09-17 14:27:30 -04:00
|
|
|
connect(ui.browseButton, SIGNAL(clicked( bool ) ), this , SLOT( browseDirectory() ) );
|
2012-11-07 19:58:20 -05:00
|
|
|
connect(ui.buttonBox, SIGNAL(accepted()), this , SLOT( addDirectory() ) );
|
|
|
|
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(close()));
|
2010-04-08 12:33:10 -04:00
|
|
|
|
2012-11-07 19:58:20 -05:00
|
|
|
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
2010-04-08 12:33:10 -04:00
|
|
|
|
2012-11-03 13:15:47 -04:00
|
|
|
QVBoxLayout *vbox = new QVBoxLayout() ;
|
2012-11-02 13:26:20 -04:00
|
|
|
|
2012-11-06 16:24:49 -05:00
|
|
|
QHBoxLayout *hb2 = new QHBoxLayout() ;
|
2015-06-12 04:27:26 -04:00
|
|
|
hb2->addWidget(new QLabel(tr("Share flags and groups:")+" ")) ;
|
2012-11-06 16:24:49 -05:00
|
|
|
|
2012-11-03 10:30:04 -04:00
|
|
|
groupflagsbox = new GroupFlagsWidget(ui.shareflags_GB) ;
|
2016-10-31 09:26:01 -04:00
|
|
|
groupflagsbox->setFlags(DIR_FLAGS_ANONYMOUS_DOWNLOAD) ; // default value
|
2012-11-06 16:24:49 -05:00
|
|
|
|
2012-11-03 13:15:47 -04:00
|
|
|
messageBox = new QTextEdit(ui.shareflags_GB) ;
|
|
|
|
messageBox->setReadOnly(true) ;
|
|
|
|
messageBox->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Preferred)) ;
|
|
|
|
|
2012-11-06 16:24:49 -05:00
|
|
|
hb2->addWidget(groupflagsbox) ;
|
|
|
|
|
|
|
|
vbox->addLayout(hb2) ;
|
2012-11-03 13:15:47 -04:00
|
|
|
vbox->addWidget(messageBox) ;
|
2012-11-02 13:26:20 -04:00
|
|
|
|
2012-11-03 13:15:47 -04:00
|
|
|
QHBoxLayout *hbox = new QHBoxLayout() ;
|
|
|
|
groupselectionbox = new GroupSelectionBox(ui.shareflags_GB);
|
|
|
|
hbox->addLayout(vbox) ;
|
2012-11-02 13:26:20 -04:00
|
|
|
hbox->addWidget(groupselectionbox) ;
|
|
|
|
|
2012-11-03 10:15:03 -04:00
|
|
|
ui.shareflags_GB->setLayout(hbox) ;
|
2012-11-06 16:24:49 -05:00
|
|
|
updateInfoMessage() ;
|
2012-11-02 13:26:20 -04:00
|
|
|
|
2015-03-19 16:39:59 -04:00
|
|
|
connect(groupselectionbox,SIGNAL(itemChanged(QListWidgetItem*)),this,SLOT(updateInfoMessage())) ;
|
2012-11-03 13:15:47 -04:00
|
|
|
connect(groupflagsbox,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateInfoMessage())) ;
|
|
|
|
|
2012-11-02 13:26:20 -04:00
|
|
|
if (!filename.empty())
|
|
|
|
{
|
2010-09-18 12:05:32 -04:00
|
|
|
std::list<SharedDirInfo> dirs;
|
|
|
|
rsFiles->getSharedDirectories(dirs);
|
|
|
|
|
|
|
|
std::list<SharedDirInfo>::const_iterator it;
|
2014-10-21 18:33:02 -04:00
|
|
|
for (it = dirs.begin(); it != dirs.end(); ++it) {
|
2012-11-02 13:26:20 -04:00
|
|
|
if (it->filename == filename)
|
|
|
|
{
|
2010-09-18 12:05:32 -04:00
|
|
|
/* fill dialog */
|
2012-11-07 19:58:20 -05:00
|
|
|
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
2010-09-18 12:05:32 -04:00
|
|
|
|
|
|
|
ui.localpath_lineEdit->setText(QString::fromUtf8(it->filename.c_str()));
|
|
|
|
ui.localpath_lineEdit->setDisabled(true);
|
|
|
|
ui.browseButton->setDisabled(true);
|
|
|
|
ui.virtualpath_lineEdit->setText(QString::fromUtf8(it->virtualname.c_str()));
|
|
|
|
|
2012-12-05 05:27:54 -05:00
|
|
|
groupflagsbox->setFlags(it->shareflags) ;
|
2012-11-08 19:46:41 -05:00
|
|
|
groupselectionbox->setSelectedGroupIds(it->parent_groups) ;
|
2012-12-05 05:27:54 -05:00
|
|
|
|
|
|
|
ui.headerFrame->setHeaderText(tr("Edit Shared Folder"));
|
2012-11-02 13:26:20 -04:00
|
|
|
|
2010-09-18 12:05:32 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-08 12:33:10 -04:00
|
|
|
}
|
|
|
|
|
2012-11-12 17:51:27 -05:00
|
|
|
void ShareDialog::groupSelectionChanged()
|
|
|
|
{
|
|
|
|
rsFiles->updateSinceGroupPermissionsChanged() ;
|
|
|
|
}
|
|
|
|
|
2012-11-03 13:15:47 -04:00
|
|
|
void ShareDialog::updateInfoMessage()
|
|
|
|
{
|
2012-11-08 19:46:41 -05:00
|
|
|
QList<QString> selectedGroupNames;
|
|
|
|
groupselectionbox->selectedGroupNames(selectedGroupNames);
|
|
|
|
messageBox->setText(GroupFlagsWidget::groupInfoString(groupflagsbox->flags(), selectedGroupNames)) ;
|
2012-11-03 13:15:47 -04:00
|
|
|
}
|
|
|
|
|
2010-04-08 12:33:10 -04:00
|
|
|
void ShareDialog::browseDirectory()
|
|
|
|
{
|
2010-09-17 14:27:30 -04:00
|
|
|
/* select a dir*/
|
2011-03-06 15:19:16 -05:00
|
|
|
QString qdir = QFileDialog::getExistingDirectory(this, tr("Select A Folder To Share"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
2010-09-17 14:27:30 -04:00
|
|
|
|
|
|
|
/* add it to the server */
|
|
|
|
if (qdir.isEmpty()) {
|
2012-11-07 19:58:20 -05:00
|
|
|
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
2010-09-17 14:27:30 -04:00
|
|
|
return;
|
|
|
|
}
|
2012-11-07 19:58:20 -05:00
|
|
|
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
2010-09-17 14:27:30 -04:00
|
|
|
ui.localpath_lineEdit->setText(qdir);
|
2010-04-08 12:33:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::addDirectory()
|
|
|
|
{
|
2010-09-17 14:27:30 -04:00
|
|
|
SharedDirInfo sdi ;
|
|
|
|
sdi.filename = ui.localpath_lineEdit->text().toUtf8().constData();
|
|
|
|
sdi.virtualname = ui.virtualpath_lineEdit->text().toUtf8().constData();
|
2012-11-03 10:30:04 -04:00
|
|
|
sdi.shareflags = groupflagsbox->flags() ;
|
2012-11-08 19:46:41 -05:00
|
|
|
groupselectionbox->selectedGroupIds(sdi.parent_groups);
|
2010-04-08 12:33:10 -04:00
|
|
|
|
2012-11-02 13:26:20 -04:00
|
|
|
if (ui.localpath_lineEdit->isEnabled())
|
|
|
|
{
|
2010-09-18 12:05:32 -04:00
|
|
|
/* add new share */
|
|
|
|
rsFiles->addSharedDirectory(sdi);
|
2012-11-02 13:26:20 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-18 12:05:32 -04:00
|
|
|
/* edit exisiting share */
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
std::list<SharedDirInfo> dirs;
|
|
|
|
rsFiles->getSharedDirectories(dirs);
|
|
|
|
|
|
|
|
std::list<SharedDirInfo>::iterator it;
|
2014-10-21 18:33:02 -04:00
|
|
|
for (it = dirs.begin(); it != dirs.end(); ++it) {
|
2010-09-18 12:05:32 -04:00
|
|
|
if (it->filename == sdi.filename) {
|
|
|
|
found = true;
|
|
|
|
|
|
|
|
if (it->virtualname != sdi.virtualname) {
|
|
|
|
/* virtual name changed, remove shared directory and add it again */
|
2012-11-02 13:26:20 -04:00
|
|
|
|
2010-09-18 12:05:32 -04:00
|
|
|
rsFiles->removeSharedDirectory(it->filename);
|
|
|
|
rsFiles->addSharedDirectory(sdi);
|
|
|
|
break;
|
|
|
|
}
|
2012-11-03 11:25:25 -04:00
|
|
|
if (it->shareflags != sdi.shareflags || it->parent_groups != sdi.parent_groups) {
|
2010-09-18 12:05:32 -04:00
|
|
|
/* modifies the flags */
|
|
|
|
it->shareflags = sdi.shareflags;
|
2012-11-03 11:25:25 -04:00
|
|
|
it->parent_groups = sdi.parent_groups;
|
2010-09-18 12:05:32 -04:00
|
|
|
rsFiles->updateShareFlags(*it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nothing changed */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found == false) {
|
|
|
|
/* not modified, add share directory instead */
|
|
|
|
rsFiles->addSharedDirectory(sdi);
|
|
|
|
}
|
2010-09-17 14:27:30 -04:00
|
|
|
}
|
2010-04-08 12:33:10 -04:00
|
|
|
|
2010-09-17 14:27:30 -04:00
|
|
|
close();
|
2010-04-08 12:33:10 -04:00
|
|
|
}
|