Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim-plugins.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwurstsalat <mailtrash@posteo.de>2022-08-16 10:36:16 +0300
committerwurstsalat <mailtrash@posteo.de>2022-09-12 23:02:17 +0300
commiteda7f4f3589b4b4f0ab66faec1e9cd927c69d03f (patch)
treea69fe3892bc46a3e3c2d1e6481445fb7a44fd9b8
parent2e3ec5d209f0141907536f3984add5df72207d82 (diff)
[now_listen] 1.4.2
-rw-r--r--now_listen/now_listen.py66
-rw-r--r--now_listen/plugin-manifest.json4
2 files changed, 44 insertions, 26 deletions
diff --git a/now_listen/now_listen.py b/now_listen/now_listen.py
index e307da3..3e43aaf 100644
--- a/now_listen/now_listen.py
+++ b/now_listen/now_listen.py
@@ -13,6 +13,10 @@
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
+from __future__ import annotations
+
+from typing import cast
+
import sys
import logging
from functools import partial
@@ -20,6 +24,10 @@ from functools import partial
from gi.repository import Gdk
from gi.repository import GObject
+from nbxmpp.structs import TuneData
+
+from gajim.gui.message_input import MessageInputTextView
+
from gajim.plugins import GajimPlugin
from gajim.plugins.plugins_i18n import _
@@ -37,9 +45,9 @@ class NowListenPlugin(GajimPlugin):
self.description = _('Copy tune info of playing music to conversation '
'input box at cursor position (Alt + N)')
self.config_dialog = partial(NowListenConfigDialog, self)
- self.gui_extension_points = {'chat_control_base':
- (self._on_connect_chat_control,
- self._on_disconnect_chat_control)}
+ self.gui_extension_points = {
+ 'message_input': (self._on_message_input_created, None)
+ }
self.config_default_values = {
'format_string':
@@ -50,36 +58,46 @@ class NowListenPlugin(GajimPlugin):
self.available_text = _('Plugin only available for Linux')
self.activatable = False
- self._event_ids = {}
-
- def _on_connect_chat_control(self, control):
- signal_id = control.msg_textview.connect('key-press-event',
- self._on_insert)
- self._event_ids[control.control_id] = signal_id
-
- def _on_disconnect_chat_control(self, control):
- signal_id = self._event_ids.pop(control.control_id)
- if GObject.signal_handler_is_connected(control.msg_textview, signal_id):
- control.msg_textview.disconnect(signal_id)
-
- def _get_tune_string(self, info):
- format_string = self.config['format_string']
- tune_string = format_string.\
- replace('%artist', info.artist or '').\
- replace('%title', info.title or '')
+ self._signal_id = None
+ self._message_input = None
+
+ def deactivate(self) -> None:
+ assert self._message_input is not None
+ assert self._signal_id is not None
+ if GObject.signal_handler_is_connected(
+ self._message_input, self._signal_id):
+ self._message_input.disconnect(self._signal_id)
+
+ def _on_message_input_created(self,
+ message_input: MessageInputTextView
+ ) -> None:
+
+ self._message_input = message_input
+ self._signal_id = message_input.connect(
+ 'key-press-event', self._on_key_press)
+
+ def _get_tune_string(self, info: TuneData) -> str:
+ format_string = cast(str, self.config['format_string'])
+ tune_string = format_string.replace(
+ '%artist', info.artist or '').replace(
+ '%title', info.title or '')
return tune_string
- def _on_insert(self, textview, event):
+ def _on_key_press(self,
+ textview: MessageInputTextView,
+ event: Gdk.EventKey
+ ) -> bool:
+
# Insert text to message input box, at cursor position
if event.keyval != Gdk.KEY_n:
- return
+ return False
if not event.state & Gdk.ModifierType.MOD1_MASK: # ALT+N
- return
+ return False
info = MusicTrackListener.get().current_tune
if info is None:
log.info('No current tune available')
- return
+ return False
tune_string = self._get_tune_string(info)
diff --git a/now_listen/plugin-manifest.json b/now_listen/plugin-manifest.json
index 7508fd4..ed9a203 100644
--- a/now_listen/plugin-manifest.json
+++ b/now_listen/plugin-manifest.json
@@ -10,8 +10,8 @@
"others"
],
"requirements": [
- "gajim>=1.4.0"
+ "gajim>=1.5.0"
],
"short_name": "now_listen",
- "version": "1.4.1"
+ "version": "1.4.2"
} \ No newline at end of file