mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
chore: change qt version
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
// DO NOT INCLUDE THIS
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QDebug>
|
||||
|
||||
//
|
||||
|
||||
@@ -15,23 +16,14 @@ inline QString software_core_name = "V2Ray";
|
||||
inline std::function<void()> MF_release_runguard;
|
||||
|
||||
// MainWindow functions
|
||||
|
||||
class QWidget;
|
||||
inline QWidget *mainwindow;
|
||||
inline std::function<void(QString)> MW_show_log;
|
||||
inline std::function<void(QString, QString)> MW_show_log_ext;
|
||||
inline std::function<void(QString)> MW_show_log_ext_vt100;
|
||||
inline std::function<void(QString, QString)> MW_dialog_message;
|
||||
|
||||
// Utils
|
||||
|
||||
#define QJSONARRAY_ADD(arr, add) \
|
||||
for (const auto &a: (add)) { \
|
||||
(arr) += a; \
|
||||
}
|
||||
#define QJSONOBJECT_COPY(src, dst, key) \
|
||||
if (src.contains(key)) dst[key] = src[key];
|
||||
#define QJSONOBJECT_COPY2(src, dst, src_key, dst_key) \
|
||||
if (src.contains(src_key)) dst[dst_key] = src[src_key];
|
||||
// String
|
||||
|
||||
#define Int2String(num) QString::number(num)
|
||||
|
||||
@@ -45,24 +37,17 @@ inline QString SubStrAfter(QString str, const QString &sub) {
|
||||
return str.right(str.length() - str.indexOf(sub) - sub.length());
|
||||
}
|
||||
|
||||
inline QString QStringList2Command(const QStringList &list) {
|
||||
QStringList new_list;
|
||||
for (auto str: list) {
|
||||
auto q = "\"" + str.replace("\"", "\\\"") + "\"";
|
||||
new_list << q;
|
||||
}
|
||||
return new_list.join(" ");
|
||||
}
|
||||
QString QStringList2Command(const QStringList &list);
|
||||
|
||||
inline QString
|
||||
DecodeB64IfValid(const QString &input, QByteArray::Base64Option options = QByteArray::Base64Option::Base64Encoding) {
|
||||
auto result = QByteArray::fromBase64Encoding(input.toUtf8(),
|
||||
options | QByteArray::Base64Option::AbortOnBase64DecodingErrors);
|
||||
if (result) {
|
||||
return result.decoded;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
QStringList SplitLines(const QString &_string);
|
||||
|
||||
// Base64
|
||||
|
||||
QString DecodeB64IfValid(const QString &input, QByteArray::Base64Options options = QByteArray::Base64Option::Base64Encoding);
|
||||
|
||||
// URL
|
||||
|
||||
class QUrlQuery;
|
||||
|
||||
#define GetQuery(url) QUrlQuery((url).query(QUrl::ComponentFormattingOption::FullyDecoded));
|
||||
|
||||
@@ -70,51 +55,34 @@ QString GetQueryValue(const QUrlQuery &q, const QString &key, const QString &def
|
||||
|
||||
QString GetRandomString(int randomStringLength);
|
||||
|
||||
// QString >> QJson
|
||||
inline QJsonObject QString2QJsonObject(const QString &jsonString) {
|
||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||
QJsonObject jsonObject = jsonDocument.object();
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
// QJson >> QString
|
||||
inline QString QJsonObject2QString(const QJsonObject &jsonObject, bool compact) {
|
||||
return QString(QJsonDocument(jsonObject).toJson(compact ? QJsonDocument::Compact : QJsonDocument::Indented));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline QJsonArray QList2QJsonArray(const QList<T> &list) {
|
||||
QVariantList list2;
|
||||
for (auto &item: list)
|
||||
list2.append(item);
|
||||
return QJsonArray::fromVariantList(list2);
|
||||
}
|
||||
|
||||
inline QList<int> QJsonArray2QListInt(const QJsonArray &arr) {
|
||||
QList<int> list2;
|
||||
for (auto item: arr)
|
||||
list2.append(item.toInt());
|
||||
return list2;
|
||||
}
|
||||
|
||||
inline QList<QString> QJsonArray2QListString(const QJsonArray &arr) {
|
||||
QList<QString> list2;
|
||||
for (auto item: arr)
|
||||
list2.append(item.toString());
|
||||
return list2;
|
||||
}
|
||||
|
||||
inline QString UrlSafe_encode(const QString &s) {
|
||||
return s.toUtf8().toPercentEncoding().replace(" ", "%20");
|
||||
}
|
||||
|
||||
inline bool InRange(unsigned x, unsigned low, unsigned high) {
|
||||
return (low <= x && x <= high);
|
||||
}
|
||||
// JSON
|
||||
|
||||
inline QStringList SplitLines(const QString &_string) {
|
||||
return _string.split(QRegularExpression("[\r\n]"), Qt::SplitBehaviorFlags::SkipEmptyParts);
|
||||
}
|
||||
class QJsonObject;
|
||||
class QJsonArray;
|
||||
|
||||
QJsonObject QString2QJsonObject(const QString &jsonString);
|
||||
|
||||
QString QJsonObject2QString(const QJsonObject &jsonObject, bool compact);
|
||||
|
||||
template<typename T>
|
||||
QJsonArray QList2QJsonArray(const QList<T> &list);
|
||||
|
||||
QList<int> QJsonArray2QListInt(const QJsonArray &arr);
|
||||
|
||||
#define QJSONARRAY_ADD(arr, add) \
|
||||
for (const auto &a: (add)) { \
|
||||
(arr) += a; \
|
||||
}
|
||||
#define QJSONOBJECT_COPY(src, dst, key) \
|
||||
if (src.contains(key)) dst[key] = src[key];
|
||||
#define QJSONOBJECT_COPY2(src, dst, src_key, dst_key) \
|
||||
if (src.contains(src_key)) dst[dst_key] = src[src_key];
|
||||
|
||||
QList<QString> QJsonArray2QListString(const QJsonArray &arr);
|
||||
|
||||
// Files
|
||||
|
||||
@@ -122,10 +90,6 @@ QByteArray ReadFile(const QString &path);
|
||||
|
||||
QString ReadFileText(const QString &path);
|
||||
|
||||
// Net
|
||||
|
||||
int MkPort();
|
||||
|
||||
// Validators
|
||||
|
||||
bool IsIpAddress(const QString &str);
|
||||
@@ -150,13 +114,11 @@ inline QString DisplayAddress(QString serverAddress, int serverPort) {
|
||||
return WrapIPV6Host(serverAddress) + ":" + Int2String(serverPort);
|
||||
};
|
||||
|
||||
// Format
|
||||
// Format & Misc
|
||||
|
||||
inline QString DisplayTime(long long time, QLocale::FormatType formatType = QLocale::LongFormat) {
|
||||
QDateTime t;
|
||||
t.setSecsSinceEpoch(time);
|
||||
return QLocale().toString(t, formatType);
|
||||
}
|
||||
int MkPort();
|
||||
|
||||
QString DisplayTime(long long time, int formatType = 0);
|
||||
|
||||
inline QString ReadableSize(const qint64 &size) {
|
||||
double sizeAsDouble = size;
|
||||
@@ -180,6 +142,10 @@ inline QString ReadableSize(const qint64 &size) {
|
||||
return QString::fromLatin1("%1 %2").arg(sizeAsDouble, 0, 'f', 2).arg(measure);
|
||||
}
|
||||
|
||||
inline bool InRange(unsigned x, unsigned low, unsigned high) {
|
||||
return (low <= x && x <= high);
|
||||
}
|
||||
|
||||
// UI
|
||||
|
||||
QWidget *GetMessageBoxParent();
|
||||
|
||||
Reference in New Issue
Block a user