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 10507 2010-04-21 19:23:27Z charles $ |
---|
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 | |
---|
34 | enum |
---|
35 | { |
---|
36 | GTR_UNICODE_UP, |
---|
37 | GTR_UNICODE_DOWN, |
---|
38 | GTR_UNICODE_INF |
---|
39 | }; |
---|
40 | const char * gtr_get_unicode_string( int ); |
---|
41 | |
---|
42 | |
---|
43 | /* return a human-readable string for the size given in bytes. */ |
---|
44 | char* tr_strlsize( char * buf, guint64 size, size_t buflen ); |
---|
45 | |
---|
46 | /* return a human-readable string for the transfer rate given in bytes. */ |
---|
47 | char* tr_strlspeed( char * buf, double KiBps, size_t buflen ); |
---|
48 | |
---|
49 | /* return a human-readable string for the given ratio. */ |
---|
50 | char* tr_strlratio( char * buf, double ratio, size_t buflen ); |
---|
51 | |
---|
52 | /* return a human-readable string for the time given in seconds. */ |
---|
53 | char* tr_strltime( char * buf, int secs, size_t buflen ); |
---|
54 | |
---|
55 | /* similar to asctime, but is utf8-clean */ |
---|
56 | char* gtr_localtime( time_t time ); |
---|
57 | |
---|
58 | /* similar to asctime, but is utf8-clean */ |
---|
59 | char* gtr_localtime2( char * buf, time_t time, size_t buflen ); |
---|
60 | |
---|
61 | /*** |
---|
62 | **** |
---|
63 | ***/ |
---|
64 | |
---|
65 | gboolean gtr_is_supported_url( const char * str ); |
---|
66 | |
---|
67 | gboolean gtr_is_magnet_link( const char * str ); |
---|
68 | |
---|
69 | gboolean gtr_is_hex_hashcode( const char * str ); |
---|
70 | |
---|
71 | |
---|
72 | /* create a copy of a GSList of strings, this dups the actual strings too */ |
---|
73 | GSList * dupstrlist( GSList * list ); |
---|
74 | |
---|
75 | /* joins a GSList of strings into one string using an optional separator */ |
---|
76 | char * joinstrlist( GSList *list, char * sep ); |
---|
77 | |
---|
78 | /* free a GSList of strings */ |
---|
79 | void freestrlist( GSList *list ); |
---|
80 | |
---|
81 | /* decodes a string that has been urlencoded */ |
---|
82 | char * decode_uri( const char * uri ); |
---|
83 | |
---|
84 | /*** |
---|
85 | **** |
---|
86 | ***/ |
---|
87 | |
---|
88 | typedef enum |
---|
89 | { |
---|
90 | GTR_LOCKFILE_SUCCESS = 0, |
---|
91 | GTR_LOCKFILE_EOPEN, |
---|
92 | GTR_LOCKFILE_ELOCK |
---|
93 | } |
---|
94 | gtr_lockfile_state_t; |
---|
95 | |
---|
96 | gtr_lockfile_state_t gtr_lockfile( const char * filename ); |
---|
97 | |
---|
98 | /*** |
---|
99 | **** |
---|
100 | ***/ |
---|
101 | |
---|
102 | void gtr_open_file( const char * path ); |
---|
103 | |
---|
104 | gboolean gtr_dbus_add_torrent( const char * filename ); |
---|
105 | |
---|
106 | gboolean gtr_dbus_present_window( void ); |
---|
107 | |
---|
108 | char* gtr_get_help_url( void ); |
---|
109 | |
---|
110 | /*** |
---|
111 | **** |
---|
112 | ***/ |
---|
113 | |
---|
114 | /* backwards-compatible wrapper around g_mkdir_with_parents() */ |
---|
115 | int gtr_mkdir_with_parents( const char *name, int mode ); |
---|
116 | |
---|
117 | /* backwards-compatible wrapper around gdk_threads_add_timeout_seconds() */ |
---|
118 | guint gtr_timeout_add_seconds( guint seconds, GSourceFunc func, gpointer data ); |
---|
119 | |
---|
120 | /* backwards-compatible wrapper around gdk_threads_add_idle() */ |
---|
121 | void gtr_idle_add( GSourceFunc func, gpointer data ); |
---|
122 | |
---|
123 | /* backwards-compatible wrapper around gtk_orientable_set_orientation() */ |
---|
124 | void gtr_toolbar_set_orientation( GtkToolbar * tb, GtkOrientation orientation ); |
---|
125 | |
---|
126 | /* backwards-compatible wrapper around gtk_widget_set_tooltip_text() */ |
---|
127 | void gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip ); |
---|
128 | |
---|
129 | /* backwards-compatible wrapper around g_object_ref_sink() */ |
---|
130 | gpointer gtr_object_ref_sink( gpointer object ); |
---|
131 | |
---|
132 | /*** |
---|
133 | **** |
---|
134 | ***/ |
---|
135 | |
---|
136 | /* create a button with the specified mnemonic and stock icon */ |
---|
137 | GtkWidget * gtr_button_new_from_stock( const char * stock, |
---|
138 | const char * mnemonic ); |
---|
139 | |
---|
140 | |
---|
141 | /*** |
---|
142 | **** |
---|
143 | ***/ |
---|
144 | |
---|
145 | void gtr_priority_combo_set_value( GtkWidget * w, tr_priority_t ); |
---|
146 | |
---|
147 | tr_priority_t gtr_priority_combo_get_value( GtkWidget * w ); |
---|
148 | |
---|
149 | GtkWidget * gtr_priority_combo_new( void ); |
---|
150 | |
---|
151 | /*** |
---|
152 | **** |
---|
153 | ***/ |
---|
154 | |
---|
155 | void gtr_unrecognized_url_dialog( GtkWidget * parent, const char * url ); |
---|
156 | |
---|
157 | |
---|
158 | void addTorrentErrorDialog( GtkWidget * window_or_child, |
---|
159 | int err, |
---|
160 | const char * filename ); |
---|
161 | |
---|
162 | /* pop up the context menu if a user right-clicks. |
---|
163 | if the row they right-click on isn't selected, select it. */ |
---|
164 | gboolean on_tree_view_button_pressed( GtkWidget * view, |
---|
165 | GdkEventButton * event, |
---|
166 | gpointer unused ); |
---|
167 | |
---|
168 | /* if the click didn't specify a row, clear the selection */ |
---|
169 | gboolean on_tree_view_button_released( GtkWidget * view, |
---|
170 | GdkEventButton * event, |
---|
171 | gpointer unused ); |
---|
172 | |
---|
173 | |
---|
174 | /* move a file to the trashcan if GIO is available; otherwise, delete it */ |
---|
175 | int gtr_file_trash_or_remove( const char * filename ); |
---|
176 | |
---|
177 | #endif /* GTR_UTIL_H */ |
---|