|
@@ -22,16 +22,19 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.ui_swing.dialogs.prefs;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.addons.ui_swing.SwingController;
|
|
25
|
+import com.dmdirc.ClientModule.GlobalConfig;
|
|
26
|
+import com.dmdirc.ClientModule.UserConfig;
|
26
|
27
|
import com.dmdirc.addons.ui_swing.components.PackingTable;
|
27
|
28
|
import com.dmdirc.config.prefs.PreferencesInterface;
|
28
|
29
|
import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
29
|
30
|
import com.dmdirc.interfaces.config.ConfigChangeListener;
|
30
|
31
|
import com.dmdirc.interfaces.config.ConfigProvider;
|
|
32
|
+import com.dmdirc.interfaces.config.IdentityController;
|
31
|
33
|
import com.dmdirc.logger.ErrorLevel;
|
32
|
34
|
import com.dmdirc.logger.Logger;
|
33
|
35
|
import com.dmdirc.updater.UpdateChannel;
|
34
|
36
|
import com.dmdirc.updater.UpdateChecker;
|
|
37
|
+import com.dmdirc.updater.manager.CachingUpdateManager;
|
35
|
38
|
|
36
|
39
|
import java.awt.event.ActionEvent;
|
37
|
40
|
import java.awt.event.ActionListener;
|
|
@@ -71,23 +74,38 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
|
71
|
74
|
private JButton checkNow;
|
72
|
75
|
/** Update channel. */
|
73
|
76
|
private JComboBox updateChannel;
|
74
|
|
- /** Swing controller. */
|
75
|
|
- private final SwingController controller;
|
76
|
77
|
/** The prefs dialog that will be hosting the panel. */
|
77
|
78
|
private final SwingPreferencesDialog prefsDialog;
|
|
79
|
+ /** The configuration to write settings changes to. */
|
|
80
|
+ private final ConfigProvider userConfig;
|
|
81
|
+ /** The configuration to read global settings from. */
|
|
82
|
+ private final AggregateConfigProvider globalConfig;
|
|
83
|
+ /** The manager to read update information from. */
|
|
84
|
+ private final CachingUpdateManager updateManager;
|
|
85
|
+ /** Controller to pass to the update checker. */
|
|
86
|
+ private final IdentityController identityController;
|
78
|
87
|
|
79
|
88
|
/**
|
80
|
89
|
* Instantiates a new update config panel.
|
81
|
90
|
*
|
82
|
|
- * @param controller Swing controller
|
83
|
91
|
* @param prefsDialog The prefs dialog that will be hosting the panel.
|
|
92
|
+ * @param userConfig The configuration to write settings changes to.
|
|
93
|
+ * @param globalConfig The configuration to read global settings from.
|
|
94
|
+ * @param updateManager The manager to read update information from.
|
|
95
|
+ * @param identityController Controller to pass to the update checker.
|
84
|
96
|
*/
|
85
|
97
|
@Inject
|
86
|
98
|
public UpdateConfigPanel(
|
87
|
|
- final SwingController controller,
|
88
|
|
- final SwingPreferencesDialog prefsDialog) {
|
89
|
|
- this.controller = controller;
|
|
99
|
+ final SwingPreferencesDialog prefsDialog,
|
|
100
|
+ @UserConfig final ConfigProvider userConfig,
|
|
101
|
+ @GlobalConfig final AggregateConfigProvider globalConfig,
|
|
102
|
+ final CachingUpdateManager updateManager,
|
|
103
|
+ final IdentityController identityController) {
|
90
|
104
|
this.prefsDialog = prefsDialog;
|
|
105
|
+ this.userConfig = userConfig;
|
|
106
|
+ this.globalConfig = globalConfig;
|
|
107
|
+ this.updateManager = updateManager;
|
|
108
|
+ this.identityController = identityController;
|
91
|
109
|
|
92
|
110
|
initComponents();
|
93
|
111
|
addListeners();
|
|
@@ -97,18 +115,16 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
|
97
|
115
|
/** {@inheritDoc} */
|
98
|
116
|
@Override
|
99
|
117
|
public void save() {
|
100
|
|
- final ConfigProvider identity = controller.getGlobalIdentity();
|
101
|
|
- identity.setOption("updater", "enable", enable.isSelected());
|
102
|
|
-
|
103
|
|
- identity.setOption("updater", "channel", updateChannel
|
|
118
|
+ userConfig.setOption("updater", "enable", enable.isSelected());
|
|
119
|
+ userConfig.setOption("updater", "channel", updateChannel
|
104
|
120
|
.getSelectedItem().toString());
|
105
|
121
|
|
106
|
122
|
for (int i = 0; i < tableModel.getRowCount(); i++) {
|
107
|
123
|
final String componentName = tableModel.getComponent(i).getName();
|
108
|
124
|
if ((Boolean) tableModel.getValueAt(i, 1)) {
|
109
|
|
- identity.unsetOption("updater", "enable-" + componentName);
|
|
125
|
+ userConfig.unsetOption("updater", "enable-" + componentName);
|
110
|
126
|
} else {
|
111
|
|
- identity.setOption("updater", "enable-" + componentName, false);
|
|
127
|
+ userConfig.setOption("updater", "enable-" + componentName, false);
|
112
|
128
|
}
|
113
|
129
|
}
|
114
|
130
|
}
|
|
@@ -117,23 +133,18 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
|
117
|
133
|
* Initialises the components.
|
118
|
134
|
*/
|
119
|
135
|
private void initComponents() {
|
120
|
|
- final AggregateConfigProvider config = controller.getGlobalConfig();
|
121
|
136
|
enable = new JCheckBox();
|
122
|
137
|
scrollPane = new JScrollPane();
|
123
|
|
- tableModel = new UpdateTableModel(
|
124
|
|
- controller.getCachingUpdateManager(),
|
125
|
|
- controller.getCachingUpdateManager().getComponents());
|
|
138
|
+ tableModel = new UpdateTableModel(updateManager, updateManager.getComponents());
|
126
|
139
|
table = new PackingTable(tableModel, scrollPane);
|
127
|
140
|
checkNow = new JButton("Check now");
|
128
|
|
- checkNow.setEnabled(config.getOptionBool("updater", "enable"));
|
129
|
|
- updateChannel = new JComboBox(new DefaultComboBoxModel(UpdateChannel.
|
130
|
|
- values()));
|
|
141
|
+ checkNow.setEnabled(globalConfig.getOptionBool("updater", "enable"));
|
|
142
|
+ updateChannel = new JComboBox(new DefaultComboBoxModel(UpdateChannel.values()));
|
131
|
143
|
|
132
|
|
- enable.setSelected(config.getOptionBool("updater", "enable"));
|
|
144
|
+ enable.setSelected(globalConfig.getOptionBool("updater", "enable"));
|
133
|
145
|
UpdateChannel channel = UpdateChannel.NONE;
|
134
|
146
|
try {
|
135
|
|
- channel = UpdateChannel.valueOf(
|
136
|
|
- config.getOption("updater", "channel"));
|
|
147
|
+ channel = UpdateChannel.valueOf(globalConfig.getOption("updater", "channel"));
|
137
|
148
|
} catch (IllegalArgumentException e) {
|
138
|
149
|
Logger.userError(ErrorLevel.LOW, "Invalid setting for update "
|
139
|
150
|
+ "channel, defaulting to none.");
|
|
@@ -147,8 +158,7 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
|
147
|
158
|
*/
|
148
|
159
|
private void addListeners() {
|
149
|
160
|
checkNow.addActionListener(this);
|
150
|
|
- controller.getGlobalConfig().addChangeListener("updater",
|
151
|
|
- "enable", this);
|
|
161
|
+ globalConfig.addChangeListener("updater", "enable", this);
|
152
|
162
|
enable.addActionListener(this);
|
153
|
163
|
}
|
154
|
164
|
|
|
@@ -175,16 +185,13 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
|
175
|
185
|
if (enable == e.getSource()) {
|
176
|
186
|
checkNow.setEnabled(enable.isSelected());
|
177
|
187
|
} else {
|
178
|
|
- UpdateChecker.checkNow(
|
179
|
|
- controller.getCachingUpdateManager(),
|
180
|
|
- controller.getIdentityManager());
|
|
188
|
+ UpdateChecker.checkNow(updateManager, identityController);
|
181
|
189
|
}
|
182
|
190
|
}
|
183
|
191
|
|
184
|
192
|
/** {@inheritDoc} */
|
185
|
193
|
@Override
|
186
|
|
- public void configChanged(final String domain, final String key) {
|
187
|
|
- checkNow.setEnabled(controller.getGlobalConfig().getOptionBool(
|
188
|
|
- "updater", "enable"));
|
|
194
|
+ public void configChanged(final String domain, final String key) {
|
|
195
|
+ checkNow.setEnabled(globalConfig.getOptionBool("updater", "enable"));
|
189
|
196
|
}
|
190
|
197
|
}
|