~ubuntu-branches/ubuntu/raring/ario/raring

« back to all changes in this revision

Viewing changes to .pc/glib-single-include.patch/src/ario-util.h

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2012-04-02 13:36:22 UTC
  • Revision ID: package-import@ubuntu.com-20120402133622-b32kfqzuwdmhqr9n
Tags: 1.5.1-1ubuntu1
glib-single-include.patch: Starting with glib 2.32 it is
now mandatory to include glib.h instead of individual
headers, or the compiler will generate an error.
Fixes FTBFS. From Debian BTS #665509.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2005 Marc Pavot <marc.pavot@gmail.com>
 
3
 *
 
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)
 
7
 *  any later version.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 */
 
19
 
 
20
#include "servers/ario-server.h"
 
21
#include "glib/gslist.h"
 
22
#include "gdk/gdkpixbuf.h"
 
23
 
 
24
/* Number of covers used to generate the drag & drop image */
 
25
#define MAX_COVERS_IN_DRAG 3
 
26
 
 
27
/* Maximum length of the string representing a int */
 
28
#define INTLEN (sizeof(int) * CHAR_BIT + 1) / 3 + 1
 
29
 
 
30
/* Maximum size of a time like 1:23:45 */
 
31
#define ARIO_MAX_TIME_SIZE 3*INTLEN+2
 
32
 
 
33
/* Maximum size of a track */
 
34
#define ARIO_MAX_TRACK_SIZE INTLEN
 
35
 
 
36
struct curl_slist;
 
37
 
 
38
/**
 
39
 * Format a track time to the form 1:23:45.
 
40
 *
 
41
 * @param time The time to format, in seconds
 
42
 *
 
43
 * @return A newly allocated string with the formated time
 
44
 */
 
45
char*                   ario_util_format_time                (const int time) G_GNUC_CONST G_GNUC_MALLOC;
 
46
 
 
47
/**
 
48
 * Format a track time to the form 1:23:45 in a buffer
 
49
 *
 
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
 
53
 */
 
54
void                    ario_util_format_time_buf            (const int time,
 
55
                                                              char *buf,
 
56
                                                              int buf_len);
 
57
/**
 
58
 * Format a time to the form : x days, y hours, z minutes, n secondes
 
59
 *
 
60
 * @param time The time to format, in seconds
 
61
 *
 
62
 * @return A newly allocated string with the formated time
 
63
 */
 
64
char*                   ario_util_format_total_time          (const int time) G_GNUC_CONST G_GNUC_MALLOC;
 
65
 
 
66
/**
 
67
 * Format a track number to be displayed
 
68
 *
 
69
 * @param track The track number
 
70
 * @param buf The buffer to fill
 
71
 * @param buf_len The len of the buffer
 
72
 */
 
73
void                    ario_util_format_track_buf           (const gchar *track,
 
74
                                                              char *buf,
 
75
                                                              int buf_len);
 
76
/**
 
77
 * Try to get the best title to display from an ArioServerSong
 
78
 *
 
79
 * @param server_song The server song
 
80
 *
 
81
 * @return A pointer to the title (should not be freed)
 
82
 */
 
83
gchar*                  ario_util_format_title               (ArioServerSong *server_song);
 
84
 
 
85
/**
 
86
 * Add an icon to the default icon factory
 
87
 *
 
88
 * @param stock_id The id of the icon to add
 
89
 * @param filename The icon filename
 
90
 */
 
91
void                    ario_util_add_stock_icons            (const char *stock_id,
 
92
                                                              const char *filename);
 
93
/**
 
94
 * Initialise default icon factory with a few icons
 
95
 */
 
96
void                    ario_util_init_stock_icons           (void);
 
97
 
 
98
/**
 
99
 * Check if an icon is already present
 
100
 *
 
101
 * @param stock_id The id of the icon to check
 
102
 *
 
103
 * @return True if the icon is present, FALSE otherwise
 
104
 */
 
105
gboolean                ario_util_has_stock_icons            (const char *stock_id);
 
106
 
 
107
/**
 
108
 * Get the path of Ario configuration
 
109
 *
 
110
 * @return The path of the directory. It should not be freed.
 
111
 */
 
