source: trunk/gtk/util.h @ 3206

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

preferences code refresh in the gtk+ client

  • Property svn:keywords set to Date Rev Author Id
File size: 4.5 KB
Line 
1/******************************************************************************
2 * $Id: util.h 3206 2007-09-27 20:57:58Z 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/* returns a string representing the download ratio.
67   the string must be g_free()d */
68char *
69ratiostr(guint64 down, guint64 up);
70
71/* create a directory and any missing parent directories */
72gboolean
73mkdir_p(const char *name, mode_t mode);
74
75/* create a copy of a GList of strings, this dups the actual strings too */
76GList *
77dupstrlist( GList * list );
78
79/* joins a GList of strings into one string using an optional separator */
80char *
81joinstrlist(GList *list, char *sep);
82
83/* free a GList of strings */
84void
85freestrlist(GList *list);
86
87/* decodes a string that has been urlencoded */
88char *
89urldecode(const char *str, int len);
90
91/* return a list of cleaned-up paths, with invalid directories removed */
92GList *
93checkfilenames(int argc, char **argv);
94
95/* returns the flag for an action string */
96enum tr_torrent_action
97toraddaction( const char * action );
98
99/* returns the action string for a flag */
100const char *
101toractionname( enum tr_torrent_action action );
102
103/* retrieve the global download directory */
104char *
105getdownloaddir( void );
106
107#ifdef GTK_MAJOR_VERSION
108
109/* here there be dragons */
110void
111sizingmagic( GtkWindow * wind, GtkScrolledWindow * scroll,
112             GtkPolicyType hscroll, GtkPolicyType vscroll );
113
114/* create an error dialog, if wind is NULL or mapped then show dialog now,
115   otherwise show it when wind becomes mapped */
116void
117errmsg( GtkWindow * wind, const char * format, ... )
118#ifdef __GNUC__
119    __attribute__ (( format ( printf, 2, 3 ) ))
120#endif
121    ;
122
123/* create an error dialog but do not gtk_widget_show() it,
124   calls func( data ) when the dialog is closed */
125GtkWidget *
126errmsg_full( GtkWindow * wind, callbackfunc_t func, void * data,
127             const char * format, ... )
128#ifdef __GNUC__
129    __attribute__ (( format ( printf, 4, 5 ) ))
130#endif
131    ;
132
133/* varargs version of errmsg_full() */
134GtkWidget *
135verrmsg_full( GtkWindow * wind, callbackfunc_t func, void * data,
136              const char * format, va_list ap );
137
138/* pop up the context menu if a user right-clicks.
139   if the row they right-click on isn't selected, select it. */
140gboolean
141on_tree_view_button_pressed (GtkWidget       * view,
142                             GdkEventButton  * event,
143                             gpointer          unused);
144
145#endif /* GTK_MAJOR_VERSION */
146
147#endif /* TG_UTIL_H */
Note: See TracBrowser for help on using the repository browser.