[now_listen] Implement API changes, port config to GTK3, general improvements
This commit is contained in:
@@ -1,51 +1,74 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.20.4 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="2.16"/>
|
<requires lib="gtk+" version="3.0"/>
|
||||||
<!-- interface-naming-policy toplevel-contextual -->
|
<object class="GtkWindow" id="config_window">
|
||||||
<object class="GtkWindow" id="window1">
|
<property name="can_focus">False</property>
|
||||||
|
<property name="title" translatable="yes">Now Listen Configuration</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkVBox" id="now_listen_config_vbox">
|
<object class="GtkBox" id="now_listen_config">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="border_width">9</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">5</property>
|
||||||
|
<property name="margin_right">5</property>
|
||||||
|
<property name="margin_top">5</property>
|
||||||
|
<property name="margin_bottom">5</property>
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="spacing">4</property>
|
<property name="spacing">5</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkHBox" id="hbox1">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">5</property>
|
||||||
|
<property name="margin_right">5</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="spacing">5</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="label1">
|
<object class="GtkLabel" id="label1">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="label" translatable="yes">Format string:</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes"><b>Format string:</b></property>
|
||||||
|
<property name="use_markup">True</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">False</property>
|
<property name="fill">False</property>
|
||||||
<property name="position">0</property>
|
<property name="position">-1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkEntry" id="format_sting">
|
<object class="GtkEntry" id="format_string">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="invisible_char">●</property>
|
<property name="invisible_char">●</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkHBox" id="hbox2">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">5</property>
|
||||||
|
<property name="margin_right">5</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="spacing">5</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="label4">
|
<object class="GtkLabel" id="label2">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="label" translatable="yes">Format string for not local files(MPRIS2 only):</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes"><b>Format string for non-local files (MPRIS2 only):</b></property>
|
||||||
|
<property name="use_markup">True</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
@@ -54,61 +77,81 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkEntry" id="format_sting_http">
|
<object class="GtkEntry" id="format_string_http">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="invisible_char">●</property>
|
<property name="invisible_char">●</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">False</property>
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkFrame" id="frame1">
|
<object class="GtkFrame" id="frame1">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="label_xalign">0</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">5</property>
|
||||||
|
<property name="margin_right">5</property>
|
||||||
|
<property name="margin_top">5</property>
|
||||||
|
<property name="margin_bottom">5</property>
|
||||||
|
<property name="label_xalign">0.05000000074505806</property>
|
||||||
<property name="shadow_type">in</property>
|
<property name="shadow_type">in</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkAlignment" id="alignment1">
|
<object class="GtkAlignment" id="alignment1">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="left_padding">12</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">5</property>
|
||||||
|
<property name="margin_right">5</property>
|
||||||
|
<property name="margin_top">5</property>
|
||||||
|
<property name="margin_bottom">5</property>
|
||||||
|
<property name="top_padding">5</property>
|
||||||
|
<property name="left_padding">15</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="label3">
|
<object class="GtkLabel" id="label4">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="xalign">0</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="yalign">0</property>
|
<property name="label" translatable="yes">%title - title of the track being played
|
||||||
<property name="label" translatable="yes">%title - song name
|
|
||||||
%artist - artist
|
%artist - artist
|
||||||
%album - album
|
%album - album
|
||||||
|
|
||||||
<b>For MPRIS2:</b>
|
<b>For MPRIS2:</b>
|
||||||
%url - the URL of the file. Local files use the file:// schema</property>
|
%url - URL of the file, local files use the file://-schema</property>
|
||||||
<property name="use_markup">True</property>
|
<property name="use_markup">True</property>
|
||||||
|
<property name="xalign">0</property>
|
||||||
|
<property name="yalign">0</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child type="label">
|
<child type="label">
|
||||||
<object class="GtkLabel" id="label2">
|
<object class="GtkLabel" id="label3">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="label" translatable="yes"><b>Legend:</b></property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes"><b>Information:</b></property>
|
||||||
<property name="use_markup">True</property>
|
<property name="use_markup">True</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">True</property>
|
||||||
<property name="fill">False</property>
|
<property name="fill">True</property>
|
||||||
|
<property name="pack_type">end</property>
|
||||||
<property name="position">2</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child type="titlebar">
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</interface>
|
</interface>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from gi.repository import Gdk
|
from gi.repository import Gdk
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
from gajim.plugins import GajimPlugin
|
from gajim.plugins import GajimPlugin
|
||||||
from gajim.plugins.helpers import log_calls
|
from gajim.plugins.helpers import log_calls
|
||||||
@@ -13,25 +14,31 @@ from gajim.common import dbus_support
|
|||||||
if dbus_support.supported:
|
if dbus_support.supported:
|
||||||
from gajim.music_track_listener import MusicTrackListener
|
from gajim.music_track_listener import MusicTrackListener
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger('gajim.plugin_system.now_listen')
|
||||||
|
|
||||||
class NowListenPlugin(GajimPlugin):
|
class NowListenPlugin(GajimPlugin):
|
||||||
|
|
||||||
@log_calls('NowListenPlugin')
|
@log_calls('NowListenPlugin')
|
||||||
def init(self):
|
def init(self):
|
||||||
self.description = _('Copy tune info to conversation input box '
|
self.description = _('Copy tune info of playing music to conversation '
|
||||||
'(alt + n) at cursor position')
|
'input box at cursor position (Alt + N)')
|
||||||
self.config_dialog = NowListenPluginConfigDialog(self)
|
self.config_dialog = NowListenPluginConfigDialog(self)
|
||||||
self.gui_extension_points = {'chat_control_base':
|
self.gui_extension_points = {'chat_control_base':
|
||||||
(self.connect_with_chat_control, self.disconnect_from_chat_control)}
|
(self.connect_with_chat_control,
|
||||||
|
self.disconnect_from_chat_control)}
|
||||||
|
|
||||||
self.config_default_values = {
|
self.config_default_values = {
|
||||||
'format_string': ('Now listen:"%title" by %artist from %album', ''),
|
'format_string':
|
||||||
'format_string_http': ('Now listen:"%title" by %artist', ''),}
|
(_('Now listening to: "%title" by %artist from %album'), ''),
|
||||||
|
'format_string_http':
|
||||||
|
(_('Now listening to: "%title" by %artist'), ''),}
|
||||||
|
|
||||||
self.controls = []
|
self.controls = []
|
||||||
self.first_run = True
|
self.first_run = True
|
||||||
self.music_track_changed_signal = None
|
self.music_track_changed_signal = None
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
self.available_text = _('Plugin can\'t be run under Windows.')
|
self.available_text = _('Plugin cannot be run under Windows.')
|
||||||
self.activatable = False
|
self.activatable = False
|
||||||
|
|
||||||
@log_calls('NowListenPlugin')
|
@log_calls('NowListenPlugin')
|
||||||
@@ -54,7 +61,7 @@ class NowListenPlugin(GajimPlugin):
|
|||||||
if not self.music_track_changed_signal:
|
if not self.music_track_changed_signal:
|
||||||
self.music_track_changed_signal = listener.connect(
|
self.music_track_changed_signal = listener.connect(
|
||||||
'music-track-changed', self.music_track_changed)
|
'music-track-changed', self.music_track_changed)
|
||||||
track = listener.get_playing_track()
|
track = listener.get_playing_track('org.mpris.MediaPlayer2')
|
||||||
self.music_track_changed(listener, track)
|
self.music_track_changed(listener, track)
|
||||||
|
|
||||||
@log_calls('NowListenPlugin')
|
@log_calls('NowListenPlugin')
|
||||||
@@ -66,15 +73,15 @@ class NowListenPlugin(GajimPlugin):
|
|||||||
self.music_track_changed_signal = None
|
self.music_track_changed_signal = None
|
||||||
|
|
||||||
def music_track_changed(self, unused_listener, music_track_info,
|
def music_track_changed(self, unused_listener, music_track_info,
|
||||||
account=None):
|
account=None):
|
||||||
is_paused = hasattr(music_track_info, 'paused') and \
|
|
||||||
music_track_info.paused == 0
|
if music_track_info is None or music_track_info.paused:
|
||||||
if not music_track_info or is_paused:
|
artist = title = album = ''
|
||||||
self.artist = self.title = self.source = ''
|
|
||||||
else:
|
else:
|
||||||
self.artist = music_track_info.artist
|
self.artist = music_track_info.artist
|
||||||
self.title = music_track_info.title
|
self.title = music_track_info.title
|
||||||
self.source = music_track_info.album
|
self.album = music_track_info.album
|
||||||
|
log.debug(self.artist + " - " + self.title)
|
||||||
if hasattr(music_track_info, 'url'):
|
if hasattr(music_track_info, 'url'):
|
||||||
self.url = music_track_info.url
|
self.url = music_track_info.url
|
||||||
self.albumartist = music_track_info.albumartist
|
self.albumartist = music_track_info.albumartist
|
||||||
@@ -86,11 +93,12 @@ class Base(object):
|
|||||||
def __init__(self, plugin, chat_control):
|
def __init__(self, plugin, chat_control):
|
||||||
self.plugin = plugin
|
self.plugin = plugin
|
||||||
self.chat_control = chat_control
|
self.chat_control = chat_control
|
||||||
self.plugin.artist = self.plugin.title = self.plugin.source = ''
|
if not hasattr(self.plugin, 'title'):
|
||||||
|
self.plugin.artist = self.plugin.title = self.plugin.album = ''
|
||||||
self.plugin.url = self.plugin.albumartist = ''
|
self.plugin.url = self.plugin.albumartist = ''
|
||||||
|
|
||||||
self.id_ = self.chat_control.msg_textview.connect('key_press_event',
|
self.id_ = self.chat_control.msg_textview.connect('key_press_event',
|
||||||
self.on_insert)
|
self.on_insert)
|
||||||
self.chat_control.handlers[self.id_] = self.chat_control.msg_textview
|
self.chat_control.handlers[self.id_] = self.chat_control.msg_textview
|
||||||
|
|
||||||
def disconnect_from_chat_control(self):
|
def disconnect_from_chat_control(self):
|
||||||
@@ -109,16 +117,23 @@ class Base(object):
|
|||||||
if not event.state & Gdk.ModifierType.MOD1_MASK: # ALT+N
|
if not event.state & Gdk.ModifierType.MOD1_MASK: # ALT+N
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.plugin.artist == self.plugin.title == self.plugin.source == '':
|
if self.plugin.artist == self.plugin.title == self.plugin.album == '':
|
||||||
tune_string = 'paused or stopped'
|
tune_string = _('No music playing')
|
||||||
else:
|
else:
|
||||||
format_string = self.plugin.config['format_string']
|
format_string = self.plugin.config['format_string']
|
||||||
if self.plugin.url and not self.plugin.url.startswith('file://'):
|
if self.plugin.url and not self.plugin.url.startswith('file://'):
|
||||||
format_string = self.plugin.config['format_string_http']
|
format_string = self.plugin.config['format_string_http']
|
||||||
tune_string = format_string.replace(
|
|
||||||
'%artist', self.plugin.artist).replace(
|
if self.plugin.artist is None:
|
||||||
'%title', self.plugin.title).replace('%album',self.plugin.source).\
|
self.plugin.artist = _('unknown artist')
|
||||||
replace('%url', self.plugin.url)
|
if self.plugin.album is None:
|
||||||
|
self.plugin.album = _('unknown album')
|
||||||
|
|
||||||
|
tune_string = format_string.\
|
||||||
|
replace('%artist', self.plugin.artist).\
|
||||||
|
replace('%title', self.plugin.title).\
|
||||||
|
replace('%album',self.plugin.album).\
|
||||||
|
replace('%url', self.plugin.url)
|
||||||
|
|
||||||
message_buffer = self.chat_control.msg_textview.get_buffer()
|
message_buffer = self.chat_control.msg_textview.get_buffer()
|
||||||
message_buffer.insert_at_cursor(tune_string)
|
message_buffer.insert_at_cursor(tune_string)
|
||||||
@@ -129,24 +144,24 @@ class Base(object):
|
|||||||
class NowListenPluginConfigDialog(GajimPluginConfigDialog):
|
class NowListenPluginConfigDialog(GajimPluginConfigDialog):
|
||||||
def init(self):
|
def init(self):
|
||||||
self.GTK_BUILDER_FILE_PATH = self.plugin.local_file_path(
|
self.GTK_BUILDER_FILE_PATH = self.plugin.local_file_path(
|
||||||
'config_dialog.ui')
|
'config_dialog.ui')
|
||||||
self.xml = Gtk.Builder()
|
self.xml = Gtk.Builder()
|
||||||
self.xml.set_translation_domain('gajim_plugins')
|
self.xml.set_translation_domain('gajim_plugins')
|
||||||
self.xml.add_objects_from_file(self.GTK_BUILDER_FILE_PATH,
|
self.xml.add_objects_from_file(self.GTK_BUILDER_FILE_PATH,
|
||||||
['now_listen_config_vbox'])
|
['now_listen_config'])
|
||||||
|
|
||||||
self.config_vbox = self.xml.get_object('now_listen_config_vbox')
|
self.config_vbox = self.xml.get_object('now_listen_config')
|
||||||
self.get_child().pack_start(self.config_vbox, True, True, 0)
|
self.get_child().pack_start(self.config_vbox, True, True, 0)
|
||||||
|
|
||||||
self.format_sting = self.xml.get_object('format_sting')
|
self.format_string = self.xml.get_object('format_string')
|
||||||
self.format_sting_http = self.xml.get_object('format_sting_http')
|
self.format_string_http = self.xml.get_object('format_string_http')
|
||||||
self.xml.connect_signals(self)
|
self.xml.connect_signals(self)
|
||||||
self.connect('hide', self.on_hide)
|
self.connect('hide', self.on_hide)
|
||||||
|
|
||||||
def on_run(self):
|
def on_run(self):
|
||||||
self.format_sting.set_text(self.plugin.config['format_string'])
|
self.format_string.set_text(self.plugin.config['format_string'])
|
||||||
self.format_sting_http.set_text(self.plugin.config['format_string_http'])
|
self.format_string_http.set_text(self.plugin.config['format_string_http'])
|
||||||
|
|
||||||
def on_hide(self, widget):
|
def on_hide(self, widget):
|
||||||
self.plugin.config['format_string'] = self.format_sting.get_text()
|
self.plugin.config['format_string'] = self.format_string.get_text()
|
||||||
self.plugin.config['format_string_http'] = self.format_sting_http.get_text()
|
self.plugin.config['format_string_http'] = self.format_string_http.get_text()
|
||||||
|
|||||||
Reference in New Issue
Block a user