Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kamm <mail@ckamm.de>2018-05-03 12:44:51 +0300
committerChristian Kamm <mail@ckamm.de>2018-05-15 15:26:35 +0300
commitf396f2f41dca0c1e3fd404db82693303f76b9062 (patch)
treefa55114b20bcc890d59f2ff27aba88496d139c26 /src/gui/ignorelisteditor.cpp
parent8d14f4357ab16e9225f17e4fdfe8a9129707abaa (diff)
IgnoreEditor: Preserve comments, add #!readonly
Useful in case we ever want to make use of directives inside the ignore list.
Diffstat (limited to 'src/gui/ignorelisteditor.cpp')
-rw-r--r--src/gui/ignorelisteditor.cpp86
1 files changed, 56 insertions, 30 deletions
diff --git a/src/gui/ignorelisteditor.cpp b/src/gui/ignorelisteditor.cpp
index c82ac7a3b..758aa5e92 100644
--- a/src/gui/ignorelisteditor.cpp
+++ b/src/gui/ignorelisteditor.cpp
@@ -27,8 +27,10 @@
namespace OCC {
-static int patternCol = 0;
-static int deletableCol = 1;
+static const int patternCol = 0;
+static const int deletableCol = 1;
+static const int skippedLinesRole = Qt::UserRole;
+static const int isGlobalRole = Qt::UserRole + 1;
IgnoreListEditor::IgnoreListEditor(QWidget *parent)
: QDialog(parent)
@@ -47,11 +49,11 @@ IgnoreListEditor::IgnoreListEditor(QWidget *parent)
"and cannot be modified in this view.")
.arg(QDir::toNativeSeparators(cfgFile.excludeFile(ConfigFile::SystemScope)));
- addPattern(".csync_journal.db*", /*deletable=*/false, /*readonly=*/true);
- addPattern("._sync_*.db*", /*deletable=*/false, /*readonly=*/true);
- addPattern(".sync_*.db*", /*deletable=*/false, /*readonly=*/true);
- readIgnoreFile(cfgFile.excludeFile(ConfigFile::SystemScope), true);
- readIgnoreFile(cfgFile.excludeFile(ConfigFile::UserScope), false);
+ addPattern(".csync_journal.db*", /*deletable=*/false, /*readonly=*/true, /*global=*/true);
+ addPattern("._sync_*.db*", /*deletable=*/false, /*readonly=*/true, /*global=*/true);
+ addPattern(".sync_*.db*", /*deletable=*/false, /*readonly=*/true, /*global=*/true);
+ readIgnoreFile(cfgFile.excludeFile(ConfigFile::SystemScope), /*global=*/true);
+ readIgnoreFile(cfgFile.excludeFile(ConfigFile::UserScope), /*global=*/false);
connect(this, &QDialog::accepted, this, &IgnoreListEditor::slotUpdateLocalIgnoreList);
ui->removePushButton->setEnabled(false);
@@ -102,15 +104,21 @@ void IgnoreListEditor::slotUpdateLocalIgnoreList()
for (int row = 0; row < ui->tableWidget->rowCount(); ++row) {
QTableWidgetItem *patternItem = ui->tableWidget->item(row, patternCol);
QTableWidgetItem *deletableItem = ui->tableWidget->item(row, deletableCol);
- if (patternItem->flags() & Qt::ItemIsEnabled) {
- QByteArray prepend;
- if (deletableItem->checkState() == Qt::Checked) {
- prepend = "]";
- } else if (patternItem->text().startsWith('#')) {
- prepend = "\\";
- }
- ignores.write(prepend + patternItem->text().toUtf8() + '\n');
+
+ if (patternItem->data(isGlobalRole).toBool())
+ continue;
+
+ QStringList skippedLines = patternItem->data(skippedLinesRole).toStringList();
+ for (const auto &line : skippedLines)
+ ignores.write(line.toUtf8() + '\n');
+
+ QByteArray prepend;
+ if (deletableItem->checkState() == Qt::Checked) {
+ prepend = "]";
+ } else if (patternItem->text().startsWith('#')) {
+ prepend = "\\";
}
+ ignores.write(prepend + patternItem->text().toUtf8() + '\n');
}
} else {
QMessageBox::warning(this, tr("Could not open file"),
@@ -146,36 +154,54 @@ void IgnoreListEditor::slotAddPattern()
if (!okClicked || pattern.isEmpty())
return;
- addPattern(pattern, false, false);
+ addPattern(pattern, /*deletable=*/false, /*readonly=*/false, /*global=*/false);
ui->tableWidget->scrollToBottom();
}
-void IgnoreListEditor::readIgnoreFile(const QString &file, bool readOnly)
+void IgnoreListEditor::readIgnoreFile(const QString &file, bool global)
{
QFile ignores(file);
- if (ignores.open(QIODevice::ReadOnly)) {
- while (!ignores.atEnd()) {
- QString line = QString::fromUtf8(ignores.readLine());
- line.chop(1);
- if (!line.isEmpty() && !line.startsWith("#")) {
- bool deletable = false;
- if (line.startsWith(']')) {
- deletable = true;
- line = line.mid(1);
- }
- addPattern(line, deletable, readOnly);
- }
+ if (!ignores.open(QIODevice::ReadOnly))
+ return;
+
+ QStringList skippedLines;
+ bool readonly = global; // global ignores default to read-only
+
+ while (!ignores.atEnd()) {
+ QString line = QString::fromUtf8(ignores.readLine());
+ line.chop(1);
+
+ // Collect empty lines and comments, we want to preserve them
+ if (line.isEmpty() || line.startsWith("#")) {
+ skippedLines.append(line);
+ // A directive that prohibits editing in the ui
+ if (line == "#!readonly")
+ readonly = true;
+ continue;
}
+
+ bool deletable = false;
+ if (line.startsWith(']')) {
+ deletable = true;
+ line = line.mid(1);
+ }
+
+ // Add and reset
+ addPattern(line, deletable, readonly, global, skippedLines);
+ skippedLines.clear();
+ readonly = global;
}
}
-int IgnoreListEditor::addPattern(const QString &pattern, bool deletable, bool readOnly)
+int IgnoreListEditor::addPattern(const QString &pattern, bool deletable, bool readOnly, bool global, const QStringList &skippedLines)
{
int newRow = ui->tableWidget->rowCount();
ui->tableWidget->setRowCount(newRow + 1);
QTableWidgetItem *patternItem = new QTableWidgetItem;
patternItem->setText(pattern);
+ patternItem->setData(skippedLinesRole, skippedLines);
+ patternItem->setData(isGlobalRole, global);
ui->tableWidget->setItem(newRow, patternCol, patternItem);
QTableWidgetItem *deletableItem = new QTableWidgetItem;