#!/usr/bin/python2
# This file is part of SSHconf.
#
#    SSHconf 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.
#
#    SSHconf 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 SSHconf.  If not, see <http://www.gnu.org/licenses/>.
#
# Author: Frank "ancho" Becker 
#
# Copyright 2010 Frank Becker <ancho@gmx.net>

from PyQt4.QtCore import QByteArray
from sshconf.gui.qt.controll.mediator import SshConfDialogManager
from sshconf.gui.qt.view.sshconfmain import SSHConfGuiQt
from sshconf.ssh.sshconfig import SSHConf
from sshconf.util.config import Settings
from PyKDE4.kdeui import KApplication, KIcon
from PyKDE4.kdecore import KAboutData, ki18n, KCmdLineArgs
import logging
import os




if __name__ == '__main__':
    import sys, traceback

    settings = Settings()

    LOGFILE= os.path.expanduser(settings.get_logfile())
    logging.basicConfig(filename=LOGFILE,level=logging.DEBUG)
    log = logging.getLogger( "SSHConfig" )
    
    try:
        appName     = QByteArray("SSHCOnf")
        catalog     = QByteArray("")
        programName = ki18n ("SSHConf")  
        version     = "1.0"
        description = ki18n ("SSHConf")
        license     = KAboutData.License_GPL
        copyright   = ki18n ("(c) 2011 Frank Becker") 
        text        = ki18n ("none") 
        homePage    = ""
        bugEmail    = "ancho@gmx.net"
 
        aboutData   = KAboutData (appName, catalog, programName, version, description, license, copyright, text, homePage, bugEmail)
 
 
        KCmdLineArgs.init (sys.argv, aboutData)
 
        app = KApplication ()
        app.setWindowIcon(KIcon("/usr/share/icons/hicolor/scalable/apps/openssh_trans.png"))
        app.setQuitOnLastWindowClosed(True)
        
        sshconf = SSHConf()
        gui = SSHConfGuiQt()
    
        hostmediator = SshConfDialogManager(sshconf, gui)
        
        log.info("Startet SSHConf GUI")
        sys.exit(app.exec_())
    except (KeyboardInterrupt), e:
        app.quit()
        log.error(str(e))
    except (Exception), e:
        log.error(str(e))
        for line in traceback.format_tb( sys.exc_info()[2] ):
            log.error( line )
        
    

