summaryrefslogtreecommitdiffstats
path: root/deluge/ui/console/modes/preferences/preference_panes.py
blob: 8663d8a9c07a34232dc4f9058d1f8032f0923445 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Nick Lanham <nick@afternight.org>
#
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#

from __future__ import unicode_literals

import logging

from deluge.common import is_ip
from deluge.decorators import overrides
from deluge.i18n import get_languages
from deluge.ui.client import client
from deluge.ui.common import DISK_CACHE_KEYS
from deluge.ui.console.widgets import BaseInputPane, BaseWindow
from deluge.ui.console.widgets.fields import FloatSpinInput, TextInput
from deluge.ui.console.widgets.popup import PopupsHandler

log = logging.getLogger(__name__)


class BasePreferencePane(BaseInputPane, BaseWindow, PopupsHandler):
    def __init__(self, name, preferences):
        PopupsHandler.__init__(self)
        self.preferences = preferences
        BaseWindow.__init__(
            self,
            '%s' % name,
            self.pane_width,
            preferences.height,
            posy=1,
            posx=self.pane_x_pos,
        )
        BaseInputPane.__init__(self, preferences, border_off_east=1)
        self.name = name

        # have we scrolled down in the list
        self.input_offset = 0

    @overrides(BaseInputPane)
    def handle_read(self, c):
        if self.popup:
            ret = self.popup.handle_read(c)
            if self.popup and self.popup.closed():
                self.pop_popup()
            self.refresh()
            return ret
        return BaseInputPane.handle_read(self, c)

    @property
    def visible_content_pane_height(self):
        y, x = self.visible_content_pane_size
        return y

    @property
    def pane_x_pos(self):
        return self.preferences.sidebar_width

    @property
    def pane_width(self):
        return self.preferences.width

    @property
    def cols(self):
        return self.pane_width

    @property
    def rows(self):
        return self.preferences.height

    def is_active_pane(self):
        return self.preferences.is_active_pane(self)

    def create_pane(self, core_conf, console_config):
        pass

    def add_config_values(self, conf_dict):
        for ipt in self.inputs:
            if ipt.has_input():
                # Need special cases for in/out ports or proxy since they are tuples or dicts.
                if ipt.name == 'listen_ports_to' or ipt.name == 'listen_ports_from':
                    conf_dict['listen_ports'] = (
                        self.infrom.get_value(),
                        self.into.get_value(),
                    )
                elif ipt.name == 'out_ports_to' or ipt.name == 'out_ports_from':
                    conf_dict['outgoing_ports'] = (
                        self.outfrom.get_value(),
                        self.outto.get_value(),
                    )
                elif ipt.name == 'listen_interface':
                    listen_interface = ipt.get_value().strip()
                    if is_ip(listen_interface) or not listen_interface:
                        conf_dict['listen_interface'] = listen_interface
                elif ipt.name == 'outgoing_interface':
                    outgoing_interface = ipt.get_value().strip()
                    conf_dict['outgoing_interface'] = outgoing_interface
                elif ipt.name.startswith('proxy_'):
                    if ipt.name == 'proxy_type':
                        conf_dict.setdefault('proxy', {})['type'] = ipt.get_value()
                    elif ipt.name == 'proxy_username':
                        conf_dict.setdefault('proxy', {})['username'] = ipt.get_value()
                    elif ipt.name == 'proxy_password':
                        conf_dict.setdefault('proxy', {})['password'] = ipt.get_value()
                    elif ipt.name == 'proxy_hostname':
                        conf_dict.setdefault('proxy', {})['hostname'] = ipt.get_value()
                    elif ipt.name == 'proxy_port':
                        conf_dict.setdefault('proxy', {})['port'] = ipt.get_value()
                    elif ipt.name == 'proxy_hostnames':
                        conf_dict.setdefault('proxy', {})[
                            'proxy_hostnames'
                        ] = ipt.get_value()
                    elif ipt.name == 'proxy_peer_connections':
                        conf_dict.setdefault('proxy', {})[
                            'proxy_peer_connections'
                        ] = ipt.get_value()
                    elif ipt.name == 'proxy_tracker_connections':
                        conf_dict.setdefault('proxy', {})[
                            'proxy_tracker_connections'
                        ] = ipt.get_value()
                elif ipt.name == 'force_proxy':
                    conf_dict.setdefault('proxy', {})['force_proxy'] = ipt.get_value()
                elif ipt.name == 'anonymous_mode':
                    conf_dict.setdefault('proxy', {})[
                        'anonymous_mode'
                    ] = ipt.get_value()
                else:
                    conf_dict[ipt.name] = ipt.get_value()

                if hasattr(ipt, 'get_child'):
                    c = ipt.get_child()
                    conf_dict[c.name] = c.get_value()

    def update_values(self, conf_dict):
        for ipt in self.inputs:
            if ipt.has_input():
                try:
                    ipt.set_value(conf_dict[ipt.name])
                except KeyError:  # just ignore if it's not in dict
                    pass
                if hasattr(ipt, 'get_child'):
                    try:
                        c = ipt.get_child()
                        c.set_value(conf_dict[c.name])
                    except KeyError:  # just ignore if it's not in dict
                        pass

    def render(self, mode, screen, width, focused):
        height = self.get_content_height()
        self.ensure_content_pane_height(height)
        self.screen.erase()

        if focused and self.active_input == -1:
            self.move_active_down(1)

        self.render_inputs(focused=focused)

    @overrides(BaseWindow)
    def refresh(self):
        BaseWindow.refresh(self)
        if self.popup:
            self.popup.refresh()

    def update(self, active):
        pass


