summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Channel.py6
-rw-r--r--IrcChannelForm.ui.qml8
-rw-r--r--IrcConnection.py15
-rw-r--r--IrcHandler.py37
4 files changed, 51 insertions, 15 deletions
diff --git a/Channel.py b/Channel.py
index 1729c4e..8af00d2 100644
--- a/Channel.py
+++ b/Channel.py
@@ -37,11 +37,11 @@ class Channel():
def set_users(self, users):
self.users = users
- def add_user(user):
+ def add_user(self, user):
self.users.append(user)
- def remove_user(user):
- self.users.delete(user)
+ def remove_user(self, user):
+ self.users.remove(user)
def get_view(self):
return self.view
diff --git a/IrcChannelForm.ui.qml b/IrcChannelForm.ui.qml
index 9b37cf6..d1f5e59 100644
--- a/IrcChannelForm.ui.qml
+++ b/IrcChannelForm.ui.qml
@@ -74,6 +74,14 @@ Item {
function add_nick(nick){
nickListModel.append({name: nick})
}
+
+ function remove_nick(nick){
+ for (var i = 0; i < nickListModel.count; ++i) {
+ if (nickListModel.get(i).name === nick) {
+ nickListModel.remove(i)
+ }
+ }
+ }
}
Button {
diff --git a/IrcConnection.py b/IrcConnection.py
index 4a1d9ed..51a39be 100644
--- a/IrcConnection.py
+++ b/IrcConnection.py
@@ -6,20 +6,21 @@ import IrcHandler
class ircConnectThread(QThread):
sig = pyqtSignal(str, str, str)
nick_sig = pyqtSignal(str, str)
+ part_sig = pyqtSignal(str, str)
join_sig = pyqtSignal(str)
namreply_sig = pyqtSignal(str, str)
- def __init__(self):
+ def __init__(self, handler):
QThread.__init__(self)
self.reactor = irc.client.Reactor()
self.server = self.reactor.server()
- self.handler = IrcHandler.IrcHandler
+ self.handler = handler
def __del__(self):
self.wait()
def run(self):
try:
- self.c = self.server.connect("irc.blatech.net", 6667, "wtest")
+ self.c = self.server.connect("irc.blatech.net", 6667, self.handler.get_nick())
except irc.client.ServerConnectionError:
print(sys.exc_info()[1])
raise SystemExit(1)
@@ -31,6 +32,7 @@ class ircConnectThread(QThread):
self.c.add_global_handler("privmsg", self.on_privmsg)
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.reactor.process_forever()
def on_connect(self, connection, event):
@@ -39,7 +41,7 @@ class ircConnectThread(QThread):
return
def on_pubmsg(self, connection, event):
print(event)
- self.sig.emit(event.target, event.source, event.arguments[0])
+ self.sig.emit(event.target, event.source.split("!")[0], event.arguments[0])
def on_privmsg(self, connection, event):
self.sig.emit(event.source, "", event.arguments[0])
@@ -48,7 +50,10 @@ class ircConnectThread(QThread):
print(event)
nick = event.source.split("!")[0]
self.nick_sig.emit(event.target, event.source.split("!")[0])
- self.sig.emit(event.target, "", event.source + " joined " + event.target)
+
+ def on_part(self, connection, event):
+ nick = event.source.split("!")[0]
+ self.part_sig.emit(event.target, event.source.split("!")[0])
def on_names(self, connection, event):
print(event)
diff --git a/IrcHandler.py b/IrcHandler.py
index 8b1b318..ff2053b 100644
--- a/IrcHandler.py
+++ b/IrcHandler.py
@@ -10,9 +10,9 @@ class IrcHandler(QObject):
def __init__(self, window):
super(self.__class__, self).__init__()
self.channels = {}
- self.nick = ""
+ self.nick = "wtest"
self.server = "irc.blatech.net"
- self.irc = IrcConnection.ircConnectThread()
+ self.irc = IrcConnection.ircConnectThread(self)
self.window = window
def get_channels():
@@ -30,10 +30,10 @@ class IrcHandler(QObject):
def set_server(server):
self.server = server
- def get_nick():
+ def get_nick(self):
return self.nick
- def set_nick(nick):
+ def set_nick(self, nick):
self.nick = nick
@pyqtSlot(str)
@@ -71,11 +71,11 @@ class IrcHandler(QObject):
if channelStr in self.channels:
channel = self.channels[channelStr]
chat_area = channel.get_view().findChild(QQuickItem, "chat_area")
- chat_area.append(msg)
+ chat_area.append(nick + ": " + msg)
@pyqtSlot(str, str)
def handle_nicks(self, channelStr, users):
- userlist = users.split(" ")
+ userlist = users.split(" ")[0:-1]
if (channelStr in self.channels):
channel = self.channels.get(channelStr)
channel.set_users(userlist)
@@ -83,11 +83,34 @@ class IrcHandler(QObject):
for user in userlist:
user_list.add_nick(user)
+ def handle_join(self, channelStr, user):
+ if (channelStr in self.channels):
+ channel = self.channels.get(channelStr)
+ channel.add_user(user)
+ user_list = channel.get_view().findChild(QQuickItem, "nick_list")
+ chat_area = channel.get_view().findChild(QQuickItem, "chat_area")
+
+ if (user != self.get_nick()):
+ user_list.add_nick(user)
+ chat_area.append(user + " joined " + channelStr)
+
+
+ def handle_part(self, channelStr, user):
+ if (channelStr in self.channels):
+ channel = self.channels.get(channelStr)
+ channel.remove_user(user)
+ user_list = channel.get_view().findChild(QQuickItem, "nick_list")
+ chat_area = channel.get_view().findChild(QQuickItem, "chat_area")
+ if (user != self.get_nick()):
+ user_list.remove_nick(user)
+ chat_area.append(user + " left " + channelStr)
+
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.add_nick)
+ self.irc.nick_sig.connect(self.handle_join)
+ self.irc.part_sig.connect(self.handle_part)
# self.irc.join_sig.connect(self.join_channel)
self.irc.start()
self.sig.connect(self.irc.send_msg)