Files
pay/FloweePay.h
T

117 lines
3.3 KiB
C++
Raw Permalink Normal View History

2020-05-24 13:20:03 +02:00
/*
* 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
2020-06-12 20:53:01 +02:00
Q_PROPERTY(QString unitName READ unitName NOTIFY unitChanged)
2020-06-11 17:56:06 +02:00
Q_PROPERTY(int windowWidth READ windowWidth WRITE setWindowWidth NOTIFY windowWidthChanged)
Q_PROPERTY(int windowHeight READ windowHeight WRITE setWindowHeight NOTIFY windowHeightChanged)
2020-06-12 20:53:01 +02:00
Q_PROPERTY(int unitAllowedDecimals READ unitAllowedDecimals NOTIFY unitChanged)
2020-05-24 13:20:03 +02:00
Q_ENUMS(UnitsOfBitcoin StringType)
public:
enum StringType {
Unknown = 0,
PrivateKey,
CashPKH,
CashSH,
LegacyPKH,
LegacySH
};
enum UnitOfBitcoin {
BCH,
MilliBCH,
MicroBCH,
2020-06-12 20:53:01 +02:00
Bits,
Satoshis
2020-05-24 13:20:03 +02:00
};
FloweePay();
~FloweePay();
static FloweePay *instance();
QList<Wallet *> wallets() const;
DownloadManager* p2pNet();
2020-06-08 14:24:27 +02:00
/// return the app data location
2020-05-24 13:20:03 +02:00
QString basedir() const;
2020-06-08 14:24:27 +02:00
/// for a price, in satoshis, return a formatted string in unitName().
2020-06-12 20:53:01 +02:00
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;
2020-05-24 13:20:03 +02:00
2020-06-08 14:24:27 +02:00
/// create a new wallet with an optional name.
2020-05-24 13:20:03 +02:00
Q_INVOKABLE void createNewWallet(const QString &walletName = QString());
2020-06-08 14:24:27 +02:00
/// swipe a paper wallet with an optional name
2020-05-24 13:20:03 +02:00
Q_INVOKABLE void createImportedWallet(const QString &privateKey, const QString &walletName);
2020-06-08 14:24:27 +02:00
/// take a bitcoin-address and identify the type.
Q_INVOKABLE StringType identifyString(const QString &string) const;
2020-05-24 13:20:03 +02:00
/// returns the unit of our prices. BCH, for instance.
QString unitName() const;
2020-06-12 20:53:01 +02:00
/// returns the amount of digits allowed behind the decimal-separator.
int unitAllowedDecimals() const;
2020-05-24 13:20:03 +02:00
2020-06-11 17:56:06 +02:00
int windowWidth() const;
void setWindowWidth(int windowWidth);
int windowHeight() const;
void setWindowHeight(int windowHeight);
2020-05-24 13:20:03 +02:00
signals:
void loadComplete();
2020-06-08 14:24:27 +02:00
/// \internal
2020-05-24 13:20:03 +02:00
void loadComplete_priv();
2020-06-12 20:53:01 +02:00
void unitChanged();
2020-05-24 13:20:03 +02:00
void walletsChanged();
2020-06-11 17:56:06 +02:00
void windowWidthChanged();
void windowHeightChanged();
2020-05-24 13:20:03 +02:00
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