Remove some unused utilities functions

This commit is contained in:
Jonas Kvinge
2020-12-29 23:13:22 +01:00
parent c213d5b8d9
commit bfaabafbfa
2 changed files with 5 additions and 104 deletions

View File

@@ -42,20 +42,13 @@
#include <QFile>
#include <QFileInfo>
#include <QProcess>
#include <QHostAddress>
#include <QSet>
#include <QList>
#include <QMap>
#include <QVariant>
#include <QString>
#include <QStringList>
#include <QUrl>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include <QTcpServer>
#include <QTemporaryFile>
#include <QPoint>
#include <QRect>
#include <QSize>
#include <QColor>
#include <QMetaEnum>
@@ -249,24 +242,6 @@ quint64 FileSystemFreeSpace(const QString &path) {
}
QString MakeTempDir(const QString template_name) {
QString path;
{
QTemporaryFile tempfile;
if (!template_name.isEmpty()) tempfile.setFileTemplate(template_name);
tempfile.open();
path = tempfile.fileName();
}
QDir d;
d.mkdir(path);
return path;
}
bool MoveToTrashRecursive(const QString &path) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
@@ -536,25 +511,6 @@ QByteArray HmacSha1(const QByteArray &key, const QByteArray &data) {
return Hmac(key, data, Sha1_Algo);
}
// File must not be open and will be closed afterwards!
QByteArray Sha1File(QFile &file) {
file.open(QIODevice::ReadOnly);
QCryptographicHash hash(QCryptographicHash::Sha1);
QByteArray data;
while (!file.atEnd()) {
data = file.read(1000000); // 1 mib
hash.addData(data.data(), data.length());
data.clear();
}
file.close();
return hash.result();
}
QByteArray Sha1CoverHash(const QString &artist, const QString &album) {
QCryptographicHash hash(QCryptographicHash::Sha1);
@@ -569,23 +525,6 @@ QString PrettySize(const QSize &size) {
return QString::number(size.width()) + "x" + QString::number(size.height());
}
quint16 PickUnusedPort() {
forever {
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
const quint64 port = QRandomGenerator::global()->bounded(49152, 65535);
#else
const quint16 port = 49152 + qrand() % 16384;
#endif
QTcpServer server;
if (server.listen(QHostAddress::Any, port)) {
return port;
}
}
}
void ConsumeCurrentElement(QXmlStreamReader *reader) {
int level = 1;
@@ -743,35 +682,6 @@ int GetThreadId() {
}
bool IsLaptop() {
#ifdef Q_OS_WIN
SYSTEM_POWER_STATUS status;
if (!GetSystemPowerStatus(&status)) {
return false;
}
return !(status.BatteryFlag & 128); // 128 = no system battery
#elif defined(Q_OS_LINUX)
return !QDir("/proc/acpi/battery").entryList(QDir::Dirs | QDir::NoDotAndDotDot).isEmpty();
#elif defined(Q_OS_MACOS)
ScopedCFTypeRef<CFTypeRef> power_sources(IOPSCopyPowerSourcesInfo());
ScopedCFTypeRef<CFArrayRef> power_source_list(IOPSCopyPowerSourcesList(power_sources.get()));
for (CFIndex i = 0; i < CFArrayGetCount(power_source_list.get()); ++i) {
CFTypeRef ps = CFArrayGetValueAtIndex(power_source_list.get(), i);
CFDictionaryRef description = IOPSGetPowerSourceDescription(power_sources.get(), ps);
if (CFDictionaryContainsKey(description, CFSTR(kIOPSBatteryHealthKey))) {
return true;
}
}
return false;
#else
return false;
#endif
}
QString PathWithoutFilenameExtension(const QString &filename) {
if (filename.section('/', -1, -1).contains('.')) return filename.section('.', 0, -2);
return filename;

View File

@@ -62,8 +62,6 @@ QString ColorToRgba(const QColor &color);
quint64 FileSystemCapacity(const QString &path);
quint64 FileSystemFreeSpace(const QString &path);
QString MakeTempDir(const QString template_name = QString());
bool MoveToTrashRecursive(const QString &path);
bool RemoveRecursive(const QString &path);
bool CopyRecursive(const QString &source, const QString &destination);
@@ -71,21 +69,17 @@ bool Copy(QIODevice *source, QIODevice *destination);
void OpenInFileBrowser(const QList<QUrl> &urls);
enum HashFunction {
Md5_Algo,
Sha256_Algo,
Sha1_Algo,
};
enum HashFunction {
Md5_Algo,
Sha256_Algo,
Sha1_Algo,
};
QByteArray Hmac(const QByteArray &key, const QByteArray &data, const HashFunction method);
QByteArray HmacMd5(const QByteArray &key, const QByteArray &data);
QByteArray HmacSha256(const QByteArray &key, const QByteArray &data);
QByteArray HmacSha1(const QByteArray &key, const QByteArray &data);
QByteArray Sha1File(QFile &file);
QByteArray Sha1CoverHash(const QString &artist, const QString &album);
// Picks an unused ephemeral port number. Doesn't hold the port open so there's the obvious race condition
quint16 PickUnusedPort();
// Reads all children of the current element,
// and returns with the stream reader either on the EndElement for the current element, or the end of the file - whichever came first.
void ConsumeCurrentElement(QXmlStreamReader *reader);
@@ -133,9 +127,6 @@ static const int IOPRIO_CLASS_SHIFT = 13;
int SetThreadIOPriority(IoPriority priority);
int GetThreadId();
// Returns true if this machine has a battery.
bool IsLaptop();
QString GetRandomStringWithChars(const int len);
QString GetRandomStringWithCharsAndNumbers(const int len);
QString CryptographicRandomString(const int len);