summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-08-05 12:19:58 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-08-05 12:19:58 +0200
commit8acd1b573753efa1e16547637922d4d1ae422b2e (patch)
treeb052d91ac93a11b0c4dac0d0aa63f2c59b5e7e17
parent0300cff32a065303b2687cf151ea4807bdb48929 (diff)
added new %d and %D conversions to pl_format_title, for directory path
-rw-r--r--deadbeef.h4
-rw-r--r--playlist.c47
-rw-r--r--plugins/gtkui/deadbeef.glade3
-rw-r--r--plugins/gtkui/interface.c2
4 files changed, 54 insertions, 2 deletions
diff --git a/deadbeef.h b/deadbeef.h
index 59d62488..1be76844 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -402,6 +402,10 @@ typedef struct {
%c comment
%r copyright
%T tags
+ %f filename without path
+ %F full pathname/uri
+ %d directory without path (e.g. /home/user/file.mp3 -> user)
+ %D directory name with full path (e.g. /home/user/file.mp3 -> /home/user)
more to come
*/
int (*pl_format_title) (DB_playItem_t *it, int idx, char *s, int size, int id, const char *fmt);
diff --git a/playlist.c b/playlist.c
index 802605a3..5446b3f6 100644
--- a/playlist.c
+++ b/playlist.c
@@ -2444,6 +2444,7 @@ pl_format_title_int (const char *escape_chars, playItem_t *it, int idx, char *s,
char elp[50];
char fno[50];
char tags[200];
+ char dirname[PATH_MAX];
const char *duration = NULL;
const char *elapsed = NULL;
@@ -2604,6 +2605,52 @@ pl_format_title_int (const char *escape_chars, playItem_t *it, int idx, char *s,
}
meta = tags;
}
+ else if (*fmt == 'd') {
+ // directory
+ const char *end = it->fname + strlen (it->fname) - 1;
+ while (end > it->fname && (*end) != '/') {
+ end--;
+ }
+ if (*end != '/') {
+ meta = ""; // got relative path without folder (should not happen)
+ }
+ else {
+ const char *start = end;
+ start--;
+ while (start > it->fname && (*start != '/')) {
+ start--;
+ }
+
+ if (*start == '/') {
+ start++;
+ }
+
+ // copy
+ int len = end-start;
+ len = min (len, sizeof (dirname)-1);
+ strncpy (dirname, start, len);
+ dirname[len] = 0;
+ meta = dirname;
+ }
+ }
+ else if (*fmt == 'D') {
+ // directory with path
+ const char *end = it->fname + strlen (it->fname) - 1;
+ while (end > it->fname && (*end) != '/') {
+ end--;
+ }
+ if (*end != '/') {
+ meta = ""; // got relative path without folder (should not happen)
+ }
+ else {
+ // copy
+ int len = end - it->fname;
+ len = min (len, sizeof (dirname)-1);
+ strncpy (dirname, it->fname, len);
+ dirname[len] = 0;
+ meta = dirname;
+ }
+ }
else {
*s++ = *fmt;
n--;
diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade
index 625eccbd..86867974 100644
--- a/plugins/gtkui/deadbeef.glade
+++ b/plugins/gtkui/deadbeef.glade
@@ -2227,7 +2227,8 @@ Right</property>
[a]rtist, [t]itle, al[b]um, [B]and, [C]omposer
track[n]umber, [N]totaltracks,
[l]ength, [y]ear, [g]enre, [c]omment,
- copy[r]ight, [f]ilename, [T]ags
+ copy[r]ight, [f]ilename, [F]ullPathname, [T]ags,
+ [d]irectory, [D]irectoryWithPath
Example: %a - %t [%l]</property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c
index ff747791..41d49496 100644
--- a/plugins/gtkui/interface.c
+++ b/plugins/gtkui/interface.c
@@ -1441,7 +1441,7 @@ create_editcolumndlg (void)
gtk_combo_box_append_text (GTK_COMBO_BOX (align), _("Left"));
gtk_combo_box_append_text (GTK_COMBO_BOX (align), _("Right"));
- label25 = gtk_label_new (_("Format conversions (start with %):\n [a]rtist, [t]itle, al[b]um, [B]and, [C]omposer\n track[n]umber, [N]totaltracks,\n [l]ength, [y]ear, [g]enre, [c]omment,\n copy[r]ight, [f]ilename, [T]ags\nExample: %a - %t [%l]"));
+ label25 = gtk_label_new (_("Format conversions (start with %):\n [a]rtist, [t]itle, al[b]um, [B]and, [C]omposer\n track[n]umber, [N]totaltracks,\n [l]ength, [y]ear, [g]enre, [c]omment,\n copy[r]ight, [f]ilename, [F]ullPathname, [T]ags,\n [d]irectory, [D]irectoryWithPath\nExample: %a - %t [%l]"));
gtk_widget_show (label25);
gtk_box_pack_start (GTK_BOX (vbox14), label25, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (label25, GTK_CAN_FOCUS);