-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
97 lines (89 loc) · 2.04 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Better Chat plugin for TeamSpeak 3
* GPLv3 license
*
* Copyright (C) 2019 Luch (https://github.com/Luch00)
*/
#pragma once
#include <utils.h>
#include <QDirIterator>
#include <QApplication>
#include <QTime>
namespace utils
{
// find mainwindow of ts
QMainWindow* findMainWindow()
{
foreach(QWidget *widget, qApp->topLevelWidgets())
{
if (QMainWindow* m = qobject_cast<QMainWindow*>(widget))
{
return m;
}
}
return nullptr;
}
// find widget by object name
QWidget* findWidget(const QString& name, QWidget* parent)
{
QList<QWidget*> children = parent->findChildren<QWidget*>();
for (int i = 0; i < children.count(); ++i)
{
if (children[i]->objectName() == name)
{
return children[i];
}
}
return nullptr;
}
// get current time as string
QString time()
{
return QTime::currentTime().toString("hh:mm:ss");
}
// make a list of all local emotesets so javascript can load them
void makeEmoteJsonArray(const QString& path)
{
QString json;
QDir emotePath(path + "LxBTSC/template/Emotes", "*.json", QDir::NoSort, QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);
QDirIterator it(emotePath, QDirIterator::Subdirectories);
if (it.hasNext())
{
json = "[\"";
QStringList files;
while (it.hasNext())
{
it.next();
QFileInfo fileInfo(it.fileInfo());
files.append(emotePath.relativeFilePath(fileInfo.filePath()));
}
json.append(files.join("\",\""));
json.append("\"]");
}
else
{
json = "[]";
}
QFile file(path + "LxBTSC/template/emotesets.json");
if (file.open(QIODevice::WriteOnly))
{
QTextStream stream(&file);
stream << json << endl;
}
}
// string used for avatar filenames
QString ts3WeirdBase16(const QString& uid)
{
static const QString hexArray = "0123456789abcdef";
static const QString replaceArray = "abcdefghijklmnop";
QByteArray hex = QByteArray::fromBase64(uid.toLatin1()).toHex();
QString str(hex);
QString ret;
for (QChar c : str)
{
int i = hexArray.indexOf(c);
ret.append(replaceArray[i]);
}
return ret;
}
}