mirror of
https://github.com/transmission/transmission
synced 2025-03-16 00:39:34 +00:00
(gtk) #307: inhibit/prevent hibernation when downloading
This commit is contained in:
parent
d9a90542b6
commit
f467beedb5
8 changed files with 111 additions and 2 deletions
15
configure.ac
15
configure.ac
|
@ -15,11 +15,13 @@ GLIB_MINIMUM=2.6.0
|
|||
GTK_MINIMUM=2.6.0
|
||||
WX_MINIMUM=2.6.0
|
||||
LIBNOTIFY_MINIMUM=0.4.4
|
||||
DBUS_GLIB_MINIMUM=0.70
|
||||
AC_SUBST(GIO_MINIMUM)
|
||||
AC_SUBST(GLIB_MINIMUM)
|
||||
AC_SUBST(GTK_MINIMUM)
|
||||
AC_SUBST(WX_MINIMUM)
|
||||
AC_SUBST(LIBNOTIFY_MINIMUM)
|
||||
AC_SUBST(DBUS_GLIB_MINIMUM)
|
||||
|
||||
AC_PROG_CC
|
||||
AC_PROG_CXX
|
||||
|
@ -116,6 +118,16 @@ if test "x$use_libnotify" = "xyes"; then
|
|||
AC_DEFINE([HAVE_LIBNOTIFY], 1)
|
||||
fi
|
||||
|
||||
PKG_CHECK_MODULES([DBUS_GLIB],
|
||||
[dbus-glib-1 >= $DBUS_GLIB_MINIMUM],
|
||||
[use_dbus_glib=yes],
|
||||
[use_dbus_glib=no])
|
||||
AC_SUBST(DBUS_GLIB_LIBS)
|
||||
AC_SUBST(DBUS_GLIB_CFLAGS)
|
||||
if test "x$use_dbus_glib" = "xyes"; then
|
||||
AC_DEFINE([HAVE_DBUS_GLIB], 1)
|
||||
fi
|
||||
|
||||
AC_CHECK_HEADERS([libintl.h])
|
||||
IT_PROG_INTLTOOL([0.23],[no-xml])
|
||||
GETTEXT_PACKAGE=transmission
|
||||
|
@ -289,8 +301,9 @@ Configuration:
|
|||
Build Daemon: ${build_daemon}
|
||||
Build BeOS client: ${build_beos}
|
||||
Build GTK+ client: ${build_gtk}
|
||||
... libnotify support: ${use_libnotify}
|
||||
... gio support: ${use_gio}
|
||||
... dbus-glib support: ${use_dbus_glib}
|
||||
... libnotify support: ${use_libnotify}
|
||||
Build OS X client: ${build_darwin}
|
||||
Build wxWidgets client: ${build_wx}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ AM_CFLAGS = \
|
|||
$(OPENSSL_CFLAGS) \
|
||||
$(PTHREAD_CFLAGS) \
|
||||
$(GIO_CFLAGS) \
|
||||
$(DBUS_GLIB_CFLAGS) \
|
||||
$(LIBNOTIFY_CFLAGS)
|
||||
|
||||
noinst_HEADERS = \
|
||||
|
@ -75,6 +76,7 @@ transmission_LDADD = \
|
|||
$(GTK_LIBS) \
|
||||
$(GIO_LIBS) \
|
||||
$(LIBNOTIFY_LIBS) \
|
||||
$(DBUS_GLIB_LIBS) \
|
||||
$(OPENSSL_LIBS) \
|
||||
$(PTHREAD_LIBS) -lm
|
||||
|
||||
|
|
|
@ -263,6 +263,8 @@ setupsighandlers( void )
|
|||
int
|
||||
main( int argc, char ** argv )
|
||||
{
|
||||
gboolean do_inhibit;
|
||||
guint inhibit_cookie;
|
||||
char * err;
|
||||
struct cbdata * cbdata;
|
||||
GSList * argfiles;
|
||||
|
@ -338,8 +340,15 @@ main( int argc, char ** argv )
|
|||
g_free( err );
|
||||
}
|
||||
|
||||
do_inhibit = pref_flag_get( PREF_KEY_INHIBIT_HIBERNATION );
|
||||
if( do_inhibit )
|
||||
inhibit_cookie = gtr_inhibit_hibernation( );
|
||||
|
||||
gtk_main();
|
||||
|
||||
if( do_inhibit )
|
||||
gtr_uninhibit_hibernation( inhibit_cookie );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ tr_prefs_init_global( void )
|
|||
#endif
|
||||
|
||||
pref_int_set_default ( PREF_KEY_PEER_SOCKET_TOS, TR_DEFAULT_PEER_SOCKET_TOS );
|
||||
|
||||
pref_flag_set_default ( PREF_KEY_INHIBIT_HIBERNATION, TRUE );
|
||||
pref_flag_set_default ( PREF_KEY_BLOCKLIST_ENABLED, FALSE );
|
||||
|
||||
pref_string_set_default ( PREF_KEY_OPEN_DIALOG_FOLDER, g_get_home_dir( ) );
|
||||
|
|
|
@ -27,6 +27,7 @@ GtkWidget * tr_prefs_dialog_new( GObject * core, GtkWindow * parent );
|
|||
#define PREF_KEY_OPTIONS_PROMPT "show-options-window"
|
||||
#define PREF_KEY_DIR_DEFAULT "default-download-directory"
|
||||
#define PREF_KEY_OPEN_DIALOG_FOLDER "open-dialog-folder"
|
||||
#define PREF_KEY_INHIBIT_HIBERNATION "inhibit-hibernation"
|
||||
#define PREF_KEY_DIR_WATCH "watch-folder"
|
||||
#define PREF_KEY_DIR_WATCH_ENABLED "watch-folder-enabled"
|
||||
#define PREF_KEY_START "start-added-torrents"
|
||||
|
|
78
gtk/util.c
78
gtk/util.c
|
@ -32,10 +32,14 @@
|
|||
#ifdef HAVE_GIO
|
||||
#include <gio/gio.h> /* g_file_trash() */
|
||||
#endif
|
||||
#ifdef HAVE_DBUS_GLIB
|
||||
#include <dbus/dbus-glib.h>
|
||||
#endif
|
||||
|
||||
#include <libevent/evhttp.h>
|
||||
|
||||
#include <libtransmission/transmission.h> /* TR_RATIO_NA, TR_RATIO_INF */
|
||||
#include <libtransmission/utils.h> /* tr_inf */
|
||||
|
||||
#include "conf.h"
|
||||
#include "tr-prefs.h"
|
||||
|
@ -461,3 +465,77 @@ gtr_open_file( const char * path )
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_DBUS_GLIB
|
||||
static DBusGProxy*
|
||||
get_hibernation_inhibit_proxy( void )
|
||||
{
|
||||
GError * error = NULL;
|
||||
DBusGConnection * conn;
|
||||
|
||||
conn = dbus_g_bus_get( DBUS_BUS_SESSION, &error );
|
||||
if( error )
|
||||
{
|
||||
g_warning ("DBUS cannot connect : %s", error->message);
|
||||
g_error_free (error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dbus_g_proxy_new_for_name (conn,
|
||||
"org.freedesktop.PowerManagement",
|
||||
"/org/freedesktop/PowerManagement/Inhibit",
|
||||
"org.freedesktop.PowerManagement.Inhibit" );
|
||||
}
|
||||
#endif
|
||||
|
||||
guint
|
||||
gtr_inhibit_hibernation( void )
|
||||
{
|
||||
guint inhibit_cookie = 0;
|
||||
#ifdef HAVE_DBUS_GLIB
|
||||
DBusGProxy * proxy = get_hibernation_inhibit_proxy( );
|
||||
if( proxy )
|
||||
{
|
||||
GError * error = NULL;
|
||||
const char * application = _( "Transmission Bittorrent Client" );
|
||||
const char * reason = _( "BitTorrent Activity" );
|
||||
gboolean success = dbus_g_proxy_call( proxy, "Inhibit", &error,
|
||||
G_TYPE_STRING, application,
|
||||
G_TYPE_STRING, reason,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_UINT, &inhibit_cookie,
|
||||
G_TYPE_INVALID );
|
||||
if( success )
|
||||
tr_inf( _( "Desktop hibernation disabled while Transmission is running" ) );
|
||||
else {
|
||||
tr_err( _( "Couldn't disable desktop hibernation: %s." ), error->message );
|
||||
g_error_free( error );
|
||||
}
|
||||
|
||||
g_object_unref( G_OBJECT( proxy ) );
|
||||
}
|
||||
#endif
|
||||
return inhibit_cookie;
|
||||
}
|
||||
|
||||
void
|
||||
gtr_uninhibit_hibernation( guint inhibit_cookie )
|
||||
{
|
||||
#ifdef HAVE_DBUS_GLIB
|
||||
DBusGProxy * proxy = get_hibernation_inhibit_proxy( );
|
||||
if( proxy )
|
||||
{
|
||||
GError * error = NULL;
|
||||
gboolean success = dbus_g_proxy_call( proxy, "UnInhibit", &error,
|
||||
G_TYPE_UINT, inhibit_cookie,
|
||||
G_TYPE_INVALID,
|
||||
G_TYPE_INVALID );
|
||||
if( !success ) {
|
||||
g_warning( "Couldn't uninhibit the system from suspending: %s.", error->message );
|
||||
g_error_free( error );
|
||||
}
|
||||
|
||||
g_object_unref( G_OBJECT( proxy ) );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -85,6 +85,10 @@ getdownloaddir( void );
|
|||
|
||||
void gtr_open_file( const char * path );
|
||||
|
||||
guint gtr_inhibit_hibernation( void );
|
||||
|
||||
void gtr_uninhibit_hibernation( guint );
|
||||
|
||||
#ifdef GTK_MAJOR_VERSION
|
||||
|
||||
/* here there be dragons */
|
||||
|
|
|
@ -15,10 +15,12 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
|
|||
BuildRequires: glib2-devel >= @GLIB_REQUIRED@
|
||||
BuildRequires: gtk2-devel >= @GTK_REQUIRED@
|
||||
BuildRequires: libnotify-devel >= @LIBNOTIFY_REQUIRED@
|
||||
BuildRequires: dbus-glib-devel >= @DBUS_GLIB_REQUIRED@
|
||||
|
||||
Requires: glib2 >= @GLIB_REQUIRED@
|
||||
Requires: gtk2 >= @GTK_REQUIRED@
|
||||
Requires: libnotify >= @LIBNOTIFY_REQUIRED@
|
||||
Requires: dbus-glib >= @DBUS_GLIB_REQUIRED@
|
||||
|
||||
Provides: %{name}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue