[gnome-music/wip/jfelder/open-audio-files: 17/18] views: Add a view to handle opened audio files
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/open-audio-files: 17/18] views: Add a view to handle opened audio files
- Date: Tue, 2 Aug 2022 18:20:42 +0000 (UTC)
commit 057237c73edf52efc4e34db1d7c4835de0e235cd
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 | 25 ++++++++++
gnomemusic/utils.py | 1 +
gnomemusic/views/filesview.py | 96 ++++++++++++++++++++++++++++++++++++++
gnomemusic/window.py | 2 +
po/POTFILES.in | 1 +
6 files changed, 126 insertions(+)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 2be39220b..d9eb327d1 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -16,6 +16,7 @@
<file preprocess="xml-stripblanks">ui/ArtistTile.ui</file>
<file preprocess="xml-stripblanks">ui/DiscBox.ui</file>
<file preprocess="xml-stripblanks">ui/EmptyView.ui</file>
+ <file preprocess="xml-stripblanks">ui/FilesView.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>
diff --git a/data/ui/FilesView.ui b/data/ui/FilesView.ui
new file mode 100644
index 000000000..953ad6e92
--- /dev/null
+++ b/data/ui/FilesView.ui
@@ -0,0 +1,25 @@
+<?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="AdwClamp">
+ <property name="maximum-size">1000</property>
+ <child>
+ <object class="GtkListBox" id="_list_box">
+ <property name="valign">start</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="boxed-list"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/gnomemusic/utils.py b/gnomemusic/utils.py
index 077859053..77662c212 100644
--- a/gnomemusic/utils.py
+++ b/gnomemusic/utils.py
@@ -72,6 +72,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..279e904ae
--- /dev/null
+++ b/gnomemusic/views/filesview.py
@@ -0,0 +1,96 @@
+# 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 __future__ import annotations
+import typing
+
+from gettext import gettext as _
+
+from gi.repository import Gio, GObject, Gtk
+
+from gnomemusic.coresong import CoreSong
+from gnomemusic.widgets.songwidget import SongWidget
+if typing.TYPE_CHECKING:
+ from gnomemusic.application import Application
+
+
+@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: 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 93f1b27d6..3db9d2f72 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -35,6 +35,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(Adw.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 2c2cbc253..db88d6085 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]