class InterfacePane(BasePreferencePane):
    def __init__(self, preferences):
        BasePreferencePane.__init__(self, ' %s ' % _('Interface'), preferences)

    @overrides(BasePreferencePane)
    def create_pane(self, core_conf, console_config):
        self.add_header(_('General options'))

        self.add_checked_input(
            'ring_bell',
            _('Ring system bell when a download finishes'),
            console_config['ring_bell'],
        )
        self.add_header('Console UI', space_above=True)
        self.add_checked_input(
            'separate_complete',
            _('List complete torrents after incomplete regardless of sorting order'),
            console_config['torrentview']['separate_complete'],
        )
        self.add_checked_input(
            'move_selection',
            _('Move selection when moving torrents in the queue'),
            console_config['torrentview']['move_selection'],
        )

        langs = get_languages()
        langs.insert(0, ('', 'System Default'))
        self.add_combo_input(
            'language', _('Language'), langs, default=console_config['language']
        )
        self.add_header(_('Command Line Mode'), space_above=True)
        self.add_checked_input(
            'ignore_duplicate_lines',
            _('Do not store duplicate input in history'),
            console_config['cmdline']['ignore_duplicate_lines'],
        )
        self.add_checked_input(
            'save_command_history',
            _('Store and load command line history in command line mode'),
            console_config['cmdline']['save_command_history'],
        )
        self.add_header('')
        self.add_checked_input(
            'third_tab_lists_all',
            _('Third tab lists all remaining torrents in command line mode'),
            console_config['cmdline']['third_tab_lists_all'],
        )
        self.add_int_spin_input(
            'torrents_per_tab_press',
            _('Torrents per tab press'),
            console_config['cmdline']['torrents_per_tab_press'],
            min_val=5,
            max_val=10000,
        )


