1 | /****************************************************************************** |
---|
2 | * $Id: util.h 760 2006-08-13 00:26:52Z joshe $ |
---|
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 | |
---|
38 | typedef 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 */ |
---|
46 | typedef 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 */ |
---|
50 | gboolean |
---|
51 | strbool(const char *str); |
---|
52 | |
---|
53 | /* return a human-readable string for the size given in bytes. |
---|
54 | the string must be g_free()d */ |
---|
55 | char * |
---|
56 | readablesize(guint64 size); |
---|
57 | |
---|
58 | /* return a human-readable string for the time given in seconds. |
---|
59 | the string must be g_free()d */ |
---|
60 | char * |
---|
61 | readabletime(int secs); |
---|
62 | |
---|
63 | /* returns a string representing the download ratio. |
---|
64 | the string must be g_free()d */ |
---|
65 | char * |
---|
66 | ratiostr(guint64 down, guint64 up); |
---|
67 | |
---|
68 | /* create a directory and any missing parent directories */ |
---|
69 | gboolean |
---|
70 | mkdir_p(const char *name, mode_t mode); |
---|
71 | |
---|
72 | /* joins a GList of strings into one string using an optional separator */ |
---|
73 | char * |
---|
74 | joinstrlist(GList *list, char *sep); |
---|
75 | |
---|
76 | /* free a GList of strings */ |
---|
77 | void |
---|
78 | freestrlist(GList *list); |
---|
79 | |
---|
80 | /* decodes a string that has been urlencoded */ |
---|
81 | char * |
---|
82 | urldecode(const char *str, int len); |
---|
83 | |
---|
84 | /* return a list of cleaned-up paths, with invalid directories removed */ |
---|
85 | GList * |
---|
86 | checkfilenames(int argc, char **argv); |
---|
87 | |
---|
88 | /* returns the flag for an action string */ |
---|
89 | guint |
---|
90 | addactionflag(const char *action); |
---|
91 | |
---|
92 | /* returns the action string for a flag */ |
---|
93 | const char * |
---|
94 | addactionname(guint flag); |
---|
95 | |
---|
96 | /* turn a NULL-terminated list of void* arguments into a glist */ |
---|
97 | GList * |
---|
98 | makeglist(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 | |
---|
104 | GtkWidget * |
---|
105 | errmsg(GtkWindow *wind, const char *format, ...) |
---|
106 | #ifdef __GNUC__ |
---|
107 | __attribute__ ((format (printf, 2, 3))) |
---|
108 | #endif |
---|
109 | ; |
---|
110 | |
---|
111 | GtkWidget * |
---|
112 | errmsg_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 | |
---|
119 | GtkWidget * |
---|
120 | verrmsg(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 */ |
---|