package org.javwer;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.*;
import org.jivesoftware.smackx.muc.InvitationListener;
import org.jivesoftware.smackx.muc.MultiUserChat;
public class JavwerManager {
private Display display;
private Shell shell;
private ProgressBar progress;
private Label statusLabel;
private JChat chat;
private JRoster roster;
private JFileTransferManager fileTransferManager;
private SettingsManager settings;
private GraphicsManager graphics;
private StatusManager status;
private StatusLogManager statusLogManager;
private NotificationManager notification;
private XMPPConnection connection;
private String javwerHomeDir;
private boolean quit;
JavwerManager() {
quit = false;
display = new Display();
shell = new Shell( SWT.ON_TOP );
createGUI();
progress.setSelection( progress.getSelection() + 1 );
File dir = new File( System.getProperty( "user.home" ) + "/.javwer" );
if( !dir.exists() )
dir.mkdirs();
javwerHomeDir = dir.getAbsolutePath();
startSettingsManager();
startGraphicsManager();
startStatusManager();
startStatusLogManager();
startNotificationManager();
createAccountDialog();
shell.dispose();
if ( !quit ) {
roster = new JRoster( this );
fileTransferManager = new JFileTransferManager( this );
while ( !roster.getShell().isDisposed() ) {
if ( !display.readAndDispatch() ) {
display.sleep();
}
}
}
statusLogManager.close();
}
public static void main( String[] args ) {
new JavwerManager();
}
public XMPPConnection getConnection() {
return connection;
}
public Display getDisplay() {
return display;
}
public GraphicsManager getGraphicsManager() {
return graphics;
}
public SettingsManager getSettingsManager() {
return settings;
}
public StatusManager getStatusManager() {
return status;
}
public StatusLogManager getStatusLogManager() {
return statusLogManager;
}
public JFileTransferManager getFileTransferManager() {
return fileTransferManager;
}
public JChat getJChat() {
final JavwerManager man = this;
if ( chat == null ) {
display.syncExec( new Runnable() {
public void run() {
chat = new JChat( man );
chat.open();
}
});
}
return chat;
}
public NotificationManager getNotificationManager() {
return notification;
}
public JRoster getJRoster() {
return roster;
}
private void startSettingsManager() {
statusLabel.setText( "Loading Settings..." );
statusLabel.pack();
settings = new SettingsManager( javwerHomeDir + "/settings", System.getProperty( "user.dir") + "/trunk/Javwer/data/settings" );
progress.setSelection( progress.getSelection() + 1 );
}
private void startGraphicsManager() {
statusLabel.setText( "Loading Graphics..." );
statusLabel.pack();
graphics = new GraphicsManager( this );
progress.setSelection( progress.getSelection() + 1 );
}
private void startStatusManager() {
statusLabel.setText( "Loading Statusmessages..." );
statusLabel.pack();
status = new StatusManager( this );
progress.setSelection( progress.getSelection() + 1 );
}
private void startStatusLogManager() {
statusLabel.setText( "Loading StatusLogManager..." );
statusLabel.pack();
statusLogManager = new StatusLogManager( this );
progress.setSelection( progress.getSelection() + 1 );
}
private void startNotificationManager() {
statusLabel.setText( "Loading Notificationmanager..." );
statusLabel.pack();
notification = new NotificationManager( this );
progress.setSelection( progress.getSelection() + 1 );
}
private void connect() {
try {
connection = new XMPPConnection( settings.getStringSetting( "server" ), settings.getIntSetting( "port" ) );
// Messages
connection.addPacketListener(
new PacketListener() {
public void processPacket( final Packet p ) {
if ( ((Message) p).getBody() != null ) {
getJChat().getMessage( ((Message) p).getFrom(), (Message) p );
}
display.asyncExec( new Runnable() {
public void run() {
if ( display.getActiveShell() != null && chat != null && display.getActiveShell().equals( chat.getShell() ) )
;//do nothing
else {
notification.addNotification( (Message) p );
}
}
});
}
},
new PacketTypeFilter( Message.class ) {}
);
// Subscription-Stuff
connection.addPacketListener(
new PacketListener() {
public void processPacket( final Packet p ) {
Presence.Type type = ((Presence) p).getType();
final String name = ((Presence) p).getFrom();
if( type == Presence.Type.SUBSCRIBE ) {
display.syncExec( new Runnable() {
public void run() {
gotSubscriptionRequest( name );
}
});
}
else if( type == Presence.Type.SUBSCRIBED );
//System.out.println( "subsED" );
}
},
new PacketTypeFilter( Presence.class ) {}
);
//MultiUserChat
MultiUserChat.addInvitationListener( connection, new InvitationListener() {
public void invitationReceived( final XMPPConnection conn, final String room, final String invitor, final String reason, final String password, final Message message ) {
display.syncExec( new Runnable() {
public void run() {
gotInvitation( conn, room, invitor, reason, password, message );
}
});
}
});
}
catch( XMPPException ex) {
new Error( display, "Unable to connect", "Sorry but an error occured while trying to connect.\nPlease check your connection settings", ex );
createAccountDialog();
}
}
private void login() {
statusLabel.setText( "Logging in..." );
statusLabel.pack();
try {
connection.login( settings.getStringSetting( "name" ), settings.getStringSetting( "password" ), "javwer" );
if ( !settings.getBooleanSetting( "savepassword" ) )
settings.setSetting( "password", "" );
} catch ( XMPPException e ) {
statusLabel.setText( "Error occured: " + e );
new Error( display, "Unable to login", "Sorry but an error occured while trying to login.\nPlease check your login settings", e );
connection.close();
createAccountDialog();
}
progress.setSelection( progress.getSelection() + 1 );
}
private void createGUI() {
RowLayout layout = new RowLayout( SWT.VERTICAL );
shell.setLayout( layout );
Label label = new Label(shell, SWT.NONE);
label.setText( "Javwer" );
progress = new ProgressBar( shell, SWT.NONE );
progress.setMaximum( 7 );
statusLabel = new Label( shell, SWT.NONE );
statusLabel.setText( "Loading..." );
shell.pack();
Rectangle splashRect = shell.getBounds();
Rectangle displayRect = display.getBounds();
int x = (displayRect.width - splashRect.width) / 2;
int y = (displayRect.height - splashRect.height) / 2;
shell.setLocation(x, y);
shell.open();
}
private void createAccountDialog() {
if( settings.getBooleanSetting( "autologin") ) {
connect();
login();
return;
}
final Shell dialogShell;
final Display display;
final Text ressourceText, serverText, nameText, passwordText;
final Label ressourceLabel, serverLabel;
final SettingsManager settings;
final Button okButton, cancelButton, autoLoginCheck, savePasswordCheck, registerButton;
settings = getSettingsManager();
display = getDisplay();
dialogShell = new Shell ( display, SWT.DIALOG_TRIM | SWT.SHADOW_IN );
dialogShell.setText( "Connection-Settings");
dialogShell.setLayout( new FormLayout() );
final int border = 10;
FormData data;
FormAttachment firstLine = new FormAttachment( 0, border );
// Username
data = new FormData ();
data.left = new FormAttachment( 0, border );
data.top = firstLine;
data.width = 100;
nameText = new Text( dialogShell, SWT.NONE );
nameText.setLayoutData( data );
nameText.setOrientation( SWT.RIGHT );
nameText.setText( settings.getStringSetting( "name" ) );
// Server
data = new FormData ();
data.left = new FormAttachment( nameText );
data.top = firstLine;
serverLabel = new Label( dialogShell, SWT.SHADOW_IN );
serverLabel.setLayoutData( data );
serverLabel.setText( "@" );
data = new FormData();
data.left = new FormAttachment( serverLabel, 0 );
data.top = firstLine;
data.width = 150;
serverText = new Text( dialogShell, SWT.NONE );
serverText.setLayoutData( data );
serverText.setText( settings.getStringSetting( "server" ) );
// Ressource
data = new FormData ();
data.left = new FormAttachment( serverText, 3 );
data.top = firstLine;
ressourceLabel = new Label( dialogShell, SWT.SHADOW_IN );
ressourceLabel.setLayoutData( data );
ressourceLabel.setText( "/" );
data = new FormData();
data.left = new FormAttachment( ressourceLabel, 3 );
data.top = firstLine;
data.width = 100;
ressourceText = new Text( dialogShell, SWT.NONE );
ressourceText.setLayoutData( data );
ressourceText.setText( settings.getStringSetting( "ressource" ) );
FormAttachment secondLine = new FormAttachment( nameText, border );
// Password
data = new FormData();
data.left = new FormAttachment( 0, border );
data.top = secondLine;
data.width = 100;
passwordText = new Text( dialogShell, SWT.NONE );
passwordText.setLayoutData( data );
passwordText.setEchoChar( '*' );
passwordText.setText( settings.getStringSetting( "password" ) );
// Javwer-Label
data = new FormData();
data.left = new FormAttachment( serverLabel, 0 );
data.top = secondLine;
data.width = ((FormData)serverText.getLayoutData()).width;
savePasswordCheck = new Button( dialogShell, SWT.CHECK );
savePasswordCheck.setLayoutData( data );
savePasswordCheck.setText( "Save password" );
savePasswordCheck.setSelection( settings.getBooleanSetting( "savepassword" ) );
// Auto-Login
data = new FormData();
data.left = new FormAttachment( ressourceLabel, 3 );
data.top = secondLine;
autoLoginCheck = new Button( dialogShell, SWT.CHECK );
autoLoginCheck.setLayoutData( data );
autoLoginCheck.setText( "Autologin" );
autoLoginCheck.setSelection( settings.getBooleanSetting( "autologin" ) );
// OK-Button
data = new FormData();
data.width = 75;
data.left = new FormAttachment( 50, -(int)(0.5*(3*data.width+2*border)) );
data.top = new FormAttachment( passwordText, border );
//data.height = 20;
okButton = new Button( dialogShell, SWT.PUSH );
okButton.setLayoutData( data );
okButton.setText( "&OK" );
okButton.setAlignment( SWT.CENTER );
okButton.addSelectionListener( new SelectionAdapter () {
public void widgetSelected( SelectionEvent e ) {
settings.setSetting( "name", nameText.getText() );
settings.setSetting( "password", passwordText.getText() );
settings.setSetting( "ressource", ressourceText.getText() );
settings.setSetting( "server", serverText.getText() );
settings.setSetting( "savepassword", savePasswordCheck.getSelection() );
settings.setSetting( "autologin", autoLoginCheck.getSelection() );
dialogShell.close();
dialogShell.dispose();
connect();
login();
}
});
// Register-Button
data = new FormData();
data.width = 75;
data.left = new FormAttachment( okButton, border );
data.top = new FormAttachment( passwordText, border );
registerButton = new Button( dialogShell, SWT.PUSH );
registerButton.setLayoutData( data );
registerButton.setText( "&Register" );
registerButton.setAlignment( SWT.CENTER );
final JavwerManager man = this;
registerButton.addSelectionListener( new SelectionAdapter () {
public void widgetSelected( SelectionEvent e ) {
settings.setSetting( "server", serverText.getText() );
connect();
ServiceDiscovery.showRegisterDialog( man, serverText.getText() );
}
});
// Cancel-Button
data = new FormData();
data.width = 75;
data.left = new FormAttachment( registerButton, border );
data.top = new FormAttachment( passwordText, border );
// data.height = 20;
cancelButton = new Button( dialogShell, SWT.PUSH );
cancelButton.setLayoutData( data );
cancelButton.setText( "&Cancel" );
cancelButton.setAlignment( SWT.CENTER );
cancelButton.addSelectionListener( new SelectionAdapter () {
public void widgetSelected( SelectionEvent e ) {
quit = true;
dialogShell.close();
dialogShell.dispose();
}
});
// MoreShell
/*
moreButton = new Button( dialogShell, SWT.TOGGLE );
data = new FormData();
data.width = 75;
data.left = new FormAttachment( okButton, border );
data.top = new FormAttachment( passwordText, border );
moreButton.setLayoutData( data );
moreButton.setText( "&Register" );
final JavwerManager man = this;
moreButton.addSelectionListener( new SelectionAdapter () {
public void widgetSelected( SelectionEvent e ) {
if( moreButton.getSelection() ) {
final Composite moreShell = new Composite( dialogShell, SWT.SHELL_TRIM );
moreShell.setLayout( new GridLayout( 2, true ) );
FormData data2 = new FormData();
data2.left = new FormAttachment( dialogShell, 0 );
data2.top = new FormAttachment( moreButton, border );
data2.width = 100;
moreShell.setLayoutData( data2 );
final Text registerText = new Text( moreShell, SWT.SINGLE );
final Button registerButton = new Button( moreShell, SWT.PUSH );
registerButton.setText( "&Register" );
registerButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent ev ) {
ServiceDiscovery.showRegisterDialog( man, serverText.getText() );
}
});
moreShell.pack();
dialogShell.pack();
dialogShell.setSize( dialogShell.getSize().x+border, dialogShell.getSize().y+border );
final SelectionAdapter ad = new SelectionAdapter() {
public void widgetSelected( SelectionEvent ev ) {
if( moreButton.getSelection() )
return;
moreShell.dispose();
moreButton.removeSelectionListener( this );
dialogShell.pack();
dialogShell.setSize( dialogShell.getSize().x+border, dialogShell.getSize().y+border );
}
};
moreButton.addSelectionListener( ad );
}
System.out.println( moreButton.getSelection() );
}
});
*/
if( savePasswordCheck.getSelection() )
okButton.setFocus();
dialogShell.pack( );
dialogShell.setSize( dialogShell.getSize().x+border, dialogShell.getSize().y+border );
dialogShell.open();
while ( !dialogShell.isDisposed() ) {
if( !display.readAndDispatch() )
display.sleep();
}
}
public static Form displayForm( Display display, final Form form ) {
final Form answerForm = form.createAnswerForm();
final Shell dialogShell = new Shell( display );
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.makeColumnsEqualWidth = true;
dialogShell.setText( form.getTitle() );
dialogShell.setLayout( layout );
ScrolledComposite scrolledComposite = new ScrolledComposite( dialogShell, SWT.V_SCROLL );
GridData data = new GridData();
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
data.horizontalSpan = layout.numColumns;
scrolledComposite.setLayoutData( data );
Composite composite = new Composite( scrolledComposite, SWT.NONE );
scrolledComposite.setContent( composite );
GridLayout layout2 = new GridLayout();
layout2.numColumns = 2;
composite.setLayout( layout2 );
Label instructionsLabel = new Label( composite, SWT.WRAP );
if( form.getInstructions() != null )
instructionsLabel.setText( form.getInstructions() );
data = new GridData();
data.horizontalSpan = 2;
data.horizontalAlignment = GridData.END;
instructionsLabel.setLayoutData( data );
int length = 0;
for( Iterator i = form.getFields(); i.hasNext(); i.next())
length++;
final Widget[] widgets = new Widget[ length ];
int c = 0;
for( Iterator i = form.getFields(); i.hasNext(); ) {
org.jivesoftware.smackx.FormField field = (org.jivesoftware.smackx.FormField) i.next();
// System.out.println("#" + c + ": " + field.getVariable());
if( !field.getType().equals( FormField.TYPE_HIDDEN ) && !field.getType().equals( FormField.TYPE_FIXED ) ) {
Label label = new Label( composite, SWT.WRAP );
if( field.getLabel() != null ) {
label.setText( field.getLabel() );
if( field.getDescription() != null )
label.setToolTipText( field.getDescription() );
}
}
if( field.getType().equals( FormField.TYPE_TEXT_SINGLE ) ) {
Text text = new Text( composite, SWT.SINGLE );
text.setLayoutData( new GridData( GridData.FILL_BOTH ) );
widgets[ c ] = (Widget) text;
if( field.getValues().hasNext() )
text.setText( (String) field.getValues().next() );
}
else if( field.getType().equals( FormField.TYPE_TEXT_PRIVATE ) ) {
Text text = new Text( composite, SWT.PASSWORD );
text.setLayoutData( new GridData( GridData.FILL_BOTH ) );
widgets[ c ] = (Widget) text;
if( field.getValues().hasNext() )
text.setText( (String) field.getValues().next() );
}
else if( field.getType().equals( FormField.TYPE_TEXT_MULTI ) ) {
Text text = new Text( composite, SWT.MULTI );
text.setLayoutData( new GridData( GridData.FILL_BOTH ) );
widgets[ c ] = (Widget) text;
if( field.getValues().hasNext() )
text.setText( (String) field.getValues().next() );
}
else if( field.getType().equals( FormField.TYPE_LIST_SINGLE ) ) {
org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List( composite, SWT.SINGLE );
System.out.println( "Type: " + field.getOptions().next().getClass().toString() );
for( Iterator v = field.getOptions(); v.hasNext(); )
list.add( ((FormField.Option) v.next()).getValue() );
widgets[ c ] = (Widget) list;
}
else if( field.getType().equals( FormField.TYPE_LIST_MULTI ) ) {
org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List( composite, SWT.MULTI );
for( Iterator v = field.getOptions(); v.hasNext(); )
list.add( ((FormField.Option) v.next()).getValue() );
widgets[ c ] = (Widget) list;
}
else if( field.getType().equals( FormField.TYPE_BOOLEAN ) ) {
Button button = new Button( composite, SWT.CHECK );
button.setSelection( false );
widgets[ c ] = (Widget) button;
}
else if( field.getType().equals( FormField.TYPE_FIXED ) ) {
// c--;
Label label = new Label( composite, SWT.NONE );
if( field.getValues().hasNext() )
label.setText( (String) field.getValues().next() );
data = new GridData();
data.horizontalSpan = 2;
data.horizontalAlignment = GridData.END;
label.setLayoutData( data );
}
else if( field.getType().equals( FormField.TYPE_HIDDEN ) ) {
// c--;
}
else if( field.getType().equals( FormField.TYPE_JID_SINGLE ) ) {
Text text = new Text( composite, SWT.SINGLE );
widgets[ c ] = (Widget) text;
if( field.getValues().hasNext() )
text.setText( (String) field.getValues().next() );
}
else if( field.getType().equals( FormField.TYPE_JID_MULTI ) ) {
Text text = new Text( composite, SWT.MULTI );
widgets[ c ] = (Widget) text;
if( field.getValues().hasNext() )
text.setText( (String) field.getValues().next() );
}
if( field.getVariable() != null )
c++;
}
composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
Button submitButton = new Button( dialogShell, SWT.PUSH );
submitButton.setText( "&Submit" );
submitButton.setLayoutData( new GridData( GridData.CENTER ) );
submitButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent e ) {
int c = 0;
for( Iterator i = answerForm.getFields(); i.hasNext(); c++ ) {
FormField field = (FormField) i.next();
// System.out.println("*" + c + ": " + field.getVariable());
//System.out.println( field.getVariable() );
if( field.getType().equals( FormField.TYPE_TEXT_SINGLE ) ) {
answerForm.setAnswer( field.getVariable(), ((Text) widgets[ c ]).getText() );
}
else if( field.getType().equals( FormField.TYPE_TEXT_PRIVATE ) ) {
System.out.println(((Text) widgets[ c ]).getText());
answerForm.setAnswer( field.getVariable(), ((Text) widgets[ c ]).getText() );
}
else if( field.getType().equals( FormField.TYPE_TEXT_MULTI ) ) {
answerForm.setAnswer( field.getVariable(), ((Text) widgets[ c ]).getText() );
}
else if( field.getType().equals( FormField.TYPE_LIST_SINGLE ) ) {
//((FormField.Option) field.getOptions().next()).
java.util.List<String> list = new ArrayList<String>();
for( String string : ((org.eclipse.swt.widgets.List) widgets[ c ]).getSelection() )
list.add( string );
answerForm.setAnswer( field.getVariable(), list );
}
else if( field.getType().equals( FormField.TYPE_LIST_MULTI ) ) {
java.util.List<String> list = new ArrayList<String>();
for( String string : ((org.eclipse.swt.widgets.List) widgets[ c ]).getSelection() )
list.add( string );
answerForm.setAnswer( field.getVariable(), list );
}
else if( field.getType().equals( FormField.TYPE_BOOLEAN ) ) {
// if( ((Button) widgets[ c ]) == null )
// answerForm.setAnswer( field.getVariable(), false );
// else
answerForm.setAnswer( field.getVariable(), ((Button) widgets[ c ]).getSelection() );
}
else if( field.getType().equals( FormField.TYPE_FIXED ) ) {
//System.out.println("fix");
}
else if( field.getType().equals( FormField.TYPE_HIDDEN ) ) {
// System.out.println("hidden");
}
else if( field.getType().equals( FormField.TYPE_JID_SINGLE ) ) {
answerForm.setAnswer( field.getVariable(), ((Text) widgets[ c ]).getText() );
}
else if( field.getType().equals( FormField.TYPE_JID_MULTI ) ) {
java.util.List<String> list = new ArrayList<String>();
list.add( ((Text) widgets[ c ]).getText() );
answerForm.setAnswer( field.getVariable(), list );
}
}
dialogShell.close();
}
});
Button cancelButton = new Button( dialogShell, SWT.PUSH );
cancelButton.setText( "&Cancel" );
cancelButton.setLayoutData( new GridData( GridData.CENTER ) );
cancelButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent e ) {
dialogShell.close();
}
}
);
dialogShell.pack();
dialogShell.open();
while ( !dialogShell.isDisposed() ) {
if ( !display.readAndDispatch() ) {
display.sleep();
}
}
return answerForm;
}
private void gotSubscriptionRequest ( final String name ) {
final Shell dialogShell;
dialogShell = new Shell( getDisplay() );
dialogShell.setText( "Subscription-Request from " + name );
dialogShell.setLayout( new FormLayout() );
FormData data;
int border = 10;
// Description
Label descLabel = new Label( dialogShell, SWT.WRAP );
data = new FormData ();
data.top = new FormAttachment( 0, border );
data.left = new FormAttachment( 0, border );
descLabel.setLayoutData( data );
descLabel.setText( "The user '" + name + "',\nwants to add you to his Roster\n\nwhat do you want to do?" );
// Allow&Add-Button
Button allowAddButton = new Button( dialogShell, SWT.PUSH );
data = new FormData ();
data.top = new FormAttachment( descLabel, border );
data.left = new FormAttachment( 0, border );
allowAddButton.setLayoutData( data );
allowAddButton.setText( "Allow&Add" );
allowAddButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent e ) {
sendSubscription( Presence.Type.SUBSCRIBED, name );
if( getJRoster() == null )
new Error( display, "Error - Roster not loaded", "An error occured while trying to add '" + name + "' the reason is that your Roster is not load yet.\nPlease try it later.", null );
else {
getJRoster().addRosterEntry( name );
dialogShell.close();
}
}
} );
// Allow-Button
Button allowButton = new Button( dialogShell, SWT.PUSH );
data = new FormData ();
data.top = new FormAttachment( descLabel, border );
data.left = new FormAttachment( allowAddButton, border );
allowButton.setLayoutData( data );
allowButton.setText( "Allow" );
allowButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent e ) {
sendSubscription( Presence.Type.SUBSCRIBED, name );
dialogShell.close();
}
} );
// Deny-Button
Button denyButton = new Button( dialogShell, SWT.PUSH );
data = new FormData ();
data.top = new FormAttachment( descLabel, border );
data.left = new FormAttachment( allowButton, border );
denyButton.setLayoutData( data );
denyButton.setText( "Deny" );
denyButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent e ) {
sendSubscription( Presence.Type.UNSUBSCRIBE, name );
dialogShell.close();
}
} );
dialogShell.pack();
dialogShell.setSize( dialogShell.getSize().x + border, dialogShell.getSize().y + border );
dialogShell.open();
}
private void gotInvitation( XMPPConnection conn, final String room, String invitor, String reason, final String password, Message message ) {
final Shell dialogShell = new Shell( display );
dialogShell.setLayout( new GridLayout( 2, true ) );
dialogShell.setText( "Invitation to " + room + " from " + invitor );
Label label = new Label( dialogShell, SWT.WRAP );
label.setText( invitor + "wants invites you to " + room + "\nTo convince you he sends you the following reason:\n\n" + reason + ( (password != null ) ? "\n\nThe password needed to join the room is '" + password + "'" : "" ) );
label.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true, 2, 1 ) );
Button ignoreButton = new Button( dialogShell, SWT.PUSH );
ignoreButton.setText( "&Ignore" );
ignoreButton.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_CENTER ) );
ignoreButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent ex ) {
dialogShell.close();
}
});
Button joinButton = new Button( dialogShell, SWT.PUSH );
joinButton.setText( "&Join" );
joinButton.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_CENTER ) );
joinButton.addSelectionListener( new SelectionAdapter() {
public void widgetSelected( SelectionEvent ex ) {
if( roster != null ) {
dialogShell.close();
roster.createGroupChat( room, StringUtils.parseName( connection.getUser() ), password );
}
}
});
dialogShell.pack();
dialogShell.open();
}
public void sendSubscription( Presence.Type type, String user ) {
Presence presence = new Presence( type );
((Packet) presence ).setFrom( settings.getStringSetting( "name" ) );
((Packet) presence ).setTo( user );
connection.sendPacket( (Packet) presence );
}
public String getJavwerHomeDir() {
return javwerHomeDir;
}
}