Utils: remove unused functions

This commit is contained in:
tobtoht 2021-01-29 16:41:31 +01:00
parent 9ead5c29cd
commit aa6533b37d
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
2 changed files with 0 additions and 128 deletions

View file

@ -21,12 +21,6 @@
QVector<logMessage> applicationLog = QVector<logMessage>(); // todo: replace with ring buffer QVector<logMessage> applicationLog = QVector<logMessage>(); // todo: replace with ring buffer
QMutex logMutex; QMutex logMutex;
void Utils::openWindow(QWidget *w) {
auto first_screen = QApplication::screens()[0];
w->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, w->size(), first_screen->availableGeometry()));
w->show();
}
bool Utils::fileExists(const QString &path) { bool Utils::fileExists(const QString &path) {
QFileInfo check_file(path); QFileInfo check_file(path);
return check_file.exists() && check_file.isFile(); return check_file.exists() && check_file.isFile();
@ -69,16 +63,6 @@ bool Utils::fileWrite(const QString &path, const QString &data) {
return false; return false;
} }
QString Utils::systemAccountName(){
QString accountName = qgetenv("USER"); // mac/linux
if (accountName.isEmpty())
return qgetenv("USERNAME"); // Windows
if (accountName.isEmpty())
qDebug() << "accountName was empty";
return "";
}
bool Utils::validateJSON(const QByteArray &blob) { bool Utils::validateJSON(const QByteArray &blob) {
QJsonDocument doc = QJsonDocument::fromJson(blob); QJsonDocument doc = QJsonDocument::fromJson(blob);
QString jsonString = doc.toJson(QJsonDocument::Indented); QString jsonString = doc.toJson(QJsonDocument::Indented);
@ -96,18 +80,6 @@ bool Utils::writeJsonFile(QIODevice &device, const QSettings::SettingsMap &map)
return true; return true;
} }
QStringList Utils::readJsonStringToQStringList(const QString &input) {
QStringList data;
QJsonDocument doc = QJsonDocument::fromJson(input.toUtf8());
QJsonObject object = doc.object();
QJsonArray array = doc.array();
for(auto &&entry: array)
data << entry.toString();
return data;
}
void Utils::applicationLogHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { void Utils::applicationLogHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
const QString fn = context.function ? QString::fromUtf8(context.function) : ""; const QString fn = context.function ? QString::fromUtf8(context.function) : "";
const QString date = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); const QString date = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
@ -147,19 +119,6 @@ void Utils::applicationLogHandler(QtMsgType type, const QMessageLogContext &cont
//emit applicationLogUpdated(message); //emit applicationLogUpdated(message);
} }
QByteArray Utils::zipExtract(const QString &path, const QString& destination) {
Q_UNUSED(path)
Q_UNUSED(destination)
return QByteArray();
}
bool Utils::isDigit(const QString& inp) {
for (auto &&i : inp) {
if(!i.isDigit()) return false;
}
return true;
}
void Utils::desktopNotify(const QString &title, const QString &message, int duration) { void Utils::desktopNotify(const QString &title, const QString &message, int duration) {
QStringList notify_send = QStringList() << title << message << "-t" << QString::number(duration); QStringList notify_send = QStringList() << title << message << "-t" << QString::number(duration);
QStringList kdialog = QStringList() << title << message; QStringList kdialog = QStringList() << title << message;
@ -193,20 +152,6 @@ QString Utils::barrayToString(const QByteArray &data) {
return QString(QTextCodec::codecForMib(106)->toUnicode(data)); return QString(QTextCodec::codecForMib(106)->toUnicode(data));
} }
QByteArray Utils::readSocket(QTcpSocket &socket, int buffer_size) {
QByteArray data;
if(!socket.waitForReadyRead(6000))
return data;
while(buffer_size > 0 && socket.bytesAvailable() > 0){
QByteArray _data = socket.read(buffer_size);
buffer_size -= _data.size();
data += _data;
}
return data;
}
void Utils::externalLinkWarning(QWidget *parent, const QString &url){ void Utils::externalLinkWarning(QWidget *parent, const QString &url){
if(!config()->get(Config::warnOnExternalLink).toBool()) { if(!config()->get(Config::warnOnExternalLink).toBool()) {
QDesktopServices::openUrl(QUrl(url)); QDesktopServices::openUrl(QUrl(url));
@ -262,12 +207,6 @@ QStringList Utils::fileFind(const QRegExp &pattern, const QString &baseDir, int
return rtn; return rtn;
} }
bool Utils::walletExists(QString name, const QString &path) {
name = name.replace(".keys", "");
auto walletPath = QDir(path).filePath(name + ".keys");
return Utils::fileExists(walletPath);
}
void Utils::copyToClipboard(const QString &string){ void Utils::copyToClipboard(const QString &string){
QClipboard * clipboard = QApplication::clipboard(); QClipboard * clipboard = QApplication::clipboard();
if (!clipboard) { if (!clipboard) {
@ -321,45 +260,6 @@ QString Utils::blockExplorerLink(const QString &blockExplorer, NetworkType::Type
return QString(""); return QString("");
} }
QList<processStruct> Utils::procList() {
// windows maybe: https://stackoverflow.com/a/13635377/2054778
QList<processStruct> rtn;
QProcess process;
#if defined(Q_OS_MAC) || defined(Q_OS_LINUX)
#if defined(Q_OS_MAC)
process.start("ps", QStringList() << "-wwaxo" << "pid,command");
#elif defined(Q_OS_LINUX)
process.start("ps", QStringList() << "-wwaxo" << "pid,command");
#endif
process.waitForFinished(-1);
QString stdout = process.readAllStandardOutput();
QString stderr = process.readAllStandardError();
if(stdout.isEmpty())
return rtn;
QStringList spl = stdout.split("\n");
if(spl.count() >= 1)
spl.removeAt(0);
for (auto& line: spl) {
line = line.trimmed();
if(line.isEmpty())
continue;
QStringList _spl = line.split(" ");
processStruct ps;
if(_spl.length() >= 2) {
ps.pid = _spl.at(0).toInt();
ps.command = _spl.at(1);
rtn.append(ps);
}
}
#endif
return rtn;
}
QStandardItem *Utils::qStandardItem(const QString& text) { QStandardItem *Utils::qStandardItem(const QString& text) {
auto font = QApplication::font(); auto font = QApplication::font();
return Utils::qStandardItem(text, font); return Utils::qStandardItem(text, font);

View file

@ -4,15 +4,10 @@
#ifndef FEATHER_UTILS_H #ifndef FEATHER_UTILS_H
#define FEATHER_UTILS_H #define FEATHER_UTILS_H
#include <cstdio>
#include <cstdlib>
#include <QRegExp> #include <QRegExp>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QtNetwork>
#include <QApplication> #include <QApplication>
#include <QMainWindow>
#include <QTextCharFormat> #include <QTextCharFormat>
#include <sstream>
#include <monero_seed/monero_seed.hpp> #include <monero_seed/monero_seed.hpp>
@ -31,18 +26,6 @@ struct logMessage
QString fn; QString fn;
}; };
struct networkPeer {
QString host;
quint16 port;
bool active = false;
};
struct processStruct {
int pid = 0;
QString command;
QFileInfo fileInfo;
};
struct xdgDesktopEntryPaths { struct xdgDesktopEntryPaths {
QString pathApp; QString pathApp;
QString pathIcon; QString pathIcon;
@ -60,28 +43,19 @@ class Utils
public: public:
static bool portOpen(const QString &hostname, quint16 port); static bool portOpen(const QString &hostname, quint16 port);
static bool isDigit(const QString &inp);
static bool fileExists(const QString &path); static bool fileExists(const QString &path);
static QByteArray fileOpen(const QString &path); static QByteArray fileOpen(const QString &path);
static QByteArray fileOpenQRC(const QString &path); static QByteArray fileOpenQRC(const QString &path);
static void desktopNotify(const QString &title, const QString &message, int duration); static void desktopNotify(const QString &title, const QString &message, int duration);
static bool fileWrite(const QString &path, const QString &data); 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 QStringList fileFind(const QRegExp &pattern, const QString &baseDir, int level, int depth, int maxPerDir);
static QString systemAccountName();
static QByteArray zipExtract(const QString &path, const QString& destination);
static bool validateJSON(const QByteArray &blob); static bool validateJSON(const QByteArray &blob);
static bool readJsonFile(QIODevice &device, QSettings::SettingsMap &map); static bool readJsonFile(QIODevice &device, QSettings::SettingsMap &map);
static bool walletExists(QString name, const QString &path);
static bool writeJsonFile(QIODevice &device, const QSettings::SettingsMap &map); static bool writeJsonFile(QIODevice &device, const QSettings::SettingsMap &map);
static QStringList readJsonStringToQStringList(const QString &input);
static void applicationLogHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg); static void applicationLogHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
static void openWindow(QWidget *w);
static void externalLinkWarning(QWidget *parent, const QString &url); static void externalLinkWarning(QWidget *parent, const QString &url);
static QList<processStruct> procList();
static bool dirExists(const QString &path); static bool dirExists(const QString &path);
static QString barrayToString(const QByteArray &data); static QString barrayToString(const QByteArray &data);
static QByteArray readSocket(QTcpSocket &socket, int buffer_size);
static QStandardItem *qStandardItem(const QString &text); static QStandardItem *qStandardItem(const QString &text);
static QStandardItem *qStandardItem(const QString &text, QFont &font); static QStandardItem *qStandardItem(const QString &text, QFont &font);
static void copyToClipboard(const QString &string); static void copyToClipboard(const QString &string);
@ -112,6 +86,4 @@ public:
class AppContext; // forward declaration class AppContext; // forward declaration
#endif //FEATHER_UTILS_H #endif //FEATHER_UTILS_H