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:
|
|
|
|
# The Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor
|
|
|
|
# Boston, MA 02110-1301, USA.
|
|
|
|
|
2007-03-26 21:09:39 +00:00
|
|
|
import common, dgtk
|
2007-03-26 01:03:00 +00:00
|
|
|
import gtk, gtk.glade
|
|
|
|
import os, os.path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PreferencesDlg:
|
|
|
|
def __init__(self, parent, preferences):
|
2007-03-26 21:09:39 +00:00
|
|
|
self.glade = gtk.glade.XML(common.get_glade_file("preferences_dialog.glade"), domain='deluge')
|
2007-03-26 01:03:00 +00:00
|
|
|
self.dialog = self.glade.get_widget("pref_dialog")
|
2007-03-26 21:09:39 +00:00
|
|
|
self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
2007-03-26 01:03:00 +00:00
|
|
|
self.glade.signal_autoconnect({
|
|
|
|
'tray_toggle': self.tray_toggle,
|
2007-06-08 03:13:34 +00:00
|
|
|
'on_btn_testport_clicked': self.TestPort,
|
2007-03-26 01:03:00 +00:00
|
|
|
})
|
|
|
|
self.parent = parent
|
|
|
|
self.preferences = preferences
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
# Load settings into dialog
|
2007-03-26 21:09:39 +00:00
|
|
|
try:
|
2007-06-06 22:26:52 +00:00
|
|
|
self.glade.get_widget("combo_encin").set_active(self.preferences.get("encin_state", int, default=common.EncState.enabled))
|
|
|
|
self.glade.get_widget("combo_encout").set_active(self.preferences.get("encout_state", int, default=common.EncState.enabled))
|
|
|
|
self.glade.get_widget("combo_enclevel").set_active(self.preferences.get("enclevel_type", int, default=common.EncLevel.both))
|
2007-05-31 01:29:09 +00:00
|
|
|
self.glade.get_widget("chk_pref_rc4").set_active(self.preferences.get("pref_rc4", bool, default=True))
|
2007-03-26 21:09:39 +00:00
|
|
|
self.glade.get_widget("chk_use_tray").set_active(self.preferences.get("enable_system_tray", bool, default=True))
|
|
|
|
self.glade.get_widget("chk_min_on_close").set_active(self.preferences.get("close_to_tray", bool, default=False))
|
2007-05-25 08:17:22 +00:00
|
|
|
self.glade.get_widget("chk_lock_tray").set_active(self.preferences.get("lock_tray", bool, default=False))
|
|
|
|
self.glade.get_widget("txt_tray_passwd").set_text(self.preferences.get("tray_passwd", default=""))
|
2007-03-26 21:09:39 +00:00
|
|
|
if(self.preferences.get("use_default_dir", bool, False)):
|
|
|
|
self.glade.get_widget("radio_save_all_to").set_active(True)
|
|
|
|
else:
|
|
|
|
self.glade.get_widget("radio_ask_save").set_active(True)
|
2007-06-06 22:26:52 +00:00
|
|
|
|
2007-03-26 21:09:39 +00:00
|
|
|
self.glade.get_widget("download_path_button").set_filename(self.preferences.get("default_download_path", str, default=os.path.expandvars('$HOME')))
|
|
|
|
self.glade.get_widget("chk_compact").set_active(self.preferences.get("use_compact_storage", bool, default=False))
|
|
|
|
self.glade.get_widget("active_port_label").set_text(str(self.parent.manager.get_state()['port']))
|
2007-06-11 19:05:14 +00:00
|
|
|
self.glade.get_widget("spin_port_min").set_value(self.preferences.get("listen_on", default=6881)[0])
|
|
|
|
self.glade.get_widget("spin_port_max").set_value(self.preferences.get("listen_on", default=6889)[1])
|
2007-03-26 21:09:39 +00:00
|
|
|
self.glade.get_widget("spin_max_upload").set_value(self.preferences.get("max_upload_rate", int, default=-1))
|
|
|
|
self.glade.get_widget("spin_num_upload").set_value(self.preferences.get("max_number_uploads", int, default=-1))
|
|
|
|
self.glade.get_widget("spin_max_download").set_value(self.preferences.get("max_download_rate", int, default=-1))
|
|
|
|
self.glade.get_widget("spin_num_download").set_value(self.preferences.get("max_number_downloads", int, default=-1))
|
|
|
|
self.glade.get_widget("spin_torrents").set_value(self.preferences.get("max_number_torrents", int, default=-1))
|
|
|
|
self.glade.get_widget("chk_seedbottom").set_active(self.preferences.get("queue_seeds_to_bottom", bool, default=False))
|
|
|
|
self.glade.get_widget("chk_dht").set_active(self.preferences.get("enable_dht", bool, default=True))
|
|
|
|
self.glade.get_widget("spin_dht").set_value(self.preferences.get("dht_connections", int, default=80))
|
|
|
|
self.glade.get_widget("spin_gui").set_value(self.preferences.get("gui_update_interval", float, default=1.0))
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2007-03-26 01:03:00 +00:00
|
|
|
# Now, show the dialog
|
|
|
|
self.dialog.show()
|
|
|
|
r = self.dialog.run()
|
|
|
|
self.dialog.hide()
|
|
|
|
# Now, get the settings from the dialog
|
|
|
|
if r == 1:
|
2007-06-06 22:26:52 +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())
|
2007-06-08 20:01:30 +00:00
|
|
|
self.preferences.set("enclevel_type", self.glade.get_widget("combo_enclevel").get_active())
|
2007-06-06 22:26:52 +00:00
|
|
|
self.preferences.set("pref_rc4", self.glade.get_widget("chk_pref_rc4").get_active())
|
2007-05-31 01:29:09 +00:00
|
|
|
self.preferences.set("system_tray", self.glade.get_widget("chk_use_tray").get_active())
|
2007-03-26 01:03:00 +00:00
|
|
|
self.preferences.set("close_to_tray", self.glade.get_widget("chk_min_on_close").get_active())
|
2007-06-06 22:26:52 +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())
|
2007-03-26 01:03:00 +00:00
|
|
|
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("auto_end_seeding", self.glade.get_widget("chk_autoseed").get_active())
|
|
|
|
self.preferences.set("end_seed_ratio", self.glade.get_widget("ratio_spinner").get_value())
|
|
|
|
self.preferences.set("use_compact_storage", self.glade.get_widget("chk_compact").get_active())
|
2007-06-11 19:05:14 +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()])
|
2007-03-26 01:03:00 +00:00
|
|
|
self.preferences.set("max_upload_rate", self.glade.get_widget("spin_max_upload").get_value())
|
|
|
|
self.preferences.set("max_number_uploads", self.glade.get_widget("spin_num_upload").get_value())
|
|
|
|
self.preferences.set("max_download_rate", self.glade.get_widget("spin_max_download").get_value())
|
|
|
|
self.preferences.set("max_number_downloads", self.glade.get_widget("spin_num_download").get_value())
|
2007-03-26 21:09:39 +00:00
|
|
|
self.preferences.set("max_number_torrents", 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("dht_connections", self.glade.get_widget("spin_dht").get_value())
|
|
|
|
self.preferences.set("gui_update_interval", self.glade.get_widget("spin_gui").get_value())
|
2007-06-08 03:13:34 +00:00
|
|
|
|
|
|
|
def TestPort(self, widget):
|
|
|
|
activep = str(self.parent.manager.get_state()['port'])
|
2007-06-08 05:28:57 +00:00
|
|
|
common.open_url_in_browser(self.dialog,'http://www.deluge-torrent.org/test-port.php?port=%s' %activep)
|
2007-06-08 03:13:34 +00:00
|
|
|
|
2007-03-26 01:03:00 +00:00
|
|
|
|
|
|
|
def tray_toggle(self, obj):
|
|
|
|
if obj.get_active():
|
|
|
|
self.glade.get_widget("chk_min_on_close").set_sensitive(True)
|
|
|
|
else:
|
|
|
|
self.glade.get_widget("chk_min_on_close").set_sensitive(False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PluginDlg:
|
|
|
|
def __init__(self, parent, plugins):
|
2007-03-26 21:09:39 +00:00
|
|
|
self.glade = gtk.glade.XML(common.get_glade_file("plugin_dialog.glade"), domain='deluge')
|
2007-03-26 01:03:00 +00:00
|
|
|
self.dialog = self.glade.get_widget("plugin_dialog")
|
2007-03-26 21:09:39 +00:00
|
|
|
self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
2007-03-26 01:03:00 +00:00
|
|
|
self.view = self.glade.get_widget("plugin_view")
|
|
|
|
self.store = gtk.ListStore(str, bool)
|
|
|
|
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-03-26 02:11:19 +00:00
|
|
|
self.glade.signal_autoconnect({'plugin_pref': self.plugin_pref})
|
2007-03-26 01:03:00 +00:00
|
|
|
self.parent = parent
|
|
|
|
self.plugins = plugins
|
2007-03-26 02:11:19 +00:00
|
|
|
|
2007-03-26 01:03:00 +00:00
|
|
|
|
|
|
|
def show(self):
|
|
|
|
self.store.clear()
|
|
|
|
for plugin in self.plugins.get_available_plugins():
|
2007-06-10 08:42:19 +00:00
|
|
|
#print plugin
|
2007-03-26 01:03:00 +00:00
|
|
|
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)
|
|
|
|
self.dialog.show()
|
|
|
|
self.dialog.run()
|
|
|
|
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)
|
2007-06-12 08:13:16 +00:00
|
|
|
author = plugin.plugin_author
|
|
|
|
version = plugin.plugin_version
|
|
|
|
description = plugin.plugin_description
|
2007-03-26 01:03:00 +00:00
|
|
|
if name in self.plugins.get_enabled_plugins():
|
2007-06-12 08:13:16 +00:00
|
|
|
config = self.plugins.configurable_plugin(name)
|
2007-03-26 01:03:00 +00:00
|
|
|
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\nBy: %s\nVersion: %s\n\n%s"%
|
|
|
|
(name, author, version, description))
|
|
|
|
return True
|
|
|
|
|
|
|
|
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:
|
|
|
|
self.plugins.enable_plugin(plugin_name)
|
2007-06-12 08:13:16 +00:00
|
|
|
config = self.plugins.configurable_plugin(plugin_name)
|
|
|
|
self.glade.get_widget("plugin_conf").set_sensitive(config)
|
2007-03-26 01:03:00 +00:00
|
|
|
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)
|
|
|
|
self.plugins.configure_plugin(plugin_name)
|
|
|
|
|
|
|
|
|
|
|
|
def show_about_dialog(parent=None):
|
2007-03-26 21:09:39 +00:00
|
|
|
gtk.about_dialog_set_url_hook(common.open_url_in_browser)
|
|
|
|
abt = gtk.glade.XML(common.get_glade_file("aboutdialog.glade")).get_widget("aboutdialog")
|
|
|
|
abt.set_name(common.PROGRAM_NAME)
|
|
|
|
abt.set_version(common.PROGRAM_VERSION)
|
2007-05-23 00:26:03 +00:00
|
|
|
abt.set_authors(["Zach Tibbits", "Alon Zakai", "Marcos Pinto"])
|
2007-03-26 01:03:00 +00:00
|
|
|
abt.set_artists(["Andrew Wedderburn"])
|
|
|
|
abt.set_website("http://deluge-torrent.org")
|
2007-05-17 19:01:29 +00:00
|
|
|
abt.set_website_label("http://deluge-torrent.org")
|
2007-03-26 21:09:39 +00:00
|
|
|
abt.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
2007-03-26 01:03:00 +00:00
|
|
|
abt.set_logo(gtk.gdk.pixbuf_new_from_file(
|
2007-03-26 21:09:39 +00:00
|
|
|
common.get_pixmap("deluge-about.png")))
|
2007-03-26 01:03:00 +00:00
|
|
|
abt.show_all()
|
|
|
|
abt.run()
|
|
|
|
abt.hide_all()
|
|
|
|
|
|
|
|
def show_popup_warning(window, message):
|
|
|
|
warner = gtk.MessageDialog(parent = window,
|
|
|
|
flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
buttons= gtk.BUTTONS_OK,
|
|
|
|
message_format=message,
|
|
|
|
type = gtk.MESSAGE_WARNING)
|
|
|
|
warner.run()
|
|
|
|
warner.destroy()
|
|
|
|
|
|
|
|
def show_popup_question(window, message):
|
|
|
|
asker = gtk.MessageDialog(parent = window,
|
|
|
|
flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
## Browse for .torrent files
|
|
|
|
def show_file_open_dialog(parent=None, title=None):
|
|
|
|
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("*")
|
|
|
|
chooser.add_filter(f1)
|
|
|
|
|
2007-03-26 21:09:39 +00:00
|
|
|
chooser.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
2007-03-26 01:03:00 +00:00
|
|
|
chooser.set_property("skip-taskbar-hint", True)
|
|
|
|
|
|
|
|
response = chooser.run()
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
result = chooser.get_filename()
|
|
|
|
else:
|
|
|
|
result = None
|
|
|
|
chooser.destroy()
|
|
|
|
return result
|
|
|
|
|
|
|
|
def show_directory_chooser_dialog(parent=None, title=None):
|
|
|
|
if title is None:
|
|
|
|
title = _("Choose a download directory")
|
|
|
|
chooser = gtk.FileChooserDialog(title, parent, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
|
|
|
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))
|
2007-03-26 21:09:39 +00:00
|
|
|
chooser.set_icon_from_file(common.get_pixmap("deluge32.png"))
|
2007-03-26 01:03:00 +00:00
|
|
|
chooser.set_property("skip-taskbar-hint", True)
|
|
|
|
if chooser.run() == gtk.RESPONSE_OK:
|
|
|
|
result = chooser.get_filename()
|
|
|
|
else:
|
|
|
|
result = None
|
|
|
|
chooser.destroy()
|
|
|
|
return result
|
2007-05-25 07:31:31 +00:00
|
|
|
|
2007-05-31 01:29:09 +00:00
|
|
|
|