Skip to content

Commit

Permalink
WIP: Server
Browse files Browse the repository at this point in the history
  • Loading branch information
askmeaboutlo0m committed Sep 21, 2023
1 parent 582c459 commit de49087
Show file tree
Hide file tree
Showing 161 changed files with 7,393 additions and 13,014 deletions.
80 changes: 52 additions & 28 deletions src/desktop/chat/chatbox.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "desktop/chat/chatbox.h"
#include "desktop/chat/chatwidget.h"
#include "desktop/chat/chatwindow.h"
#include "desktop/chat/useritemdelegate.h"
#include "desktop/widgets/groupedtoolbutton.h"
#include "desktop/utils/widgetutils.h"
#include "libclient/document.h"
#include "desktop/widgets/groupedtoolbutton.h"
#include "libclient/canvas/canvasmodel.h"
#include "libclient/canvas/userlist.h"
#include "libclient/drawdance/message.h"
#include "libclient/document.h"
#include "libclient/net/client.h"

#include <QAction>
#include <QResizeEvent>
#include <QSplitter>
#include <QListView>
#include <QVBoxLayout>
#include <QMetaObject>
#include <QPushButton>
#include <QResizeEvent>
#include <QSplitter>
#include <QVBoxLayout>

namespace widgets {

Expand Down Expand Up @@ -48,12 +45,14 @@ ChatBox::ChatBox(Document *doc, QWidget *parent)
m_inviteButton->setText(tr("Invite"));
buttonsLayout->addWidget(m_inviteButton);

m_sessionSettingsButton = new GroupedToolButton{GroupedToolButton::GroupCenter, this};
m_sessionSettingsButton =
new GroupedToolButton{GroupedToolButton::GroupCenter, this};
m_sessionSettingsButton->setIcon(QIcon::fromTheme("configure"));
m_sessionSettingsButton->setText(tr("Session"));
buttonsLayout->addWidget(m_sessionSettingsButton);

m_chatMenuButton = new GroupedToolButton{GroupedToolButton::GroupRight, this};
m_chatMenuButton =
new GroupedToolButton{GroupedToolButton::GroupRight, this};
m_chatMenuButton->setIcon(QIcon::fromTheme("edit-comment"));
m_chatMenuButton->setText(tr("Chat"));
m_chatMenuButton->setStatusTip(tr("Show chat options"));
Expand Down Expand Up @@ -83,25 +82,42 @@ ChatBox::ChatBox(Document *doc, QWidget *parent)
setLayout(layout);

connect(m_chatWidget, &ChatWidget::message, this, &ChatBox::message);
connect(m_chatWidget, &ChatWidget::detachRequested, this, &ChatBox::detachFromParent);
connect(
m_chatWidget, &ChatWidget::detachRequested, this,
&ChatBox::detachFromParent);
connect(m_chatWidget, &ChatWidget::expandRequested, this, [this]() {
if(isCollapsed()) {
emit expandPlease();
}
});
connect(m_chatWidget, &ChatWidget::muteChanged, this, &ChatBox::muteChanged);
connect(
m_chatWidget, &ChatWidget::muteChanged, this, &ChatBox::muteChanged);

connect(doc, &Document::canvasChanged, this, &ChatBox::onCanvasChanged);
connect(doc, &Document::serverLoggedIn, this, &ChatBox::onServerLogin);
connect(doc, &Document::compatibilityModeChanged, this, &ChatBox::onCompatibilityModeChanged);

connect(doc, &Document::sessionPreserveChatChanged, m_chatWidget, &ChatWidget::setPreserveMode);
connect(doc->client(), &net::Client::serverMessage, m_chatWidget, &ChatWidget::systemMessage);
connect(doc->client(), &net::Client::youWereKicked, m_chatWidget, &ChatWidget::kicked);

connect(m_userItemDelegate, &widgets::UserItemDelegate::opCommand, doc->client(), &net::Client::sendMessage);
connect(m_userItemDelegate, &widgets::UserItemDelegate::requestPrivateChat, m_chatWidget, &ChatWidget::openPrivateChat);
connect(m_userItemDelegate, &widgets::UserItemDelegate::requestUserInfo, this, &ChatBox::requestUserInfo);
connect(
doc, &Document::compatibilityModeChanged, this,
&ChatBox::onCompatibilityModeChanged);

connect(
doc, &Document::sessionPreserveChatChanged, m_chatWidget,
&ChatWidget::setPreserveMode);
connect(
doc->client(), &net::Client::serverMessage, m_chatWidget,
&ChatWidget::systemMessage);
connect(
doc->client(), &net::Client::youWereKicked, m_chatWidget,
&ChatWidget::kicked);

connect(
m_userItemDelegate, &widgets::UserItemDelegate::opCommand,
doc->client(), &net::Client::sendMessage);
connect(
m_userItemDelegate, &widgets::UserItemDelegate::requestPrivateChat,
m_chatWidget, &ChatWidget::openPrivateChat);
connect(
m_userItemDelegate, &widgets::UserItemDelegate::requestUserInfo, this,
&ChatBox::requestUserInfo);
}

