Browse Source

Fixes issue 3437: "Check now" button should be disabled if update checking is disabled

Change-Id: Ibbbcf53d4c7aa1670d464693a81e55135f44a7fa
Reviewed-on: http://gerrit.dmdirc.com/343
Tested-by: Gregory Holmes <greboid@dmdirc.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Gregory Holmes 14 years ago
parent
commit
d7b0b81b5a
1 changed files with 25 additions and 13 deletions
  1. 25
    13
      src/com/dmdirc/addons/ui_swing/dialogs/prefs/UpdateConfigPanel.java

+ 25
- 13
src/com/dmdirc/addons/ui_swing/dialogs/prefs/UpdateConfigPanel.java View File

22
 
22
 
23
 package com.dmdirc.addons.ui_swing.dialogs.prefs;
23
 package com.dmdirc.addons.ui_swing.dialogs.prefs;
24
 
24
 
25
-import com.dmdirc.Main;
26
 import com.dmdirc.addons.ui_swing.SwingController;
25
 import com.dmdirc.addons.ui_swing.SwingController;
27
 import com.dmdirc.config.ConfigManager;
26
 import com.dmdirc.config.ConfigManager;
28
 import com.dmdirc.config.Identity;
27
 import com.dmdirc.config.Identity;
29
 import com.dmdirc.config.IdentityManager;
28
 import com.dmdirc.config.IdentityManager;
30
 import com.dmdirc.config.prefs.PreferencesInterface;
29
 import com.dmdirc.config.prefs.PreferencesInterface;
31
 import com.dmdirc.addons.ui_swing.components.PackingTable;
30
 import com.dmdirc.addons.ui_swing.components.PackingTable;
31
+import com.dmdirc.interfaces.ConfigChangeListener;
32
 import com.dmdirc.logger.ErrorLevel;
32
 import com.dmdirc.logger.ErrorLevel;
33
 import com.dmdirc.logger.Logger;
33
 import com.dmdirc.logger.Logger;
34
 import com.dmdirc.updater.UpdateChannel;
34
 import com.dmdirc.updater.UpdateChannel;
51
  * Updates configuration UI.
51
  * Updates configuration UI.
52
  */
52
  */
53
 public class UpdateConfigPanel extends JPanel implements ActionListener,
53
 public class UpdateConfigPanel extends JPanel implements ActionListener,
54
-        PreferencesInterface {
54
+        PreferencesInterface, ConfigChangeListener {
55
 
55
 
56
     /**
56
     /**
57
      * A version number for this class. It should be changed whenever the class
57
      * A version number for this class. It should be changed whenever the class
81
      */
81
      */
82
     public UpdateConfigPanel(final SwingController controller) {
82
     public UpdateConfigPanel(final SwingController controller) {
83
         this.controller = controller;
83
         this.controller = controller;
84
-        
84
+
85
         initComponents();
85
         initComponents();
86
         addListeners();
86
         addListeners();
87
         layoutComponents();
87
         layoutComponents();
91
     @Override
91
     @Override
92
     public void save() {
92
     public void save() {
93
         final Identity identity = IdentityManager.getConfigIdentity();
93
         final Identity identity = IdentityManager.getConfigIdentity();
94
-        if (enable.isSelected()) {
95
-            identity.setOption("updater", "enable", true);
96
-        } else {
97
-            identity.setOption("updater", "enable", false);
98
-        }
94
+        identity.setOption("updater", "enable", enable.isSelected());
99
 
95
 
100
         IdentityManager.getConfigIdentity().setOption("updater", "channel",
96
         IdentityManager.getConfigIdentity().setOption("updater", "channel",
101
                 updateChannel.getSelectedItem().toString());
97
                 updateChannel.getSelectedItem().toString());
120
         tableModel = new UpdateTableModel(UpdateChecker.getComponents());
116
         tableModel = new UpdateTableModel(UpdateChecker.getComponents());
121
         table = new PackingTable(tableModel, false, scrollPane);
117
         table = new PackingTable(tableModel, false, scrollPane);
122
         checkNow = new JButton("Check now");
118
         checkNow = new JButton("Check now");
119
+        checkNow.setEnabled(IdentityManager.getGlobalConfig().getOptionBool(
120
+                "updater", "enable"));
123
         updateChannel = new JComboBox(new DefaultComboBoxModel(UpdateChannel.
121
         updateChannel = new JComboBox(new DefaultComboBoxModel(UpdateChannel.
124
                 values()));
122
                 values()));
125
 
123
 
129
             channel = UpdateChannel.valueOf(
127
             channel = UpdateChannel.valueOf(
130
                     config.getOption("updater", "channel"));
128
                     config.getOption("updater", "channel"));
131
         } catch (IllegalArgumentException e) {
129
         } catch (IllegalArgumentException e) {
132
-            Logger.userError(ErrorLevel.LOW, "Invalid setting for update " +
133
-                    "channel, defaulting to none.");
130
+            Logger.userError(ErrorLevel.LOW, "Invalid setting for update "
131
+                    + "channel, defaulting to none.");
134
         }
132
         }
135
         updateChannel.setSelectedItem(channel);
133
         updateChannel.setSelectedItem(channel);
136
         scrollPane.setViewportView(table);
134
         scrollPane.setViewportView(table);
141
      */
139
      */
142
     private void addListeners() {
140
     private void addListeners() {
143
         checkNow.addActionListener(this);
141
         checkNow.addActionListener(this);
142
+        IdentityManager.getGlobalConfig().addChangeListener("updater",
143
+                "enable", this);
144
+        enable.addActionListener(this);
144
     }
145
     }
145
 
146
 
146
     /**
147
     /**
147
      * Lays out the components.
148
      * Lays out the components.
148
      */
149
      */
149
     private void layoutComponents() {
150
     private void layoutComponents() {
150
-        setLayout(new MigLayout("fill, ins 0, hmax " + controller.
151
-                getPrefsDialog().getPanelHeight()));
151
+        setLayout(new MigLayout("fill, ins 0, hmax " + controller.getPrefsDialog().
152
+                getPanelHeight()));
152
 
153
 
153
         add(new JLabel("Update checking:"), "split");
154
         add(new JLabel("Update checking:"), "split");
154
         add(enable, "growx");
155
         add(enable, "growx");
164
      */
165
      */
165
     @Override
166
     @Override
166
     public void actionPerformed(final ActionEvent e) {
167
     public void actionPerformed(final ActionEvent e) {
167
-        UpdateChecker.checkNow();
168
+        if (enable == e.getSource()) {
169
+            checkNow.setEnabled(enable.isSelected());
170
+        } else {
171
+            UpdateChecker.checkNow();
172
+        }
173
+    }
174
+
175
+    /** {@inheritDoc} */
176
+    @Override
177
+    public void configChanged(final String domain, final    String key) {
178
+        checkNow.setEnabled(IdentityManager.getGlobalConfig().getOptionBool(
179
+                "updater", "enable"));
168
     }
180
     }
169
 }
181
 }

Loading…
Cancel
Save