/***************************************************************************
 *   Copyright (C) 2004 by ImoLUG Staff                                    *
 *   developers@imolug.org                                                 *
 *                                                                         *
 *   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 "qtswaret.h"
#include <stdlib.h>
#include <unistd.h>
#include <kapplication.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <klocale.h>
#include <qmessagebox.h>
#include <qfile.h>

static const char description[] =
    I18N_NOOP("A Swaret GUI. http://qtswaret.sf.net");

static const char version[] = "0.1.5";

static KCmdLineOptions options[] =
{
    KCmdLineLastOption
};

int main(int argc, char **argv)
{
    KAboutData about("qtswaret", I18N_NOOP("QtSwaret"), version, description,
    KAboutData::License_GPL, "(C) 2004 ImoLUG Staff", 0, 0, "qtswaret@altervista.org");
    about.addAuthor( "ImoLUG Staff", 0, "qtswaret@altervista.org" );
    KCmdLineArgs::init(argc, argv, &about);
    KCmdLineArgs::addCmdLineOptions( options );
    KApplication app;
    
    // Creo l'istanza alla finestra principale
    QtSwaret *mainWin = new QtSwaret();
    QFile file( "/usr/sbin/swaret" );
    QFile file_spi( "/usr/bin/spi" );
    // Setto la finestra princiapale dell'applicativo
    app.setMainWidget( mainWin );
    
    // Controllo di avere i permessi per eseguire QtSwaret
    if( getuid() )
    {
	QMessageBox::critical( 0, "QtSwaret - Error", 
	    "Swaret must have ROOT permissions!\nLaunch:\n\n $ kdesu qtswaret.\n", QMessageBox::Ok, QMessageBox::NoButton );
    	exit( -1 );
	}
	
	
     //Controllo se Swaret e' installato
    if(! file.exists() )
  {
    QMessageBox::critical( 0, "QtSwaret - Error", 
	    "Swaret must be installed!", QMessageBox::Ok, QMessageBox::NoButton );
	exit( -1 );
    }
    if(! file_spi.exists() )
    {
        QMessageBox::critical( 0, "QtSwaret - Error", 
	    "For advanced filename research, SPI must be installed!\n\n Download it from http://spi.slackit.org\n\n Without SPI, some features are disabled.", QMessageBox::Ok, QMessageBox::NoButton );
	
    }
    // Se tutto va bene lancio l'applicazione
    mainWin->show();
            
    // Eseguo l'applicativo
    return app.exec();
}

