mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-09-21 13:24:47 -04:00
Fix various quirks with CSV import widget and parser
* Fixes #11502 - correct improper handling of text qualifiers * Improve layout of csv import widget * Hide error messages when trying to import again
This commit is contained in:
parent
244ed42231
commit
1b1643b5d1
8 changed files with 248 additions and 120 deletions
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "CsvImportWidget.h"
|
||||
|
||||
#include "ui_CsvImportWidget.h"
|
||||
|
||||
#include "core/Clock.h"
|
||||
|
@ -145,6 +146,13 @@ void CsvImportWidget::updatePreview()
|
|||
m_ui->spinBoxSkip->setRange(minSkip, qMax(minSkip, m_parserModel->rowCount() - 1));
|
||||
m_ui->spinBoxSkip->setValue(minSkip);
|
||||
|
||||
// Store the previous column information for comparison later
|
||||
auto prevColumns = m_comboModel->stringList();
|
||||
QList<int> prevComboIndexes;
|
||||
for (auto combo : m_combos) {
|
||||
prevComboIndexes << combo->currentIndex();
|
||||
}
|
||||
|
||||
QStringList csvColumns(tr("Not Present"));
|
||||
auto parser = m_parserModel->parser();
|
||||
for (int i = 0; i < parser->getCsvCols(); ++i) {
|
||||
|
@ -159,6 +167,8 @@ void CsvImportWidget::updatePreview()
|
|||
csvColumns << QString(tr("Column %1").arg(i));
|
||||
}
|
||||
}
|
||||
// Before setting new columns, see if they changed
|
||||
bool newColumns = prevColumns != csvColumns;
|
||||
m_comboModel->setStringList(csvColumns);
|
||||
|
||||
// Try to match named columns to the combo boxes
|
||||
|
@ -177,9 +187,10 @@ void CsvImportWidget::updatePreview()
|
|||
break;
|
||||
}
|
||||
}
|
||||
// Named column not found, default to "Not Present"
|
||||
// Named column not found, default to "Not Present" or previous index
|
||||
if (!found) {
|
||||
m_combos.at(i)->setCurrentIndex(0);
|
||||
auto idx = newColumns ? 0 : prevComboIndexes.at(i);
|
||||
m_combos.at(i)->setCurrentIndex(idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,15 +207,19 @@ void CsvImportWidget::load(const QString& filename)
|
|||
|
||||
void CsvImportWidget::parse()
|
||||
{
|
||||
configParser();
|
||||
// Hide any previous messages
|
||||
emit message("");
|
||||
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
QApplication::processEvents();
|
||||
bool good = m_parserModel->parse();
|
||||
updatePreview();
|
||||
QApplication::restoreOverrideCursor();
|
||||
if (!good) {
|
||||
|
||||
configParser();
|
||||
if (!m_parserModel->parse()) {
|
||||
emit message(tr("Failed to parse CSV file: %1").arg(formatStatusText()));
|
||||
}
|
||||
updatePreview();
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
QSharedPointer<Database> CsvImportWidget::buildDatabase()
|
||||
|
|
|
@ -79,7 +79,17 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QComboBox" name="notesCombo"/>
|
||||
<widget class="QComboBox" name="notesCombo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="notesLabel">
|
||||
|
@ -120,16 +130,56 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="urlCombo"/>
|
||||
<widget class="QComboBox" name="urlCombo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QComboBox" name="totpCombo"/>
|
||||
<widget class="QComboBox" name="totpCombo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="4">
|
||||
<widget class="QComboBox" name="createdCombo"/>
|
||||
<widget class="QComboBox" name="createdCombo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="titleCombo"/>
|
||||
<widget class="QComboBox" name="titleCombo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="5">
|
||||
<widget class="QCheckBox" name="checkBoxFieldNames">
|
||||
|
@ -148,10 +198,30 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<widget class="QComboBox" name="iconCombo"/>
|
||||
<widget class="QComboBox" name="iconCombo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="usernameCombo"/>
|
||||
<widget class="QComboBox" name="usernameCombo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="passwordLabel">
|
||||
|
@ -192,7 +262,17 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="passwordCombo"/>
|
||||
<widget class="QComboBox" name="passwordCombo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="usernameLabel">
|
||||
|
@ -233,7 +313,17 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="3" column="4">
|
||||
<widget class="QComboBox" name="lastModifiedCombo"/>
|
||||
<widget class="QComboBox" name="lastModifiedCombo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="3">
|
||||
<widget class="QLabel" name="createdLabel">
|
||||
|
@ -255,7 +345,17 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="groupCombo"/>
|
||||
<widget class="QComboBox" name="groupCombo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QLabel" name="lastModifiedLabel">
|
||||
|
|
|
@ -122,7 +122,11 @@ void ImportWizardPageReview::setupCsvImport(const QString& filename)
|
|||
|
||||
m_csvWidget = new CsvImportWidget();
|
||||
connect(m_csvWidget, &CsvImportWidget::message, m_ui->messageWidget, [this](QString message) {
|
||||
m_ui->messageWidget->showMessage(message, KMessageWidget::Error, -1);
|
||||
if (message.isEmpty()) {
|
||||
m_ui->messageWidget->hideMessage();
|
||||
} else {
|
||||
m_ui->messageWidget->showMessage(message, MessageWidget::Error, -1);
|
||||
}
|
||||
});
|
||||
|
||||
m_csvWidget->load(filename);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue