Halfway rewriting to use QT MVC
[ipypbx] / src / ipypbx / ui.py
index e1c854f..c13d6f5 100644 (file)
@@ -1,24 +1,42 @@
-# -*- coding: utf-8 -*-
+# Copyright (c) Stas Shtin, 2010
 
-# Form implementation generated from reading ui file '../ui/layout.ui'
-#
-# Created: Thu Apr  8 20:06:26 2010
-#      by: PyQt4 UI code generator 4.7.2
-#
-# WARNING! All changes made in this file will be lost!
+# This file is part of IPyPBX.
 
-from PyQt4 import QtCore, QtGui
+# 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.
 
-class Ui_MainWindow(object):
-    def setupUi(self, MainWindow):
-        MainWindow.setObjectName("MainWindow")
-        MainWindow.resize(800, 400)
-        self.centralwidget = QtGui.QWidget(MainWindow)
+# 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 <http://www.gnu.org/licenses/>.
+
+from PyQt4 import QtCore, QtGui, QtSql
+
+class MainWindow(QtGui.QMainWindow):
+    """
+    Main GUI window.
+    """
+    def __init__(self, parent=None):
+        super(MainWindow, self).__init__(parent)
+
+        # Tweak layout.
+        self.setObjectName("MainWindow")
+        self.resize(800, 400)
+        self.centralwidget = QtGui.QWidget(self)
         self.centralwidget.setObjectName("centralwidget")
+
+        # Add tab widget
         self.tabWidget = QtGui.QTabWidget(self.centralwidget)
         self.tabWidget.setGeometry(QtCore.QRect(-2, -1, 811, 491))
         self.tabWidget.setMinimumSize(QtCore.QSize(800, 480))
         self.tabWidget.setObjectName("tabWidget")
+
+        # Connections tab definition.
         self.connectionsTab = QtGui.QWidget()
         self.connectionsTab.setObjectName("connectionsTab")
         self.layoutWidget = QtGui.QWidget(self.connectionsTab)
@@ -26,51 +44,52 @@ class Ui_MainWindow(object):
         self.layoutWidget.setObjectName("layoutWidget")
         self.gridLayout = QtGui.QGridLayout(self.layoutWidget)
         self.gridLayout.setObjectName("gridLayout")
-        self.formLayout_7 = QtGui.QFormLayout()
-        self.formLayout_7.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow)
-        self.formLayout_7.setObjectName("formLayout_7")
-        self.label_5 = QtGui.QLabel(self.layoutWidget)
-        self.label_5.setObjectName("label_5")
-        self.formLayout_7.setWidget(0, QtGui.QFormLayout.LabelRole, self.label_5)
-        self.connectionName = QtGui.QLineEdit(self.layoutWidget)
-        self.connectionName.setMaxLength(100)
-        self.connectionName.setObjectName("connectionName")
-        self.formLayout_7.setWidget(0, QtGui.QFormLayout.FieldRole, self.connectionName)
-        self.connectionLocalIpAddress = QtGui.QLineEdit(self.layoutWidget)
-        self.connectionLocalIpAddress.setInputMethodHints(QtCore.Qt.ImhNone)
-        self.connectionLocalIpAddress.setObjectName("connectionLocalIpAddress")
-        self.formLayout_7.setWidget(1, QtGui.QFormLayout.FieldRole, self.connectionLocalIpAddress)
-        self.label_11 = QtGui.QLabel(self.layoutWidget)
-        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.setObjectName("connectionLocalPort")
-        self.formLayout_7.setWidget(2, QtGui.QFormLayout.FieldRole, self.connectionLocalPort)
-        self.label_13 = QtGui.QLabel(self.layoutWidget)
-        self.label_13.setObjectName("label_13")
-        self.formLayout_7.setWidget(4, QtGui.QFormLayout.LabelRole, self.label_13)
-        self.connectionFreeswitchPort = QtGui.QLineEdit(self.layoutWidget)
-        self.connectionFreeswitchPort.setObjectName("connectionFreeswitchPort")
-        self.formLayout_7.setWidget(4, QtGui.QFormLayout.FieldRole, self.connectionFreeswitchPort)
-        self.label_12 = QtGui.QLabel(self.layoutWidget)
-        self.label_12.setObjectName("label_12")
-        self.formLayout_7.setWidget(1, QtGui.QFormLayout.LabelRole, self.label_12)
-        self.connectionFreeswitchIpAddress = QtGui.QLineEdit(self.layoutWidget)
-        self.connectionFreeswitchIpAddress.setObjectName("connectionFreeswitchIpAddress")
-        self.formLayout_7.setWidget(3, QtGui.QFormLayout.FieldRole, self.connectionFreeswitchIpAddress)
-        self.label_14 = QtGui.QLabel(self.layoutWidget)
-        self.label_14.setObjectName("label_14")
-        self.formLayout_7.setWidget(3, QtGui.QFormLayout.LabelRole, self.label_14)
-        self.gridLayout.addLayout(self.formLayout_7, 0, 1, 1, 1)
+        self.connectionData = QtGui.QDataWidgetMapper()
+        #self.formLayout_7 = QtGui.QFormLayout()
+        #self.formLayout_7.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow)
+        #self.formLayout_7.setObjectName("formLayout_7")
+        #self.label_5 = QtGui.QLabel(self.layoutWidget)
+        #self.label_5.setObjectName("label_5")
+        #self.formLayout_7.setWidget(0, QtGui.QFormLayout.LabelRole, self.label_5)
+        #self.connectionName = QtGui.QLineEdit(self.layoutWidget)
+        #self.connectionName.setMaxLength(100)
+        #self.connectionName.setObjectName("connectionName")
+        #self.formLayout_7.setWidget(0, QtGui.QFormLayout.FieldRole, self.connectionName)
+        #self.connectionLocalIpAddress = QtGui.QLineEdit(self.layoutWidget)
+        #self.connectionLocalIpAddress.setInputMethodHints(QtCore.Qt.ImhNone)
+        #self.connectionLocalIpAddress.setObjectName("connectionLocalIpAddress")
+        #self.formLayout_7.setWidget(1, QtGui.QFormLayout.FieldRole, self.connectionLocalIpAddress)
+        #self.label_11 = QtGui.QLabel(self.layoutWidget)
+        #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.setObjectName("connectionLocalPort")
+        #self.formLayout_7.setWidget(2, QtGui.QFormLayout.FieldRole, self.connectionLocalPort)
+        #self.label_13 = QtGui.QLabel(self.layoutWidget)
+        #self.label_13.setObjectName("label_13")
+        #self.formLayout_7.setWidget(4, QtGui.QFormLayout.LabelRole, self.label_13)
+        #self.connectionFreeswitchPort = QtGui.QLineEdit(self.layoutWidget)
+        #self.connectionFreeswitchPort.setObjectName("connectionFreeswitchPort")
+        #self.formLayout_7.setWidget(4, QtGui.QFormLayout.FieldRole, self.connectionFreeswitchPort)
+        #self.label_12 = QtGui.QLabel(self.layoutWidget)
+        #self.label_12.setObjectName("label_12")
+        #self.formLayout_7.setWidget(1, QtGui.QFormLayout.LabelRole, self.label_12)
+        #self.connectionFreeswitchIpAddress = QtGui.QLineEdit(self.layoutWidget)
+        #self.connectionFreeswitchIpAddress.setObjectName("connectionFreeswitchIpAddress")
+        #self.formLayout_7.setWidget(3, QtGui.QFormLayout.FieldRole, self.connectionFreeswitchIpAddress)
+        #self.label_14 = QtGui.QLabel(self.layoutWidget)
+        #self.label_14.setObjectName("label_14")
+        #self.formLayout_7.setWidget(3, QtGui.QFormLayout.LabelRole, self.label_14)
+        #self.gridLayout.addLayout(self.formLayout_7, 0, 1, 1, 1)
         self.connectionAdd = QtGui.QPushButton(self.layoutWidget)
         self.connectionAdd.setObjectName("connectionAdd")
         self.gridLayout.addWidget(self.connectionAdd, 1, 0, 1, 1)
         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.connectionView = QtGui.QTableView(self.layoutWidget)
