source: trunk/gtk/util.h @ 10101

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

(trunk gtk) #2864 "when adding a non-BitTorrent? magnet link fails, explain why to the user" -- implemented for GTK+ client for 1.90

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