source: trunk/gtk/util.h @ 8846

Last change on this file since 8846 was 8846, checked in by charles, 13 years ago

remove some unused utilities. better commenting on the utils that remain.

  • Property svn:keywords set to Date Rev Author Id
File size: 3.9 KB
Line 
1/*
2 * This file Copyright (C) 2008-2009 Charles Kerr <charles@transmissionbt.com>
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:$
11 */
12
13#ifndef GTR_UTIL_H
14#define GTR_UTIL_H
15
16#include <sys/types.h>
17
18/* macro to shut up "unused parameter" warnings */
19#ifndef UNUSED
20 #define UNUSED G_GNUC_UNUSED
21#endif
22
23/* return a human-readable string for the size given in bytes. */
24char* tr_strlsize( char * buf, guint64  size, size_t buflen );
25
26/* return a human-readable string for the transfer rate given in bytes. */
27char* tr_strlspeed( char * buf, double KiBps, size_t buflen );
28
29/* return a human-readable string for the given ratio. */
30char* tr_strlratio( char * buf, double ratio, size_t buflen );
31
32/* return a human-readable string for the time given in seconds. */
33char* tr_strltime( char * buf, int secs, size_t buflen );
34
35/* similar to asctime, but is utf8-clean */
36char* gtr_localtime( time_t time );
37
38/* similar to asctime, but is utf8-clean */
39char* gtr_localtime2( char * buf, time_t time, size_t buflen );
40
41/* create a directory and any missing parent directories */
42int mkdir_p( const char *name, mode_t mode );
43
44/***
45****
46***/
47
48/* create a copy of a GSList of strings, this dups the actual strings too */
49GSList * dupstrlist( GSList * list );
50
51/* joins a GSList of strings into one string using an optional separator */
52char * joinstrlist( GSList *list, char *  sep );
53
54/* free a GSList of strings */
55void freestrlist( GSList *list );
56
57/* decodes a string that has been urlencoded */
58char * decode_uri( const char * uri );
59
60/* return a list of cleaned-up paths, with invalid directories removed */
61GSList * checkfilenames( int argc, char ** argv );
62
63/***
64****
65***/
66
67void        gtr_open_file( const char * path );
68
69gboolean    gtr_dbus_add_torrent( const char * filename );
70
71gboolean    gtr_dbus_present_window( void );
72
73char*       gtr_get_help_url( void );
74
75/***
76****
77***/
78
79/* GTK-related utilities */
80#ifdef GTK_MAJOR_VERSION
81
82/* backwards-compatible wrapper around gdk_threads_add_timeout_seconds() */
83guint gtr_timeout_add_seconds( guint seconds, GSourceFunc func, gpointer data );
84
85/* backwards-compatible wrapper around gdk_threads_add_idle() */
86void gtr_idle_add( GSourceFunc  func, gpointer data );
87
88/* backwards-compatible wrapper around gtk_orientable_set_orientation() */
89void gtr_toolbar_set_orientation( GtkToolbar * tb, GtkOrientation orientation );
90
91/* backwards-compatible wrapper around gtk_widget_set_tooltip_text() */
92void gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip );
93
94/* backwards-compatible wrapper around g_object_ref_sink() */
95gpointer tr_object_ref_sink( gpointer object );
96
97/***
98****
99***/
100
101/* create a button with the specified mnemonic and stock icon */
102GtkWidget * gtr_button_new_from_stock( const char * stock,
103                                       const char * mnemonic );
104
105void addTorrentErrorDialog( GtkWidget  * window_or_child,
106                            int          err,
107                            const char * filename );
108
109/* pop up the context menu if a user right-clicks.
110   if the row they right-click on isn't selected, select it. */
111gboolean on_tree_view_button_pressed( GtkWidget      * view,
112                                      GdkEventButton * event,
113                                      gpointer         unused );
114
115/* if the click didn't specify a row, clear the selection */
116gboolean on_tree_view_button_released( GtkWidget      * view,
117                                       GdkEventButton * event,
118                                       gpointer         unused );
119
120
121/* move a file to the trashcan if GIO is available; otherwise, delete it */
122int tr_file_trash_or_remove( const char * filename );
123
124#endif /* GTK_MAJOR_VERSION */
125
126#endif /* GTR_UTIL_H */
Note: See TracBrowser for help on using the repository browser.