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

#include "settings.h"

#include <klocalizedstring.h>

#include <qglobal.h>
#include <QFile>

#include <QDebug>

class SettingsHelper
{
  public:
    SettingsHelper() noexcept : q(nullptr) {}
    ~SettingsHelper() noexcept { delete q; q = nullptr; }
    SettingsHelper(const SettingsHelper&) = delete;
    SettingsHelper& operator=(const SettingsHelper&) = delete;
    Settings *q;
};
Q_GLOBAL_STATIC(SettingsHelper, s_globalSettings)
Settings *Settings::self()
{
  if (!s_globalSettings()->q)
     qFatal("you need to call Settings::instance before using");
  return s_globalSettings()->q;
}

void Settings::instance(const QString& cfgfilename)
{
  if (s_globalSettings()->q) {
     qDebug() << "Settings::instance called after the first use - ignoring";
     return;
  }
  new Settings(KSharedConfig::openConfig(cfgfilename));
  s_globalSettings()->q->read();
}

void Settings::instance(KSharedConfig::Ptr config)
{
  if (s_globalSettings()->q) {
     qDebug() << "Settings::instance called after the first use - ignoring";
     return;
  }
  new Settings(std::move(config));
  s_globalSettings()->q->read();
}

Settings::Settings( KSharedConfig::Ptr config )
  : KConfigSkeleton( std::move( config ) )
{
  Q_ASSERT(!s_globalSettings()->q);
  s_globalSettings()->q = this;
  setCurrentGroup( QStringLiteral( "General" ) );

  mPathItem = new KConfigSkeleton::ItemPath( currentGroup(), QStringLiteral( "Path" ), mPath );
  mPathItem->setLabel( i18n("Path to KMail mail folder") );
  addItem( mPathItem, QStringLiteral( "Path" ) );
  mTopLevelIsContainerItem = new KConfigSkeleton::ItemBool( currentGroup(), QStringLiteral( "TopLevelIsContainer" ), mTopLevelIsContainer, false );
  mTopLevelIsContainerItem->setLabel( i18n("Path points to a folder containing Maildirs instead of to a maildir itself.") );
  addItem( mTopLevelIsContainerItem, QStringLiteral( "TopLevelIsContainer" ) );
  mReadOnlyItem = new KConfigSkeleton::ItemBool( currentGroup(), QStringLiteral( "ReadOnly" ), mReadOnly, false );
  mReadOnlyItem->setLabel( i18n("Do not change the actual backend data.") );
  addItem( mReadOnlyItem, QStringLiteral( "ReadOnly" ) );
}

Settings::~Settings()
{
  if (s_globalSettings.exists() && !s_globalSettings.isDestroyed()) {
    s_globalSettings()->q = nullptr;
  }
}

