1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2003-16-10
7  * Description : application settings interface
8  *
9  * Copyright (C) 2003-2004 by Renchi Raju <renchi dot raju at gmail dot com>
10  * Copyright (C) 2003-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  * Copyright (C) 2007      by Arnd Baecker <arnd dot baecker at web dot de>
12  * Copyright (C) 2014-2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
13  * Copyright (C) 2017      by Simon Frei <freisim93 at gmail dot com>
14  *
15  * This program is free software; you can redistribute it
16  * and/or modify it under the terms of the GNU General
17  * Public License as published by the Free Software Foundation;
18  * either version 2, or (at your option)
19  * any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * ============================================================ */
27 
28 #ifndef DIGIKAM_APPLICATION_SETTINGS_H
29 #define DIGIKAM_APPLICATION_SETTINGS_H
30 
31 // Qt includes
32 
33 #include <QFont>
34 #include <QHash>
35 #include <QObject>
36 #include <QString>
37 #include <QStringList>
38 
39 // Local includes
40 
41 #include "digikam_config.h"
42 #include "sidebar.h"
43 #include "dbengineparameters.h"
44 #include "versionmanager.h"
45 #include "digikam_export.h"
46 
47 class KConfigGroup;
48 
49 namespace Digikam
50 {
51 
52 class DbEngineParameters;
53 class VersionManagerSettings;
54 class PreviewSettings;
55 
56 class DIGIKAM_GUI_EXPORT ApplicationSettings : public QObject
57 {
58     Q_OBJECT
59 
60 public:
61 
62     enum AlbumSortRole
63     {
64         ByFolder = 0,
65         ByCategory,
66         ByDate
67     };
68 
69     enum ItemLeftClickAction
70     {
71         ShowPreview = 0,
72         StartEditor,
73         OpenDefault
74     };
75 
76     /**
77      * Possible ways of comparing strings.
78      */
79     enum StringComparisonType
80     {
81         /**
82          * Natural compare using KStringHandler::naturalCompare.
83          */
84         Natural = 0,
85 
86         /**
87          * Normal comparison using Qt's compare function.
88          */
89         Normal
90     };
91 
92     /**
93      * Types of operations
94      * Originally introduced for grouping to configure whether an operation
95      * should be done on all group members or only it's head.
96      */
97     enum OperationType
98     {
99         Metadata = 0,
100         ImportExport,
101         BQM,
102         LightTable,
103         Slideshow,
104         Rename,
105         Tools,
106         Unspecified ///< This element must always come last
107     };
108 
109     enum ApplyToEntireGroup
110     {
111         No = 0,
112         Yes,
113         Ask
114     };
115 
116     typedef QHash<ApplicationSettings::OperationType, QString> OperationStrings;
117     typedef QHash<ApplicationSettings::OperationType, ApplicationSettings::ApplyToEntireGroup> OperationModes;
118 
119 Q_SIGNALS:
120 
121     void setupChanged();
122     void recurseSettingsChanged();
123     void balooSettingsChanged();
124 
125 public:
126 
127     static ApplicationSettings* instance();
128 
129     void readSettings();
130     void saveSettings();
131     void emitSetupChanged();
132 
133     QString generalConfigGroupName() const;
134 
135     // -- MessageBox Notification ---------------------------------------------------
136 
137     /**
138      * @return true if the corresponding message box should be shown.
139      * @param dontShowAgainName the name that identify the message box.
140      */
141     bool readMsgBoxShouldBeShown(const QString& dontShowAgainName);
142 
143     /**
144      * Save the fact that the message box should not be shown again.
145      * @param dontShowAgainName the name that identify the message box. If
146      * empty, this method does nothing.
147      */
148     void saveMsgBoxShouldBeShown(const QString& dontShowAgainName);
149 
150     // -- Database Settings ---------------------------------------------------------
151 
152     DbEngineParameters getDbEngineParameters() const;
153     void setDbEngineParameters(const DbEngineParameters& params);
154 
155     void setSyncBalooToDigikam(bool val);
156     bool getSyncBalooToDigikam() const;
157 
158     void setSyncDigikamToBaloo(bool val);
159     bool getSyncDigikamToBaloo() const;
160 
161     // -- Albums Settings -------------------------------------------------------
162 
163     void setTreeViewIconSize(int val);
164     int  getTreeViewIconSize() const;
165 
166     void setTreeViewFaceSize(int val);
167     int  getTreeViewFaceSize() const;
168 
169     void setTreeViewFont(const QFont& font);
170     QFont getTreeViewFont() const;
171 
172     void setAlbumSortRole(const AlbumSortRole role);
173     AlbumSortRole getAlbumSortRole() const;
174 
175     void setAlbumSortChanged(bool val);
176     bool getAlbumSortChanged() const;
177 
178     void setShowFolderTreeViewItemsCount(bool val);
179     bool getShowFolderTreeViewItemsCount() const;
180 
181     void setAlbumMonitoring(bool val);
182     bool getAlbumMonitoring() const;
183 
184     void setRecurseAlbums(bool val);
185     bool getRecurseAlbums() const;
186 
187     void setRecurseTags(bool val);
188     bool getRecurseTags() const;
189 
190     void setAllGroupsOpen(bool val);
191     bool getAllGroupsOpen() const;
192 
193     void setAlbumCategoryNames(const QStringList& list);
194     QStringList getAlbumCategoryNames() const;
195 
196     bool addAlbumCategoryName(const QString& name) const;
197     bool delAlbumCategoryName(const QString& name) const;
198 
199     // -- Icon-View Settings -------------------------------------------------------
200 
201     void setDefaultIconSize(int val);
202     int  getDefaultIconSize() const;
203 
204     void setIconViewFont(const QFont& font);
205     QFont getIconViewFont() const;
206 
207     void setImageSortOrder(int order);
208     int  getImageSortOrder() const;
209 
210     /**
211      * means ascending or descending
212      */
213     void setImageSorting(int sorting);
214     int  getImageSorting() const;
215 
216     void setImageSeparationMode(int mode);
217     int  getImageSeparationMode() const;
218 
219     void setImageSeparationSortOrder(int order);
220     int  getImageSeparationSortOrder() const;
221 
222     void setItemLeftClickAction(int action);
223     int  getItemLeftClickAction() const;
224 
225     void setIconShowName(bool val);
226     bool getIconShowName() const;
227 
228     void setIconShowSize(bool val);
229     bool getIconShowSize() const;
230 
231     void setIconShowTitle(bool val);
232     bool getIconShowTitle() const;
233 
234     void setIconShowComments(bool val);
235     bool getIconShowComments() const;
236 
237     void setIconShowResolution(bool val);
238     bool getIconShowResolution() const;
239 
240     void setIconShowAspectRatio(bool val);
241     bool getIconShowAspectRatio() const;
242 
243     void setIconShowTags(bool val);
244     bool getIconShowTags() const;
245 
246     void setIconShowDate(bool val);
247     bool getIconShowDate() const;
248 
249     void setIconShowModDate(bool val);
250     bool getIconShowModDate() const;
251 
252     void setIconShowRating(bool val);
253     bool getIconShowRating() const;
254 
255     void setIconShowImageFormat(bool val);
256     bool getIconShowImageFormat() const;
257 
258     void setIconShowCoordinates(bool val);
259     bool getIconShowCoordinates() const;
260 
261     /**
262      * Sets the visibility of the overlay buttons on the image icons.
263      */
264     void setIconShowOverlays(bool val);
265 
266     /**
267      * Determines whether the overlay buttons should be displayed on the icons.
268      */
269     bool getIconShowOverlays() const;
270 
271     void setIconShowFullscreen(bool val);
272     bool getIconShowFullscreen() const;
273 
274     void setPreviewSettings(const PreviewSettings& settings);
275     PreviewSettings getPreviewSettings() const;
276 
277     void setPreviewShowIcons(bool val);
278     bool getPreviewShowIcons() const;
279 
280     // -- Mime-Types Settings -------------------------------------------------------
281 
282     QString getImageFileFilter() const;
283     QString getMovieFileFilter() const;
284     QString getAudioFileFilter() const;
285     QString getRawFileFilter()   const;
286     QString getAllFileFilter()   const;
287 
288     void addToImageFileFilter(const QString& extensions);
289 
290     // -- Tool-Tips Settings -------------------------------------------------------
291 
292     bool showToolTipsIsValid()      const;
293     bool showAlbumToolTipsIsValid() const;
294 
295     void setToolTipsFont(const QFont& font);
296     QFont getToolTipsFont() const;
297 
298     void setShowToolTips(bool val);
299     bool getShowToolTips() const;
300 
301     void setToolTipsShowFileName(bool val);
302     bool getToolTipsShowFileName() const;
303 
304     void setToolTipsShowFileDate(bool val);
305     bool getToolTipsShowFileDate() const;
306 
307     void setToolTipsShowFileSize(bool val);
308     bool getToolTipsShowFileSize() const;
309 
310     void setToolTipsShowImageType(bool val);
311     bool getToolTipsShowImageType() const;
312 
313     void setToolTipsShowImageDim(bool val);
314     bool getToolTipsShowImageDim() const;
315 
316     void setToolTipsShowImageAR(bool val);
317     bool getToolTipsShowImageAR() const;
318 
319     void setToolTipsShowPhotoMake(bool val);
320     bool getToolTipsShowPhotoMake() const;
321 
322     void setToolTipsShowPhotoLens(bool val);
323     bool getToolTipsShowPhotoLens() const;
324 
325     void setToolTipsShowPhotoDate(bool val);
326     bool getToolTipsShowPhotoDate() const;
327 
328     void setToolTipsShowPhotoFocal(bool val);
329     bool getToolTipsShowPhotoFocal() const;
330 
331     void setToolTipsShowPhotoExpo(bool val);
332     bool getToolTipsShowPhotoExpo() const;
333 
334     void setToolTipsShowPhotoMode(bool val);
335     bool getToolTipsShowPhotoMode() const;
336 
337     void setToolTipsShowPhotoFlash(bool val);
338     bool getToolTipsShowPhotoFlash() const;
339 
340     void setToolTipsShowPhotoWB(bool val);
341     bool getToolTipsShowPhotoWB() const;
342 
343     void setToolTipsShowAlbumName(bool val);
344     bool getToolTipsShowAlbumName() const;
345 
346     void setToolTipsShowTitles(bool val);
347     bool getToolTipsShowTitles() const;
348 
349     void setToolTipsShowComments(bool val);
350     bool getToolTipsShowComments() const;
351 
352     void setToolTipsShowTags(bool val);
353     bool getToolTipsShowTags() const;
354 
355     void setToolTipsShowLabelRating(bool val);
356     bool getToolTipsShowLabelRating() const;
357 
358     void setShowAlbumToolTips(bool val);
359     bool getShowAlbumToolTips() const;
360 
361     void setToolTipsShowAlbumTitle(bool val);
362     bool getToolTipsShowAlbumTitle() const;
363 
364     void setToolTipsShowAlbumDate(bool val);
365     bool getToolTipsShowAlbumDate() const;
366 
367     void setToolTipsShowAlbumCollection(bool val);
368     bool getToolTipsShowAlbumCollection() const;
369 
370     void setToolTipsShowAlbumCategory(bool val);
371     bool getToolTipsShowAlbumCategory() const;
372 
373     void setToolTipsShowAlbumCaption(bool val);
374     bool getToolTipsShowAlbumCaption() const;
375 
376     void setToolTipsShowAlbumPreview(bool val);
377     bool getToolTipsShowAlbumPreview() const;
378 
379     void setToolTipsShowVideoAspectRatio(bool val);
380     bool getToolTipsShowVideoAspectRatio() const;
381 
382     void setToolTipsShowVideoAudioBitRate(bool val);
383     bool getToolTipsShowVideoAudioBitRate() const;
384 
385     void setToolTipsShowVideoAudioChannelType(bool val);
386     bool getToolTipsShowVideoAudioChannelType() const;
387 
388     void setToolTipsShowVideoAudioCodec(bool val);
389     bool getToolTipsShowVideoAudioCodec() const;
390 
391     void setToolTipsShowVideoDuration(bool val);
392     bool getToolTipsShowVideoDuration() const;
393 
394     void setToolTipsShowVideoFrameRate(bool val);
395     bool getToolTipsShowVideoFrameRate() const;
396 
397     void setToolTipsShowVideoVideoCodec(bool val);
398     bool getToolTipsShowVideoVideoCodec() const;
399 
400     // -- Miscs Settings -------------------------------------------------------
401 
402     void setScanAtStart(bool val);
403     bool getScanAtStart() const;
404 
405     void setCleanAtStart(bool val);
406     bool getCleanAtStart() const;
407 
408     void setDatabaseDirSetAtCmd(bool val);
409     bool getDatabaseDirSetAtCmd() const;
410 
411     void setUseTrash(bool val);
412     bool getUseTrash() const;
413 
414     void setShowTrashDeleteDialog(bool val);
415     bool getShowTrashDeleteDialog() const;
416 
417     void setShowPermanentDeleteDialog(bool val);
418     bool getShowPermanentDeleteDialog() const;
419 
420     void setApplySidebarChangesDirectly(bool val);
421     bool getApplySidebarChangesDirectly() const;
422 
423     void setUseNativeFileDialog(bool val);
424     bool getUseNativeFileDialog() const;
425 
426     void setDrawFramesToGrouped(bool val);
427     bool getDrawFramesToGrouped() const;
428 
429     void setExpandNewCurrentItem(bool val);
430     bool getExpandNewCurrentItem() const;
431 
432     void setScrollItemToCenter(bool val);
433     bool getScrollItemToCenter() const;
434 
435     void setShowOnlyPersonTagsInPeopleSidebar(bool val);
436     bool showOnlyPersonTagsInPeopleSidebar() const;
437 
438     /**
439      * Defines the way in which string comparisons are performed.
440      *
441      * @param val new way to compare strings
442      */
443     void setStringComparisonType(ApplicationSettings::StringComparisonType val);
444 
445     /**
446      * Tells in which way strings are compared at the moment.
447      *
448      * @return string comparison type to use.
449      */
450     StringComparisonType getStringComparisonType() const;
451 
452     bool isStringTypeNatural() const;
453 
454     void setApplicationStyle(const QString& style);
455     QString getApplicationStyle() const;
456 
457     void setIconTheme(const QString& theme);
458     QString getIconTheme() const;
459 
460     void setApplicationFont(const QFont& fnt);
461     QFont getApplicationFont() const;
462 
463     void setShowSplashScreen(bool val);
464     bool getShowSplashScreen() const;
465 
466     void setCurrentTheme(const QString& theme);
467     QString getCurrentTheme() const;
468 
469     void setSidebarTitleStyle(DMultiTabBar::TextStyle style);
470     DMultiTabBar::TextStyle getSidebarTitleStyle() const;
471 
472     int getUpdateType() const;
473     void setUpdateType(int type);
474 
475     bool getUpdateWithDebug() const;
476     void setUpdateWithDebug(bool dbg);
477 
478     void setVersionManagerSettings(const VersionManagerSettings& settings);
479     VersionManagerSettings getVersionManagerSettings() const;
480 
481     double getFaceDetectionAccuracy() const;
482     void setFaceDetectionAccuracy(double value);
483 
484     bool getFaceDetectionYoloV3() const;
485     void setFaceDetectionYoloV3(bool yolo);
486 
487     void setShowThumbbar(bool val);
488     bool getShowThumbbar() const;
489 
490     void setRatingFilterCond(int val);
491     int  getRatingFilterCond() const;
492 
493     void setMinimumSimilarityBound(int val);
494     int  getMinimumSimilarityBound() const;
495 
496     void setDuplicatesSearchLastMinSimilarity(int val);
497     int  getDuplicatesSearchLastMinSimilarity() const;
498 
499     void setDuplicatesSearchLastMaxSimilarity(int val);
500     int  getDuplicatesSearchLastMaxSimilarity() const;
501 
502     /**
503      * Defines whether an operation should be performed on all grouped items
504      * or just the head item.
505      *
506      * @param type Operation to be performed
507      * @param applyAll Whether to apply to all images or just one, or ask
508      */
509     void setGroupingOperateOnAll(OperationType type, ApplyToEntireGroup applyAll);
510 
511     /**
512      * Tells whether an operation should be performed on all grouped items
513      * or just the head item.
514      *
515      * @param type Operation to be performed
516      * @return Whether to apply to all images or just one, or ask
517      */
518     ApplyToEntireGroup getGroupingOperateOnAll(OperationType type) const;
519 
520     /**
521      * Asks the user whether the operation should be performed on all grouped
522      * images or just the first. Also supplies an option to remember the answer.
523      *
524      * @param type Operation to be performed
525      * @return Whether to apply to all images or just one
526      */
527     bool askGroupingOperateOnAll(OperationType type);
528 
529     /**
530      * Gives the translated title/short explanation of the operation
531      *
532      * @param type Operation to be performed
533      * @return Translated operation title/short explanation
534      */
535     static QString operationTypeTitle(OperationType type);
536 
537     /**
538      * Gives a translated explanation of the operation and an empty string,
539      * if there is none (e.g. for tooltips)
540      *
541      * @param type Operation to be performed
542      * @return Translated operation explanation
543      */
544     static QString operationTypeExplanation(OperationType type);
545 
546     void setDuplicatesAlbumTagRelation(int val);
547     int  getDuplicatesAlbumTagRelation() const;
548 
549     void setDuplicatesSearchRestrictions(int val);
550     int  getDuplicatesSearchRestrictions() const;
551 
552     void setHelpBoxNotificationSeen(bool val);
553     bool getHelpBoxNotificationSeen();
554 
555 private Q_SLOTS:
556 
557     void applyBalooSettings();
558 
559 private:
560 
561     // Disabled
562     ApplicationSettings();
563     explicit ApplicationSettings(QObject*) = delete;
564     ~ApplicationSettings() override;
565 
566     KConfigGroup generalConfigGroup() const;
567 
568 private:
569 
570     friend class ApplicationSettingsCreator;
571 
572     class Private;
573     Private* const d;
574 };
575 
576 } // namespace Digikam
577 
578 #endif // DIGIKAM_APPLICATION_SETTINGS_H
579