Browse Source

Fix URL panel.

Reading settings needed to be done from the global config to pick
the defaults, writing settings to the user config.

Change-Id: I626284ac3b5a70827d8872edbd488865b959f9c4
Fixes-Issue: CLIENT-457
Reviewed-on: http://gerrit.dmdirc.com/3209
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8
Greg Holmes 10 years ago
parent
commit
2f2b81f5cd

+ 17
- 10
src/com/dmdirc/addons/ui_swing/components/URLProtocolPanel.java View File

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.ui_swing.components;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.dialogs.url.URLSubsitutionsPanel;
26
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
26 27
 import com.dmdirc.interfaces.config.ConfigProvider;
27 28
 import com.dmdirc.ui.core.util.URLHandler;
28 29
 
@@ -53,8 +54,10 @@ public class URLProtocolPanel extends JPanel implements ActionListener,
53 54
 
54 55
     /** Serial version UID. */
55 56
     private static final long serialVersionUID = 1;
56
-    /** Config. */
57
-    private final ConfigProvider config;
57
+    /** Global config. */
58
+    private final AggregateConfigProvider globalConfig;
59
+    /** User settings. */
60
+    private final ConfigProvider userSettings;
58 61
     /** URL. */
59 62
     private final URI uri;
60 63
     /** Show insets? */
@@ -83,15 +86,19 @@ public class URLProtocolPanel extends JPanel implements ActionListener,
83 86
     /**
84 87
      * Instantiates the URLDialog.
85 88
      *
86
-     * @param config    Configuration
87
-     * @param url       URL to open once added
88
-     * @param useInsets Show insets?
89
+     * @param globalConfig Global configuration
90
+     * @param userSettings User settings
91
+     * @param url          URL to open once added
92
+     * @param useInsets    Show insets?
89 93
      */
