history: import descriptions from CSV

This commit is contained in:
tobtoht
2024-10-07 15:34:27 +02:00
parent b7ef31610e
commit 6aa661d7ba
9 changed files with 137 additions and 9 deletions
+17 -1
View File
@@ -315,6 +315,7 @@ void MainWindow::initMenu() {
// [Wallet] -> [History]
connect(ui->actionExport_CSV, &QAction::triggered, this, &MainWindow::onExportHistoryCSV);
connect(ui->actionImportHistoryCSV, &QAction::triggered, this, &MainWindow::onImportHistoryDescriptionsCSV);
// [Wallet] -> [Contacts]
connect(ui->actionExportContactsCSV, &QAction::triggered, this, &MainWindow::onExportContactsCSV);
@@ -575,7 +576,7 @@ void MainWindow::onWalletOpened() {
m_wallet->history()->refresh();
});
// Vice versa
connect(m_wallet->history(), &TransactionHistory::txNoteChanged, [this] {
connect(m_wallet->transactionHistoryModel(), &TransactionHistoryModel::transactionDescriptionChanged, [this] {
m_wallet->coins()->refresh();
});
@@ -1713,6 +1714,21 @@ void MainWindow::onExportHistoryCSV() {
Utils::showInfo(this, "CSV export", QString("Transaction history exported to %1").arg(fn));
}
void MainWindow::onImportHistoryDescriptionsCSV() {
const QString fileName = QFileDialog::getOpenFileName(this, "Import CSV file", QDir::homePath(), "CSV Files (*.csv)");
if (fileName.isEmpty()) {
return;
}
QString error = m_wallet->history()->importLabelsFromCSV(fileName);
if (!error.isEmpty()) {
Utils::showError(this, "Unable to import transaction descriptions from CSV", error);
}
else {
Utils::showInfo(this, "Successfully imported transaction descriptions from CSV");
}
}
void MainWindow::onExportContactsCSV() {
auto *model = m_wallet->addressBookModel();
if (model->rowCount() <= 0){