From db5ff277e0e5f4d3c2837fc8b50718915f8fc5a6 Mon Sep 17 00:00:00 2001 From: Stas Shtin Date: Thu, 8 Apr 2010 18:44:00 +0400 Subject: [PATCH] Connection adding implemented --- src/ipypbx/controllers.py | 57 +++++++++++++++++++++++++++++++++++---------- src/ipypbx/main.py | 5 ---- src/ipypbx/state.py | 3 --- src/ipypbx/ui.py | 9 ++++--- ui/layout.ui | 12 ++++------ 5 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/ipypbx/controllers.py b/src/ipypbx/controllers.py index f4cbd26..b233cfc 100644 --- a/src/ipypbx/controllers.py +++ b/src/ipypbx/controllers.py @@ -1,3 +1,20 @@ +# Copyright (c) Stas Shtin, 2010 + +# This file is part of IPyPBX. + +# IPyPBX is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# IPyPBX is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with IPyPBX. If not, see . + from ipypbx import models, state @@ -12,17 +29,25 @@ class BaseHandler(object): def __init__(self, parent): self.parent = parent + self.initState() + + def initState(self): + return NotImplemented class ConnectionsHandler(BaseHandler): """ Connections handler. """ + def initState(self): + self.connections = list(state.store.query(models.Connection)) + self.currentConnection = None + def select(self, index): """ Select another connection as current. """ - state.currentConnection = state.connections[index] + self.currentConnection = state.connections[index] def clone(self): """ @@ -33,9 +58,9 @@ class ConnectionsHandler(BaseHandler): def add(self): """ - Add a new connection. + Add new connection. """ - state.currentConnection = None + self.currentConnection = None self.parent.ui.connectionName.setText('') self.parent.ui.connectionLocalIpAddress.setText('') self.parent.ui.connectionLocalPort.setText('') @@ -43,13 +68,21 @@ class ConnectionsHandler(BaseHandler): self.parent.ui.connectionFreeswitchPort.setText('') def save(self): + """ + Save new or existing connection. + """ + name = unicode(self.parent.ui.connectionName.text()) connection = models.Connection( - name=self.parent.ui.connectionName.getText(), - local_ip_address=self.parent.ui.connectionLocalIpAddress.\ - getText(), - local_port=self.parent.ui.connectionLocalPort.getText(), - freeswitch_ip_address=self.parent.ui.\ - connectionFreeswitchIpAddress.getText(), - freeswitch_port=self.parent.ui.connectionFreeswitchPort.getText() - ) - #state.currentConnection = + name=name, + local_ip_address=unicode( + self.parent.ui.connectionLocalIpAddress.text()), + local_port=int( + self.parent.ui.connectionLocalPort.text()), + freeswitch_ip_address=unicode( + self.parent.ui.connectionFreeswitchIpAddress.text()), + freeswitch_port=int( + self.parent.ui.connectionFreeswitchPort.text())) + if not self.currentConnection: + self.connections.append(connection) + self.currentConnection = connection + self.parent.ui.connectionList.addItem(name) diff --git a/src/ipypbx/main.py b/src/ipypbx/main.py index c38d394..197e921 100644 --- a/src/ipypbx/main.py +++ b/src/ipypbx/main.py @@ -26,16 +26,11 @@ class MainWindow(QtGui.QMainWindow): """ def __init__(self): QtGui.QMainWindow.__init__(self) - locale = QtCore.QLocale.system().name() - print "Locale is", locale - translator = QtCore.QTranslator() if translator.load("ipypbx_%s" % locale.toLower(), "ipypbx/locale"): app.installTranslator(translator) - else: - print "Translation not found" self.ui = ui.Ui_MainWindow() self.ui.setupUi(self) diff --git a/src/ipypbx/state.py b/src/ipypbx/state.py index 6ae8319..d60fe6e 100644 --- a/src/ipypbx/state.py +++ b/src/ipypbx/state.py @@ -31,12 +31,9 @@ if not os.path.exists(PREFIX): store = Store(os.path.join(PREFIX, 'ipypbx.db')) # Program state data. -connections = list(store.query(models.Connection)) sipProfiles = [] domains = [] gateways = [] endpoints = [] extensions = [] - -currentConnection = None diff --git a/src/ipypbx/ui.py b/src/ipypbx/ui.py index e3dd085..7e7f80c 100644 --- a/src/ipypbx/ui.py +++ b/src/ipypbx/ui.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file '../ui/layout.ui' # -# Created: Wed Apr 7 23:01:27 2010 +# Created: Thu Apr 8 18:41:19 2010 # by: PyQt4 UI code generator 4.7.2 # # WARNING! All changes made in this file will be lost! @@ -26,9 +26,6 @@ class Ui_MainWindow(object): self.layoutWidget.setObjectName("layoutWidget") self.gridLayout = QtGui.QGridLayout(self.layoutWidget) self.gridLayout.setObjectName("gridLayout") - self.connectionList = QtGui.QListView(self.layoutWidget) - self.connectionList.setObjectName("connectionList") - self.gridLayout.addWidget(self.connectionList, 0, 0, 1, 1) self.formLayout_7 = QtGui.QFormLayout() self.formLayout_7.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow) self.formLayout_7.setObjectName("formLayout_7") @@ -47,7 +44,6 @@ class Ui_MainWindow(object): self.label_11.setObjectName("label_11") self.formLayout_7.setWidget(2, QtGui.QFormLayout.LabelRole, self.label_11) self.connectionLocalPort = QtGui.QLineEdit(self.layoutWidget) - self.connectionLocalPort.setInputMethodHints(QtCore.Qt.ImhDigitsOnly) self.connectionLocalPort.setObjectName("connectionLocalPort") self.formLayout_7.setWidget(2, QtGui.QFormLayout.FieldRole, self.connectionLocalPort) self.label_13 = QtGui.QLabel(self.layoutWidget) @@ -72,6 +68,9 @@ class Ui_MainWindow(object): self.connectionSave = QtGui.QPushButton(self.layoutWidget) self.connectionSave.setObjectName("connectionSave") self.gridLayout.addWidget(self.connectionSave, 1, 1, 1, 1) + self.connectionList = QtGui.QListWidget(self.layoutWidget) + self.connectionList.setObjectName("connectionList") + self.gridLayout.addWidget(self.connectionList, 0, 0, 1, 1) self.tabWidget.addTab(self.connectionsTab, "") self.sipProfilesTab = QtGui.QWidget() self.sipProfilesTab.setMaximumSize(QtCore.QSize(796, 16777215)) diff --git a/ui/layout.ui b/ui/layout.ui index e43edb2..537cfa8 100644 --- a/ui/layout.ui +++ b/ui/layout.ui @@ -46,9 +46,6 @@ - - - @@ -83,11 +80,7 @@ - - - Qt::ImhDigitsOnly - - + @@ -132,6 +125,9 @@ + + + -- 1.7.9.5