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