2021-07-06 19:36:27 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2023-01-02 19:30:11 +00:00
|
|
|
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
|
2021-07-06 19:36:27 +00:00
|
|
|
|
|
|
|
#ifndef FEATHER_UTILS_H
|
|
|
|
#define FEATHER_UTILS_H
|
|
|
|
|
2022-03-04 10:05:20 +00:00
|
|
|
#include <QRegularExpression>
|
2021-07-06 19:36:27 +00:00
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QTextCharFormat>
|
2023-09-12 14:15:40 +00:00
|
|
|
#include <QMessageBox>
|
2021-07-06 19:36:27 +00:00
|
|
|
|
|
|
|
#include "libwalletqt/Wallet.h"
|
|
|
|
#include "networktype.h"
|
|
|
|
|
|
|
|
namespace Utils
|
|
|
|
{
|
2023-09-12 14:15:40 +00:00
|
|
|
enum MessageType
|
|
|
|
{
|
|
|
|
INFO = 0,
|
|
|
|
WARNING,
|
|
|
|
ERROR
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Message
|
|
|
|
{
|
|
|
|
QWidget *parent;
|
|
|
|
MessageType type;
|
|
|
|
QString title;
|
|
|
|
QString description;
|
|
|
|
QStringList helpItems;
|
|
|
|
QString doc;
|
|
|
|
QString highlight;
|
|
|
|
QString link;
|
|
|
|
|
|
|
|
QString toString() const {
|
|
|
|
return QString("%1: %2").arg(title, description);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-06 19:36:27 +00:00
|
|
|
bool fileExists(const QString &path);
|
|
|
|
QByteArray fileOpen(const QString &path);
|
|
|
|
QByteArray fileOpenQRC(const QString &path);
|
2023-09-12 14:15:40 +00:00
|
|
|
QString loadQrc(const QString &qrc);
|
2021-07-06 19:36:27 +00:00
|
|
|
bool fileWrite(const QString &path, const QString &data);
|
|
|
|
bool pixmapWrite(const QString &path, const QPixmap &pixmap);
|
2022-03-04 10:05:20 +00:00
|
|
|
QStringList fileFind(const QRegularExpression &pattern, const QString &baseDir, int level, int depth, int maxPerDir);
|
2021-07-06 19:36:27 +00:00
|
|
|
|
2023-12-02 18:28:31 +00:00
|
|
|
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &filename, const QString &filter);
|
|
|
|
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &filter);
|
|
|
|
|
2022-06-22 19:06:32 +00:00
|
|
|
QString portablePath();
|
|
|
|
bool isPortableMode();
|
2022-05-22 17:52:03 +00:00
|
|
|
bool portableFileExists(const QString &dir);
|
2022-06-22 19:06:32 +00:00
|
|
|
QString ringDatabasePath();
|
|
|
|
|
|
|
|
bool dirExists(const QString &path);
|
2021-07-06 19:36:27 +00:00
|
|
|
QString defaultWalletDir();
|
2021-10-28 16:55:47 +00:00
|
|
|
QString applicationPath();
|
2023-11-28 00:34:35 +00:00
|
|
|
QString applicationFilePath();
|
2021-07-06 19:36:27 +00:00
|
|
|
|
|
|
|
bool validateJSON(const QByteArray &blob);
|
|
|
|
bool readJsonFile(QIODevice &device, QSettings::SettingsMap &map);
|
|
|
|
bool writeJsonFile(QIODevice &device, const QSettings::SettingsMap &map);
|
|
|
|
|
|
|
|
void copyToClipboard(const QString &string);
|
|
|
|
QString copyFromClipboard();
|
2023-03-28 20:42:12 +00:00
|
|
|
void copyColumn(QModelIndex * index, int column);
|
2021-07-06 19:36:27 +00:00
|
|
|
|
|
|
|
QString xdgDesktopEntry();
|
|
|
|
bool xdgDesktopEntryWrite(const QString &path);
|
|
|
|
void xdgRefreshApplications();
|
|
|
|
bool xdgDesktopEntryRegister();
|
|
|
|
|
|
|
|
bool portOpen(const QString &hostname, quint16 port);
|
|
|
|
quint16 getDefaultRpcPort(NetworkType::Type type);
|
|
|
|
bool isTorsocks();
|
|
|
|
|
|
|
|
double roundSignificant(double N, double n);
|
|
|
|
int maxLength(const QVector<QString> &array);
|
|
|
|
QString formatBytes(quint64 bytes);
|
|
|
|
|
|
|
|
QLocale getCurrencyLocale(const QString ¤cyCode);
|
|
|
|
QString amountToCurrencyString(double amount, const QString ¤cyCode);
|
|
|
|
|
|
|
|
QStandardItem *qStandardItem(const QString &text);
|
|
|
|
QStandardItem *qStandardItem(const QString &text, QFont &font);
|
|
|
|
|
|
|
|
QString blockExplorerLink(const QString &blockExplorer, NetworkType::Type nettype, const QString &txid);
|
|
|
|
void externalLinkWarning(QWidget *parent, const QString &url);
|
|
|
|
|
2023-03-28 20:42:12 +00:00
|
|
|
QString displayAddress(const QString& address, int sections = 3, const QString & sep = " ");
|
2021-07-06 19:36:27 +00:00
|
|
|
QTextCharFormat addressTextFormat(const SubaddressIndex &index, quint64 amount);
|
2023-03-28 20:42:12 +00:00
|
|
|
|
|
|
|
QFont getMonospaceFont();
|
|
|
|
QFont relativeFont(int delta);
|
|
|
|
|
2021-07-06 19:36:27 +00:00
|
|
|
void applicationLogHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
|
|
|
QString barrayToString(const QByteArray &data);
|
|
|
|
|
2023-02-11 17:11:21 +00:00
|
|
|
bool isLocalUrl(const QUrl &url);
|
|
|
|
|
2021-07-06 19:36:27 +00:00
|
|
|
template<typename QEnum>
|
|
|
|
QString QtEnumToString (QEnum value) {
|
|
|
|
return QString::fromStdString(std::string(QMetaEnum::fromType<QEnum>().valueToKey(value)));
|
|
|
|
}
|
2023-09-12 14:15:40 +00:00
|
|
|
|
|
|
|
void showError(QWidget *parent, const QString &title, const QString &description = "", const QStringList &helpItems = {}, const QString &doc = "", const QString &highlight = "", const QString &link = "");
|
|
|
|
void showInfo(QWidget *parent, const QString &title, const QString &description = "", const QStringList &helpItems = {}, const QString &doc = "", const QString &highlight = "", const QString &link = "");
|
|
|
|
void showWarning(QWidget *parent, const QString &title, const QString &description = "", const QStringList &helpItems = {}, const QString &doc = "", const QString &highlight = "", const QString &link = "");
|
|
|
|
void showMsg(QWidget *parent, QMessageBox::Icon icon, const QString &windowTitle, const QString &title, const QString &description, const QStringList &helpItems = {}, const QString &doc = "", const QString &highlight = "", const QString &link = "");
|
|
|
|
void showMsg(const Message &message);
|
|
|
|
|
2023-12-02 18:28:31 +00:00
|
|
|
void openDir(QWidget *parent, const QString &message, const QString& dir);
|
|
|
|
|
2023-09-12 14:15:40 +00:00
|
|
|
QWindow* windowForQObject(QObject* object);
|
2023-11-30 14:01:39 +00:00
|
|
|
void clearLayout(QLayout *layout, bool deleteWidgets = true);
|
2023-12-30 13:17:11 +00:00
|
|
|
|
|
|
|
QString formatSyncStatus(quint64 height, quint64 target, bool daemonSync = false);
|
2021-07-06 19:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif //FEATHER_UTILS_H
|