source: trunk/gtk/util.h @ 1125

Last change on this file since 1125 was 760, checked in by joshe, 15 years ago

Change all my 2-clause BSD licenses to the same MIT/X11 license as libtransmission.

  • Property svn:keywords set to Date Rev Author Id
File size: 3.7 KB
Line 
1/******************************************************************************
2 * $Id: util.h 760 2006-08-13 00:26:52Z livings124 $
3 *
4 * Copyright (c) 2005-2006 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#ifndef TG_UTIL_H
26#define TG_UTIL_H
27
28#include <sys/types.h>
29#include <stdarg.h>
30
31/* macro to shut up "unused parameter" warnings */
32#ifdef __GNUC__
33#define SHUTUP                  __attribute__((unused))
34#else
35#define SHUTUP
36#endif
37
38typedef void (*add_torrents_func_t)(void*,void*,GList*,const char*,guint);
39
40/* return number of items in array */
41#define ALEN(a)                 (sizeof(a) / sizeof((a)[0]))
42
43#define ISA(o, t)               (g_type_is_a(G_OBJECT_TYPE(G_OBJECT(o)), (t)))
44
45/* used for a callback function with a data parameter */
46typedef void (*callbackfunc_t)(void*);
47
48/* try to interpret a string as a textual representation of a boolean */
49/* note that this isn't localized */
50gboolean
51strbool(const char *str);
52
53/* return a human-readable string for the size given in bytes.
54   the string must be g_free()d */
55char *
56readablesize(guint64 size);
57
58/* return a human-readable string for the time given in seconds.
59   the string must be g_free()d */
60char *
61readabletime(int secs);
62
63/* returns a string representing the download ratio.
64   the string must be g_free()d */
65char *
66ratiostr(guint64 down, guint64 up);
67
68/* create a directory and any missing parent directories */
69gboolean
70mkdir_p(const char *name, mode_t mode);
71
72/* joins a GList of strings into one string using an optional separator */
73char *
74joinstrlist(GList *list, char *sep);
75
76/* free a GList of strings */
77void
78freestrlist(GList *list);
79
80/* decodes a string that has been urlencoded */
81char *
82urldecode(const char *str, int len);
83
84/* return a list of cleaned-up paths, with invalid directories removed */
85GList *
86checkfilenames(int argc, char **argv);
87
88/* returns the flag for an action string */
89guint
90addactionflag(const char *action);
91
92/* returns the action string for a flag */
93const char *
94addactionname(guint flag);
95
96/* turn a NULL-terminated list of void* arguments into a glist */
97GList *
98makeglist(void *ptr, ...);
99
100#ifdef GTK_MAJOR_VERSION
101
102/* if wind is NULL then you must call gtk_widget_show on the returned widget */
103
104GtkWidget *
105errmsg(GtkWindow *wind, const char *format, ...)
106#ifdef __GNUC__
107  __attribute__ ((format (printf, 2, 3)))
108#endif
109  ;
110
111GtkWidget *
112errmsg_full(GtkWindow *wind, callbackfunc_t func, void *data,
113            const char *format, ...)
114#ifdef __GNUC__
115  __attribute__ ((format (printf, 4, 5)))
116#endif
117  ;
118
119GtkWidget *
120verrmsg(GtkWindow *wind, callbackfunc_t func, void *data,
121        const char *format, va_list ap);
122
123#endif /* GTK_MAJOR_VERSION */
124
125#endif /* TG_UTIL_H */
Note: See TracBrowser for help on using the repository browser.