[gnome-music/gnome-3-14] view: show No Music view if XDG user dirs are not set



commit 7b072bd97f365b3f33c5192753844d2dcde849f2
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Tue Jan 6 12:10:39 2015 +0100

    view: show No Music view if XDG user dirs are not set
    
    https://bugzilla.gnome.org/show_bug.cgi?id=731613

 gnomemusic/query.py  |   18 ++++++++++++------
 gnomemusic/window.py |   29 +++++++++++++++++------------
 2 files changed, 29 insertions(+), 18 deletions(-)
---
diff --git a/gnomemusic/query.py b/gnomemusic/query.py
index 0e33119..f872414 100644
--- a/gnomemusic/query.py
+++ b/gnomemusic/query.py
@@ -29,12 +29,18 @@ from gi.repository import GLib, Tracker
 
 
 class Query():
-    MUSIC_DIR = Tracker.sparql_escape_string(GLib.filename_to_uri(
-        GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_MUSIC)
-    ))
-    DOWNLOAD_DIR = Tracker.sparql_escape_string(GLib.filename_to_uri(
-        GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DOWNLOAD)
-    ))
+    music_folder = None
+    MUSIC_URI = None
+    download_folder = None
+    DOWNLOAD_URI = None
+    try:
+        music_folder = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_MUSIC)
+        MUSIC_URI = Tracker.sparql_escape_string(GLib.filename_to_uri(music_folder))
+        download_folder = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DOWNLOAD)
+        DOWNLOAD_URI = Tracker.sparql_escape_string(GLib.filename_to_uri(download_folder))
+
+    except TypeError:
+        print("XDG user dirs are not set")
 
     @staticmethod
     def all_albums():
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 760895b..b691288 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -197,20 +197,25 @@ class Window(Gtk.ApplicationWindow):
         self.add(self._box)
         count = 1
         cursor = None
-        try:
-            cursor = tracker.query(Query.all_songs_count(), None)
-        except Exception as e:
-            logger.error("Tracker query crashed: %s" % e)
-            count = 0
 
-        if cursor is not None and cursor.next(None):
-            count = cursor.get_integer(0)
-        if count > 0:
-            self._switch_to_player_view()
-        # To revert to the No Music View when no songs are found
+        if Query.music_folder and Query.download_folder:
+            try:
+                cursor = tracker.query(Query.all_songs_count(), None)
+            except Exception as e:
+                logger.error("Tracker query crashed: %s" % e)
+                count = 0
+
+            if cursor is not None and cursor.next(None):
+                count = cursor.get_integer(0)
+            if count > 0:
+                self._switch_to_player_view()
+            # To revert to the No Music View when no songs are found
+            else:
+                if self.toolbar._selectionMode is False:
+                    self._switch_to_empty_view()
         else:
-            if self.toolbar._selectionMode is False:
-                self._switch_to_empty_view()
+            # Revert to No Music view if XDG dirs are not set
+            self._switch_to_empty_view()
 
         self.toolbar._search_button.connect('toggled', self._on_search_toggled)
         self.toolbar.connect('selection-mode-changed', self._on_selection_mode_changed)


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