(gtk) #1063: don't inhibit power management when torrents are paused

This commit is contained in:
Charles Kerr 2008-07-02 18:49:07 +00:00
parent 3aa164fbd2
commit 13a9af099f
3 changed files with 32 additions and 6 deletions

View File

@ -45,7 +45,7 @@
#include "tr-torrent.h"
#include "util.h"
static void tr_core_set_hibernation_allowed( TrCore * core, gboolean allowed );
static void maybeInhibitHibernation( TrCore * core );
static gboolean our_instance_adds_remote_torrents = FALSE;
@ -501,7 +501,7 @@ prefsChanged( TrCore * core, const char * key, gpointer data UNUSED )
}
else if( !strcmp( key, PREF_KEY_ALLOW_HIBERNATION ) )
{
tr_core_set_hibernation_allowed( core, pref_flag_get( key ) );
maybeInhibitHibernation( core );
}
#ifdef HAVE_GIO
else if( !strcmp( key, PREF_KEY_DIR_WATCH ) ||
@ -906,6 +906,9 @@ tr_core_update( TrCore * self )
/* resume sorting */
gtk_tree_sortable_set_sort_column_id( sortable, column, order );
/* maybe inhibit hibernation */
maybeInhibitHibernation( self );
}
void
@ -993,8 +996,7 @@ gtr_uninhibit_hibernation( guint inhibit_cookie )
#endif
void
static void
tr_core_set_hibernation_allowed( TrCore * core, gboolean allowed )
{
#ifdef HAVE_DBUS_GLIB
@ -1016,6 +1018,30 @@ tr_core_set_hibernation_allowed( TrCore * core, gboolean allowed )
#endif
}
static void
maybeInhibitHibernation( TrCore * core )
{
gboolean allowHibernation;
tr_handle * session = tr_core_handle( core );
/* allow hibernation unless we have active torrents */
allowHibernation = TRUE;
tr_torrent * tor = NULL;
while(( tor = tr_torrentNext( session, tor ))) {
if( tr_torrentGetStatus( tor ) != TR_STATUS_STOPPED ) {
allowHibernation = FALSE;
break;
}
}
/* even if we do have active torrents,
* maybe allow hibernation anyway... */
if( !allowHibernation )
allowHibernation = pref_flag_get( PREF_KEY_ALLOW_HIBERNATION );
tr_core_set_hibernation_allowed( core, allowHibernation );
}
/**
*** Prefs
**/

View File

@ -52,7 +52,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_ALLOW_HIBERNATION, TRUE );
pref_flag_set_default ( PREF_KEY_ALLOW_HIBERNATION, FALSE );
pref_flag_set_default ( PREF_KEY_BLOCKLIST_ENABLED, TR_DEFAULT_BLOCKLIST_ENABLED );
pref_string_set_default ( PREF_KEY_OPEN_DIALOG_FOLDER, g_get_home_dir( ) );

View File

@ -27,7 +27,7 @@ GtkWidget * tr_prefs_dialog_new( GObject * core, GtkWindow * parent );
#define PREF_KEY_OPTIONS_PROMPT "show-options-window"
#define PREF_KEY_DOWNLOAD_DIR "download-dir"
#define PREF_KEY_OPEN_DIALOG_FOLDER "open-dialog-dir"
#define PREF_KEY_ALLOW_HIBERNATION "allow-hibernation"
#define PREF_KEY_ALLOW_HIBERNATION "allow-hibernation-even-when-torrents-are-active"
#define PREF_KEY_DIR_WATCH "watch-dir"
#define PREF_KEY_DIR_WATCH_ENABLED "watch-dir-enabled"
#define PREF_KEY_SHOW_TRAY_ICON "show-tray-icon"