[gnome-music/wip/jfelder/songeditor-gtk4: 23/32] notificationspopup: Add support for tag notification




commit 6a4459f4a301c5a446aacf2b1a79c1d9af140702
Author: Sumaid Syed <sumaidsyed gmail com>
Date:   Sun Aug 4 23:22:41 2019 +0530

    notificationspopup: Add support for tag notification
    
    This notification will be used by the tag editor dialogs.
    
    Related: #293

 data/org.gnome.Music.gresource.xml       |  1 +
 data/ui/TagEditorNotification.ui         | 23 ++++++++++
 gnomemusic/widgets/notificationspopup.py | 72 ++++++++++++++++++++++++++++++++
 po/POTFILES.in                           |  1 +
 4 files changed, 97 insertions(+)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index b2de9b6c8..02adcff33 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -37,6 +37,7 @@
     <file preprocess="xml-stripblanks">ui/SongsView.ui</file>
     <file preprocess="xml-stripblanks">ui/SongWidget.ui</file>
     <file preprocess="xml-stripblanks">ui/SongWidgetMenu.ui</file>
+    <file preprocess="xml-stripblanks">ui/TagEditorNotification.ui</file>
     <file preprocess="xml-stripblanks">ui/TwoLineTip.ui</file>
     <file preprocess="xml-stripblanks">ui/Window.ui</file>
   </gresource>
diff --git a/data/ui/TagEditorNotification.ui b/data/ui/TagEditorNotification.ui
new file mode 100644
index 000000000..d44c7e876
--- /dev/null
+++ b/data/ui/TagEditorNotification.ui
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="TagEditorNotification" parent="GtkGrid">
+    <property name="column_spacing">18</property>
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkLabel" id="_label">
+        <property name="visible">True</property>
+        <property name="halign">start</property>
+        <property name="hexpand">True</property>
+        <property name="visible">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkButton" id="_undo_button">
+        <property name="label" translatable="yes">_Undo</property>
+        <property name="use_underline">True</property>
+        <property name="visible">False</property>
+        <signal name="clicked" handler="_undo_clicked" swapped="no"/>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gnomemusic/widgets/notificationspopup.py b/gnomemusic/widgets/notificationspopup.py
index f18e48b66..37f402efd 100644
--- a/gnomemusic/widgets/notificationspopup.py
+++ b/gnomemusic/widgets/notificationspopup.py
@@ -22,6 +22,7 @@
 # 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 __future__ import annotations
 from enum import IntEnum
 from gettext import gettext as _
 from gi.repository import GLib, GObject, Gtk
@@ -251,3 +252,74 @@ class PlaylistNotification(Gtk.Grid):
             self._coregrilo.finish_playlist_deletion(self._playlist, True)
         else:
             self._playlist.finish_song_deletion(self._coresong, self._position)
+
+
+@Gtk.Template(resource_path="/org/gnome/Music/ui/TagEditorNotification.ui")
+class TagEditorNotification(Gtk.Grid):
+    """Show a notification on filling with suggested tags.
+
+    It also provides an option to undo filling fields. Notification is added
+    to the NotificationsPopup.
+    """
+
+    class Type(IntEnum):
+        """Enum for Tag Editor Notifications"""
+        ALBUM = 0
+        SONG = 1
+        NONE = 2
+
+    __gtype_name__ = "TagEditorNotification"
+
+    __gsignals__ = {
+        "finished": (GObject.SignalFlags.RUN_FIRST, None, ()),
+        "undo-fill": (GObject.SignalFlags.RUN_FIRST, None, ()),
+    }
+
+    _label = Gtk.Template.Child()
+    _undo_button = Gtk.Template.Child()
+
+    def __init__(
+            self, notifications_popup: Gtk.Revealer,
+            type_: TagEditorNotification.Type) -> None:
+        """Creates a Tag notification popup (album, song or not found)
+
+        :param GtkRevealer: notifications_popup: the popup object
+        :param enum type_: notification type
+        """
+        super().__init__()
+
+        self._notifications_popup: Gtk.Revealer = notifications_popup
+        self.type_: TagEditorNotification.Type = type_
+
+        self._label.props.label = self._create_notification_message()
+        self._undo_button.props.visible = (
+            self.type_ != TagEditorNotification.Type.NONE)
+
+        self._timeout_id: int = GLib.timeout_add_seconds(
+            5, self._finish)
+
+        self._notifications_popup.add_notification(self)
+
+    def _create_notification_message(self) -> str:
+        if self.type_ == TagEditorNotification.Type.ALBUM:
+            msg: str = _("Album info updated based on online suggestions.")
+        elif self.type_ == TagEditorNotification.Type.SONG:
+            msg = _("Song info updated based on online suggestions.")
+        else:
+            msg = _("No Tags found online for the given media.")
+
+        return msg
+
+    def _finish(self) -> None:
+        self._notifications_popup.remove_notification(self)
+        self.emit("finished")
+
+    @Gtk.Template.Callback()
+    def _undo_clicked(self, widget: Gtk.Button) -> None:
+        """Undo fill and remove notification"""
+        if self._timeout_id > 0:
+            GLib.source_remove(self._timeout_id)
+            self._timeout_id = 0
+
+        self._notifications_popup.remove_notification(self)
+        self.emit("undo-fill")
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 302fb4376..fc291cbd3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -20,6 +20,7 @@ data/ui/SearchView.ui
 data/ui/SelectionBarMenuButton.ui
 data/ui/SelectionToolbar.ui
 data/ui/SongWidgetMenu.ui
+data/ui/TagEditorNotification.ui
 gnomemusic/__init__.py
 gnomemusic/application.py
 gnomemusic/grilowrappers/grltrackerplaylists.py


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