class DownloadsPane(BasePreferencePane):
    def __init__(self, preferences):
        BasePreferencePane.__init__(self, ' %s ' % _('Downloads'), preferences)

    @overrides(BasePreferencePane)
    def create_pane(self, core_conf, console_config):
        self.add_header(_('Folders'))
        self.add_text_input(
            'download_location',
            '%s:' % _('Download To'),
            core_conf['download_location'],
            complete=True,
            activate_input=True,
            col='+1',
        )
        cmptxt = TextInput(
            self.preferences,
            'move_completed_path',
            None,
            self.move,
            self.pane_width,
            core_conf['move_completed_path'],
            False,
        )
        self.add_checkedplus_input(
            'move_completed',
            '%s:' % _('Move completed to'),
            cmptxt,
            core_conf['move_completed'],
        )
        copytxt = TextInput(
            self.preferences,
            'torrentfiles_location',
            None,
            self.move,
            self.pane_width,
            core_conf['torrentfiles_location'],
            False,
        )
        self.add_checkedplus_input(
            'copy_torrent_file',
            '%s:' % _('Copy of .torrent files to'),
            copytxt,
            core_conf['copy_torrent_file'],
        )
        self.add_checked_input(
            'del_copy_torrent_file',
            _('Delete copy of torrent file on remove'),
            core_conf['del_copy_torrent_file'],
        )

        self.add_header(_('Options'), space_above=True)
        self.add_checked_input(
            'prioritize_first_last_pieces',
            ('Prioritize first and last pieces of torrent'),
            core_conf['prioritize_first_last_pieces'],
        )
        self.add_checked_input(
            'sequential_download',
            _('Sequential download'),
            core_conf['sequential_download'],
        )
        self.add_checked_input('add_paused', _('Add Paused'), core_conf['add_paused'])
        self.add_checked_input(
            'pre_allocate_storage',
            _('Pre-Allocate disk space'),
            core_conf['pre_allocate_storage'],
        )


class NetworkPane(BasePreferencePane):
    def __init__(self, preferences):
        BasePreferencePane.__init__(self, ' %s ' % _('Network'), preferences)

    @overrides(BasePreferencePane)
    def create_pane(self, core_conf, console_config):
        self.add_header(_('Incomming Ports'))
        inrand = self.add_checked_input(
            'random_port',
            'Use Random Ports    Active Port: %d' % self.preferences.active_port,
            core_conf['random_port'],
        )
        listen_ports = core_conf['listen_ports']
        self.infrom = self.add_int_spin_input(
            'listen_ports_from',
            '    %s:' % _('From'),
            value=listen_ports[0],
            min_val=0,
            max_val=65535,
        )
        self.infrom.set_depend(inrand, inverse=True)
        self.into = self.add_int_spin_input(
            'listen_ports_to',
            '    %s:' % _('To'),
            value=listen_ports[1],
            min_val=0,
            max_val=65535,
        )
        self.into.set_depend(inrand, inverse=True)

        self.add_header(_('Outgoing Ports'), space_above=True)
        outrand = self.add_checked_input(
            'random_outgoing_ports',
            _('Use Random Ports'),
            core_conf['random_outgoing_ports'],
        )
        out_ports = core_conf['outgoing_ports']
        self.outfrom = self.add_int_spin_input(
            'out_ports_from',
            '    %s:' % _('From'),
            value=out_ports[0],
            min_val=0,
            max_val=65535,
        )
        self.outfrom.set_depend(outrand, inverse=True)
        self.outto = self.add_int_spin_input(
            'out_ports_to',
            '    %s:' % _('To'),
            value=out_ports[1],
            min_val=0,
            max_val=65535,
        )
        self.outto.set_depend(outrand, inverse=True)

        self.add_header(_('Incoming Interface'), space_above=True)
        self.add_text_input(
            'listen_interface',
            _('IP address of the interface to listen on (leave empty for default):'),
            core_conf['listen_interface'],
        )

        self.add_header(_('Outgoing Interface'), space_above=True)
        self.add_text_input(
            'outgoing_interface',
            _(
                'The network interface name or IP address for outgoing '
                'BitTorrent connections. (Leave empty for default.):'
            ),
            core_conf['outgoing_interface'],
        )

        self.add_header('TOS', space_above=True)
        self.add_text_input('peer_tos', 'Peer TOS Byte:', core_conf['peer_tos'])

        self.add_header(_('Network Extras'), space_above=True)
        self.add_checked_input('upnp', 'UPnP', core_conf['upnp'])
        self.add_checked_input('natpmp', 'NAT-PMP', core_conf['natpmp'])
        self.add_checked_input('utpex', 'Peer Exchange', core_conf['utpex'])
        self.add_checked_input('lsd', 'LSD', core_conf['lsd'])
        self.add_checked_input('dht', 'DHT', core_conf['dht'])

        self.add_header(_('Encryption'), space_above=True)
        self.add_select_input(
            'enc_in_policy',
            '%s:' % _('Inbound'),
            [_('Forced'), _('Enabled'), _('Disabled')],
            [0, 1, 2],
            core_conf['enc_in_policy'],
            active_default=True,
            col='+1',
        )
        self.add_select_input(
            'enc_out_policy',
            '%s:' % _('Outbound'),
            [_('Forced'), _('Enabled'), _('Disabled')],
            [0, 1, 2],
            core_conf['enc_out_policy'],
            active_default=True,
        )
        self.add_select_input(
            'enc_level',
            '%s:' % _('Level'),
            [_('Handshake'), _('Full Stream'), _('Either')],
            [0, 1, 2],
            core_conf['enc_level'],
            active_default=True,
        )


