1
# Copyright (C) 2008-2011 LottaNZB Development Team
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; version 3.
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU General Public License for more details.
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
16
from lottanzb.core.environ import _
17
from lottanzb.backend import Backend
18
from lottanzb.config.sabnzbd import create_api_key
19
from lottanzb.gui.prefs.base import Tab
20
from lottanzb.gui.framework.proxy import (
21
GObjectEndPoint, ToggleEndPoint, SpinButtonEndPoint, DelayedEntryEndPoint,
22
LabelEndPoint, Conduit, ConduitCollection, DelayedPasswordEntryEndPoint)
24
class RemoteAccessTab(Tab):
26
builder_file = "prefs_tab_remote_access"
27
label = _("Remote Access")
28
help_topic = "remote-access"
30
def __init__(self, component_manager):
31
Tab.__init__(self, component_manager)
33
self.conduits = ConduitCollection()
35
def set_config(self, lottanzb_config, sabnzbd_config):
36
self.conduits.remove_all()
38
self.conduits.add(Conduit(
39
GObjectEndPoint(sabnzbd_config.misc, "host"),
40
RemoteConnnectionEndPoint(self.allow_remote_connections)))
42
self.conduits.add(Conduit(
43
GObjectEndPoint(sabnzbd_config.misc, "port"),
44
SpinButtonEndPoint(self.port)))
46
self.conduits.add(Conduit(
47
GObjectEndPoint(sabnzbd_config.misc, "username"),
48
DelayedEntryEndPoint(self.username)))
50
self.conduits.add(Conduit(
51
GObjectEndPoint(sabnzbd_config.misc, "password"),
52
DelayedPasswordEntryEndPoint(self.password)))
54
self.conduits.add(Conduit(
55
GObjectEndPoint(sabnzbd_config.misc, "api_key"),
56
LabelEndPoint(self.api_key)))
58
info = self._component_manager.get(Backend).interface.connection_info
60
self.allow_remote_connections.set_sensitive(info.is_local)
62
if sabnzbd_config.misc.username or sabnzbd_config.misc.password:
63
self.authenticate.set_active(True)
65
self.authenticate.set_active(False)
67
self.authenticate.emit("toggled")
69
def on_authenticate__toggled(self, widget):
70
active = widget.get_active()
72
self.username.set_sensitive(active)
73
self.username_label.set_sensitive(active)
74
self.password.set_sensitive(active)
75
self.password_label.set_sensitive(active)
78
self.username.set_text("")
79
self.password.set_text("")
81
def on_generate_api_key__clicked(self, widget):
82
self.api_key.set_text(create_api_key())
84
def needs_restart(self, lottanzb_config, old_lottanzb_config,
85
sabnzbd_config, old_sabnzbd_config):
86
old = [old_sabnzbd_config.misc.host, old_sabnzbd_config.misc.port]
87
new = [sabnzbd_config.misc.host, sabnzbd_config.misc.port]
92
class RemoteConnnectionEndPoint(ToggleEndPoint):
94
if self._object.get_active():
99
def set_value(self, value):
100
if value in ("localhost", "127.0.0.1"):
101
self._object.set_active(False)
103
self._object.set_active(True)