summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Channel.py16
-rw-r--r--IrcChannelForm.ui.qml14
-rw-r--r--IrcHandler.py46
-rw-r--r--User.py43
4 files changed, 91 insertions, 28 deletions
diff --git a/Channel.py b/Channel.py
index 8af00d2..01b266d 100644
--- a/Channel.py
+++ b/Channel.py
@@ -3,20 +3,20 @@ class Channel():
def __init__(self):
self.name = ""
self.topic = ""
- self.users = list()
+ self.users = {}
self.modes = list()
def __init__(self, name, topic, userlist, modes):
self.name = name
self.topic = topic
users = userlist.split(" ")
- self.users = list(users)
+ self.users = {}
self.modes = list()
def __init__(self, name):
self.name = name
self.topic = ""
- self.users = list()
+ self.users = {}
self.modes = list()
def get_name(self):
@@ -35,13 +35,15 @@ class Channel():
return self.users
def set_users(self, users):
- self.users = users
+ for user in users:
+ self.users[user.get_nick()] = user
def add_user(self, user):
- self.users.append(user)
+ self.users[user.get_nick()] = user
- def remove_user(self, user):
- self.users.remove(user)
+ def remove_user(self, nick):
+ del(self.users[nick])
+ # self.users.remove(user)
def get_view(self):
return self.view
diff --git a/IrcChannelForm.ui.qml b/IrcChannelForm.ui.qml
index d1f5e59..eba1072 100644
--- a/IrcChannelForm.ui.qml
+++ b/IrcChannelForm.ui.qml
@@ -18,7 +18,7 @@ Item {
height: 411
x: 8
y: 8
- TextArea {
+ TextArea.flickable: TextArea {
objectName: "chat_area"
id: textArea
x: 8
@@ -44,6 +44,7 @@ Item {
selectByMouse: true
Keys.onEnterPressed: send_to_irc()
Keys.onReturnPressed: send_to_irc()
+ Keys.onTabPressed: textField.text = "bla"
}
@@ -60,10 +61,11 @@ Item {
height: 20
Text {
text: name
+ property string nick
anchors.verticalCenter: parent.verticalCenter
- font.bold: true
+ font.bold: false
font.family: "Source Code Pro"
- font.pointSize: 11
+ font.pointSize: 9
}
}
@@ -71,13 +73,13 @@ Item {
id: nickListModel
}
- function add_nick(nick){
- nickListModel.append({name: nick})
+ function add_nick(nick, mode){
+ nickListModel.append({name: '<b>'+mode+'</b>'+nick, nick: nick})
}
function remove_nick(nick){
for (var i = 0; i < nickListModel.count; ++i) {
- if (nickListModel.get(i).name === nick) {
+ if (nickListModel.get(i).nick === nick) {
nickListModel.remove(i)
}
}
diff --git a/IrcHandler.py b/IrcHandler.py
index ff2053b..7e0618c 100644
--- a/IrcHandler.py
+++ b/IrcHandler.py
@@ -3,6 +3,8 @@ from PyQt5.QtQuick import QQuickView, QQuickItem, QQuickWindow
import IrcConnection
import Channel
+import User
+
class IrcHandler(QObject):
sig = pyqtSignal(str,str)
join_sig = pyqtSignal(str)
@@ -62,7 +64,7 @@ class IrcHandler(QObject):
self.join_channel(channel)
else:
self.sig.emit(current_channel, text)
- self.window.update_chat(current_channel, text)
+ self.window.update_chat(current_channel, self.nick + ": " + text)
self.window.reset_input(current_channel)
@@ -70,39 +72,53 @@ class IrcHandler(QObject):
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(nick + ": " + msg)
+ self.window.update_chat(channelStr , nick + ": " + msg)
@pyqtSlot(str, str)
- def handle_nicks(self, channelStr, users):
- userlist = users.split(" ")[0:-1]
+ def handle_nicks(self, channelStr, nicks):
+ nick_listStr = nicks.split(" ")[0:-1]
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 handle_join(self, channelStr, user):
+ user_list = channel.get_view().findChild(QQuickItem, "nick_list")
+ for nickStr in nick_listStr:
+ if (nickStr[0] in ["@", "+", "~", "%"]):
+ mode = nickStr[0]
+ nickStr = nickStr[1:]
+ else:
+ mode = ""
+ user = User.User(nickStr, mode)
+ channel.add_user(user)
+ user_list.add_nick(nickStr, mode)
+
+ def handle_join(self, channelStr, nickStr):
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)
+ if (nickStr != self.get_nick()):
+ if (nickStr[0] in ["@", "+", "~", "%"]):
+ mode = nickStr[0]
+ nickStr = nickStr[1:]
+ else:
+ mode = ""
+ user = User.User(nickStr, mode)
+ channel.add_user(user)
+ user_list.add_nick(nickStr, mode)
+ chat_area.append(nickStr + " joined " + channelStr)
def handle_part(self, channelStr, user):
if (channelStr in self.channels):
channel = self.channels.get(channelStr)
- channel.remove_user(user)
+ print(channel.get_users())
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)
+ channel.remove_user(user)
chat_area.append(user + " left " + channelStr)
def connect_to_irc(self, view):
diff --git a/User.py b/User.py
new file mode 100644
index 0000000..9ad3eeb
--- /dev/null
+++ b/User.py
@@ -0,0 +1,43 @@
+class User():
+
+ def __init__(self):
+ self.nick = ""
+ self.mode = ""
+ self.host = ""
+ self.real_name = ""
+
+ def __init__(self, nick, mode, host, real_name):
+ self.nick = nick
+ self.mode = mode
+ self.host = host
+ self.real_name = real_name
+
+ def __init__(self, nick, mode):
+ self.nick = nick
+ self.mode = mode
+ self.host = ""
+ self.real_name = ""
+
+ def get_nick(self):
+ return self.nick
+
+ def set_nick(self, nick):
+ self.nick = nick
+
+ def get_mode(self):
+ return self.mode
+
+ def set_host(self, mode):
+ self.mode = mode
+
+ def get_host(self):
+ return self.host
+
+ def set_host(self, host):
+ self.host = host
+
+ def get_real_name(self):
+ return self.real_name
+
+ def set_real_name(self, host):
+ self.real_name = real_name