source: trunk/gtk/util.h @ 3821

Last change on this file since 3821 was 3821, checked in by charles, 15 years ago

cruft removal: use tr_stat's ratio field instead of calculating it ourself.

  • Property svn:keywords set to Date Rev Author Id
File size: 4.4 KB
Line 
1/******************************************************************************
2 * $Id: util.h 3821 2007-11-15 04:19:53Z charles $
3 *
4 * Copyright (c) 2005-2007 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#define SHUTUP G_GNUC_UNUSED
33#define UNUSED G_GNUC_UNUSED
34
35/* NULL-safe version of strcmp */
36int tr_strcmp( const char*, const char * );
37
38/* XXX this shouldn't be here */
39enum tr_torrent_action { TR_TOR_LEAVE, TR_TOR_COPY, TR_TOR_MOVE };
40
41/* return number of items in array */
42#define ALEN(a) ((signed)G_N_ELEMENTS(a))
43
44/* used for a callback function with a data parameter */
45typedef void (*callbackfunc_t)(void*);
46
47/* return a human-readable string for the size given in bytes.
48   the string must be g_free()d */
49char *
50readablesize(guint64 size);
51
52/* return a human-readable string for the transfer rate given in bytes.
53   the string must be g_free()d */
54char *
55readablespeed (double KiBps);
56
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
63char *
64rfc822date (guint64 epoch_msec);
65
66/* create a directory and any missing parent directories */
67gboolean
68mkdir_p(const char *name, mode_t mode);
69
70/* create a copy of a GList of strings, this dups the actual strings too */
71GList *
72dupstrlist( GList * list );
73
74/* joins a GList of strings into one string using an optional separator */
75char *
76joinstrlist(GList *list, char *sep);
77
78/* free a GList of strings */
79void
80freestrlist(GList *list);
81
82/* decodes a string that has been urlencoded */
83char *
84urldecode(const char *str, int len);
85
86/* return a list of cleaned-up paths, with invalid directories removed */
87GList *
88checkfilenames( int argc, char ** argv );
89
90/* returns the flag for an action string */
91enum tr_torrent_action
92toraddaction( const char * action );
93
94/* returns the action string for a flag */
95const char *
96toractionname( enum tr_torrent_action action );
97
98/* retrieve the global download directory */
99char *
100getdownloaddir( void );
101
102#ifdef GTK_MAJOR_VERSION
103
104/* here there be dragons */
105void
106sizingmagic( GtkWindow * wind, GtkScrolledWindow * scroll,
107             GtkPolicyType hscroll, GtkPolicyType vscroll );
108
109/* create an error dialog, if wind is NULL or mapped then show dialog now,
110   otherwise show it when wind becomes mapped */
111void
112errmsg( GtkWindow * wind, const char * format, ... )
113#ifdef __GNUC__
114    __attribute__ (( format ( printf, 2, 3 ) ))
115#endif
116    ;
117
118/* create an error dialog but do not gtk_widget_show() it,
119   calls func( data ) when the dialog is closed */
120GtkWidget *
121errmsg_full( GtkWindow * wind, callbackfunc_t func, void * data,
122             const char * format, ... )
123#ifdef __GNUC__
124    __attribute__ (( format ( printf, 4, 5 ) ))
125#endif
126    ;
127
128/* varargs version of errmsg_full() */
129GtkWidget *
130verrmsg_full( GtkWindow * wind, callbackfunc_t func, void * data,
131              const char * format, va_list ap );
132
133/* pop up the context menu if a user right-clicks.
134   if the row they right-click on isn't selected, select it. */
135gboolean
136on_tree_view_button_pressed (GtkWidget       * view,
137                             GdkEventButton  * event,
138                             gpointer          unused);
139
140#endif /* GTK_MAJOR_VERSION */
141
142#endif /* TG_UTIL_H */
Note: See TracBrowser for help on using the repository browser.