141 lines
5.2 KiB
C++
141 lines
5.2 KiB
C++
/* Главное окно desktop-чата: связывает списки, bridge-события, UtunNode, media и звонки.
|
|
* Координирует запуск/остановку ядра, tray и отдельные окна; UI-обработчики работают в GUI-потоке. */
|
|
#pragma once
|
|
|
|
#include <QMainWindow>
|
|
#include <QSystemTrayIcon>
|
|
#include <QMenu>
|
|
#include <QQueue>
|
|
#include <QSet>
|
|
#include <QHash>
|
|
#include <QTimer>
|
|
#include <QPointer>
|
|
#include <memory>
|
|
|
|
class ChannelList;
|
|
class MessageList;
|
|
class AccountList;
|
|
class DbManager;
|
|
class QSplitter;
|
|
class UtunNode;
|
|
class AudioRecorder;
|
|
class ConnMonitorWindow;
|
|
class VideoPlayerWindow;
|
|
class StreamPlayerWindow;
|
|
class ImageViewerWindow;
|
|
class CallWindow;
|
|
class CallAudioEngine;
|
|
class MemberFileBrowser;
|
|
class MessageNotification;
|
|
|
|
struct AutoPlayItem {
|
|
QString channelId;
|
|
qint64 msgId = 0;
|
|
bool downloadStarted = false;
|
|
float durationSec = 0.0f;
|
|
};
|
|
|
|
class MainWindow : public QMainWindow {
|
|
Q_OBJECT
|
|
public:
|
|
explicit MainWindow(QWidget *parent, DbManager* db, const QString& cfgPath,
|
|
const QString& dbPath = QString(),
|
|
const QString& debugFile = QString(),
|
|
const QString& debugLevel = QString(),
|
|
const QString& debugCategories = QString());
|
|
~MainWindow() override;
|
|
|
|
protected:
|
|
void closeEvent(QCloseEvent *event) override;
|
|
|
|
private slots:
|
|
void onTrayActivated(QSystemTrayIcon::ActivationReason reason);
|
|
void showShareInviteDialog(const QString& channelId);
|
|
void showInviteByLinkDialog(const QString& channelId);
|
|
void showJoinDialog();
|
|
void onCreateGroupRequested();
|
|
void showSettings();
|
|
void showConnMonitor();
|
|
void openVideo(const QString& filePath);
|
|
void openImage(const QString& filePath);
|
|
void showChannelSettings(const QString& channelId);
|
|
void autoPlayTimerTick();
|
|
|
|
public:
|
|
void onMessageReceived(const char* ch_id, int ch_id_len, uint64_t author, bool initialSync);
|
|
void onMemberList(const QString& chId, int count, const uint8_t* data, int dataLen);
|
|
void onMemberUpdated(const QString& chId, const uint8_t* data);
|
|
void onMemberRemoved(const QString& chId, uint64_t nodeId);
|
|
void onAutoConnectStatus(uint8_t status, uint16_t total, uint16_t totalNodes, uint16_t connected);
|
|
void onChannelPeersOnline(const char* ch_id, int ch_id_len, uint16_t online);
|
|
void reloadChannels();
|
|
void onAttachmentDownloadedForAutoPlay(const QString& chId, int64_t msgId);
|
|
void requestShutdown();
|
|
UtunNode* utunNode() const { return m_node; }
|
|
|
|
/* звонки */
|
|
void onCallRequested(const QString& chId, quint64 nodeId, const QString& name);
|
|
void onCallIncoming(const QString& chId, quint64 caller, quint64 callId);
|
|
void onCallRinging(quint64 callId);
|
|
void onCallAccepted(quint64 callId);
|
|
void onCallEnded(quint64 callId, uint8_t reason);
|
|
void onCallError(quint64 callId, uint8_t err);
|
|
void onCallPath(quint64 callId, const QString& path);
|
|
void closeCallWindow(quint64 callId);
|
|
|
|
/* DM (p2p чат) */
|
|
void onPmRequested(const QString& chId, quint64 nodeId, const QString& name);
|
|
void onInviteToPmRequested(const QString& source, quint64 peer, const QString& name);
|
|
void onMessageLinkActivated(const QString& link);
|
|
void onDmConvUpdated(const QString& convId);
|
|
void onDmMsgReceived(const QString& convId, quint64 author);
|
|
|
|
private:
|
|
void setupUi();
|
|
void saveWindowGeometry();
|
|
void restoreWindowGeometry();
|
|
void setupTray();
|
|
void showIncomingMessageNotification(const QString& target, quint64 author);
|
|
void setupNode();
|
|
void setupMessaging();
|
|
void setupSoundFromConfig();
|
|
void setupBridgeCallbacks();
|
|
void setupConnects();
|
|
void onShutdownCheck();
|
|
void autoPlayCheckNewMessage(const QString& channelId);
|
|
QString autoPlayMediaDir() const;
|
|
void showMemberFiles(const QString& channel, quint64 owner = 0);
|
|
|
|
ChannelList *m_channelList;
|
|
MessageList *m_messageList;
|
|
AccountList *m_accountList;
|
|
QSplitter *m_splitter = nullptr;
|
|
QSystemTrayIcon *m_trayIcon;
|
|
QMenu *m_trayMenu;
|
|
std::unique_ptr<MessageNotification> m_messageNotification;
|
|
DbManager *m_db;
|
|
UtunNode *m_node = nullptr;
|
|
QString m_cfgPath;
|
|
QString m_cfgDbPath;
|
|
QString m_cfgDebugFile;
|
|
QString m_cfgDebugLevel;
|
|
QString m_cfgDebugCategories;
|
|
QString m_pendingChannelSelect;
|
|
QString m_currentChannelId;
|
|
AudioRecorder *m_recorder = nullptr;
|
|
ConnMonitorWindow *m_connMonitor = nullptr;
|
|
VideoPlayerWindow *m_videoPlayer = nullptr;
|
|
QPointer<StreamPlayerWindow> m_streamPlayer;
|
|
ImageViewerWindow *m_imageViewer = nullptr;
|
|
QPointer<MemberFileBrowser> m_fileBrowser;
|
|
|
|
QQueue<AutoPlayItem> m_autoPlayQueue;
|
|
QTimer* m_autoPlayTimer = nullptr;
|
|
QTimer* m_cpuLoadTimer = nullptr;
|
|
bool m_cpuLoadPending = false;
|
|
QTimer* m_shutdownTimer = nullptr;
|
|
QSet<int64_t> m_autoPlayDownloading; /* msgIds with download in progress */
|
|
|
|
QHash<quint64, CallWindow*> m_activeCalls; /* call_id → окно звонка */
|
|
};
|