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/>.
20 from ipypbx import controllers, ui
21 from PyQt4 import QtCore, QtGui, QtSql
24 # Working directory path.
25 PREFIX = os.path.expanduser('~/.ipypbx')
31 def setupDb(prefix=PREFIX, dbname=DB_NAME):
36 # Create it if necessary.
38 if not os.path.exists(prefix):
40 os.mkdir(prefix, 0700)
44 # Connect to SQLite database.
45 db = QtSql.QSqlDatabase.addDatabase("QSQLITE")
46 db.setDatabaseName(dbname)
50 # Load script from local file.
51 sql_script = open(os.path.join(os.path.dirname(__file__), 'create.sql')).read()
53 # Split into individual queries.
54 sql_queries = sql_script.split(';')
56 # Execute all queries except last that is empty.
57 query = QtSql.QSqlQuery()
58 for query_string in sql_queries[:-1]:
59 query.exec_(query_string)
61 # Something went horribly wrong.
62 QtGui.QMessageBox.warning(
63 None, "Fatal Error", "Database Error: %s" % db.lastError().text())
67 if __name__ == '__main__':
68 app = QtGui.QApplication(sys.argv)
70 locale = QtCore.QLocale.system().name()
71 translator = QtCore.QTranslator()
73 if translator.load("ipypbx_%s" % locale.toLower(), "ipypbx/locale"):
74 QtGui.QApplication.installTranslator(translator)
77 main = QtGui.QMainWindow()
78 views = ui.Ui_MainWindow()
83 for basename in ('Connection', 'SipProfile', 'Domain', 'Gateway',
84 'Endpoint', 'Extension'):
85 main.controllers.append(getattr(
86 controllers, basename + 'Controller'
87 )(parent=main, views=views))
89 connection_model = main.controllers[0].model
90 connection_index = connection_model.index(0, 0)
91 first_row_id, ok = connection_model.data(
92 connection_index.sibling(0, 0)).toInt()
96 main.controllers[0].view_list.selectionModel(),
97 QtCore.SIGNAL('currentRowChanged(QModelIndex, QModelIndex)'),
98 connection_index, connection_index)
102 sys.exit(app.exec_())