source: trunk/gtk/util.h @ 10822

Last change on this file since 10822 was 10822, checked in by Longinus00, 12 years ago

#3298:Prettier formating of percentages

  • Property svn:keywords set to Date Rev Author Id
File size: 5.0 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 10822 2010-06-22 22:30:58Z Longinus00 $
11 */
12
13#ifndef GTR_UTIL_H
14#define GTR_UTIL_H
15
16#include <sys/types.h>
17#include <glib.h>
18#include <gtk/gtk.h>
19
20/* portability wrapper around g_warn_if_fail() for older versions of glib */
21#ifdef g_warn_if_fail
22 #define gtr_warn_if_fail(expr) g_warn_if_fail(expr)
23#else
24 #define gtr_warn_if_fail(expr) do { if G_LIKELY (expr) ; else \
25                                       g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "%s:%d func(): %s: invariant failed: %s", \
26                                              __FILE__, __LINE__, G_STRFUNC, #expr ); } while(0)
27#endif
28
29/* macro to shut up "unused parameter" warnings */
30#ifndef UNUSED
31 #define UNUSED G_GNUC_UNUSED
32#endif
33
34enum
35{
36    GTR_UNICODE_UP,
37    GTR_UNICODE_DOWN,
38    GTR_UNICODE_INF
39};
40const char * gtr_get_unicode_string( int );
41
42/* return a percent formatted string of either x.xx, xx.x or xxx */
43char* tr_strlpercent( char * buf, double x, size_t buflen );
44
45/* return a human-readable string for the size given in bytes. */
46char* tr_strlsize( char * buf, guint64  size, size_t buflen );
47
48/* return a human-readable string for the transfer rate given in bytes. */
49char* tr_strlspeed( char * buf, double KiBps, size_t buflen );
50
51/* return a human-readable string for the given ratio. */
52char* tr_strlratio( char * buf, double ratio, size_t buflen );
53
54/* return a human-readable string for the time given in seconds. */
55char* tr_strltime( char * buf, int secs, size_t buflen );
56
57/* similar to asctime, but is utf8-clean */
58char* gtr_localtime( time_t time );
59
60/***
61****
62***/
63
64/* http://www.legaltorrents.com/some/announce/url --> legaltorrents.com */
65char* gtr_get_host_from_url( const char * url );
66
67gboolean gtr_is_supported_url( const char * str );
68
69gboolean gtr_is_magnet_link( const char * str );
70
71gboolean gtr_is_hex_hashcode( const char * str );
72
73
74/* create a copy of a GSList of strings, this dups the actual strings too */
75GSList * dupstrlist( GSList * list );
76
77/* joins a GSList of strings into one string using an optional separator */
78char * joinstrlist( GSList *list, char *  sep );
79
80/* free a GSList of strings */
81void freestrlist( GSList *list );
82
83/* decodes a string that has been urlencoded */
84char * decode_uri( const char * uri );
85
86/***
87****
88***/
89
90typedef enum
91{
92    GTR_LOCKFILE_SUCCESS = 0,
93    GTR_LOCKFILE_EOPEN,
94    GTR_LOCKFILE_ELOCK
95}
96gtr_lockfile_state_t;
97
98gtr_lockfile_state_t gtr_lockfile( const char * filename );
99
100/***
101****
102***/
103
104void        gtr_open_file( const char * path );
105
106gboolean    gtr_dbus_add_torrent( const char * filename );
107
108gboolean    gtr_dbus_present_window( void );
109
110char*       gtr_get_help_url( void );
111
112/***
113****
114***/
115
116/* backwards-compatible wrapper around g_mkdir_with_parents() */
117int gtr_mkdir_with_parents( const char *name, int mode );
118
119/* backwards-compatible wrapper around gdk_threads_add_timeout_seconds() */
120guint gtr_timeout_add_seconds( guint seconds, GSourceFunc func, gpointer data );
121
122/* backwards-compatible wrapper around gdk_threads_add_idle() */
123void gtr_idle_add( GSourceFunc  func, gpointer data );
124
125/* backwards-compatible wrapper around gtk_orientable_set_orientation() */
126void gtr_toolbar_set_orientation( GtkToolbar * tb, GtkOrientation orientation );
127
128/* backwards-compatible wrapper around gtk_widget_set_tooltip_text() */
129void gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip );
130
131/* backwards-compatible wrapper around g_object_ref_sink() */
132gpointer gtr_object_ref_sink( gpointer object );
133
134/***
135****
136***/
137
138/* create a button with the specified mnemonic and stock icon */
139GtkWidget * gtr_button_new_from_stock( const char * stock,
140                                       const char * mnemonic );
141
142
143/***
144****
145***/
146
147void gtr_priority_combo_set_value( GtkWidget * w, tr_priority_t );
148
149tr_priority_t gtr_priority_combo_get_value( GtkWidget * w );
150
151GtkWidget * gtr_priority_combo_new( void );
152
153/***
154****
155***/
156
157void gtr_unrecognized_url_dialog( GtkWidget * parent, const char * url );
158
159
160void addTorrentErrorDialog( GtkWidget  * window_or_child,
161                            int          err,
162                            const char * filename );
163
164/* pop up the context menu if a user right-clicks.
165   if the row they right-click on isn't selected, select it. */
166gboolean on_tree_view_button_pressed( GtkWidget      * view,
167                                      GdkEventButton * event,
168                                      gpointer         unused );
169
170/* if the click didn't specify a row, clear the selection */
171gboolean on_tree_view_button_released( GtkWidget      * view,
172                                       GdkEventButton * event,
173                                       gpointer         unused );
174
175
176/* move a file to the trashcan if GIO is available; otherwise, delete it */
177int gtr_file_trash_or_remove( const char * filename );
178
179#endif /* GTR_UTIL_H */
Note: See TracBrowser for help on using the repository browser.