mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-13 08:19:50 -05:00
parent
3662f6aa77
commit
f80e79f71a
@ -1391,6 +1391,15 @@ Do you want to overwrite the passkey in %1 - %2?</source>
|
|||||||
<source>Imported from CSV file: %1</source>
|
<source>Imported from CSV file: %1</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>No Title Selected</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>No title column was selected, entries will be hard to tell apart.
|
||||||
|
Are you sure you want to import?</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>CsvParserModel</name>
|
<name>CsvParserModel</name>
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "core/Totp.h"
|
#include "core/Totp.h"
|
||||||
#include "format/CsvParser.h"
|
#include "format/CsvParser.h"
|
||||||
#include "format/KeePass2Writer.h"
|
#include "format/KeePass2Writer.h"
|
||||||
|
#include "gui/MessageBox.h"
|
||||||
#include "gui/csvImport/CsvParserModel.h"
|
#include "gui/csvImport/CsvParserModel.h"
|
||||||
|
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
@ -213,19 +214,29 @@ void CsvImportWidget::parse()
|
|||||||
|
|
||||||
QSharedPointer<Database> CsvImportWidget::buildDatabase()
|
QSharedPointer<Database> CsvImportWidget::buildDatabase()
|
||||||
{
|
{
|
||||||
|
// Warn if the title column wasn't specified
|
||||||
|
if (m_combos[1]->currentIndex() == 0) {
|
||||||
|
auto ans = MessageBox::question(
|
||||||
|
this,
|
||||||
|
tr("No Title Selected"),
|
||||||
|
tr("No title column was selected, entries will be hard to tell apart.\nAre you sure you want to import?"),
|
||||||
|
MessageBox::Continue | MessageBox::Cancel);
|
||||||
|
if (ans == MessageBox::Cancel) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto db = QSharedPointer<Database>::create();
|
auto db = QSharedPointer<Database>::create();
|
||||||
db->rootGroup()->setNotes(tr("Imported from CSV file: %1").arg(m_filename));
|
db->rootGroup()->setNotes(tr("Imported from CSV file: %1").arg(m_filename));
|
||||||
|
|
||||||
for (int r = 0; r < m_parserModel->rowCount(); ++r) {
|
auto rows = m_parserModel->rowCount() - m_parserModel->skippedRows();
|
||||||
// use validity of second column as a GO/NOGO for all others fields
|
for (int r = 0; r < rows; ++r) {
|
||||||
if (!m_parserModel->data(m_parserModel->index(r, 1)).isValid()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto group = createGroupStructure(db.data(), m_parserModel->data(m_parserModel->index(r, 0)).toString());
|
auto group = createGroupStructure(db.data(), m_parserModel->data(m_parserModel->index(r, 0)).toString());
|
||||||
if (!group) {
|
if (!group) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Standard entry fields
|
||||||
auto entry = new Entry();
|
auto entry = new Entry();
|
||||||
entry->setUuid(QUuid::createUuid());
|
entry->setUuid(QUuid::createUuid());
|
||||||
entry->setGroup(group);
|
entry->setGroup(group);
|
||||||
@ -235,6 +246,7 @@ QSharedPointer<Database> CsvImportWidget::buildDatabase()
|
|||||||
entry->setUrl(m_parserModel->data(m_parserModel->index(r, 4)).toString());
|
entry->setUrl(m_parserModel->data(m_parserModel->index(r, 4)).toString());
|
||||||
entry->setNotes(m_parserModel->data(m_parserModel->index(r, 5)).toString());
|
entry->setNotes(m_parserModel->data(m_parserModel->index(r, 5)).toString());
|
||||||
|
|
||||||
|
// TOTP
|
||||||
auto otpString = m_parserModel->data(m_parserModel->index(r, 6));
|
auto otpString = m_parserModel->data(m_parserModel->index(r, 6));
|
||||||
if (otpString.isValid() && !otpString.toString().isEmpty()) {
|
if (otpString.isValid() && !otpString.toString().isEmpty()) {
|
||||||
auto totp = Totp::parseSettings(otpString.toString());
|
auto totp = Totp::parseSettings(otpString.toString());
|
||||||
@ -245,12 +257,14 @@ QSharedPointer<Database> CsvImportWidget::buildDatabase()
|
|||||||
entry->setTotp(totp);
|
entry->setTotp(totp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Icon
|
||||||
bool ok;
|
bool ok;
|
||||||
int icon = m_parserModel->data(m_parserModel->index(r, 7)).toInt(&ok);
|
int icon = m_parserModel->data(m_parserModel->index(r, 7)).toInt(&ok);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
entry->setIcon(icon);
|
entry->setIcon(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Modified Time
|
||||||
TimeInfo timeInfo;
|
TimeInfo timeInfo;
|
||||||
if (m_parserModel->data(m_parserModel->index(r, 8)).isValid()) {
|
if (m_parserModel->data(m_parserModel->index(r, 8)).isValid()) {
|
||||||
auto datetime = m_parserModel->data(m_parserModel->index(r, 8)).toString();
|
auto datetime = m_parserModel->data(m_parserModel->index(r, 8)).toString();
|
||||||
@ -270,6 +284,7 @@ QSharedPointer<Database> CsvImportWidget::buildDatabase()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Creation Time
|
||||||
if (m_parserModel->data(m_parserModel->index(r, 9)).isValid()) {
|
if (m_parserModel->data(m_parserModel->index(r, 9)).isValid()) {
|
||||||
auto datetime = m_parserModel->data(m_parserModel->index(r, 9)).toString();
|
auto datetime = m_parserModel->data(m_parserModel->index(r, 9)).toString();
|
||||||
if (datetime.contains(QRegularExpression("^\\d+$"))) {
|
if (datetime.contains(QRegularExpression("^\\d+$"))) {
|
||||||
|
@ -92,6 +92,11 @@ void CsvParserModel::setSkippedRows(int skipped)
|
|||||||
emit layoutChanged();
|
emit layoutChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CsvParserModel::skippedRows() const
|
||||||
|
{
|
||||||
|
return m_skipped;
|
||||||
|
}
|
||||||
|
|
||||||
void CsvParserModel::setHeaderLabels(const QStringList& labels)
|
void CsvParserModel::setHeaderLabels(const QStringList& labels)
|
||||||
{
|
{
|
||||||
m_columnHeader = labels;
|
m_columnHeader = labels;
|
||||||
|
@ -45,8 +45,8 @@ public:
|
|||||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||||
|
|
||||||
public slots:
|
|
||||||
void setSkippedRows(int skipped);
|
void setSkippedRows(int skipped);
|
||||||
|
int skippedRows() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CsvParser* m_parser;
|
CsvParser* m_parser;
|
||||||
|
Loading…
Reference in New Issue
Block a user