Commit f6dc4d37 authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist

[now_listen] Implement API changes, port config to GTK3, general improvements

parent d5453669
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.4 -->
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy toplevel-contextual -->
<object class="GtkWindow" id="window1">
<requires lib="gtk+" version="3.0"/>
<object class="GtkWindow" id="config_window">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Now Listen Configuration</property>
<child>
<object class="GtkVBox" id="now_listen_config_vbox">
<object class="GtkBox" id="now_listen_config">
<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="spacing">4</property>
<property name="spacing">5</property>
<child>
<object class="GtkHBox" id="hbox1">
<object class="GtkBox">
<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>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">Format string:</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Format string:&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
<property name="position">-1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="format_sting">
<object class="GtkEntry" id="format_string">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
<property name="invisible_char"></property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox2">
<object class="GtkBox">
<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>
<object class="GtkLabel" id="label4">
<object class="GtkLabel" id="label2">
<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">&lt;b&gt;Format string for non-local files (MPRIS2 only):&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
......@@ -54,61 +77,81 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="format_sting_http">
<object class="GtkEntry" id="format_string_http">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
<property name="invisible_char"></property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame1">
<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>
<child>
<object class="GtkAlignment" id="alignment1">
<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>
<object class="GtkLabel" id="label3">
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="label" translatable="yes">%title - song name
<property name="can_focus">False</property>
<property name="label" translatable="yes">%title - title of the track being played
%artist - artist
%album - album
&lt;b&gt;For MPRIS2:&lt;/b&gt;
%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="xalign">0</property>
<property name="yalign">0</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label2">
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Legend:&lt;/b&gt;</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Information:&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</object>
</interface>
......@@ -3,6 +3,7 @@
from gi.repository import Gtk
from gi.repository import Gdk
import os
import logging
from gajim.plugins import GajimPlugin
from gajim.plugins.helpers import log_calls
......@@ -13,25 +14,31 @@ from gajim.common import dbus_support
if dbus_support.supported:
from gajim.music_track_listener import MusicTrackListener
log = logging.getLogger('gajim.plugin_system.now_listen')
class NowListenPlugin(GajimPlugin):
@log_calls('NowListenPlugin')
def init(self):
self.description = _('Copy tune info to conversation input box '
'(alt + n) at cursor position')
self.description = _('Copy tune info of playing music to conversation '
'input box at cursor position (Alt + N)')
self.config_dialog = NowListenPluginConfigDialog(self)
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 = {
'format_string': ('Now listen:"%title" by %artist from %album', ''),
'format_string_http': ('Now listen:"%title" by %artist', ''),}
'format_string':
(_('Now listening to: "%title" by %artist from %album'), ''),
'format_string_http':
(_('Now listening to: "%title" by %artist'), ''),}
self.controls = []
self.first_run = True
self.music_track_changed_signal = None
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
@log_calls('NowListenPlugin')
......@@ -54,7 +61,7 @@ class NowListenPlugin(GajimPlugin):
if not self.music_track_changed_signal:
self.music_track_changed_signal = listener.connect(
'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)
@log_calls('NowListenPlugin')
......@@ -66,15 +73,15 @@ class NowListenPlugin(GajimPlugin):
self.music_track_changed_signal = None
def music_track_changed(self, unused_listener, music_track_info,
account=None):
is_paused = hasattr(music_track_info, 'paused') and \
music_track_info.paused == 0
if not music_track_info or is_paused:
self.artist = self.title = self.source = ''
account=None):
if music_track_info is None or music_track_info.paused:
artist = title = album = ''
else:
self.artist = music_track_info.artist
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'):
self.url = music_track_info.url
self.albumartist = music_track_info.albumartist
......@@ -86,11 +93,12 @@ class Base(object):
def __init__(self, plugin, chat_control):
self.plugin = plugin
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.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
def disconnect_from_chat_control(self):
......@@ -109,16 +117,23 @@ class Base(object):
if not event.state & Gdk.ModifierType.MOD1_MASK: # ALT+N
return
if self.plugin.artist == self.plugin.title == self.plugin.source == '':
tune_string = 'paused or stopped'
if self.plugin.artist == self.plugin.title == self.plugin.album == '':
tune_string = _('No music playing')
else:
format_string = self.plugin.config['format_string']
if self.plugin.url and not self.plugin.url.startswith('file://'):
format_string = self.plugin.config['format_string_http']
tune_string = format_string.replace(
'%artist', self.plugin.artist).replace(
'%title', self.plugin.title).replace('%album',self.plugin.source).\
replace('%url', self.plugin.url)
if self.plugin.artist is None:
self.plugin.artist = _('unknown artist')
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.insert_at_cursor(tune_string)
......@@ -129,24 +144,24 @@ class Base(object):
class NowListenPluginConfigDialog(GajimPluginConfigDialog):
def init(self):
self.GTK_BUILDER_FILE_PATH = self.plugin.local_file_path(
'config_dialog.ui')
'config_dialog.ui')
self.xml = Gtk.Builder()
self.xml.set_translation_domain('gajim_plugins')
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.format_sting = self.xml.get_object('format_sting')
self.format_sting_http = self.xml.get_object('format_sting_http')
self.format_string = self.xml.get_object('format_string')
self.format_string_http = self.xml.get_object('format_string_http')
self.xml.connect_signals(self)
self.connect('hide', self.on_hide)
def on_run(self):
self.format_sting.set_text(self.plugin.config['format_string'])
self.format_sting_http.set_text(self.plugin.config['format_string_http'])
self.format_string.set_text(self.plugin.config['format_string'])
self.format_string_http.set_text(self.plugin.config['format_string_http'])
def on_hide(self, widget):
self.plugin.config['format_string'] = self.format_sting.get_text()
self.plugin.config['format_string_http'] = self.format_sting_http.get_text()
self.plugin.config['format_string'] = self.format_string.get_text()
self.plugin.config['format_string_http'] = self.format_string_http.get_text()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment