ShareDialog: UI is different for files/dirs

Bunch of if statements to make sure that we do not display delete/create on
files.
This commit is contained in:
Roeland Jago Douma 2015-01-14 10:35:09 +01:00
parent d1d8a40acf
commit f6a83d5de2
4 changed files with 66 additions and 58 deletions

View file

@ -21,9 +21,11 @@ namespace {
namespace OCC { namespace OCC {
ShareDialog::ShareDialog(QWidget *parent) : ShareDialog::ShareDialog(const QString &path, const bool &isDir, QWidget *parent) :
QDialog(parent), QDialog(parent),
_ui(new Ui::ShareDialog) _ui(new Ui::ShareDialog),
_path(path),
_isDir(isDir)
{ {
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
_ui->setupUi(this); _ui->setupUi(this);
@ -61,11 +63,17 @@ ShareDialog::ShareDialog(QWidget *parent) :
headerUser << tr("User name"); headerUser << tr("User name");
headerUser << tr("User"); headerUser << tr("User");
headerUser << tr("Edit"); headerUser << tr("Edit");
headerUser << tr("Create"); if (_isDir) {
headerUser << tr("Delete"); headerUser << tr("Create");
headerUser << tr("Delete");
}
headerUser << tr("Share"); headerUser << tr("Share");
_ui->treeWidget_shareUser->setHeaderLabels(headerUser); _ui->treeWidget_shareUser->setHeaderLabels(headerUser);
_ui->treeWidget_shareUser->setColumnCount(7); if (_isDir) {
_ui->treeWidget_shareUser->setColumnCount(7);
} else {
_ui->treeWidget_shareUser->setColumnCount(5);
}
_ui->treeWidget_shareUser->hideColumn(0); _ui->treeWidget_shareUser->hideColumn(0);
connect(_ui->treeWidget_shareUser, SIGNAL(itemChanged(QTreeWidgetItem *, int)), SLOT(slotUserShareWidgetClicked(QTreeWidgetItem *, int))); connect(_ui->treeWidget_shareUser, SIGNAL(itemChanged(QTreeWidgetItem *, int)), SLOT(slotUserShareWidgetClicked(QTreeWidgetItem *, int)));
connect(_ui->pushButton_shareUser, SIGNAL(clicked()), SLOT(slotAddUserShareClicked())); connect(_ui->pushButton_shareUser, SIGNAL(clicked()), SLOT(slotAddUserShareClicked()));
@ -76,18 +84,29 @@ ShareDialog::ShareDialog(QWidget *parent) :
headerGroup << "share_id"; headerGroup << "share_id";
headerGroup << tr("Group"); headerGroup << tr("Group");
headerGroup << tr("Edit"); headerGroup << tr("Edit");
headerGroup << tr("Create"); if (_isDir) {
headerGroup << tr("Delete"); headerGroup << tr("Create");
headerGroup << tr("Delete");
}
headerGroup << tr("Share"); headerGroup << tr("Share");
_ui->treeWidget_shareGroup->setHeaderLabels(headerGroup); _ui->treeWidget_shareGroup->setHeaderLabels(headerGroup);
_ui->treeWidget_shareGroup->setColumnCount(6); if (_isDir) {
_ui->treeWidget_shareGroup->setColumnCount(6);
} else {
_ui->treeWidget_shareGroup->setColumnCount(4);
}
_ui->treeWidget_shareGroup->hideColumn(0); _ui->treeWidget_shareGroup->hideColumn(0);
connect(_ui->treeWidget_shareGroup, SIGNAL(itemChanged(QTreeWidgetItem *, int)), SLOT(slotGroupShareWidgetClicked(QTreeWidgetItem *, int))); connect(_ui->treeWidget_shareGroup, SIGNAL(itemChanged(QTreeWidgetItem *, int)), SLOT(slotGroupShareWidgetClicked(QTreeWidgetItem *, int)));
connect(_ui->pushButton_shareGroup, SIGNAL(clicked()), SLOT(slotAddGroupShareClicked())); connect(_ui->pushButton_shareGroup, SIGNAL(clicked()), SLOT(slotAddGroupShareClicked()));
connect(_ui->lineEdit_shareGroup, SIGNAL(returnPressed()), SLOT(slotAddGroupShareClicked())); connect(_ui->lineEdit_shareGroup, SIGNAL(returnPressed()), SLOT(slotAddGroupShareClicked()));
connect(_ui->pushButton_group_deleteShare, SIGNAL(clicked()), SLOT(slotDeleteGroupShareClicked())); connect(_ui->pushButton_group_deleteShare, SIGNAL(clicked()), SLOT(slotDeleteGroupShareClicked()));
if (!_isDir) {
_ui->checkBox_user_create->hide();
_ui->checkBox_user_delete->hide();
_ui->checkBox_group_create->hide();
_ui->checkBox_group_delete->hide();
}
} }
void ShareDialog::setExpireDate(const QString &date) void ShareDialog::setExpireDate(const QString &date)
@ -121,9 +140,10 @@ QString ShareDialog::getPath()
return _path; return _path;
} }
void ShareDialog::setPath(const QString &path) void ShareDialog::setPath(const QString &path, const bool &isDir)
{ {
_path = path; _path = path;
_isDir = isDir;
ShareDialog::getShares(); ShareDialog::getShares();
} }
@ -194,33 +214,25 @@ void ShareDialog::slotSharesFetched(const QString &reply)
columns << data.value("share_with_displayname").toString(); columns << data.value("share_with_displayname").toString();
columns << ""; columns << "";
columns << ""; columns << "";
columns << ""; if (_isDir) {
columns << ""; columns << "";
columns << "";
}
QTreeWidgetItem *item = new QTreeWidgetItem(columns); QTreeWidgetItem *item = new QTreeWidgetItem(columns);
int perm = data.value("permissions").toInt(); int perm = data.value("permissions").toInt();
if (perm & PERM_UPDATE) { int col = 3;
item->setCheckState(3, Qt::Checked); item->setCheckState(col, perm & PERM_UPDATE ? Qt::Checked : Qt::Unchecked);
} else { col++;
item->setCheckState(3, Qt::Unchecked); if (_isDir) {
} item->setCheckState(col, perm & PERM_CREATE ? Qt::Checked : Qt::Unchecked);
if (perm & PERM_CREATE) { col++;
item->setCheckState(4, Qt::Checked); item->setCheckState(col, perm & PERM_DELETE ? Qt::Checked : Qt::Unchecked);
} else { col++;
item->setCheckState(4, Qt::Unchecked);
}
if (perm & PERM_DELETE) {
item->setCheckState(5, Qt::Checked);
} else {
item->setCheckState(5, Qt::Unchecked);
}
if (perm & PERM_SHARE) {
item->setCheckState(6, Qt::Checked);
} else {
item->setCheckState(6, Qt::Unchecked);
} }
item->setCheckState(col, perm & PERM_SHARE ? Qt::Checked : Qt::Unchecked);
_ui->treeWidget_shareUser->insertTopLevelItem(0, item); _ui->treeWidget_shareUser->insertTopLevelItem(0, item);
} }
@ -233,33 +245,26 @@ void ShareDialog::slotSharesFetched(const QString &reply)
columns << data.value("share_with").toString(); columns << data.value("share_with").toString();
columns << ""; columns << "";
columns << ""; columns << "";
columns << ""; if (_isDir) {
columns << ""; columns << "";
columns << "";
}
QTreeWidgetItem *item = new QTreeWidgetItem(columns); QTreeWidgetItem *item = new QTreeWidgetItem(columns);
int perm = data.value("permissions").toInt(); int perm = data.value("permissions").toInt();
int col = 2;
item->setCheckState(col, perm & PERM_UPDATE ? Qt::Checked : Qt::Unchecked);
col++;
if (_isDir) {
item->setCheckState(col, perm & PERM_CREATE ? Qt::Checked : Qt::Unchecked);
col++;
item->setCheckState(col, perm & PERM_DELETE ? Qt::Checked : Qt::Unchecked);
col++;
}
item->setCheckState(col, perm & PERM_SHARE ? Qt::Checked : Qt::Unchecked);
if (perm & PERM_UPDATE) {
item->setCheckState(2, Qt::Checked);
} else {
item->setCheckState(2, Qt::Unchecked);
}
if (perm & PERM_CREATE) {
item->setCheckState(3, Qt::Checked);
} else {
item->setCheckState(3, Qt::Unchecked);
}
if (perm & PERM_DELETE) {
item->setCheckState(4, Qt::Checked);
} else {
item->setCheckState(4, Qt::Unchecked);
}
if (perm & PERM_SHARE) {
item->setCheckState(5, Qt::Checked);
} else {
item->setCheckState(5, Qt::Unchecked);
}
_ui->treeWidget_shareGroup->insertTopLevelItem(0, item); _ui->treeWidget_shareGroup->insertTopLevelItem(0, item);
} }

