summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Robinson <joe@grabyo.com>2017-04-19 14:32:48 +0100
committerJoe Robinson <joe@grabyo.com>2017-04-19 14:32:48 +0100
commit37d883535366f03e3ee4044a59569942864af0a5 (patch)
treefa7cf527d2defb6291e45f932abc5ba55c57e01a
parent5422ca830c2d5f2845c837cccf00a42f4e310fa6 (diff)
Add topic handling
-rw-r--r--Channel.py6
-rw-r--r--IrcChannelForm.ui.qml22
-rw-r--r--IrcConnection.py38
-rw-r--r--IrcHandler.py7
-rw-r--r--IrcWindow.py5
5 files changed, 71 insertions, 7 deletions
diff --git a/Channel.py b/Channel.py
index 01b266d..332e175 100644
--- a/Channel.py
+++ b/Channel.py
@@ -22,13 +22,13 @@ class Channel():
def get_name(self):
return self.name
- def set_name(name):
+ def set_name(self, name):
self.name = name
- def get_topic():
+ def get_topic(self):
return self.topic
- def set_topic(topic):
+ def set_topic(self, topic):
self.topic = topic
def get_users(self):
diff --git a/IrcChannelForm.ui.qml b/IrcChannelForm.ui.qml
index eba1072..053b04a 100644
--- a/IrcChannelForm.ui.qml
+++ b/IrcChannelForm.ui.qml
@@ -12,17 +12,31 @@ Item {
anchors.top: parent.top
}
+ TextField {
+ id: topic
+ objectName: "topic"
+ width: 472
+ height: 25
+ x: 8
+ y: 8
+ readOnly: true
+ font.family: "Source Code Pro"
+ font.pointSize: 9
+ }
+
Flickable {
id: flickable
width: 472
- height: 411
+ height: 390
x: 8
- y: 8
+ y: 38
+ flickableDirection: Flickable.AutoFlickIfNeeded
TextArea.flickable: TextArea {
objectName: "chat_area"
id: textArea
x: 8
- y: 8
+ y: 38
+ readOnly: true
anchors.fill: parent
wrapMode: TextArea.Wrap
textFormat: TextEdit.RichText
@@ -30,7 +44,7 @@ Item {
font.pointSize: 9
selectByMouse: true
}
- ScrollBar.vertical: ScrollBar { }
+ ScrollBar.vertical: ScrollBar { position: 1.0 }
}
TextField {
diff --git a/IrcConnection.py b/IrcConnection.py
index 51a39be..45c41c1 100644
--- a/IrcConnection.py
+++ b/IrcConnection.py
@@ -8,6 +8,7 @@ class ircConnectThread(QThread):
nick_sig = pyqtSignal(str, str)
part_sig = pyqtSignal(str, str)
join_sig = pyqtSignal(str)
+ topic_sig = pyqtSignal(str, str)
namreply_sig = pyqtSignal(str, str)
def __init__(self, handler):
QThread.__init__(self)
@@ -33,6 +34,14 @@ class ircConnectThread(QThread):
self.c.add_global_handler("join", self.on_join)
self.c.add_global_handler("namreply", self.on_names)
self.c.add_global_handler("part", self.on_part)
+ self.c.add_global_handler("ctcp", self.on_ctcp)
+ self.c.add_global_handler("quit", self.on_quit)
+ self.c.add_global_handler("kick", self.on_kick)
+ self.c.add_global_handler("mode", self.on_mode)
+ self.c.add_global_handler("currenttopic", self.on_cur_topic)
+ self.c.add_global_handler("topic", self.on_topic)
+ self.c.add_global_handler("topicinfo", self.on_topic)
+ self.c.add_global_handler("motd", self.on_motd)
self.reactor.process_forever()
def on_connect(self, connection, event):
@@ -59,6 +68,35 @@ class ircConnectThread(QThread):
print(event)
self.namreply_sig.emit(event.arguments[1], event.arguments[2])
+ def on_ctcp(self, connection, event):
+ source = event.source.split("!")[0]
+ if (event.arguments[0] == "VERSION"):
+ connection.ctcp_reply(source, "VERSION wclient 0.2.0")
+ print(event)
+
+ def on_quit(self, connection, event):
+ print(event)
+
+ def on_kick(self, connection, event):
+ print(event)
+
+ def on_mode(self, connection, event):
+ print(event)
+
+ def on_cur_topic(self, connection, event):
+ self.topic_sig.emit(event.arguments[0], event.arguments[1])
+ print(event)
+
+ def on_topic_info(self, connection, event):
+ print(event)
+
+ def on_topic(self, connection, event):
+ self.topic_sig.emit(event.target, event.arguments[0])
+ print(event)
+
+ def on_motd(self, connection, event):
+ print(event)
+
@pyqtSlot(str, str)
def send_msg(self, channel, message):
if (message.startswith("/join")):
diff --git a/IrcHandler.py b/IrcHandler.py
index 7e0618c..bf5c166 100644
--- a/IrcHandler.py
+++ b/IrcHandler.py
@@ -121,12 +121,19 @@ class IrcHandler(QObject):
channel.remove_user(user)
chat_area.append(user + " left " + channelStr)
+ def handle_topic(self, channelStr, topic):
+ if (channelStr in self.channels):
+ channel = self.channels.get(channelStr)
+ channel.set_topic(topic)
+ self.window.update_topic(channel, topic)
+
def connect_to_irc(self, view):
self.irc.sig.connect(self.handle_msg)
self.irc.join_sig.connect(self.join_channel)
self.irc.namreply_sig.connect(self.handle_nicks)
self.irc.nick_sig.connect(self.handle_join)
self.irc.part_sig.connect(self.handle_part)
+ self.irc.topic_sig.connect(self.handle_topic)
# self.irc.join_sig.connect(self.join_channel)
self.irc.start()
self.sig.connect(self.irc.send_msg)
diff --git a/IrcWindow.py b/IrcWindow.py
index 4dc0d4c..ec5537a 100644
--- a/IrcWindow.py
+++ b/IrcWindow.py
@@ -49,6 +49,11 @@ class IrcWindow(QQuickWindow):
channel_chat_area = channel_tab.findChild(QQuickItem, "chat_area")
channel_chat_area.append(text)
+ def update_topic(self, channel, topic):
+ print(channel.get_view())
+ topic_field = channel.get_view().findChild(QQuickItem, "topic")
+ topic_field.setProperty("text", topic)
+
def dumpQMLComponents(self, root):
children = root.findChildren(QObject)
for item in children: