2007-07-23 21:59:32 +00:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2007-03-26 01:03:00 +00:00
# dialogs.py
#
# Copyright (C) Zach Tibbitts 2006 <zach@collegegeek.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, write to:
2007-07-11 04:22:44 +00:00
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
2007-06-12 16:33:32 +00:00
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
2007-03-26 01:03:00 +00:00
2007-07-16 13:31:30 +00:00
import gtk
2007-07-11 04:22:44 +00:00
import common
import dgtk
2007-08-05 04:07:17 +00:00
import files
2007-07-11 04:22:44 +00:00
import pref
2007-03-26 01:03:00 +00:00
2007-07-09 04:40:34 +00:00
PREFS_FILENAME = " prefs.state "
2007-03-26 01:03:00 +00:00
class PreferencesDlg :
2007-07-16 13:59:22 +00:00
def __init__ ( self , preferences , active_port ) :
2007-07-11 04:22:44 +00:00
self . glade = gtk . glade . XML ( common . get_glade_file ( " preferences_dialog.glade " ) , domain = ' deluge ' )
self . dialog = self . glade . get_widget ( " pref_dialog " )
2007-08-05 20:13:24 +00:00
self . dialog . set_position ( gtk . WIN_POS_CENTER )
2007-07-11 04:22:44 +00:00
self . dialog . set_icon_from_file ( common . get_pixmap ( " deluge32.png " ) )
self . glade . signal_autoconnect ( {
2007-08-01 01:00:10 +00:00
' toggle_ui ' : self . toggle_ui ,
2007-08-09 16:56:49 +00:00
' on_btn_testport_clicked ' : self . TestPort ,
' on_combo_file_manager_entry_focus_in_event ' : self . on_combo_file_manager_entry_focus_in_event ,
' on_txt_open_folder_location_focus_in_event ' : self . on_txt_open_folder_location_focus_in_event ,
' on_radio_open_folder_custom_focus_in_event ' : self . on_radio_open_folder_custom_focus_in_event
2007-07-11 04:22:44 +00:00
} )
2007-07-16 13:59:22 +00:00
2007-07-11 04:22:44 +00:00
self . preferences = preferences
2007-07-16 13:59:22 +00:00
self . active_port = str ( active_port )
2007-07-11 04:22:44 +00:00
2007-08-06 00:40:18 +00:00
def show ( self , interface , window ) :
2007-07-11 04:22:44 +00:00
# Load settings into dialog
try :
2007-08-08 21:45:18 +00:00
self . glade . get_widget ( " combo_file_manager " ) . set_active ( self . preferences . get ( " file_manager " ) )
2007-08-08 23:03:44 +00:00
self . glade . get_widget ( " txt_open_folder_location " ) . set_text ( self . preferences . get ( " open_folder_location " ) )
2007-08-10 21:32:20 +00:00
self . glade . get_widget ( " radio_open_folder_stock " ) . set_active ( self . preferences . get ( " open_folder_stock " ) )
self . glade . get_widget ( " radio_open_folder_custom " ) . set_active ( not self . preferences . get ( " open_folder_stock " ) )
2007-07-11 04:22:44 +00:00
self . glade . get_widget ( " combo_encin " ) . set_active ( self . preferences . get ( " encin_state " ) )
self . glade . get_widget ( " combo_encout " ) . set_active ( self . preferences . get ( " encout_state " ) )
self . glade . get_widget ( " combo_enclevel " ) . set_active ( self . preferences . get ( " enclevel_type " ) )
2007-08-01 19:57:32 +00:00
self . glade . get_widget ( " combo_peer_proxy_type " ) . set_active ( self . preferences . get ( " peer_proxy_type " ) )
self . glade . get_widget ( " combo_dht_proxy_type " ) . set_active ( self . preferences . get ( " dht_proxy_type " ) )
self . glade . get_widget ( " combo_tracker_proxy_type " ) . set_active ( self . preferences . get ( " tracker_proxy_type " ) )
self . glade . get_widget ( " combo_web_proxy_type " ) . set_active ( self . preferences . get ( " web_proxy_type " ) )
2007-08-07 03:09:18 +00:00
self . glade . get_widget ( " chk_send_info " ) . set_active ( self . preferences . get ( " send_info " ) )
2007-07-11 04:22:44 +00:00
self . glade . get_widget ( " chk_pref_rc4 " ) . set_active ( self . preferences . get ( " pref_rc4 " ) )
self . glade . get_widget ( " chk_peer_proxy " ) . set_active ( self . preferences . get ( " peer_proxy " ) )
self . glade . get_widget ( " chk_tracker_proxy " ) . set_active ( self . preferences . get ( " tracker_proxy " ) )
self . glade . get_widget ( " chk_dht_proxy " ) . set_active ( self . preferences . get ( " dht_proxy " ) )
self . glade . get_widget ( " chk_upnp " ) . set_active ( self . preferences . get ( " use_upnp " ) )
2007-07-28 18:58:59 +00:00
self . glade . get_widget ( " chk_random_port " ) . set_active ( self . preferences . get ( " random_port " ) )
2007-07-11 04:22:44 +00:00
self . glade . get_widget ( " chk_natpmp " ) . set_active ( self . preferences . get ( " use_natpmp " ) )
self . glade . get_widget ( " chk_utpex " ) . set_active ( self . preferences . get ( " use_utpex " ) )
2007-08-01 04:14:58 +00:00
self . glade . get_widget ( " chk_new_releases " ) . set_active ( self . preferences . get ( " new_releases " ) )
2007-07-11 04:22:44 +00:00
self . glade . get_widget ( " chk_use_tray " ) . set_active ( self . preferences . get ( " enable_system_tray " ) )
self . glade . get_widget ( " chk_min_on_close " ) . set_active ( self . preferences . get ( " close_to_tray " ) )
2007-08-11 01:18:50 +00:00
self . glade . get_widget ( " chk_start_in_tray " ) . set_active ( self . preferences . get ( " start_in_tray " ) )
2007-07-11 04:22:44 +00:00
self . glade . get_widget ( " chk_lock_tray " ) . set_active ( self . preferences . get ( " lock_tray " ) )
self . glade . get_widget ( " txt_tray_passwd " ) . set_text ( self . preferences . get ( " tray_passwd " ) )
2007-08-01 19:57:32 +00:00
self . glade . get_widget ( " txt_peer_proxy_hostname " ) . set_text ( self . preferences . get ( " peer_proxy_hostname " ) )
self . glade . get_widget ( " txt_peer_proxy_username " ) . set_text ( self . preferences . get ( " peer_proxy_username " ) )
self . glade . get_widget ( " txt_peer_proxy_password " ) . set_text ( self . preferences . get ( " peer_proxy_password " ) )
self . glade . get_widget ( " txt_dht_proxy_hostname " ) . set_text ( self . preferences . get ( " dht_proxy_hostname " ) )
self . glade . get_widget ( " txt_dht_proxy_username " ) . set_text ( self . preferences . get ( " dht_proxy_username " ) )
self . glade . get_widget ( " txt_dht_proxy_password " ) . set_text ( self . preferences . get ( " dht_proxy_password " ) )
self . glade . get_widget ( " txt_web_proxy_hostname " ) . set_text ( self . preferences . get ( " web_proxy_hostname " ) )
self . glade . get_widget ( " txt_web_proxy_username " ) . set_text ( self . preferences . get ( " web_proxy_username " ) )
self . glade . get_widget ( " txt_web_proxy_password " ) . set_text ( self . preferences . get ( " web_proxy_password " ) )
2007-07-11 04:22:44 +00:00
self . glade . get_widget ( " download_path_button " ) . set_filename ( self . preferences . get ( " default_download_path " ) )
2007-07-15 19:24:37 +00:00
self . glade . get_widget ( " chk_enable_files_dialog " ) . set_active ( self . preferences . get ( " enable_files_dialog " ) )
2007-07-23 23:29:37 +00:00
self . glade . get_widget ( " chk_prioritize_first_last_pieces " ) . set_active ( self . preferences . get ( " prioritize_first_last_pieces " ) )
2007-08-10 21:32:20 +00:00
self . glade . get_widget ( " radio_compact_allocation " ) . set_active ( self . preferences . get ( " use_compact_storage " ) )
self . glade . get_widget ( " radio_full_allocation " ) . set_active ( not self . preferences . get ( " use_compact_storage " ) )
2007-07-16 13:59:22 +00:00
self . glade . get_widget ( " active_port_label " ) . set_text ( str ( self . active_port ) )
2007-07-11 04:22:44 +00:00
self . glade . get_widget ( " spin_port_min " ) . set_value ( self . preferences . get ( " listen_on " ) [ 0 ] )
self . glade . get_widget ( " spin_port_max " ) . set_value ( self . preferences . get ( " listen_on " ) [ 1 ] )
self . glade . get_widget ( " spin_max_upload " ) . set_value ( self . preferences . get ( " max_upload_speed " ) )
2007-08-08 19:59:46 +00:00
self . glade . get_widget ( " spin_max_upload_slots_global " ) . set_value ( float ( self . preferences . get ( " max_upload_slots_global " ) ) )
self . glade . get_widget ( " spin_max_upload_slots_per_torrent " ) . set_value ( float ( self . preferences . get ( " max_upload_slots_per_torrent " ) ) )
2007-07-11 04:22:44 +00:00
self . glade . get_widget ( " spin_max_download " ) . set_value ( self . preferences . get ( " max_download_speed " ) )
2007-08-08 19:59:46 +00:00
self . glade . get_widget ( " spin_max_connections_global " ) . set_value ( self . preferences . get ( " max_connections_global " ) )
self . glade . get_widget ( " spin_max_connections_per_torrent " ) . set_value ( self . preferences . get ( " max_connections_per_torrent " ) )
2007-08-01 19:57:32 +00:00
self . glade . get_widget ( " spin_peer_proxy_port " ) . set_value ( self . preferences . get ( " peer_proxy_port " ) )
self . glade . get_widget ( " spin_tracker_proxy_port " ) . set_value ( self . preferences . get ( " tracker_proxy_port " ) )
self . glade . get_widget ( " spin_dht_proxy_port " ) . set_value ( self . preferences . get ( " dht_proxy_port " ) )
self . glade . get_widget ( " spin_web_proxy_port " ) . set_value ( self . preferences . get ( " web_proxy_port " ) )
2007-07-11 04:22:44 +00:00
self . glade . get_widget ( " spin_torrents " ) . set_value ( float ( self . preferences . get ( " max_active_torrents " ) ) )
self . glade . get_widget ( " chk_seedbottom " ) . set_active ( self . preferences . get ( " queue_seeds_to_bottom " ) )
2007-07-17 05:24:43 +00:00
self . glade . get_widget ( " chk_queue_above_completed " ) . set_sensitive ( self . preferences . get ( " queue_seeds_to_bottom " ) )
self . glade . get_widget ( " chk_queue_above_completed " ) . set_active ( self . preferences . get ( " queue_above_completed " ) )
2007-07-11 04:22:44 +00:00
self . glade . get_widget ( " chk_autoseed " ) . set_active ( self . preferences . get ( " auto_end_seeding " ) )
2007-07-17 04:51:11 +00:00
self . glade . get_widget ( " chk_clear_max_ratio_torrents " ) . set_sensitive ( self . preferences . get ( " auto_end_seeding " ) )
self . glade . get_widget ( " chk_clear_max_ratio_torrents " ) . set_active ( self . preferences . get ( " clear_max_ratio_torrents " ) )
2007-07-11 04:22:44 +00:00
self . glade . get_widget ( " ratio_spinner " ) . set_value ( self . preferences . get ( " auto_seed_ratio " ) )
self . glade . get_widget ( " chk_dht " ) . set_active ( self . preferences . get ( " enable_dht " ) )
self . glade . get_widget ( " spin_gui " ) . set_value ( self . preferences . get ( " gui_update_interval " ) )
2007-07-18 03:08:06 +00:00
#smart dialog set sensitivities
if ( self . preferences . get ( " use_default_dir " ) ) :
self . glade . get_widget ( " radio_save_all_to " ) . set_active ( True )
else :
self . glade . get_widget ( " radio_ask_save " ) . set_active ( True )
2007-08-11 01:18:50 +00:00
self . glade . get_widget ( ' chk_min_on_close ' ) . set_sensitive (
self . glade . get_widget ( ' chk_use_tray ' ) . get_active ( ) )
self . glade . get_widget ( ' chk_start_in_tray ' ) . set_sensitive (
self . glade . get_widget ( ' chk_use_tray ' ) . get_active ( ) )
self . glade . get_widget ( ' chk_lock_tray ' ) . set_sensitive (
self . glade . get_widget ( ' chk_use_tray ' ) . get_active ( ) )
self . glade . get_widget ( ' txt_tray_passwd ' ) . set_sensitive (
self . glade . get_widget ( ' chk_use_tray ' ) . get_active ( ) and \
self . glade . get_widget ( ' chk_lock_tray ' ) . get_active ( ) )
self . glade . get_widget ( ' spin_port_min ' ) . set_sensitive (
not self . glade . get_widget ( ' chk_random_port ' ) . get_active ( ) )
self . glade . get_widget ( ' spin_port_max ' ) . set_sensitive (
not self . glade . get_widget ( ' chk_random_port ' ) . get_active ( ) )
2007-08-05 20:13:24 +00:00
2007-08-08 02:03:28 +00:00
self . glade . get_widget ( " ok_button " ) . connect ( " clicked " ,
self . ok_clicked , interface )
self . glade . get_widget ( " cancel_button " ) . connect ( " clicked " ,
self . cancel_clicked )
2007-07-11 04:22:44 +00:00
except KeyError :
pass
# Now, show the dialog
2007-08-06 00:40:18 +00:00
self . dialog . set_transient_for ( window )
2007-07-11 04:22:44 +00:00
self . dialog . show ( )
2007-08-05 20:13:24 +00:00
2007-08-08 02:03:28 +00:00
def ok_clicked ( self , source , interface ) :
2007-07-11 04:22:44 +00:00
self . dialog . hide ( )
2007-08-08 21:45:18 +00:00
self . preferences . set ( " file_manager " , self . glade . get_widget ( " combo_file_manager " ) . get_active ( ) )
2007-08-10 21:32:20 +00:00
self . preferences . set ( " open_folder_stock " , self . glade . get_widget ( " radio_open_folder_stock " ) . get_active ( ) )
2007-08-08 23:03:44 +00:00
self . preferences . set ( " open_folder_location " , self . glade . get_widget ( " txt_open_folder_location " ) . get_text ( ) )
2007-08-05 20:13:24 +00:00
self . preferences . set ( " encin_state " , self . glade . get_widget ( " combo_encin " ) . get_active ( ) )
self . preferences . set ( " encout_state " , self . glade . get_widget ( " combo_encout " ) . get_active ( ) )
self . preferences . set ( " enclevel_type " , self . glade . get_widget ( " combo_enclevel " ) . get_active ( ) )
self . preferences . set ( " peer_proxy_type " , self . glade . get_widget ( " combo_peer_proxy_type " ) . get_active ( ) )
2007-08-07 03:09:18 +00:00
self . preferences . set ( " send_info " , self . glade . get_widget ( " chk_send_info " ) . get_active ( ) )
2007-08-05 20:13:24 +00:00
self . preferences . set ( " pref_rc4 " , self . glade . get_widget ( " chk_pref_rc4 " ) . get_active ( ) )
self . preferences . set ( " peer_proxy " , self . glade . get_widget ( " chk_peer_proxy " ) . get_active ( ) )
self . preferences . set ( " tracker_proxy " , self . glade . get_widget ( " chk_tracker_proxy " ) . get_active ( ) )
self . preferences . set ( " dht_proxy " , self . glade . get_widget ( " chk_dht_proxy " ) . get_active ( ) )
self . preferences . set ( " web_proxy " , self . glade . get_widget ( " chk_web_proxy " ) . get_active ( ) )
self . preferences . set ( " use_upnp " , self . glade . get_widget ( " chk_upnp " ) . get_active ( ) )
self . preferences . set ( " tracker_proxy_type " , self . glade . get_widget ( " combo_tracker_proxy_type " ) . get_active ( ) )
self . preferences . set ( " dht_proxy_type " , self . glade . get_widget ( " combo_dht_proxy_type " ) . get_active ( ) )
self . preferences . set ( " web_proxy_type " , self . glade . get_widget ( " combo_web_proxy_type " ) . get_active ( ) )
self . preferences . set ( " new_releases " , self . glade . get_widget ( " chk_new_releases " ) . get_active ( ) )
self . preferences . set ( " random_port " , self . glade . get_widget ( " chk_random_port " ) . get_active ( ) )
self . preferences . set ( " use_natpmp " , self . glade . get_widget ( " chk_natpmp " ) . get_active ( ) )
self . preferences . set ( " use_utpex " , self . glade . get_widget ( " chk_utpex " ) . get_active ( ) )
self . preferences . set ( " enable_system_tray " , self . glade . get_widget ( " chk_use_tray " ) . get_active ( ) )
self . preferences . set ( " close_to_tray " , self . glade . get_widget ( " chk_min_on_close " ) . get_active ( ) )
2007-08-11 01:18:50 +00:00
self . preferences . set ( " start_in_tray " , self . glade . get_widget ( " chk_start_in_tray " ) . get_active ( ) )
2007-08-05 20:13:24 +00:00
self . preferences . set ( " lock_tray " , self . glade . get_widget ( " chk_lock_tray " ) . get_active ( ) )
self . preferences . set ( " tray_passwd " , self . glade . get_widget ( " txt_tray_passwd " ) . get_text ( ) )
self . preferences . set ( " tracker_proxy_username " , self . glade . get_widget ( " txt_tracker_proxy_username " ) . get_text ( ) )
self . preferences . set ( " tracker_proxy_password " , self . glade . get_widget ( " txt_tracker_proxy_password " ) . get_text ( ) )
self . preferences . set ( " tracker_proxy_hostname " , self . glade . get_widget ( " txt_tracker_proxy_hostname " ) . get_text ( ) )
self . preferences . set ( " web_proxy_username " , self . glade . get_widget ( " txt_web_proxy_username " ) . get_text ( ) )
self . preferences . set ( " web_proxy_password " , self . glade . get_widget ( " txt_web_proxy_password " ) . get_text ( ) )
self . preferences . set ( " web_proxy_hostname " , self . glade . get_widget ( " txt_web_proxy_hostname " ) . get_text ( ) )
self . preferences . set ( " dht_proxy_username " , self . glade . get_widget ( " txt_dht_proxy_username " ) . get_text ( ) )
self . preferences . set ( " dht_proxy_password " , self . glade . get_widget ( " txt_dht_proxy_password " ) . get_text ( ) )
self . preferences . set ( " dht_proxy_hostname " , self . glade . get_widget ( " txt_dht_proxy_hostname " ) . get_text ( ) )
self . preferences . set ( " peer_proxy_username " , self . glade . get_widget ( " txt_peer_proxy_username " ) . get_text ( ) )
self . preferences . set ( " peer_proxy_password " , self . glade . get_widget ( " txt_peer_proxy_password " ) . get_text ( ) )
self . preferences . set ( " peer_proxy_hostname " , self . glade . get_widget ( " txt_peer_proxy_hostname " ) . get_text ( ) )
self . preferences . set ( " use_default_dir " , self . glade . get_widget ( " radio_save_all_to " ) . get_active ( ) )
self . preferences . set ( " default_download_path " , self . glade . get_widget ( " download_path_button " ) . get_filename ( ) )
self . preferences . set ( " enable_files_dialog " , self . glade . get_widget ( " chk_enable_files_dialog " ) . get_active ( ) )
self . preferences . set ( " prioritize_first_last_pieces " , self . glade . get_widget ( " chk_prioritize_first_last_pieces " ) . get_active ( ) )
self . preferences . set ( " auto_end_seeding " , self . glade . get_widget ( " chk_autoseed " ) . get_active ( ) )
self . preferences . set ( " auto_seed_ratio " , self . glade . get_widget ( " ratio_spinner " ) . get_value ( ) )
2007-08-10 21:32:20 +00:00
self . preferences . set ( " use_compact_storage " , self . glade . get_widget ( " radio_compact_allocation " ) . get_active ( ) )
2007-08-05 20:13:24 +00:00
self . preferences . set ( " listen_on " , [ self . glade . get_widget ( " spin_port_min " ) . get_value ( ) , self . glade . get_widget ( " spin_port_max " ) . get_value ( ) ] )
self . preferences . set ( " max_upload_speed " , self . glade . get_widget ( " spin_max_upload " ) . get_value ( ) )
2007-08-08 19:59:46 +00:00
self . preferences . set ( " max_upload_slots_global " , int ( self . glade . get_widget ( " spin_max_upload_slots_global " ) . get_value ( ) ) )
self . preferences . set ( " max_upload_slots_per_torrent " , int ( self . glade . get_widget ( " spin_max_upload_slots_per_torrent " ) . get_value ( ) ) )
2007-08-05 20:13:24 +00:00
self . preferences . set ( " max_download_speed " , self . glade . get_widget ( " spin_max_download " ) . get_value ( ) )
self . preferences . set ( " peer_proxy_port " , self . glade . get_widget ( " spin_peer_proxy_port " ) . get_value ( ) )
self . preferences . set ( " dht_proxy_port " , self . glade . get_widget ( " spin_dht_proxy_port " ) . get_value ( ) )
self . preferences . set ( " web_proxy_port " , self . glade . get_widget ( " spin_web_proxy_port " ) . get_value ( ) )
self . preferences . set ( " tracker_proxy_port " , self . glade . get_widget ( " spin_tracker_proxy_port " ) . get_value ( ) )
2007-08-08 19:59:46 +00:00
self . preferences . set ( " max_connections_global " , int ( self . glade . get_widget ( " spin_max_connections_global " ) . get_value ( ) ) )
self . preferences . set ( " max_connections_per_torrent " , int ( self . glade . get_widget ( " spin_max_connections_per_torrent " ) . get_value ( ) ) )
2007-08-05 20:13:24 +00:00
self . preferences . set ( " max_active_torrents " , int ( self . glade . get_widget ( " spin_torrents " ) . get_value ( ) ) )
self . preferences . set ( " queue_seeds_to_bottom " , self . glade . get_widget ( " chk_seedbottom " ) . get_active ( ) )
self . preferences . set ( " enable_dht " , self . glade . get_widget ( " chk_dht " ) . get_active ( ) )
self . preferences . set ( " gui_update_interval " , self . glade . get_widget ( " spin_gui " ) . get_value ( ) )
self . preferences . set ( " clear_max_ratio_torrents " , self . glade . get_widget ( " chk_clear_max_ratio_torrents " ) . get_active ( ) )
self . preferences . set ( " queue_above_completed " , self . glade . get_widget ( " chk_queue_above_completed " ) . get_active ( ) )
2007-06-08 03:13:34 +00:00
2007-08-05 20:13:24 +00:00
interface . apply_prefs ( )
interface . config . save ( )
2007-08-08 02:03:28 +00:00
def cancel_clicked ( self , source ) :
2007-08-05 20:13:24 +00:00
self . dialog . hide ( )
2007-07-11 04:22:44 +00:00
def TestPort ( self , widget ) :
2007-07-16 15:26:37 +00:00
common . open_url_in_browser ( ' http://www.deluge-torrent.org/test-port.php?port= %s ' % self . active_port )
2007-07-17 22:29:53 +00:00
2007-07-18 03:11:36 +00:00
def toggle_ui ( self , widget ) :
2007-07-18 03:08:06 +00:00
value = widget . get_active ( )
if widget == self . glade . get_widget ( ' radio_save_all_to ' ) :
self . glade . get_widget ( ' download_path_button ' ) . set_sensitive ( value )
elif widget == self . glade . get_widget ( ' chk_autoseed ' ) :
self . glade . get_widget ( ' ratio_spinner ' ) . set_sensitive ( value )
2007-07-18 03:41:26 +00:00
self . glade . get_widget ( ' chk_clear_max_ratio_torrents ' ) . set_sensitive ( value )
elif widget == self . glade . get_widget ( ' chk_seedbottom ' ) :
self . glade . get_widget ( ' chk_queue_above_completed ' ) . set_sensitive ( value )
2007-08-01 19:57:32 +00:00
elif widget == self . glade . get_widget ( ' chk_peer_proxy ' ) :
value = self . glade . get_widget ( ' chk_peer_proxy ' ) . get_active ( )
for x in [ ' combo_peer_proxy_type ' , ' txt_peer_proxy_hostname ' ,
' txt_peer_proxy_username ' , ' spin_peer_proxy_port ' ,
' txt_peer_proxy_password ' ] :
self . glade . get_widget ( x ) . set_sensitive ( value )
elif widget == self . glade . get_widget ( ' chk_tracker_proxy ' ) :
value = self . glade . get_widget ( ' chk_tracker_proxy ' ) . get_active ( )
for x in [ ' combo_tracker_proxy_type ' , ' txt_tracker_proxy_hostname ' ,
' txt_tracker_proxy_username ' , ' spin_tracker_proxy_port ' ,
' txt_tracker_proxy_password ' ] :
self . glade . get_widget ( x ) . set_sensitive ( value )
elif widget == self . glade . get_widget ( ' chk_dht_proxy ' ) :
value = self . glade . get_widget ( ' chk_dht_proxy ' ) . get_active ( )
for x in [ ' combo_dht_proxy_type ' , ' txt_dht_proxy_hostname ' ,
' txt_dht_proxy_username ' , ' spin_dht_proxy_port ' ,
' txt_dht_proxy_password ' ] :
self . glade . get_widget ( x ) . set_sensitive ( value )
elif widget == self . glade . get_widget ( ' chk_web_proxy ' ) :
value = self . glade . get_widget ( ' chk_web_proxy ' ) . get_active ( )
for x in [ ' combo_web_proxy_type ' , ' txt_web_proxy_hostname ' ,
' txt_web_proxy_username ' , ' spin_web_proxy_port ' ,
' txt_web_proxy_password ' ] :
2007-07-18 03:08:06 +00:00
self . glade . get_widget ( x ) . set_sensitive ( value )
elif widget == self . glade . get_widget ( ' chk_use_tray ' ) :
self . glade . get_widget ( ' chk_min_on_close ' ) . set_sensitive ( value )
2007-08-11 01:18:50 +00:00
self . glade . get_widget ( ' chk_start_in_tray ' ) . set_sensitive ( value )
2007-07-18 03:08:06 +00:00
self . glade . get_widget ( ' chk_lock_tray ' ) . set_sensitive ( value )
2007-08-11 01:18:50 +00:00
self . glade . get_widget ( ' txt_tray_passwd ' ) . set_sensitive ( value and \
self . glade . get_widget ( ' chk_lock_tray ' ) . get_active ( ) )
2007-07-18 03:08:06 +00:00
elif widget == self . glade . get_widget ( ' chk_lock_tray ' ) :
self . glade . get_widget ( ' txt_tray_passwd ' ) . set_sensitive ( value )
2007-07-28 23:02:15 +00:00
elif widget == self . glade . get_widget ( ' chk_random_port ' ) :
self . glade . get_widget ( ' spin_port_min ' ) . set_sensitive ( False )
self . glade . get_widget ( ' spin_port_max ' ) . set_sensitive ( False )
if not value :
2007-07-28 18:58:59 +00:00
self . glade . get_widget ( ' spin_port_min ' ) . set_sensitive ( True )
self . glade . get_widget ( ' spin_port_max ' ) . set_sensitive ( True )
2007-03-26 01:03:00 +00:00
2007-08-09 16:56:49 +00:00
def on_combo_file_manager_entry_focus_in_event ( self , widget , event ) :
self . glade . get_widget ( " radio_open_folder_stock " ) . set_active ( True )
def on_txt_open_folder_location_focus_in_event ( self , widget , event ) :
self . glade . get_widget ( " radio_open_folder_custom " ) . set_active ( True )
def on_radio_open_folder_custom_focus_in_event ( self , widget , event ) :
self . glade . get_widget ( " txt_open_folder_location " ) . grab_focus ( )
2007-07-20 02:32:33 +00:00
class MergeDlg :
def __init__ ( self ) :
self . glade = gtk . glade . XML ( common . get_glade_file ( " merge_dialog.glade " ) ,
domain = ' deluge ' )
self . dialog = self . glade . get_widget ( " merge_dialog " )
2007-08-05 20:13:24 +00:00
self . dialog . set_position ( gtk . WIN_POS_CENTER )
2007-07-20 02:32:33 +00:00
self . dialog . set_icon_from_file ( common . get_pixmap ( " deluge32.png " ) )
2007-08-06 00:40:18 +00:00
def show ( self , window ) :
self . dialog . set_transient_for ( window )
2007-07-20 02:32:33 +00:00
self . dialog . show ( )
r = self . dialog . run ( )
self . dialog . hide ( )
return r
2007-07-15 19:24:37 +00:00
class FilesDlg :
2007-07-18 09:06:24 +00:00
def __init__ ( self , dumped_torrent ) :
2007-07-16 13:31:30 +00:00
self . glade = gtk . glade . XML ( common . get_glade_file ( " files_dialog.glade " ) ,
domain = ' deluge ' )
2007-07-15 19:24:37 +00:00
self . dialog = self . glade . get_widget ( " file_dialog " )
2007-08-05 20:13:24 +00:00
self . dialog . set_position ( gtk . WIN_POS_CENTER )
2007-07-15 19:24:37 +00:00
self . dialog . set_icon_from_file ( common . get_pixmap ( " deluge32.png " ) )
2007-07-16 13:31:30 +00:00
2007-08-05 04:07:17 +00:00
self . files_manager = files . FilesDialogManager (
2007-08-04 18:38:29 +00:00
self . glade . get_widget ( " file_view " ) ,
dumped_torrent )
self . files_manager . build_file_view ( )
2007-07-18 09:06:24 +00:00
self . files_manager . prepare_file_store ( )
2007-07-16 13:31:30 +00:00
2007-08-06 00:40:18 +00:00
def show ( self , window ) :
2007-07-16 00:15:04 +00:00
#clear private setting
self . glade . get_widget ( " chk_setpriv " ) . set_active ( False )
2007-08-06 00:40:18 +00:00
self . dialog . set_transient_for ( window )
2007-07-15 19:24:37 +00:00
self . dialog . show ( )
r = self . dialog . run ( )
self . dialog . hide ( )
2007-07-16 13:31:30 +00:00
2007-07-15 19:24:37 +00:00
return r
2007-07-18 09:06:24 +00:00
2007-08-04 18:47:56 +00:00
def is_private_flag_checked ( self ) :
return self . glade . get_widget ( " chk_setpriv " ) . get_active ( )
2007-07-18 09:06:24 +00:00
def get_priorities ( self ) :
2007-08-04 18:47:56 +00:00
return self . files_manager . get_priorities ( )
2007-07-15 19:24:37 +00:00
2007-03-26 01:03:00 +00:00
class PluginDlg :
2007-07-16 13:59:22 +00:00
def __init__ ( self , plugins ) :
2007-07-11 04:22:44 +00:00
self . glade = gtk . glade . XML ( common . get_glade_file ( " plugin_dialog.glade " ) , domain = ' deluge ' )
self . dialog = self . glade . get_widget ( " plugin_dialog " )
2007-08-05 20:13:24 +00:00
self . dialog . set_position ( gtk . WIN_POS_CENTER )
2007-07-11 04:22:44 +00:00
self . dialog . set_icon_from_file ( common . get_pixmap ( " deluge32.png " ) )
self . view = self . glade . get_widget ( " plugin_view " )
self . store = gtk . ListStore ( str , bool )
2007-07-13 07:53:16 +00:00
self . store . set_sort_column_id ( 0 , gtk . SORT_ASCENDING )
2007-07-11 04:22:44 +00:00
self . view . set_model ( self . store )
try :
self . view . get_selection ( ) . set_select_function ( self . plugin_clicked , full = True )
except TypeError :
self . view . get_selection ( ) . set_select_function ( self . old_clicked )
name_col = dgtk . add_text_column ( self . view , _ ( " Plugin " ) , 0 )
name_col . set_expand ( True )
dgtk . add_toggle_column ( self . view , _ ( " Enabled " ) , 1 , toggled_signal = self . plugin_toggled )
2007-08-05 20:13:24 +00:00
signals = { ' plugin_pref ' : self . plugin_pref ,
2007-08-08 02:03:28 +00:00
' on_close_clicked ' : self . close_clicked }
2007-08-05 20:13:24 +00:00
self . glade . signal_autoconnect ( signals )
2007-07-11 04:22:44 +00:00
self . plugins = plugins
2007-03-26 01:03:00 +00:00
2007-08-06 00:40:18 +00:00
def show ( self , window ) :
2007-07-11 04:22:44 +00:00
self . store . clear ( )
for plugin in self . plugins . get_available_plugins ( ) :
#print plugin
if plugin in self . plugins . get_enabled_plugins ( ) :
self . store . append ( ( plugin , True ) )
else :
self . store . append ( ( plugin , False ) )
self . glade . get_widget ( " plugin_text " ) . get_buffer ( ) . set_text ( " " )
self . glade . get_widget ( " plugin_conf " ) . set_sensitive ( False )
2007-08-06 00:40:18 +00:00
self . dialog . set_transient_for ( window )
2007-07-11 04:22:44 +00:00
self . dialog . show ( )
2007-08-05 20:13:24 +00:00
2007-08-08 02:03:28 +00:00
def close_clicked ( self , source ) :
2007-07-11 04:22:44 +00:00
self . dialog . hide ( )
def old_clicked ( self , path ) :
return self . plugin_clicked ( self . view . get_selection ( ) , self . store , path , False )
def plugin_clicked ( self , selection , model , path , is_selected ) :
if is_selected :
return True
name = model . get_value ( model . get_iter ( path ) , 0 )
plugin = self . plugins . get_plugin ( name )
author = plugin . plugin_author
version = plugin . plugin_version
description = plugin . plugin_description
if name in self . plugins . get_enabled_plugins ( ) :
config = self . plugins . configurable_plugin ( name )
self . glade . get_widget ( " plugin_conf " ) . set_sensitive ( config )
else :
self . glade . get_widget ( " plugin_conf " ) . set_sensitive ( False )
self . glade . get_widget ( " plugin_text " ) . get_buffer (
) . set_text ( " %s \n By: %s \n Version: %s \n \n %s " %
( name , author , version , description ) )
return True
2007-03-26 01:03:00 +00:00
2007-07-11 04:22:44 +00:00
def plugin_toggled ( self , renderer , path ) :
plugin_iter = self . store . get_iter_from_string ( path )
plugin_name = self . store . get_value ( plugin_iter , 0 )
plugin_value = not self . store . get_value ( plugin_iter , 1 )
self . store . set_value ( plugin_iter , 1 , plugin_value )
if plugin_value :
2007-07-14 08:58:30 +00:00
self . plugins . enable_plugin ( plugin_name )
2007-07-11 04:22:44 +00:00
config = self . plugins . configurable_plugin ( plugin_name )
self . glade . get_widget ( " plugin_conf " ) . set_sensitive ( config )
else :
self . plugins . disable_plugin ( plugin_name )
self . glade . get_widget ( " plugin_conf " ) . set_sensitive ( False )
def plugin_pref ( self , widget = None ) :
( model , plugin_iter ) = self . view . get_selection ( ) . get_selected ( )
plugin_name = self . store . get_value ( plugin_iter , 0 )
2007-08-06 00:40:18 +00:00
self . plugins . configure_plugin ( plugin_name , self . dialog )
2007-03-26 01:03:00 +00:00
def show_about_dialog ( parent = None ) :
2007-07-16 15:26:37 +00:00
def url_hook ( dialog , url ) :
common . open_url_in_browser ( url )
gtk . about_dialog_set_url_hook ( url_hook )
2007-07-11 04:22:44 +00:00
abt = gtk . glade . XML ( common . get_glade_file ( " aboutdialog.glade " ) ) . get_widget ( " aboutdialog " )
2007-08-05 20:13:24 +00:00
abt . set_position ( gtk . WIN_POS_CENTER )
2007-07-11 04:22:44 +00:00
abt . set_name ( common . PROGRAM_NAME )
abt . set_version ( common . PROGRAM_VERSION )
2007-07-18 14:42:19 +00:00
abt . set_authors ( [ " Zach Tibbitts " , " Alon Zakai " , " Marcos Pinto " , " Andrew Resch " , " Alex Dedul " ] )
2007-07-11 04:22:44 +00:00
abt . set_artists ( [ " Andrew Wedderburn " ] )
abt . set_translator_credits ( _ ( " translator-credits " ) )
2007-08-13 08:45:31 +00:00
abt . set_license ( _ ( " Deluge is free software, you can redistribute it and/or \n modify it under the terms of the GNU General Public \n License as published by the Free Software Foundation, \n either version 2 of the License, or (at your option) any \n later version. Deluge is distributed in the hope that it \n will be useful, but WITHOUT ANY WARRANTY, without even \n the implied warranty of MERCHANTABILITY or FITNESS \n FOR A PARTICULAR PURPOSE. See the GNU General \n Public License for more details. You should have received \n a copy of the GNU General Public License along with \n Deluge, but if not, write to the Free Software Foundation, \n Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110- \n 1301 USA " ) )
2007-07-11 04:22:44 +00:00
abt . set_website ( " http://deluge-torrent.org " )
abt . set_website_label ( " http://deluge-torrent.org " )
abt . set_icon_from_file ( common . get_pixmap ( " deluge32.png " ) )
abt . set_logo ( gtk . gdk . pixbuf_new_from_file (
common . get_pixmap ( " deluge-about.png " ) ) )
abt . show_all ( )
abt . run ( )
abt . hide_all ( )
2007-03-26 01:03:00 +00:00
def show_popup_warning ( window , message ) :
2007-07-11 04:22:44 +00:00
warner = gtk . MessageDialog ( parent = window ,
2007-07-14 22:22:37 +00:00
flags = gtk . DIALOG_MODAL | gtk . DIALOG_DESTROY_WITH_PARENT ,
2007-07-11 04:22:44 +00:00
buttons = gtk . BUTTONS_OK ,
message_format = message ,
2007-07-14 22:22:37 +00:00
type = gtk . MESSAGE_WARNING )
2007-07-11 04:22:44 +00:00
warner . run ( )
warner . destroy ( )
2007-03-26 01:03:00 +00:00
def show_popup_question ( window , message ) :
2007-07-11 04:22:44 +00:00
asker = gtk . MessageDialog ( parent = window ,
2007-07-14 22:22:37 +00:00
flags = gtk . DIALOG_MODAL | gtk . DIALOG_DESTROY_WITH_PARENT ,
2007-07-11 04:22:44 +00:00
buttons = gtk . BUTTONS_YES_NO ,
message_format = message ,
type = gtk . MESSAGE_QUESTION )
result = asker . run ( )
asker . destroy ( )
if result == gtk . RESPONSE_YES :
return True
elif result == gtk . RESPONSE_NO :
return False
elif result == gtk . RESPONSE_DELETE_EVENT :
return False
else :
return False
2007-03-26 01:03:00 +00:00
## Browse for .torrent files
def show_file_open_dialog ( parent = None , title = None ) :
2007-07-11 04:22:44 +00:00
if title is None :
title = _ ( " Choose a .torrent file " )
chooser = gtk . FileChooserDialog ( title , parent , gtk . FILE_CHOOSER_ACTION_OPEN ,
buttons = ( gtk . STOCK_CANCEL , gtk . RESPONSE_CANCEL , gtk . STOCK_OPEN , gtk . RESPONSE_OK ) )
f0 = gtk . FileFilter ( )
f0 . set_name ( _ ( " Torrent files " ) )
f0 . add_pattern ( " *. " + " torrent " )
chooser . add_filter ( f0 )
f1 = gtk . FileFilter ( )
f1 . set_name ( _ ( " All files " ) )
f1 . add_pattern ( " * " )
2007-08-15 03:13:04 +00:00
config = pref . Preferences ( )
chooser . set_current_folder ( config . get ( " open_torrent_dialog_path " ) )
2007-07-11 04:22:44 +00:00
chooser . add_filter ( f1 )
chooser . set_select_multiple ( True )
chooser . set_icon_from_file ( common . get_pixmap ( " deluge32.png " ) )
chooser . set_property ( " skip-taskbar-hint " , True )
response = chooser . run ( )
if response == gtk . RESPONSE_OK :
result = chooser . get_filenames ( )
2007-08-15 03:13:04 +00:00
config . set ( " open_torrent_dialog_path " , chooser . get_current_folder ( ) )
2007-07-11 04:22:44 +00:00
else :
result = None
chooser . destroy ( )
return result
2007-03-26 01:03:00 +00:00
2007-08-19 23:16:10 +00:00
def show_directory_chooser_dialog ( parent , title ) :
2007-07-11 04:22:44 +00:00
chooser = gtk . FileChooserDialog ( title , parent , gtk . FILE_CHOOSER_ACTION_SELECT_FOLDER ,
buttons = ( gtk . STOCK_CANCEL , gtk . RESPONSE_CANCEL , gtk . STOCK_OK , gtk . RESPONSE_OK ) )
chooser . set_icon_from_file ( common . get_pixmap ( " deluge32.png " ) )
chooser . set_property ( " skip-taskbar-hint " , True )
2007-08-15 03:13:04 +00:00
config = pref . Preferences ( )
2007-08-19 23:16:10 +00:00
chooser . set_current_folder ( config . get ( " choose_directory_dialog_path " ) )
2007-07-11 04:22:44 +00:00
if chooser . run ( ) == gtk . RESPONSE_OK :
result = chooser . get_filename ( )
2007-08-19 23:16:10 +00:00
config . set ( " choose_directory_dialog_path " , result )
2007-07-11 04:22:44 +00:00
else :
result = None
chooser . destroy ( )
return result