// This file is generated by kconfig_compiler_kf6 from openxchangeresource.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" ) );

  mBaseUrlItem = new KConfigSkeleton::ItemString( currentGroup(), QStringLiteral( "BaseUrl" ), mBaseUrl );
  mBaseUrlItem->setLabel( i18n("Server URL") );
  mBaseUrlItem->setToolTip( i18n("The URL of the Open-Xchange server, should be something like https://myserver.org/") );
  mBaseUrlItem->setWhatsThis( i18n("The URL of the Open-Xchange server, should be something like https://myserver.org/") );
  addItem( mBaseUrlItem, QStringLiteral( "BaseUrl" ) );
  mUsernameItem = new KConfigSkeleton::ItemString( currentGroup(), QStringLiteral( "Username" ), mUsername );
  mUsernameItem->setLabel( i18nc("the username to login on server", "Username") );
  mUsernameItem->setToolTip( i18n("The username that is used to log into the Open-Xchange server") );
  mUsernameItem->setWhatsThis( i18n("The username that is used to log into the Open-Xchange server") );
  addItem( mUsernameItem, QStringLiteral( "Username" ) );
  mPasswordItem = new KConfigSkeleton::ItemPassword( currentGroup(), QStringLiteral( "Password" ), mPassword );
  mPasswordItem->setLabel( i18n("Password") );
  mPasswordItem->setToolTip( i18n("The password that is used to log into the Open-Xchange server") );
  mPasswordItem->setWhatsThis( i18n("The password that is used to log into the Open-Xchange server") );
  addItem( mPasswordItem, QStringLiteral( "Password" ) );
  mUseIncrementalUpdatesItem = new KConfigSkeleton::ItemBool( currentGroup(), QStringLiteral( "UseIncrementalUpdates" ), mUseIncrementalUpdates, true );
  mUseIncrementalUpdatesItem->setLabel( i18n("Use incremental updates") );
  mUseIncrementalUpdatesItem->setToolTip( i18n("Use incremental updates instead of reloading all data from the server each time") );
  mUseIncrementalUpdatesItem->setWhatsThis( i18n("Use incremental updates instead of reloading all data from the server each time") );
  addItem( mUseIncrementalUpdatesItem, QStringLiteral( "UseIncrementalUpdates" ) );
  mFoldersLastSyncItem = new KConfigSkeleton::ItemULongLong( currentGroup(), QStringLiteral( "FoldersLastSync" ), mFoldersLastSync, 0 );
  mFoldersLastSyncItem->setLabel( i18n("FoldersLastSync") );
  addItem( mFoldersLastSyncItem, QStringLiteral( "FoldersLastSync" ) );
  mObjectsLastSyncItem = new KConfigSkeleton::ItemString( currentGroup(), QStringLiteral( "ObjectsLastSync" ), mObjectsLastSync );
  mObjectsLastSyncItem->setLabel( i18n("ObjectsLastSync") );
  addItem( mObjectsLastSyncItem, QStringLiteral( "ObjectsLastSync" ) );
}

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

