/* * This file is part of the Flowee project * Copyright (C) 2025-2026 Tom Zander * * 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 . */ #include "BackupAccountInfo.h" #include "BackupSyncModuleInfo.h" #include "WalletData.h" #include 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); }); connect(m_walletData, &WalletData::storeWaitingForSync, this, [=]() { setWalletUploadScheduled(true); }); 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. if (m_walletData && !m_walletUploadScheduled) QTimer::singleShot(300, m_walletData, [=]() { m_walletData->restore(WalletData::BeforeSave); }); } bool BackupAccountInfo::walletUploadScheduled() const { return m_walletUploadScheduled; } void BackupAccountInfo::setWalletUploadScheduled(bool newWalletUploadScheduled) { if (m_walletUploadScheduled == newWalletUploadScheduled) return; m_walletUploadScheduled = newWalletUploadScheduled; emit walletUploadScheduledChanged(); }