2
* Copyright (C) 2005 Marc Pavot <marc.pavot@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2, or (at your option)
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include "servers/ario-server.h"
21
#include "glib/gslist.h"
22
#include "gdk/gdkpixbuf.h"
24
/* Number of covers used to generate the drag & drop image */
25
#define MAX_COVERS_IN_DRAG 3
27
/* Maximum length of the string representing a int */
28
#define INTLEN (sizeof(int) * CHAR_BIT + 1) / 3 + 1
30
/* Maximum size of a time like 1:23:45 */
31
#define ARIO_MAX_TIME_SIZE 3*INTLEN+2
33
/* Maximum size of a track */
34
#define ARIO_MAX_TRACK_SIZE INTLEN
39
* Format a track time to the form 1:23:45.
41
* @param time The time to format, in seconds
43
* @return A newly allocated string with the formated time
45
char* ario_util_format_time (const int time) G_GNUC_CONST G_GNUC_MALLOC;
48
* Format a track time to the form 1:23:45 in a buffer
50
* @param time The time to format, in seconds
51
* @param buf The buffer to fill
52
* @param buf_len The len of the buffer
54
void ario_util_format_time_buf (const int time,
58
* Format a time to the form : x days, y hours, z minutes, n secondes
60
* @param time The time to format, in seconds
62
* @return A newly allocated string with the formated time
64
char* ario_util_format_total_time (const int time) G_GNUC_CONST G_GNUC_MALLOC;
67
* Format a track number to be displayed
69
* @param track The track number
70
* @param buf The buffer to fill
71
* @param buf_len The len of the buffer
73
void ario_util_format_track_buf (const gchar *track,
77
* Try to get the best title to display from an ArioServerSong
79
* @param server_song The server song
81
* @return A pointer to the title (should not be freed)
83
gchar* ario_util_format_title (ArioServerSong *server_song);
86
* Add an icon to the default icon factory
88
* @param stock_id The id of the icon to add
89
* @param filename The icon filename
91
void ario_util_add_stock_icons (const char *stock_id,
92
const char *filename);
94
* Initialise default icon factory with a few icons
96
void ario_util_init_stock_icons (void);
99
* Check if an icon is already present
101
* @param stock_id The id of the icon to check
103
* @return True if the icon is present, FALSE otherwise
105
gboolean ario_util_has_stock_icons (const char *stock_id);
108
* Get the path of Ario configuration
110
* @return The path of the directory. It should not be freed.
112
const char* ario_util_config_dir (void);
115
* Check whether a file exists or not
117
* @param uri The uri of the file
119
* @return True if the file exists, FALSE otherwise
121
gboolean ario_util_uri_exists (const char *uri);
124
* Delete a file on the disk
126
* @param uri The uri of the file to delete
128
void ario_util_unlink_uri (const char *uri);
131
* Create a new directory
133
* @param uri The uri of the directory to create
135
void ario_util_mkdir (const char *uri);
138
* Copy a file on disk
140
* @param src_uri The source file to copy
141
* @param dest_uri The destination place to copy the file
143
void ario_util_copy_file (const char *src_uri,
144
const char *dest_uri);
146
* Download a file on internet
148
* @param uri The uri of the file to download
149
* @param post_data Post data to use for POST requests or NULL
150
* @param post_size The size of post data (no used if post_data is NULL)
151
* @param headers Http headers to use or NULL
152
* @param size A pointer to a int that will contain the size of the downloaded data
153
* @param data Newly allocated data containing the downloaded file
155
void ario_util_download_file (const char *uri,
156
const char *post_data,
158
const struct curl_slist *headers,
162
* Replace string 'old' by string 'new' in 'string'
164
* @param string The string where the replacement will be done
165
* @param old The string to replace
166
* @param new The string that will replace 'old'
168
void ario_util_string_replace (char **string,
172
* Load a URL in user's web browser
174
* @param uri The URL to load
176
void ario_util_load_uri (const char *uri);
179
* Format a keyword to be used for example in an online search
181
* @param keyword The keyword to format
183
* @return A newly allocated formated keyword
185
char * ario_util_format_keyword (const char *keyword) G_GNUC_MALLOC;
188
* Format a keyword to be used for a search on last.fm
190
* @param keyword The keyword to format
192
* @return A newly allocated formated keyword
194
char * ario_util_format_keyword_for_lastfm (const char *keyword) G_GNUC_MALLOC;
197
* Compute the MD5 hash of a string
199
* @param string The string to use for MD5 computation
201
* @return A newly allocated hash
203
gchar * ario_util_md5 (const char *string) G_GNUC_MALLOC;
206
* Generate an icon to use for Drag & Drop from a list of albums
208
* @param albums The list of albums
210
* @return A newly allocated pixbuf
212
GdkPixbuf * ario_util_get_dnd_pixbuf_from_albums (const GSList *albums) G_GNUC_MALLOC;
215
* Generate an icon to use for Drag & Drop from a list of criteria
217
* @param criterias The list of ArioServerCriteria
219
* @return A newly allocated pixbuf
221
GdkPixbuf * ario_util_get_dnd_pixbuf (const GSList *criterias) G_GNUC_MALLOC;
224
* Convert a string from iso8859 to locale
226
* @param string The string to convert
228
* @return A newly allocated string
230
gchar * ario_util_convert_from_iso8859 (const char *string) G_GNUC_MALLOC;
233
* Remove bad caracters from a filename
235
* @param filename The filename to convert
237
void ario_util_sanitize_filename (char *filename);
240
* Get the content of a file from disk
242
* @param filename The filename
243
* @param contents A pointer to a newly allocated file content
244
* @param length A pointer to the size of file content
245
* @param error return location for a GError, or NULL
247
* @return TRUE on success, FALSE if an error occurred
249
gboolean ario_file_get_contents (const gchar *filename,
254
* Writes all of contents to a file named filename
256
* @param filename name of a file to write contents
257
* @param contents string to write to the file
258
* @param length length of contents, or -1 if contents is a nul-terminated string
259
* @param error return location for a GError, or NULL
261
* @return TRUE on success, FALSE if an error occurred
263
gboolean ario_file_set_contents (const gchar *filename,
264
const gchar *contents,
268
* Returns TRUE if any of the tests in the bitfield test are TRUE.
270
* @param filename a filename to test
271
* @param test bitfield of GFileTest flags
273
* @return whether a test was TRUE
275
gboolean ario_file_test (const gchar *filename,
279
* Case insensitive strstr (locate a substring in a string)
281
* @param haystack The string to do the location
282
* @param needle String to locate
286
const char * ario_util_stristr (const char *haystack,
292
* @param The GSList to randomize. This list should not be used anymore after
293
* this function has been called. Elements of the list should be freed if
294
* needed and the list should be freed in addition to the one returned by
295
* ario_util_gslist_randomize.
296
* @param max The number of items to randomize in the list
298
* @return A pointer to the GSList to use instead of 'list'
300
GSList * ario_util_gslist_randomize (GSList **list,
304
* Format a string so that it can be used in an HTTP requests
306
* @param text The string to format
308
* @return A newly allocated string formated for HTTP requests
310
gchar * ario_util_format_for_http (const gchar *text);
313
* Computes the absolute value of a int
315
* @param a An integer
317
* @return a if a is positive, -a if a is negative
320
ario_util_abs (const gint a)
322
return (a > 0 ? a : -a);
326
* Returns the min of two values
328
* @param a First value
329
* @param b Second value
331
* @return Minimum of a and b
334
ario_util_min (const gint a,
337
return (a > b ? b : a);
341
* Returns the max of two values
343
* @param a First value
344
* @param b Second value
346
* @return Maximum of a and b
349
ario_util_max (const gint a,
352
return (a > b ? a : b);
356
* Compare two strings. These two strings can be NULL
358
* @param a First string or NULL
359
* @param b Second string or NULL
361
* @return < 0 if a compares before b, 0 if they compare equal, > 0 if a compares after b
364
ario_util_strcmp (const gchar *a,
373
return g_utf8_collate (a, b);