예제 #1
0
    def run(self):
        # Make sure we have a torrent_id.. if not just return
        if self.torrent_id == None:
            return

        # Get the trackers for this torrent
        session = component.get("SessionProxy")
        session.get_torrent_status(self.torrent_id, ["trackers"]).addCallback(self._on_get_torrent_status)
        client.force_call()
예제 #2
0
    def run(self):
        # Make sure we have a torrent_id.. if not just return
        if self.torrent_id is None:
            return

        # Get the trackers for this torrent
        session = component.get('SessionProxy')
        session.get_torrent_status(
            self.torrent_id, ['trackers']
        ).addCallback(self._on_get_torrent_status)
        client.force_call()

        self.deferred = defer.Deferred()
        return self.deferred
예제 #3
0
    def _save_config(self):
        # ui config
        new_config = WidgetLoader.from_widgets(self, self.ui_config.config, "ui__")
        for key in new_config.keys():
            if self.ui_config[key] != new_config[key]:
                self.ui_config[key] = new_config[key]

        # core config
        if self.core_config and client.connected():
            new_config = WidgetLoader.from_widgets(self, self.core_config, "core__")
            client.core.set_config(dict((key, new_config[key])
                                        for key in new_config.keys() if self.core_config[key] != new_config[key]))
            client.force_call(True)
            self.core_config = new_config
예제 #4
0
    def on_test_port_clicked(self, data):
        log.debug("on_test_port_clicked")

        def on_get_test(status):
            if status:
                self.glade.get_widget("port_img").set_from_stock(gtk.STOCK_YES, 4)
                self.glade.get_widget("port_img").show()
            else:
                self.glade.get_widget("port_img").set_from_stock(gtk.STOCK_DIALOG_WARNING, 4)
                self.glade.get_widget("port_img").show()

        client.core.test_listen_port().addCallback(on_get_test)
        self.glade.get_widget("port_img").set_from_file(deluge.common.get_pixmap("loading.gif"))
        self.glade.get_widget("port_img").show()
        client.force_call()
예제 #5
0
    def _apply_prefs(self):
        if self.core_config is None:
            return

        def update_conf_value(key, source_dict, dest_dict, updated):
            if dest_dict[key] != source_dict[key]:
                dest_dict[key] = source_dict[key]
                updated = True
            return updated

        new_core_config = {}
        for pane in self.panes:
            if not isinstance(pane, InterfacePane):
                pane.add_config_values(new_core_config)
        # Apply Core Prefs
        if client.connected():
            # Only do this if we're connected to a daemon
            config_to_set = {}
            for key in new_core_config:
                # The values do not match so this needs to be updated
                if self.core_config[key] != new_core_config[key]:
                    config_to_set[key] = new_core_config[key]

            if config_to_set:
                # Set each changed config value in the core
                client.core.set_config(config_to_set)
                client.force_call(True)
                # Update the configuration
                self.core_config.update(config_to_set)

        # Update Interface Prefs
        new_console_config = {}
        didupdate = False
        for pane in self.panes:
            # could just access panes by index, but that would break if panes
            # are ever reordered, so do it the slightly slower but safer way
            if isinstance(pane, InterfacePane):
                pane.add_config_values(new_console_config)
                for k in ['ring_bell', 'language']:
                    didupdate = update_conf_value(k, new_console_config, self.console_config, didupdate)
                for k in ['separate_complete', 'move_selection']:
                    didupdate = update_conf_value(k, new_console_config, self.console_config['torrentview'], didupdate)
                for k in ['ignore_duplicate_lines', 'save_command_history',
                          'third_tab_lists_all', 'torrents_per_tab_press']:
                    didupdate = update_conf_value(k, new_console_config, self.console_config['cmdline'], didupdate)

        if didupdate:
            self.parent_mode.on_config_changed()
예제 #6
0
    def on_test_port_clicked(self, data):
        log.debug("on_test_port_clicked")

        def on_get_test(status):
            if status:
                self.glade.get_widget("port_img").set_from_stock(
                    gtk.STOCK_YES, 4)
                self.glade.get_widget("port_img").show()
            else:
                self.glade.get_widget("port_img").set_from_stock(
                    gtk.STOCK_DIALOG_WARNING, 4)
                self.glade.get_widget("port_img").show()

        client.core.test_listen_port().addCallback(on_get_test)
        self.glade.get_widget("port_img").set_from_file(
            deluge.common.get_pixmap('loading.gif'))
        self.glade.get_widget("port_img").show()
        client.force_call()
