1 /******************************************************************************************************* 2 DkSettings.h 3 Created on: 07.07.2011 4 5 nomacs is a fast and small image viewer with the capability of synchronizing multiple instances 6 7 Copyright (C) 2011-2013 Markus Diem <markus@nomacs.org> 8 Copyright (C) 2011-2013 Stefan Fiel <stefan@nomacs.org> 9 Copyright (C) 2011-2013 Florian Kleber <florian@nomacs.org> 10 11 This file is part of nomacs. 12 13 nomacs is free software: you can redistribute it and/or modify 14 it under the terms of the GNU General Public License as published by 15 the Free Software Foundation, either version 3 of the License, or 16 (at your option) any later version. 17 18 nomacs is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU General Public License for more details. 22 23 You should have received a copy of the GNU General Public License 24 along with this program. If not, see <http://www.gnu.org/licenses/>. 25 26 *******************************************************************************************************/ 27 28 #pragma once 29 30 #pragma warning(push, 0) // no warnings from includes - begin 31 #include <QSettings> 32 #include <QBitArray> 33 #include <QColor> 34 #include <QDate> 35 #include <QSharedPointer> 36 #include <QVector> 37 #pragma warning(pop) // no warnings from includes - end 38 39 #pragma warning(disable: 4251) // TODO: remove 40 41 #ifndef DllCoreExport 42 #ifdef DK_CORE_DLL_EXPORT 43 #define DllCoreExport Q_DECL_EXPORT 44 #elif DK_DLL_IMPORT 45 #define DllCoreExport Q_DECL_IMPORT 46 #else 47 #define DllCoreExport Q_DECL_IMPORT 48 #endif 49 #endif 50 51 class QFileInfo; 52 class QTranslator; 53 54 namespace nmc { 55 56 class DllCoreExport DefaultSettings : public QSettings { 57 58 public: 59 DefaultSettings(); 60 }; 61 62 class DllCoreExport DkFileFilterHandling { 63 64 public: DkFileFilterHandling()65 DkFileFilterHandling() {}; 66 void registerNomacs(bool showDefaultApps = false); 67 void registerFileType(const QString& filterString, const QString& attribute, bool add); 68 void showDefaultSoftware() const; 69 70 static void registerFileAssociations(); 71 72 protected: 73 QString registerProgID(const QString& ext, const QString& friendlyName, bool add); 74 void registerExtension(const QString& ext, const QString& progKey, bool add); 75 void setAsDefaultApp(const QString& ext, const QString& progKey, bool defaultApp); 76 void registerDefaultApp(const QString& ext, const QString& progKey, bool defaultApp); 77 QString getIconID(const QString& ext) const; 78 79 QStringList getExtensions(const QString& filter) const; 80 QStringList getExtensions(const QString& filter, QString& friendlyName) const; 81 }; 82 83 class DllCoreExport DkThemeManager { 84 85 public: DkThemeManager()86 DkThemeManager() {}; 87 88 QStringList getAvailableThemes() const; 89 QString getCurrentThemeName() const; 90 QString themeDir() const; 91 92 void setCurrentTheme(const QString& themeName) const; 93 QString loadTheme(const QString& themeName) const; 94 95 QString loadStylesheet() const; 96 void applyTheme() const; 97 98 QString cleanThemeName(const QString& theme) const; 99 QStringList cleanThemeNames(const QStringList& themes) const; 100 101 protected: 102 QString parseColors(const QString & styleSheet) const; 103 QString replaceColors(const QString & cssString) const; 104 }; 105 106 class DllCoreExport DkSettings { 107 108 public: 109 DkSettings(); 110 111 enum modes { 112 mode_default = 0, 113 mode_frameless, 114 mode_contrast, 115 mode_default_fullscreen, 116 mode_frameless_fullscreen, 117 mode_contrast_fullscreen, 118 mode_end, 119 }; 120 121 enum sortMode { 122 sort_filename, 123 sort_date_created, 124 sort_date_modified, 125 sort_random, 126 sort_end, 127 }; 128 129 enum sortDir { 130 sort_ascending, 131 sort_descending, 132 133 sort_dir_end, 134 }; 135 136 enum rawThumb { 137 raw_thumb_always, 138 raw_thumb_if_large, 139 raw_thumb_never, 140 141 raw_thumb_end, 142 }; 143 144 enum keepZoom { 145 zoom_always_keep, 146 zoom_keep_same_size, 147 zoom_never_keep, 148 149 zoom_end, 150 }; 151 152 enum TransitionMode { 153 trans_appear, 154 trans_fade, 155 trans_swipe, 156 157 trans_end 158 }; 159 160 enum LoadSaveMode { 161 ls_load, 162 ls_load_to_tab, 163 ls_do_nothing, 164 165 ls,end 166 }; 167 168 struct App { 169 bool showToolBar; 170 bool showMenuBar; 171 bool showStatusBar; 172 bool showMovieToolBar; 173 QBitArray showFilePreview; 174 QBitArray showFileInfoLabel; 175 QBitArray showPlayer; 176 QBitArray showMetaData; 177 QBitArray showHistogram; 178 QBitArray showOverview; 179 QBitArray showScroller; 180 QBitArray showComment; 181 QBitArray showExplorer; 182 QBitArray showMetaDataDock; 183 QBitArray showEditDock; 184 QBitArray showHistoryDock; 185 QBitArray showLogDock; 186 bool showRecentFiles; 187 bool useLogFile; 188 int appMode; 189 int currentAppMode; 190 bool privateMode; 191 bool advancedSettings; 192 bool closeOnEsc; 193 bool hideAllPanels; 194 195 int defaultJpgQuality; 196 197 QStringList browseFilters; 198 QStringList registerFilters; 199 200 QStringList fileFilters; // just the filters 201 QStringList openFilters; // for open dialog 202 QStringList saveFilters; // for save dialog 203 QStringList rawFilters; 204 QStringList containerFilters; 205 QString containerRawFilters; 206 }; 207 208 struct Display { 209 int keepZoom; 210 bool zoomToFit; 211 bool invertZoom; 212 bool tpPattern; 213 bool showNavigation; 214 QString themeName; 215 QColor highlightColor; 216 QColor hudBgColor; 217 QColor bgColor; 218 QColor bgColorFrameless; 219 QColor hudFgdColor; 220 QColor iconColor; 221 222 // theme colors 223 QColor themeFgdColor; 224 QColor themeBgdColor; 225 226 bool defaultBackgroundColor; 227 bool defaultIconColor; 228 int thumbSize; 229 int iconSize; 230 int thumbPreviewSize; 231 //bool saveThumb; 232 int interpolateZoomLevel; 233 bool showCrop; 234 bool antiAliasing; 235 bool highQualityAntiAliasing; 236 bool showBorder; 237 bool displaySquaredThumbs; 238 bool showThumbLabel; 239 bool showScrollBars; 240 241 TransitionMode transition; 242 bool alwaysAnimate; 243 float animationDuration; 244 245 int histogramStyle; 246 }; 247 248 struct Global { 249 int skipImgs; 250 int numFiles; 251 bool loop; 252 bool scanSubFolders; 253 254 QString lastDir; 255 QString lastSaveDir; 256 QStringList recentFiles; 257 QStringList recentFolders; 258 QStringList pinnedFiles; 259 bool logRecentFiles; 260 bool checkOpenDuplicates; 261 bool extendedTabs; 262 bool askToSaveDeletedFiles; 263 QString tmpPath; 264 QString language; 265 QStringList searchHistory; 266 267 Qt::KeyboardModifier altMod; 268 Qt::KeyboardModifier ctrlMod; 269 bool zoomOnWheel; 270 bool horZoomSkips; 271 bool doubleClickForFullscreen; 272 bool showBgImage; 273 274 QString setupPath; 275 QString setupVersion; 276 int numThreads; 277 278 int sortMode; 279 int sortDir; 280 QString pluginsDir; 281 }; 282 283 struct SlideShow { 284 int filter; 285 float time; 286 bool showPlayer; 287 bool silentFullscreen; 288 QBitArray display; 289 QColor backgroundColor; 290 float moveSpeed; 291 }; 292 struct Sync { 293 bool checkForUpdates; 294 bool updateDialogShown; 295 bool disableUpdateInteraction; 296 QDate lastUpdateCheck; 297 bool syncAbsoluteTransform; 298 bool switchModifier; 299 bool syncActions; 300 }; 301 struct MetaData { 302 bool ignoreExifOrientation; 303 bool saveExifOrientation; 304 }; 305 306 struct Resources { 307 float cacheMemory; 308 float historyMemory; 309 bool nativeDialog; 310 int maxImagesCached; 311 bool waitForLastImg; 312 bool filterRawImages; 313 bool filterDuplicats; 314 int loadRawThumb; 315 QString preferredExtension; 316 bool gammaCorrection; 317 int loadSavedImage; 318 }; 319 320 enum DisplayItems{ 321 display_file_name, 322 display_creation_date, 323 display_file_rating, 324 325 display_end 326 }; 327 328 QStringList translatedCamData() const; 329 QStringList translatedDescriptionData() const; 330 331 void initFileFilters(); 332 void loadTranslation(const QString& fileName, QTranslator& translator); 333 QStringList getTranslationDirs(); 334 335 void load(); 336 void load(QSettings& settings, bool defaults = false); 337 void save(bool force = false); 338 void save(QSettings& settings, bool force = false); 339 void setToDefaultSettings(); 340 void setNumThreads(int numThreads); 341 342 bool isPortable(); 343 QString settingsPath() const; 344 345 double dpiScaleFactor(QWidget *w = 0) const; 346 int effectiveIconSize(QWidget *w = 0) const; 347 int effectiveThumbSize(QWidget *w = 0) const; 348 int effectiveThumbPreviewSize(QWidget *w = 0) const; 349 350 App& app(); 351 Global& global(); 352 Display& display(); 353 SlideShow& slideShow(); 354 Sync& sync(); 355 MetaData& metaData(); 356 Resources& resources(); 357 358 protected: 359 QStringList scamDataDesc; 360 QStringList sdescriptionDesc; 361 362 App app_p; 363 Global global_p; 364 Display display_p; 365 SlideShow slideShow_p; 366 Sync sync_p; 367 MetaData meta_p; 368 Resources resources_p; 369 370 App app_d; 371 Global global_d; 372 Display display_d; 373 SlideShow slideShow_d; 374 Sync sync_d; 375 MetaData meta_d; 376 Resources resources_d; 377 378 void init(); 379 380 void applyDefaultsFromFile(); 381 void copySettings(const QSettings& src, QSettings& dst) const; 382 QString getDefaultSettingsFile() const; 383 384 QString mSettingsPath; 385 }; 386 387 class DllCoreExport DkSettingsManager { 388 389 public: 390 static DkSettingsManager& instance(); 391 ~DkSettingsManager(); 392 393 // singleton 394 DkSettingsManager(DkSettingsManager const&) = delete; 395 void operator=(DkSettingsManager const&) = delete; 396 397 static DkSettings& param(); // convenience 398 //QSettings& qSettings(); 399 DkSettings& settings(); // rename 400 void init(); 401 402 static void importSettings(const QString& settingsPath); 403 404 private: 405 DkSettingsManager(); 406 407 //QSettings* mSettings = 0; 408 DkSettings* mParams = 0; 409 }; 410 411 class DkZoomConfig { 412 413 public: 414 static DkZoomConfig& instance(); 415 ~DkZoomConfig(); 416 417 // singleton 418 DkZoomConfig(DkZoomConfig const&) = delete; 419 void operator=(DkZoomConfig const&) = delete; 420 421 double nextFactor(double currentFactor, double delta) const; 422 QVector<double> defaultLevels() const; 423 424 bool useLevels() const; 425 void setUseLevels(bool useLevels); 426 427 bool setLevels(const QString& levelStr); 428 QString levelsToString() const; 429 430 void setLevelsToDefault(); 431 432 static bool checkLevels(const QVector<double>& levels); 433 434 private: 435 436 QVector<double> mLevels; 437 bool mUseLevels = false; 438 439 DkZoomConfig(); 440 void loadSettings(QSettings& settings); 441 void saveSettings(QSettings& settings) const; 442 443 }; 444 445 } 446