summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Robinson <joe@lc8n.com>2017-04-15 16:08:40 +0200
committerJoe Robinson <joe@lc8n.com>2017-04-15 16:08:40 +0200
commit166a8206a3747628182a97acbc25bf393e78eac9 (patch)
tree7725fbfd060ed4ac0e6ec698ab2eb20199b699b5
parentcb1429328b11e1acef99e4c5730e55e3384b19fd (diff)
Handle joining of channels, tab UI, probably some other things
-rw-r--r--Channel.py50
-rw-r--r--IrcChannelForm.ui.qml2
-rw-r--r--IrcConnection.py29
-rw-r--r--IrcHandler.py71
-rw-r--r--IrcWindow.py29
-rw-r--r--main.qml20
6 files changed, 154 insertions, 47 deletions
diff --git a/Channel.py b/Channel.py
new file mode 100644
index 0000000..1729c4e
--- /dev/null
+++ b/Channel.py
@@ -0,0 +1,50 @@
+class Channel():
+
+ def __init__(self):
+ self.name = ""
+ self.topic = ""
+ self.users = list()
+ self.modes = list()
+
+ def __init__(self, name, topic, userlist, modes):
+ self.name = name
+ self.topic = topic
+ users = userlist.split(" ")
+ self.users = list(users)
+ self.modes = list()
+
+ def __init__(self, name):
+ self.name = name
+ self.topic = ""
+ self.users = list()
+ self.modes = list()
+
+ def get_name(self):
+ return self.name
+
+ def set_name(name):
+ self.name = name
+
+ def get_topic():
+ return self.topic
+
+ def set_topic(topic):
+ self.topic = topic
+
+ def get_users(self):
+ return self.users
+
+ def set_users(self, users):
+ self.users = users
+
+ def add_user(user):
+ self.users.append(user)
+
+ def remove_user(user):
+ self.users.delete(user)
+
+ def get_view(self):
+ return self.view
+
+ def set_view(self, view):
+ self.view = view
diff --git a/IrcChannelForm.ui.qml b/IrcChannelForm.ui.qml
index 9e7ec37..9b37cf6 100644
--- a/IrcChannelForm.ui.qml
+++ b/IrcChannelForm.ui.qml
@@ -27,7 +27,7 @@ Item {
wrapMode: TextArea.Wrap
textFormat: TextEdit.RichText
font.family: "Source Code Pro"
- font.pointSize: 11
+ font.pointSize: 9
selectByMouse: true
}
ScrollBar.vertical: ScrollBar { }
diff --git a/IrcConnection.py b/IrcConnection.py
index e51e4e3..4a1d9ed 100644
--- a/IrcConnection.py
+++ b/IrcConnection.py
@@ -1,14 +1,18 @@
from PyQt5.QtCore import QUrl, QThread, pyqtSignal, QObject, pyqtSlot, Qt
import irc.client
+import IrcHandler
+
class ircConnectThread(QThread):
- sig = pyqtSignal(str)
+ sig = pyqtSignal(str, str, str)
nick_sig = pyqtSignal(str, str)
join_sig = pyqtSignal(str)
+ namreply_sig = pyqtSignal(str, str)
def __init__(self):
QThread.__init__(self)
self.reactor = irc.client.Reactor()
self.server = self.reactor.server()
+ self.handler = IrcHandler.IrcHandler
def __del__(self):
self.wait()
@@ -31,25 +35,24 @@ class ircConnectThread(QThread):
def on_connect(self, connection, event):
if irc.client.is_channel("#wtest"):
- connection.join("#wtest")
+ self.join_sig.emit("#wtest")
return
def on_pubmsg(self, connection, event):
- self.sig.emit(event.source + ": " + event.arguments[0])
+ print(event)
+ self.sig.emit(event.target, event.source, event.arguments[0])
def on_privmsg(self, connection, event):
- self.sig.emit(event.source + ": " + event.arguments[0])
+ self.sig.emit(event.source, "", event.arguments[0])
def on_join(self, connection, event):
print(event)
nick = event.source.split("!")[0]
self.nick_sig.emit(event.target, event.source.split("!")[0])
- self.sig.emit(event.source + " joined " + event.target)
+ self.sig.emit(event.target, "", event.source + " joined " + event.target)
def on_names(self, connection, event):
print(event)
- for nick in event.arguments[2].split(" "):
- if (nick.strip() != ""):
- self.nick_sig.emit(event.arguments[1], nick)
+ self.namreply_sig.emit(event.arguments[1], event.arguments[2])
@pyqtSlot(str, str)
def send_msg(self, channel, message):
@@ -59,7 +62,9 @@ class ircConnectThread(QThread):
self.server.privmsg(channel, message)
print(message)
- def handle_join(self, message):
- print(message)
- self.c.join(message.split(" ")[1])
- self.join_sig.emit(message.split(" ")[1])
+ @pyqtSlot(str)
+ def join_channel(self, channel):
+ print(channel)
+ self.c.join(channel)
+ #TODO: handle errors such as invalid/passworded channel
+ return True
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()
diff --git a/IrcWindow.py b/IrcWindow.py
index 77a61cd..4dc0d4c 100644
--- a/IrcWindow.py
+++ b/IrcWindow.py
@@ -1,5 +1,5 @@
from PyQt5.QtCore import QUrl, QThread, pyqtSignal, QObject, pyqtSlot, Qt
-from PyQt5.QtWidgets import QApplication
+from PyQt5.QtWidgets import QApplication, QTabBar
from PyQt5.QtQuick import QQuickView, QQuickItem, QQuickWindow
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtGui import QGuiApplication, QKeyEvent
@@ -11,34 +11,43 @@ class IrcWindow(QQuickWindow):
def __init__(self, view):
super(self.__class__, self).__init__()
self.view = view
- self.handler = IrcHandler.IrcHandler()
+ self.handler = IrcHandler.IrcHandler(self)
self.dumpQMLComponents(self.view)
+
self.connect_button = self.view.findChild(QQuickItem, "connect_button")
self.send_button = self.view.findChild(QQuickItem, "send_button")
self.input_field = self.view.findChild(QQuickItem, "input")
self.chat_area = self.view.findChild(QQuickItem, "chat_area")
+ self.nick_list = self.view.findChild(QQuickItem, "nick_list")
+ self.channel_tabs = self.view.findChild(QQuickItem, "channel_tabs")
self.send_button.clicked.connect(self.handle_input)
self.connect_button.clicked.connect(self.connect_to_irc)
self.input_field.send_to_irc.connect(self.handle_input)
- print(self.input_field)
def connect_to_irc(self):
self.handler.connect_to_irc(self)
def handle_input(self):
- self.handler.handle_input(self)
+ self.handler.handle_input()
- def get_input(self):
- return self.input_field.property("text")
+ def get_input(self, channel):
+ print(channel)
+ channel_tab = self.view.findChild(QQuickItem, "channel-" + channel)
+ channel_input = channel_tab.findChild(QQuickItem, "input")
+ return channel_input.property("text")
- def reset_input(self):
- self.input_field.setProperty("text", "")
+ def reset_input(self, channel):
+ channel_tab = self.view.findChild(QQuickItem, "channel-" + channel)
+ channel_input = channel_tab.findChild(QQuickItem, "input")
+ channel_input.setProperty("text", "")
@pyqtSlot(str)
- def update_chat(self, text):
- self.chat_area.append(text)
+ def update_chat(self, channel, text):
+ channel_tab = self.view.findChild(QQuickItem, "channel-" + channel)
+ channel_chat_area = channel_tab.findChild(QQuickItem, "chat_area")
+ channel_chat_area.append(text)
def dumpQMLComponents(self, root):
children = root.findChildren(QObject)
diff --git a/main.qml b/main.qml
index e1052fd..9623c04 100644
--- a/main.qml
+++ b/main.qml
@@ -27,18 +27,20 @@ ApplicationWindow {
id: channel_tabs
objectName: "channel_tabs"
TabButton {
- text: "a"
+ objectName: "channel-status"
+ text: "status"
}
- function add_channel(channel){
+ function add_channel(channel) {
var newTab = tabButton.createObject(channel_tabs, {"text": channel})
- channel_tabs.addItem(newTab)
- var newChannel = Qt.createComponent("Page1.qml").createObject(swipeView, {"objectName": "channel"+channel})
-
+ channel_tabs.insertItem(channel_tabs.count, newTab)
+ var newChannel = Qt.createComponent("IrcChannel.qml").createObject(swipeView, {"objectName": "channel-"+channel})
+ channel_tabs.currentIndex = channel_tabs.count-1
+ for (var i = 0; i < newChannel.children.length; ++i) {
+ if (newChannel.children[i].objectName === "input") {
+ newChannel.children[i].focus = true
+ }
+ }
}
-
-
-
}
-
}