예제 #7
0
    def _on_button_remote_path_clicked(self, widget):
        log.debug("_on_button_remote_path_clicked")
        dialog = self.builder.get_object("remote_path_dialog")
        entry = self.builder.get_object("entry_path")
        dialog.set_transient_for(self.dialog)
        entry.set_text("/")
        entry.grab_focus()
        response = dialog.run()

        if response == gtk.RESPONSE_OK:
            result = entry.get_text()
            def _on_get_path_size(size):
                log.debug("size: %s", size)
                if size > 0:
                    self.files_treestore.clear()
                    self.files_treestore.append(None, [result, gtk.STOCK_NETWORK, size])
                    self.adjust_piece_size()
            client.core.get_path_size(result).addCallback(_on_get_path_size)
            client.force_call(True)

        dialog.hide()
예제 #8
0
    def __apply_prefs(self):
        new_core_config = {}
        for pane in self.panes:
            if not isinstance(pane, InterfacePane) and not isinstance(
                    pane, ColumnsPane):
                pane.add_config_values(new_core_config)
        # Apply Core Prefs
        if client.connected():
            # Only do this if we're connected to a daemon
            config_to_set = {}
            for key in new_core_config.keys():
                # The values do not match so this needs to be updated
                if self.core_config[key] != new_core_config[key]:
                    config_to_set[key] = new_core_config[key]

            if config_to_set:
                # Set each changed config value in the core
                client.core.set_config(config_to_set)
                client.force_call(True)
                # Update the configuration
                self.core_config.update(config_to_set)

        # Update Interface Prefs
        new_console_config = {}
        didupdate = False
        for pane in self.panes:
            # could just access panes by index, but that would break if panes
            # are ever reordered, so do it the slightly slower but safer way
            if isinstance(pane, InterfacePane) or isinstance(
                    pane, ColumnsPane):
                pane.add_config_values(new_console_config)
        for key in new_console_config.keys():
            # The values do not match so this needs to be updated
            if self.console_config[key] != new_console_config[key]:
                self.console_config[key] = new_console_config[key]
                didupdate = True
        if didupdate:
            # changed something, save config and tell alltorrents
            self.console_config.save()
            self.parent_mode.update_config()
예제 #9
0
    def __apply_prefs(self):
        new_core_config = {}
        for pane in self.panes:
            if not isinstance(pane,InterfacePane):
                pane.add_config_values(new_core_config)
        # Apply Core Prefs
        if client.connected():
            # Only do this if we're connected to a daemon
            config_to_set = {}
            for key in new_core_config.keys():
                # The values do not match so this needs to be updated
                if self.core_config[key] != new_core_config[key]:
                    config_to_set[key] = new_core_config[key]

            if config_to_set:
                # Set each changed config value in the core
                client.core.set_config(config_to_set)
                client.force_call(True)
                # Update the configuration
                self.core_config.update(config_to_set)

        # Update Interface Prefs
        new_console_config = {}
        didupdate = False
        for pane in self.panes:
            # could just access panes by index, but that would break if panes
            # are ever reordered, so do it the slightly slower but safer way
            if isinstance(pane,InterfacePane):
                pane.add_config_values(new_console_config)
        for key in new_console_config.keys():
            # The values do not match so this needs to be updated
            if self.console_config[key] != new_console_config[key]:
                self.console_config[key] = new_console_config[key]
                didupdate = True
        if didupdate:
            # changed something, save config and tell alltorrents
            self.console_config.save()
            self.parent_mode.update_config()
예제 #10
0
    def on_button_remote_path_clicked(self, widget):
        log.debug('on_button_remote_path_clicked')
        dialog = self.builder.get_object('remote_path_dialog')
        entry = self.builder.get_object('entry_path')
        dialog.set_transient_for(self.dialog)
        entry.set_text('/')
        entry.grab_focus()
        response = dialog.run()

        if response == Gtk.ResponseType.OK:
            result = entry.get_text()

            def _on_get_path_size(size):
                log.debug('size: %s', size)
                if size > 0:
                    self.files_treestore.clear()
                    self.files_treestore.append(
                        None, [result, 'network-workgroup-symbolic', size])
                    self.adjust_piece_size()

            client.core.get_path_size(result).addCallback(_on_get_path_size)
            client.force_call(True)

        dialog.hide()
예제 #11
0
    def set_config(self, hide=False):
        """
        Sets all altered config values in the core.

        :param hide: bool, if True, will not re-show the dialog and will hide it instead
        """
        try:
            from hashlib import sha1 as sha_hash
        except ImportError:
            from sha import new as sha_hash

        # Get the values from the dialog
        new_core_config = {}
        new_gtkui_config = {}

        ## Downloads tab ##
        new_gtkui_config["interactive_add"] = \
            self.glade.get_object("chk_show_dialog").get_active()
        new_gtkui_config["focus_add_dialog"] = \
            self.glade.get_object("chk_focus_dialog").get_active()
        new_core_config["copy_torrent_file"] = \
            self.glade.get_object("chk_copy_torrent_file").get_active()
        new_core_config["del_copy_torrent_file"] = \
            self.glade.get_object("chk_del_copy_torrent_file").get_active()
        new_core_config["move_completed"] = \
            self.glade.get_object("chk_move_completed").get_active()
        if client.is_localhost():
            new_core_config["download_location"] = \
                self.glade.get_object("download_path_button").get_filename()
            new_core_config["move_completed_path"] = \
                self.glade.get_object("move_completed_path_button").get_filename()
            new_core_config["torrentfiles_location"] = \
                self.glade.get_object("torrent_files_button").get_filename()
        else:
            new_core_config["download_location"] = \
                self.glade.get_object("entry_download_path").get_text()
            new_core_config["move_completed_path"] = \
                self.glade.get_object("entry_move_completed_path").get_text()
            new_core_config["torrentfiles_location"] = \
                self.glade.get_object("entry_torrents_path").get_text()

        new_core_config["autoadd_enable"] = \
            self.glade.get_object("chk_autoadd").get_active()
        if client.is_localhost():
            new_core_config["autoadd_location"] = \
                self.glade.get_object("folder_autoadd").get_filename()
        else:
            new_core_config["autoadd_location"] = \
                self.glade.get_object("entry_autoadd").get_text()

        new_core_config["compact_allocation"] = \
            self.glade.get_object("radio_compact_allocation").get_active()
        new_core_config["prioritize_first_last_pieces"] = \
            self.glade.get_object(
                "chk_prioritize_first_last_pieces").get_active()
        new_core_config["add_paused"] = \
            self.glade.get_object("chk_add_paused").get_active()

        ## Network tab ##
        listen_ports = (
            self.glade.get_object("spin_port_min").get_value_as_int(),
            self.glade.get_object("spin_port_max").get_value_as_int())
        new_core_config["listen_ports"] = listen_ports
        new_core_config["random_port"] = \
            self.glade.get_object("chk_random_port").get_active()
        outgoing_ports = (
            self.glade.get_object("spin_outgoing_port_min").get_value_as_int(),
            self.glade.get_object("spin_outgoing_port_max").get_value_as_int())
        new_core_config["outgoing_ports"] = outgoing_ports
        new_core_config["random_outgoing_ports"] = \
            self.glade.get_object("chk_random_outgoing_ports").get_active()
        incoming_address = self.glade.get_object(
            "entry_interface").get_text().strip()
        if deluge.common.is_ip(incoming_address) or not incoming_address:
            new_core_config["listen_interface"] = incoming_address
        new_core_config["peer_tos"] = self.glade.get_object(
            "entry_peer_tos").get_text()
        new_core_config["dht"] = self.glade.get_object("chk_dht").get_active()
        new_core_config["upnp"] = self.glade.get_object(
            "chk_upnp").get_active()
        new_core_config["natpmp"] = \
            self.glade.get_object("chk_natpmp").get_active()
        new_core_config["utpex"] = \
            self.glade.get_object("chk_utpex").get_active()
        new_core_config["lsd"] = \
            self.glade.get_object("chk_lsd").get_active()
        new_core_config["enc_in_policy"] = \
            self.glade.get_object("combo_encin").get_active()
        new_core_config["enc_out_policy"] = \
            self.glade.get_object("combo_encout").get_active()
        new_core_config["enc_level"] = \
            self.glade.get_object("combo_enclevel").get_active()
        new_core_config["enc_prefer_rc4"] = \
            self.glade.get_object("chk_pref_rc4").get_active()

        ## Bandwidth tab ##
        new_core_config["max_connections_global"] = \
            self.glade.get_object(
                "spin_max_connections_global").get_value_as_int()
        new_core_config["max_download_speed"] = \
            self.glade.get_object("spin_max_download").get_value()
        new_core_config["max_upload_speed"] = \
            self.glade.get_object("spin_max_upload").get_value()
        new_core_config["max_upload_slots_global"] = \
            self.glade.get_object(
                "spin_max_upload_slots_global").get_value_as_int()
        new_core_config["max_half_open_connections"] = \
            self.glade.get_object("spin_max_half_open_connections").get_value_as_int()
        new_core_config["max_connections_per_second"] = \
            self.glade.get_object(
                "spin_max_connections_per_second").get_value_as_int()
        new_core_config["max_connections_per_torrent"] = \
            self.glade.get_object(
                "spin_max_connections_per_torrent").get_value_as_int()
        new_core_config["max_upload_slots_per_torrent"] = \
            self.glade.get_object(
                "spin_max_upload_slots_per_torrent").get_value_as_int()
        new_core_config["max_upload_speed_per_torrent"] = \
            self.glade.get_object(
                "spin_max_upload_per_torrent").get_value()
        new_core_config["max_download_speed_per_torrent"] = \
            self.glade.get_object(
                "spin_max_download_per_torrent").get_value()
        new_core_config["ignore_limits_on_local_network"] = \
            self.glade.get_object("chk_ignore_limits_on_local_network").get_active()
        new_core_config["rate_limit_ip_overhead"] = \
            self.glade.get_object("chk_rate_limit_ip_overhead").get_active()

        ## Interface tab ##
        new_gtkui_config["enable_system_tray"] = \
            self.glade.get_object("chk_use_tray").get_active()
        new_gtkui_config["close_to_tray"] = \
            self.glade.get_object("chk_min_on_close").get_active()
        new_gtkui_config["start_in_tray"] = \
            self.glade.get_object("chk_start_in_tray").get_active()
        new_gtkui_config["enable_appindicator"] = \
            self.glade.get_object("chk_enable_appindicator").get_active()
        new_gtkui_config["lock_tray"] = \
            self.glade.get_object("chk_lock_tray").get_active()
        passhex = sha_hash(\
            self.glade.get_object("txt_tray_password").get_text()).hexdigest()
        if passhex != "c07eb5a8c0dc7bb81c217b67f11c3b7a5e95ffd7":
            new_gtkui_config["tray_password"] = passhex
        new_gtkui_config["classic_mode"] = \
            self.glade.get_object("chk_classic_mode").get_active()
        new_gtkui_config["show_rate_in_title"] = \
            self.glade.get_object("chk_show_rate_in_title").get_active()
        new_gtkui_config["focus_main_window_on_add"] = \
            self.glade.get_object("chk_focus_main_window_on_add").get_active()

        ## Other tab ##
        new_gtkui_config["show_new_releases"] = \
            self.glade.get_object("chk_show_new_releases").get_active()
        new_core_config["send_info"] = \
            self.glade.get_object("chk_send_info").get_active()
        new_core_config["geoip_db_location"] = \
            self.glade.get_object("entry_geoip").get_text()

        ## Daemon tab ##
        new_core_config["daemon_port"] = \
            self.glade.get_object("spin_daemon_port").get_value_as_int()
        new_core_config["allow_remote"] = \
            self.glade.get_object("chk_allow_remote_connections").get_active()
        new_core_config["new_release_check"] = \
            self.glade.get_object("chk_new_releases").get_active()

        ## Proxy tab ##
        new_core_config["proxies"] = {}
        for t in ("peer", "web_seed", "tracker", "dht"):
            new_core_config["proxies"][t] = {}
            new_core_config["proxies"][t]["type"] = \
                self.glade.get_object("combo_proxy_type_%s" % t).get_active()
            new_core_config["proxies"][t]["port"] = \
                self.glade.get_object("spin_proxy_port_%s" % t).get_value_as_int()
            new_core_config["proxies"][t]["username"] = \
                self.glade.get_object("txt_proxy_username_%s" % t).get_text()
            new_core_config["proxies"][t]["password"] = \
                self.glade.get_object("txt_proxy_password_%s" % t).get_text()
            new_core_config["proxies"][t]["hostname"] = \
                self.glade.get_object("txt_proxy_server_%s" % t).get_text()

        ## Queue tab ##
        new_core_config["queue_new_to_top"] = \
            self.glade.get_object("chk_queue_new_top").get_active()
        new_core_config["max_active_seeding"] = \
            self.glade.get_object("spin_seeding").get_value_as_int()
        new_core_config["max_active_downloading"] = \
            self.glade.get_object("spin_downloading").get_value_as_int()
        new_core_config["max_active_limit"] = \
            self.glade.get_object("spin_active").get_value_as_int()
        new_core_config["dont_count_slow_torrents"] = \
            self.glade.get_object("chk_dont_count_slow_torrents").get_active()
        new_core_config["stop_seed_at_ratio"] = \
            self.glade.get_object("chk_seed_ratio").get_active()
        new_core_config["remove_seed_at_ratio"] = \
            self.glade.get_object("chk_remove_ratio").get_active()
        new_core_config["stop_seed_ratio"] = \
            self.glade.get_object("spin_share_ratio").get_value()
        new_core_config["share_ratio_limit"] = \
            self.glade.get_object("spin_share_ratio_limit").get_value()
        new_core_config["seed_time_ratio_limit"] = \
            self.glade.get_object("spin_seed_time_ratio_limit").get_value()
        new_core_config["seed_time_limit"] = \
            self.glade.get_object("spin_seed_time_limit").get_value()

        ## Cache tab ##
        new_core_config["cache_size"] = \
            self.glade.get_object("spin_cache_size").get_value_as_int()
        new_core_config["cache_expiry"] = \
            self.glade.get_object("spin_cache_expiry").get_value_as_int()

        # Run plugin hook to apply preferences
        component.get("PluginManager").run_on_apply_prefs()

        # GtkUI
        for key in new_gtkui_config.keys():
            # The values do not match so this needs to be updated
            if self.gtkui_config[key] != new_gtkui_config[key]:
                self.gtkui_config[key] = new_gtkui_config[key]

        # Core
        if client.connected():
            # Only do this if we're connected to a daemon
            config_to_set = {}
            for key in new_core_config.keys():
                # The values do not match so this needs to be updated
                try:
                    if self.core_config[key] != new_core_config[key]:
                        config_to_set[key] = new_core_config[key]
                except KeyError:
                    config_to_set[key] = new_core_config[key]

            if config_to_set:
                # Set each changed config value in the core
                client.core.set_config(config_to_set)
                client.force_call(True)
                # Update the configuration
                self.core_config.update(config_to_set)

        if hide:
            self.hide()
        else:
            # Re-show the dialog to make sure everything has been updated
            self.show()

        if client.is_classicmode() != new_gtkui_config["classic_mode"]:
            dialog = Gtk.MessageDialog(
                flags=Gtk.DialogFlags.MODAL
                | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                type=Gtk.MessageType.QUESTION,
                buttons=Gtk.ButtonsType.YES_NO,
                message_format=
                _("You must restart the deluge UI to change classic mode. Quit now?"
                  ))
            result = dialog.run()
            if result == Gtk.ResponseType.YES:
                shutdown_daemon = (not client.is_classicmode()
                                   and client.connected()
                                   and client.is_localhost())
                component.get("MainWindow").quit(shutdown=shutdown_daemon)
            dialog.destroy()
