From 33a379607466bc80c75724d3990e1ba88ae35130 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sun, 23 Feb 2025 22:33:48 -0500 Subject: [PATCH] Add ability to parse tags from CSV files * Closes #7956 --- share/translations/keepassxc_en.ts | 8 + src/gui/csvImport/CsvImportWidget.cpp | 18 +- src/gui/csvImport/CsvImportWidget.ui | 471 ++++++++++++++------------ 3 files changed, 268 insertions(+), 229 deletions(-) diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts index db844c3b0..301d888ff 100644 --- a/share/translations/keepassxc_en.ts +++ b/share/translations/keepassxc_en.ts @@ -1445,6 +1445,10 @@ Do you want to overwrite the passkey in %1 - %2? Are you sure you want to import? + + Tags + + CsvParserModel @@ -9232,6 +9236,10 @@ This option is deprecated, use --set-key-file instead. %1, row: %2, column: %3 + + Tags + + QtIOCompressor diff --git a/src/gui/csvImport/CsvImportWidget.cpp b/src/gui/csvImport/CsvImportWidget.cpp index 714e62cff..cbabd3138 100644 --- a/src/gui/csvImport/CsvImportWidget.cpp +++ b/src/gui/csvImport/CsvImportWidget.cpp @@ -75,13 +75,14 @@ CsvImportWidget::CsvImportWidget(QWidget* parent) m_ui->tableViewFields->setFocusPolicy(Qt::NoFocus); m_columnHeader << QObject::tr("Group") << QObject::tr("Title") << QObject::tr("Username") << QObject::tr("Password") - << QObject::tr("URL") << QObject::tr("Notes") << QObject::tr("TOTP") << QObject::tr("Icon") - << QObject::tr("Last Modified") << QObject::tr("Created"); + << QObject::tr("URL") << QObject::tr("Tags") << QObject::tr("Notes") << QObject::tr("TOTP") + << QObject::tr("Icon") << QObject::tr("Last Modified") << QObject::tr("Created"); m_fieldSeparatorList << "," << ";" << "-" << ":" << "." << "\t"; m_combos << m_ui->groupCombo << m_ui->titleCombo << m_ui->usernameCombo << m_ui->passwordCombo << m_ui->urlCombo - << m_ui->notesCombo << m_ui->totpCombo << m_ui->iconCombo << m_ui->lastModifiedCombo << m_ui->createdCombo; + << m_ui->tagsCombo << m_ui->notesCombo << m_ui->totpCombo << m_ui->iconCombo << m_ui->lastModifiedCombo + << m_ui->createdCombo; for (auto combo : m_combos) { combo->setModel(m_comboModel); @@ -254,10 +255,11 @@ QSharedPointer CsvImportWidget::buildDatabase() entry->setUsername(m_parserModel->data(m_parserModel->index(r, 2)).toString()); entry->setPassword(m_parserModel->data(m_parserModel->index(r, 3)).toString()); entry->setUrl(m_parserModel->data(m_parserModel->index(r, 4)).toString()); - entry->setNotes(m_parserModel->data(m_parserModel->index(r, 5)).toString()); + entry->setTags(m_parserModel->data(m_parserModel->index(r, 5)).toString()); + entry->setNotes(m_parserModel->data(m_parserModel->index(r, 6)).toString()); // TOTP - auto otpString = m_parserModel->data(m_parserModel->index(r, 6)); + auto otpString = m_parserModel->data(m_parserModel->index(r, 7)); if (otpString.isValid() && !otpString.toString().isEmpty()) { auto totp = Totp::parseSettings(otpString.toString()); if (!totp || totp->key.isEmpty()) { @@ -269,14 +271,14 @@ QSharedPointer CsvImportWidget::buildDatabase() // Icon bool ok; - int icon = m_parserModel->data(m_parserModel->index(r, 7)).toInt(&ok); + int icon = m_parserModel->data(m_parserModel->index(r, 8)).toInt(&ok); if (ok) { entry->setIcon(icon); } // Modified Time TimeInfo timeInfo; - if (m_parserModel->data(m_parserModel->index(r, 8)).isValid()) { + if (m_parserModel->data(m_parserModel->index(r, 9)).isValid()) { auto datetime = m_parserModel->data(m_parserModel->index(r, 8)).toString(); if (datetime.contains(QRegularExpression("^\\d+$"))) { auto t = datetime.toLongLong(); @@ -295,7 +297,7 @@ QSharedPointer CsvImportWidget::buildDatabase() } } // Creation Time - if (m_parserModel->data(m_parserModel->index(r, 9)).isValid()) { + if (m_parserModel->data(m_parserModel->index(r, 10)).isValid()) { auto datetime = m_parserModel->data(m_parserModel->index(r, 9)).toString(); if (datetime.contains(QRegularExpression("^\\d+$"))) { auto t = datetime.toLongLong(); diff --git a/src/gui/csvImport/CsvImportWidget.ui b/src/gui/csvImport/CsvImportWidget.ui index d4eddba74..6fb21e595 100644 --- a/src/gui/csvImport/CsvImportWidget.ui +++ b/src/gui/csvImport/CsvImportWidget.ui @@ -40,95 +40,6 @@ Column Association - - - - - 50 - false - - - - Icon - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 2 - - - - - - - - 50 - false - - - - TOTP - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 2 - - - - - - - - 200 - 16777215 - - - - QComboBox::AdjustToContents - - - - - - - - 50 - false - - - - Notes - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 2 - - - - - - - - 50 - false - - - - Title - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 2 - - - @@ -142,74 +53,6 @@ - - - - - 200 - 16777215 - - - - QComboBox::AdjustToContents - - - - - - - - 200 - 16777215 - - - - QComboBox::AdjustToContents - - - - - - - - 200 - 16777215 - - - - QComboBox::AdjustToContents - - - - - - - - 50 - false - - - - First line has field names - - - true - - - - - - - - 200 - 16777215 - - - - QComboBox::AdjustToContents - - - @@ -223,25 +66,6 @@ - - - - - 50 - false - - - - Password - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 2 - - - @@ -261,16 +85,22 @@ - - - - - 200 - 16777215 - + + + + + 50 + false + - - QComboBox::AdjustToContents + + Notes + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 2 @@ -293,25 +123,6 @@ - - - - - 50 - false - - - - URL - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 2 - - - @@ -325,27 +136,21 @@ - - - - - 50 - false - + + + + + 200 + 16777215 + - - Created - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 2 + + QComboBox::AdjustToContents - - + + 200 @@ -376,6 +181,51 @@ + + + + + 200 + 16777215 + + + + QComboBox::AdjustToContents + + + + + + + + 200 + 16777215 + + + + QComboBox::AdjustToContents + + + + + + + + 50 + false + + + + Password + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 2 + + + @@ -392,6 +242,169 @@ + + + + + 50 + false + + + + Created + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 2 + + + + + + + + 200 + 16777215 + + + + QComboBox::AdjustToContents + + + + + + + + 50 + false + + + + URL + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 2 + + + + + + + + 50 + false + + + + TOTP + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 2 + + + + + + + + 200 + 16777215 + + + + QComboBox::AdjustToContents + + + + + + + + 50 + false + + + + Icon + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 2 + + + + + + + + 50 + false + + + + Title + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 2 + + + + + + + + 200 + 16777215 + + + + QComboBox::AdjustToContents + + + + + + + + 50 + false + + + + Tags + + + 2 + + + + + + + + 200 + 16777215 + + + + QComboBox::AdjustToContents + + + @@ -684,6 +697,22 @@ + + + + + 50 + false + + + + First line has field names + + + true + + +