Skip to content

Commit

Permalink
Add some more events, remove some unused methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
csmith committed Feb 2, 2016
1 parent 4b61733 commit dfb63e9
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 59 deletions.
7 changes: 5 additions & 2 deletions res/com/dmdirc/ui/messages/format.yml
Expand Up @@ -8,6 +8,8 @@ ServerCtcpEvent:
ServerCtcpReplyEvent:
format: "-!- CTCP {{type}} reply from {{user.nickname}}: {{content}}."
colour: 4
ServerConnectingEvent:
format: "Connecting to {{uri.host}}:{{uri.port}}..."
ServerDisconnectedEvent:
format: "-!- You have been disconnected from the server."
colour: 2
Expand Down Expand Up @@ -50,6 +52,9 @@ ServerNickChangeEvent:
ServerErrorEvent:
format: "ERROR: {{reason}}"
colour: 4
ServerUnknownProtocolEvent:
format: "Unknown protocol '{{protocol}}'. Unable to connect."
colour: 4

################## Server messaging events #########################################################

Expand Down Expand Up @@ -205,15 +210,13 @@ CommandOutputEvent:
# selfCTCP=4->- [%1$s] %2$s
# selfNotice=5>%1$s> %2$s
# selfMessage=>[%1$s]> %2$s
# serverConnecting=Connecting to %1$s:%2$s...
# serverDisconnectInProgress=A disconnection attempt is in progress, please wait...
# serverConnectInProgress=A connection attempt is in progress, please wait...
# rawCommand=10>>> %1$s
# unknownCommand=14Unknown command %1$s.
# commandOutput=%1$s
# actionTooLong=Warning: action too long to be sent
# tabCompletion=14Multiple possibilities: %1$s
# serverUnknownProtocol=4Unknown protocol '%1$s'. Unable to connect.
# commandUsage=7Usage: %1$s%2$s %3$s
# numeric_006=%4$s
# numeric_007=%4$s
Expand Down
18 changes: 0 additions & 18 deletions src/com/dmdirc/FrameContainer.java
Expand Up @@ -319,24 +319,6 @@ public void addLine(final String type, final Object... args) {
addLine(type, new Date(), args);
}

@Override
public void addLine(final StringBuffer type, final Date timestamp, final Object... args) {
if (type != null) {
addLine(type.toString(), timestamp, args);
}
}

@Override
public void addLine(final StringBuffer type, final Object... args) {
addLine(type, new Date(), args);
}

@Override
@Deprecated
public void addLine(final String line, final boolean timestamp) {
addLine(line, new Date());
}

@Override
public void addLine(final String line, final Date timestamp) {
for (final String myLine : line.split("\n")) {
Expand Down
9 changes: 4 additions & 5 deletions src/com/dmdirc/Server.java
Expand Up @@ -29,6 +29,7 @@
import com.dmdirc.events.ServerConnectingEvent;
import com.dmdirc.events.ServerDisconnectedEvent;
import com.dmdirc.events.ServerReconnectScheduledEvent;
import com.dmdirc.events.ServerUnknownProtocolEvent;
import com.dmdirc.interfaces.Connection;
import com.dmdirc.interfaces.GroupChatManager;
import com.dmdirc.interfaces.InviteManager;
Expand Down Expand Up @@ -69,7 +70,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentSkipListMap;
Expand Down Expand Up @@ -322,7 +322,8 @@ public void connect(final URI address, final Profile profile) {
parser = Optional.ofNullable(buildParser());

if (!parser.isPresent()) {
addLine("serverUnknownProtocol", address.getScheme());
getEventBus().publishAsync(
new ServerUnknownProtocolEvent(this, address.getScheme()));
return;
}

Expand All @@ -332,8 +333,6 @@ public void connect(final URI address, final Profile profile) {
parserLock.writeLock().unlock();
}

addLine("serverConnecting", connectAddress.getHost(), connectAddress.getPort());

myState.transition(ServerState.CONNECTING);

doCallbacks();
Expand All @@ -348,7 +347,7 @@ public void connect(final URI address, final Profile profile) {
}
}

getEventBus().publish(new ServerConnectingEvent(this));
getEventBus().publish(new ServerConnectingEvent(this, address));
}

@Override
Expand Down
16 changes: 13 additions & 3 deletions src/com/dmdirc/events/ServerConnectingEvent.java
Expand Up @@ -24,17 +24,27 @@

import com.dmdirc.interfaces.Connection;

import java.net.URI;

/**
* Fire when a server is connecting.
*/
public class ServerConnectingEvent extends ServerEvent {
public class ServerConnectingEvent extends ServerDisplayableEvent {

private final URI uri;

public ServerConnectingEvent(final Connection connection) {
public ServerConnectingEvent(final Connection connection, final URI uri) {
super(connection);
this.uri = uri;
}

public ServerConnectingEvent(final long timestamp, final Connection connection) {
public ServerConnectingEvent(final long timestamp, final Connection connection, final URI uri) {
super(timestamp, connection);
this.uri = uri;
}

public URI getUri() {
return uri;
}

}
48 changes: 48 additions & 0 deletions src/com/dmdirc/events/ServerUnknownProtocolEvent.java
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2006-2015 DMDirc Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.dmdirc.events;

import com.dmdirc.interfaces.Connection;

/**
* Raised when a server attempts to connect to an unknown protocol.
*/
public class ServerUnknownProtocolEvent extends ServerDisplayableEvent {

private final String protocol;

public ServerUnknownProtocolEvent(final long timestamp, final Connection connection, final String protocol) {
super(timestamp, connection);
this.protocol = protocol;
}

public ServerUnknownProtocolEvent(final Connection connection, final String protocol) {
super(connection);
this.protocol = protocol;
}

public String getProtocol() {
return protocol;
}

}
31 changes: 0 additions & 31 deletions src/com/dmdirc/interfaces/WindowModel.java
Expand Up @@ -161,37 +161,6 @@ public interface WindowModel {
*/
void addLine(String type, Object... args);

/**
* Adds a line to this container's window. If the window is null for some reason, the line is
* silently discarded.
*
* @param type The message type to use
* @param timestamp The timestamp to use for this line
* @param args The message's arguments
*
* @since 0.6.4
*/
void addLine(StringBuffer type, Date timestamp, Object... args);

/**
* Adds a line to this container's window. If the window is null for some reason, the line is
* silently discarded.
*
* @param type The message type to use
* @param args The message's arguments
*/
void addLine(StringBuffer type, Object... args);

/**
* Adds the specified raw line to the window, without using a formatter.
*
* @param line The line to be added
* @param timestamp Whether or not to display the timestamp for this line
* @deprecated Timestamps are always displayed.
*/
@Deprecated
void addLine(String line, boolean timestamp);

/**
* Adds the specified raw line to the window, without using a formatter, and using the specified
* timestamp. If the timestamp is <code>null</code>, no timestamp is added.
Expand Down

0 comments on commit dfb63e9

Please sign in to comment.