void ChatBox::setActions(QAction *inviteAction, QAction *sessionSettingsAction)
Expand All @@ -116,7 +132,7 @@ void ChatBox::setActions(QAction *inviteAction, QAction *sessionSettingsAction)
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
connect(action, &QAction::enabledChanged, button, &QWidget::setEnabled);
#else
connect(action, &QAction::changed, this, [=]{
connect(action, &QAction::changed, this, [=] {
button->setEnabled(action->isEnabled());
});
#endif
Expand All @@ -133,15 +149,23 @@ void ChatBox::onCanvasChanged(canvas::CanvasModel *canvas)
m_userList->setModel(canvas->userlist()->onlineUsers());
m_chatWidget->setUserList(canvas->userlist());

connect(canvas, &canvas::CanvasModel::chatMessageReceived, m_chatWidget, &ChatWidget::receiveMessage);
connect(canvas, &canvas::CanvasModel::pinnedMessageChanged, m_chatWidget, &ChatWidget::setPinnedMessage);
connect(canvas, &canvas::CanvasModel::userJoined, m_chatWidget, &ChatWidget::userJoined);
connect(canvas, &canvas::CanvasModel::userLeft, m_chatWidget, &ChatWidget::userParted);
connect(
canvas, &canvas::CanvasModel::chatMessageReceived, m_chatWidget,
&ChatWidget::receiveMessage);
connect(
canvas, &canvas::CanvasModel::pinnedMessageChanged, m_chatWidget,
&ChatWidget::setPinnedMessage);
connect(
canvas, &canvas::CanvasModel::userJoined, m_chatWidget,
&ChatWidget::userJoined);
connect(
canvas, &canvas::CanvasModel::userLeft, m_chatWidget,
&ChatWidget::userParted);
}

void ChatBox::onServerLogin()
{
m_chatWidget->loggedIn(static_cast<Document*>(sender())->client()->myId());
m_chatWidget->loggedIn(static_cast<Document *>(sender())->client()->myId());
}

void ChatBox::onCompatibilityModeChanged(bool compatibilityMode)
Expand All @@ -156,7 +180,7 @@ void ChatBox::focusInput()

void ChatBox::detachFromParent()
{
if(!parent() || qobject_cast<ChatWindow*>(parent()))
if(!parent() || qobject_cast<ChatWindow *>(parent()))
return;

m_state = State::Detached;
Expand Down
39 changes: 17 additions & 22 deletions src/desktop/chat/chatbox.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef CHATBOX_H
#define CHATBOX_H

#include <QWidget>

class Document;
class QListView;
class QPushButton;

namespace canvas {
class CanvasModel;
class CanvasModel;
}

namespace drawdance {
class Message;
namespace net {
class Message;
}

class QListView;
class QPushButton;

class Document;

namespace widgets {

class ChatWidget;
Expand All @@ -27,18 +24,20 @@ class UserItemDelegate;
/**
* Chat box with user list
*/
class ChatBox final : public QWidget
{
class ChatBox final : public QWidget {
Q_OBJECT
public:
explicit ChatBox(Document *doc, QWidget *parent=nullptr);
explicit ChatBox(Document *doc, QWidget *parent = nullptr);

void setActions(QAction *inviteAction, QAction *sessionSettingsAction);

//! Focus the text input widget
void focusInput();

bool isCollapsed() const { return m_state == State::Collapsed || !isVisible(); }
bool isCollapsed() const
{
return m_state == State::Collapsed || !isVisible();
}

private slots:
void onCanvasChanged(canvas::CanvasModel *canvas);
Expand All @@ -49,7 +48,7 @@ private slots:

signals:
//! User has written a new message
void message(const drawdance::Message &msg);
void message(const net::Message &msg);

//! Request information dialog about this user
void requestUserInfo(int userId);
Expand All @@ -60,7 +59,8 @@ private slots:
//! Request that the chatbox be expanded
void expandPlease();

//! Detached chat box should be re-attached and reparented (or it will be destroyed)
//! Detached chat box should be re-attached and reparented (or it will be
//! destroyed)
void reattachNowPlease();

void muteChanged(bool muted);
Expand All @@ -69,11 +69,7 @@ private slots:
void resizeEvent(QResizeEvent *event) override;

private:
enum class State {
Expanded,
Collapsed,
Detached
};
enum class State { Expanded, Collapsed, Detached };

ChatWidget *m_chatWidget;
UserItemDelegate *m_userItemDelegate;
Expand All @@ -88,4 +84,3 @@ private slots:
}

#endif

Loading

0 comments on commit de49087

Please sign in to comment.