/***************************************************************************
 *   Copyright (C) 2004 by Dieter Landolt                                  *
 *   dieter.landolt@secs.ch                                                *
 *                                                                         *
 *   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 2 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, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <kapplication.h>
#include <kuniqueapp.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <klocale.h>
#include <dcopclient.h>
#include "kkeyled.h"

static const char description[] =
    I18N_NOOP("A KDE Application for watching and contoling the keyboard led");

static const char version[] = "0.8.11";

static KCmdLineOptions options[] =
{
//   { "mi", I18N_NOOP( "Allow multi Instabze." ), 0 },
    KCmdLineLastOption
};

/**
 * 
 * @param argc 
 * @param argv 
 * @return 
 */
int main(int argc, char **argv)
{
    KAboutData about("kkeyled", I18N_NOOP("kkeyled"), version, description,
                     KAboutData::License_GPL, "(C) 2001-2005 Dieter Landolt", 0, "http://www.truesoft.ch/dieter/kkeyled.html", "dieter.landolt@secs.ch");
    about.addAuthor("Dieter Landolt", 0, "dieter.landolt@secs.ch" );
    about.addCredit("Alexey Kouznetsov",I18N_NOOP("Russian translation"),"AlexeyKouznetsov@Rambler.ru");

    KCmdLineArgs::init(argc, argv, &about);
    KCmdLineArgs::addCmdLineOptions( options );

    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    KUniqueApplication::addCmdLineOptions();

    Kkeyled *mainWin = 0;

    if (! KUniqueApplication::start())
    {
	qDebug("Try Restore kkeyled");
	DCOPClient *meclient = new DCOPClient();; //  = kapp->dcopClient();;
        if ( meclient->attach() ) {
		qDebug("Send");
		meclient->send("kkeyled","qt/kkeyLed","show()","");
		
	} else {
		qDebug("Attach dcop failed!");
	}
    }
    else
    {
#ifdef debug
//#line __LINE__ __FILE__
    	KApplication app;
#else
//#line __LINE__ __FILE__
    	KUniqueApplication app;
#endif
        /// @todo do something with the command line args here

        mainWin = new Kkeyled(0,"kkeyLed"); // ,Qt::WStyle_Customize | Qt::WStyle_StaysOnTop | Qt::WStyle_NoBorder | Qt::WX11BypassWM);
        args->clear();
    	return app.exec();
   }

    // mainWin has WDestructiveClose flag by default, so it will delete itself.
}

