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
 import com.dmdirc.ui.interfaces.ServerWindow;
52
 import com.dmdirc.ui.interfaces.ServerWindow;
53
 import com.dmdirc.ui.interfaces.Window;
53
 import com.dmdirc.ui.interfaces.Window;
54
 
54
 
55
+import com.dmdirc.util.InvalidAddressException;
56
+import com.dmdirc.util.IrcAddress;
55
 import java.io.Serializable;
57
 import java.io.Serializable;
56
 import java.util.ArrayList;
58
 import java.util.ArrayList;
57
 import java.util.Hashtable;
59
 import java.util.Hashtable;
152
     // <editor-fold defaultstate="collapsed" desc="Constructors">
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
      * @param profile The profile to use
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
      * @param profile The profile to use
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
         window = Main.getUI().getServer(this);
186
         window = Main.getUI().getServer(this);
208
 
187
 
209
         ServerManager.getServerManager().registerServer(this);
188
         ServerManager.getServerManager().registerServer(this);
210
         WindowManager.addWindow(window);
189
         WindowManager.addWindow(window);
211
 
190
 
212
-        window.setTitle(server + ":" + port);
191
+        window.setTitle(url.getServer() + ":" + url.getPort());
213
 
192
 
214
         tabCompleter.addEntries(TabCompletionType.COMMAND,
193
         tabCompleter.addEntries(TabCompletionType.COMMAND,
215
                 AliasWrapper.getAliasWrapper().getAliases());
194
                 AliasWrapper.getAliasWrapper().getAliases());
237
             addRaw();
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
     // </editor-fold>
222
     // </editor-fold>

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

23
 package com.dmdirc;
23
 package com.dmdirc;
24
 
24
 
25
 import com.dmdirc.config.IdentityManager;
25
 import com.dmdirc.config.IdentityManager;
26
+import com.dmdirc.logger.ErrorLevel;
27
+import com.dmdirc.logger.Logger;
26
 import com.dmdirc.ui.interfaces.Window;
28
 import com.dmdirc.ui.interfaces.Window;
29
+import com.dmdirc.util.InvalidAddressException;
27
 
30
 
28
 import java.util.ArrayList;
31
 import java.util.ArrayList;
29
 import java.util.List;
32
 import java.util.List;
218
         }
221
         }
219
 
222
 
220
         if (connectedServer == null) {
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
         } else {
230
         } else {
227
             connectedServer.join("#DMDirc");
231
             connectedServer.join("#DMDirc");
228
         }
232
         }

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

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

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

30
 import com.dmdirc.logger.ErrorLevel;
30
 import com.dmdirc.logger.ErrorLevel;
31
 import com.dmdirc.logger.Logger;
31
 import com.dmdirc.logger.Logger;
32
 import com.dmdirc.ui.interfaces.InputWindow;
32
 import com.dmdirc.ui.interfaces.InputWindow;
33
+import com.dmdirc.util.IrcAddress;
33
 
34
 
34
 /**
35
 /**
35
  * The new server command allows users to open a new server window.
36
  * The new server command allows users to open a new server window.
102
             pass = args.getArgumentsAsString(offset);
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
         }
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
      * Processes the password part of this address.
127
      * Processes the password part of this address.
111
      *
128
      *
214
         final List<Server> servers = ServerManager.getServerManager().
231
         final List<Server> servers = ServerManager.getServerManager().
215
                 getServersByAddress(getServer());
232
                 getServersByAddress(getServer());
216
         if (servers.isEmpty()) {
233
         if (servers.isEmpty()) {
217
-            new Server(getServer(), getPort(), getPassword(), isSSL(), 
218
-                    profile, getChannels());
234
+            new Server(this, profile);
219
         } else {
235
         } else {
220
             final Server thisServer = servers.get(0);
236
             final Server thisServer = servers.get(0);
221
             for (String channel : new ArrayList<String>(getChannels())) {
237
             for (String channel : new ArrayList<String>(getChannels())) {

Loading…
Cancel
Save