Procházet zdrojové kódy

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 před 14 roky
rodič
revize
d7b0b81b5a

+ 25
- 13
src/com/dmdirc/addons/ui_swing/dialogs/prefs/UpdateConfigPanel.java Zobrazit soubor

@@ -22,13 +22,13 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.prefs;
24 24
 
25
-import com.dmdirc.Main;
26 25
 import com.dmdirc.addons.ui_swing.SwingController;
27 26
 import com.dmdirc.config.ConfigManager;
28 27
 import com.dmdirc.config.Identity;
29 28
 import com.dmdirc.config.IdentityManager;
30 29
 import com.dmdirc.config.prefs.PreferencesInterface;
31 30
 import com.dmdirc.addons.ui_swing.components.PackingTable;
31
+import com.dmdirc.interfaces.ConfigChangeListener;
32 32
 import com.dmdirc.logger.ErrorLevel;
33 33
 import com.dmdirc.logger.Logger;
34 34
 import com.dmdirc.updater.UpdateChannel;
@@ -51,7 +51,7 @@ import net.miginfocom.swing.MigLayout;
51 51
  * Updates configuration UI.
52 52
  */
53 53
 public class UpdateConfigPanel extends JPanel implements ActionListener,
54
-        PreferencesInterface {
54
+        PreferencesInterface, ConfigChangeListener {
55 55
 
56 56
     /**
57 57
      * A version number for this class. It should be changed whenever the class
@@ -81,7 +81,7 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
81 81
      */
82 82
     public UpdateConfigPanel(final SwingController controller) {
83 83
         this.controller = controller;
84
-        
84
+
85 85
         initComponents();
86 86
         addListeners();
87 87
         layoutComponents();
@@ -91,11 +91,7 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
91 91
     @Override
92 92
     public void save() {
93 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 96
         IdentityManager.getConfigIdentity().setOption("updater", "channel",
101 97
                 updateChannel.getSelectedItem().toString());
@@ -120,6 +116,8 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
120 116
         tableModel = new UpdateTableModel(UpdateChecker.getComponents());
121 117
         table = new PackingTable(tableModel, false, scrollPane);
122 118
         checkNow = new JButton("Check now");
119
+        checkNow.setEnabled(IdentityManager.getGlobalConfig().getOptionBool(
120
+                "updater", "enable"));
123 121
         updateChannel = new JComboBox(new DefaultComboBoxModel(UpdateChannel.
124 122
                 values()));
125 123
 
@@ -129,8 +127,8 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
129 127
             channel = UpdateChannel.valueOf(
130 128
                     config.getOption("updater", "channel"));
131 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 133
         updateChannel.setSelectedItem(channel);
136 134
         scrollPane.setViewportView(table);
@@ -141,14 +139,17 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
141 139
      */
142 140
     private void addListeners() {
143 141
         checkNow.addActionListener(this);
142
+        IdentityManager.getGlobalConfig().addChangeListener("updater",
143
+                "enable", this);
144
+        enable.addActionListener(this);
144 145
     }
145 146
 
146 147
     /**
147 148
      * Lays out the components.
148 149
      */
149 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 154
         add(new JLabel("Update checking:"), "split");
154 155
         add(enable, "growx");
@@ -164,6 +165,17 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
164 165
      */
165 166
     @Override
166 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
 }

Načítá se…
Zrušit
Uložit