112
const char*             ario_util_config_dir                 (void);
 
113
 
 
114
/**
 
115
 * Check whether a file exists or not
 
116
 *
 
117
 * @param uri The uri of the file
 
118
 *
 
119
 * @return True if the file exists, FALSE otherwise
 
120
 */
 
121
gboolean                ario_util_uri_exists                 (const char *uri);
 
122
 
 
123
/**
 
124
 * Delete a file on the disk
 
125
 *
 
126
 * @param uri The uri of the file to delete
 
127
 */
 
128
void                    ario_util_unlink_uri                 (const char *uri);
 
129
 
 
130
/**
 
131
 * Create a new directory
 
132
 *
 
133
 * @param uri The uri of the directory to create
 
134
 */
 
135
void                    ario_util_mkdir                      (const char *uri);
 
136
 
 
137
/**
 
138
 * Copy a file on disk
 
139
 *
 
140
 * @param src_uri The source file to copy
 
141
 * @param dest_uri The destination place to copy the file
 
142
 */
 
143
void                    ario_util_copy_file                  (const char *src_uri,
 
144
                                                              const char *dest_uri);
 
145
/**
 
146
 * Download a file on internet
 
147
 *
 
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
 
154
 */
 
155
void                    ario_util_download_file              (const char *uri,
 
156
                                                              const char *post_data,
 
157
                                                              const int post_size,
 
158
                                                              const struct curl_slist *headers,
 
159
                                                              int* size,
 
160
                                                              char** data);
 
161
/**
 
162
 * Replace string 'old' by string 'new' in 'string'
 
163
 *
 
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'
 
167
 */
 
168
void                    ario_util_string_replace             (char **string,
 
169
                                                              const char *old,
 
170
                                                              const char *new);
 
171
/**
 
172
 * Load a URL in user's web browser
 
173
 *
 
174
 * @param uri The URL to load
 
175
 */
 
176
void                    ario_util_load_uri                   (const char *uri);
 
177
 
 
178
/**
 
179
 * Format a keyword to be used for example in an online search
 
180
 *
 
181
 * @param keyword The keyword to format
 
182
 *
 
183
 * @return A newly allocated formated keyword
 
184
 */
 
185
char *                  ario_util_format_keyword             (const char *keyword) G_GNUC_MALLOC;
 
186
 
 
187
/**
 
188
 * Format a keyword to be used for a search on last.fm
 
189
 *
 
190
 * @param keyword The keyword to format
 
191
 *
 
192
 * @return A newly allocated formated keyword
 
193
 */
 
194
char *                  ario_util_format_keyword_for_lastfm  (const char *keyword) G_GNUC_MALLOC;
 
195
 
 
196
/**
 
197
 * Compute the MD5 hash of a string
 
198
 *
 
199
 * @param string The string to use for MD5 computation
 
200
 *
 
201
 * @return A newly allocated hash
 
202
 */
 
203
gchar *                 ario_util_md5                        (const char *string) G_GNUC_MALLOC;
 
204
 
 
205
/**
 
206
 * Generate an icon to use for Drag & Drop from a list of albums
 
207
 *
 
208
 * @param albums The list of albums
 
209
 *
 
210
 * @return A newly allocated pixbuf
 
211
 */
 
212
GdkPixbuf *             ario_util_get_dnd_pixbuf_from_albums (const GSList *albums) G_GNUC_MALLOC;
 
213
 
 
214
/**
 
215
 * Generate an icon to use for Drag & Drop from a list of criteria
 
216
 *
 
217
 * @param criterias The list of ArioServerCriteria
 
218
 *
 
219
 * @return A newly allocated pixbuf
 
220
 */
 
221
GdkPixbuf *             ario_util_get_dnd_pixbuf             (const GSList *criterias) G_GNUC_MALLOC;
 
222
 
 
223
/**
 
224
 * Convert a string from iso8859 to locale
 
225
 *
 
226
 * @param string The string to convert
 
227
 *
 
228
 * @return A newly allocated string
 
229
 */
 
230
gchar *                 ario_util_convert_from_iso8859       (const char *string) G_GNUC_MALLOC;
 
