File indexing completed on 2024-05-12 15:55:35

0001 // SPDX-FileCopyrightText: 2003-2021 Jesper K. Pedersen <jesper.pedersen@kdab.com>
0002 // SPDX-FileCopyrightText: 2005-2007 Dirk Mueller <mueller@kde.org>
0003 // SPDX-FileCopyrightText: 2006-2008 Tuomas Suutari <tuomas@nepnep.net>
0004 // SPDX-FileCopyrightText: 2007-2008 Jan Kundrát <jkt@flaska.net>
0005 // SPDX-FileCopyrightText: 2008 Henner Zeller <h.zeller@acm.org>
0006 // SPDX-FileCopyrightText: 2009-2012 Miika Turkia <miika.turkia@gmail.com>
0007 // SPDX-FileCopyrightText: 2010 Wes Hardaker <kpa@capturedonearth.com>
0008 // SPDX-FileCopyrightText: 2011 Andreas Neustifter <andreas.neustifter@gmail.com>
0009 // SPDX-FileCopyrightText: 2012-2023 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0010 // SPDX-FileCopyrightText: 2014-2022 Tobias Leupold <tl@stonemx.de>
0011 // SPDX-FileCopyrightText: 2019 Robert Krawitz <rlk@alum.mit.edu>
0012 //
0013 // SPDX-License-Identifier: GPL-2.0-or-later
0014 
0015 #ifndef KPABASE_SETTINGSDATA_H
0016 #define KPABASE_SETTINGSDATA_H
0017 
0018 #include "StringSet.h"
0019 #include "UIDelegate.h"
0020 #include "enums.h"
0021 
0022 #include <QObject>
0023 
0024 #define property(GET_TYPE, GET_FUNC, SET_FUNC, SET_TYPE) \
0025     GET_TYPE GET_FUNC() const;                           \
0026     void SET_FUNC(const SET_TYPE)
0027 
0028 #define property_copy(GET_FUNC, SET_FUNC, TYPE) property(TYPE, GET_FUNC, SET_FUNC, TYPE)
0029 #define property_ref(GET_FUNC, SET_FUNC, TYPE) property(TYPE, GET_FUNC, SET_FUNC, TYPE &)
0030 
0031 namespace DB
0032 {
0033 class CategoryCollection;
0034 }
0035 
0036 namespace Settings
0037 {
0038 Q_NAMESPACE
0039 
0040 using Utilities::StringSet;
0041 
0042 enum Position { Bottom,
0043                 Top,
0044                 Left,
0045                 Right,
0046                 TopLeft,
0047                 TopRight,
0048                 BottomLeft,
0049                 BottomRight };
0050 enum ViewSortType { SortLastUse,
0051                     SortAlphaTree,
0052                     SortAlphaFlat };
0053 enum TimeStampTrust { Always,
0054                       Ask,
0055                       Never };
0056 enum StandardViewSize { FullSize,
0057                         NaturalSize,
0058                         NaturalSizeIfFits };
0059 enum ThumbnailAspectRatio { Aspect_1_1,
0060                             Aspect_4_3,
0061                             Aspect_3_2,
0062                             Aspect_16_9,
0063                             Aspect_3_4,
0064                             Aspect_2_3,
0065                             Aspect_9_16 };
0066 enum LoadOptimizationPreset { LoadOptimizationHardDisk,
0067                               LoadOptimizationNetwork,
0068                               LoadOptimizationSataSSD,
0069                               LoadOptimizationSlowNVME,
0070                               LoadOptimizationFastNVME,
0071                               LoadOptimizationManual };
0072 
0073 enum class VideoBackend { NotConfigured = 0b0000,
0074                           Phonon = 0b0001,
0075                           QtAV = 0b0010,
0076                           VLC = 0b0100 };
0077 Q_DECLARE_FLAGS(VideoBackends, VideoBackend)
0078 Q_FLAG_NS(VideoBackend)
0079 
0080 typedef const char *WindowType;
0081 extern const WindowType MainWindow, AnnotationDialog;
0082 
0083 class SettingsData : public QObject
0084 {
0085     Q_OBJECT
0086 
0087 public:
0088     static SettingsData *instance();
0089     static bool ready();
0090     static void setup(const QString &imageDirectory, DB::UIDelegate &delegate);
0091 
0092     /////////////////
0093     //// General ////
0094     /////////////////
0095 
0096     property_ref(histogramSize, setHistogramSize, QSize);
0097     property_copy(useEXIFRotate, setUseEXIFRotate, bool);
0098     property_copy(useEXIFComments, setUseEXIFComments, bool);
0099     property_copy(stripEXIFComments, setStripEXIFComments, bool);
0100     property_copy(commentsToStrip, setCommentsToStrip, QString);
0101     property_copy(searchForImagesOnStart, setSearchForImagesOnStart, bool);
0102     property_copy(ignoreFileExtension, setIgnoreFileExtension, bool);
0103     property_copy(skipSymlinks, setSkipSymlinks, bool);
0104     property_copy(skipRawIfOtherMatches, setSkipRawIfOtherMatches, bool);
0105     property_copy(useRawThumbnail, setUseRawThumbnail, bool);
0106     property_copy(useRawThumbnailSize, setUseRawThumbnailSize, QSize);
0107     property_copy(useCompressedIndexXML, setUseCompressedIndexXML, bool);
0108     property_copy(compressBackup, setCompressBackup, bool);
0109     property_copy(showSplashScreen, setShowSplashScreen, bool);
0110     property_copy(showHistogram, setShowHistogram, bool);
0111     property_copy(histogramUseLinearScale, setHistogramUseLinearScale, bool);
0112     property_copy(autoSave, setAutoSave, int);
0113     property_copy(backupCount, setBackupCount, int);
0114     property_copy(viewSortType, setViewSortType, ViewSortType);
0115     property_copy(matchType, setMatchType, AnnotationDialog::MatchType);
0116     property_copy(tTimeStamps, setTTimeStamps, TimeStampTrust);
0117     property_copy(excludeDirectories, setExcludeDirectories, QString);
0118     property_copy(browserUseNaturalSortOrder, setBrowserUseNaturalSortOrder, bool);
0119 #ifdef KPA_ENABLE_REMOTECONTROL
0120     property_copy(recentAndroidAddress, setRecentAndroidAddress, QString);
0121     property_copy(listenForAndroidDevicesOnStartup, setListenForAndroidDevicesOnStartup, bool);
0122 #endif
0123 
0124     ////////////////////////////////
0125     //// File Version Detection ////
0126     ////////////////////////////////
0127 
0128     property_copy(detectModifiedFiles, setDetectModifiedFiles, bool);
0129     property_copy(modifiedFileComponent, setModifiedFileComponent, QString);
0130     property_copy(originalFileComponent, setOriginalFileComponent, QString);
0131     property_copy(moveOriginalContents, setMoveOriginalContents, bool);
0132     property_copy(autoStackNewFiles, setAutoStackNewFiles, bool);
0133     property_copy(copyFileComponent, setCopyFileComponent, QString);
0134     property_copy(copyFileReplacementComponent, setCopyFileReplacementComponent, QString);
0135     property_copy(loadOptimizationPreset, setLoadOptimizationPreset, int);
0136     property_copy(overlapLoadMD5, setOverlapLoadMD5, bool);
0137     property_copy(preloadThreadCount, setPreloadThreadCount, int);
0138     property_copy(thumbnailPreloadThreadCount, setThumbnailPreloadThreadCount, int);
0139     property_copy(thumbnailBuilderThreadCount, setThumbnailBuilderThreadCount, int);
0140 
0141     bool trustTimeStamps();
0142 
0143     ////////////////////
0144     //// Thumbnails ////
0145     ////////////////////
0146 
0147     property_copy(displayLabels, setDisplayLabels, bool);
0148     property_copy(displayCategories, setDisplayCategories, bool);
0149     property_copy(autoShowThumbnailView, setAutoShowThumbnailView, int);
0150     property_copy(showNewestThumbnailFirst, setShowNewestFirst, bool);
0151     property_copy(thumbnailDisplayGrid, setThumbnailDisplayGrid, bool);
0152     property_copy(previewSize, setPreviewSize, int);
0153     property_ref(colorScheme, setColorScheme, QString);
0154     property_copy(incrementalThumbnails, setIncrementalThumbnails, bool);
0155 
0156     // Border space around thumbnails.
0157     property_copy(thumbnailSpace, setThumbnailSpace, int);
0158     property_copy(thumbnailSize, setThumbnailSize, int);
0159     property_copy(minimumThumbnailSize, setMinimumThumbnailSize, int);
0160     property_copy(maximumThumbnailSize, setMaximumThumbnailSize, int);
0161     property_copy(actualThumbnailSize, setActualThumbnailSize, int);
0162     property_copy(thumbnailAspectRatio, setThumbnailAspectRatio, ThumbnailAspectRatio);
0163 
0164     ////////////////
0165     //// Viewer ////
0166     ////////////////
0167 
0168     property_ref(viewerSize, setViewerSize, QSize);
0169     property_ref(slideShowSize, setSlideShowSize, QSize);
0170     property_copy(launchViewerFullScreen, setLaunchViewerFullScreen, bool);
0171     property_copy(launchSlideShowFullScreen, setLaunchSlideShowFullScreen, bool);
0172     property_copy(showInfoBox, setShowInfoBox, bool);
0173     property_copy(showLabel, setShowLabel, bool);
0174     property_copy(showDescription, setShowDescription, bool);
0175     property_copy(showDate, setShowDate, bool);
0176     property_copy(showImageSize, setShowImageSize, bool);
0177     property_copy(showRating, setShowRating, bool);
0178     property_copy(showTime, setShowTime, bool);
0179     property_copy(showFilename, setShowFilename, bool);
0180     property_copy(showEXIF, setShowEXIF, bool);
0181     property_copy(smoothScale, setSmoothScale, bool);
0182     property_copy(slideShowInterval, setSlideShowInterval, int);
0183     property_copy(viewerCacheSize, setViewerCacheSize, int);
0184     property_copy(infoBoxWidth, setInfoBoxWidth, int);
0185     property_copy(infoBoxHeight, setInfoBoxHeight, int);
0186     property_copy(infoBoxPosition, setInfoBoxPosition, Position);
0187     property_copy(viewerStandardSize, setViewerStandardSize, StandardViewSize);
0188     property_copy(videoBackend, setVideoBackend, VideoBackend);
0189 
0190     ////////////////////
0191     //// Categories ////
0192     ////////////////////
0193 
0194     property_ref(untaggedCategory, setUntaggedCategory, QString);
0195     property_ref(untaggedTag, setUntaggedTag, QString);
0196     property_copy(untaggedImagesTagVisible, setUntaggedImagesTagVisible, bool);
0197 
0198     //////////////
0199     //// Exif ////
0200     //////////////
0201 
0202     property_ref(exifForViewer, setExifForViewer, StringSet);
0203     property_ref(exifForDialog, setExifForDialog, StringSet);
0204     property_ref(iptcCharset, setIptcCharset, QString);
0205 
0206     /////////////////////
0207     //// Exif Import ////
0208     /////////////////////
0209 
0210     property_copy(updateExifData, setUpdateExifData, bool);
0211     property_copy(updateImageDate, setUpdateImageDate, bool);
0212     property_copy(useModDateIfNoExif, setUseModDateIfNoExif, bool);
0213     property_copy(updateOrientation, setUpdateOrientation, bool);
0214     property_copy(updateDescription, setUpdateDescription, bool);
0215 
0216     ///////////////////////
0217     //// Miscellaneous ////
0218     ///////////////////////
0219 
0220     property_ref(HTMLBaseDir, setHTMLBaseDir, QString);
0221     property_ref(HTMLBaseURL, setHTMLBaseURL, QString);
0222     property_ref(HTMLDestURL, setHTMLDestURL, QString);
0223     property_ref(HTMLCopyright, setHTMLCopyright, QString);
0224     property_ref(HTMLDate, setHTMLDate, int);
0225     property_ref(HTMLTheme, setHTMLTheme, int);
0226     property_ref(HTMLKimFile, setHTMLKimFile, int);
0227     property_ref(HTMLInlineMovies, setHTMLInlineMovies, int);
0228     property_ref(HTML5Video, setHTML5Video, int);
0229     property_ref(HTML5VideoGenerate, setHTML5VideoGenerate, int);
0230     property_ref(HTMLThumbSize, setHTMLThumbSize, int);
0231     property_ref(HTMLNumOfCols, setHTMLNumOfCols, int);
0232     property_ref(HTMLSizes, setHTMLSizes, QString);
0233     property_ref(HTMLIncludeSelections, setHTMLIncludeSelections, QString);
0234 
0235     property_ref(fromDate, setFromDate, QDate);
0236     property_ref(toDate, setToDate, QDate);
0237 
0238     QString imageDirectory() const;
0239 
0240     QString groupForDatabase(const char *setting) const;
0241 
0242     QVariantMap currentLock() const;
0243     void setCurrentLock(const QVariantMap &pairs, bool exclude);
0244     bool lockExcludes() const;
0245 
0246     bool locked() const;
0247     void setLocked(bool locked, bool force);
0248 
0249     void setWindowGeometry(WindowType, const QRect &geometry);
0250     QRect windowGeometry(WindowType) const;
0251 
0252     double getThumbnailAspectRatio() const;
0253 
0254     QStringList EXIFCommentsToStrip();
0255     void setEXIFCommentsToStrip(QStringList EXIFCommentsToStrip);
0256 
0257     bool getOverlapLoadMD5() const;
0258     int getPreloadThreadCount() const;
0259     int getThumbnailPreloadThreadCount() const;
0260     int getThumbnailBuilderThreadCount() const;
0261 
0262 Q_SIGNALS:
0263     void locked(bool lock, bool exclude);
0264     void viewSortTypeChanged(Settings::ViewSortType);
0265     void matchTypeChanged(AnnotationDialog::MatchType);
0266     void histogramSizeChanged(const QSize &);
0267     void thumbnailSizeChanged(int);
0268     void actualThumbnailSizeChanged(int);
0269     void histogramScaleChanged();
0270     void colorSchemeChanged();
0271     void displayLabelsChanged(bool);
0272     void displayCategoriesChanged(bool);
0273     /**
0274      * @brief untaggedTagChanged is emitted when untaggedCategory() or untaggedTag() changes.
0275      * Note that code in KPhotoAlbum currently calls setUntaggedCategory(const QString&) and setUntaggedTag(const QString&),
0276      * const QString&), which may result in the signal being triggered two times instead of once.
0277      * @param category
0278      * @param tag
0279      */
0280     void untaggedTagChanged(const QString &category, const QString &tag);
0281 
0282 private:
0283     SettingsData(const QString &imageDirectory, DB::UIDelegate &delegate);
0284     DB::UIDelegate &uiDelegate() const;
0285 
0286     bool m_trustTimeStamps;
0287     bool m_hasAskedAboutTimeStamps;
0288     QString m_imageDirectory;
0289     static SettingsData *s_instance;
0290 
0291     friend class DB::CategoryCollection;
0292 
0293     QStringList m_EXIFCommentsToStrip;
0294     DB::UIDelegate &m_UI;
0295 };
0296 } // end of namespace
0297 
0298 #undef property
0299 #undef property_copy
0300 #undef property_ref
0301 
0302 #endif /* KPABASE_SETTINGSDATA_H */
0303 // vi:expandtab:tabstop=4 shiftwidth=4: