/***************************************************************************
 *   Copyright (C) 2003-2005 by liuspider                                  *
 *   liuspider@users.sourceforge.net                                       *
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/
#include "src/skimpluginmanager.h"
#include "src/skimglobalactions.h"
#include "configmainwindow.h"

// #include "plugins/setupwindow/scimsetupwindow.h"
// #include <klocale.h>
#include <kedittoolbar.h>
#include <kconfigdialogmanager.h>
#include <qlayout.h>

//FIXME
#include <qcheckbox.h>
#include <qspinbox.h>

ConfigMainWindow::ConfigMainWindow(QWidget *parent, const char */*name*/)
 : MainWindow_Settings(parent), _changed(false)
{
    editToolbar = new KEditToolbarWidget("MainToolBar",
     SkimPluginManager::self()->getActionCollection(),"mainwindowui.rc",false,this);
    layout()->add(editToolbar);
    connect(editToolbar,SIGNAL(enableOk(bool)),SLOT(checkChanged(bool)));
    //FIXME:
    kcfg_Hide_Timeout->hide();
    kcfg_Always_Show->hide();
}
void ConfigMainWindow::saveSettings()
{
    if(!_changed)
      return;
    _changed = false;
    if(!editToolbar->save())
      std::cerr <<"Can no save settings for toolbar " << editToolbar->name() << "\n";
}
void ConfigMainWindow::checkChanged(bool e)
{
    _changed = e;
    emit changed(e);
}
bool ConfigMainWindow::hasChanged()
{
    return _changed;
}
ConfigMainWindow::~ConfigMainWindow()
{
//     _configmainwindow_widget = 0;
}

#include <kgenericfactory.h>

typedef KGenericFactory<KCMLoader_MW> KCMLoaderMWFactory;

K_EXPORT_COMPONENT_FACTORY( kcm_skimplugin_mainwindow, KCMLoaderMWFactory( "kcm_skimplugin_mainwindow" ) )

KCMLoader_MW::KCMLoader_MW( QWidget *parent, const char * /* name */, const QStringList &args )
 : KAutoCModule( KCMLoaderMWFactory::instance(), parent, args )
{
  d = new ConfigMainWindow(this);
  connect(d, SIGNAL(changed(bool )), SLOT(slotWidgetModified()));
  setMainWidget(d);
}

void KCMLoader_MW::save(){  d->saveSettings(); KAutoCModule::save();}

void KCMLoader_MW::slotWidgetModified()
{
    emit changed(d->hasChanged() || configDialgoMgr()->hasChanged());
}

// void KCMLoader_MW::load() { d->load(); KAutoCModule::load();}

KCMLoader_MW::~KCMLoader_MW()
{
}

#include "configmainwindow.moc"
