1 #pragma once
2 
3 #include "common/common_pch.h"
4 
5 #include <QDialog>
6 
7 #include "mkvtoolnix-gui/util/settings.h"
8 
9 class QItemSelection;
10 class QListWidget;
11 class QListWidgetItem;
12 class QModelIndex;
13 
14 namespace mtx::gui {
15 
16 namespace Ui {
17 class PreferencesDialog;
18 }
19 
20 class PreferencesDialog : public QDialog {
21   Q_OBJECT
22 
23 public:
24   enum class Page {
25     Gui,
26     OftenUsedSelections,
27     LanguagesShortcuts,
28     Merge,
29     PredefinedValues,
30     DefaultValues,
31     DeriveTrackLanguage,
32     Output,
33     EnablingTracks,
34     Playlists,
35     Info,
36     HeaderEditor,
37     ChapterEditor,
38     Jobs,
39     RunPrograms,
40 
41     PreviouslySelected,
42   };
43 
44 protected:
45   static Page ms_previouslySelectedPage;
46 
47   // UI stuff:
48   std::unique_ptr<Ui::PreferencesDialog> ui;
49   Util::Settings &m_cfg;
50   QString const m_previousUiLocale;
51   bool const m_previousDisableToolTips;
52   double m_previousProbeRangePercentage;
53   QMap<Page, int> m_pageIndexes;
54   bool m_ignoreNextCurrentChange;
55 
56 public:
57   explicit PreferencesDialog(QWidget *parent, Page pageToShow);
58   ~PreferencesDialog();
59 
60   void save();
61   bool uiLocaleChanged() const;
62   bool disableToolTipsChanged() const;
63   bool probeRangePercentageChanged() const;
64 
65 public Q_SLOTS:
66   void editDefaultAdditionalCommandLineOptions();
67   void enableOutputFileNameControls();
68   void browseMediaInfoExe();
69   void browseFixedOutputDirectory();
70   void pageSelectionChanged(QItemSelection const &selection);
71   void addProgramToExecute();
72   void removeProgramToExecute(int index);
73   void setSendersTabTitleForRunProgramWidget();
74   void adjustPlaylistControls();
75   void adjustRemoveOldJobsControls();
76   void revertDeriveTrackLanguageFromFileNameChars();
77   void setupCommonLanguages(bool withISO639_3);
78 
79   void setupLanguageShortcuts();
80   void enableLanguageShortcutControls();
81   void addLanguageShortcut();
82   void editLanguageShortcut();
83   void removeLanguageShortcuts();
84 
85   void addFileColor();
86   void removeFileColors();
87   void editSelectedFileColor();
88   void editFileColor(QListWidgetItem *item);
89   void revertFileColorsToDefault();
90   void enableFileColorsControls();
91 
92   void enableOftendUsedLanguagesOnly();
93   void enableOftendUsedRegionsOnly();
94   void enableOftendUsedCharacterSetsOnly();
95 
96   virtual void accept() override;
97   virtual void reject() override;
98 
99 protected:
100   void setupPageSelector(Page pageToShow);
101   void setupToolTips();
102   void setupConnections();
103 
104   void setupBCP47LanguageEditMode();
105   void setupInterfaceLanguage();
106   void setupTabPositions();
107   void setupDerivingTrackLanguagesFromFileName();
108   void setupWhenToSetDefaultLanguage();
109   void setupJobRemovalPolicy();
110   void setupCommonRegions();
111   void setupCommonCharacterSets();
112   void setupProcessPriority();
113   void setupPlaylistScanningPolicy();
114   void setupOutputFileNamePolicy();
115   void setupRecentDestinationDirectoryList();
116   void setupTrackPropertiesLayout();
117   void setupEnableMuxingTracksByType();
118   void setupEnableMuxingTracksByLanguage();
119   void setupMergeAddingAppendingFilesPolicy();
120   void setupMergeWarnMissingAudioTrack();
121   void setupMergePredefinedItems();
122   void setupHeaderEditorDroppedFilesPolicy();
123   void setupJobsRunPrograms();
124   void setupFontAndScaling();
125   void setupFileColorsControls();
126   void setupFileColors(QVector<QColor> const &colors);
127 
128   QListWidgetItem &setupFileColorItem(QListWidgetItem &item, QColor const &color);
129 
130   void showPage(Page page);
131 
132   void setTabTitleForRunProgramWidget(int tabIdx, QString const &title);
133 
134   QModelIndex modelIndexForPage(int pageIndex);
135 
136   bool verifyDeriveTrackLanguageSettings();
137   bool verifyRunProgramConfigurations();
138 
139   void rememberCurrentlySelectedPage();
140 
141   void saveLanguageShortcuts();
142   void saveFileColors();
143 };
144 
145 }
146