class BandwidthPane(BasePreferencePane):
    def __init__(self, preferences):
        BasePreferencePane.__init__(self, ' %s ' % _('Bandwidth'), preferences)

    @overrides(BasePreferencePane)
    def create_pane(self, core_conf, console_config):
        self.add_header(_('Global Bandwidth Usage'))
        self.add_int_spin_input(
            'max_connections_global',
            '%s:' % _('Maximum Connections'),
            core_conf['max_connections_global'],
            min_val=-1,
            max_val=9000,
        )
        self.add_int_spin_input(
            'max_upload_slots_global',
            '%s:' % _('Maximum Upload Slots'),
            core_conf['max_upload_slots_global'],
            min_val=-1,
            max_val=9000,
        )
        self.add_float_spin_input(
            'max_download_speed',
            '%s:' % _('Maximum Download Speed (KiB/s)'),
            core_conf['max_download_speed'],
            min_val=-1.0,
            max_val=60000.0,
        )
        self.add_float_spin_input(
            'max_upload_speed',
            '%s:' % _('Maximum Upload Speed (KiB/s)'),
            core_conf['max_upload_speed'],
            min_val=-1.0,
            max_val=60000.0,
        )
        self.add_int_spin_input(
            'max_half_open_connections',
            '%s:' % _('Maximum Half-Open Connections'),
            core_conf['max_half_open_connections'],
            min_val=-1,
            max_val=9999,
        )
        self.add_int_spin_input(
            'max_connections_per_second',
            '%s:' % _('Maximum Connection Attempts per Second'),
            core_conf['max_connections_per_second'],
            min_val=-1,
            max_val=9999,
        )
        self.add_checked_input(
            'ignore_limits_on_local_network',
            _('Ignore limits on local network'),
            core_conf['ignore_limits_on_local_network'],
        )
        self.add_checked_input(
            'rate_limit_ip_overhead',
            _('Rate Limit IP Overhead'),
            core_conf['rate_limit_ip_overhead'],
        )
        self.add_header(_('Per Torrent Bandwidth Usage'), space_above=True)
        self.add_int_spin_input(
            'max_connections_per_torrent',
            '%s:' % _('Maximum Connections'),
            core_conf['max_connections_per_torrent'],
            min_val=-1,
            max_val=9000,
        )
        self.add_int_spin_input(
            'max_upload_slots_per_torrent',
            '%s:' % _('Maximum Upload Slots'),
            core_conf['max_upload_slots_per_torrent'],
            min_val=-1,
            max_val=9000,
        )
        self.add_float_spin_input(
            'max_download_speed_per_torrent',
            '%s:' % _('Maximum Download Speed (KiB/s)'),
            core_conf['max_download_speed_per_torrent'],
            min_val=-1.0,
            max_val=60000.0,
        )
        self.add_float_spin_input(
            'max_upload_speed_per_torrent',
            '%s:' % _('Maximum Upload Speed (KiB/s)'),
            core_conf['max_upload_speed_per_torrent'],
            min_val=-1.0,
            max_val=60000.0,
        )


class OtherPane(BasePreferencePane):
    def __init__(self, preferences):
        BasePreferencePane.__init__(self, ' %s ' % _('Other'), preferences)

    @overrides(BasePreferencePane)
    def create_pane(self, core_conf, console_config):
        self.add_header(_('System Information'))
        self.add_info_field('info1', ' Help us improve Deluge by sending us your', '')
        self.add_info_field(
            'info2', ' Python version, PyGTK version, OS and processor', ''
        )
        self.add_info_field(
            'info3', ' types.  Absolutely no other information is sent.', ''
        )
        self.add_checked_input(
            'send_info',
            _('Yes, please send anonymous statistics.'),
            core_conf['send_info'],
        )
        self.add_header(_('GeoIP Database'), space_above=True)
        self.add_text_input(
            'geoip_db_location', 'Location:', core_conf['geoip_db_location']
        )


