source: trunk/gtk/util.h @ 525

Last change on this file since 525 was 525, checked in by joshe, 16 years ago

Move the ETA cap of 99:59:59 from libtransmission to the MacOS X GUI.
Display the ETA better in the GTK GUI.

  • Property svn:keywords set to Date Rev Author Id
File size: 3.8 KB
Line 
1/*
2  $Id: util.h 525 2006-07-04 22:31:14Z joshe $
3
4  Copyright (c) 2005-2006 Joshua Elsasser. All rights reserved.
5   
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions
8  are met:
9   
10   1. Redistributions of source code must retain the above copyright
11      notice, this list of conditions and the following disclaimer.
12   2. Redistributions in binary form must reproduce the above copyright
13      notice, this list of conditions and the following disclaimer in the
14      documentation and/or other materials provided with the distribution.
15   
16  THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS "AS IS" AND
17  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#ifndef TG_UTIL_H
30#define TG_UTIL_H
31
32#include <sys/types.h>
33#include <stdarg.h>
34
35/* macro to shut up "unused parameter" warnings */
36#ifdef __GNUC__
37#define SHUTUP                  __attribute__((unused))
38#else
39#define SHUTUP
40#endif
41
42typedef void (*add_torrents_func_t)(void*,void*,GList*,const char*,guint);
43
44/* return number of items in array */
45#define ALEN(a)                 (sizeof(a) / sizeof((a)[0]))
46
47#define ISA(o, t)               (g_type_is_a(G_OBJECT_TYPE(G_OBJECT(o)), (t)))
48
49/* used for a callback function with a data parameter */
50typedef void (*callbackfunc_t)(void*);
51
52/* try to interpret a string as a textual representation of a boolean */
53/* note that this isn't localized */
54gboolean
55strbool(const char *str);
56
57/* return a human-readable string for the size given in bytes.
58   the string must be g_free()d */
59char *
60readablesize(guint64 size);
61
62/* return a human-readable string for the time given in seconds.
63   the string must be g_free()d */
64char *
65readabletime(int secs);
66
67/* returns a string representing the download ratio.
68   the string must be g_free()d */
69char *
70ratiostr(guint64 down, guint64 up);
71
72/* create a directory and any missing parent directories */
73gboolean
74mkdir_p(const char *name, mode_t mode);
75
76/* joins a GList of strings into one string using an optional separator */
77char *
78joinstrlist(GList *list, char *sep);
79
80/* free a GList of strings */
81void
82freestrlist(GList *list);
83
84/* decodes a string that has been urlencoded */
85char *
86urldecode(const char *str, int len);
87
88/* return a list of cleaned-up paths, with invalid directories removed */
89GList *
90checkfilenames(int argc, char **argv);
91
92/* returns the flag for an action string */
93guint
94addactionflag(const char *action);
95
96/* returns the action string for a flag */
97const char *
98addactionname(guint flag);
99
100/* turn a NULL-terminated list of void* arguments into a glist */
101GList *
102makeglist(void *ptr, ...);
103
104#ifdef GTK_MAJOR_VERSION
105
106/* if wind is NULL then you must call gtk_widget_show on the returned widget */
107
108GtkWidget *
109errmsg(GtkWindow *wind, const char *format, ...)
110#ifdef __GNUC__
111  __attribute__ ((format (printf, 2, 3)))
112#endif
113  ;
114
115GtkWidget *
116errmsg_full(GtkWindow *wind, callbackfunc_t func, void *data,
117            const char *format, ...)
118#ifdef __GNUC__
119  __attribute__ ((format (printf, 4, 5)))
120#endif
121  ;
122
123GtkWidget *
124verrmsg(GtkWindow *wind, callbackfunc_t func, void *data,
125        const char *format, va_list ap);
126
127#endif /* GTK_MAJOR_VERSION */
128
129#endif /* TG_UTIL_H */
Note: See TracBrowser for help on using the repository browser.