Rockbox Development > Feature Ideas

Exclude a directory from bookmarking

(1/2) > >>

rockbox_dev123:

--- Quote ---Subject: [PATCH] Allow excluding a directory from bookmarking

Long pressing a directory in the file browser will reveal a new 'Set As...' option of 'Bookmark Exclude Directory'.

This patch will not call the bookmarking code if the defined directory is found at the beginning of the path to the currently playing track.

On a disk with the following example directories:
'/Audio books'
'/Podcasts'
'/Music'

One can now easily exclude '/Music' while still keeping bookmarking enabled for all other directories.

--- End quote ---


--- Code: ------ a/apps/gui/wps.c
+++ b/apps/gui/wps.c
@@ -615,7 +615,13 @@ static long do_wps_exit(long action, bool bookmark)
     audio_pause();
     update_non_static();
     if (bookmark)
-        bookmark_autobookmark(true);
+    {
+        if(strncmp(get_wps_state()->id3->path, global_settings.bookmark_exclude_dir,
+        strlen(global_settings.bookmark_exclude_dir)) != 0)
+        {
+            bookmark_autobookmark(true);
+        }
+    }
     audio_stop();
 
     ab_reset_markers();

--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -16573,3 +16573,17 @@
     *: "tracks saved"
   </voice>
 </phrase>
+<phrase>
+  id: LANG_BOOKMARK_EXCLUDE_DIR
+  desc: used in the onplay menu
+  user: core
+  <source>
+    *: "Bookmark Exclude Directory"
+  </source>
+  <dest>
+    *: "Bookmark Exclude Directory"
+  </dest>
+  <voice>
+    *: "Bookmark Exclude Directory"
+  </voice>
+</phrase>

--- a/apps/onplay.c
+++ b/apps/onplay.c
@@ -891,6 +891,15 @@ static bool set_startdir(void)
 MENUITEM_FUNCTION(set_startdir_item, 0, ID2P(LANG_START_DIR),
                   set_startdir, clipboard_callback, Icon_file_view_menu);
 
+static bool set_bookmark_exclude_dir(void)
+{
+    set_dir_helper(global_settings.bookmark_exclude_dir,
+                   sizeof(global_settings.bookmark_exclude_dir));
+    return false;
+}
+MENUITEM_FUNCTION(set_bookmark_exclude_dir_item, 0, ID2P(LANG_BOOKMARK_EXCLUDE_DIR),
+                  set_bookmark_exclude_dir, clipboard_callback, Icon_file_view_menu);
+
 static bool set_catalogdir(void)
 {
     catalog_set_directory(selected_file.path);
@@ -926,7 +935,8 @@ MAKE_ONPLAYMENU(set_as_dir_menu, ID2P(LANG_SET_AS),
 #ifdef HAVE_RECORDING
                 &set_recdir_item,
 #endif
-                &set_startdir_item);
+                &set_startdir_item,
+                &set_bookmark_exclude_dir_item);
 
 static int clipboard_callback(int action,
                               const struct menu_item_ex *this_item,
@@ -983,6 +993,7 @@ static int clipboard_callback(int action,
                     /* only for directories */
                     if (this_item == &delete_dir_item ||
                         this_item == &set_startdir_item ||
+                        this_item == &set_bookmark_exclude_dir_item ||
                         this_item == &set_catalogdir_item ||
 #ifdef HAVE_TAGCACHE
                         this_item == &set_databasedir_item ||

--- a/apps/settings.h
+++ b/apps/settings.h
@@ -867,6 +867,7 @@ struct user_settings
 #endif
 
     char start_directory[MAX_PATHNAME+1];
+    char bookmark_exclude_dir[MAX_PATHNAME+1];
     /* Has the root been customized from the .cfg file? false = no, true = loaded from cfg */
     bool root_menu_customized;
 #ifdef HAVE_QUICKSCREEN

--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -1397,6 +1397,7 @@ const struct settings_list settings[] = {
 #endif /* HAVE_DISK_STORAGE */
     /* browser */
     TEXT_SETTING(0, start_directory, "start directory", "/", NULL, NULL),
+    TEXT_SETTING(0, bookmark_exclude_dir, "bookmark exclude directory", "/Music/", NULL, NULL),
     CHOICE_SETTING(0, dirfilter, LANG_FILTER, SHOW_SUPPORTED, "show files",
                    "all,supported,music,playlists", NULL, 4, ID2P(LANG_ALL),
                    ID2P(LANG_FILTER_SUPPORTED), ID2P(LANG_FILTER_MUSIC),

--- End code ---

The patch file above can be applied (from the rockbox git root) via:

--- Code: ---patch -p1 < patch_file.patch
--- End code ---

rockbox_dev123:
This mostly works correctly.

However if I am playing files from the '/Music' folder via a playlist file which is not itself beneath '/Music' then I assume rockbox is taking the path of the playlist file for the strncmp instead of the path of the currently playing track. This results in a bookmark file for the playlist being created.

Could a dev advise if I be using 'audio_current_track()' instead of 'get_wps_state()' ?

Bilgus:
Not completely sure what you are trying for here

is it that you want to block auto bookmarks for a particular directory or all bookmarks if its in that dir?

anyway maybe you would be better off checking inside bookmark_is_bookmarkable_state() if you can get the resume_info early enough

otherwise you get access to resume_info
via the call to create_bookmark

--- Code: ---static char* create_bookmark(char **name,
                             size_t *namelen,
                             struct resume_info *resume_info)
{
[...]
                             resume_info->id3->
--- End code ---

final thing, if you look at how the db paths are supplied you could probably do something similar, basically a list of dirs separated by ';'  to ignore bookmarking in

rockbox_dev123:

--- Quote from: Bilgus on January 14, 2025, 08:12:19 AM ---Not completely sure what you are trying for here

is it that you want to block auto bookmarks for a particular directory or all bookmarks if its in that dir?

--- End quote ---

I find bookmarks invaluable when listening to audio books. However I never want to bookmark a play through of music.

Another reason is that a close friend who uses a rockbox player I built reported to me that they were selecting tracks in albums and the wrong tracks kept getting played. I realised this was because there were auto bookmark files in the directories from previous listens that were always being started instead of the chosen track. As they also use rockbox for audio books I wanted to disable bookmarking entirely for music.

Thanks for the suggestions. I'll take another look when I finish work.

rockbox_dev123:
I used splashf to print all of the relevant strings in the simulator and sanity check myself.

get_wps_state()->id3->path does indeed return the path to the file being played and not the playlist file.

I think I fixed the issues I was seeing by explicitly checking the return code from strncmp and also by changing the default exclude dir to include a trailing slash.

Navigation

[0] Message Index

[#] Next page

Go to full version