/***************************************************************************
 *   Copyright (C) 2005 by xavier helluy                                   *
 *   xavier.helluy@web.de                                                  *
 *                                                                         *
 *   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.,                                       *
 *   51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ***************************************************************************/

#include <kwin.h> 
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <klocale.h>
#include <kuniqueapplication.h>
#include <dcopobject.h>
#include <qbutton.h>
#include <kmainwindow.h>
#include <kdebug.h>

#include "maingui.h"
#include <qapplication.h>   // QApplication::exit()

static const char description[] =
    I18N_NOOP("A KDE Application");

static const char version[] = "0.1";

static KCmdLineOptions options[] =
{
    { "displayIOSlaveconfigOnly", I18N_NOOP("A long binary option, off by default"), 0 },
    KCmdLineLastOption
};

int main(int argc, char **argv)
{
    KAboutData about("kclucene-indexer-config", I18N_NOOP("Configure and build indexes"), version, description,
                     KAboutData::License_GPL, "(C) %{YEAR} xavier helluy", 0, 0, "xavier.helluy@web.de");
    about.addAuthor( "xavier helluy", 0, "xavier.helluy@web.de" );
    KCmdLineArgs::init(argc, argv, &about);
    KCmdLineArgs::addCmdLineOptions(options);
    KUniqueApplication::addCmdLineOptions();

    
    
    if (!KUniqueApplication::start()) 
    {
	    fprintf(stderr, "myAppName is already running!\n");

// 	    KWin::activateWindow (kapp->activeWindow ()->winId());
// 	    kdDebug() << "my id: " << kapp->activeWindow ();
	    QApplication::exit(0);
    }

    KUniqueApplication app;
    
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    
    //called from within kio-clucene: show the page with possible index selection
    if (args->isSet("displayIOSlaveconfigOnly"))
    {
	    MainGUI * manager = new MainGUI(IOSLAVE_ONLY);
	    app.setMainWidget(manager->m_dialog );
    }
    else
    {
	    MainGUI * manager = new MainGUI(ALL);
	    app.setMainWidget(manager->m_dialog );
    }
   
    return app.exec();
}

