Extends the authorization request process with the possibility to automatically add the requesting contact to the contact list.

cusax-fix
Yana Stamcheva 14 years ago
parent e6380c3507
commit 45817241ad

@ -34,6 +34,7 @@ service.gui.ACCOUNTS=Accounts
service.gui.ADD=&Add
service.gui.ADD_ACCOUNT=Add account
service.gui.ADD_CONTACT=&Add contact
service.gui.ADD_AUTHORIZED_CONTACT=Add {0} to your contact list
service.gui.ADD_CONTACT_TO=&Add contact to
service.gui.ADD_CONTACT_ERROR=Failed to add contact with id: {0}
service.gui.ADD_CONTACT_ERROR_TITLE=Add contact Error
@ -56,6 +57,7 @@ service.gui.APPLY=&Apply
service.gui.ARE_CALLING=are calling...
service.gui.ARE_NOW=You are now {0}
service.gui.AT=at
service.gui.AUTHORIZE=&Authorize
service.gui.AUTHORIZATION_ACCEPTED=contact has accepted your authorization request.
service.gui.AUTHENTICATION_FAILED=Authentication failed. The password you entered is not valid.
service.gui.AUTHENTICATION_REQUESTED=Authentication requested
@ -149,6 +151,7 @@ service.gui.CONTACT_INFO_NOT_SUPPORTED=This contact doesn't support web contact
service.gui.CUT=C&ut
service.gui.DATE=Date
service.gui.DELETE=Delete
service.gui.DENY=&Deny
service.gui.DESKTOP_SHARING_WARNING=<b>Are you sure you want to start screen sharing?</b> <br> Clicking OK will let people on this call see your screen.
service.gui.DIALPAD=Dialpad
service.gui.DISPLAY_NAME=Display name

