source: trunk/gtk/util.h @ 1605

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

Remove unused function.

  • Property svn:keywords set to Date Rev Author Id
File size: 6.0 KB
Line 
1/******************************************************************************
2 * $Id: util.h 1605 2007-03-29 19:53:40Z joshe $
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#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 )               ( ( signed )( sizeof(a) / sizeof( (a)[0] ) ) )
42
43/* used for a callback function with a data parameter */
44typedef void (*callbackfunc_t)(void*);
45
46/* flags indicating where and when an action is valid */
47#define ACTF_TOOL       ( 1 << 0 ) /* appear in the toolbar */
48#define ACTF_MENU       ( 1 << 1 ) /* appear in the popup menu */
49#define ACTF_ALWAYS     ( 1 << 2 ) /* available regardless of selection */
50#define ACTF_ACTIVE     ( 1 << 3 ) /* available for active torrent */
51#define ACTF_INACTIVE   ( 1 << 4 ) /* available for inactive torrent */
52#define ACTF_SEPARATOR  ( 1 << 5 ) /* dummy action to create menu separator */
53/* appear in the toolbar and the popup menu */
54#define ACTF_WHEREVER   ( ACTF_TOOL | ACTF_MENU )
55/* available if there is something selected */
56#define ACTF_WHATEVER   ( ACTF_ACTIVE | ACTF_INACTIVE )
57
58/* checking action flags against torrent status */
59#define ACT_ISAVAIL( flags, status ) \
60    ( ( ACTF_ACTIVE   & (flags) && TR_STATUS_ACTIVE   & (status) ) || \
61      ( ACTF_INACTIVE & (flags) && TR_STATUS_INACTIVE & (status) ) || \
62        ACTF_ALWAYS   & (flags) )
63
64/* column names for the model used to store torrent information */
65enum {
66  MC_NAME, MC_SIZE, MC_STAT, MC_ERR, MC_TERR,
67  MC_PROG, MC_DRATE, MC_URATE, MC_ETA, MC_PEERS,
68  MC_UPEERS, MC_DPEERS, MC_DOWN, MC_UP,
69  MC_TORRENT, MC_ROW_COUNT,
70};
71
72/* try to interpret a string as a textual representation of a boolean */
73/* note that this isn't localized */
74gboolean
75strbool(const char *str);
76
77/* return a human-readable string for the size given in bytes.
78   the string must be g_free()d */
79char *
80readablesize(guint64 size);
81
82/* return a human-readable string for the time given in seconds.
83   the string must be g_free()d */
84char *
85readabletime(int secs);
86
87/* returns a string representing the download ratio.
88   the string must be g_free()d */
89char *
90ratiostr(guint64 down, guint64 up);
91
92/* create a directory and any missing parent directories */
93gboolean
94mkdir_p(const char *name, mode_t mode);
95
96/* create a copy of a GList of strings, this dups the actual strings too */
97GList *
98dupstrlist( GList * list );
99
100/* joins a GList of strings into one string using an optional separator */
101char *
102joinstrlist(GList *list, char *sep);
103
104/* free a GList of strings */
105void
106freestrlist(GList *list);
107
108/* decodes a string that has been urlencoded */
109char *
110urldecode(const char *str, int len);
111
112/* return a list of cleaned-up paths, with invalid directories removed */
113GList *
114checkfilenames(int argc, char **argv);
115
116/* returns the flag for an action string */
117guint
118addactionflag(const char *action);
119
120/* returns the action string for a flag */
121const char *
122addactionname(guint flag);
123
124/* retrieve the global download directory */
125const char *
126getdownloaddir( void );
127
128#ifdef GTK_MAJOR_VERSION
129
130/* action handling */
131struct action
132{
133    int            id;
134    int            flags;
135    char         * label;
136    char         * stock;
137    GtkWidget    * tool;
138    GtkWidget    * menu;
139    callbackfunc_t func;
140    gpointer       data;
141};
142struct action *
143action_new( int id, int flags, const char * label, const char * stock );
144void
145action_free( struct action * act );
146GtkWidget *
147action_maketool( struct action * act, const char * key,
148                 GCallback func, gpointer data );
149GtkWidget *
150action_makemenu( struct action * act, const char * actkey,
151                 GtkAccelGroup * accel, const char * path, guint keyval,
152                 GCallback func, gpointer data );
153
154/* here there be dragons */
155void
156windowsizehack( GtkWidget * wind, GtkWidget * scroll, GtkWidget * view,
157                callbackfunc_t func, void * arg );
158
159/* create an error dialog, if wind is NULL or mapped then show dialog now,
160   otherwise show it when wind becomes mapped */
161void
162errmsg( GtkWindow * wind, const char * format, ... )
163#ifdef __GNUC__
164    __attribute__ (( format ( printf, 2, 3 ) ))
165#endif
166    ;
167
168/* create an error dialog but do not gtk_widget_show() it,
169   calls func( data ) when the dialog is closed */
170GtkWidget *
171errmsg_full( GtkWindow * wind, callbackfunc_t func, void * data,
172             const char * format, ... )
173#ifdef __GNUC__
174    __attribute__ (( format ( printf, 4, 5 ) ))
175#endif
176    ;
177
178/* varargs version of errmsg_full() */
179GtkWidget *
180verrmsg_full( GtkWindow * wind, callbackfunc_t func, void * data,
181              const char * format, va_list ap );
182
183#endif /* GTK_MAJOR_VERSION */
184
185#endif /* TG_UTIL_H */
Note: See TracBrowser for help on using the repository browser.