Browse Source

- Validate label names to make sure there is no character forbidden by the file system

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
037e57b687
  1. 14
      src/misc.h
  2. 4
      src/torrentadditiondlg.h
  3. 23
      src/transferlistfilterswidget.h
  4. 19
      src/transferlistwidget.cpp

14
src/misc.h

@ -183,6 +183,20 @@ public: @@ -183,6 +183,20 @@ public:
}
}
static QString toValidFileSystemName(QString filename) {
filename = filename.replace("\\", "/");
QRegExp regex("[/:!?\"*<>|]");
return filename.replace(regex, " ");
}
static bool isValidFileSystemName(QString filename) {
filename = filename.replace("\\", "/");
QRegExp regex("[/:!?\"*<>|]");
if(filename.contains(regex))
return false;
return true;
}
#ifdef Q_WS_MAC
static QString getFullPath(const FSRef &ref)
{

4
src/torrentadditiondlg.h

@ -424,6 +424,10 @@ public slots: @@ -424,6 +424,10 @@ public slots:
return;
}
}
if (!misc::isValidFileSystemName(comboLabel->currentText().trimmed())) {
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
return;
}
// Save savepath
TorrentTempData::setSavePath(hash, savePath.path());
qDebug("Torrent label is: %s", comboLabel->currentText().trimmed().toLocal8Bit().data());

23
src/transferlistfilterswidget.h

@ -41,6 +41,7 @@ @@ -41,6 +41,7 @@
#include <QInputDialog>
#include <QDragMoveEvent>
#include <QStandardItemModel>
#include <QMessageBox>
#include "transferlistdelegate.h"
#include "transferlistwidget.h"
@ -244,8 +245,8 @@ protected slots: @@ -244,8 +245,8 @@ protected slots:
}
void addLabel(QString label) {
if(label.trimmed().isEmpty()) return;
if(customLabels.contains(label)) return;
label = misc::toValidFileSystemName(label.trimmed());
if(label.isEmpty() || customLabels.contains(label)) return;
QListWidgetItem *newLabel = new QListWidgetItem(labelFilters);
newLabel->setText(label + " (0)");
newLabel->setData(Qt::DecorationRole, QIcon(":/Icons/oxygen/folder.png"));
@ -269,10 +270,20 @@ protected slots: @@ -269,10 +270,20 @@ protected slots:
}
if(act == addAct) {
bool ok;
QString label = QInputDialog::getText(this, tr("New Label"), tr("Label:"), QLineEdit::Normal, "", &ok);
if (ok && !label.isEmpty()) {
addLabel(label);
}
QString label = "";
bool invalid;
do {
invalid = false;
label = QInputDialog::getText(this, tr("New Label"), tr("Label:"), QLineEdit::Normal, label, &ok);
if (ok && !label.isEmpty()) {
if(misc::isValidFileSystemName(label)) {
addLabel(label);
} else {
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
invalid = true;
}
}
}while(invalid);
return;
}
}

19
src/transferlistwidget.cpp

@ -868,11 +868,20 @@ void TransferListWidget::toggleSelectedFirstLastPiecePrio() { @@ -868,11 +868,20 @@ void TransferListWidget::toggleSelectedFirstLastPiecePrio() {
void TransferListWidget::askNewLabelForSelection() {
// Ask for label
bool ok;
QString label = QInputDialog::getText(this, tr("New Label"), tr("Label:"), QLineEdit::Normal, "", &ok);
if (ok && !label.isEmpty()) {
// Assign label to selection
setSelectionLabel(label);
}
QString label = "";
bool invalid;
do {
invalid = false;
label = QInputDialog::getText(this, tr("New Label"), tr("Label:"), QLineEdit::Normal, label, &ok);
if (ok && !label.isEmpty()) {
if(misc::isValidFileSystemName(label)) {
setSelectionLabel(label);
} else {
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
invalid = true;
}
}
}while(invalid);
}
void TransferListWidget::renameSelectedTorrent() {

Loading…
Cancel
Save