[gnome-music/wip/jfelder/open-audio-files: 4/6] views: Add a view to handle opened audio files




commit 89a7ffb43d63de39e5127713aa9a75181886b506
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Dec 3 16:36:13 2021 +0100

    views: Add a view to handle opened audio files
    
    It is not used yet. Its support will be added in the next commit
    This view is only visible if some audio files have been received from
    command line.

 data/org.gnome.Music.gresource.xml |  1 +
 data/ui/FilesView.ui               | 26 +++++++++++
 gnomemusic/utils.py                |  1 +
 gnomemusic/views/filesview.py      | 91 ++++++++++++++++++++++++++++++++++++++
 gnomemusic/window.py               |  2 +
 po/POTFILES.in                     |  1 +
 6 files changed, 122 insertions(+)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 5ea55cddb..02101d53c 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -17,6 +17,7 @@
     <file preprocess="xml-stripblanks">ui/DiscBox.ui</file>
     <file preprocess="xml-stripblanks">ui/DropDown.ui</file>
     <file preprocess="xml-stripblanks">ui/EmptyView.ui</file>
+    <file preprocess="xml-stripblanks">ui/FilesView.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>
diff --git a/data/ui/FilesView.ui b/data/ui/FilesView.ui
new file mode 100644
index 000000000..7b855e87b
--- /dev/null
+++ b/data/ui/FilesView.ui
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="FilesView" parent="GtkScrolledWindow">
+    <property name="hexpand">True</property>
+    <property name="vexpand">True</property>
+    <property name="visible">False</property>
+    <child>
+      <object class="HdyClamp">
+        <property name="maximum-size">1000</property>
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkListBox" id="_list_box">
+            <property name="visible">True</property>
+            <property name="selection_mode">none</property>
+            <property name="margin-bottom">48</property>
+            <property name="margin-top">48</property>
+            <signal name="row-activated" handler="_song_activated" swapped="no"/>
+            <style>
+              <class name="content"/>
+            </style>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gnomemusic/utils.py b/gnomemusic/utils.py
index 5d3262a00..c3a7bcea6 100644
--- a/gnomemusic/utils.py
+++ b/gnomemusic/utils.py
@@ -60,6 +60,7 @@ class View(IntEnum):
     SONG = 3
     PLAYLIST = 4
     SEARCH = 5
+    FILES = 6
 
 
 def get_album_title(item):
diff --git a/gnomemusic/views/filesview.py b/gnomemusic/views/filesview.py
new file mode 100644
index 000000000..8d002897b
--- /dev/null
+++ b/gnomemusic/views/filesview.py
@@ -0,0 +1,91 @@
+# Copyright 2022 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 Gio, GObject, Gtk
+
+from gnomemusic.coresong import CoreSong
+from gnomemusic.widgets.songwidget import SongWidget
+
+
+@Gtk.Template(resource_path="/org/gnome/Music/ui/FilesView.ui")
+class FilesView(Gtk.ScrolledWindow):
+    """Main view of all songs sorted artistwise
+
+    Consists all songs along with songname, star, length, artist
+    and the album name.
+    """
+
+    __gtype_name__ = "FilesView"
+
+    icon_name = GObject.Property(
+        type=str, default="folder-symbolic",
+        flags=GObject.ParamFlags.READABLE)
+    title = GObject.Property(
+        type=str, default=_("Files"), flags=GObject.ParamFlags.READABLE)
+
+    _list_box = Gtk.Template.Child()
+
+    def __init__(self, application):
+        """Initialize
+
+        :param GtkApplication window: The application object
+        """
+        super().__init__()
+
+        self.props.name = "files"
+
+        self._player = application.props.player
+
+        self._coremodel = application.props.coremodel
+        self._files_model = self._coremodel.props.files
+        self._list_box.bind_model(self._files_model, self._create_widget)
+
+        self._files_model.connect(
+            "items-changed", self._on_files_model_items_changed)
+        self._on_files_model_items_changed(self._files_model, 0, 0, 0)
+
+    def _create_widget(self, coresong: CoreSong) -> SongWidget:
+        song_widget = SongWidget(coresong, show_artist_and_album=True)
+        song_widget.props.show_song_number = False
+        return song_widget
+
+    def _on_files_model_items_changed(
+            self, model: Gio.ListStore, pos: int, removed: int,
+            added: int) -> None:
+        self.props.visible = model.get_n_items() > 0
+
+    @Gtk.Template.Callback()
+    def _song_activated(
+            self, widget: Gtk.Widget, song_widget: SongWidget) -> None:
+        signal_id = 0
+
+        def _on_playlist_loaded(klass, playlist_type):
+            self._player.play(song_widget.props.coresong)
+            self._coremodel.disconnect(signal_id)
+
+        signal_id = self._coremodel.connect(
+            "playlist-loaded", _on_playlist_loaded)
+        self._coremodel.props.active_core_object = song_widget.props.coresong
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 846e3b812..1d8005ac9 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -34,6 +34,7 @@ from gnomemusic.utils import View
 from gnomemusic.views.albumsview import AlbumsView
 from gnomemusic.views.artistsview import ArtistsView
 from gnomemusic.views.emptyview import EmptyView
+from gnomemusic.views.filesview import FilesView
 from gnomemusic.views.searchview import SearchView
 from gnomemusic.views.songsview import SongsView
 from gnomemusic.views.playlistsview import PlaylistsView
@@ -242,6 +243,7 @@ class Window(Handy.ApplicationWindow):
         self.views[View.SONG] = SongsView(self._app)
         self.views[View.PLAYLIST] = PlaylistsView(self._app)
         self.views[View.SEARCH] = SearchView(self._app)
+        self.views[View.FILES] = FilesView(self._app)
 
         # empty view has already been created in self._setup_view starting at
         # View.ALBUM
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6cd6fab51..1af96bef7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -31,6 +31,7 @@ gnomemusic/utils.py
 gnomemusic/views/albumsview.py
 gnomemusic/views/artistsview.py
 gnomemusic/views/emptyview.py
+gnomemusic/views/filesview.py
 gnomemusic/views/playlistsview.py
 gnomemusic/views/searchview.py
 gnomemusic/views/songsview.py


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