class DaemonPane(BasePreferencePane):
    def __init__(self, preferences):
        BasePreferencePane.__init__(self, ' %s ' % _('Daemon'), preferences)

    @overrides(BasePreferencePane)
    def create_pane(self, core_conf, console_config):
        self.add_header('Port')
        self.add_int_spin_input(
            'daemon_port',
            '%s:' % _('Daemon Port'),
            core_conf['daemon_port'],
            min_val=0,
            max_val=65535,
        )
        self.add_header('Connections', space_above=True)
        self.add_checked_input(
            'allow_remote', _('Allow remote connections'), core_conf['allow_remote']
        )
        self.add_header('Other', space_above=True)
        self.add_checked_input(
            'new_release_check',
            _('Periodically check the website for new releases'),
            core_conf['new_release_check'],
        )


class QueuePane(BasePreferencePane):
    def __init__(self, preferences):
        BasePreferencePane.__init__(self, ' %s ' % _('Queue'), preferences)

    @overrides(BasePreferencePane)
    def create_pane(self, core_conf, console_config):
        self.add_header(_('New Torrents'))
        self.add_checked_input(
            'queue_new_to_top', _('Queue to top'), core_conf['queue_new_to_top']
        )
        self.add_header(_('Active Torrents'), True)
        self.add_int_spin_input(
            'max_active_limit',
            '%s:' % _('Total'),
            core_conf['max_active_limit'],
            min_val=-1,
            max_val=9999,
        )
        self.add_int_spin_input(
            'max_active_downloading',
            '%s:' % _('Downloading'),
            core_conf['max_active_downloading'],
            min_val=-1,
            max_val=9999,
        )
        self.add_int_spin_input(
            'max_active_seeding',
            '%s:' % _('Seeding'),
            core_conf['max_active_seeding'],
            min_val=-1,
            max_val=9999,
        )
        self.add_checked_input(
            'dont_count_slow_torrents',
            'Ignore slow torrents',
            core_conf['dont_count_slow_torrents'],
        )
        self.add_checked_input(
            'auto_manage_prefer_seeds',
            'Prefer seeding torrents',
            core_conf['auto_manage_prefer_seeds'],
        )
        self.add_header(_('Seeding Rotation'), space_above=True)
        self.add_float_spin_input(
            'share_ratio_limit',
            '%s:' % _('Share Ratio'),
            core_conf['share_ratio_limit'],
            precision=2,
            min_val=-1.0,
            max_val=100.0,
        )
        self.add_float_spin_input(
            'seed_time_ratio_limit',
            '%s:' % _('Time Ratio'),
            core_conf['seed_time_ratio_limit'],
            precision=2,
            min_val=-1.0,
            max_val=100.0,
        )
        self.add_int_spin_input(
            'seed_time_limit',
            '%s:' % _('Time (m)'),
            core_conf['seed_time_limit'],
            min_val=1,
            max_val=10000,
        )
        seedratio = FloatSpinInput(
            self.mode,
            'stop_seed_ratio',
            '',
            self.move,
            core_conf['stop_seed_ratio'],
            precision=2,
            inc_amt=0.1,
            min_val=0.5,
            max_val=100.0,
        )
        self.add_checkedplus_input(
            'stop_seed_at_ratio',
            '%s:' % _('Share Ratio Reached'),
            seedratio,
            core_conf['stop_seed_at_ratio'],
        )
        self.add_checked_input(
            'remove_seed_at_ratio',
            _('Remove torrent (Unchecked pauses torrent)'),
            core_conf['remove_seed_at_ratio'],
        )


