From 1af1f7d958fcec70817962563ce1608d985c9a44 Mon Sep 17 00:00:00 2001 From: Lucas Fryzek Date: Mon, 7 Oct 2024 18:14:05 +0100 Subject: fix various exceptions from missing Qweechat code --- src/chat.py | 12 ++++++++++++ src/main.py | 28 ++++++++++++++++++++++++---- src/relay/network.py | 2 ++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/chat.py b/src/chat.py index ede2817..93b49a3 100644 --- a/src/chat.py +++ b/src/chat.py @@ -102,6 +102,18 @@ class WeegtkChat(Adw.Bin): self.messages.scroll_to(n_items - 1, Gtk.ListScrollFlags.FOCUS) self.window.emit("scroll_child", Gtk.ScrollType.END, False) + def nicklist_add_item(self, parent, group, prefix, name, visible): + # TODO start handling nicklist + pass + + def nicklist_remove_item(self, parent, group, name): + # TODO start handling nicklist + pass + + def nicklist_refresh(self): + # TODO start handling nicklist + pass + def update_prompt(self): # TODO code copied from QWeechat, figure out what I should do with it pass diff --git a/src/main.py b/src/main.py index 5334516..ffe1e43 100644 --- a/src/main.py +++ b/src/main.py @@ -20,6 +20,7 @@ import sys import os import gi +import traceback gi.require_version('Gtk', '4.0') gi.require_version('Adw', '1') @@ -80,6 +81,22 @@ class WeegtkApplication(Adw.Application): self.buffers.pop(index) self.pages.pop(index) + def find_buffer_index_for_insert(self, next_buffer): + """Find position to insert a buffer in list.""" + index = -1 + if next_buffer == '0x0': + index = len(self.buffers) + else: + bufs = [i for i, b in enumerate(self.buffers) + if b.pointer() == next_buffer] + if bufs: + index = bufs[0] + if index < 0: + print('Warning: unable to find position for buffer, using end of ' + 'list by default') + index = len(self.buffers) + return index + def disconnect(self, *args): self.network.disconnect_weechat() @@ -109,9 +126,8 @@ class WeegtkApplication(Adw.Application): #print(f"parsed message is f{message}") self.parse_message(message) except: - print('Error while decoding message from WeeChat:\n%s' - % traceback.format_exc()) - self.net.disconnect_weechat() + print(f"Error while decoding message from WeeChat:\n{traceback.format_exc()}") + self.disconnect() def do_activate(self): """Called when the application is activated. @@ -298,8 +314,11 @@ class WeegtkApplication(Adw.Application): self.buffers[index].data['full_name'] = item['full_name'] self.buffers[index].data['short_name'] = item['short_name'] elif message.msgid == '_buffer_title_changed': + # TODO figure out what to do when we get a title change + # as grep plugin seems to override title with results + # which can break UI self.buffers[index].data['title'] = item['title'] - self.buffers[index].update_title() + ##self.pages[index].set_title(item['title']) elif message.msgid == '_buffer_cleared': self.buffers[index].widget.chat.clear() elif message.msgid.startswith('_buffer_localvar_'): @@ -347,6 +366,7 @@ class WeegtkApplication(Adw.Application): # Only make chats visible on main screen if True or buf.is_chat(): + print(f"TITLE IS {buf_name}") page = self.props.active_window.stack.add_titled(buf, name=buf_name, title=buf_name) if buf.data["full_name"] == "core.weechat": self.props.active_window.set_page(page) diff --git a/src/relay/network.py b/src/relay/network.py index b502ddd..b27edaa 100644 --- a/src/relay/network.py +++ b/src/relay/network.py @@ -247,6 +247,8 @@ class Network(GObject.GObject): def is_connected(self): """Return True if the socket is connected, False otherwise.""" + if self._socket is None: + return False return self._socket.is_connected() def is_ssl(self): -- cgit