mirror of
https://github.com/feather-wallet/feather.git
synced 2025-04-10 07:07:32 +00:00
contacts: move import/export to tool button
This commit is contained in:
parent
b27d724a5b
commit
45f3d89dd3
5 changed files with 42 additions and 50 deletions
|
@ -5,6 +5,7 @@
|
|||
#include "ui_ContactsWidget.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
|
||||
#include "dialog/ContactsDialog.h"
|
||||
#include "model/AddressBookModel.h"
|
||||
|
@ -38,6 +39,9 @@ ContactsWidget::ContactsWidget(Wallet *wallet, QWidget *parent)
|
|||
m_headerMenu->addAction("New contact", [this] {
|
||||
this->newContact();
|
||||
});
|
||||
m_headerMenu->addAction("Import CSV", this, &ContactsWidget::importCSV);
|
||||
m_headerMenu->addAction("Export CSV", this, &ContactsWidget::exportCSV);
|
||||
m_headerMenu->addSeparator();
|
||||
m_showFullAddressesAction = m_headerMenu->addAction("Show full addresses", this, &ContactsWidget::setShowFullAddresses);
|
||||
m_showFullAddressesAction->setCheckable(true);
|
||||
|
||||
|
@ -118,6 +122,42 @@ void ContactsWidget::showHeaderMenu(const QPoint& position)
|
|||
m_headerMenu->exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void ContactsWidget::importCSV() {
|
||||
const QString targetFile = QFileDialog::getOpenFileName(this, "Import CSV file", QDir::homePath(), "CSV Files (*.csv)");
|
||||
if(targetFile.isEmpty()) return;
|
||||
|
||||
auto *model = m_wallet->addressBookModel();
|
||||
QMapIterator<QString, QString> i(model->readCSV(targetFile));
|
||||
int inserts = 0;
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
bool addressValid = WalletManager::addressValid(i.value(), m_wallet->nettype());
|
||||
if(addressValid) {
|
||||
m_wallet->addressBook()->addRow(i.value(), i.key());
|
||||
inserts++;
|
||||
}
|
||||
}
|
||||
|
||||
Utils::showInfo(this, "Contacts imported", QString("Total contacts imported: %1").arg(inserts));
|
||||
}
|
||||
|
||||
void ContactsWidget::exportCSV() {
|
||||
auto *model = m_wallet->addressBookModel();
|
||||
if (model->rowCount() <= 0){
|
||||
Utils::showInfo(this, "Unable to export contacts", "No contacts to export");
|
||||
return;
|
||||
}
|
||||
|
||||
const QString targetDir = QFileDialog::getExistingDirectory(this, "Select CSV output directory ", QDir::homePath(), QFileDialog::ShowDirsOnly);
|
||||
if(targetDir.isEmpty()) return;
|
||||
|
||||
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||
QString fn = QString("%1/monero-contacts_%2.csv").arg(targetDir, QString::number(now / 1000));
|
||||
if (model->writeCSV(fn)) {
|
||||
Utils::showInfo(this, "Contacts exported successfully", QString("Exported to: %1").arg(fn));
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsWidget::newContact(QString address, QString name)
|
||||
{
|
||||
ContactsDialog dialog{this, address, name};
|
||||
|
|
|
@ -41,6 +41,8 @@ signals:
|
|||
|
||||
private slots:
|
||||
void showHeaderMenu(const QPoint &position);
|
||||
void importCSV();
|
||||
void exportCSV();
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::ContactsWidget> ui;
|
||||
|
|
|
@ -326,10 +326,6 @@ void MainWindow::initMenu() {
|
|||
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);
|
||||
connect(ui->actionImportContactsCSV, &QAction::triggered, this, &MainWindow::importContacts);
|
||||
|
||||
// [View]
|
||||
m_tabShowHideSignalMapper = new QSignalMapper(this);
|
||||
connect(ui->actionShow_Searchbar, &QAction::toggled, this, &MainWindow::toggleSearchbar);
|
||||
|
@ -1340,25 +1336,6 @@ void MainWindow::onResendTransaction(const QString &txid) {
|
|||
dialog.exec();
|
||||
}
|
||||
|
||||
void MainWindow::importContacts() {
|
||||
const QString targetFile = QFileDialog::getOpenFileName(this, "Import CSV file", QDir::homePath(), "CSV Files (*.csv)");
|
||||
if(targetFile.isEmpty()) return;
|
||||
|
||||
auto *model = m_wallet->addressBookModel();
|
||||
QMapIterator<QString, QString> i(model->readCSV(targetFile));
|
||||
int inserts = 0;
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
bool addressValid = WalletManager::addressValid(i.value(), m_wallet->nettype());
|
||||
if(addressValid) {
|
||||
m_wallet->addressBook()->addRow(i.value(), i.key());
|
||||
inserts++;
|
||||
}
|
||||
}
|
||||
|
||||
Utils::showInfo(this, "Contacts imported", QString("Total contacts imported: %1").arg(inserts));
|
||||
}
|
||||
|
||||
void MainWindow::saveGeo() {
|
||||
conf()->set(Config::geometry, QString(saveGeometry().toBase64()));
|
||||
conf()->set(Config::windowState, QString(saveState().toBase64()));
|
||||
|
@ -1764,23 +1741,6 @@ void MainWindow::onImportHistoryDescriptionsCSV() {
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::onExportContactsCSV() {
|
||||
auto *model = m_wallet->addressBookModel();
|
||||
if (model->rowCount() <= 0){
|
||||
Utils::showInfo(this, "Unable to export contacts", "No contacts to export");
|
||||
return;
|
||||
}
|
||||
|
||||
const QString targetDir = QFileDialog::getExistingDirectory(this, "Select CSV output directory ", QDir::homePath(), QFileDialog::ShowDirsOnly);
|
||||
if(targetDir.isEmpty()) return;
|
||||
|
||||
qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||
QString fn = QString("%1/monero-contacts_%2.csv").arg(targetDir, QString::number(now / 1000));
|
||||
if (model->writeCSV(fn)) {
|
||||
Utils::showInfo(this, "Contacts exported successfully", QString("Exported to: %1").arg(fn));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onCreateDesktopEntry() {
|
||||
auto msg = Utils::xdgDesktopEntryRegister() ? "Desktop entry created" : "Desktop entry not created due to an error.";
|
||||
QMessageBox::information(this, "Desktop entry", msg);
|
||||
|
|
|
@ -114,7 +114,6 @@ private slots:
|
|||
void menuClearHistoryClicked();
|
||||
void onExportHistoryCSV();
|
||||
void onImportHistoryDescriptionsCSV();
|
||||
void onExportContactsCSV();
|
||||
void onCreateDesktopEntry();
|
||||
void onShowDocumentation();
|
||||
void onReportBug();
|
||||
|
@ -159,7 +158,6 @@ private slots:
|
|||
void skinChanged(const QString &skinName);
|
||||
void onViewOnBlockExplorer(const QString &txid);
|
||||
void onResendTransaction(const QString &txid);
|
||||
void importContacts();
|
||||
void importTransaction();
|
||||
void onDeviceError(const QString &error, quint64 errorCode);
|
||||
void onDeviceButtonRequest(quint64 code);
|
||||
|
|
|
@ -538,13 +538,6 @@
|
|||
<addaction name="actionExport_CSV"/>
|
||||
<addaction name="actionImportHistoryCSV"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuContacts">
|
||||
<property name="title">
|
||||
<string>Contacts</string>
|
||||
</property>
|
||||
<addaction name="actionExportContactsCSV"/>
|
||||
<addaction name="actionImportContactsCSV"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuAdvanced">
|
||||
<property name="title">
|
||||
<string>Advanced</string>
|
||||
|
@ -565,7 +558,6 @@
|
|||
<addaction name="actionViewOnly"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="menuHistory"/>
|
||||
<addaction name="menuContacts"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuTools">
|
||||
<property name="title">
|
||||
|
|
Loading…
Reference in a new issue