From dabcb81e1380aeab8e50a64efcc1dc4a59145094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Wallm=C3=A9nius?= Date: Thu, 1 May 2008 10:13:12 +0000 Subject: [PATCH] Introduce a small helper function that asks the user if the dynamic playlist should be erased to increase code re-use git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17295 a1c6a512-1295-4272-9138-f99709370657 --- apps/filetree.c | 24 +++++------------------- apps/misc.c | 20 ++++++++++++++++++++ apps/misc.h | 4 ++++ apps/tagtree.c | 12 ++---------- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/apps/filetree.c b/apps/filetree.c index dd541fe0a2..64a12b5050 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -42,6 +42,7 @@ #include "yesno.h" #include "cuesheet.h" #include "filetree.h" +#include "misc.h" #ifdef HAVE_LCD_BITMAP #include "keyboard.h" #endif @@ -102,15 +103,8 @@ bool ft_play_playlist(char* pathname, char* dirname, char* filename) /* about to create a new current playlist... allow user to cancel the operation */ - if (global_settings.warnon_erase_dynplaylist && - playlist_modified(NULL)) - { - const char *lines[] = {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT)}; - struct text_message message = {lines, 1}; - - if (gui_syncyesno_run(&message, NULL, NULL) != YESNO_YES) - return false; - } + if (!warn_on_pl_erase()) + return false; if (playlist_create(dirname, filename) != -1) { @@ -405,16 +399,8 @@ int ft_enter(struct tree_context* c) /* about to create a new current playlist... allow user to cancel the operation */ - if (global_settings.warnon_erase_dynplaylist && - !global_settings.party_mode && - playlist_modified(NULL)) - { - static const char *lines[]={ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT)}; - static const struct text_message message={lines, 1}; - - if(gui_syncyesno_run(&message, NULL, NULL) != YESNO_YES) - break; - } + if (!warn_on_pl_erase()) + break; if (global_settings.party_mode) { diff --git a/apps/misc.c b/apps/misc.c index c97b9cf0f3..23341a82e8 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -50,6 +50,8 @@ #include "tagcache.h" #include "scrobbler.h" #include "sound.h" +#include "playlist.h" +#include "yesno.h" #ifdef HAVE_MMC #include "ata_mmc.h" @@ -244,6 +246,24 @@ char *create_datetime_filename(char *buffer, const char *path, } #endif /* CONFIG_RTC */ +/* Ask the user if they really want to erase the current dynamic playlist + * returns true if the playlist should be replaced */ +bool warn_on_pl_erase(void) +{ + if (global_settings.warnon_erase_dynplaylist && + !global_settings.party_mode && + playlist_modified(NULL)) + { + static const char *lines[] = + {ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT)}; + static const struct text_message message={lines, 1}; + + return (gui_syncyesno_run(&message, NULL, NULL) == YESNO_YES); + } + else + return true; +} + /* Read (up to) a line of text from fd into buffer and return number of bytes * read (which may be larger than the number of bytes stored in buffer). If * an error occurs, -1 is returned (and buffer contains whatever could be diff --git a/apps/misc.h b/apps/misc.h index c6a91646b8..4d0226ae51 100644 --- a/apps/misc.h +++ b/apps/misc.h @@ -69,6 +69,10 @@ char *create_datetime_filename(char *buffer, const char *path, bool unique_time); #endif /* CONFIG_RTC */ +/* Ask the user if they really want to erase the current dynamic playlist + * returns true if the playlist should be replaced */ +bool warn_on_pl_erase(void); + /* Read (up to) a line of text from fd into buffer and return number of bytes * read (which may be larger than the number of bytes stored in buffer). If * an error occurs, -1 is returned (and buffer contains whatever could be diff --git a/apps/tagtree.c b/apps/tagtree.c index 627cad3817..3562a48a5a 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -1497,16 +1497,8 @@ int tagtree_enter(struct tree_context* c) c->dirlevel--; /* about to create a new current playlist... allow user to cancel the operation */ - if (global_settings.warnon_erase_dynplaylist && - !global_settings.party_mode && - playlist_modified(NULL)) - { - static const char *lines[]={ID2P(LANG_WARN_ERASEDYNPLAYLIST_PROMPT)}; - static const struct text_message message={lines, 1}; - - if (gui_syncyesno_run(&message, NULL, NULL) != YESNO_YES) - break; - } + if (!warn_on_pl_erase()) + break; if (tagtree_play_folder(c) >= 0) rc = 2;