Mercurial > audlegacy-plugins
comparison src/song_change/song_change.c @ 2480:f88dd72c9156
Moved formatter stuff to the only plugin that actually used it.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 31 Mar 2008 08:14:09 +0300 |
parents | c44b90b6322e |
children | ed6c81bd9016 |
comparison
equal
deleted
inserted
replaced
2477:11f7c096f7e6 | 2480:f88dd72c9156 |
---|---|
17 | 17 |
18 #include <audacious/plugin.h> | 18 #include <audacious/plugin.h> |
19 #include <audacious/ui_preferences.h> | 19 #include <audacious/ui_preferences.h> |
20 #include <audacious/configdb.h> | 20 #include <audacious/configdb.h> |
21 #include <audacious/auddrct.h> | 21 #include <audacious/auddrct.h> |
22 #include <audacious/formatter.h> | 22 #include "formatter.h" |
23 #include <audacious/i18n.h> | 23 #include <audacious/i18n.h> |
24 #include <audacious/hook.h> | 24 #include <audacious/hook.h> |
25 #include <audacious/playlist.h> | 25 #include <audacious/playlist.h> |
26 | 26 |
27 static void init(void); | 27 static void init(void); |
97 @pos: playlist_pos */ | 97 @pos: playlist_pos */ |
98 static void | 98 static void |
99 do_command(char *cmd, const char *current_file, int pos) | 99 do_command(char *cmd, const char *current_file, int pos) |
100 { | 100 { |
101 int length, rate, freq, nch; | 101 int length, rate, freq, nch; |
102 char *str, *shstring = NULL, *temp, numbuf[16]; | 102 char *str, *shstring = NULL, *temp, numbuf[32]; |
103 gboolean playing; | 103 gboolean playing; |
104 Formatter *formatter; | 104 Formatter *formatter; |
105 | 105 |
106 if (cmd && strlen(cmd) > 0) | 106 if (cmd && strlen(cmd) > 0) |
107 { | 107 { |
108 formatter = aud_formatter_new(); | 108 formatter = formatter_new(); |
109 str = audacious_drct_pl_get_title(pos); | 109 str = audacious_drct_pl_get_title(pos); |
110 if (str) | 110 if (str) |
111 { | 111 { |
112 temp = aud_escape_shell_chars(str); | 112 temp = aud_escape_shell_chars(str); |
113 aud_formatter_associate(formatter, 's', temp); | 113 formatter_associate(formatter, 's', temp); |
114 aud_formatter_associate(formatter, 'n', temp); | 114 formatter_associate(formatter, 'n', temp); |
115 g_free(str); | 115 g_free(str); |
116 g_free(temp); | 116 g_free(temp); |
117 } | 117 } |
118 else | 118 else |
119 { | 119 { |
120 aud_formatter_associate(formatter, 's', ""); | 120 formatter_associate(formatter, 's', ""); |
121 aud_formatter_associate(formatter, 'n', ""); | 121 formatter_associate(formatter, 'n', ""); |
122 } | 122 } |
123 | 123 |
124 if (current_file) | 124 if (current_file) |
125 { | 125 { |
126 temp = aud_escape_shell_chars(current_file); | 126 temp = aud_escape_shell_chars(current_file); |
127 aud_formatter_associate(formatter, 'f', temp); | 127 formatter_associate(formatter, 'f', temp); |
128 g_free(temp); | 128 g_free(temp); |
129 } | 129 } |
130 else | 130 else |
131 aud_formatter_associate(formatter, 'f', ""); | 131 formatter_associate(formatter, 'f', ""); |
132 sprintf(numbuf, "%02d", pos + 1); | 132 g_snprintf(numbuf, sizeof(numbuf), "%02d", pos + 1); |
133 aud_formatter_associate(formatter, 't', numbuf); | 133 formatter_associate(formatter, 't', numbuf); |
134 length = audacious_drct_pl_get_time(pos); | 134 length = audacious_drct_pl_get_time(pos); |
135 if (length != -1) | 135 if (length != -1) |
136 { | 136 { |
137 sprintf(numbuf, "%d", length); | 137 g_snprintf(numbuf, sizeof(numbuf), "%d", length); |
138 aud_formatter_associate(formatter, 'l', numbuf); | 138 formatter_associate(formatter, 'l', numbuf); |
139 } | 139 } |
140 else | 140 else |
141 aud_formatter_associate(formatter, 'l', "0"); | 141 formatter_associate(formatter, 'l', "0"); |
142 audacious_drct_get_info(&rate, &freq, &nch); | 142 audacious_drct_get_info(&rate, &freq, &nch); |
143 sprintf(numbuf, "%d", rate); | 143 g_snprintf(numbuf, sizeof(numbuf), "%d", rate); |
144 aud_formatter_associate(formatter, 'r', numbuf); | 144 formatter_associate(formatter, 'r', numbuf); |
145 sprintf(numbuf, "%d", freq); | 145 g_snprintf(numbuf, sizeof(numbuf), "%d", freq); |
146 aud_formatter_associate(formatter, 'F', numbuf); | 146 formatter_associate(formatter, 'F', numbuf); |
147 sprintf(numbuf, "%d", nch); | 147 g_snprintf(numbuf, sizeof(numbuf), "%d", nch); |
148 aud_formatter_associate(formatter, 'c', numbuf); | 148 formatter_associate(formatter, 'c', numbuf); |
149 playing = audacious_drct_get_playing(); | 149 playing = audacious_drct_get_playing(); |
150 sprintf(numbuf, "%d", playing); | 150 g_snprintf(numbuf, sizeof(numbuf), "%d", playing); |
151 aud_formatter_associate(formatter, 'p', numbuf); | 151 formatter_associate(formatter, 'p', numbuf); |
152 shstring = aud_formatter_format(formatter, cmd); | 152 shstring = formatter_format(formatter, cmd); |
153 aud_formatter_destroy(formatter); | 153 formatter_destroy(formatter); |
154 | 154 |
155 if (shstring) | 155 if (shstring) |
156 { | 156 { |
157 execute_command(shstring); | 157 execute_command(shstring); |
158 /* FIXME: This can possibly be freed too early */ | 158 /* FIXME: This can possibly be freed too early */ |
536 } | 536 } |
537 | 537 |
538 static void | 538 static void |
539 songchange_playlist_eof(gpointer unused, gpointer unused2) | 539 songchange_playlist_eof(gpointer unused, gpointer unused2) |
540 { | 540 { |
541 int pos; | 541 gint pos; |
542 char *current_file; | 542 gchar *current_file; |
543 | 543 |
544 pos = audacious_drct_pl_get_pos(); | 544 pos = audacious_drct_pl_get_pos(); |
545 current_file = audacious_drct_pl_get_file(pos); | 545 current_file = audacious_drct_pl_get_file(pos); |
546 | 546 |
547 do_command(cmd_line_end, current_file, pos); | 547 do_command(cmd_line_end, current_file, pos); |