mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
IRClient: Add a member list to channel views.
This commit is contained in:
parent
08c15be0ca
commit
491aa112ab
7 changed files with 115 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include "IRCChannel.h"
|
#include "IRCChannel.h"
|
||||||
#include "IRCClient.h"
|
#include "IRCClient.h"
|
||||||
|
#include "IRCChannelMemberListModel.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
@ -8,6 +9,7 @@ IRCChannel::IRCChannel(IRCClient& client, const String& name)
|
||||||
, m_name(name)
|
, m_name(name)
|
||||||
, m_log(IRCLogBuffer::create())
|
, m_log(IRCLogBuffer::create())
|
||||||
{
|
{
|
||||||
|
m_member_model = new IRCChannelMemberListModel(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
IRCChannel::~IRCChannel()
|
IRCChannel::~IRCChannel()
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "IRCLogBuffer.h"
|
#include "IRCLogBuffer.h"
|
||||||
|
|
||||||
class IRCClient;
|
class IRCClient;
|
||||||
|
class IRCChannelMemberListModel;
|
||||||
|
|
||||||
class IRCChannel : public Retainable<IRCChannel> {
|
class IRCChannel : public Retainable<IRCChannel> {
|
||||||
public:
|
public:
|
||||||
|
@ -31,6 +32,12 @@ public:
|
||||||
const IRCLogBuffer& log() const { return *m_log; }
|
const IRCLogBuffer& log() const { return *m_log; }
|
||||||
IRCLogBuffer& log() { return *m_log; }
|
IRCLogBuffer& log() { return *m_log; }
|
||||||
|
|
||||||
|
IRCChannelMemberListModel* member_model() { return m_member_model; }
|
||||||
|
const IRCChannelMemberListModel* member_model() const { return m_member_model; }
|
||||||
|
|
||||||
|
int member_count() const { return m_members.size(); }
|
||||||
|
String member_at(int i) { return m_members[i].name; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IRCChannel(IRCClient&, const String&);
|
IRCChannel(IRCClient&, const String&);
|
||||||
|
|
||||||
|
@ -44,4 +51,5 @@ private:
|
||||||
bool m_open { false };
|
bool m_open { false };
|
||||||
|
|
||||||
Retained<IRCLogBuffer> m_log;
|
Retained<IRCLogBuffer> m_log;
|
||||||
|
IRCChannelMemberListModel* m_member_model { nullptr };
|
||||||
};
|
};
|
||||||
|
|
59
Applications/IRCClient/IRCChannelMemberListModel.cpp
Normal file
59
Applications/IRCClient/IRCChannelMemberListModel.cpp
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#include "IRCChannelMemberListModel.h"
|
||||||
|
#include "IRCChannel.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
IRCChannelMemberListModel::IRCChannelMemberListModel(IRCChannel& channel)
|
||||||
|
: m_channel(channel)
|
||||||
|
{
|
||||||
|
set_activates_on_selection(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
IRCChannelMemberListModel::~IRCChannelMemberListModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int IRCChannelMemberListModel::row_count() const
|
||||||
|
{
|
||||||
|
return m_channel.member_count();
|
||||||
|
}
|
||||||
|
|
||||||
|
int IRCChannelMemberListModel::column_count() const
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
String IRCChannelMemberListModel::column_name(int column) const
|
||||||
|
{
|
||||||
|
switch (column) {
|
||||||
|
case Column::Name: return "Name";
|
||||||
|
}
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
GTableModel::ColumnMetadata IRCChannelMemberListModel::column_metadata(int column) const
|
||||||
|
{
|
||||||
|
switch (column) {
|
||||||
|
case Column::Name: return { 70, TextAlignment::CenterLeft };
|
||||||
|
}
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
GVariant IRCChannelMemberListModel::data(const GModelIndex& index, Role) const
|
||||||
|
{
|
||||||
|
switch (index.column()) {
|
||||||
|
case Column::Name: return m_channel.member_at(index.row());
|
||||||
|
}
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRCChannelMemberListModel::update()
|
||||||
|
{
|
||||||
|
did_update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRCChannelMemberListModel::activate(const GModelIndex& index)
|
||||||
|
{
|
||||||
|
if (on_activation)
|
||||||
|
on_activation(m_channel.member_at(index.row()));
|
||||||
|
}
|
26
Applications/IRCClient/IRCChannelMemberListModel.h
Normal file
26
Applications/IRCClient/IRCChannelMemberListModel.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibGUI/GTableModel.h>
|
||||||
|
#include <AK/Function.h>
|
||||||
|
|
||||||
|
class IRCChannel;
|
||||||
|
|
||||||
|
class IRCChannelMemberListModel final : public GTableModel {
|
||||||
|
public:
|
||||||
|
enum Column { Name };
|
||||||
|
explicit IRCChannelMemberListModel(IRCChannel&);
|
||||||
|
virtual ~IRCChannelMemberListModel() override;
|
||||||
|
|
||||||
|
virtual int row_count() const override;
|
||||||
|
virtual int column_count() const override;
|
||||||
|
virtual String column_name(int column) const override;
|
||||||
|
virtual ColumnMetadata column_metadata(int column) const override;
|
||||||
|
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
|
||||||
|
virtual void update() override;
|
||||||
|
virtual void activate(const GModelIndex&) override;
|
||||||
|
|
||||||
|
Function<void(const String&)> on_activation;
|
||||||
|
|
||||||
|
private:
|
||||||
|
IRCChannel& m_channel;
|
||||||
|
};
|
|
@ -51,6 +51,9 @@ public:
|
||||||
void handle_user_input_in_query(const String& query_name, const String&);
|
void handle_user_input_in_query(const String& query_name, const String&);
|
||||||
void handle_user_input_in_server(const String&);
|
void handle_user_input_in_server(const String&);
|
||||||
|
|
||||||
|
IRCQuery& ensure_query(const String& name);
|
||||||
|
IRCChannel& ensure_channel(const String& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Message {
|
struct Message {
|
||||||
String prefix;
|
String prefix;
|
||||||
|
@ -70,8 +73,6 @@ private:
|
||||||
void handle_namreply(const Message&);
|
void handle_namreply(const Message&);
|
||||||
void handle_privmsg(const Message&);
|
void handle_privmsg(const Message&);
|
||||||
void handle(const Message&, const String& verbatim);
|
void handle(const Message&, const String& verbatim);
|
||||||
IRCQuery& ensure_query(const String& name);
|
|
||||||
IRCChannel& ensure_channel(const String& name);
|
|
||||||
|
|
||||||
String m_hostname;
|
String m_hostname;
|
||||||
int m_port { 0 };
|
int m_port { 0 };
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "IRCClientWindow.h"
|
#include "IRCClientWindow.h"
|
||||||
#include "IRCClient.h"
|
#include "IRCClient.h"
|
||||||
|
#include "IRCChannel.h"
|
||||||
|
#include "IRCChannelMemberListModel.h"
|
||||||
#include "IRCLogBufferModel.h"
|
#include "IRCLogBufferModel.h"
|
||||||
#include <LibGUI/GBoxLayout.h>
|
#include <LibGUI/GBoxLayout.h>
|
||||||
#include <LibGUI/GTableView.h>
|
#include <LibGUI/GTableView.h>
|
||||||
|
@ -13,10 +15,23 @@ IRCClientWindow::IRCClientWindow(IRCClient& client, Type type, const String& nam
|
||||||
, m_name(name)
|
, m_name(name)
|
||||||
{
|
{
|
||||||
set_layout(make<GBoxLayout>(Orientation::Vertical));
|
set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||||
m_table_view = new GTableView(this);
|
|
||||||
|
// Make a container for the log buffer view + optional member list.
|
||||||
|
GWidget* container = new GWidget(this);
|
||||||
|
container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||||
|
|
||||||
|
m_table_view = new GTableView(container);
|
||||||
m_table_view->set_headers_visible(false);
|
m_table_view->set_headers_visible(false);
|
||||||
m_table_view->set_font(Font::default_fixed_width_font());
|
m_table_view->set_font(Font::default_fixed_width_font());
|
||||||
|
|
||||||
|
if (m_type == Channel) {
|
||||||
|
auto* member_view = new GTableView(container);
|
||||||
|
member_view->set_headers_visible(false);
|
||||||
|
member_view->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||||
|
member_view->set_preferred_size({ 100, 0 });
|
||||||
|
member_view->set_model(OwnPtr<IRCChannelMemberListModel>(m_client.ensure_channel(m_name).member_model()));
|
||||||
|
}
|
||||||
|
|
||||||
m_text_editor = new GTextEditor(GTextEditor::SingleLine, this);
|
m_text_editor = new GTextEditor(GTextEditor::SingleLine, this);
|
||||||
m_text_editor->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
m_text_editor->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||||
m_text_editor->set_preferred_size({ 0, 18 });
|
m_text_editor->set_preferred_size({ 0, 18 });
|
||||||
|
|
|
@ -7,6 +7,7 @@ OBJS = \
|
||||||
IRCAppWindow.o \
|
IRCAppWindow.o \
|
||||||
IRCClientWindow.o \
|
IRCClientWindow.o \
|
||||||
IRCClientWindowListModel.o \
|
IRCClientWindowListModel.o \
|
||||||
|
IRCChannelMemberListModel.o \
|
||||||
main.o
|
main.o
|
||||||
|
|
||||||
APP = IRCClient
|
APP = IRCClient
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue