mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-19 20:32:15 +02:00
7cd5ede1e0
Currently, the chat input elements (lineEdit, sendButton, and chatLayout) are initialized when the QCefWidget gets set. This is problematic behavior that only happened to work because we're a bit lucky: The chat is only enabled after a widget is set, and it's only set once. Without those conditions, the chat dock would crash when enabling the chat before a widget is set, and the elements would get recreated if the widget is set a second time, resulting in the original elements not getting freed and leaking. Moving the element creation to the constructor fixes both of these problems, as now they're created immediately and only once. Detected by PVS-Studio.
67 lines
1.5 KiB
C++
67 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <random>
|
|
#include <string>
|
|
|
|
#include "auth-oauth.hpp"
|
|
|
|
#ifdef BROWSER_AVAILABLE
|
|
#include "window-dock-browser.hpp"
|
|
#include "lineedit-autoresize.hpp"
|
|
#include <QHBoxLayout>
|
|
class YoutubeChatDock : public BrowserDock {
|
|
Q_OBJECT
|
|
|
|
private:
|
|
std::string apiChatId;
|
|
LineEditAutoResize *lineEdit;
|
|
QPushButton *sendButton;
|
|
QHBoxLayout *chatLayout;
|
|
|
|
public:
|
|
YoutubeChatDock(const QString &title);
|
|
void SetWidget(QCefWidget *widget_);
|
|
void SetApiChatId(const std::string &id);
|
|
|
|
private slots:
|
|
void SendChatMessage();
|
|
void ShowErrorMessage(const QString &error);
|
|
void EnableChatInput();
|
|
};
|
|
#endif
|
|
|
|
inline const std::vector<Auth::Def> youtubeServices = {
|
|
{"YouTube - RTMP", Auth::Type::OAuth_LinkedAccount, true, true},
|
|
{"YouTube - RTMPS", Auth::Type::OAuth_LinkedAccount, true, true},
|
|
{"YouTube - HLS", Auth::Type::OAuth_LinkedAccount, true, true}};
|
|
|
|
class YoutubeAuth : public OAuthStreamKey {
|
|
Q_OBJECT
|
|
|
|
bool uiLoaded = false;
|
|
std::string section;
|
|
|
|
#ifdef BROWSER_AVAILABLE
|
|
YoutubeChatDock *chat = nullptr;
|
|
#endif
|
|
|
|
virtual bool RetryLogin() override;
|
|
virtual void SaveInternal() override;
|
|
virtual bool LoadInternal() override;
|
|
virtual void LoadUI() override;
|
|
|
|
QString GenerateState();
|
|
|
|
public:
|
|
YoutubeAuth(const Def &d);
|
|
~YoutubeAuth();
|
|
|
|
void SetChatId(const QString &chat_id, const std::string &api_chat_id);
|
|
void ResetChat();
|
|
|
|
static std::shared_ptr<Auth> Login(QWidget *parent,
|
|
const std::string &service);
|
|
};
|