1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2017 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 string_list_free(GList
*string_list
)
29 g_list_free_full(string_list
, g_free
);
34 string_list_find(GList
*string_list
, const gchar
*str
)
36 GList
*list
= g_list_first(string_list
);
39 if( strcmp(str
, (gchar
*) list
->data
) == 0 )
47 string_list_remove(GList
*string_list
, const gchar
*str
)
49 GList
*list
= g_list_first(string_list
);
52 if( strcmp(str
, (gchar
*) list
->data
) == 0 ) {
55 return g_list_delete_link(string_list
, list
);
63 format_duration_short(char *buffer
, size_t length
, unsigned duration
)
66 g_snprintf(buffer
, length
,
67 "%i:%02i", duration
/ 60, duration
% 60);
69 g_snprintf(buffer
, length
,
70 "%i:%02i:%02i", duration
/ 3600,
71 (duration
% 3600) / 60, duration
% 60);
75 format_duration_long(char *p
, size_t length
, unsigned long duration
)
77 unsigned bytes_written
= 0;
79 if (duration
/ 31536000 > 0) {
80 if (duration
/ 31536000 == 1)
81 bytes_written
= g_snprintf(p
, length
, "%d %s, ", 1, _("year"));
83 bytes_written
= g_snprintf(p
, length
, "%lu %s, ", duration
/ 31536000, _("years"));
85 length
-= bytes_written
;
88 if (duration
/ 604800 > 0) {
89 if (duration
/ 604800 == 1)
90 bytes_written
= g_snprintf(p
, length
, "%d %s, ",
93 bytes_written
= g_snprintf(p
, length
, "%lu %s, ",
94 duration
/ 604800, _("weeks"));
96 length
-= bytes_written
;
99 if (duration
/ 86400 > 0) {
100 if (duration
/ 86400 == 1)
101 bytes_written
= g_snprintf(p
, length
, "%d %s, ",
104 bytes_written
= g_snprintf(p
, length
, "%lu %s, ",
105 duration
/ 86400, _("days"));
107 length
-= bytes_written
;
111 g_snprintf(p
, length
, "%02lu:%02lu:%02lu", duration
/ 3600,
112 duration
% 3600 / 60, duration
% 3600 % 60);