class ProxyPane(BasePreferencePane):
    def __init__(self, preferences):
        BasePreferencePane.__init__(self, ' %s ' % _('Proxy'), preferences)

    @overrides(BasePreferencePane)
    def create_pane(self, core_conf, console_config):
        proxy = core_conf['proxy']

        self.add_header(_('Proxy Settings'))
        self.add_header(_('Proxy'), space_above=True)
        self.add_int_spin_input(
            'proxy_type', '%s:' % _('Type'), proxy['type'], min_val=0, max_val=5
        )
        self.add_text_input('proxy_username', '%s:' % _('Username'), proxy['username'])
        self.add_text_input('proxy_password', '%s:' % _('Password'), proxy['password'])
        self.add_text_input('proxy_hostname', '%s:' % _('Hostname'), proxy['hostname'])
        self.add_int_spin_input(
            'proxy_port', '%s:' % _('Port'), proxy['port'], min_val=0, max_val=65535
        )
        self.add_checked_input(
            'proxy_hostnames', _('Proxy Hostnames'), proxy['proxy_hostnames']
        )
        self.add_checked_input(
            'proxy_peer_connections', _('Proxy Peers'), proxy['proxy_peer_connections']
        )
        self.add_checked_input(
            'proxy_tracker_connections',
            _('Proxy Trackers'),
            proxy['proxy_tracker_connections'],
        )
        self.add_header('%s' % _('Force Proxy'), space_above=True)
        self.add_checked_input('force_proxy', _('Force Proxy'), proxy['force_proxy'])
        self.add_checked_input(
            'anonymous_mode', _('Hide Client Identity'), proxy['anonymous_mode']
        )
        self.add_header('%s' % _('Proxy Type Help'), space_above=True)
        self.add_text_area(
            'proxy_text_area',
            ' 0: None   1: Socks4\n'
            ' 2: Socks5 3: Socks5 Auth\n'
            ' 4: HTTP   5: HTTP Auth\n'
            ' 6: I2P',
        )


class CachePane(BasePreferencePane):
    def __init__(self, preferences):
        BasePreferencePane.__init__(self, ' %s ' % _('Cache'), preferences)
        self.created = False

    @overrides(BasePreferencePane)
    def create_pane(self, core_conf, console_config):
        self.core_conf = core_conf

    def build_pane(self, core_conf, status):
        self.created = True
        self.add_header(_('Settings'), space_below=True)
        self.add_int_spin_input(
            'cache_size',
            '%s:' % _('Cache Size (16 KiB blocks)'),
            core_conf['cache_size'],
            min_val=0,
            max_val=99999,
        )
        self.add_int_spin_input(
            'cache_expiry',
            '%s:' % _('Cache Expiry (seconds)'),
            core_conf['cache_expiry'],
            min_val=1,
            max_val=32000,
        )
        self.add_header(' %s' % _('Write'), space_above=True)
        self.add_info_field(
            'blocks_written',
            '  %s:' % _('Blocks Written'),
            status['disk.num_blocks_written'],
        )
        self.add_info_field(
            'writes', '  %s:' % _('Writes'), status['disk.num_write_ops']
        )
        self.add_info_field(
            'write_hit_ratio',
            '  %s:' % _('Write Cache Hit Ratio'),
            '%.2f' % status['write_hit_ratio'],
        )
        self.add_header(' %s' % _('Read'))
        self.add_info_field(
            'blocks_read', '  %s:' % _('Blocks Read'), status['disk.num_blocks_read']
        )
        self.add_info_field('reads', '  %s:' % _('Reads'), status['disk.num_read_ops'])
        self.add_info_field(
            'read_hit_ratio',
            '  %s:' % _('Read Cache Hit Ratio'),
            '%.2f' % status['read_hit_ratio'],
        )
        self.add_header(' %s' % _('Size'))
        self.add_info_field(
            'cache_size_info',
            '  %s:' % _('Cache Size'),
            status['disk.disk_blocks_in_use'],
        )
        self.add_info_field(
            'read_cache_size',
            '  %s:' % _('Read Cache Size'),
            status['disk.read_cache_blocks'],
        )

    @overrides(BasePreferencePane)
    def update(self, active):
        if active:
            client.core.get_session_status(DISK_CACHE_KEYS).addCallback(
                self.update_cache_status_fields
            )

    def update_cache_status_fields(self, status):
        if not self.created:
            self.build_pane(self.core_conf, status)
        else:
            for ipt in self.inputs:
                if not ipt.has_input() and ipt.name in status:
                    ipt.set_value(status[ipt.name])
        self.preferences.refresh()