Skip to content

Commit

Permalink
format code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidelxyz committed Apr 10, 2023
1 parent f22f91e commit 2a0878d
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 99 deletions.
5 changes: 3 additions & 2 deletions src/danmuku.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ Danmuku::Danmuku(QWidget *parent)

layout_modules = new QVBoxLayout(ui->centralWidget); // deleted by QT

loadModule(new LiveRoom(this)); // deleted in unloadModule
loadModule(new DanmuDisplay(this)); // deleted in unloadModule
// TODO: Dynamic modules loader
loadModule(new LiveRoom(this)); // deleted by Qt
loadModule(new DanmuDisplay(this)); // deleted by Qt

// Qss
QFile qss(":/stylesheet/danmuku.qss");
Expand Down
6 changes: 3 additions & 3 deletions src/danmuku.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#ifndef DANMUKU_DANMUKU_H_
#define DANMUKU_DANMUKU_H_

#include <QMainWindow>
#include <QVBoxLayout>
Expand Down Expand Up @@ -29,4 +29,4 @@ class Danmuku : public QMainWindow {
std::unordered_map<QString, Module*> modules;
};

#endif
#endif // DANMUKU_DANMUKU_H_
6 changes: 3 additions & 3 deletions src/global.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef GLOBAL_H
#define GLOBAL_H
#ifndef DANMUKU_GLOBAL_H_
#define DANMUKU_GLOBAL_H_

#include <QCoreApplication>

#define APP_DIR_PATH QCoreApplication::applicationDirPath()
#define CONFIG_DIR_PATH "/config"

#endif
#endif // DANMUKU_GLOBAL_H_
2 changes: 1 addition & 1 deletion src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Module::Module(const QString &name, const QList<QString> &dependencies,
moduleMetadata.name = name;
moduleMetadata.dependencies = dependencies;

widget = new QWidget(parent); // deleted by QT
widget = new QWidget(parent); // deleted by Qt
// TODO check dependencies
}

Expand Down
6 changes: 3 additions & 3 deletions src/module.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MODULE_H
#define MODULE_H
#ifndef DANMUKU_MODULE_H_
#define DANMUKU_MODULE_H_

