File indexing completed on 2025-01-05 03:52:04

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2006-04-04
0007  * Description : a tool to generate HTML image galleries
0008  *
0009  * SPDX-FileCopyrightText: 2006-2010 by Aurelien Gateau <aurelien dot gateau at free dot fr>
0010  * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "galleryinfo.h"
0017 
0018 // KDE includes
0019 
0020 #include <kconfigbase.h>
0021 
0022 namespace DigikamGenericHtmlGalleryPlugin
0023 {
0024 
0025 static const char* THEME_GROUP_PREFIX = "Theme ";
0026 
0027 GalleryInfo::GalleryInfo(DInfoInterface* const iface)
0028 {
0029     m_iface     = iface;
0030     m_getOption = IMAGES;
0031 }
0032 
0033 GalleryInfo::~GalleryInfo()
0034 {
0035 }
0036 
0037 QString GalleryInfo::fullFormatString() const
0038 {
0039     return getEnumString(QLatin1String("fullFormat"));
0040 }
0041 
0042 QString GalleryInfo::thumbnailFormatString() const
0043 {
0044     return getEnumString(QLatin1String("thumbnailFormat"));
0045 }
0046 
0047 QString GalleryInfo::getThemeParameterValue(const QString& theme,
0048                                             const QString& parameter,
0049                                             const QString& defaultValue) const
0050 {
0051     QString groupName  = QLatin1String(THEME_GROUP_PREFIX) + theme;
0052     KConfigGroup group = config()->group(groupName);
0053 
0054     return group.readEntry(parameter, defaultValue);
0055 }
0056 
0057 void GalleryInfo::setThemeParameterValue(const QString& theme,
0058                                          const QString& parameter,
0059                                          const QString& value)
0060 {
0061     // FIXME: This is hackish, but config() is const :'(
0062     KConfig* const localConfig = const_cast<KConfig*>(config());
0063     QString groupName          = QLatin1String(THEME_GROUP_PREFIX) + theme;
0064     KConfigGroup group         = localConfig->group(groupName);
0065     group.writeEntry(parameter, value);
0066 }
0067 
0068 QString GalleryInfo::getEnumString(const QString& itemName) const
0069 {
0070     // findItem is not marked const :-(
0071     GalleryInfo* const that               = const_cast<GalleryInfo*>(this);
0072     KConfigSkeletonItem* const tmp        = that->findItem(itemName);
0073     KConfigSkeleton::ItemEnum* const item = dynamic_cast<KConfigSkeleton::ItemEnum*>(tmp);
0074 
0075     Q_ASSERT(item);
0076 
0077     if (!item)
0078         return QString();
0079 
0080     int value                                                   = item->value();
0081     QList<KConfigSkeleton::ItemEnum::Choice> lst                = item->choices();
0082     QList<KConfigSkeleton::ItemEnum::Choice>::ConstIterator it  = lst.constBegin();
0083     QList<KConfigSkeleton::ItemEnum::Choice>::ConstIterator end = lst.constEnd();
0084 
0085     for (int pos = 0 ; it != end ; ++it, ++pos)
0086     {
0087         if (pos == value)
0088         {
0089             return (*it).name;
0090         }
0091     }
0092 
0093     return QString();
0094 }
0095 
0096 QDebug operator<<(QDebug dbg, const GalleryInfo& t)
0097 {
0098     dbg.nospace() << "GalleryInfo::Albums: "
0099                   << t.m_albumList << ", ";
0100     dbg.nospace() << "GalleryInfo::Theme: "
0101                   << t.theme() << ", ";
0102     dbg.nospace() << "GalleryInfo::UseOriginalImageAsFullImage: "
0103                   << t.useOriginalImageAsFullImage() << ", ";
0104     dbg.nospace() << "GalleryInfo::FullResize: "
0105                   << t.fullResize() << ", ";
0106     dbg.nospace() << "GalleryInfo::FullSize: "
0107                   << t.fullSize() << ", ";
0108     dbg.nospace() << "GalleryInfo::FullFormat: "
0109                   << t.fullFormat() << ", ";
0110     dbg.nospace() << "GalleryInfo::FullQuality: "
0111                   << t.fullQuality() << ", ";
0112     dbg.nospace() << "GalleryInfo::CopyOriginalImage: "
0113                   << t.copyOriginalImage() << ", ";
0114     dbg.nospace() << "GalleryInfo::ThumbnailSize: "
0115                   << t.thumbnailSize() << ", ";
0116     dbg.nospace() << "GalleryInfo::ThumbnailFormat: "
0117                   << t.thumbnailFormat() << ", ";
0118     dbg.nospace() << "GalleryInfo::ThumbnailQuality: "
0119                   << t.thumbnailQuality();
0120     dbg.nospace() << "GalleryInfo::ThumbnailSquare: "
0121                   << t.thumbnailSquare();
0122     dbg.nospace() << "GalleryInfo::DestUrl: "
0123                   << t.destUrl();
0124     dbg.nospace() << "GalleryInfo::OpenInBrowser: "
0125                   << t.openInBrowser();
0126     dbg.nospace() << "GalleryInfo::ImageSelectionTitle: "
0127                   << t.imageSelectionTitle();
0128     return dbg.space();
0129 }
0130 
0131 } // namespace DigikamGenericHtmlGalleryPlugin
0132 
0133 #include "moc_galleryinfo.cpp"