[gnome-music/wip/jfelder/lastfm-ui-part-2: 5/7] lastfmdialog: Add a dialog to configure a Last.fm account



commit 2df05c04dedd1b11736d8e14e0f76776bf89f4f2
Author: Jean Felder <jfelder src gnome org>
Date:   Tue Jan 14 21:21:39 2020 +0100

    lastfmdialog: Add a dialog to configure a Last.fm account

 data/org.gnome.Music.css           |  5 +++
 data/org.gnome.Music.gresource.xml |  1 +
 data/ui/LastfmDialog.ui            | 69 ++++++++++++++++++++++++++++++++++
 gnomemusic/widgets/lastfmdialog.py | 77 ++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                     |  2 +
 5 files changed, 154 insertions(+)
---
diff --git a/data/org.gnome.Music.css b/data/org.gnome.Music.css
index ee821f79..617c8650 100644
--- a/data/org.gnome.Music.css
+++ b/data/org.gnome.Music.css
@@ -177,3 +177,8 @@ padding: 0px;
 .drag-handle:backdrop {
   color: alpha(@theme_unfocused_fg_color, 0.4);
 }
+
+/* Last.fm dialog */
+.lastfm-status-label {
+    font-weight: bold;
+}
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 80ea92f9..9d3cceb2 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -17,6 +17,7 @@
     <file preprocess="xml-stripblanks">ui/EmptyView.ui</file>
     <file preprocess="xml-stripblanks">ui/FilterView.ui</file>
     <file preprocess="xml-stripblanks">ui/HeaderBar.ui</file>
+    <file preprocess="xml-stripblanks">ui/LastfmDialog.ui</file>
     <file preprocess="xml-stripblanks">ui/PlayerToolbar.ui</file>
     <file preprocess="xml-stripblanks">ui/PlaylistContextMenu.ui</file>
     <file preprocess="xml-stripblanks">ui/PlaylistControls.ui</file>
