source: trunk/gtk/util.h @ 8757

Last change on this file since 8757 was 8757, checked in by charles, 13 years ago

(trunk gtk) #2251: gtk client should use GDK-safe versions of g_idle_add() and g_timeout_add*()

  • Property svn:keywords set to Date Rev Author Id
File size: 5.5 KB
Line 
1/******************************************************************************
2 * $Id: util.h 8757 2009-06-29 17:22:35Z charles $
3 *
4 * Copyright (c) 2005-2008 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#ifndef UNUSED
33 #define UNUSED G_GNUC_UNUSED
34#endif
35
36/* return number of items in array */
37#define ALEN( a ) ( (signed)G_N_ELEMENTS( a ) )
38
39/* used for a callback function with a data parameter */
40typedef void ( *callbackfunc_t )( void* );
41
42/* return a human-readable string for the size given in bytes. */
43char*       tr_strlsize( char *   buf,
44                         guint64  size,
45                         size_t   buflen );
46
47/* return a human-readable string for the transfer rate given in bytes. */
48char*       tr_strlspeed( char * buf,
49                          double KiBps,
50                          size_t buflen );
51
52/* return a human-readable string for the given ratio. */
53char*       tr_strlratio( char * buf,
54                          double ratio,
55                          size_t buflen );
56
57/* return a human-readable string for the time given in seconds. */
58char*       tr_strltime( char * buf,
59                         int    secs,
60                         size_t buflen );
61
62char*       gtr_localtime( time_t time );
63
64char*       gtr_localtime2( char * buf, time_t time, size_t buflen );
65
66/* create a directory and any missing parent directories */
67int         mkdir_p( const char *name,
68                     mode_t      mode );
69
70/* create a copy of a GSList of strings, this dups the actual strings too */
71GSList *    dupstrlist( GSList * list );
72
73/* joins a GSList of strings into one string using an optional separator */
74char *      joinstrlist( GSList *list,
75                         char *  sep );
76
77/* free a GSList of strings */
78void        freestrlist( GSList *list );
79
80/* decodes a string that has been urlencoded */
81char *      decode_uri( const char * uri );
82
83/* return a list of cleaned-up paths, with invalid directories removed */
84GSList *    checkfilenames( int     argc,
85                            char ** argv );
86
87void        gtr_open_file( const char * path );
88
89gboolean    gtr_dbus_add_torrent( const char * filename );
90
91gboolean    gtr_dbus_present_window( void );
92
93char*       gtr_get_help_url( void );
94
95#ifdef GTK_MAJOR_VERSION
96
97guint       gtr_timeout_add_seconds( guint       seconds,
98                                     GSourceFunc function,
99                                     gpointer    data );
100
101void        gtr_idle_add( GSourceFunc  func, 
102                          gpointer     data );
103
104void        gtr_toolbar_set_orientation( GtkToolbar      * toolbar,
105                                         GtkOrientation    orientation );
106
107void        gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip );
108
109GtkWidget * gtr_button_new_from_stock( const char * stock,
110                                       const char * mnemonic );
111
112void        addTorrentErrorDialog( GtkWidget *  window_or_child,
113                                   int          err,
114                                   const char * filename );
115
116/* create an error dialog, if wind is NULL or mapped then show dialog now,
117   otherwise show it when wind becomes mapped */
118void        errmsg( GtkWindow *  wind,
119                    const char * format,
120                    ... ) G_GNUC_PRINTF( 2, 3 );
121
122/* create an error dialog but do not gtk_widget_show() it,
123   calls func( data ) when the dialog is closed */
124GtkWidget * errmsg_full( GtkWindow *    wind,
125                         callbackfunc_t func,
126                         void *         data,
127                         const char *   format,
128                         ... ) G_GNUC_PRINTF( 4, 5 );
129
130/* pop up the context menu if a user right-clicks.
131   if the row they right-click on isn't selected, select it. */
132gboolean    on_tree_view_button_pressed( GtkWidget *      view,
133                                         GdkEventButton * event,
134                                         gpointer         unused );
135
136/* if the click didn't specify a row, clear the selection */
137gboolean    on_tree_view_button_released( GtkWidget *      view,
138                                          GdkEventButton * event,
139                                          gpointer         unused );
140
141
142
143gpointer    tr_object_ref_sink( gpointer object );
144
145int         tr_file_trash_or_remove( const char * filename );
146
147#endif /* GTK_MAJOR_VERSION */
148
149#endif /* TG_UTIL_H */
Note: See TracBrowser for help on using the repository browser.