###############################################################################
# iiMonitor
# Copyright (C) 2008 Lucas Murray
# http://www.undefinedfire.com
#
# This program 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.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
###############################################################################

import sys, socket
from PyQt4 import QtCore, QtGui

from account import Account
from mainwindow import MainWindow
from loginwindow import LoginWindow

if __name__ == '__main__':
    try:
        # Prevent hanging for remote connections
        socket.setdefaulttimeout(10)

        app = QtGui.QApplication(sys.argv)
        app.connect(app, QtCore.SIGNAL('lastWindowClosed()'), app, QtCore.SLOT('quit()'))

        account = Account()

        mainWindow = MainWindow(app, QtCore.QSettings('iiMonitor', 'Undefined Fire'), account)
        mainWindow.setWindowIcon(QtGui.QIcon('rc/tray-yr.png'))
        mainWindow.show()

        loginWindow = LoginWindow(app, mainWindow.settings, account, mainWindow)
        mainWindow.setLoginWindow(loginWindow)
        loginWindow.setWindowIcon(QtGui.QIcon('rc/tray-yr.png'))
        loginWindow.login()
    except:
        print 'Something went wrong'
        sys.exit(1)

    sys.exit(app.exec_())
