Browse Source

Servers now use IrcAddresses in constructors. Issue 2736.

tags/0.6.3m2a1
Chris Smith 15 years ago
parent
commit
5aec5dfc9f

+ 21
- 42
src/com/dmdirc/Server.java View File

@@ -52,6 +52,8 @@ import com.dmdirc.ui.interfaces.InputWindow;
52 52
 import com.dmdirc.ui.interfaces.ServerWindow;
53 53
 import com.dmdirc.ui.interfaces.Window;
54 54
 
55
+import com.dmdirc.util.InvalidAddressException;
56
+import com.dmdirc.util.IrcAddress;
55 57
 import java.io.Serializable;
56 58
 import java.util.ArrayList;
57 59
 import java.util.Hashtable;
@@ -152,64 +154,41 @@ public class Server extends WritableFrameContainer implements Serializable {
152 154
     // <editor-fold defaultstate="collapsed" desc="Constructors">
153 155
 
154 156
     /**
155
-     * Creates a new instance of Server. Does not auto-join any channels, and
156
-     * uses a default {@link ParserFactory}.
157
-     *
158
-     * @param server The hostname/ip of the server to connect to
159
-     * @param port The port to connect to
160
-     * @param password The server password
161
-     * @param ssl Whether to use SSL or not
162
-     * @param profile The profile to use
163
-     */
164
-    public Server(final String server, final int port, final String password,
165
-            final boolean ssl, final Identity profile) {
166
-        this(server, port, password, ssl, profile, new ArrayList<String>());
167
-    }
168
-
169
-    /**
170
-     * Creates a new instance of Server. Uses a default {@link ParserFactory}.
157
+     * Creates a new instance of Server.
171 158
      *
172
-     * @param server The hostname/ip of the server to connect to
173
-     * @param port The port to connect to
174
-     * @param password The server password
175
-     * @param ssl Whether to use SSL or not
159
+     * @since 0.6.3m2
160
+     * @param url The address of the server to connect to
176 161
      * @param profile The profile to use
177
-     * @param autochannels A list of channels to auto-join when we connect
162
+     * @throws InvalidAddressException If the specified URL is not valid
178 163
      */
179
-    public Server(final String server, final int port, final String password,
180
-            final boolean ssl, final Identity profile, final List<String> autochannels) {
181
-        this(server, port, password, ssl, profile, autochannels, new ParserFactory());
164
+    public Server(final String url, final Identity profile) throws InvalidAddressException {
165
+        this(new IrcAddress(url), profile);
182 166
     }
183 167
 
184 168
     /**
185
-     * Creates a new instance of Server.
169
+     * Creates a new server which will connect to the specified URL with
170
+     * the specified profile.
186 171
      *
187
-     * @since 0.6
188
-     * @param server The hostname/ip of the server to connect to
189
-     * @param port The port to connect to
190
-     * @param password The server password
191
-     * @param ssl Whether to use SSL or not
172
+     * @since 0.6.3m2
173
+     * @param url The address of the server to connect to
192 174
      * @param profile The profile to use
193
-     * @param autochannels A list of channels to auto-join when we connect
194
-     * @param factory The {@link ParserFactory} to use to create parsers
195 175
      */
196
-    public Server(final String server, final int port, final String password,
197
-            final boolean ssl, final Identity profile,
198
-            final List<String> autochannels, final ParserFactory factory) {
199
-        super("server-disconnected", server, new ConfigManager("", "", server));
176
+    public Server(final IrcAddress url, final Identity profile) {
177
+        super("server-disconnected", url.getServer(),
178
+                new ConfigManager("", "", url.getServer()));
200 179
 
201
-        serverInfo = new ServerInfo(server, port, password);
202
-        serverInfo.setSSL(ssl);
180
+        serverInfo = new ServerInfo(url.getServer(), url.getPort(), url.getPassword());
181
+        serverInfo.setSSL(url.isSSL());
203 182
 
204
-        this.autochannels = autochannels;
205
-        this.parserFactory = factory;
183
+        this.autochannels = url.getChannels();
184
+        this.parserFactory = new ParserFactory();
206 185
 
207 186
         window = Main.getUI().getServer(this);
208 187
 
209 188
         ServerManager.getServerManager().registerServer(this);
210 189
         WindowManager.addWindow(window);
211 190
 
212
-        window.setTitle(server + ":" + port);
191
+        window.setTitle(url.getServer() + ":" + url.getPort());
213 192
 
214 193
         tabCompleter.addEntries(TabCompletionType.COMMAND,
215 194
                 AliasWrapper.getAliasWrapper().getAliases());
@@ -237,7 +216,7 @@ public class Server extends WritableFrameContainer implements Serializable {
237 216
             addRaw();
238 217
         }
239 218
 
240
-        connect(server, port, password, ssl, profile);
219
+        connect(url.getServer(), url.getPort(), url.getPassword(), url.isSSL(), profile);
241 220
     }
242 221
 
243 222
     // </editor-fold>

+ 9
- 5
src/com/dmdirc/ServerManager.java View File

@@ -23,7 +23,10 @@
23 23
 package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.config.IdentityManager;
26
+import com.dmdirc.logger.ErrorLevel;
27
+import com.dmdirc.logger.Logger;
26 28
 import com.dmdirc.ui.interfaces.Window;
29
+import com.dmdirc.util.InvalidAddressException;
27 30
 
28 31
 import java.util.ArrayList;
29 32
 import java.util.List;
@@ -218,11 +221,12 @@ public final class ServerManager {
218 221
         }
219 222
 
220 223
         if (connectedServer == null) {
221
-            final List<String> channels = new ArrayList<String>();
222
-                channels.add("#DMDirc");
223
-
224
-                new Server("irc.quakenet.org", 6667, "", false,
225
-                        IdentityManager.getProfiles().get(0), channels);
224
+            try {
225
+                new Server("irc://irc.quakenet.org/DMDirc",
226
+                        IdentityManager.getProfiles().get(0));
227
+            } catch (InvalidAddressException ex) {
228
+                Logger.appError(ErrorLevel.MEDIUM, "Unable to construct new server", ex);
229
+            }
226 230
         } else {
227 231
             connectedServer.join("#DMDirc");
228 232
         }

+ 3
- 2
src/com/dmdirc/addons/ui_swing/dialogs/NewServerDialog.java View File

@@ -33,6 +33,7 @@ import com.dmdirc.addons.ui_swing.components.LoggingSwingWorker;
33 33
 import com.dmdirc.addons.ui_swing.components.validating.ValidatingJTextField;
34 34
 import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
35 35
 
36
+import com.dmdirc.util.IrcAddress;
36 37
 import java.awt.Dialog.ModalityType;
37 38
 import java.awt.Insets;
38 39
 import java.awt.event.ActionEvent;
@@ -280,7 +281,7 @@ public final class NewServerDialog extends StandardDialog implements ActionListe
280 281
 
281 282
                 @Override
282 283
                 protected Object doInBackground() throws Exception {
283
-                    new Server(host, port, pass, sslCheck.isSelected(), profile);
284
+                    new Server(new IrcAddress(host, port, pass, sslCheck.isSelected()), profile);
284 285
                     return null;
285 286
                 }
286 287
             }.execute();
@@ -294,7 +295,7 @@ public final class NewServerDialog extends StandardDialog implements ActionListe
294 295
                 @Override
295 296
                 protected Object doInBackground() throws Exception {
296 297
                     if (server == null) {
297
-                        new Server(host, port, pass, sslCheck.isSelected(),
298
+                        new Server(new IrcAddress(host, port, pass, sslCheck.isSelected()),
298 299
                             profile);
299 300
                     } else {
300 301
                         server.connect(host, port, pass, sslCheck.isSelected(),

+ 2
- 1
src/com/dmdirc/commandparser/commands/global/NewServer.java View File

@@ -30,6 +30,7 @@ import com.dmdirc.config.IdentityManager;
30 30
 import com.dmdirc.logger.ErrorLevel;
31 31
 import com.dmdirc.logger.Logger;
32 32
 import com.dmdirc.ui.interfaces.InputWindow;
33
+import com.dmdirc.util.IrcAddress;
33 34
 
34 35
 /**
35 36
  * The new server command allows users to open a new server window.
@@ -102,7 +103,7 @@ public final class NewServer extends GlobalCommand {
102 103
             pass = args.getArgumentsAsString(offset);
103 104
         }
104 105
         
105
-        new Server(host, port, pass, ssl, IdentityManager.getProfiles().get(0));
106
+        new Server(new IrcAddress(host, port, pass, ssl), IdentityManager.getProfiles().get(0));
106 107
     }
107 108
     
108 109
     

+ 18
- 2
src/com/dmdirc/util/IrcAddress.java View File

@@ -106,6 +106,23 @@ public class IrcAddress implements Serializable {
106 106
         }
107 107
     }
108 108
 
109
+    /**
110
+     * Constructs a new IrcAddress object representing the specified details.
111
+     *
112
+     * @param host The hostname or IP of the server
113
+     * @param port The port of the server
114
+     * @param pass The password to use for the server
115
+     * @param ssl Whether or not to use SSL
116
+     * @since 0.6.3m2
117
+     */
118
+    public IrcAddress(final String host, final int port, final String pass,
119
+            final boolean ssl) {
120
+        this.server = host;
121
+        this.port = port;
122
+        this.pass = pass;
123
+        this.usesSSL = ssl;
124
+    }
125
+
109 126
     /**
110 127
      * Processes the password part of this address.
111 128
      *
@@ -214,8 +231,7 @@ public class IrcAddress implements Serializable {
214 231
         final List<Server> servers = ServerManager.getServerManager().
215 232
                 getServersByAddress(getServer());
216 233
         if (servers.isEmpty()) {
217
-            new Server(getServer(), getPort(), getPassword(), isSSL(), 
218
-                    profile, getChannels());
234
+            new Server(this, profile);
219 235
         } else {
220 236
             final Server thisServer = servers.get(0);
221 237
             for (String channel : new ArrayList<String>(getChannels())) {

Loading…
Cancel
Save