Now About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/main.py
diff options
context:
space:
mode:
authorLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-10-06 17:34:29 +0100
committerLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-10-06 17:34:29 +0100
commitdb10dc4fdd656b25442c63eb02ea30931eee300e (patch)
tree9b2a4e835d6d52b48c0e7fb9bcb83884999ee1da /src/main.py
parent0dc8409b168b293e9566dc5a35bded510fbd043d (diff)
window: Add interface for connecting and disconnecting
Diffstat (limited to 'src/main.py')
-rw-r--r--src/main.py51
1 files changed, 33 insertions, 18 deletions
diff --git a/src/main.py b/src/main.py
index 5a1427a..53206be 100644
--- a/src/main.py
+++ b/src/main.py
@@ -27,11 +27,12 @@ gi.require_version('Adw', '1')
from gi.repository import Gtk, Gio, Adw
from .window import WeegtkWindow
-from .network import Network
+from weegtk import network
from weegtk import protocol
from weegtk import config
from .chat import WeegtkChat
from .preferences import WeegtkPreferences
+from .welcome import WeegtkWelcome
class WeegtkApplication(Adw.Application):
"""The main application singleton class."""
@@ -42,13 +43,20 @@ class WeegtkApplication(Adw.Application):
self.create_action('quit', lambda *_: self.quit(), ['<primary>q'])
self.create_action('about', self.on_about_action)
self.create_action('preferences', self.on_preferences_action)
+ self.create_action('disconnect', self.disconnect)
- self.network = Network()
+ self.network = network.Network()
self.network.connect("status_changed", self._network_status_changed)
self.network.connect("message_from_weechat", self._network_weechat_msg)
+ self.buffers = []
+
+ conf = config.read()
+ if config.str_to_bool(conf["relay"]["autoconnect"]):
+ self.connect_to_weechat()
+
+ def connect_to_weechat(self, *args):
conf = config.read()
- #self.network.connect_weechat("localhost", "9001", False, relay_pw, None, "")
self.network.connect_weechat_ssh(conf["ssh"]["host"],
conf["ssh"]["port"],
conf["ssh"]["username"],
@@ -56,21 +64,25 @@ class WeegtkApplication(Adw.Application):
conf["relay"]["hostname"],
conf["relay"]["port"],
conf["relay"]["password"])
-
+ def clear_buffers(self):
+ for buffer in self.buffers:
+ self.props.active_window.stack.remove(buffer)
self.buffers = []
+ def disconnect(self, *args):
+ self.network.disconnect_weechat()
+
+ def handle_disconnect(self):
+ self.props.active_window.set_page(self.welcome_page)
+ self.clear_buffers()
+
def _network_status_changed(self, source_object, status, extra):
"""Called when the network status has changed."""
- # TODO handle this
- #if self.config.getboolean('look', 'statusbar'):
- # self.statusBar().showMessage(status)
- #self.network.debug_print(0, '', status, forcecolor='#0000AA')
- #self.network_status_set(status)
- print(f"Status is {status}")
+ if status == network.STATUS_DISCONNECTED:
+ self.handle_disconnect()
def _network_weechat_msg(self, source_object, message):
"""Called when a message is received from WeeChat."""
- #print(f"Message {message}")
try:
proto = protocol.Protocol()
message = proto.decode(message.get_data())
@@ -99,6 +111,10 @@ class WeegtkApplication(Adw.Application):
win = self.props.active_window
if not win:
win = WeegtkWindow(application=self)
+ welcome = WeegtkWelcome()
+ welcome.connect("connect-network", self.connect_to_weechat)
+ self.welcome_page = win.stack.add_named(welcome, "welcome")
+ win.set_page(self.welcome_page)
win.present()
def on_about_action(self, *args):
@@ -148,11 +164,8 @@ class WeegtkApplication(Adw.Application):
for obj in message.objects:
if obj.objtype != 'hda' or obj.value['path'][-1] != 'buffer':
continue
- #self.list_buffers.clear()
- #while self.stacked_buffers.count() > 0:
- # buf = self.stacked_buffers.widget(0)
- # self.stacked_buffers.removeWidget(buf)
- self.buffers = []
+
+ self.clear_buffers()
for item in obj.value['items']:
buf = self.create_buffer(item)
self.insert_buffer(len(self.buffers), buf)
@@ -323,8 +336,9 @@ class WeegtkApplication(Adw.Application):
# Only make chats visible on main screen
if True or buf.is_chat():
- test_label = Gtk.Label(label="Hello")
- self.props.active_window.stack.add_titled(buf, name=buf_name, title=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)
def buffer_input(self, source_object, full_name, text):
if self.network.is_connected():
@@ -335,3 +349,4 @@ def main(version):
"""The application's entry point."""
app = WeegtkApplication()
return app.run(sys.argv)
+