/*
  'Acqua' kwin client

  Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.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; see the file COPYING.  If not, write to
  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.
*/


#include "AcquaConfig.h"
#include <klocale.h>
#include <qvbuttongroup.h>
#include <qlabel.h>

extern "C"
{
   QObject* allocate_config( KConfig* conf, QWidget* parent )
   {
      return(new AcquaConfig(conf, parent));
   }
}

AcquaConfig::AcquaConfig( KConfig* conf, QWidget* parent )
   : QObject( parent )
{
   gb0 = new QGroupBox( 1, Qt::Horizontal,
      i18n("General settings"), parent );

   QVButtonGroup *bg0 = new QVButtonGroup(gb0);
   bg0->setMargin(0);
   bg0->setInsideMargin(0);
   //bg->setLineWidth(0);
   bg0->setFrameShape(QFrame::NoFrame);
	// buttons on left side or right side?
   //forceAppleStyle=new QCheckBox(i18n("Force OS X Style"),bg0);
   
   noBorders=new QCheckBox(i18n("No borders (on the sides and on the bottom)"),bg0);

   connect((QButtonGroup*)bg0,SIGNAL(clicked(int)),SIGNAL(changed()));

   gb3= new QGroupBox(1,Qt::Horizontal,
      i18n("Titlebar Settings"), parent);
   QVButtonGroup *bg3 = new QVButtonGroup(gb3);
   bg3->setMargin(0);
   bg3->setInsideMargin(0);
   //bg->setLineWidth(0);
   bg3->setFrameShape(QFrame::NoFrame);
   bg3->setRadioButtonExclusive(true);

	// it should not be called buttonStyle but inactiveStyle or something like that
	// ...this is a relict but i'm too lazy to change it everywhere at the moment
	//
   rightXIAButtons=new QCheckBox(i18n("Colored (X - + ) buttons on the right side"),bg3);

   buttonStyle = new QCheckBox(i18n("Light 'inactive-style' ( inactive title bars are not darkened )"),bg3);

   showMiniIcon = new QCheckBox(i18n("Show application icon in title bar"),
         bg3);

   shadowedText = new QCheckBox(i18n("Text on titlebar is shadowed"),
         bg3);
   biggerFonts = new QCheckBox(i18n("Bigger fonts on title bar"),
         bg3);


   noRightButton = new QRadioButton(i18n("No right-side button"),bg3);
   rightButtonIsMenu = new QRadioButton(i18n("Right-side button is 'Menu'"),bg3);
   rightButtonIsHelp = new QRadioButton(i18n("Right-side button is 'Help'"),bg3);

   connect((QButtonGroup*)bg3,SIGNAL(clicked(int)),SIGNAL(changed()));

   gb = new QGroupBox( 1, Qt::Horizontal,
      i18n("Drop shadow settings"), parent );

   //QLabel* label = new QLabel(i18n("Drop shadows:"),gb);
   //QVGroupBox* gb2 = new QVGroupBox(gb);
   QVButtonGroup* bg = new QVButtonGroup(gb);
   bg->setMargin(0);
   bg->setInsideMargin(0);
   //bg->setLineWidth(0);
   bg->setFrameShape(QFrame::NoFrame);
   noShadows = new QRadioButton(i18n("No drop-shadow"),bg);
   winShadows = new QRadioButton(i18n("Windows style drop-shadow"),bg);
   macosxShadows = new QRadioButton(i18n("Mac OS X style drop-shadow"),bg);
   updateInterval = new KIntNumInput(bg);
   updateInterval->setLabel(i18n("Update interval"));
   updateInterval->setPrefix(i18n("Every "));
   updateInterval->setSuffix(i18n(" milliseconds"));
   updateInterval->setSpecialValueText(i18n("Never"));
   updateInterval->setRange(0,5000,250,true);
   allWindowsShadowed = new QCheckBox(i18n("Draw shadows behind all windows"),bg);

   connect((QButtonGroup*)bg,SIGNAL(clicked(int)),SIGNAL(changed()));
   connect(updateInterval,SIGNAL(valueChanged(int)),SIGNAL(changed()));
   connect(allWindowsShadowed,SIGNAL(valueChanged(int)),SIGNAL(changed()));

   gb2= new QGroupBox(1,Qt::Horizontal,
      i18n("Corners Settings"), parent);

   QVButtonGroup *bg2 = new QVButtonGroup(gb2);
   bg2->setMargin(0);
   bg2->setInsideMargin(0);
   //bg->setLineWidth(0);
   bg2->setFrameShape(QFrame::NoFrame);
   bg2->setRadioButtonExclusive(true);

   noneRounded = new QRadioButton(i18n("No rounded corners"),bg2);
   topRounded = new QRadioButton(i18n("Just top rounded corners"),bg2);
   bottomRounded = new QRadioButton(i18n("Just bottom rounded corners"),bg2);
   topBottomRounded = new QRadioButton(i18n("All four rounded corners"),bg2);
   
   connect((QButtonGroup*)bg2,SIGNAL(clicked(int)),SIGNAL(changed()));

   load(conf);

   gb0->show();
   gb->show();
   gb2->show();
   gb3->show();
}

AcquaConfig::~AcquaConfig()
{
   delete gb0;
   delete gb;
   delete gb2;
   delete gb3;
}

