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




commit 9eccd0ed8a27ab10caf9d8150d66266b493477be
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 aeb2da9c3..c577cef9b 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(Gtk.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)
@@ -231,6 +232,10 @@ class Application(Gtk.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):
         Gtk.Application.do_startup(self)
         Adw.StyleManager.get_default().set_color_scheme(
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 418327cbc..96ba71434 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]