summaryrefslogtreecommitdiff
path: root/IrcHandler.py
diff options
context:
space:
mode:
Diffstat (limited to 'IrcHandler.py')
-rw-r--r--IrcHandler.py71
1 files changed, 56 insertions, 15 deletions
diff --git a/IrcHandler.py b/IrcHandler.py
index 1427f3e..8b1b318 100644
--- a/IrcHandler.py
+++ b/IrcHandler.py
@@ -1,20 +1,19 @@
from PyQt5.QtCore import QUrl, QThread, pyqtSignal, QObject, pyqtSlot, Qt
-from PyQt5.QtWidgets import QApplication
from PyQt5.QtQuick import QQuickView, QQuickItem, QQuickWindow
-from PyQt5.QtQml import QQmlApplicationEngine
-from PyQt5.QtGui import QGuiApplication, QKeyEvent
import IrcConnection
-
+import Channel
class IrcHandler(QObject):
sig = pyqtSignal(str,str)
+ join_sig = pyqtSignal(str)
- def __init__(self):
+ def __init__(self, window):
super(self.__class__, self).__init__()
- self.channels = list()
+ self.channels = {}
self.nick = ""
self.server = "irc.blatech.net"
self.irc = IrcConnection.ircConnectThread()
+ self.window = window
def get_channels():
return self.channels
@@ -22,8 +21,8 @@ class IrcHandler(QObject):
def set_channels(channels):
self.channels = channels
- def add_channel(channel):
- self.channels.append(channel)
+ def add_channel(self, channel):
+ self.channels[channel.get_name()] = channel
def get_server():
return self.server
@@ -37,15 +36,57 @@ class IrcHandler(QObject):
def set_nick(nick):
self.nick = nick
- def handle_input(self, view):
- text = view.get_input()
- print(text)
- self.sig.emit("#wtest", text)
- view.reset_input()
- view.update_chat(text)
+ @pyqtSlot(str)
+ def join_channel(self, channelStr):
+ res = self.irc.join_channel(channelStr)
+ if (res):
+ channel = Channel.Channel(channelStr)
+ self.add_channel(channel)
+ self.window.channel_tabs.add_channel(channelStr)
+
+ channel_view = self.window.view.findChild(QQuickItem, "channel-" + channelStr)
+ send_button = channel_view.findChild(QQuickItem, "send_button")
+ input_field = channel_view.findChild(QQuickItem, "input")
+ send_button.clicked.connect(self.handle_input)
+ input_field.send_to_irc.connect(self.handle_input)
+ channel.set_view(channel_view)
+
+ 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:]
+ if (command == "join"):
+ channel = text.split(" ")[1]
+ self.join_channel(channel)
+ else:
+ self.sig.emit(current_channel, text)
+ self.window.update_chat(current_channel, text)
+
+ self.window.reset_input(current_channel)
+
+ @pyqtSlot(str, str, str)
+ def handle_msg(self, channelStr, nick, msg):
+ if channelStr in self.channels:
+ channel = self.channels[channelStr]
+ chat_area = channel.get_view().findChild(QQuickItem, "chat_area")
+ chat_area.append(msg)
+
+ @pyqtSlot(str, str)
+ def handle_nicks(self, channelStr, users):
+ userlist = users.split(" ")
+ if (channelStr in self.channels):
+ channel = self.channels.get(channelStr)
+ channel.set_users(userlist)
+ user_list = channel.get_view().findChild(QQuickItem, "nick_list")
+ for user in userlist:
+ user_list.add_nick(user)
def connect_to_irc(self, view):
- self.irc.sig.connect(view.update_chat)
+ 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.add_nick)
# self.irc.join_sig.connect(self.join_channel)
self.irc.start()