From 04a26f18dd9841c07aeb0fbbb1b30e71308ba068 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 20 Apr 2017 17:02:28 +0100 Subject: Add ability to /part channels --- IrcChannelForm.ui.qml | 1 + IrcConnection.py | 7 +++++++ IrcHandler.py | 21 +++++++++++++++++++-- main.qml | 13 +++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/IrcChannelForm.ui.qml b/IrcChannelForm.ui.qml index 993c41f..a963dda 100644 --- a/IrcChannelForm.ui.qml +++ b/IrcChannelForm.ui.qml @@ -20,6 +20,7 @@ Item { x: 8 y: 8 readOnly: true + selectByMouse: true font.family: "Source Code Pro" font.pointSize: 9 } diff --git a/IrcConnection.py b/IrcConnection.py index 7345f6d..08240fe 100644 --- a/IrcConnection.py +++ b/IrcConnection.py @@ -125,3 +125,10 @@ class ircConnectThread(QThread): self.c.join(channel) #TODO: handle errors such as invalid/passworded channel return True + + @pyqtSlot(str) + def part_channel(self, channel): + print(channel) + self.c.part(channel) + #TODO: handle errors such as invalid/passworded channel + return True diff --git a/IrcHandler.py b/IrcHandler.py index 589087f..9fd8b39 100644 --- a/IrcHandler.py +++ b/IrcHandler.py @@ -26,6 +26,9 @@ class IrcHandler(QObject): def add_channel(self, channel): self.channels[channel.get_name()] = channel + def remove_channel(self, channel_name): + del self.channels[channel_name] + def get_server(): return self.server @@ -53,15 +56,29 @@ class IrcHandler(QObject): input_field.send_to_irc.connect(self.handle_input) channel.set_view(channel_view) + def part_channel(self, channelStr): + if (channelStr in self.channels): + res = self.irc.part_channel(channelStr) + if (res): + self.remove_channel(channelStr) + self.window.channel_tabs.remove_channel(channelStr) + def handle_input(self): current_channel = self.window.channel_tabs.property('currentItem').property('text') text = self.window.get_input(current_channel) if (text.startswith("/")): - command = text.split(" ")[0][1:] + params = text.split(" ") + command = params[0][1:] if (command == "join"): - channel = text.split(" ")[1] + channel = params[1] self.join_channel(channel) + elif (command == "part"): + if (len(params) > 1 and params[1].strip() != ""): + channel = params[1] + else: + channel = current_channel + self.part_channel(channel) else: self.sig.emit(current_channel, text) self.window.update_chat(current_channel, "<" + self.nick + "> " + text) diff --git a/main.qml b/main.qml index a4714a8..592e9f0 100644 --- a/main.qml +++ b/main.qml @@ -42,5 +42,18 @@ ApplicationWindow { } } } + + function remove_channel(channel) { + for (var i = 0; i < channel_tabs.count; ++i) { + if (channel_tabs.itemAt(i).text === channel) { + channel_tabs.removeItem(i) + } + } + for (var i = 0; i < swipeView.children.length; ++i) { + if (swipeView.children[i].objectName === "channel-"+channel) { + swipeView.children[i].destroy() + } + } + } } } -- cgit v1.2.3