90
-    public URLProtocolPanel(final ConfigProvider config, final URI url,
94
+    public URLProtocolPanel(final AggregateConfigProvider globalConfig,
95
+            final ConfigProvider userSettings,
96
+            final URI url,
91 97
             final boolean useInsets) {
92 98
         super();
93 99
 
94
-        this.config = config;
100
+        this.globalConfig = globalConfig;
101
+        this.userSettings = userSettings;
95 102
         uri = url;
96 103
         this.useInsets = useInsets;
97 104
 
@@ -165,7 +172,7 @@ public class URLProtocolPanel extends JPanel implements ActionListener,
165 172
 
166 173
     /** Saves the settings. */
167 174
     public void save() {
168
-        config.setOption("protocol", uri.getScheme().toLowerCase(), getSelection());
175
+        userSettings.setOption("protocol", uri.getScheme().toLowerCase(), getSelection());
169 176
     }
170 177
 
171 178
     /**
@@ -204,8 +211,8 @@ public class URLProtocolPanel extends JPanel implements ActionListener,
204 211
      * Updates the selection.
205 212
      */
206 213
     public void updateSelection() {
207
-        if (uri != null && config.hasOptionString("protocol", uri.getScheme())) {
208
-            final String option = config.getOption("protocol", uri.getScheme());
214
+        if (uri != null && globalConfig.hasOptionString("protocol", uri.getScheme())) {
215
+            final String option = globalConfig.getOption("protocol", uri.getScheme());
209 216
             switch (option) {
210 217
                 case "DMDIRC":
211 218
                     optionType.setSelected(dmdirc.getModel(), true);

+ 3
- 3
src/com/dmdirc/addons/ui_swing/dialogs/prefs/URLConfigPanel.java View File

@@ -152,7 +152,7 @@ public class URLConfigPanel extends JPanel implements
152 152
         table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
153 153
         table.getRowSorter().toggleSortOrder(0);
154 154
         details = new HashMap<>();
155
-        empty = new URLProtocolPanel(userConfig, null, true);
155
+        empty = new URLProtocolPanel(globalConfig, userConfig, null, true);
156 156
         activeComponent = empty;
157 157
         add = new JButton("Add");
158 158
         remove = new JButton("Remove");
@@ -166,7 +166,7 @@ public class URLConfigPanel extends JPanel implements
166 166
             try {
167 167
                 final URI uri = new URI(option + "://example.test.com");
168 168
                 model.addURI(uri);
169
-                details.put(uri, new URLProtocolPanel(userConfig, uri, true));
169
+                details.put(uri, new URLProtocolPanel(globalConfig, userConfig, uri, true));
170 170
             } catch (final URISyntaxException ex) {
171 171
                 //Ignore wont happen
172 172
             }
@@ -286,7 +286,7 @@ public class URLConfigPanel extends JPanel implements
286 286
                     try {
287 287
                         final URI uri = new URI(getText() + "://example.test.com");
288 288
                         model.addURI(uri);
289
-                        details.put(uri, new URLProtocolPanel(userConfig, uri, true));
289
+                        details.put(uri, new URLProtocolPanel(globalConfig, userConfig, uri, true));
290 290
                         return true;
291 291
                     } catch (final URISyntaxException ex) {
292 292
                         return false;

+ 8
- 4
src/com/dmdirc/addons/ui_swing/dialogs/url/URLDialog.java View File

@@ -22,11 +22,13 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.url;
24 24
 
25
+import com.dmdirc.ClientModule.GlobalConfig;
25 26
 import com.dmdirc.ClientModule.UserConfig;
26 27
 import com.dmdirc.addons.ui_swing.MainFrame;
27 28
 import com.dmdirc.addons.ui_swing.components.URLProtocolPanel;
28 29
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
29 30
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
31
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
30 32
 import com.dmdirc.interfaces.config.ConfigProvider;
31 33
 import com.dmdirc.ui.core.util.URLHandler;
32 34
 import com.dmdirc.util.annotations.factory.Factory;
@@ -62,12 +64,14 @@ public class URLDialog extends StandardDialog implements ActionListener {
62 64
      * Instantiates the URLDialog.
63 65
      *
64 66
      * @param url          URL to open once added
65
-     * @param config       Config
67
+     * @param global       Global Configuration
68
+     * @param config       User settings
66 69
      * @param parentWindow Parent window
67 70
      * @param urlHandler   The URL Handler to use to handle clicked links
68 71
      */
69 72
     public URLDialog(
70 73
             @Unbound final URI url,
74
+            @SuppressWarnings("qualifiers") @GlobalConfig final AggregateConfigProvider global,
71 75
             @SuppressWarnings("qualifiers") @UserConfig final ConfigProvider config,
72 76
             final MainFrame parentWindow,
73 77
             final URLHandler urlHandler) {
@@ -77,7 +81,7 @@ public class URLDialog extends StandardDialog implements ActionListener {
77 81
         this.parentWindow = parentWindow;
78 82
         this.urlHandler = urlHandler;
79 83
 
80
-        initComponents(config);
84
+        initComponents(global, config);
81 85
         layoutComponents();
82 86
         addListeners();
83 87
 
@@ -85,11 +89,11 @@ public class URLDialog extends StandardDialog implements ActionListener {
85 89
     }
86 90
 
87 91
     /** Initialises the components. */
88
-    private void initComponents(final ConfigProvider config) {
92
+    private void initComponents(final AggregateConfigProvider global, final ConfigProvider config) {
89 93
         orderButtons(new JButton(), new JButton());
90 94
         blurb = new TextLabel("Please select the appropriate action to " + "handle " + url.
91 95
                 getScheme() + ":// URLs from the list " + "below.");
92
-        panel = new URLProtocolPanel(config, url, false);
96
+        panel = new URLProtocolPanel(global, config, url, false);
93 97
     }
94 98
 
95 99
     /** Lays out the components. */

Loading…
Cancel
Save