2 * Dictix / DixUtils - dix-utils.vala
4 * Copyright (C) Martin Blanchard 2011 <tinram@gmx.fr>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 public const string[] size_units
= {
33 public string codec_to_string (string codec
) {
34 if (codec
== "FLAC") {
35 return _("FLAC (lossless)");
36 } else if (codec
== "Vorbis") {
37 return _("Vorbis (lossy)");
43 public string basename_from_uri (string uri
) {
49 path
= Filename
.from_uri (uri
);
50 } catch (Error error
) {
51 warning (error
.message
);
56 return Path
.get_basename (path
);
62 public string size_to_string (uint64 bytes
) {
69 while (size
> 1000.0f
) {
76 size
= Math
.roundf (size
);
79 return size
.to_string ("%.01lf") + " " + size_units
[i
];
82 return size
.to_string ("%.01lf") + " " + size_units
[0];
85 public string duration_to_string (int64 duration
) {
86 int secs
, mins
, hours
;
89 /* Computation of secs / mins / hours : */
90 secs
= (int) (duration
% 60);
93 mins
= (int) ((duration
% (60 * 60)) / 60);
94 duration
-= mins
* 60;
97 return mins
.to_string () + ":" + secs
.to_string ("%02d");
100 hours
= (int) (duration
/ (60 * 60));
102 return hours
.to_string () + ":" + mins
.to_string ("%02d") + ":" + secs
.to_string ("%02d");
108 public string channels_to_string (int channels
) {
110 return channels
.to_string ();
116 public string sample_rate_to_string (int sample_rate
) {
120 rate
= ((float) sample_rate
) / 1000.0f
;
123 hundreds
= (int) (sample_rate
% 1000);
125 if ((hundreds
% 100) == 0) {
126 return rate
.to_string ("%.01lf") + " " + _("kHz");
129 if ((hundreds
% 10) == 0) {
130 return rate
.to_string ("%.02lf") + " " + _("kHz");
133 return rate
.to_string ("%.03lf") + " " + _("kHz");
139 public string bit_rate_to_string (int bit_rate
) {
143 kbytes
= (int) (bit_rate
/ 1000);
145 return kbytes
.to_string () + " " + _("kbps");