//
// ================================================================
//
//#include <qapplication.h>
#include <kapp.h>

#include "PikMain.h"

#include <kaboutdata.h>
#include <klocale.h>
#include <kcmdlineargs.h>
#include <kstandarddirs.h>
#include <kmessagebox.h>

// splashscreen class not available before Qt 3.2.0


// because splashscreen freeze some computers for obscure reason
// I prefer to de-activate it - just set SPLASH to 1 for reactivation
#define SPLASH 0

#if QT_VERSION >= 0x030200  &&  SPLASH
  #include <ksplashscreen.h>
  #include <qpixmap.h>
#endif

#include "../config.h" 

int main( int argc, char *argv[] )
{
    static KCmdLineOptions options[] =
        {
	    { "+[file]", I18N_NOOP("Optional filename to open upon startup."), 0},
            { 0, 0, 0}
        };

    KAboutData aboutData ("pikdev", I18N_NOOP("PiKdev"), VERSION ,
                          I18N_NOOP( "PiKdev - A simple IDE for software development of PIC-based applications." ),
                          KAboutData::License_GPL,
                          I18N_NOOP( "(c) 2002-2008 Alain Gibaud" ), 0, "http://pikdev.free.fr");

                         
    aboutData.addAuthor("Alain Gibaud", I18N_NOOP("Author"), "alain.gibaud@free.fr",0);
    aboutData.addCredit("Brian C. Lane", I18N_NOOP("His code for programming PICs helped me during my first developments."), 0,0);
    aboutData.addCredit("Christoph Cullmann and all The Kate Project team", I18N_NOOP("Fantastic text editing engine."), "cullmann@kde.org" ,
                        "http://kate.kde.org");
    aboutData.addCredit("Craig Franklin", I18N_NOOP("gputils tools"), "craigfranklin@attbi.com" ,
                        "http://gputils.sourceforge.net");
    aboutData.addCredit("Scott Dattalo", I18N_NOOP("gputils tools"), "scott@dattalo.com" ,
                        "http://gputils.sourceforge.net");
    aboutData.addCredit("Manwlis \"Manos\" Giannos", I18N_NOOP("Pic18F programming code"), "mgiannos2000@yahoo.gr" );
    aboutData.addCredit("Gerardo", I18N_NOOP("Parsing command line arguments"), "gpuga@gioia.ing.unlp.edu.ar" );
    aboutData.addCredit("Sean A. Walberg", I18N_NOOP("16F676/630 support"), "sean@ertw.com" );
    aboutData.addCredit("Mirko Panciri", I18N_NOOP("Support for programmers with bidirectionnal buffers"), "mirko.panciri@adept.it" );
    aboutData.addCredit("Keith Baker", I18N_NOOP("Support for 16F73/74/76/77"), "susyzygy@pubnix.org" );
    aboutData.addCredit("Javier Fernando Vargas G", I18N_NOOP("Help for program internationalization, Spanish translation"), "fernandovargas@cable.net.co" );
    aboutData.addCredit("Andre Lohan", I18N_NOOP("German translation"), "payne@aldervista.de" );
    aboutData.addCredit("Jochen Graeber", I18N_NOOP("Device donation"), "" );
    aboutData.addCredit("Holger Olhm", I18N_NOOP("Device donation"), "" );
    aboutData.addCredit("Brian Sipos", I18N_NOOP("Linker file support in project mode"), "" );
    aboutData.addCredit("Jean-Claude Vandenhekke", I18N_NOOP("Support for 18F6525/8525/6621/8621"), "jc.vdhekke@free.fr" );
    aboutData.addCredit("Jeff Post", I18N_NOOP("Collaboration for pk2 support"), "j_post@pacbell.net" );
    aboutData.addCredit("Walter Kicinski", I18N_NOOP("Collaboration for pk2cmd support - Thanks !"), "http://forum.microchip.com/tt.aspx?forumid=182" );

    aboutData.addCredit("The KDE developers", I18N_NOOP("Great environment"), "" , "http://www.kde.org");
    aboutData.addCredit("The Trolls", I18N_NOOP("*The* Qt library"), "" , "http://www.trolltech.com");
                       
    // Command line arguments; PikMain will check those later
    KCmdLineArgs::init( argc, argv, &aboutData );
    KCmdLineArgs::addCmdLineOptions( options );
    KApplication::addCmdLineOptions();

    // the KApplication a( argc, argv , "pikdev");  constructor must NOT be used if
    // KAboutData is used
    KApplication a ;
    
#if QT_VERSION >= 0x030200 && SPLASH
    QString splashimg_name =  locate("data", "pikdev/pics/splash.png") ;
    QPixmap spimg(splashimg_name) ;
    KSplashScreen *sp = 0 ;

    if( spimg.isNull() )
    {
        KMessageBox::detailedSorry( 0,  i18n("Installation path seems to be incorrect"),
        i18n(
                       "Ressource files not found:\n"
                       "This might be caused by incorrect RPMs, but "
                       "more probably by an incorrect installation from tarball.\n" 
                       "Please visit the installation page "
                       "(http://pikdev.free.fr) for details.\n"
                       "You will now probably get an empty user interface.\n"
        )) ;
      
    }
    else
    {
      sp = new KSplashScreen(spimg, 0 /*, Qt::WStyle_StaysOnTop*/ ) ;
      sp->setFixedSize(spimg.size());
      sp->show();
      sp->message( i18n("Restoring session ..."), Qt::AlignRight, QColor(0,0,0) );
    }     
#endif


    PikMain *wid = new  PikMain;
    // wid->resize( 900, 660 );    // no more needed because auto save is now enabled
    // a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit() ) );
    // YAKM (Yet Another KDE Mystery)
    // il semblerait que l'attachement du MainWidget soit implicite ...
    a.setMainWidget( wid );   // necessaire en Qt, pas indispensable en KDE
    wid->show();

#if QT_VERSION >= 0x030200  && SPLASH
    if( sp )
    {
      sp->clear();
      sp->message( i18n("Done.") , Qt::AlignRight, QColor(0,0,0));
      sp->finish(wid);
      delete sp ;
    }
#endif
    
    return a.exec();
}
