Files
pay/FloweePay.h
T
2020-06-13 11:04:34 +02:00

117 lines
3.3 KiB
C++

/*
* This file is part of the Flowee project
* Copyright (C) 2020 Tom Zander <tomz@freedommail.ch>
*
* 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/>.
*/
#ifndef FLOWEEPAY_H
#define FLOWEEPAY_H
#include <QObject>
#include <DownloadManager.h>
#include <WorkerThreads.h>
#include <QList>
#include <QString>
class Wallet;
class FloweePay : public QObject, WorkerThreads
{
Q_OBJECT
Q_PROPERTY(QString unitName READ unitName NOTIFY unitChanged)
Q_PROPERTY(int windowWidth READ windowWidth WRITE setWindowWidth NOTIFY windowWidthChanged)
Q_PROPERTY(int windowHeight READ windowHeight WRITE setWindowHeight NOTIFY windowHeightChanged)
Q_PROPERTY(int unitAllowedDecimals READ unitAllowedDecimals NOTIFY unitChanged)
Q_ENUMS(UnitsOfBitcoin StringType)
public:
enum StringType {
Unknown = 0,
PrivateKey,
CashPKH,
CashSH,
LegacyPKH,
LegacySH
};
enum UnitOfBitcoin {
BCH,
MilliBCH,
MicroBCH,
Bits,
Satoshis
};
FloweePay();
~FloweePay();
static FloweePay *instance();
QList<Wallet *> wallets() const;
DownloadManager* p2pNet();
/// return the app data location
QString basedir() const;
/// for a price, in satoshis, return a formatted string in unitName().
Q_INVOKABLE inline QString priceToString(double price) const {
return priceToString(static_cast<qint64>(price));
}
/// for a price, in satoshis, return a formatted string in unitName().
QString priceToString(qint64 price) const;
/// create a new wallet with an optional name.
Q_INVOKABLE void createNewWallet(const QString &walletName = QString());
/// swipe a paper wallet with an optional name
Q_INVOKABLE void createImportedWallet(const QString &privateKey, const QString &walletName);
/// take a bitcoin-address and identify the type.
Q_INVOKABLE StringType identifyString(const QString &string) const;
/// returns the unit of our prices. BCH, for instance.
QString unitName() const;
/// returns the amount of digits allowed behind the decimal-separator.
int unitAllowedDecimals() const;
int windowWidth() const;
void setWindowWidth(int windowWidth);
int windowHeight() const;
void setWindowHeight(int windowHeight);
signals:
void loadComplete();
/// \internal
void loadComplete_priv();
void unitChanged();
void walletsChanged();
void windowWidthChanged();
void windowHeightChanged();
private:
void init();
void saveData();
void saveAll();
Wallet *createWallet(const QString &name);
UnitOfBitcoin m_unit = BCH;
QString m_basedir;
std::unique_ptr<DownloadManager> m_downloadManager;
QList<Wallet*> m_wallets;
};
#endif