// This file is generated by tdeconfig_compiler from kturtle.kcfg.
// All changes you do to this file will be lost.

#include "settings.h"

#include <kstaticdeleter.h>

Settings *Settings::mSelf = 0;
static KStaticDeleter<Settings> staticSettingsDeleter;

Settings *Settings::self()
{
  if ( !mSelf ) {
    staticSettingsDeleter.setObject( mSelf, new Settings() );
    mSelf->readConfig();
  }

  return mSelf;
}

Settings::Settings(  )
  : TDEConfigSkeleton( TQString::fromLatin1( "kturtlerc" ) )
{
  mSelf = this;
  setCurrentGroup( TQString::fromLatin1( "general" ) );

  TDEConfigSkeleton::ItemInt  *itemCanvasWidth;
  itemCanvasWidth = new TDEConfigSkeleton::ItemInt( currentGroup(), TQString::fromLatin1( "CanvasWidth" ), mCanvasWidth, 300 );
  addItem( itemCanvasWidth, TQString::fromLatin1( "CanvasWidth" ) );
  TDEConfigSkeleton::ItemInt  *itemCanvasHeight;
  itemCanvasHeight = new TDEConfigSkeleton::ItemInt( currentGroup(), TQString::fromLatin1( "CanvasHeight" ), mCanvasHeight, 250 );
  addItem( itemCanvasHeight, TQString::fromLatin1( "CanvasHeight" ) );

  setCurrentGroup( TQString::fromLatin1( "language" ) );



          // This StringList (LogoLanguageList) is a list of all possible language codes all possible [en_US, fr, nl, etc.]. It is used to (1) find the LogoLanguage variable (that is defined later on), and (2) in the Settings dialog to fill the language ComboBox. Better not to dupe this code. The LogoLanguageList is made pretty in the slotSettings class of kturtle.cpp.

          // We assume keyword and highlight files come in pairs (if not there will be no highlight style)

          TQStringList xmlFiles = TDEGlobal::dirs()->findAllResources("data", "kturtle/data/*.xml");
          TQStringList LogoLanguageList;
          TQString xmlTranslationFiles; // for debug purposes
          for ( TQStringList::Iterator it = xmlFiles.begin(); it != xmlFiles.end(); ++it ) {
              TQString xmlFile(*it);
              xmlTranslationFiles += xmlFile.section('.', -2, -2).append(", "); // for debug purposes
              // build list of language codes (en_US, nl, etc.)
              LogoLanguageList += xmlFile.section('.', -2, -2);
          }
          kdDebug(0) << "Available translations of Logo: "<< xmlTranslationFiles <<endl;
          LogoLanguageList.sort();

      
  TDEConfigSkeleton::ItemStringList  *itemLogoLanguageList;
  itemLogoLanguageList = new TDEConfigSkeleton::ItemStringList( currentGroup(), TQString::fromLatin1( "LogoLanguageList" ), mLogoLanguageList, LogoLanguageList );
  addItem( itemLogoLanguageList, TQString::fromLatin1( "LogoLanguageList" ) );


          // This is the String (LogoLanguage) that actually gets picked up by the app to know what XML files (for HLstyle and Logo language) to use. It is not directly changeable by the ComboBox but is translated from the Ints that ComboBox LogoLanguageList emits. It is better to have the logic that changes the Ints to Strings at the settings dept.

          // The KconfigXT framework makes shure the value that is saved in the kturtlerc file will be used in stead of the defaultLanguage that we find here.

          // Get the desktops language
          TDEConfigBase *globalConf = TDEGlobal::config();
          globalConf->setGroup("Locale");
          TQString desktopLanguage = globalConf->readEntry("Language");
          kdDebug(0) << "desktopLanguage: "<< desktopLanguage <<endl;

          TQString defaultLanguage = "en_US";  // init to the fall back value
          int itemCount = 0;  // for the LanguageComboBox
          for (TQStringList::Iterator it = LogoLanguageList.begin(); it != LogoLanguageList.end(); ++it ) {
              TQString testLanguage(*it);
              if (testLanguage == desktopLanguage) { // exact match
                  defaultLanguage = testLanguage;
                  break;
              } else if ( testLanguage.left(2) == desktopLanguage.left(2) ) { // close match (different dialect)
                  // The default language must still be one of the kturtle languages.
                  // defaultLanguage = testLanguage.left(2);
                  defaultLanguage = testLanguage;
                  break;
              }
              itemCount++;
          }
          kdDebug(0) << "Logo command language: "<< defaultLanguage <<endl;

      
  TDEConfigSkeleton::ItemString  *itemLogoLanguage;
  itemLogoLanguage = new TDEConfigSkeleton::ItemString( currentGroup(), TQString::fromLatin1( "LogoLanguage" ), mLogoLanguage, defaultLanguage );
  addItem( itemLogoLanguage, TQString::fromLatin1( "LogoLanguage" ) );


         // This is the parameter that actually gets changed (and emits the signal to the dialog to enable the Apply and Defaults buttons). This value is saved in the kturtlerc file but is never used.

      
  TDEConfigSkeleton::ItemInt  *itemLanguageComboBox;
  itemLanguageComboBox = new TDEConfigSkeleton::ItemInt( currentGroup(), TQString::fromLatin1( "LanguageComboBox" ), mLanguageComboBox, itemCount );
  addItem( itemLanguageComboBox, TQString::fromLatin1( "LanguageComboBox" ) );
}

Settings::~Settings()
{
  if ( mSelf == this )
    staticSettingsDeleter.setObject( mSelf, 0, false );
}

