[gnome-music/wip/jfelder/open-audio-files: 120/120] application: Handle files opening




commit 35dc6267a9209af4cbd4068d635094615e27c17e
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Dec 3 16:36:40 2021 +0100

    application: Handle files opening
    
    This allows to display a FilesView populated with the audio files
    received from command line. In that event, the FilesView is displayed
    instead of the AlbumsView.
    
    Closes: https://gitlab.gnome.org/GNOME/gnome-music/-/issues/268

 data/org.gnome.Music.desktop.in.in | 3 ++-
 gnomemusic/application.py          | 7 ++++++-
 gnomemusic/window.py               | 6 +++++-
 3 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/data/org.gnome.Music.desktop.in.in b/data/org.gnome.Music.desktop.in.in
index 62dfd398b..601ebe9ee 100644
--- a/data/org.gnome.Music.desktop.in.in
+++ b/data/org.gnome.Music.desktop.in.in
@@ -4,10 +4,11 @@ GenericName=Music Player
 Comment=Play and organize your music collection
 # Translators: Do NOT translate or transliterate this text (this is an icon file name)!
 Icon=@icon@
-Exec=gnome-music
+Exec=gnome-music %U
 Terminal=false
 Type=Application
 Categories=GNOME;GTK;AudioVideo;Player;Audio;
 # Translators: Search terms to find this application. Do NOT translate or localize the semicolons! The list 
MUST also end with a semicolon!
 Keywords=Music;Player;
 StartupNotify=true
+MimeType=application/ogg;application/x-ogg;application/x-ogm-audio;audio/aac;audio/mp4;audio/mpeg;audio/mpegurl;audio/ogg;audio/vnd.rn-realaudio;audio/vorbis;audio/x-flac;audio/x-mp3;audio/x-mpeg;audio/x-mpegurl;audio/x-ms-wma;audio/x-musepack;audio/x-oggflac;audio/x-pn-realaudio;audio/x-scpls;audio/x-speex;audio/x-vorbis;audio/x-vorbis+ogg;audio/x-wav;x-content/audio-player;audio/x-aac;audio/m4a;audio/x-m4a;audio/mp3;audio/ac3;audio/flac;application/xspf+xml;audio/x-opus+ogg;application/vnd.apple.mpegurl
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index 30ba7606d..49faea38a 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -32,6 +32,7 @@
 
 from typing import Optional
 from gettext import gettext as _
+from typing import List
 
 from gi.repository import Adw, Gtk, Gio, GLib, Gdk, GObject
 
@@ -56,7 +57,7 @@ class Application(Adw.Application):
     def __init__(self, application_id):
         super().__init__(
             application_id=application_id,
-            flags=Gio.ApplicationFlags.FLAGS_NONE)
+            flags=Gio.ApplicationFlags.HANDLES_OPEN)
         self.props.resource_base_path = "/org/gnome/Music"
         GLib.set_application_name(_("Music"))
         GLib.set_prgname(application_id)
@@ -229,6 +230,10 @@ class Application(Adw.Application):
         about.props.transient_for = self._window
         about.present()
 
+    def do_open(self, files: List[Gio.File], n_files: int, hint: str) -> None:
+        self.props.coregrilo.load_files(files)
+        self.do_activate()
+
     def do_startup(self):
         Adw.Application.do_startup(self)
         Adw.StyleManager.get_default().set_color_scheme(
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 3db9d2f72..87bccdbd1 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -259,7 +259,11 @@ class Window(Adw.ApplicationWindow):
 
         # The "visible-child" notification ensures that the AlbumView
         # appears as selected by the stack switcher on launch.
-        self._stack.props.visible_child = self.views[View.ALBUM]
+        if self.views[View.FILES].props.visible:
+            self._stack.props.visible_child = self.views[View.FILES]
+        else:
+            self._stack.props.visible_child = self.views[View.ALBUM]
+
         self._stack.notify("visible-child")
 
         self.views[View.SEARCH].bind_property(


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