@ -7,6 +7,7 @@
package net.java.sip.communicator.impl.gui.main.authorization;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.impl.gui.main.contactlist.*;
import net.java.sip.communicator.service.protocol.*;
/**
@ -39,24 +40,36 @@ public AuthorizationHandlerImpl(MainFrame mainFrame) {
public AuthorizationResponse processAuthorisationRequest(
AuthorizationRequest req, Contact sourceContact) {
AuthorizationResponse response = null;
AuthorizationRequestedDialog dialog
= new AuthorizationRequestedDialog(mainFrame, sourceContact, req);
int result = dialog.showDialog();
if(result == AuthorizationRequestedDialog.ACCEPT_CODE) {
response = new AuthorizationResponse(AuthorizationResponse.ACCEPT,
null);
if(result == AuthorizationRequestedDialog.ACCEPT_CODE)
{
response
= new AuthorizationResponse(AuthorizationResponse.ACCEPT, null);
// If the add contact option has been selected then open the
// add contact window.
if (dialog.isAddContact())
{
ContactListUtils.addContact(sourceContact.getProtocolProvider(),
dialog.getSelectedMetaContactGroup(),
sourceContact.getAddress());
}
}
else if(result == AuthorizationRequestedDialog.REJECT_CODE) {
else if(result == AuthorizationRequestedDialog.REJECT_CODE)
{
response = new AuthorizationResponse(AuthorizationResponse.REJECT,
null);
}
else if(result == AuthorizationRequestedDialog.IGNORE_CODE) {
else if(result == AuthorizationRequestedDialog.IGNORE_CODE)
{
response = new AuthorizationResponse(AuthorizationResponse.IGNORE,
null);
}
}
return response;
}

@ -13,10 +13,12 @@
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.lookandfeel.*;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.impl.gui.main.contactlist.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.skin.*;
import net.java.sip.communicator.util.swing.*;
@ -29,6 +31,9 @@ public class AuthorizationRequestedDialog
implements ActionListener,
Skinnable
{
private final Logger logger
= Logger.getLogger(AuthorizationRequestedDialog.class);
public static final int ACCEPT_CODE = 0;
public static final int REJECT_CODE = 1;
@ -39,7 +44,7 @@ public class AuthorizationRequestedDialog
private JTextArea infoTextArea = new JTextArea();
private JEditorPane requestPane = new JEditorPane();
private JTextPane requestPane = new JTextPane();
private JPanel buttonsPanel =
new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
@ -54,10 +59,10 @@ public class AuthorizationRequestedDialog
ImageLoader.getImage(ImageLoader.AUTHORIZATION_ICON)));
private JButton acceptButton = new JButton(
GuiActivator.getResources().getI18NString("service.gui.ACCEPT"));
GuiActivator.getResources().getI18NString("service.gui.AUTHORIZE"));
private JButton rejectButton = new JButton(
GuiActivator.getResources().getI18NString("service.gui.REJECT"));
GuiActivator.getResources().getI18NString("service.gui.DENY"));
private JButton ignoreButton = new JButton(
GuiActivator.getResources().getI18NString("service.gui.IGNORE"));
@ -66,13 +71,16 @@ public class AuthorizationRequestedDialog
private JPanel mainPanel = new TransparentPanel(new BorderLayout(10, 10));
private JPanel reasonsPanel =
new TransparentPanel(new GridLayout(0, 1, 5, 5));
private JPanel reasonsPanel = new TransparentPanel();
private String title
= GuiActivator.getResources()
.getI18NString("service.gui.AUTHORIZATION_REQUESTED");
private SIPCommCheckBox addContactCheckBox;
private JComboBox groupComboBox;
private Object lock = new Object();
private int result;
@ -84,10 +92,11 @@ public class AuthorizationRequestedDialog
* @param contact The <tt>Contact</tt>, which requires authorisation.
* @param request The <tt>AuthorizationRequest</tt> that will be sent.
*/
public AuthorizationRequestedDialog(MainFrame mainFrame, Contact contact,
AuthorizationRequest request)
public AuthorizationRequestedDialog(MainFrame mainFrame,
Contact contact,
AuthorizationRequest request)
{
super(mainFrame);
super(mainFrame, false);
this.setModal(false);
@ -116,11 +125,17 @@ public AuthorizationRequestedDialog(MainFrame mainFrame, Contact contact,
this.northPanel.add(iconLabel, BorderLayout.WEST);
this.northPanel.add(titlePanel, BorderLayout.CENTER);
reasonsPanel.setLayout(new BoxLayout(reasonsPanel, BoxLayout.Y_AXIS));
reasonsPanel.setBorder(BorderFactory.createEmptyBorder(
0, iconLabel.getIcon().getIconWidth() + 5, 0, 0));
if(request.getReason() != null && !request.getReason().equals(""))
{
this.requestScrollPane.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(3, 3, 3, 3),
SIPCommBorders.getBoldRoundBorder()));
BorderFactory.createEtchedBorder(),
BorderFactory.createEmptyBorder(3, 3, 3, 3)));
requestScrollPane.getViewport().setOpaque(false);
this.requestPane.setEditable(false);
this.requestPane.setOpaque(false);
@ -130,14 +145,42 @@ public AuthorizationRequestedDialog(MainFrame mainFrame, Contact contact,
this.reasonsPanel.add(requestScrollPane);
this.mainPanel.setPreferredSize(new Dimension(550, 300));
this.mainPanel.setPreferredSize(new Dimension(500, 250));
}
else
{
this.mainPanel.setPreferredSize(new Dimension(500, 200));
}
else {
this.mainPanel.setPreferredSize(new Dimension(550, 200));
// If the authorization request comes from a non-persistent contact,
// we'll suggest to the user to add it to the contact list.
if (!contact.isPersistent())
{
addContactCheckBox
= new SIPCommCheckBox(GuiActivator.getResources()
.getI18NString("service.gui.ADD_AUTHORIZED_CONTACT",
new String[]{contact.getDisplayName()}), true);
addContactCheckBox.setBorder(null);
JPanel checkBoxPanel
= new TransparentPanel(new FlowLayout(FlowLayout.LEFT));
checkBoxPanel.add(addContactCheckBox);
JLabel groupLabel = new JLabel(GuiActivator.getResources()
.getI18NString("service.gui.SELECT_GROUP"));
groupComboBox = AddContactDialog.createGroupCombo(this);
JPanel groupPanel = new TransparentPanel(new BorderLayout(5, 5));
groupPanel.add(groupLabel, BorderLayout.WEST);
groupPanel.add(groupComboBox, BorderLayout.CENTER);
reasonsPanel.add(checkBoxPanel);
reasonsPanel.add(groupPanel);
}
this.acceptButton.setName("service.gui.ACCEPT");
this.rejectButton.setName("reject");
this.acceptButton.setName("authorize");
this.rejectButton.setName("deny");
this.ignoreButton.setName("ignore");
this.acceptButton.addActionListener(this);
@ -145,9 +188,9 @@ public AuthorizationRequestedDialog(MainFrame mainFrame, Contact contact,
this.ignoreButton.addActionListener(this);
this.acceptButton.setMnemonic(
GuiActivator.getResources().getI18nMnemonic("service.gui.ACCEPT"));
GuiActivator.getResources().getI18nMnemonic("service.gui.AUTHORIZE"));
this.rejectButton.setMnemonic(
GuiActivator.getResources().getI18nMnemonic("service.gui.REJECT"));
GuiActivator.getResources().getI18nMnemonic("service.gui.DENY"));
this.ignoreButton.setMnemonic(
GuiActivator.getResources().getI18nMnemonic("service.gui.IGNORE"));
@ -156,7 +199,7 @@ public AuthorizationRequestedDialog(MainFrame mainFrame, Contact contact,
this.buttonsPanel.add(ignoreButton);
this.mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
this.mainPanel.add(northPanel, BorderLayout.NORTH);
this.mainPanel.add(northPanel, BorderLayout.NORTH);
this.mainPanel.add(reasonsPanel, BorderLayout.CENTER);
this.mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
@ -177,9 +220,9 @@ public int showDialog()
{
lock.wait();
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
catch (InterruptedException e)
{
logger.error("Authorization request interrupted.", e);
}
}
@ -197,11 +240,11 @@ public void actionPerformed(ActionEvent e)
JButton button = (JButton)e.getSource();
String name = button.getName();
if (name.equals("service.gui.ACCEPT"))
if (name.equals("authorize"))
{
this.result = ACCEPT_CODE;
}
else if (name.equals("reject"))
else if (name.equals("deny"))
{
this.result = REJECT_CODE;
}
@ -241,4 +284,28 @@ public void loadSkin()
iconLabel.setIcon(new ImageIcon(
ImageLoader.getImage(ImageLoader.AUTHORIZATION_ICON)));
}
/**
* Indicates if the "Add contact" checkbox has been selected.
*
* @return <tt>true</tt> if the "Add contact" checkbox has been selected,
* otherwise returns <tt>false</tt>.
*/
public boolean isAddContact()
{
if (addContactCheckBox != null)
return addContactCheckBox.isSelected();
return false;
}
/**
* Returns the currently selected group to add the contact to.
*
* @return the group to add the contact to
*/
public MetaContactGroup getSelectedMetaContactGroup()
{
return (MetaContactGroup) groupComboBox.getSelectedItem();
}
}

