2020-10-07 10:36:04 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-12-26 19:56:06 +00:00
|
|
|
// Copyright (c) 2020-2021, The Monero Project.
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2021-03-30 09:52:29 +00:00
|
|
|
#ifndef WOWLET_UTILS_H
|
|
|
|
#define WOWLET_UTILS_H
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
#include <QRegExp>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QApplication>
|
2021-01-29 14:51:59 +00:00
|
|
|
#include <QTextCharFormat>
|
2021-04-19 22:02:37 +00:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
#include <QtAndroid>
|
|
|
|
#endif
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2022-05-20 15:40:22 +00:00
|
|
|
#include <wownero_seed/wownero_seed.hpp>
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
#include "networktype.h"
|
2021-01-29 14:51:59 +00:00
|
|
|
#include "libwalletqt/Wallet.h"
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
struct logMessage
|
|
|
|
{
|
|
|
|
logMessage(const QtMsgType &type, const QString &message, const QString &fn){
|
|
|
|
logMessage::type = type;
|
|
|
|
logMessage::message = message;
|
|
|
|
logMessage::fn = fn;
|
|
|
|
}
|
|
|
|
QtMsgType type;
|
|
|
|
QString message;
|
|
|
|
QString fn;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xdgDesktopEntryPaths {
|
|
|
|
QString pathApp;
|
|
|
|
QString pathIcon;
|
|
|
|
QString PathMime;
|
|
|
|
};
|
|
|
|
|
|
|
|
const xdgDesktopEntryPaths xdgPaths = {
|
2021-03-30 19:16:32 +00:00
|
|
|
QString("%1/org.wowlet.wowlet.desktop").arg(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation)),
|
|
|
|
QString("%1/usr/share/icons/hicolor/64x64/apps/wowlet.png").arg(QDir::homePath()),
|
2020-10-07 10:36:04 +00:00
|
|
|
QString("/")
|
|
|
|
};
|
|
|
|
|
|
|
|
class Utils
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
static bool portOpen(const QString &hostname, quint16 port);
|
|
|
|
static bool fileExists(const QString &path);
|
|
|
|
static QByteArray fileOpen(const QString &path);
|
|
|
|
static QByteArray fileOpenQRC(const QString &path);
|
2021-04-13 09:39:12 +00:00
|
|
|
static qint64 fileModifiedAge(const QString &path);
|
2020-10-07 10:36:04 +00:00
|
|
|
static void desktopNotify(const QString &title, const QString &message, int duration);
|
|
|
|
static bool fileWrite(const QString &path, const QString &data);
|
|
|
|
static QStringList fileFind(const QRegExp &pattern, const QString &baseDir, int level, int depth, int maxPerDir);
|
|
|
|
static bool validateJSON(const QByteArray &blob);
|
|
|
|
static bool readJsonFile(QIODevice &device, QSettings::SettingsMap &map);
|
|
|
|
static bool writeJsonFile(QIODevice &device, const QSettings::SettingsMap &map);
|
|
|
|
static void applicationLogHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
2020-12-14 02:20:05 +00:00
|
|
|
static void externalLinkWarning(QWidget *parent, const QString &url);
|
2020-10-07 10:36:04 +00:00
|
|
|
static bool dirExists(const QString &path);
|
|
|
|
static QString barrayToString(const QByteArray &data);
|
|
|
|
static QStandardItem *qStandardItem(const QString &text);
|
|
|
|
static QStandardItem *qStandardItem(const QString &text, QFont &font);
|
|
|
|
static void copyToClipboard(const QString &string);
|
2020-10-16 03:05:05 +00:00
|
|
|
static QString copyFromClipboard();
|
2022-03-22 15:31:03 +00:00
|
|
|
static QString blockExplorerLink(const QString &txid);
|
2020-10-07 10:36:04 +00:00
|
|
|
static QString getUnixAccountName();
|
|
|
|
static QString xdgDesktopEntry();
|
|
|
|
static bool xdgDesktopEntryWrite(const QString &path);
|
|
|
|
static void xdgRefreshApplications();
|
|
|
|
static bool xdgDesktopEntryRegister();
|
2022-05-01 23:19:12 +00:00
|
|
|
static unsigned int countAlphaNum(const QByteArray &line);
|
2020-10-07 10:36:04 +00:00
|
|
|
static bool pixmapWrite(const QString &path, const QPixmap &pixmap);
|
|
|
|
static QFont relativeFont(int delta);
|
|
|
|
static double roundSignificant(double N, double n);
|
2020-11-23 16:57:38 +00:00
|
|
|
static QString formatBytes(quint64 bytes);
|
2020-12-16 18:41:19 +00:00
|
|
|
static QLocale getCurrencyLocale(const QString ¤cyCode);
|
2022-04-25 19:35:16 +00:00
|
|
|
static QString amountToCurrencyString(double amount, const QString ¤cyCode, int precision = 2);
|
2020-12-16 16:31:25 +00:00
|
|
|
static int maxLength(const QVector<QString> &array);
|
2021-04-08 01:40:44 +00:00
|
|
|
static double roundUp(double value, int decimal_places);
|
2020-12-16 18:41:19 +00:00
|
|
|
static QMap<QString, QLocale> localeCache;
|
2020-12-31 02:14:48 +00:00
|
|
|
static QString balanceFormat(quint64 balance);
|
2021-01-29 14:51:59 +00:00
|
|
|
static QTextCharFormat addressTextFormat(const SubaddressIndex &index);
|
2021-05-13 23:44:42 +00:00
|
|
|
static bool versionOutdated(const QString ¤t_version, const QString &newest_version);
|
2020-11-23 16:57:38 +00:00
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
template<typename QEnum>
|
2021-04-19 22:02:37 +00:00
|
|
|
static QString QtEnumToString (const QEnum value) {
|
2020-10-07 10:36:04 +00:00
|
|
|
return QString::fromStdString(std::string(QMetaEnum::fromType<QEnum>().valueToKey(value)));
|
|
|
|
}
|
2021-04-19 22:02:37 +00:00
|
|
|
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
static bool androidAskPermissions(const QVector<QString> &permissions);
|
|
|
|
#endif
|
2020-10-07 10:36:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AppContext; // forward declaration
|
|
|
|
|
2021-03-30 09:52:29 +00:00
|
|
|
#endif //WOWLET_UTILS_H
|