예제 #12
0
 def _on_switch_page(self, notebook, page, page_num):
     self.update(page_num)
     client.force_call(False)
예제 #13
0
 def _on_switch_page(self, notebook, page, page_num):
     self.update(page_num)
     client.force_call(False)
예제 #14
0
    def set_config(self, hide=False):
        """
        Sets all altered config values in the core.

        :param hide: bool, if True, will not re-show the dialog and will hide it instead
        """
        try:
            from hashlib import sha1 as sha_hash
        except ImportError:
            from sha import new as sha_hash

        # Get the values from the dialog
        new_core_config = {}
        new_gtkui_config = {}

        ## Downloads tab ##
        new_gtkui_config["interactive_add"] = self.glade.get_widget("chk_show_dialog").get_active()
        new_gtkui_config["focus_add_dialog"] = self.glade.get_widget("chk_focus_dialog").get_active()
        new_core_config["copy_torrent_file"] = self.glade.get_widget("chk_copy_torrent_file").get_active()
        new_core_config["del_copy_torrent_file"] = self.glade.get_widget("chk_del_copy_torrent_file").get_active()
        new_core_config["move_completed"] = self.glade.get_widget("chk_move_completed").get_active()
        if client.is_localhost():
            new_core_config["download_location"] = self.glade.get_widget("download_path_button").get_filename()
            new_core_config["move_completed_path"] = self.glade.get_widget("move_completed_path_button").get_filename()
            new_core_config["torrentfiles_location"] = self.glade.get_widget("torrent_files_button").get_filename()
        else:
            new_core_config["download_location"] = self.glade.get_widget("entry_download_path").get_text()
            new_core_config["move_completed_path"] = self.glade.get_widget("entry_move_completed_path").get_text()
            new_core_config["torrentfiles_location"] = self.glade.get_widget("entry_torrents_path").get_text()

        new_core_config["autoadd_enable"] = self.glade.get_widget("chk_autoadd").get_active()
        if client.is_localhost():
            new_core_config["autoadd_location"] = self.glade.get_widget("folder_autoadd").get_filename()
        else:
            new_core_config["autoadd_location"] = self.glade.get_widget("entry_autoadd").get_text()

        new_core_config["compact_allocation"] = self.glade.get_widget("radio_compact_allocation").get_active()
        new_core_config["prioritize_first_last_pieces"] = self.glade.get_widget(
            "chk_prioritize_first_last_pieces"
        ).get_active()
        new_core_config["add_paused"] = self.glade.get_widget("chk_add_paused").get_active()

        ## Network tab ##
        listen_ports = (
            self.glade.get_widget("spin_port_min").get_value_as_int(),
            self.glade.get_widget("spin_port_max").get_value_as_int(),
        )
        new_core_config["listen_ports"] = listen_ports
        new_core_config["random_port"] = self.glade.get_widget("chk_random_port").get_active()
        outgoing_ports = (
            self.glade.get_widget("spin_outgoing_port_min").get_value_as_int(),
            self.glade.get_widget("spin_outgoing_port_max").get_value_as_int(),
        )
        new_core_config["outgoing_ports"] = outgoing_ports
        new_core_config["random_outgoing_ports"] = self.glade.get_widget("chk_random_outgoing_ports").get_active()
        new_core_config["listen_interface"] = self.glade.get_widget("entry_interface").get_text()
        new_core_config["peer_tos"] = self.glade.get_widget("entry_peer_tos").get_text()
        new_core_config["dht"] = self.glade.get_widget("chk_dht").get_active()
        new_core_config["upnp"] = self.glade.get_widget("chk_upnp").get_active()
        new_core_config["natpmp"] = self.glade.get_widget("chk_natpmp").get_active()
        new_core_config["utpex"] = self.glade.get_widget("chk_utpex").get_active()
        new_core_config["lsd"] = self.glade.get_widget("chk_lsd").get_active()
        new_core_config["enc_in_policy"] = self.glade.get_widget("combo_encin").get_active()
        new_core_config["enc_out_policy"] = self.glade.get_widget("combo_encout").get_active()
        new_core_config["enc_level"] = self.glade.get_widget("combo_enclevel").get_active()
        new_core_config["enc_prefer_rc4"] = self.glade.get_widget("chk_pref_rc4").get_active()

        ## Bandwidth tab ##
        new_core_config["max_connections_global"] = self.glade.get_widget(
            "spin_max_connections_global"
        ).get_value_as_int()
        new_core_config["max_download_speed"] = self.glade.get_widget("spin_max_download").get_value()
        new_core_config["max_upload_speed"] = self.glade.get_widget("spin_max_upload").get_value()
        new_core_config["max_upload_slots_global"] = self.glade.get_widget(
            "spin_max_upload_slots_global"
        ).get_value_as_int()
        new_core_config["max_half_open_connections"] = self.glade.get_widget(
            "spin_max_half_open_connections"
        ).get_value_as_int()
        new_core_config["max_connections_per_second"] = self.glade.get_widget(
            "spin_max_connections_per_second"
        ).get_value_as_int()
        new_core_config["max_connections_per_torrent"] = self.glade.get_widget(
            "spin_max_connections_per_torrent"
        ).get_value_as_int()
        new_core_config["max_upload_slots_per_torrent"] = self.glade.get_widget(
            "spin_max_upload_slots_per_torrent"
        ).get_value_as_int()
        new_core_config["max_upload_speed_per_torrent"] = self.glade.get_widget(
            "spin_max_upload_per_torrent"
        ).get_value()
        new_core_config["max_download_speed_per_torrent"] = self.glade.get_widget(
            "spin_max_download_per_torrent"
        ).get_value()
        new_core_config["ignore_limits_on_local_network"] = self.glade.get_widget(
            "chk_ignore_limits_on_local_network"
        ).get_active()
        new_core_config["rate_limit_ip_overhead"] = self.glade.get_widget("chk_rate_limit_ip_overhead").get_active()

        ## Interface tab ##
        new_gtkui_config["enable_system_tray"] = self.glade.get_widget("chk_use_tray").get_active()
        new_gtkui_config["close_to_tray"] = self.glade.get_widget("chk_min_on_close").get_active()
        new_gtkui_config["start_in_tray"] = self.glade.get_widget("chk_start_in_tray").get_active()
        new_gtkui_config["enable_appindicator"] = self.glade.get_widget("chk_enable_appindicator").get_active()
        new_gtkui_config["lock_tray"] = self.glade.get_widget("chk_lock_tray").get_active()
        passhex = sha_hash(self.glade.get_widget("txt_tray_password").get_text()).hexdigest()
        if passhex != "c07eb5a8c0dc7bb81c217b67f11c3b7a5e95ffd7":
            new_gtkui_config["tray_password"] = passhex
        new_gtkui_config["classic_mode"] = self.glade.get_widget("chk_classic_mode").get_active()
        new_gtkui_config["show_rate_in_title"] = self.glade.get_widget("chk_show_rate_in_title").get_active()

        ## Other tab ##
        new_gtkui_config["show_new_releases"] = self.glade.get_widget("chk_show_new_releases").get_active()
        new_core_config["send_info"] = self.glade.get_widget("chk_send_info").get_active()
        new_core_config["geoip_db_location"] = self.glade.get_widget("entry_geoip").get_text()

        ## Daemon tab ##
        new_core_config["daemon_port"] = self.glade.get_widget("spin_daemon_port").get_value_as_int()
        new_core_config["allow_remote"] = self.glade.get_widget("chk_allow_remote_connections").get_active()
        new_core_config["new_release_check"] = self.glade.get_widget("chk_new_releases").get_active()

        ## Proxy tab ##
        new_core_config["proxies"] = {}
        for t in ("peer", "web_seed", "tracker", "dht"):
            new_core_config["proxies"][t] = {}
            new_core_config["proxies"][t]["type"] = self.glade.get_widget("combo_proxy_type_%s" % t).get_active()
            new_core_config["proxies"][t]["port"] = self.glade.get_widget("spin_proxy_port_%s" % t).get_value_as_int()
            new_core_config["proxies"][t]["username"] = self.glade.get_widget("txt_proxy_username_%s" % t).get_text()
            new_core_config["proxies"][t]["password"] = self.glade.get_widget("txt_proxy_password_%s" % t).get_text()
            new_core_config["proxies"][t]["hostname"] = self.glade.get_widget("txt_proxy_server_%s" % t).get_text()

        ## Queue tab ##
        new_core_config["queue_new_to_top"] = self.glade.get_widget("chk_queue_new_top").get_active()
        new_core_config["max_active_seeding"] = self.glade.get_widget("spin_seeding").get_value_as_int()
        new_core_config["max_active_downloading"] = self.glade.get_widget("spin_downloading").get_value_as_int()
        new_core_config["max_active_limit"] = self.glade.get_widget("spin_active").get_value_as_int()
        new_core_config["dont_count_slow_torrents"] = self.glade.get_widget("chk_dont_count_slow_torrents").get_active()
        new_core_config["stop_seed_at_ratio"] = self.glade.get_widget("chk_seed_ratio").get_active()
        new_core_config["remove_seed_at_ratio"] = self.glade.get_widget("chk_remove_ratio").get_active()
        new_core_config["stop_seed_ratio"] = self.glade.get_widget("spin_share_ratio").get_value()
        new_core_config["share_ratio_limit"] = self.glade.get_widget("spin_share_ratio_limit").get_value()
        new_core_config["seed_time_ratio_limit"] = self.glade.get_widget("spin_seed_time_ratio_limit").get_value()
        new_core_config["seed_time_limit"] = self.glade.get_widget("spin_seed_time_limit").get_value()

        ## Cache tab ##
        new_core_config["cache_size"] = self.glade.get_widget("spin_cache_size").get_value_as_int()
        new_core_config["cache_expiry"] = self.glade.get_widget("spin_cache_expiry").get_value_as_int()

        # Run plugin hook to apply preferences
        component.get("PluginManager").run_on_apply_prefs()

        # GtkUI
        for key in new_gtkui_config.keys():
            # The values do not match so this needs to be updated
            if self.gtkui_config[key] != new_gtkui_config[key]:
                self.gtkui_config[key] = new_gtkui_config[key]

        # Core
        if client.connected():
            # Only do this if we're connected to a daemon
            config_to_set = {}
            for key in new_core_config.keys():
                # The values do not match so this needs to be updated
                try:
                    if self.core_config[key] != new_core_config[key]:
                        config_to_set[key] = new_core_config[key]
                except KeyError:
                    config_to_set[key] = new_core_config[key]

            if config_to_set:
                # Set each changed config value in the core
                client.core.set_config(config_to_set)
                client.force_call(True)
                # Update the configuration
                self.core_config.update(config_to_set)

        if hide:
            self.hide()
        else:
            # Re-show the dialog to make sure everything has been updated
            self.show()
