Files

100 lines
3.2 KiB
C++
Raw Permalink Normal View History

2025-11-12 13:54:22 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2025-2026 Tom Zander <tom@flowee.org>
2025-11-12 13:54:22 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "BackupAccountInfo.h"
#include "BackupSyncModuleInfo.h"
#include "WalletData.h"
#include <FloweePay.h>
BackupAccountInfo::BackupAccountInfo(QObject *parent)
: QObject{parent}
{}
AccountInfo *BackupAccountInfo::account() const
{
return m_account;
}
void BackupAccountInfo::setAccount(AccountInfo *newAccount)
{
if (m_account == newAccount)
return;
m_account = newAccount;
if (m_walletData)
disconnect(m_walletData, SIGNAL(lastSavedChanged()), this, SIGNAL(lastSavedChanged()));
m_walletData = nullptr;
if (m_account) {
const auto wallets = BackupSyncModuleInfo::instance()->walletData();
for (auto *wallet : wallets) {
if (wallet->wallet() == m_account->wallet()) {
m_walletData = wallet;
m_walletData->deriveAuthKey();
connect(m_walletData, SIGNAL(lastSavedChanged()), this, SIGNAL(lastSavedChanged()));
connect(m_walletData, &WalletData::startUpload, [=]() {
setWalletUploadScheduled(false);
});
2026-01-19 00:01:11 +01:00
connect(m_walletData, &WalletData::storeWaitingForSync, this, [=]() {
setWalletUploadScheduled(true);
});
2025-11-12 13:54:22 +01:00
break;
}
}
}
emit lastSavedChanged();
emit accountChanged();
}
QString BackupAccountInfo::lastSaved() const
{
if (!m_walletData)
return QString();
if (m_walletData->lastSavedTime() == 0)
return QString();
QDateTime time = QDateTime::fromSecsSinceEpoch(m_walletData->lastSavedTime());
return FloweePay::instance()->formatDateTime(time);
}
QString BackupAccountInfo::address() const
{
if (!m_walletData)
return QString();
return m_walletData->fancyAddess();
}
void BackupAccountInfo::startBackup()
{
// we'll be naughty and call restore first, to download the current
// state (and apply it, should it be needed) before we upload the new state.
2026-01-19 00:01:11 +01:00
if (m_walletData && !m_walletUploadScheduled)
2025-11-12 13:54:22 +01:00
QTimer::singleShot(300, m_walletData, [=]() { m_walletData->restore(WalletData::BeforeSave); });
}
2026-01-19 00:01:11 +01:00
bool BackupAccountInfo::walletUploadScheduled() const
{
return m_walletUploadScheduled;
}
void BackupAccountInfo::setWalletUploadScheduled(bool newWalletUploadScheduled)
{
if (m_walletUploadScheduled == newWalletUploadScheduled)
return;
m_walletUploadScheduled = newWalletUploadScheduled;
emit walletUploadScheduledChanged();
}