annotate libaudacious/titlestring.c @ 1095:dec5caa8768b trunk

[svn] - nevermind
author nenolod
date Sun, 21 May 2006 12:16:21 -0700
parents 6636d328fa38
children ca5d03c4b3f1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /*
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 2001, Espen Skoglund <esk@ira.uka.de>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 * Copyright (C) 2001, Haavard Kvaalen <havardk@xmms.org>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 * modify it under the terms of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * as published by the Free Software Foundation; either version 2
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * of the License, or (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 * along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 * 02111-1307, USA.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #ifdef HAVE_CONFIG_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 # include "config.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25
751
6636d328fa38 [svn] more progress
nenolod
parents: 0
diff changeset
26 #define GETTEXT_PACKAGE PACKAGE_NAME
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #include <glib/gi18n-lib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 #include <gtk/gtk.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 #include <stdio.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 #include "titlestring.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 #define CHECK(input, field) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 (((gchar *) &input->field - (gchar *) input) < input->__size)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 #define VS(input, field) (CHECK(input, field) ? input->field : NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 #define VI(input, field) (CHECK(input, field) ? input->field : 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 BmpTitleInput *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 bmp_title_input_new()
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 BmpTitleInput *input;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 input = g_new0(BmpTitleInput, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 input->__size = XMMS_TITLEINPUT_SIZE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 input->__version = XMMS_TITLEINPUT_VERSION;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 return input;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 bmp_title_input_free(BmpTitleInput * input)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 if (!input)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 g_free(input->performer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 g_free(input->album_name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 g_free(input->track_name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 g_free(input->date);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 g_free(input->genre);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 g_free(input->comment);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 g_free(input->file_name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 g_free(input->file_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 g_free(input);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 gchar *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 xmms_get_titlestring(const gchar * fmt, TitleInput * input)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 GString *outstr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 const gchar *string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 gchar c, convert[16];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 gint numdigits, numpr, val, i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 gint f_left, f_space, f_zero, someflag, width, precision;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 gboolean did_output = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 gchar digits[] = "0123456789";
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 #define PUTCH(ch) g_string_append_c(outstr, ch)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 #define LEFTPAD(num) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 G_STMT_START { \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 gint cnt = (num); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 if ( ! f_left && cnt > 0 ) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 while ( cnt-- > 0 ) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 PUTCH(f_zero ? '0' : ' '); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 } G_STMT_END;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 #define RIGHTPAD(num) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 G_STMT_START { \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 gint cnt = (num); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 if ( f_left && cnt > 0 ) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 while ( cnt-- > 0 ) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 PUTCH( ' ' ); \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 } G_STMT_END;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 if (fmt == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 outstr = g_string_new("");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 for (;;) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 /* Copy characters until we encounter '%'. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 while ((c = *fmt++) != '%') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 if (c == '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 goto Done;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 g_string_append_c(outstr, c);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 f_left = f_space = f_zero = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 someflag = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 /* Parse flags. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 while (someflag) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 switch (*fmt) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 case '-':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 f_left = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 fmt++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 case ' ':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 f_space = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 fmt++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 case '0':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 f_zero = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 fmt++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 someflag = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 /* Parse field width. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 if ((c = *fmt) >= '0' && c <= '9') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 width = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 while ((c = *fmt++) >= '0' && c <= '9') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 width *= 10;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 width += c - '0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 fmt--;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 width = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 /* Parse precision. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 if (*fmt == '.') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 if ((c = *++fmt) >= '0' && c <= '9') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 precision = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 while ((c = *fmt++) >= '0' && c <= '9') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 precision *= 10;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 precision += c - '0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 fmt--;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 precision = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 precision = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 /* Parse format conversion. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 switch (c = *fmt++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 case '}': /* close optional, just ignore */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 case '{':{ /* optional entry: %{n:...%} */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 char n = *fmt++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 if (!((n == 'a' && VS(input, album_name)) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 (n == 'c' && VS(input, comment)) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 (n == 'd' && VS(input, date)) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 (n == 'e' && VS(input, file_ext)) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 (n == 'f' && VS(input, file_name)) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 (n == 'F' && VS(input, file_path)) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 (n == 'g' && VS(input, genre)) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 (n == 'n' && VI(input, track_number)) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 (n == 'p' && VS(input, performer)) ||
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 (n == 't' && VS(input, track_name)))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 int nl = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 char c;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 while ((c = *fmt++)) /* until end of string */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 if (c == '}') /* if end of opt */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 if (!nl)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 break; /* if outmost indent level */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 --nl; /* else reduce indent */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 else if (c == '{')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 ++nl; /* increase indent */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 ++fmt;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 case 'a':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 string = VS(input, album_name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 goto Print_string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 case 'c':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 string = VS(input, comment);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 goto Print_string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 case 'd':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 string = VS(input, date);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 goto Print_string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 case 'e':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 string = VS(input, file_ext);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 goto Print_string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 case 'f':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 string = VS(input, file_name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 goto Print_string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 case 'F':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 string = VS(input, file_path);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 goto Print_string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 case 'g':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 string = VS(input, genre);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 goto Print_string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 case 'n':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 val = VI(input, track_number);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 goto Print_number;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 case 'p':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 string = VS(input, performer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 goto Print_string;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 case 't':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 string = VS(input, track_name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 Print_string:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 if (string == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 did_output = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 numpr = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 if (width > 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 /* Calculate printed size. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 numpr = strlen(string);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 if (precision >= 0 && precision < numpr)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 numpr = precision;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 LEFTPAD(width - numpr);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 /* Insert string. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 if (precision >= 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 while (precision-- > 0 && (c = *string++) != '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 PUTCH(c);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 while ((c = *string++) != '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 PUTCH(c);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 RIGHTPAD(width - numpr);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 case 'y':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 val = VI(input, year);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 Print_number:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 if (val == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 if (c != 'N')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 did_output = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 /* Create reversed number string. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 numdigits = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 do {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 convert[numdigits++] = digits[val % 10];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 val /= 10;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 while (val > 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 numpr = numdigits > precision ? numdigits : precision;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 /* Insert left padding. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 if (!f_left && width > numpr) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 if (f_zero)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 numpr = width;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 for (i = width - numpr; i-- > 0;)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 PUTCH(' ');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 /* Insert zero padding. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 for (i = numpr - numdigits; i-- > 0;)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 PUTCH('0');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 /* Insert number. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 while (numdigits > 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 PUTCH(convert[--numdigits]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 RIGHTPAD(width - numpr);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 case '%':
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 PUTCH('%');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 PUTCH('%');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 PUTCH(c);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 Done:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 if (did_output)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 return g_string_free(outstr, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 struct _TagDescription {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 gchar tag;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 gchar *description;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 typedef struct _TagDescription TagDescription;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 static TagDescription tag_descriptions[] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 {'p', N_("Performer/Artist")},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 {'a', N_("Album")},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 {'g', N_("Genre")},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 {'f', N_("File name")},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 {'F', N_("File path")},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 {'e', N_("File extension")},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 {'t', N_("Track name")},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 {'n', N_("Track number")},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 {'d', N_("Date")},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 {'y', N_("Year")},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 {'c', N_("Comment")}
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 gint tag_descriptions_length =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 sizeof(tag_descriptions) / sizeof(TagDescription);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 GtkWidget *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 xmms_titlestring_descriptions(gchar * tags, gint columns)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 GtkWidget *table, *label;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 gchar tag_str[5];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 gint num = strlen(tags);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 gint r = 0, c, i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 g_return_val_if_fail(tags != NULL, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 g_return_val_if_fail(columns <= num, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 table = gtk_table_new((num + columns - 1) / columns, columns * 2, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 gtk_table_set_row_spacings(GTK_TABLE(table), 2);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353 gtk_table_set_col_spacings(GTK_TABLE(table), 5);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355 for (c = 0; c < columns; c++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 for (r = 0; r < (num + columns - 1 - c) / columns; r++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 g_snprintf(tag_str, sizeof(tag_str), "%%%c:", *tags);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 label = gtk_label_new(tag_str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 gtk_table_attach(GTK_TABLE(table), label, 2 * c, 2 * c + 1, r,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 r + 1, GTK_FILL, GTK_FILL, 0, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 gtk_widget_show(label);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 for (i = 0; i < tag_descriptions_length; i++) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 if (*tags == tag_descriptions[i].tag) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 label = gtk_label_new(_(tag_descriptions[i].description));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 gtk_table_attach(GTK_TABLE(table), label, 2 * c + 1,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 2 * c + 2, r, r + 1,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 GTK_EXPAND | GTK_FILL,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 GTK_EXPAND | GTK_FILL, 0, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 gtk_widget_show(label);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377 if (i == tag_descriptions_length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378 g_warning("Invalid tag: %c", *tags);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380 tags++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385 label = gtk_label_new(_("%{n:...%}: Display \"...\" only if element "
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386 "%n is present"));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 gtk_table_attach(GTK_TABLE(table), label, 0, r + 1,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389 r + 1, r + 2, GTK_FILL, GTK_FILL, 0, 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 gtk_widget_show(label);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 return table;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 }