+        self.connectionView.setObjectName("connectionView")
+        self.gridLayout.addWidget(self.connectionView, 0, 0, 1, 1)
         self.tabWidget.addTab(self.connectionsTab, "")
         self.sipProfilesTab = QtGui.QWidget()
         self.sipProfilesTab.setMaximumSize(QtCore.QSize(796, 16777215))
@@ -358,19 +377,27 @@ class Ui_MainWindow(object):
         self.formLayout_4.setWidget(3, QtGui.QFormLayout.FieldRole, self.extensionEndpoint)
         self.gridLayout_4.addLayout(self.formLayout_4, 0, 1, 1, 1)
         self.tabWidget.addTab(self.extensionsTab, "")
-        MainWindow.setCentralWidget(self.centralwidget)
+        self.setCentralWidget(self.centralwidget)
 
-        self.retranslateUi(MainWindow)
+        self.retranslateUi()
         self.tabWidget.setCurrentIndex(0)
-        QtCore.QMetaObject.connectSlotsByName(MainWindow)
+        QtCore.QMetaObject.connectSlotsByName(self)
+
+    def retranslateUi(self):
+        locale = QtCore.QLocale.system().name()
+        translator = QtCore.QTranslator()
+    
+        if translator.load("ipypbx_%s" % locale.toLower(), "ipypbx/locale"):
+            QtGui.QApplication.installTranslator(translator)
 
-    def retranslateUi(self, MainWindow):
-        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "IPyPBX", None, QtGui.QApplication.UnicodeUTF8))
-        self.label_5.setText(QtGui.QApplication.translate("MainWindow", "Name", None, QtGui.QApplication.UnicodeUTF8))
-        self.label_11.setText(QtGui.QApplication.translate("MainWindow", "Local Port", None, QtGui.QApplication.UnicodeUTF8))
-        self.label_13.setText(QtGui.QApplication.translate("MainWindow", "Freeswitch Port", None, QtGui.QApplication.UnicodeUTF8))
-        self.label_12.setText(QtGui.QApplication.translate("MainWindow", "Local IP address", None, QtGui.QApplication.UnicodeUTF8))
-        self.label_14.setText(QtGui.QApplication.translate("MainWindow", "Freeswitch IP Address", None, QtGui.QApplication.UnicodeUTF8))
+        self.setWindowTitle(
+            QtGui.QApplication.translate(
+                "MainWindow", "IPyPBX", None, QtGui.QApplication.UnicodeUTF8))
+        #self.label_5.setText(QtGui.QApplication.translate("MainWindow", "Name", None, QtGui.QApplication.UnicodeUTF8))
+        #self.label_11.setText(QtGui.QApplication.translate("MainWindow", "Local Port", None, QtGui.QApplication.UnicodeUTF8))
+        #self.label_13.setText(QtGui.QApplication.translate("MainWindow", "Freeswitch Port", None, QtGui.QApplication.UnicodeUTF8))
+        #self.label_12.setText(QtGui.QApplication.translate("MainWindow", "Local IP address", None, QtGui.QApplication.UnicodeUTF8))
+        #self.label_14.setText(QtGui.QApplication.translate("MainWindow", "Freeswitch IP Address", None, QtGui.QApplication.UnicodeUTF8))
         self.connectionAdd.setText(QtGui.QApplication.translate("MainWindow", "Add", None, QtGui.QApplication.UnicodeUTF8))
         self.connectionSave.setText(QtGui.QApplication.translate("MainWindow", "Save", None, QtGui.QApplication.UnicodeUTF8))
         self.tabWidget.setTabText(self.tabWidget.indexOf(self.connectionsTab), QtGui.QApplication.translate("MainWindow", "Connections", None, QtGui.QApplication.UnicodeUTF8))