source: trunk/gtk/util.h @ 10505

Last change on this file since 10505 was 10505, checked in by charles, 12 years ago

(trunk gtk) #3143 "remote RPC calls cause gtk+ API calls to be made from the wrong thread" -- fixed in trunk for 2.00

  • Property svn:keywords set to Date Rev Author Id
File size: 4.4 KB
Line 
1/*
2 * This file Copyright (C) 2008-2010 Mnemosyne LLC
3 *
4 * This file is licensed by the GPL version 2.  Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id: util.h 10505 2010-04-21 04:38:54Z charles $
11 */
12
13#ifndef GTR_UTIL_H
14#define GTR_UTIL_H
15
16#include <sys/types.h>
17#include <gtk/gtk.h>
18
19/* macro to shut up "unused parameter" warnings */
20#ifndef UNUSED
21 #define UNUSED G_GNUC_UNUSED
22#endif
23
24enum
25{
26    GTR_UNICODE_UP,
27    GTR_UNICODE_DOWN,
28    GTR_UNICODE_INF
29};
30const char * gtr_get_unicode_string( int );
31
32
33/* return a human-readable string for the size given in bytes. */
34char* tr_strlsize( char * buf, guint64  size, size_t buflen );
35
36/* return a human-readable string for the transfer rate given in bytes. */
37char* tr_strlspeed( char * buf, double KiBps, size_t buflen );
38
39/* return a human-readable string for the given ratio. */
40char* tr_strlratio( char * buf, double ratio, size_t buflen );
41
42/* return a human-readable string for the time given in seconds. */
43char* tr_strltime( char * buf, int secs, size_t buflen );
44
45/* similar to asctime, but is utf8-clean */
46char* gtr_localtime( time_t time );
47
48/* similar to asctime, but is utf8-clean */
49char* gtr_localtime2( char * buf, time_t time, size_t buflen );
50
51/***
52****
53***/
54
55gboolean gtr_is_supported_url( const char * str );
56
57gboolean gtr_is_magnet_link( const char * str );
58
59gboolean gtr_is_hex_hashcode( const char * str );
60
61
62/* create a copy of a GSList of strings, this dups the actual strings too */
63GSList * dupstrlist( GSList * list );
64
65/* joins a GSList of strings into one string using an optional separator */
66char * joinstrlist( GSList *list, char *  sep );
67
68/* free a GSList of strings */
69void freestrlist( GSList *list );
70
71/* decodes a string that has been urlencoded */
72char * decode_uri( const char * uri );
73
74/***
75****
76***/
77
78typedef enum
79{
80    GTR_LOCKFILE_SUCCESS = 0,
81    GTR_LOCKFILE_EOPEN,
82    GTR_LOCKFILE_ELOCK
83}
84gtr_lockfile_state_t;
85
86gtr_lockfile_state_t gtr_lockfile( const char * filename );
87
88/***
89****
90***/
91
92void        gtr_open_file( const char * path );
93
94gboolean    gtr_dbus_add_torrent( const char * filename );
95
96gboolean    gtr_dbus_present_window( void );
97
98char*       gtr_get_help_url( void );
99
100/***
101****
102***/
103
104/* backwards-compatible wrapper around g_mkdir_with_parents() */
105int gtr_mkdir_with_parents( const char *name, int mode );
106
107/* backwards-compatible wrapper around gdk_threads_add_timeout_seconds() */
108guint gtr_timeout_add_seconds( guint seconds, GSourceFunc func, gpointer data );
109
110/* backwards-compatible wrapper around gdk_threads_add_idle() */
111void gtr_idle_add( GSourceFunc  func, gpointer data );
112
113/* backwards-compatible wrapper around gtk_orientable_set_orientation() */
114void gtr_toolbar_set_orientation( GtkToolbar * tb, GtkOrientation orientation );
115
116/* backwards-compatible wrapper around gtk_widget_set_tooltip_text() */
117void gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip );
118
119/* backwards-compatible wrapper around g_object_ref_sink() */
120gpointer gtr_object_ref_sink( gpointer object );
121
122/***
123****
124***/
125
126/* create a button with the specified mnemonic and stock icon */
127GtkWidget * gtr_button_new_from_stock( const char * stock,
128                                       const char * mnemonic );
129
130
131/***
132****
133***/
134
135void gtr_priority_combo_set_value( GtkWidget * w, tr_priority_t );
136
137tr_priority_t gtr_priority_combo_get_value( GtkWidget * w );
138
139GtkWidget * gtr_priority_combo_new( void );
140
141/***
142****
143***/
144
145void gtr_unrecognized_url_dialog( GtkWidget * parent, const char * url );
146
147
148void addTorrentErrorDialog( GtkWidget  * window_or_child,
149                            int          err,
150                            const char * filename );
151
152/* pop up the context menu if a user right-clicks.
153   if the row they right-click on isn't selected, select it. */
154gboolean on_tree_view_button_pressed( GtkWidget      * view,
155                                      GdkEventButton * event,
156                                      gpointer         unused );
157
158/* if the click didn't specify a row, clear the selection */
159gboolean on_tree_view_button_released( GtkWidget      * view,
160                                       GdkEventButton * event,
161                                       gpointer         unused );
162
163
164/* move a file to the trashcan if GIO is available; otherwise, delete it */
165int gtr_file_trash_or_remove( const char * filename );
166
167#endif /* GTR_UTIL_H */
Note: See TracBrowser for help on using the repository browser.