# You should have received a copy of the GNU General Public License
# along with IPyPBX. If not, see <http://www.gnu.org/licenses/>.
-#from ipypbx import models
from PyQt4 import QtCore, QtGui, QtSql
Doesn't do anything useful on its own.
"""
+ # TODO: possibly use a separate class for options and a meta-class.
fields = ()
view_list_fields = ()
view_display_fields = ()
+ view_display_fields_hidden = 'ID', 'Connection ID'
+ is_bound_to_connection = True
def __init__(self, model=None, view_list=None, view_display=None, parent=None, views=None):
super(BaseController, self).__init__(parent=parent)
# Otherwise initialize a new model.
else:
self.model = QtSql.QSqlTableModel(parent)
- self.model.setTable('ipypbxweb_%s' % self.basename)
+ self.model.setTable('ipypbxweb_%s' % self.basename.lower())
# Create model header from fields list.
for i, field in enumerate(self.fields):
self.model.setHeaderData(
- i, QtCore.Qt.Horizontal, QtCore.QVariant(field))
+ i, QtCore.Qt.Horizontal,
+ QtCore.QVariant(QtGui.QApplication.translate(
+ "MainWindow", field, None,
+ QtGui.QApplication.UnicodeUTF8)))
# Fetch model data.
self.model.select()
self.view_list.resizeColumnsToContents()
self.view_list.resizeRowsToContents()
self.view_list.horizontalHeader().setStretchLastSection(True)
+
+ # Select first row.
self.view_list.selectRow(0)
# Are we given an existing view display?
# If view_display_fields is not send, display all fields except
# the first one that is usually the ID.
- display_fields = self.getDisplayFields()
+ display_fields = [
+ field for field in self.fields if not field in
+ self.view_display_fields_hidden]
+
for i, field in enumerate(self.fields):
if field in display_fields:
field_widget = self.getFieldWidget(field)
QtCore.QObject.connect(
sender, QtCore.SIGNAL(signal), receiver, QtCore.SLOT(slot))
-
- def getDisplayFields(self):
- """
- Return the list of fields to display.
-
- If it's not set explicitly, use all defined fields except the first
- which usually is the primary key.
- """
- return self.view_display_fields or self.fields[1:]
-
def getFieldWidget(self, field):
"""
Return widget for given field name.
"""
Default signals built from controller's base name.
"""
+ # Default signals handle row selection, Add and Save buttons.
return (
(getattr(self.views, self.basename + 'Add'), 'clicked()', self.add),
(self.view_list.selectionModel(),
# Clear all displayed fields.
for field in self.getDisplayFields():
- self.getFieldWidget(field).clear()
+ if hasattr(field, 'clear'):
+ self.getFieldWidget(field).clear()
def save(self):
"""
- Save currently selected object.
+ Save to database.
"""
- #print self.model.isDirty(self.view_list.currentRow())
- #print self.view_list.selectedIndexes()[0].row()
-
- #if self.model.isDirty(self.view_display.currentIndex()), self.model.rowCount()
+ # For now we just submit everything - QT seems to be able to handle it
+ # on its own.
self.view_display.submit()
self.getFieldWidget('Add').setEnabled(True)
-
+
+ def update(self):
+ pass
class ConnectionController(BaseController):
"""
- Connections handler.
+ Connections controller.
"""
fields = (
- 'ID', 'Name', 'Local IP Address', 'Local Port',
- 'Freeswitch IP Address', 'Freeswitch Port')
- view_list_fields = ('Name', 'Freeswitch IP Address', 'Freeswitch Port')
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Name'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Local IP Address'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Local Port'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Freeswitch IP Address'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Freeswitch Port'))
+ view_list_fields = 'Name', 'Freeswitch IP Address', 'Freeswitch Port'
def clone(self):
"""
This creates a new connection with bound data copied from another one.
"""
- def _save(self):
- """
- Save new or existing connection.
- """
- name = unicode(self.parent.ui.connectionName.text())
-
- # Add to connection list if we've created it.
- if self.currentConnection is None:
- #self.currentConnection = models.Connection(store=state.store)
- self.connections.append(self.currentConnection)
- self.parent.ui.connectionList.addItem(name)
-
- self.currentConnection.name = name
- self.currentConnection.local_ip_address = unicode(
- self.parent.ui.connectionLocalIpAddress.text())
- self.currentConnection.local_port = int(
- self.parent.ui.connectionLocalPort.text())
- self.currentConnection.freeswitch_ip_address = unicode(
- self.parent.ui.connectionFreeswitchIpAddress.text())
- self.currentConnection.freeswitch_port = int(
- self.parent.ui.connectionFreeswitchPort.text())
-
- self.currentConnection.checkpoint()
+
+class SipProfileController(BaseController):
+ """
+ SIP Profile controller.
+ """
+ fields = (
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Connection ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Name'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'External RTP IP'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'External SIP IP'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'RTP IP'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'SIP IP'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'SIP Port'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Accept Blind Registration'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Authenticate Calls'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Is Active'))
+ view_list_fields = 'Name', 'SIP IP', 'SIP Port'
+
+
+class DomainController(BaseController):
+ """
+ Domain controller.
+ """
+ fields = (
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Connection ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'SIP Profile ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Host Name'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Is Active'))
+ view_list_fields = 'SIP Profile ID', 'Host Name', 'Is Active'
+
+
+class GatewayController(BaseController):
+ """
+ Gateway controller.
+ """
+ fields = (
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Connection ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'SIP Profile ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Name'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Username'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Password'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Realm'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'From Domain'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Expire In Seconds'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Retry In Seconds'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Caller ID In From Field'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Is Active'))
+ view_list_fields = 'SIP Profile ID', 'Name'
+
+
+class EndpointController(BaseController):
+ """
+ Endpoint controller.
+ """
+ fields = (
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Connection ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'User ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Password'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Domain ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Is Active'))
+ view_list_fields = 'User ID', 'Password', 'Domain ID'
+
+
+class ExtensionController(BaseController):
+ """
+ Extension controller.
+ """
+ fields = (
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Connection ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Destination Match'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'XML Dialplan'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Domain ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Endpoint ID'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Authenticate Calls'),
+ QtCore.QT_TRANSLATE_NOOP('MainWindow', 'Is Active'))
+ view_list_fields = 'Destination Match', 'Domain ID', 'Endpoint ID'
+