diff --git a/data/ui/LastfmDialog.ui b/data/ui/LastfmDialog.ui
new file mode 100644
index 00000000..ac322d2a
--- /dev/null
+++ b/data/ui/LastfmDialog.ui
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="LastfmDialog" parent="GtkDialog">
+    <property name="can_focus">False</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="modal">True</property>
+    <property name="resizable">False</property>
+    <property name="title" translatable="yes">Last.fm Account</property>
+    <property name="type_hint">dialog</property>
+    <property name="valign">start</property>
+    <property name="window_position">center-on-parent</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="margin">16</property>
+        <property name="orientation">vertical</property>
+        <property name="valign">start</property>
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkLabel" id="introduction_label">
+            <property name="halign">start</property>
+            <property name="label" translatable="yes">Last.fm is a music discovery service that gives you 
personalised recommendations based on the music you listen to.</property>
+            <property name="margin_bottom">16</property>
+            <property name="visible">True</property>
+            <property name="max_width_chars">60</property>
+            <property name="wrap">True</property>
+            <property name="xalign">0</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="_status_label">
+            <property name="halign">start</property>
+            <property name="label" translatable="yes">Music Reporting Not Setup</property>
+            <property name="margin_bottom">8</property>
+            <property name="visible">True</property>
+            <property name="max_width_chars">60</property>
+            <property name="wrap">True</property>
+            <property name="xalign">0</property>
+            <style>
+              <class name="lastfm-status-label"/>
+            </style>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="_action_label">
+            <property name="halign">start</property>
+            <property name="label" translatable="yes">Login to your Last.fm account to report your music 
listening.</property>
+            <property name="margin_bottom">12</property>
+            <property name="visible">True</property>
+            <property name="max_width_chars">60</property>
+            <property name="wrap">True</property>
+            <property name="xalign">0</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkButton" id="_action_button">
+            <property name="halign">start</property>
+            <property name="label" translatable="yes">Login</property>
+            <property name="margin_bottom">8</property>
+            <property name="visible">True</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+  <object class="GtkGestureMultiPress" id="_action_button_gesture">
+    <property name="widget">_action_button</property>
+    <signal name="released" handler="_on_action_button_clicked" swapped="no"/>
+  </object>
+</interface>
diff --git a/gnomemusic/widgets/lastfmdialog.py b/gnomemusic/widgets/lastfmdialog.py
new file mode 100644
index 00000000..5ba22656
--- /dev/null
+++ b/gnomemusic/widgets/lastfmdialog.py
@@ -0,0 +1,77 @@
+# Copyright 2020 The GNOME Music Developers
+#
+# GNOME Music is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# GNOME Music is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with GNOME Music; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# The GNOME Music authors hereby grant permission for non-GPL compatible
+# GStreamer plugins to be used and distributed together with GStreamer
+# and GNOME Music.  This permission is above and beyond the permissions
+# granted by the GPL license by which GNOME Music is covered.  If you
+# modify this code, you may extend this exception to your version of the
+# code, but you are not obligated to do so.  If you do not wish to do so,
+# delete this exception statement from your version.
+
+from gettext import gettext as _
+
+from gi.repository import Gtk
+
+from gnomemusic.scrobbler import GoaLastFM
+
+
+@Gtk.Template(resource_path="/org/gnome/Music/ui/LastfmDialog.ui")
+class LastfmDialog(Gtk.Dialog):
+    """Dialog to configure a Last.fm account"""
+
+    __gtype_name__ = "LastfmDialog"
+
+    _action_button = Gtk.Template.Child()
+    _action_button_gesture = Gtk.Template.Child()
+    _action_label = Gtk.Template.Child()
+    _status_label = Gtk.Template.Child()
+
+    def __init__(self, parent, lastfm_scrobbler):
+        super().__init__()
+
+        self.props.transient_for = parent
+        self._lastfm_scrobbler = lastfm_scrobbler
+        self._lastfm_scrobbler.connect(
+            "notify::account-state", self._on_account_state_changed)
+        self._update_view()
+
+    def _on_account_state_changed(self, klass, value):
+        self._update_view()
+
+    def _update_view(self):
+        account_state = self._lastfm_scrobbler.props.account_state
+        if account_state == GoaLastFM.State.NOT_CONFIGURED:
+            self._status_label.props.label = _("Music Reporting Not Setup")
+            self._action_button.props.label = _("Login")
+            self._action_label.props.label = _(
+                "Login to your Last.fm account to report your music listening.")  # noqa: E501
+            return
+
+        if self._lastfm_scrobbler.can_scrobble is True:
+            action = _("Your music listening is reported to Last.fm.")
+        else:
+            action = _("Your music listening is not reported to Last.fm.")
+
+        identity = self._lastfm_scrobbler.props.identity
+        # TRANSLATORS: displays the username of the Last.fm account
+        self._status_label.props.label = _("Logged in as {}").format(identity)
+        self._action_button.props.label = _("Configure")
+        self._action_label.props.label = action
+
+    @Gtk.Template.Callback()
+    def _on_action_button_clicked(self, widget, n_press, x, y):
+        self._lastfm_scrobbler.configure()
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2df13b28..337ac20b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,6 +8,7 @@ data/ui/AlbumWidget.ui
 data/ui/AppMenu.ui
 data/ui/HeaderBar.ui
 data/ui/help-overlay.ui
+data/ui/LastfmDialog.ui
 data/ui/PlayerToolbar.ui
 data/ui/PlaylistContextMenu.ui
 data/ui/PlaylistControls.ui
@@ -34,6 +35,7 @@ gnomemusic/widgets/albumwidget.py
 gnomemusic/widgets/artistalbumwidget.py
 gnomemusic/widgets/disclistboxwidget.py
 gnomemusic/widgets/headerbar.py
+gnomemusic/widgets/lastfmdialog.py
 gnomemusic/widgets/notificationspopup.py
 gnomemusic/widgets/playertoolbar.py
 gnomemusic/widgets/playlistcontrols.py


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]