2009-07-22 15:55:48 +00:00
|
|
|
/*
|
2011-01-19 13:48:47 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2006-08-13 00:26:52 +00:00
|
|
|
*
|
2010-12-27 19:18:17 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
2009-07-22 15:55:48 +00:00
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2009-08-10 20:04:08 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2009-07-22 15:55:48 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2006-08-13 00:26:52 +00:00
|
|
|
*
|
2009-07-22 20:39:12 +00:00
|
|
|
* $Id$
|
2009-07-22 15:55:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GTR_UTIL_H
|
|
|
|
#define GTR_UTIL_H
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
2010-04-21 19:23:27 +00:00
|
|
|
#include <glib.h>
|
2009-08-14 12:53:08 +00:00
|
|
|
#include <gtk/gtk.h>
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2010-07-03 00:25:22 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
|
|
|
|
extern const int mem_K;
|
|
|
|
extern const char * mem_K_str;
|
|
|
|
extern const char * mem_M_str;
|
|
|
|
extern const char * mem_G_str;
|
2010-07-06 20:25:54 +00:00
|
|
|
extern const char * mem_T_str;
|
2010-07-03 00:25:22 +00:00
|
|
|
|
|
|
|
extern const int disk_K;
|
|
|
|
extern const char * disk_K_str;
|
|
|
|
extern const char * disk_M_str;
|
|
|
|
extern const char * disk_G_str;
|
2010-07-06 20:25:54 +00:00
|
|
|
extern const char * disk_T_str;
|
2010-07-03 00:25:22 +00:00
|
|
|
|
|
|
|
extern const int speed_K;
|
|
|
|
extern const char * speed_K_str;
|
|
|
|
extern const char * speed_M_str;
|
|
|
|
extern const char * speed_G_str;
|
2010-07-06 20:25:54 +00:00
|
|
|
extern const char * speed_T_str;
|
2010-07-03 00:25:22 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
/* macro to shut up "unused parameter" warnings */
|
2008-05-18 16:44:30 +00:00
|
|
|
#ifndef UNUSED
|
2008-09-23 19:11:04 +00:00
|
|
|
#define UNUSED G_GNUC_UNUSED
|
2008-05-18 16:44:30 +00:00
|
|
|
#endif
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2010-03-20 14:53:08 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
GTR_UNICODE_UP,
|
|
|
|
GTR_UNICODE_DOWN,
|
2010-12-22 07:00:25 +00:00
|
|
|
GTR_UNICODE_INF,
|
|
|
|
GTR_UNICODE_BULLET
|
2010-03-20 14:53:08 +00:00
|
|
|
};
|
|
|
|
const char * gtr_get_unicode_string( int );
|
|
|
|
|
2010-06-22 22:30:58 +00:00
|
|
|
/* return a percent formatted string of either x.xx, xx.x or xxx */
|
|
|
|
char* tr_strlpercent( char * buf, double x, size_t buflen );
|
2010-03-20 14:53:08 +00:00
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
/* return a human-readable string for the size given in bytes. */
|
2009-07-22 15:55:48 +00:00
|
|
|
char* tr_strlsize( char * buf, guint64 size, size_t buflen );
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2008-01-04 18:52:39 +00:00
|
|
|
/* return a human-readable string for the given ratio. */
|
2009-07-22 15:55:48 +00:00
|
|
|
char* tr_strlratio( char * buf, double ratio, size_t buflen );
|
2008-01-04 18:52:39 +00:00
|
|
|
|
2007-12-26 06:38:33 +00:00
|
|
|
/* return a human-readable string for the time given in seconds. */
|
2009-07-22 15:55:48 +00:00
|
|
|
char* tr_strltime( char * buf, int secs, size_t buflen );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2009-07-22 15:55:48 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2010-04-23 01:46:02 +00:00
|
|
|
/* http://www.legaltorrents.com/some/announce/url --> legaltorrents.com */
|
2011-04-04 16:54:09 +00:00
|
|
|
void gtr_get_host_from_url( char * buf, size_t buflen, const char * url );
|
2010-04-23 01:46:02 +00:00
|
|
|
|
2009-11-22 16:20:22 +00:00
|
|
|
gboolean gtr_is_supported_url( const char * str );
|
|
|
|
|
|
|
|
gboolean gtr_is_magnet_link( const char * str );
|
|
|
|
|
2009-11-29 07:42:39 +00:00
|
|
|
gboolean gtr_is_hex_hashcode( const char * str );
|
|
|
|
|
2009-07-22 15:55:48 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2009-08-14 12:53:08 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GTR_LOCKFILE_SUCCESS = 0,
|
|
|
|
GTR_LOCKFILE_EOPEN,
|
|
|
|
GTR_LOCKFILE_ELOCK
|
|
|
|
}
|
|
|
|
gtr_lockfile_state_t;
|
|
|
|
|
|
|
|
gtr_lockfile_state_t gtr_lockfile( const char * filename );
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2010-09-22 16:44:38 +00:00
|
|
|
void gtr_open_uri( const char * uri );
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void gtr_open_file( const char * path );
|
2008-04-11 02:21:33 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
gboolean gtr_dbus_add_torrent( const char * filename );
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
gboolean gtr_dbus_present_window( void );
|
|
|
|
|
2010-09-22 16:44:38 +00:00
|
|
|
const char* gtr_get_help_uri( void );
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2009-07-22 15:55:48 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2009-07-22 20:39:12 +00:00
|
|
|
/* backwards-compatible wrapper around g_mkdir_with_parents() */
|
|
|
|
int gtr_mkdir_with_parents( const char *name, int mode );
|
|
|
|
|
2009-07-22 15:55:48 +00:00
|
|
|
/* backwards-compatible wrapper around gdk_threads_add_timeout_seconds() */
|
|
|
|
guint gtr_timeout_add_seconds( guint seconds, GSourceFunc func, gpointer data );
|
2009-06-29 17:22:35 +00:00
|
|
|
|
2009-07-22 15:55:48 +00:00
|
|
|
/* backwards-compatible wrapper around gdk_threads_add_idle() */
|
2010-12-23 22:31:28 +00:00
|
|
|
guint gtr_idle_add( GSourceFunc func, gpointer data );
|
2009-06-29 17:22:35 +00:00
|
|
|
|
2009-07-22 15:55:48 +00:00
|
|
|
/* backwards-compatible wrapper around gtk_widget_set_tooltip_text() */
|
|
|
|
void gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip );
|
2009-03-28 16:47:01 +00:00
|
|
|
|
2010-12-24 09:04:52 +00:00
|
|
|
/* backwards-compatible wrapper around gtk_widget_get_window() */
|
|
|
|
GdkWindow* gtr_widget_get_window( GtkWidget * w );
|
|
|
|
|
2010-06-26 16:07:15 +00:00
|
|
|
/* backwards-compatible wrapper around gtk_widget_get_realized() */
|
|
|
|
gboolean gtr_widget_get_realized( GtkWidget * w );
|
|
|
|
|
2010-07-24 03:07:04 +00:00
|
|
|
/* backwards-compatible wrapper around gtk_widget_set_visible() */
|
|
|
|
void gtr_widget_set_visible( GtkWidget *, gboolean );
|
|
|
|
|
2009-07-22 15:55:48 +00:00
|
|
|
/* backwards-compatible wrapper around g_object_ref_sink() */
|
2010-04-21 04:38:54 +00:00
|
|
|
gpointer gtr_object_ref_sink( gpointer object );
|
2008-06-01 15:46:20 +00:00
|
|
|
|
2010-08-06 14:38:54 +00:00
|
|
|
/* backwards-compatible wrapper around g_dngettext() */
|
|
|
|
const gchar* gtr_ngettext( const gchar*, const gchar*, gulong );
|
|
|
|
|
2010-12-22 03:12:47 +00:00
|
|
|
void gtr_dialog_set_content( GtkDialog * dialog, GtkWidget * content );
|
|
|
|
|
2010-02-02 07:51:45 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
GtkWidget * gtr_priority_combo_new( void );
|
2010-07-23 19:10:02 +00:00
|
|
|
#define gtr_priority_combo_get_value(w) gtr_combo_box_get_active_enum(w)
|
|
|
|
#define gtr_priority_combo_set_value(w,val) gtr_combo_box_set_active_enum(w,val)
|
2010-07-23 06:54:49 +00:00
|
|
|
|
2010-07-23 19:10:02 +00:00
|
|
|
GtkWidget * gtr_combo_box_new_enum ( const char * text_1, ... );
|
|
|
|
int gtr_combo_box_get_active_enum ( GtkComboBox * );
|
|
|
|
void gtr_combo_box_set_active_enum ( GtkComboBox *, int value );
|
2010-02-02 07:51:45 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2010-02-05 13:59:44 +00:00
|
|
|
void gtr_unrecognized_url_dialog( GtkWidget * parent, const char * url );
|
|
|
|
|
2010-06-25 17:40:55 +00:00
|
|
|
void gtr_http_failure_dialog( GtkWidget * parent, const char * url, long response_code );
|
2010-02-05 13:59:44 +00:00
|
|
|
|
2010-12-21 19:20:58 +00:00
|
|
|
void gtr_add_torrent_error_dialog( GtkWidget * window_or_child,
|
|
|
|
int err,
|
|
|
|
const char * filename );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
/* pop up the context menu if a user right-clicks.
|
|
|
|
if the row they right-click on isn't selected, select it. */
|
2009-07-22 15:55:48 +00:00
|
|
|
gboolean on_tree_view_button_pressed( GtkWidget * view,
|
|
|
|
GdkEventButton * event,
|
|
|
|
gpointer unused );
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2008-09-27 18:01:31 +00:00
|
|
|
/* if the click didn't specify a row, clear the selection */
|
2009-07-22 15:55:48 +00:00
|
|
|
gboolean on_tree_view_button_released( GtkWidget * view,
|
|
|
|
GdkEventButton * event,
|
|
|
|
gpointer unused );
|
2008-09-27 18:01:31 +00:00
|
|
|
|
2008-01-15 17:55:09 +00:00
|
|
|
|
2009-07-22 15:55:48 +00:00
|
|
|
/* move a file to the trashcan if GIO is available; otherwise, delete it */
|
2010-04-21 04:38:54 +00:00
|
|
|
int gtr_file_trash_or_remove( const char * filename );
|
2008-03-09 15:27:08 +00:00
|
|
|
|
2011-01-14 21:57:20 +00:00
|
|
|
void gtr_paste_clipboard_url_into_entry( GtkWidget * entry );
|
|
|
|
|
2011-01-21 16:32:27 +00:00
|
|
|
/* Only call gtk_label_set_text() if the new text differs from the old.
|
|
|
|
* This prevents the label from having to recalculate its size
|
|
|
|
* and prevents selected text in the label from being deselected */
|
|
|
|
void gtr_label_set_text( GtkLabel * lb, const char * text );
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2009-07-22 15:55:48 +00:00
|
|
|
#endif /* GTR_UTIL_H */
|