#include <QObject>
#include <QPointer>
Expand Down Expand Up @@ -33,4 +33,4 @@ class Module : public QObject {

#define MODULE

#endif
#endif // DANMUKU_MODULE_H_
6 changes: 3 additions & 3 deletions src/modules/danmu_display/danmu_config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DANMU_CONFIG_H
#define DANMU_CONFIG_H
#ifndef DANMUKU_MODULES_DANMU_DISPLAY_DANMU_CONFIG_H_
#define DANMUKU_MODULES_DANMU_DISPLAY_DANMU_CONFIG_H_

#include <QColor>
#include <QFont>
Expand Down Expand Up @@ -69,4 +69,4 @@ class DanmuConfig : public QObject {
QSettings settings;
};

#endif
#endif // DANMUKU_MODULES_DANMU_DISPLAY_DANMU_CONFIG_H_
12 changes: 7 additions & 5 deletions src/modules/danmu_display/danmu_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

#include "ui_danmu_window.h"

DanmuDisplay::DanmuDisplay(Danmuku *parent) : Module("danmu_display", {}, parent) {
DanmuDisplay::DanmuDisplay(Danmuku *parent)
: Module("danmu_display", {}, parent) {
config = nullptr;
updateFollowersCountTimer = nullptr;

Expand Down Expand Up @@ -58,9 +59,10 @@ void DanmuDisplay::startDisplay() {
Q_ASSERT(window == nullptr);
window = new DanmuWindow(); // deleted in stop()
Q_ASSERT(danmuLoader == nullptr);
danmuLoader = new DanmuLoader(window->ui->list_danmu); // deleted in stop()
danmuLoader =
new DanmuLoader(window->ui->list_danmu, this); // deleted in stop()
Q_ASSERT(config == nullptr);
config = new DanmuConfig(); // deleted in stop()
config = new DanmuConfig(this); // deleted in stop()

connect(config, SIGNAL(changed()), this, SLOT(applyConfig()));

Expand Down Expand Up @@ -254,8 +256,8 @@ void DanmuDisplay::applyConfig() {
// giftLoader
if (config->showGift) { // showGift == true
if (giftLoader.isNull()) {
giftLoader =
new DanmuLoader(window->ui->list_gift); // deleted in stop()
giftLoader = new DanmuLoader(window->ui->list_gift,
this); // deleted in stop()
giftLoader->start();
window->ui->list_gift->show();
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/danmu_display/danmu_display.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DANMU_DISPLAY_H
#define DANMU_DISPLAY_H
#ifndef DANMUKU_MODULES_DANMU_DISPLAY_DANMU_DISPLAY_H_
#define DANMUKU_MODULES_DANMU_DISPLAY_DANMU_DISPLAY_H_

#include <QHBoxLayout>
#include <QListWidget>
Expand Down Expand Up @@ -63,4 +63,4 @@ class DanmuDisplay : public Module {
QString giftContentFormat;
};

#endif
#endif // DANMUKU_MODULES_DANMU_DISPLAY_DANMU_DISPLAY_H_
2 changes: 1 addition & 1 deletion src/modules/danmu_display/danmu_loader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "danmu_loader.h"

DanmuLoader::DanmuLoader(QListWidget *list) {
DanmuLoader::DanmuLoader(QListWidget *list, QObject *parent) : QThread(parent) {
this->list = list;
list->installEventFilter(this);
scrollBar = list->verticalScrollBar();
Expand Down
8 changes: 4 additions & 4 deletions src/modules/danmu_display/danmu_loader.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DANMU_LOADER_H
#define DANMU_LOADER_H
#ifndef DANMUKU_MODULES_DANMU_DISPLAY_DANMU_LOADER_H_
#define DANMUKU_MODULES_DANMU_DISPLAY_DANMU_LOADER_H_

#include <QEvent>
#include <QListWidget>
Expand All @@ -13,7 +13,7 @@ class DanmuLoader : public QThread {
Q_OBJECT

public:
DanmuLoader(QListWidget *list);
DanmuLoader(QListWidget *list, QObject *parent = nullptr);
~DanmuLoader();
void loadItem(QListWidgetItem *item);

Expand Down Expand Up @@ -41,4 +41,4 @@ class DanmuLoader : public QThread {
QWaitCondition updateCondition;
};

#endif
#endif // DANMUKU_MODULES_DANMU_DISPLAY_DANMU_LOADER_H_
6 changes: 3 additions & 3 deletions src/modules/danmu_display/danmu_panel.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DANMU_PANEL_H
#define DANMU_PANEL_H
#ifndef DANMUKU_MODULES_DANMU_DISPLAY_DANMU_PANEL_H_
#define DANMUKU_MODULES_DANMU_DISPLAY_DANMU_PANEL_H_

#include <QWidget>

Expand Down Expand Up @@ -54,4 +54,4 @@ class DanmuPanel : public QWidget {
bool showGift;
};

#endif
#endif // DANMUKU_MODULES_DANMU_DISPLAY_DANMU_LOADER_H_
6 changes: 3 additions & 3 deletions src/modules/danmu_display/danmu_window.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DANMU_WINDOW_H
#define DANMU_WINDOW_H
#ifndef DANMUKU_MODULES_DANMU_DISPLAY_DANMU_WINDOW_H_
#define DANMUKU_MODULES_DANMU_DISPLAY_DANMU_WINDOW_H_

#include <QWidget>

Expand Down Expand Up @@ -30,4 +30,4 @@ class DanmuWindow : public QWidget {
QPoint mouseDragPosition;
};

#endif
#endif // DANMUKU_MODULES_DANMU_DISPLAY_DANMU_WINDOW_H_
10 changes: 4 additions & 6 deletions src/modules/live_room/live_room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ LiveRoom::LiveRoom(Danmuku *parent) : Module("live_room", {}, parent) {
protocal = nullptr;

// Control UI
QHBoxLayout *layout = new QHBoxLayout(widget); // deleted by QT
QHBoxLayout *layout = new QHBoxLayout(widget); // deleted by Qt

input_roomID = new QLineEdit(widget); // deleted by QT
input_roomID = new QLineEdit(widget); // deleted by Qt
input_roomID->setPlaceholderText(tr("直播间号"));
#ifdef QT_DEBUG
input_roomID->setText("14003442"); // debug
#endif
layout->addWidget(input_roomID);

btn_start = new QPushButton(tr("连接"), widget); // deleted by QT
btn_start = new QPushButton(tr("连接"), widget); // deleted by Qt
connect(btn_start, SIGNAL(clicked()), this, SLOT(start()));
layout->addWidget(btn_start);
}
Expand Down Expand Up @@ -48,6 +48,7 @@ void LiveRoom::start() {

Q_ASSERT(protocal == nullptr);
protocal = new Protocal(); // deleted in stop()
// protocal cannot be assigned a parent if it is passed into moveToThread()
protocal->moveToThread(&protocalThread);
protocalThread.start();

Expand All @@ -71,9 +72,6 @@ void LiveRoom::stop() {
(Qt::ConnectionType)Qt::BlockingQueuedConnection);
protocalThread.quit();
protocalThread.wait();
// protocal->deleteLater();
delete protocal;
protocal = nullptr;
qDebug("Exit stop");
}

Expand Down
6 changes: 3 additions & 3 deletions src/modules/live_room/live_room.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef LIVE_ROOM_H
#define LIVE_ROOM_H
#ifndef DANMUKU_MODULES_LIVE_ROOM_LIVE_ROOM_H_
#define DANMUKU_MODULES_LIVE_ROOM_LIVE_ROOM_H_

#include <QHBoxLayout>
#include <QLineEdit>
Expand Down Expand Up @@ -43,4 +43,4 @@ class LiveRoom : public Module {
QThread protocalThread;
};

#endif
#endif // DANMUKU_MODULES_LIVE_ROOM_LIVE_ROOM_H_
17 changes: 10 additions & 7 deletions src/modules/live_room/protocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ const QHash<QString, enum Protocal::CMD> Protocal::cmdMap =

QByteArray genHead(int datalength, int opeation, int sequence) {
QByteArray buffer = QByteArray();
buffer.append(int32ToBytes(
(uint32_t)(datalength + Protocal::WS_PACKAGE_HEADER_TOTAL_LENGTH)));
buffer.append(
int32ToBytes((uint32_t)(datalength + WS_PACKAGE_HEADER_TOTAL_LENGTH)));
buffer.append(int16ToBytes((uint16_t)(WS_PACKAGE_HEADER_TOTAL_LENGTH)));
buffer.append(int16ToBytes((uint16_t)(WS_HEADER_DEFAULT_VERSION)));
int16ToBytes((uint16_t)(Protocal::WS_PACKAGE_HEADER_TOTAL_LENGTH)));
buffer.append(
int16ToBytes((uint16_t)(Protocal::WS_HEADER_DEFAULT_VERSION)));
buffer.append(int32ToBytes((uint32_t)(opeation)));
buffer.append(int32ToBytes((uint32_t)(sequence)));
return buffer;
}

bool checkHello(QByteArray data) {
QByteArray valData("{\"code\":0}");
valData.prepend(genHead(valData.length(), WS_OP_CONNECT_SUCCESS,
WS_HEADER_DEFAULT_SEQUENCE));
valData.prepend(genHead(valData.length(), Protocal::WS_OP_CONNECT_SUCCESS,
Protocal::WS_HEADER_DEFAULT_SEQUENCE));
return valData == data;
}

Expand Down Expand Up @@ -66,7 +68,8 @@ void Protocal::startConnection(const int& roomID,
request.setRawHeader("Accept-Language",
"zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6");

ws = new QWebSocket(); // deleted in stopConnection()
ws = new QWebSocket(QString(), QWebSocketProtocol::VersionLatest,
this); // deleted in stopConnection()
ws->open(request);

QEventLoop eventLoop;
Expand All @@ -84,7 +87,7 @@ void Protocal::startConnection(const int& roomID,
heartBeatTimer->start(WS_HEARTBEAT_INTERVAL_MS);
}

Protocal::Protocal() {
Protocal::Protocal(QObject* parent) : QObject(parent) {
ws = nullptr;
heartBeatTimer = nullptr;
}
Expand Down
Loading

0 comments on commit 2a0878d

Please sign in to comment.