1 #pragma once
2 
3 #include <QHash>
4 #include <QSortFilterProxyModel>
5 
6 #include "controllers/controllerinputmappingtablemodel.h"
7 #include "controllers/controlleroutputmappingtablemodel.h"
8 #include "controllers/controllerpreset.h"
9 #include "controllers/controllerpresetinfo.h"
10 #include "controllers/dlgcontrollerlearning.h"
11 #include "controllers/ui_dlgprefcontrollerdlg.h"
12 #include "preferences/dialog/dlgpreferencepage.h"
13 #include "preferences/usersettings.h"
14 
15 // Forward declarations
16 class Controller;
17 class ControllerManager;
18 class PresetInfoEnumerator;
19 
20 /// Configuration dialog for a single DJ controller
21 class DlgPrefController : public DlgPreferencePage {
22     Q_OBJECT
23   public:
24     DlgPrefController(QWidget *parent, Controller* controller,
25                       ControllerManager* controllerManager,
26                       UserSettingsPointer pConfig);
27     virtual ~DlgPrefController();
28 
29     QUrl helpUrl() const override;
30 
31   public slots:
32     /// Called when the preference dialog (not this page) is shown to the user.
33     void slotUpdate() override;
34     /// Called when the user clicks the global "Apply" button.
35     void slotApply() override;
36     /// Called when the user clicks the global "Reset to Defaults" button.
37     void slotResetToDefaults() override;
38 
39   signals:
40     void applyPreset(Controller* pController, ControllerPresetPointer pPreset, bool bEnabled);
41     void mappingStarted();
42     void mappingEnded();
43 
44   private slots:
45     /// Called when the user selects another preset in the combobox
46     void slotPresetSelected(int index);
47     /// Used to selected the current preset in the combobox and display the
48     /// preset information.
49     void slotShowPreset(ControllerPresetPointer preset);
50     /// Called when the Controller Learning Wizard is closed.
51     void slotStopLearning();
52 
53     // Input mappings
54     void addInputMapping();
55     void showLearningWizard();
56     void removeInputMappings();
57     void clearAllInputMappings();
58 
59     // Output mappings
60     void addOutputMapping();
61     void removeOutputMappings();
62     void clearAllOutputMappings();
63 
64     void midiInputMappingsLearned(const MidiInputMappings& mappings);
65 
66   private:
67     QString presetShortName(const ControllerPresetPointer pPreset) const;
68     QString presetName(const ControllerPresetPointer pPreset) const;
69     QString presetAuthor(const ControllerPresetPointer pPreset) const;
70     QString presetDescription(const ControllerPresetPointer pPreset) const;
71     QString presetSupportLinks(const ControllerPresetPointer pPreset) const;
72     QString presetFileLinks(const ControllerPresetPointer pPreset) const;
73     QString presetPathFromIndex(int index) const;
74     QString askForPresetName(const QString& prefilledName = QString()) const;
75     void applyPresetChanges();
76     void savePreset();
77     void initTableView(QTableView* pTable);
78 
79     /// Set dirty state (i.e. changes have been made).
80     ///
81     /// When this preferences page is marked as "dirty", changes have occurred
82     /// that can be applied or discarded.
83     ///
84     /// @param bDirty The new dialog's dirty state.
setDirty(bool bDirty)85     void setDirty(bool bDirty) {
86         m_bDirty = bDirty;
87     }
88 
89     /// Set dirty state (i.e. changes have been made).
90     ///
91     /// When this preferences page is marked as "dirty", changes have occurred
92     /// that can be applied or discarded.
93     ///
94     /// @param bDirty The new dialog's dirty state.
isDirty()95     bool isDirty() {
96         return m_bDirty;
97     }
98 
99     /// Reload the mappings in the dropdown dialog
100     void enumeratePresets(const QString& selectedPresetPath);
101     PresetInfo enumeratePresetsFromEnumerator(
102             QSharedPointer<PresetInfoEnumerator> pPresetEnumerator,
103             const QIcon& icon = QIcon());
104 
105     void enableDevice();
106     void disableDevice();
107 
108     Ui::DlgPrefControllerDlg m_ui;
109     UserSettingsPointer m_pConfig;
110     const QString m_pUserDir;
111     ControllerManager* m_pControllerManager;
112     Controller* m_pController;
113     DlgControllerLearning* m_pDlgControllerLearning;
114     ControllerPresetPointer m_pPreset;
115     QMap<QString, bool> m_pOverwritePresets;
116     ControllerInputMappingTableModel* m_pInputTableModel;
117     QSortFilterProxyModel* m_pInputProxyModel;
118     ControllerOutputMappingTableModel* m_pOutputTableModel;
119     QSortFilterProxyModel* m_pOutputProxyModel;
120     bool m_bDirty;
121 };
122