[quick_replies] Port to Gtk4
This commit is contained in:
@@ -16,15 +16,13 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import Gtk
|
||||
|
||||
from gajim.common import app
|
||||
from gajim.gtk.widgets import GajimAppWindow
|
||||
from gajim.plugins.helpers import get_builder
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
|
||||
@@ -32,34 +30,48 @@ if TYPE_CHECKING:
|
||||
from ..plugin import QuickRepliesPlugin
|
||||
|
||||
|
||||
class ConfigDialog(Gtk.ApplicationWindow):
|
||||
class ConfigDialog(GajimAppWindow):
|
||||
def __init__(self, plugin: QuickRepliesPlugin, transient: Gtk.Window) -> None:
|
||||
|
||||
Gtk.ApplicationWindow.__init__(self)
|
||||
self.set_application(app.app)
|
||||
self.set_show_menubar(False)
|
||||
self.set_title(_("Quick Replies Configuration"))
|
||||
self.set_transient_for(transient)
|
||||
self.set_default_size(400, 400)
|
||||
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
|
||||
self.set_modal(True)
|
||||
self.set_destroy_with_parent(True)
|
||||
GajimAppWindow.__init__(
|
||||
self,
|
||||
name="QuickRepliesConfigDialog",
|
||||
title=_("Quick Replies Configuration"),
|
||||
default_width=400,
|
||||
default_height=400,
|
||||
transient_for=transient,
|
||||
modal=True,
|
||||
)
|
||||
|
||||
ui_path = Path(__file__).parent
|
||||
self._ui = get_builder(str(ui_path.resolve() / "config.ui"))
|
||||
|
||||
self._plugin = plugin
|
||||
|
||||
self.add(self._ui.box)
|
||||
self.set_child(self._ui.box)
|
||||
|
||||
self._fill_list()
|
||||
self.show_all()
|
||||
self._load_replies()
|
||||
|
||||
self._ui.connect_signals(self)
|
||||
self.connect("destroy", self._on_destroy)
|
||||
self._connect(self._ui.add_button, "clicked", self._on_add_clicked)
|
||||
self._connect(self._ui.remove_button, "clicked", self._on_remove_clicked)
|
||||
self._connect(self._ui.cellrenderer, "edited", self._on_reply_edited)
|
||||
self._connect(self.window, "close-request", self._on_close_request)
|
||||
|
||||
def _fill_list(self) -> None:
|
||||
for reply in self._plugin.quick_replies:
|
||||
self.show()
|
||||
|
||||
def _cleanup(self) -> None:
|
||||
del self._plugin
|
||||
|
||||
def _on_close_request(self, win: Gtk.ApplicationWindow) -> None:
|
||||
replies: list[str] = []
|
||||
for row in self._ui.replies_store:
|
||||
if row[0] == "":
|
||||
continue
|
||||
replies.append(row[0])
|
||||
self._plugin.set_quick_replies(replies)
|
||||
|
||||
def _load_replies(self) -> None:
|
||||
for reply in self._plugin.get_quick_replies():
|
||||
self._ui.replies_store.append([reply])
|
||||
|
||||
def _on_reply_edited(
|
||||
@@ -85,11 +97,3 @@ class ConfigDialog(Gtk.ApplicationWindow):
|
||||
for ref in references:
|
||||
iter_ = model.get_iter(ref.get_path())
|
||||
self._ui.replies_store.remove(iter_)
|
||||
|
||||
def _on_destroy(self, *args: Any) -> None:
|
||||
replies: list[str] = []
|
||||
for row in self._ui.replies_store:
|
||||
if row[0] == "":
|
||||
continue
|
||||
replies.append(row[0])
|
||||
self._plugin.set_quick_replies(replies)
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.2 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<object class="GtkListStore" id="replies_store">
|
||||
<columns>
|
||||
<!-- column-name reply -->
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkBox" id="box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">18</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<property name="focusable">1</property>
|
||||
<property name="vexpand">1</property>
|
||||
<property name="hexpand">1</property>
|
||||
<property name="child">
|
||||
<object class="GtkTreeView" id="replies_treeview">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="focusable">1</property>
|
||||
<property name="model">replies_store</property>
|
||||
<property name="search_column">1</property>
|
||||
<child internal-child="selection">
|
||||
@@ -32,15 +25,14 @@
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="title" translatable="yes">Quick Reply</property>
|
||||
<property name="clickable">True</property>
|
||||
<property name="sort_indicator">True</property>
|
||||
<property name="resizable">1</property>
|
||||
<property name="title" translatable="1">Quick Reply</property>
|
||||
<property name="clickable">1</property>
|
||||
<property name="sort_indicator">1</property>
|
||||
<property name="sort_column_id">0</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText">
|
||||
<property name="editable">True</property>
|
||||
<signal name="edited" handler="_on_reply_edited" swapped="no"/>
|
||||
<object class="GtkCellRendererText" id="cellrenderer">
|
||||
<property name="editable">1</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">0</attribute>
|
||||
@@ -49,55 +41,28 @@
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolbar">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="toolbar_style">icons</property>
|
||||
<property name="icon_size">4</property>
|
||||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Add</property>
|
||||
<property name="icon_name">list-add-symbolic</property>
|
||||
<signal name="clicked" handler="_on_add_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Remove</property>
|
||||
<property name="icon_name">list-remove-symbolic</property>
|
||||
<signal name="clicked" handler="_on_remove_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<object class="GtkBox">
|
||||
<property name="css-classes">toolbar</property>
|
||||
<style>
|
||||
<class name="inline-toolbar"/>
|
||||
</style>
|
||||
<child>
|
||||
<object class="GtkButton" id="add_button">
|
||||
<property name="tooltip_text" translatable="1">Add</property>
|
||||
<property name="icon_name">list-add-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="remove_button">
|
||||
<property name="tooltip_text" translatable="1">Remove</property>
|
||||
<property name="icon_name">list-remove-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
|
||||
Reference in New Issue
Block a user