1 # Copyright (c) Stas Shtin, 2010
3 # This file is part of IPyPBX.
5 # IPyPBX is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # IPyPBX is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with IPyPBX. If not, see <http://www.gnu.org/licenses/>.
18 from ipypbx import models, state
21 class BaseHandler(object):
23 Base class for various entity handlers.
25 Doesn't do anything useful on its own.
30 def __init__(self, parent):
38 class ConnectionsHandler(BaseHandler):
43 self.connections = list(state.store.query(models.Connection))
44 self.currentConnection = None
46 def select(self, index):
48 Select another connection as current.
50 self.currentConnection = state.connections[index]
54 TODO: Clone an existing connection.
56 This creates a new connection with bound data copied from another one.
63 self.currentConnection = None
64 self.parent.ui.connectionName.setText('')
65 self.parent.ui.connectionLocalIpAddress.setText('')
66 self.parent.ui.connectionLocalPort.setText('')
67 self.parent.ui.connectionFreeswitchIpAddress.setText('')
68 self.parent.ui.connectionFreeswitchPort.setText('')
72 Save new or existing connection.
74 name = unicode(self.parent.ui.connectionName.text())
75 connection = models.Connection(
77 local_ip_address=unicode(
78 self.parent.ui.connectionLocalIpAddress.text()),
80 self.parent.ui.connectionLocalPort.text()),
81 freeswitch_ip_address=unicode(
82 self.parent.ui.connectionFreeswitchIpAddress.text()),
84 self.parent.ui.connectionFreeswitchPort.text()))
85 if not self.currentConnection:
86 self.connections.append(connection)
87 self.currentConnection = connection
88 self.parent.ui.connectionList.addItem(name)