231
 
 
232
/**
 
233
 * Remove bad caracters from a filename
 
234
 *
 
235
 * @param filename The filename to convert
 
236
 */
 
237
void                    ario_util_sanitize_filename          (char *filename);
 
238
 
 
239
/**
 
240
 * Get the content of a file from disk
 
241
 *
 
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
 
246
 *
 
247
 * @return TRUE on success, FALSE if an error occurred
 
248
 */
 
249
gboolean                ario_file_get_contents               (const gchar *filename,
 
250
                                                              gchar **contents,
 
251
                                                              gsize *length,
 
252
                                                              GError **error);
 
253
/**
 
254
 * Writes all of contents to a file named filename
 
255
 *
 
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
 
260
 *
 
261
 * @return TRUE on success, FALSE if an error occurred
 
262
 */
 
263
gboolean                ario_file_set_contents               (const gchar *filename,
 
264
                                                              const gchar *contents,
 
265
                                                              gsize length,
 
266
                                                              GError **error);
 
267
/**
 
268
 * Returns TRUE if any of the tests in the bitfield test are TRUE.
 
269
 *
 
270
 * @param filename a filename to test
 
271
 * @param test bitfield of GFileTest flags
 
272
 *
 
273
 * @return whether a test was TRUE
 
274
 */
 
275
gboolean                ario_file_test                       (const gchar *filename,
 
276
                                                              GFileTest test);
 
277
 
 
278
/**
 
279
 * Case insensitive strstr (locate a substring in a string)
 
280
 *
 
281
 * @param haystack The string to do the location
 
282
 * @param needle String to locate
 
283
 *
 
284
 * @return
 
285
 */
 
286
const char *            ario_util_stristr                    (const char *haystack,
 
287
                                                              const char *needle);
 
288
 
 
289
/**
 
290
 * Randomize a GSList
 
291
 *
 
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
 
297
 *
 
298
 * @return A pointer to the GSList to use instead of 'list'
 
299
 */
 
300
GSList *                ario_util_gslist_randomize           (GSList **list,
 
301
                                                              const int max);
 
302
 
 
303
/**
 
304
 * Format a string so that it can be used in an HTTP requests
 
305
 *
 
306
 * @param text The string to format
 
307
 *
 
308
 * @return A newly allocated string formated for HTTP requests
 
309
 */
 
310
gchar *                 ario_util_format_for_http            (const gchar *text);
 
311
 
 
312
/**
 
313
 * Computes the absolute value of a int
 
314
 *
 
315
 * @param a An integer
 
316
 *
 
317
 * @return a if a is positive, -a if a is negative
 
318
 */
 
319
static inline gint
 
320
ario_util_abs (const gint a)
 
321
{
 
322
        return (a > 0 ? a : -a);
 
323
}
 
324
 
 
325
/**
 
326
 * Returns the min of two values
 
327
 *
 
328
 * @param a First value
 
329
 * @param b Second value
 
330
 *
 
331
 * @return Minimum of a and b
 
332
 */
 
333
static inline gint
 
334
ario_util_min (const gint a,
 
335
               const gint b)
 
336
{
 
337
        return (a > b ? b : a);
 
338
}
 
339
 
 
340
/**
 
341
 * Returns the max of two values
 
342
 *
 
343
 * @param a First value
 
344
 * @param b Second value
 
345
 *
 
346
 * @return Maximum of a and b
 
347
 */
 
348
static inline gint
 
349
ario_util_max (const gint a,
 
350
               const gint b)
 
351
{
 
352
        return (a > b ? a : b);
 
353
}
 
354
 
 
355
/**
 
356
 * Compare two strings. These two strings can be NULL
 
357
 *
 
358
 * @param a First string or NULL
 
359
 * @param b Second string or NULL
 
360
 *
 
361
 * @return < 0 if a compares before b, 0 if they compare equal, > 0 if a compares after b
 
362
 */
 
363
static inline gint
 
364
ario_util_strcmp (const gchar *a,
 
365
                  const gchar* b)
 
366
{
 
367
        if (!a && !b)
 
368
                return 0;
 
369
        if (!a && b)
 
370
                return 1;
 
371
        if (a && !b)
 
372
                return -1;
 
373
        return g_utf8_collate (a, b);
 
374
}