source: trunk/gtk/util.h @ 6559

Last change on this file since 6559 was 6559, checked in by muks, 13 years ago

Don't show an error when transmission is run twice

Instead, present the main window. This commit also auto-generates
the dbus bindings.

  • Property svn:keywords set to Date Rev Author Id
File size: 4.1 KB
Line 
1/******************************************************************************
2 * $Id: util.h 6559 2008-08-17 12:39:26Z muks $
3 *
4 * Copyright (c) 2005-2008 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#ifndef TG_UTIL_H
26#define TG_UTIL_H
27
28#include <sys/types.h>
29#include <stdarg.h>
30
31/* macro to shut up "unused parameter" warnings */
32#ifndef UNUSED
33#define UNUSED G_GNUC_UNUSED
34#endif
35
36/* return number of items in array */
37#define ALEN(a) ((signed)G_N_ELEMENTS(a))
38
39/* used for a callback function with a data parameter */
40typedef void (*callbackfunc_t)(void*);
41
42/* return a human-readable string for the size given in bytes. */
43char* tr_strlsize( char * buf, guint64 size, size_t buflen );
44
45/* return a human-readable string for the transfer rate given in bytes. */
46char* tr_strlspeed (char * buf, double KiBps, size_t buflen );
47
48/* return a human-readable string for the given ratio. */
49char* tr_strlratio( char * buf, double ratio, size_t buflen );
50
51/* return a human-readable string for the time given in seconds. */
52char* tr_strltime( char * buf, int secs, size_t buflen );
53
54char* gtr_localtime( time_t time );
55
56/* create a directory and any missing parent directories */
57gboolean
58mkdir_p(const char *name, mode_t mode);
59
60/* create a copy of a GSList of strings, this dups the actual strings too */
61GSList *
62dupstrlist( GSList * list );
63
64/* joins a GSList of strings into one string using an optional separator */
65char *
66joinstrlist(GSList *list, char *sep);
67
68/* free a GSList of strings */
69void
70freestrlist(GSList *list);
71
72/* decodes a string that has been urlencoded */
73char *
74decode_uri( const char * uri );
75
76/* return a list of cleaned-up paths, with invalid directories removed */
77GSList *
78checkfilenames( int argc, char ** argv );
79
80void gtr_open_file( const char * path );
81
82gboolean gtr_dbus_add_torrent( const char * filename );
83gboolean gtr_dbus_present_window( void );
84
85char* gtr_get_help_url( void );
86
87#ifdef GTK_MAJOR_VERSION
88
89GtkWidget * tr_button_new_from_stock( const char * stock,
90                                      const char * mnemonic );
91
92void addTorrentErrorDialog( GtkWidget  * window_or_child,
93                            int          err,
94                            const char * filename );
95
96/* create an error dialog, if wind is NULL or mapped then show dialog now,
97   otherwise show it when wind becomes mapped */
98void
99errmsg( GtkWindow * wind, const char * format, ... ) G_GNUC_PRINTF(2,3);
100
101/* create an error dialog but do not gtk_widget_show() it,
102   calls func( data ) when the dialog is closed */
103GtkWidget *
104errmsg_full( GtkWindow * wind, callbackfunc_t func, void * data,
105             const char * format, ... ) G_GNUC_PRINTF(4,5);
106
107/* pop up the context menu if a user right-clicks.
108   if the row they right-click on isn't selected, select it. */
109gboolean
110on_tree_view_button_pressed (GtkWidget       * view,
111                             GdkEventButton  * event,
112                             gpointer          unused);
113
114gpointer tr_object_ref_sink (gpointer object);
115
116void tr_file_trash_or_unlink( const char * filename );
117
118#endif /* GTK_MAJOR_VERSION */
119
120#endif /* TG_UTIL_H */
Note: See TracBrowser for help on using the repository browser.