wowlet/src/libwalletqt/SubaddressAccount.cpp
dsc 133700160a Feather, a free Monero desktop wallet
Co-Authored-By: tobtoht <thotbot@protonmail.com>
2020-10-08 04:31:22 +02:00

64 lines
1.4 KiB
C++

// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2014-2020, The Monero Project.
#include "SubaddressAccount.h"
#include <QDebug>
SubaddressAccount::SubaddressAccount(Monero::SubaddressAccount *subaddressAccountImpl, QObject *parent)
: QObject(parent), m_subaddressAccountImpl(subaddressAccountImpl)
{
getAll();
}
void SubaddressAccount::getAll() const
{
emit refreshStarted();
{
QWriteLocker locker(&m_lock);
m_rows.clear();
for (auto &row: m_subaddressAccountImpl->getAll()) {
m_rows.append(row);
}
}
emit refreshFinished();
}
bool SubaddressAccount::getRow(int index, std::function<void (Monero::SubaddressAccountRow &)> callback) const
{
QReadLocker locker(&m_lock);
if (index < 0 || index >= m_rows.size())
{
return false;
}
callback(*m_rows.value(index));
return true;
}
void SubaddressAccount::addRow(const QString &label) const
{
m_subaddressAccountImpl->addRow(label.toStdString());
getAll();
}
void SubaddressAccount::setLabel(quint32 accountIndex, const QString &label) const
{
m_subaddressAccountImpl->setLabel(accountIndex, label.toStdString());
getAll();
}
void SubaddressAccount::refresh() const
{
m_subaddressAccountImpl->refresh();
getAll();
}
quint64 SubaddressAccount::count() const
{
QReadLocker locker(&m_lock);
return m_rows.size();
}