]> git.phdru.name Git - xsetbg.git/commitdiff
Feat: Show only image files
authorOleg Broytman <phd@phdru.name>
Mon, 20 Aug 2018 14:57:21 +0000 (17:57 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 20 Aug 2018 14:57:21 +0000 (17:57 +0300)
xsetbg.py

index 1aea77f28e2493885bdd24929ed0e9d79da47942..68828cf567b5db4c43875df9e5c36b737c02362d 100644 (file)
--- a/xsetbg.py
+++ b/xsetbg.py
@@ -72,13 +72,15 @@ else:
     min_delay = 3600*24  # 24 hours
 
 
-if xsetbg_db.select('last_shown IS NULL OR last_shown < %d' %
-                    (time() - min_delay)).count() == 0:
+if xsetbg_db.select(
+        '(is_image = 1) AND (last_shown IS NULL OR last_shown < %d)' %
+        (time() - min_delay)).count() == 0:
     error("No unshown images found. Run rescan_fs.py "
           "or decrease min_delay. Abort.")
 
 fs_encoding = xsetbg_conf.get("images", "fs_encoding")
 
+
 def change(force=False):
     # Use the program's file as the lock file:
     # lock it to prevent two processes run in parallel.
@@ -91,8 +93,9 @@ def change(force=False):
         return
 
     try:
-        timestamp = xsetbg_db.select('last_shown IS NOT NULL',
-                                     orderBy='-last_shown')[0].last_shown
+        timestamp = xsetbg_db.select(
+            '(is_image = 1) AND (last_shown IS NOT NULL)',
+            orderBy='-last_shown')[0].last_shown
         current_time = time()
 
         if not force and timestamp is not None and \
@@ -101,13 +104,15 @@ def change(force=False):
             return
 
         # Select a random image that has never been shown
-        not_shown_select = xsetbg_db.select('last_shown IS NULL')
+        not_shown_select = xsetbg_db.select(
+            '(is_image = 1) AND (last_shown IS NULL)')
         not_shown_count = not_shown_select.count()
         if not_shown_count:
             row = not_shown_select[random.randint(0, not_shown_count - 1)]
         else:
             old_shown_select = xsetbg_db.select(
-                'last_shown IS NOT NULL AND last_shown < %d' %
+                '(is_image = 1) AND '
+                '(last_shown IS NOT NULL AND last_shown < %d)' %
                 current_time - min_delay)
             old_shown_count = old_shown_select.count()
             if old_shown_count: