/***************************************************************************
 * main.cpp
 *
 * This file is part of KTabEdit, a KDE tabulature editor
 *
 * copyright (C) 2004-2006 the KTabEdit development team <mrgwen@gmail.com>
 * copyright (C) 2002-2004 the KGuitar development team <mrgwen@gmail.com>
 ***************************************************************************/

/***************************************************************************
 * 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.
 *
 * See the file COPYING for more information.
 ***************************************************************************/

#include "main.h"
#include "ktabedit.h"

#include <qdir.h>

#include <KAboutData>
#include <KApplication>
#include <KCmdLineArgs>
#include <KConfig>
#include <KDebug>
#include <KGlobalSettings>
#include <KLocale>
#include <KSplashScreen>
#include <KStandardDirs>
#include <ktip.h>

static const char* sDescription = "A stringed instrument tabulature editor (with MIDI support)";

int main(int argc, char **argv)
{
	KAboutData about(QByteArray("ktabedit"), QByteArray(0), ki18n("KTabEdit"), QByteArray(VERSION), ki18n(sDescription),
					 KAboutData::License_GPL, ki18n("(C) 2004-2007 by KTabEdit Development Team"), KLocalizedString(),
					 QByteArray("http://ktabedit.sourceforge.net"));
	
	about.addAuthor(ki18n("Gwenael Casaccio"), ki18n("Maintainer and main coder"), "mrgwen@gmail.com");
	about.addCredit(ki18n("KTabEdit team"), ki18n("http://ktabedit.sourceforge.net"));
	
	KCmdLineArgs::init(argc, argv, &about);

	KCmdLineOptions options;
	options.add("+[URL]", ki18n("Document to open."));
	KCmdLineArgs::addCmdLineOptions(options);
	
	
	KApplication app;
	KConfig* config;
	
	if (app.isSessionRestored())
		;//RESTORE(KTabEdit)
	else {
		KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
		bool logo;
		
		config = app.sessionConfig();
		
		KConfigGroup assistantGroup(config, "Assistant");
		logo = assistantGroup.readEntry("FirstTime", false);
		
		QPixmap picture(KStandardDirs::locate("data", "ktabedit/pics/startup.png"));
		KSplashScreen splash(picture);
		
		if (logo)
			splash.show();
		if (args->count() == 0) {
			KTabEdit* widget = new KTabEdit;
			
			app.setMainWidget(widget);
			
			widget->show();
			
			if (logo)
				splash.finish(widget);
		} else {
			for (int i = 0; i < args->count(); i++) {
				KTabEdit* widget = new KTabEdit;
				app.setMainWidget(widget);
				
				//widget->show();
				//widget->load(args->url(i));
				
				//if (logo)
				//	splash.finish(widget);
			}
		}
		args->clear();
	}
	KTipDialog::showTip();
	return app.exec();
}
