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

#include "videosettings.h"

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

class VideoSettingsHelper
{
  public:
    VideoSettingsHelper() : q(nullptr) {}
    ~VideoSettingsHelper() { delete q; q = nullptr; }
    VideoSettingsHelper(const VideoSettingsHelper&) = delete;
    VideoSettingsHelper& operator=(const VideoSettingsHelper&) = delete;
    VideoSettings *q;
};
Q_GLOBAL_STATIC(VideoSettingsHelper, s_globalVideoSettings)
VideoSettings *VideoSettings::self()
{
  if (!s_globalVideoSettings()->q) {
    new VideoSettings;
    s_globalVideoSettings()->q->read();
  }

  return s_globalVideoSettings()->q;
}

VideoSettings *VideoSettings::create(QQmlEngine *, QJSEngine *)
{
  QQmlEngine::setObjectOwnership(self(), QQmlEngine::CppOwnership);
  return self();
}

VideoSettings::VideoSettings( QObject *parent )
  : KConfigSkeleton( QStringLiteral( "haruna/haruna.conf" ) )
{
  setParent(parent);
  Q_ASSERT(!s_globalVideoSettings()->q);
  s_globalVideoSettings()->q = this;
  KConfigCompilerSignallingItem::NotifyFunction notifyFunction = static_cast<KConfigCompilerSignallingItem::NotifyFunction>(&VideoSettings::itemChanged);

  setCurrentGroup( QStringLiteral( "Video" ) );

  KConfigCompilerSignallingItem  *itemDefaultCover;
  KConfigSkeleton::ItemString  *innerItemDefaultCover;
  innerItemDefaultCover = new KConfigSkeleton::ItemString( currentGroup(), QStringLiteral( "DefaultCover" ), mDefaultCover );
  itemDefaultCover = new KConfigCompilerSignallingItem(innerItemDefaultCover, this, notifyFunction, signalDefaultCoverChanged);
  addItem( itemDefaultCover, QStringLiteral( "DefaultCover" ) );
  KConfigCompilerSignallingItem  *itemScreenshotFormat;
  KConfigSkeleton::ItemString  *innerItemScreenshotFormat;
  innerItemScreenshotFormat = new KConfigSkeleton::ItemString( currentGroup(), QStringLiteral( "ScreenshotFormat" ), mScreenshotFormat, QStringLiteral( "jpg" ) );
  itemScreenshotFormat = new KConfigCompilerSignallingItem(innerItemScreenshotFormat, this, notifyFunction, signalScreenshotFormatChanged);
  addItem( itemScreenshotFormat, QStringLiteral( "ScreenshotFormat" ) );

        QString screenshotsFolder = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
        screenshotsFolder.append(QStringLiteral("/Haruna screenshots/%F-%n"));
      
  KConfigCompilerSignallingItem  *itemScreenshotTemplate;
  KConfigSkeleton::ItemString  *innerItemScreenshotTemplate;
  innerItemScreenshotTemplate = new KConfigSkeleton::ItemString( currentGroup(), QStringLiteral( "ScreenshotTemplate" ), mScreenshotTemplate, screenshotsFolder );
  itemScreenshotTemplate = new KConfigCompilerSignallingItem(innerItemScreenshotTemplate, this, notifyFunction, signalScreenshotTemplateChanged);
  addItem( itemScreenshotTemplate, QStringLiteral( "ScreenshotTemplate" ) );
}

QString VideoSettings::defaultScreenshotFormatValue_helper()
{

  return QStringLiteral( "jpg" );
}

QString VideoSettings::defaultScreenshotTemplateValue_helper()
{

        QString screenshotsFolder = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
        screenshotsFolder.append(QStringLiteral("/Haruna screenshots/%F-%n"));
      
  return screenshotsFolder;
}

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


void VideoSettings::itemChanged(quint64 signalFlag) {

  switch (signalFlag) {
  case signalDefaultCoverChanged:
    Q_EMIT DefaultCoverChanged();
    break;
  case signalScreenshotFormatChanged:
    Q_EMIT ScreenshotFormatChanged();
    break;
  case signalScreenshotTemplateChanged:
    Q_EMIT ScreenshotTemplateChanged();
    break;
  }
}
