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
19 from PyQt4 import QtCore
22 class BaseHandler(object):
24 Base class for various entity handlers.
26 Doesn't do anything useful on its own.
31 def __init__(self, parent):
39 class ConnectionController(QtCore.QObject):
43 # def initState(self):
44 # self.connections = []
45 # #self.connections = list(state.store.query(models.Connection))
46 # self.currentConnection = None
48 # for connection in self.connections:
49 # self.parent.ui.connectionList.addItem(connection.name)
51 # if self.connections:
52 # print self.parent.ui.connectionList.currentRow()
53 # self.parent.ui.connectionList.setCurrentRow(0)
54 # QtCore.QObject.emit(
55 # self.parent.ui.connectionList, QtCore.SIGNAL('currentRowChanged(int)'), 0)
57 def select(self, row):
59 Select another connection as current.
61 self.currentConnection = self.connections[row]
63 # Fill in form based on selection.
64 self.parent.ui.connectionName.setText(self.currentConnection.name)
65 self.parent.ui.connectionLocalIpAddress.setText(
66 self.currentConnection.local_ip_address)
67 self.parent.ui.connectionLocalPort.setText(
68 unicode(self.currentConnection.local_port))
69 self.parent.ui.connectionFreeswitchIpAddress.setText(
70 self.currentConnection.freeswitch_ip_address)
71 self.parent.ui.connectionFreeswitchPort.setText(
72 unicode(self.currentConnection.freeswitch_port))
76 TODO: Clone an existing connection.
78 This creates a new connection with bound data copied from another one.
87 self.currentConnection = None
89 name_template = 'New connection [{0:02}]'
90 for i in xrange(1, 100):
91 name = name_template.format(i)
92 connection_exists = False
93 for connection in self.connections:
94 if connection.name == name:
95 connection_exists = True
98 if not connection_exists:
101 self.parent.ui.connectionName.setText('New connection')
102 self.parent.ui.connectionName.setFocus()
103 self.parent.ui.connectionName.selectAll()
104 self.parent.ui.connectionLocalIpAddress.clear()
105 self.parent.ui.connectionLocalPort.clear()
106 self.parent.ui.connectionFreeswitchIpAddress.clear()
107 self.parent.ui.connectionFreeswitchPort.clear()
111 Save new or existing connection.
113 name = unicode(self.parent.ui.connectionName.text())
115 # Add to connection list if we've created it.
116 if self.currentConnection is None:
117 #self.currentConnection = models.Connection(store=state.store)
118 self.connections.append(self.currentConnection)
119 self.parent.ui.connectionList.addItem(name)
121 self.currentConnection.name = name
122 self.currentConnection.local_ip_address = unicode(
123 self.parent.ui.connectionLocalIpAddress.text())
124 self.currentConnection.local_port = int(
125 self.parent.ui.connectionLocalPort.text())
126 self.currentConnection.freeswitch_ip_address = unicode(
127 self.parent.ui.connectionFreeswitchIpAddress.text())
128 self.currentConnection.freeswitch_port = int(
129 self.parent.ui.connectionFreeswitchPort.text())
131 self.currentConnection.checkpoint()