@ -103,10 +103,9 @@ else if(responseCode.equals(AuthorizationResponse.REJECT))
if(response.getReason() != null && !response.getReason().equals(""))
{
this.responseScrollPane.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(3, 3, 3, 3),
SIPCommBorders.getBoldRoundBorder()));
this.responseScrollPane.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEtchedBorder(),
BorderFactory.createEmptyBorder(3, 3, 3, 3)));
this.responseArea.setText(response.getReason());
this.responseArea.setLineWrap(true);

@ -54,7 +54,7 @@ public class AddContactDialog
GuiActivator.getResources().getI18NString(
"service.gui.SELECT_GROUP") + ": ");
private final JComboBox groupCombo = new JComboBox();
private JComboBox groupCombo;
private final JLabel contactAddressLabel = new JLabel(
GuiActivator.getResources().getI18NString(
@ -98,6 +98,8 @@ public AddContactDialog(MainFrame mainFrame)
this.setTitle(GuiActivator.getResources()
.getI18NString("service.gui.ADD_CONTACT"));
groupCombo = createGroupCombo(this);
this.init();
}
@ -114,6 +116,9 @@ public AddContactDialog(MainFrame parentWindow, MetaContact metaContact)
this.metaContact = metaContact;
this.setSelectedGroup(metaContact.getParentMetaContactGroup());
groupCombo = createGroupCombo(this);
this.groupCombo.setEnabled(false);
this.setTitle(GuiActivator.getResources()
@ -168,8 +173,6 @@ private void init()
labelsPanel.add(groupLabel);
fieldsPanel.add(groupCombo);
initGroupCombo();
groupCombo.setRenderer(new GroupComboRenderer());
labelsPanel.add(contactAddressLabel);
fieldsPanel.add(contactAddressField);
@ -295,8 +298,12 @@ public void itemStateChanged(ItemEvent e)
/**
* Initializes groups combo box.
*/
private void initGroupCombo()
public static JComboBox createGroupCombo(final Dialog parentDialog)
{
final JComboBox groupCombo = new JComboBox();
groupCombo.setRenderer(new GroupComboRenderer());
groupCombo.addItem(GuiActivator.getContactListService().getRoot());
Iterator<MetaContactGroup> groupList
@ -319,7 +326,7 @@ public void actionPerformed(ActionEvent e)
if (groupCombo.getSelectedItem().equals(newGroupString))
{
CreateGroupDialog dialog
= new CreateGroupDialog(AddContactDialog.this, false);
= new CreateGroupDialog(parentDialog, false);
dialog.setModal(true);
dialog.setVisible(true);
@ -336,6 +343,8 @@ public void actionPerformed(ActionEvent e)
}
}
});
return groupCombo;
}
/**
@ -378,67 +387,10 @@ public void run()
}
else
{
new Thread()
{
@Override
public void run()
{
try
{
metaContact
= GuiActivator.getContactListService()
.createMetaContact(
protocolProvider,
(MetaContactGroup) groupCombo
.getSelectedItem(),
contactAddress);
}
catch (MetaContactListException ex)
{
logger.error(ex);
ex.printStackTrace();
int errorCode = ex.getErrorCode();
if (errorCode
== MetaContactListException
.CODE_CONTACT_ALREADY_EXISTS_ERROR)
{
new ErrorDialog(mainFrame,
GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT_ERROR_TITLE"),
GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT_EXIST_ERROR",
new String[]{contactAddress}),
ex)
.showDialog();
}
else if (errorCode
== MetaContactListException
.CODE_NETWORK_ERROR)
{
new ErrorDialog(mainFrame,
GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT_ERROR_TITLE"),
GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT_NETWORK_ERROR",
new String[]{contactAddress}),
ex)
.showDialog();
}
else
{
new ErrorDialog(mainFrame,
GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT_ERROR_TITLE"),
GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT_ERROR",
new String[]{contactAddress}),
ex)
.showDialog();
}
}
}
}.start();
ContactListUtils.addContact( protocolProvider,
(MetaContactGroup) groupCombo
.getSelectedItem(),
contactAddress);
}
}
dispose();

@ -0,0 +1,87 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.contactlist;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
public class ContactListUtils
{
private static final Logger logger
= Logger.getLogger(ContactListUtils.class);
public static void addContact(
final ProtocolProviderService protocolProvider,
final MetaContactGroup group,
final String contactAddress)
{
new Thread()
{
@Override
public void run()
{
try
{
GuiActivator.getContactListService()
.createMetaContact( protocolProvider,
group,
contactAddress);
}
catch (MetaContactListException ex)
{
logger.error(ex);
ex.printStackTrace();
int errorCode = ex.getErrorCode();
if (errorCode
== MetaContactListException
.CODE_CONTACT_ALREADY_EXISTS_ERROR)
{
new ErrorDialog(
GuiActivator.getUIService().getMainFrame(),
GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT_ERROR_TITLE"),
GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT_EXIST_ERROR",
new String[]{contactAddress}),
ex)
.showDialog();
}
else if (errorCode
== MetaContactListException
.CODE_NETWORK_ERROR)
{
new ErrorDialog(
GuiActivator.getUIService().getMainFrame(),
GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT_ERROR_TITLE"),
GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT_NETWORK_ERROR",
new String[]{contactAddress}),
ex)
.showDialog();
}
else
{
new ErrorDialog(
GuiActivator.getUIService().getMainFrame(),
GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT_ERROR_TITLE"),
GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT_ERROR",
new String[]{contactAddress}),
ex)
.showDialog();
}
}
}
}.start();
}
}
Loading…
Cancel
Save