[now_listen] 1.4.2
This commit is contained in:
committed by
Philipp Hörist
parent
397e093ace
commit
5925b7ed2f
@@ -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 = {}
|
||||
self._signal_id = None
|
||||
self._message_input = None
|
||||
|
||||
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 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_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 _on_message_input_created(self,
|
||||
message_input: MessageInputTextView
|
||||
) -> None:
|
||||
|
||||
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._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)
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
"linux"
|
||||
],
|
||||
"requirements": [
|
||||
"gajim>=1.4.0"
|
||||
"gajim>=1.5.0"
|
||||
],
|
||||
"short_name": "now_listen",
|
||||
"version": "1.4.1"
|
||||
"version": "1.4.2"
|
||||
}
|
||||
Reference in New Issue
Block a user