View file

@ -50,10 +50,10 @@ class ShareDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit ShareDialog(QWidget *parent = 0); explicit ShareDialog(const QString &path, const bool &isDir, QWidget *parent = 0);
~ShareDialog(); ~ShareDialog();
void getShares(); void getShares();
void setPath(const QString &path); void setPath(const QString &path, const bool &isDir);
QString getPath(); QString getPath();
private slots: private slots:
void slotSharesFetched(const QString &reply); void slotSharesFetched(const QString &reply);
@ -83,6 +83,7 @@ private slots:
private: private:
Ui::ShareDialog *_ui; Ui::ShareDialog *_ui;
QString _path; QString _path;
bool _isDir;
QList<QVariant> _shares; QList<QVariant> _shares;
qulonglong _public_share_id; qulonglong _public_share_id;
void setPassword(QString password); void setPassword(QString password);

View file

@ -414,9 +414,11 @@ void SocketApi::command_SHARE(const QString& argument, SocketType* socket)
} else { } else {
const QString message = QLatin1String("SHARE:OK:")+QDir::toNativeSeparators(argument); const QString message = QLatin1String("SHARE:OK:")+QDir::toNativeSeparators(argument);
sendMessage(socket, message); sendMessage(socket, message);
QFileInfo info(argument);
const QString folderForPath = shareFolder->path(); const QString folderForPath = shareFolder->path();
const QString path = shareFolder->remotePath() + argument.right(argument.count()-folderForPath.count()+1); const QString path = shareFolder->remotePath() + argument.right(argument.count()-folderForPath.count()+1);
emit shareCommandReceived(path); emit shareCommandReceived(path, info.isDir());
} }
} }

View file

@ -58,7 +58,7 @@ public slots:
void slotClearExcludesList(); void slotClearExcludesList();
signals: signals:
void shareCommandReceived(const QString &path); void shareCommandReceived(const QString &path, const bool &isDir);
private slots: private slots:
void slotNewConnection(); void slotNewConnection();