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

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/csvImport/CsvImportWidget.cpp')
-rw-r--r--src/gui/csvImport/CsvImportWidget.cpp105
1 files changed, 30 insertions, 75 deletions
diff --git a/src/gui/csvImport/CsvImportWidget.cpp b/src/gui/csvImport/CsvImportWidget.cpp
index 6e6c282b9..01fd5fc89 100644
--- a/src/gui/csvImport/CsvImportWidget.cpp
+++ b/src/gui/csvImport/CsvImportWidget.cpp
@@ -39,69 +39,26 @@ CsvImportWidget::CsvImportWidget(QWidget* parent)
, m_comboModel(new QStringListModel(this))
, m_columnHeader(QStringList() << QObject::tr("Group") << QObject::tr("Title") << QObject::tr("Username")
<< QObject::tr("Password") << QObject::tr("URL") << QObject::tr("Notes")
- << QObject::tr("Last Modified") << QObject::tr("Created")
- /* << QObject::tr("Future field1") */)
-{
- m_ui->setupUi(this);
-
- m_ui->comboBoxCodec->addItems(QStringList() << "UTF-8"
- << "Windows-1252"
- << "UTF-16"
- << "UTF-16LE");
- m_ui->comboBoxFieldSeparator->addItems(QStringList() << ","
- << ";"
- << "-"
- << ":"
- << "."
- << "TAB (\\t)");
- m_fieldSeparatorList = QStringList() << ","
+ << QObject::tr("Last Modified") << QObject::tr("Created"))
+ , m_fieldSeparatorList(QStringList() << ","
<< ";"
<< "-"
<< ":"
<< "."
- << "\t";
- m_ui->comboBoxTextQualifier->addItems(QStringList() << "\""
- << "'"
- << ":"
- << "."
- << "|");
- m_ui->comboBoxComment->addItems(QStringList() << "#"
- << ";"
- << ":"
- << "@");
+ << "\t")
+{
+ m_ui->setupUi(this);
+
m_ui->tableViewFields->setSelectionMode(QAbstractItemView::NoSelection);
m_ui->tableViewFields->setFocusPolicy(Qt::NoFocus);
m_ui->messageWidget->setHidden(true);
- for (int i = 0; i < m_columnHeader.count(); ++i) {
- QLabel* label = new QLabel(m_columnHeader.at(i), this);
- label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
- QFont font = label->font();
- font.setBold(false);
- label->setFont(font);
-
- QComboBox* combo = new QComboBox(this);
- font = combo->font();
- font.setBold(false);
- combo->setFont(font);
- m_combos.append(combo);
+ m_combos << m_ui->groupCombo << m_ui->titleCombo << m_ui->usernameCombo << m_ui->passwordCombo << m_ui->urlCombo
+ << m_ui->notesCombo << m_ui->lastModifiedCombo << m_ui->createdCombo;
+
+ for (auto combo : m_combos) {
combo->setModel(m_comboModel);
-#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
- connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=] { comboChanged(combo, i); });
-#else
- connect(combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=] {
- comboChanged(combo, i);
- });
-#endif
-
- // layout labels and combo fields in column-first order
- int combo_rows = 1 + (m_columnHeader.count() - 1) / 2;
- int x = i % combo_rows;
- int y = 2 * (i / combo_rows);
- m_ui->gridLayout_combos->addWidget(label, x, y);
- m_ui->gridLayout_combos->addWidget(combo, x, y + 1);
- QSpacerItem* item = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
- m_ui->gridLayout_combos->addItem(item, x, y + 2);
+ connect(combo, SIGNAL(currentIndexChanged(int)), SLOT(comboChanged(int)));
}
m_parserModel->setHeaderLabels(m_columnHeader);
@@ -119,12 +76,10 @@ CsvImportWidget::CsvImportWidget(QWidget* parent)
connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
}
-void CsvImportWidget::comboChanged(QComboBox* currentSender, int comboId)
+void CsvImportWidget::comboChanged(int index)
{
- if (currentSender->currentIndex() != -1) {
- // this line is the one that actually updates GUI table
- m_parserModel->mapColumns(currentSender->currentIndex(), comboId);
- }
+ // this line is the one that actually updates GUI table
+ m_parserModel->mapColumns(index, m_combos.indexOf(qobject_cast<QComboBox*>(sender())));
updateTableview();
}
@@ -167,19 +122,17 @@ void CsvImportWidget::updatePreview()
m_ui->spinBoxSkip->setRange(minSkip, qMax(minSkip, m_parserModel->rowCount() - 1));
m_ui->spinBoxSkip->setValue(minSkip);
- int emptyId = 0;
- QString columnName;
- QStringList list(tr("Not present in CSV file"));
-
+ QStringList list(tr("Not Present"));
for (int i = 1; i < m_parserModel->getCsvCols(); ++i) {
if (m_ui->checkBoxFieldNames->isChecked()) {
- columnName = m_parserModel->getCsvTable().at(0).at(i);
+ auto columnName = m_parserModel->getCsvTable().at(0).at(i);
if (columnName.isEmpty()) {
- columnName = "<" + tr("Empty fieldname %1").arg(++emptyId) + ">";
+ list << QString(tr("Column %1").arg(i));
+ } else {
+ list << columnName;
}
- list << columnName;
} else {
- list << QString(tr("column %1").arg(i));
+ list << QString(tr("Column %1").arg(i));
}
}
m_comboModel->setStringList(list);
@@ -221,7 +174,6 @@ void CsvImportWidget::parse()
} else {
m_ui->messageWidget->setHidden(true);
}
- QWidget::adjustSize();
}
QString CsvImportWidget::formatStatusText() const
@@ -294,27 +246,30 @@ void CsvImportWidget::setRootGroup()
for (int r = 0; r < m_parserModel->rowCount(); ++r) {
// use validity of second column as a GO/NOGO for all others fields
- if (not m_parserModel->data(m_parserModel->index(r, 1)).isValid())
+ if (not m_parserModel->data(m_parserModel->index(r, 1)).isValid()) {
continue;
+ }
groupLabel = m_parserModel->data(m_parserModel->index(r, 0)).toString();
// check if group name is either "root", "" (empty) or some other label
groupList = groupLabel.split("/", QString::SkipEmptyParts);
- if (groupList.isEmpty())
+ if (groupList.isEmpty()) {
is_empty = true;
- else if (not groupList.first().compare("Root", Qt::CaseSensitive))
+ } else if (not groupList.first().compare("Root", Qt::CaseSensitive)) {
is_root = true;
- else if (not groupLabel.compare(""))
+ } else if (not groupLabel.compare("")) {
is_empty = true;
- else
+ } else {
is_label = true;
+ }
groupList.clear();
}
- if ((is_empty and is_root) or (is_label and not is_empty and is_root))
+ if ((is_empty and is_root) or (is_label and not is_empty and is_root)) {
m_db->rootGroup()->setName("CSV IMPORTED");
- else
+ } else {
m_db->rootGroup()->setName("Root");
+ }
}
Group* CsvImportWidget::splitGroups(const QString& label)