Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jkallunki/grtot-2012
Browse files Browse the repository at this point in the history
Conflicts:
	Swirc/src/swirc/SwircController.java
  • Loading branch information
Janne Kallunki committed Mar 13, 2012
2 parents 7b13811 + e36fff4 commit 6b9d24d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Swirc/src/swirc/Channel.java
Expand Up @@ -18,8 +18,8 @@ public class Channel extends Observable {
/** /**
* Constructor * Constructor
* @param name Name of channel * @param name Name of channel
* @param name Server address * @param server Server address
* @param gw IrcGateway for the channel * @param model SwircModel of this channel
*/ */
public Channel(String name, String server, SwircModel model) { public Channel(String name, String server, SwircModel model) {
this.name = name; this.name = name;
Expand Down
16 changes: 8 additions & 8 deletions Swirc/src/swirc/ConnectDialog.java
Expand Up @@ -18,7 +18,7 @@ public class ConnectDialog extends JDialog {
private JSpinner portNumber; private JSpinner portNumber;
private JPasswordField serverPsw; private JPasswordField serverPsw;
private JCheckBox showPsw; private JCheckBox showPsw;
private JTextField nick; //private JTextField nick;
private boolean confirmed; private boolean confirmed;


/** /**
Expand Down Expand Up @@ -61,10 +61,10 @@ public ConnectDialog(JFrame parent, SwircModel model) {
inputPane.add(showPsw); inputPane.add(showPsw);


//TODO remember to remove nick from this dialog //TODO remember to remove nick from this dialog
inputPane.add(new JLabel("Nick")); // inputPane.add(new JLabel("Nick"));
nick = new JTextField(20); // nick = new JTextField(20);
nick.setText(this.model.getUserData("nick")); // nick.setText(this.model.getUserData("nick"));
inputPane.add(nick); // inputPane.add(nick);


formPane.add(inputPane); formPane.add(inputPane);


Expand Down Expand Up @@ -104,9 +104,9 @@ public String getServerAddress() {
* Method gets user's nickname. * Method gets user's nickname.
* @return User's nickname * @return User's nickname
*/ */
public String getNick() { // public String getNick() {
return nick.getText(); // return nick.getText();
} // }


/** /**
* Returns the password of the server * Returns the password of the server
Expand Down
4 changes: 4 additions & 0 deletions Swirc/src/swirc/IrcGateway.java
Expand Up @@ -21,7 +21,11 @@ public class IrcGateway extends PircBot implements Runnable {
/** /**
* Constructor. * Constructor.
* @param model SwircModel of this IrcGateway * @param model SwircModel of this IrcGateway
* @param serverAddress Server of this IrcGateway
* @param nick Nickname of the user * @param nick Nickname of the user
* @param port Port of this IrcGateway
* @param password Password of server
* @throws Exception
*/ */
public IrcGateway(SwircModel model, String serverAddress, String nick, String port, String password) throws Exception { public IrcGateway(SwircModel model, String serverAddress, String nick, String port, String password) throws Exception {
this.model = model; this.model = model;
Expand Down
4 changes: 4 additions & 0 deletions Swirc/src/swirc/ServerTab.java
Expand Up @@ -29,6 +29,10 @@ public ServerTab(String serverAddress) {
this.add(msgPane, BorderLayout.CENTER); this.add(msgPane, BorderLayout.CENTER);
} }


/**
* Adds message to messages panel.
* @param msg message to be added
*/
public void addMsg(String msg) { public void addMsg(String msg) {
this.messages.setText(this.messages.getText() + "\n" + msg); this.messages.setText(this.messages.getText() + "\n" + msg);
} }
Expand Down
18 changes: 14 additions & 4 deletions Swirc/src/swirc/SwircConfs.java
Expand Up @@ -42,8 +42,13 @@ private void initServerProperties() {
input.close(); input.close();
} }
catch(FileNotFoundException e) { catch(FileNotFoundException e) {
System.out.println(e.toString()); try {
File makefile = new File("src/properties/usedServers"); FileOutputStream out = new FileOutputStream("src/properties/usedServers");
out.close();
}
catch(Exception ex) {

}
} }
catch(Exception e) { catch(Exception e) {
System.out.println(e.toString()); System.out.println(e.toString());
Expand All @@ -57,8 +62,13 @@ private void initUserData() {
dataIn.close(); dataIn.close();
} }
catch(FileNotFoundException e) { catch(FileNotFoundException e) {
System.out.println(e.toString()); try {
File makefile = new File("src/properties/userData"); FileOutputStream out = new FileOutputStream("src/properties/userData");
out.close();
}
catch(Exception ex) {

}
} }
catch(Exception e) { catch(Exception e) {
//TODO properties not found //TODO properties not found
Expand Down
6 changes: 3 additions & 3 deletions Swirc/src/swirc/SwircController.java
Expand Up @@ -33,12 +33,12 @@ public void actionPerformed(ActionEvent e) {
if(code.equals("connectServer")) { if(code.equals("connectServer")) {
HashMap<String,String> con = view.connectPrompt(); HashMap<String,String> con = view.connectPrompt();
if(con != null) { if(con != null) {
if(!con.get("serverAddress").equals("") && !con.get("nick").equals("")) { if(!con.get("serverAddress").equals("")) {
this.view.addServerView(con.get("serverAddress")); this.view.addServerView(con.get("serverAddress"));
this.model.connect(con.get("serverAddress"), con.get("nick"), con.get("port"), con.get("pasword")); this.model.connect(con.get("serverAddress"), con.get("port"), con.get("password"));
} }
else { else {
view.showWarning("Your server address or nick was empty!"); view.showWarning("Your server address was empty!");
} }
} }
} }
Expand Down
22 changes: 17 additions & 5 deletions Swirc/src/swirc/SwircModel.java
Expand Up @@ -52,10 +52,10 @@ public void sendMsg(String msg, String channel) {
* @param port Server's port * @param port Server's port
* @param password Server's password * @param password Server's password
*/ */
public void connect(String serverAddress, String nick, String port, String password) { public void connect(String serverAddress, String port, String password) {
IrcGateway igw; IrcGateway igw;
try { try {
igw = new IrcGateway(this, serverAddress, nick, port, password); igw = new IrcGateway(this, serverAddress, confs.getUserData("nick"), port, password);
new Thread(igw).start(); new Thread(igw).start();
connections.add(igw); connections.add(igw);
if(!confs.findServer(serverAddress)) { if(!confs.findServer(serverAddress)) {
Expand Down Expand Up @@ -173,8 +173,7 @@ public String[] getConnectedChannels() {


/** /**
* Sets user data to confs * Sets user data to confs
* @param key Key to user's data * @param userData User's data
* @param value User's data
*/ */
public void setUserData(HashMap<String, String> userData) { public void setUserData(HashMap<String, String> userData) {
HashMap<String, String> data = new HashMap<String, String>(); HashMap<String, String> data = new HashMap<String, String>();
Expand Down Expand Up @@ -241,7 +240,7 @@ public IrcGateway getGateway(String serverName) {
* Kicks user with given nick out of the given channel in given server * Kicks user with given nick out of the given channel in given server
* @param server Server of the wanted channel * @param server Server of the wanted channel
* @param channel Channel from where user will be kicked * @param channel Channel from where user will be kicked
* @param nick U * @param nick User's nick
*/ */
public void kick(String server, String channel, String nick) { public void kick(String server, String channel, String nick) {
// Get the correct connection // Get the correct connection
Expand All @@ -256,6 +255,12 @@ public void kick(String server, String channel, String nick) {
} }
} }


/**
* Bans user with given nick out of the given channel in given server
* @param server Server of the wanted channel
* @param channel Channel from where user will be kicked
* @param nick User's nick
*/
public void ban(String server, String channel, String nick) { public void ban(String server, String channel, String nick) {
// Get the correct connection // Get the correct connection
IrcGateway gw = this.getGateway(server); IrcGateway gw = this.getGateway(server);
Expand Down Expand Up @@ -330,11 +335,18 @@ public SwircConfs getConfs() {
return confs; return confs;
} }


/**
* Notifies observers that can't connect to server
*/
public void cantConnect() { public void cantConnect() {
this.setChanged(); this.setChanged();
this.notifyObservers("cant connect"); this.notifyObservers("cant connect");
} }


/**
* Notifies observers that has connected to server
* @param serverAddress server where is connected
*/
public void connectedServer(String serverAddress) { public void connectedServer(String serverAddress) {
this.setChanged(); this.setChanged();
this.notifyObservers("ConnectedServer:" + serverAddress); this.notifyObservers("ConnectedServer:" + serverAddress);
Expand Down
2 changes: 1 addition & 1 deletion Swirc/src/swirc/SwircView.java
Expand Up @@ -270,7 +270,7 @@ public HashMap<String,String> connectPrompt() {
HashMap<String,String> connectDetails = new HashMap<String,String>(); HashMap<String,String> connectDetails = new HashMap<String,String>();
if(cd.isConfirmed()) { if(cd.isConfirmed()) {
connectDetails.put("serverAddress", cd.getServerAddress()); connectDetails.put("serverAddress", cd.getServerAddress());
connectDetails.put("nick", cd.getNick()); //connectDetails.put("nick", cd.getNick());
connectDetails.put("port", cd.getPort()); connectDetails.put("port", cd.getPort());
connectDetails.put("password", cd.getPassword()); connectDetails.put("password", cd.getPassword());
return connectDetails; return connectDetails;
Expand Down

0 comments on commit 6b9d24d

Please sign in to comment.