void AcquaConfig::load( KConfig* conf )
{
   /*switch(conf->readNumEntry("AcquaForceStyle",1))
   {
      case 0: forceAppleStyle->setChecked(false); break;
      case 1: forceAppleStyle->setChecked(true); break;
   }*/

   switch(conf->readNumEntry("AcquaRightXIAButtons",1))
   {
      case 0: rightXIAButtons->setChecked(false); break;
      case 1: rightXIAButtons->setChecked(true); break;
   }

   switch(conf->readNumEntry("ShadowType",1))
   {
      case 0: noShadows->setChecked(true); break;
      case 1: winShadows->setChecked(true); break;
      case 2: macosxShadows->setChecked(true); break;
   }
   updateInterval->setValue(conf->readNumEntry("ShadowUpdateInterval",0));
   allWindowsShadowed->setChecked(conf->readBoolEntry("AllWindowsShadowed",0));

   switch(conf->readNumEntry("CornersType",1))
   {
      case 0: noneRounded->setChecked(true); break;
      case 1: topRounded->setChecked(true); break;
      case 2: bottomRounded->setChecked(true); break;
      case 3: topBottomRounded->setChecked(true); break;
   }
   switch(conf->readNumEntry("AcquaNoBorders",1))
   {
      case 0: noBorders->setChecked(false); break;
      case 1: noBorders->setChecked(true); break;
   }
   switch(conf->readNumEntry("AcquaShowIcons",1))
   {
      case 0: showMiniIcon->setChecked(false); break;
      case 1: showMiniIcon->setChecked(true); break;
   }

   switch(conf->readNumEntry("AcquaShadowedTitlebarText",1))
   {
      case 0: shadowedText->setChecked(false); break;
      case 1: shadowedText->setChecked(true); break;
   }

   switch(conf->readNumEntry("AcquaBiggerFonts",1))
   {
      case 0: biggerFonts->setChecked(false); break;
      case 1: biggerFonts->setChecked(true); break;
   }

   switch(conf->readNumEntry("AcquaRightButtonIs",1))
   {
      case 0: noRightButton->setChecked(true); break;
      case 1: rightButtonIsMenu->setChecked(true); break;
      case 2: rightButtonIsHelp->setChecked(true); break;
   }
   switch(conf->readNumEntry("AcquaButtonStyle",1))
   {
      case 0: buttonStyle->setChecked(false); break;
      case 1: buttonStyle->setChecked(true); break;
   }


}

void AcquaConfig::save( KConfig* conf )
{
   //if (forceAppleStyle->isChecked()) conf->writeEntry("AcquaForceStyle",1);
   //if (!forceAppleStyle->isChecked()) conf->writeEntry("AcquaForceStyle",0);
   if (rightXIAButtons->isChecked()) conf->writeEntry("AcquaRightXIAButtons",1);
   if (!rightXIAButtons->isChecked()) conf->writeEntry("AcquaRightXIAButtons",0);
   if (noShadows->isChecked()) conf->writeEntry("ShadowType",0);
   if (winShadows->isChecked()) conf->writeEntry("ShadowType",1);
   if (macosxShadows->isChecked()) conf->writeEntry("ShadowType",2);
   conf->writeEntry("ShadowUpdateInterval",updateInterval->value());
   conf->writeEntry("AllWindowsShadowed",allWindowsShadowed->isChecked());
   if (noneRounded->isChecked()) conf->writeEntry("CornersType",0);
   if (topRounded->isChecked()) conf->writeEntry("CornersType",1);
   if (bottomRounded->isChecked()) conf->writeEntry("CornersType",2);
   if (topBottomRounded->isChecked()) conf->writeEntry("CornersType",3);
   if (noBorders->isChecked()) conf->writeEntry("AcquaNoBorders",1);
   if (!noBorders->isChecked()) conf->writeEntry("AcquaNoBorders",0);
   if (showMiniIcon->isChecked()) conf->writeEntry("AcquaShowIcons",1);
   if (!showMiniIcon->isChecked()) conf->writeEntry("AcquaShowIcons",0);
   if (shadowedText->isChecked()) conf->writeEntry("AcquaShadowedTitlebarText",1);
   if (!shadowedText->isChecked()) conf->writeEntry("AcquaShadowedTitlebarText",0);

   if (biggerFonts->isChecked()) conf->writeEntry("AcquaBiggerFonts",1);
   if (!biggerFonts->isChecked()) conf->writeEntry("AcquaBiggerFonts",0);

   if (noRightButton->isChecked()) conf->writeEntry("AcquaRightButtonIs",0);
   if (rightButtonIsMenu->isChecked()) conf->writeEntry("AcquaRightButtonIs",1);
   if (rightButtonIsHelp->isChecked()) conf->writeEntry("AcquaRightButtonIs",2);
   if (buttonStyle->isChecked()) conf->writeEntry("AcquaButtonStyle",1);
   if (!buttonStyle->isChecked()) conf->writeEntry("AcquaButtonStyle",0);

   conf->sync();
}

void AcquaConfig::defaults()
{
   forceAppleStyle->setChecked(true);
   rightXIAButtons->setChecked(false);
   noShadows->setChecked(false);
   winShadows->setChecked(true);
   macosxShadows->setChecked(false);
   topRounded->setChecked(true);
   showMiniIcon->setChecked(true);
   noBorders->setChecked(false);
   biggerFonts->setChecked(false);
   updateInterval->setValue(0);
   shadowedText->setChecked(false);
   noRightButton->setChecked(true);
   rightButtonIsMenu->setChecked(false);
   rightButtonIsHelp->setChecked(false);
   buttonStyle->setChecked(true);
   emit changed();
}

#include "AcquaConfig.moc"