예제 #15
0
파일: preferences.py 프로젝트: zluca/deluge
    def _apply_prefs(self):
        if self.core_config is None:
            return

        def update_conf_value(key, source_dict, dest_dict, updated):
            if dest_dict[key] != source_dict[key]:
                dest_dict[key] = source_dict[key]
                updated = True
            return updated

        new_core_config = {}
        for pane in self.panes:
            if not isinstance(pane, InterfacePane):
                pane.add_config_values(new_core_config)
        # Apply Core Prefs
        if client.connected():
            # Only do this if we're connected to a daemon
            config_to_set = {}
            for key in new_core_config:
                # The values do not match so this needs to be updated
                if self.core_config[key] != new_core_config[key]:
                    config_to_set[key] = new_core_config[key]

            if config_to_set:
                # Set each changed config value in the core
                client.core.set_config(config_to_set)
                client.force_call(True)
                # Update the configuration
                self.core_config.update(config_to_set)

        # Update Interface Prefs
        new_console_config = {}
        didupdate = False
        for pane in self.panes:
            # could just access panes by index, but that would break if panes
            # are ever reordered, so do it the slightly slower but safer way
            if isinstance(pane, InterfacePane):
                pane.add_config_values(new_console_config)
                for k in ['ring_bell', 'language']:
                    didupdate = update_conf_value(k, new_console_config,
                                                  self.console_config,
                                                  didupdate)
                for k in ['separate_complete', 'move_selection']:
                    didupdate = update_conf_value(
                        k,
                        new_console_config,
                        self.console_config['torrentview'],
                        didupdate,
                    )
                for k in [
                        'ignore_duplicate_lines',
                        'save_command_history',
                        'third_tab_lists_all',
                        'torrents_per_tab_press',
                ]:
                    didupdate = update_conf_value(
                        k, new_console_config, self.console_config['cmdline'],
                        didupdate)

        if didupdate:
            self.parent_mode.on_config_changed()