Update Theme work.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@6187 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2006-11-21 00:06:09 +00:00
committed by derek
parent d039de5651
commit 18d682961d
21 changed files with 708 additions and 227 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -590,10 +590,11 @@ public final class LoginDialog {
config = new ConnectionConfiguration(localPref.getXmppHost(), port, serverName); config = new ConnectionConfiguration(localPref.getXmppHost(), port, serverName);
} }
//config.setReconnectionAllowed(false);
} }
if (config != null) { if (config != null) {
config.setReconnectionAllowed(true);
boolean compressionEnabled = localPref.isCompressionEnabled(); boolean compressionEnabled = localPref.isCompressionEnabled();
config.setCompressionEnabled(compressionEnabled); config.setCompressionEnabled(compressionEnabled);
connection = new XMPPConnection(config); connection = new XMPPConnection(config);
@ -613,8 +614,7 @@ public final class LoginDialog {
sessionManager.setServerAddress(connection.getServiceName()); sessionManager.setServerAddress(connection.getServiceName());
sessionManager.initializeSession(connection, getUsername(), getPassword()); sessionManager.initializeSession(connection, getUsername(), getPassword());
final String jid = getUsername() + '@' + sessionManager.getServerAddress() + "/" + resource; sessionManager.setJID(connection.getUser());
sessionManager.setJID(jid);
} }
catch (Exception xee) { catch (Exception xee) {

View File

@ -24,6 +24,7 @@ import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.log.Log; import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.alerts.InputTextAreaDialog; import org.jivesoftware.sparkimpl.plugin.alerts.InputTextAreaDialog;
import org.jivesoftware.sparkimpl.settings.JiveInfo; import org.jivesoftware.sparkimpl.settings.JiveInfo;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import org.jivesoftware.sparkimpl.updater.CheckUpdates; import org.jivesoftware.sparkimpl.updater.CheckUpdates;
import java.awt.BorderLayout; import java.awt.BorderLayout;
@ -260,6 +261,9 @@ public final class MainWindow extends JFrame implements ActionListener {
// Notify all MainWindowListeners // Notify all MainWindowListeners
try { try {
// Set auto-login to false;
SettingsManager.getLocalPreferences().setAutoLogin(false);
fireWindowShutdown(); fireWindowShutdown();
setVisible(false); setVisible(false);
} }
@ -282,7 +286,6 @@ public final class MainWindow extends JFrame implements ActionListener {
}; };
shutdownThread.start(); shutdownThread.start();
} }
} }
@ -317,7 +320,6 @@ public final class MainWindow extends JFrame implements ActionListener {
* Setup the Main Toolbar with File, Tools and Help. * Setup the Main Toolbar with File, Tools and Help.
*/ */
private void buildMenu() { private void buildMenu() {
// setup file menu // setup file menu
JMenuItem exitMenuItem = new JMenuItem(); JMenuItem exitMenuItem = new JMenuItem();
@ -365,11 +367,9 @@ public final class MainWindow extends JFrame implements ActionListener {
connectMenu.add(logoutWithStatus); connectMenu.add(logoutWithStatus);
} }
// Only add a separator and an "exit" menu item if we're not on the Mac platform connectMenu.addSeparator();
if (!Spark.isMac()) {
connectMenu.addSeparator(); connectMenu.add(exitMenuItem);
connectMenu.add(exitMenuItem);
}
Action showTrafficAction = new AbstractAction() { Action showTrafficAction = new AbstractAction() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {

View File

@ -313,12 +313,11 @@ public final class Spark {
UIManager.put("TextField.foreground", Color.BLACK); UIManager.put("TextField.foreground", Color.BLACK);
UIManager.put("TextField.caretForeground", Color.black); UIManager.put("TextField.caretForeground", Color.black);
UIManager.put("List.selectionBackground", new Color(103, 121, 142)); UIManager.put("List.selectionBackground", new Color(217, 232, 250));
UIManager.put("List.selectionForeground", Color.white); UIManager.put("List.selectionForeground", Color.black);
UIManager.put("List.selectionBorder", new Color(187, 195, 215)); UIManager.put("List.selectionBorder", new Color(187, 195, 215));
UIManager.put("List.foreground", Color.black); UIManager.put("List.foreground", Color.black);
UIManager.put("List.background", Color.white); UIManager.put("List.background", Color.white);
UIManager.put("List.secondBackground", new Color(237, 243, 254));
UIManager.put("TextPane.foreground", Color.black); UIManager.put("TextPane.foreground", Color.black);
UIManager.put("TextPane.background", Color.white); UIManager.put("TextPane.background", Color.white);
UIManager.put("TextPane.inactiveForeground", Color.white); UIManager.put("TextPane.inactiveForeground", Color.white);
@ -342,9 +341,5 @@ public final class Spark {
UIManager.put("Notification.foreground", new Color(51, 153, 51)); UIManager.put("Notification.foreground", new Color(51, 153, 51));
UIManager.put("Error.foreground", Color.red); UIManager.put("Error.foreground", Color.red);
UIManager.put("Question.foreground", Color.red); UIManager.put("Question.foreground", Color.red);
UIManager.put("SparkTabbedPane.startColor", new Color(236, 236, 236));
UIManager.put("SparkTabbedPane.endColor", new Color(236, 236, 236));
UIManager.put("SparkTabbedPane.borderColor", Color.lightGray);
} }
} }

View File

@ -378,7 +378,7 @@ public final class SessionManager implements ConnectionListener {
public void reconnectingIn(int i) { public void reconnectingIn(int i) {
} }
public void reconectionSuccessful() { public void reconnectionSuccessful() {
} }
public void reconnectionFailed(Exception exception) { public void reconnectionFailed(Exception exception) {

View File

@ -49,18 +49,9 @@ public class JPanelRenderer extends JPanel implements ListCellRenderer {
panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.selectionBorder"))); panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.selectionBorder")));
} }
else { else {
if (index % 2 != 0) { panel.setBackground(list.getBackground());
panel.setBackground((Color)UIManager.get("List.secondBackground")); panel.setForeground(list.getForeground());
panel.setForeground(list.getForeground()); panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.background")));
panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.secondBackground")));
}
else {
panel.setBackground(list.getBackground());
panel.setForeground(list.getForeground());
panel.setBorder(BorderFactory.createLineBorder((Color)UIManager.get("List.background")));
}
} }
list.setBackground((Color)UIManager.get("List.background")); list.setBackground((Color)UIManager.get("List.background"));

View File

@ -23,7 +23,6 @@ import javax.swing.JList;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JWindow; import javax.swing.JWindow;
import javax.swing.Timer; import javax.swing.Timer;
import javax.swing.ImageIcon;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
@ -34,7 +33,6 @@ import java.awt.GridBagLayout;
import java.awt.Insets; import java.awt.Insets;
import java.awt.Point; import java.awt.Point;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.Image;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
@ -49,7 +47,6 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.net.URL;
/** /**
* Container representing a RosterGroup within the Contact List. * Container representing a RosterGroup within the Contact List.
@ -144,14 +141,6 @@ public class ContactGroup extends CollapsiblePane implements MouseListener {
// Add Popup Window // Add Popup Window
addPopupWindow(); addPopupWindow();
// Use background image
/*
URL url = getClass().getResource("/images/blue-steel-background.png");
ImageIcon icon = new ImageIcon(url);
getTitlePane().useImageAsBackground(icon.getImage());
getTitlePane().setTitleColor(Color.white);
*/
} }
/** /**
@ -766,7 +755,6 @@ public class ContactGroup extends CollapsiblePane implements MouseListener {
} }
} }
} }

View File

@ -25,13 +25,6 @@ import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.log.Log; import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.profile.VCardManager; import org.jivesoftware.sparkimpl.profile.VCardManager;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
@ -42,7 +35,17 @@ import java.io.File;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
public class ContactItem extends JPanel { public class ContactItem extends JPanel {
private JLabel imageLabel; private JLabel imageLabel;
@ -214,15 +217,6 @@ public class ContactItem extends JPanel {
return null; return null;
} }
public void setForeground(Color fg) {
super.setForeground(fg);
if (nicknameLabel != null) {
nicknameLabel.setForeground(fg);
}
}
private void updateAvatar(final String hash) { private void updateAvatar(final String hash) {
Thread updateAvatarThread = new Thread(new Runnable() { Thread updateAvatarThread = new Thread(new Runnable() {
public void run() { public void run() {
@ -280,8 +274,7 @@ public class ContactItem extends JPanel {
} }
} }
} }
else else if (this.presence != null && (this.presence.getMode() == Presence.Mode.available || this.presence.getMode() == Presence.Mode.chat)) {
if (this.presence != null && (this.presence.getMode() == Presence.Mode.available || this.presence.getMode() == Presence.Mode.chat)) {
if (presence != null && presence.getMode() != Presence.Mode.available && presence.getMode() != Presence.Mode.chat) { if (presence != null && presence.getMode() != Presence.Mode.available && presence.getMode() != Presence.Mode.chat) {
awayTime = new Date(); awayTime = new Date();
String status = presence.getStatus(); String status = presence.getStatus();
@ -330,8 +323,7 @@ public class ContactItem extends JPanel {
statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY); statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
} }
} }
else else if (presence != null && (presence.getMode() == Presence.Mode.dnd || presence.getMode() == Presence.Mode.away || presence.getMode() == Presence.Mode.xa)) {
if (presence != null && (presence.getMode() == Presence.Mode.dnd || presence.getMode() == Presence.Mode.away || presence.getMode() == Presence.Mode.xa)) {
statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY); statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
} }
else if (presence != null && presence.getType() == Presence.Type.available) { else if (presence != null && presence.getType() == Presence.Type.available) {
@ -343,7 +335,7 @@ public class ContactItem extends JPanel {
RosterEntry entry = SparkManager.getConnection().getRoster().getEntry(getFullJID()); RosterEntry entry = SparkManager.getConnection().getRoster().getEntry(getFullJID());
if (entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) if (entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM)
&& RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) { && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
// Do not move out of group. // Do not move out of group.
setIcon(SparkRes.getImageIcon(SparkRes.SMALL_QUESTION)); setIcon(SparkRes.getImageIcon(SparkRes.SMALL_QUESTION));
getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, 11)); getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, 11));
@ -434,7 +426,7 @@ public class ContactItem extends JPanel {
RosterEntry entry = SparkManager.getConnection().getRoster().getEntry(getFullJID()); RosterEntry entry = SparkManager.getConnection().getRoster().getEntry(getFullJID());
if (entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) if (entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM)
&& RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) { && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
// Do not move out of group. // Do not move out of group.
getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, 11)); getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, 11));
setStatusText("Pending"); setStatusText("Pending");
@ -495,7 +487,7 @@ public class ContactItem extends JPanel {
} }
} }
public void setSideIcon(Icon icon) { public void setSideIcon(Icon icon){
sideIcon.setIcon(icon); sideIcon.setIcon(icon);
} }

View File

@ -49,6 +49,23 @@ import org.jivesoftware.sparkimpl.profile.VCardManager;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences; import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager; import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
@ -73,23 +90,6 @@ import java.util.StringTokenizer;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public final class ContactList extends JPanel implements ActionListener, ContactGroupListener, Plugin, RosterListener, ConnectionListener { public final class ContactList extends JPanel implements ActionListener, ContactGroupListener, Plugin, RosterListener, ConnectionListener {
private JPanel mainPanel = new JPanel(); private JPanel mainPanel = new JPanel();
private JScrollPane treeScroller; private JScrollPane treeScroller;
@ -255,7 +255,7 @@ public final class ContactList extends JPanel implements ActionListener, Contact
RosterEntry entry = roster.getEntry(bareJID); RosterEntry entry = roster.getEntry(bareJID);
boolean isPending = entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) boolean isPending = entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM)
&& RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus(); && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus();
// If online, check to see if they are in the offline group. // If online, check to see if they are in the offline group.
// If so, remove from offline group and add to all groups they // If so, remove from offline group and add to all groups they
@ -418,7 +418,7 @@ public final class ContactList extends JPanel implements ActionListener, Contact
ContactItem contactItem = new ContactItem(name, entry.getUser()); ContactItem contactItem = new ContactItem(name, entry.getUser());
contactItem.setPresence(null); contactItem.setPresence(null);
if ((entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) if ((entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM)
&& RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) { && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
// Add to contact group. // Add to contact group.
contactGroup.addContactItem(contactItem); contactGroup.addContactItem(contactItem);
contactGroup.setVisible(true); contactGroup.setVisible(true);
@ -493,7 +493,7 @@ public final class ContactList extends JPanel implements ActionListener, Contact
} }
boolean isPending = entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) boolean isPending = entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM)
&& RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus(); && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus();
if (isPending) { if (isPending) {
contactGroup.setVisible(true); contactGroup.setVisible(true);
} }
@ -618,7 +618,7 @@ public final class ContactList extends JPanel implements ActionListener, Contact
updateUserPresence(presence); updateUserPresence(presence);
if (entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM) if (entry != null && (entry.getType() == RosterPacket.ItemType.NONE || entry.getType() == RosterPacket.ItemType.FROM)
&& RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) { && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
contactGroup.setVisible(true); contactGroup.setVisible(true);
} }
@ -662,7 +662,7 @@ public final class ContactList extends JPanel implements ActionListener, Contact
ContactItem offlineItem = offlineGroup.getContactItemByJID(jid); ContactItem offlineItem = offlineGroup.getContactItemByJID(jid);
if (offlineItem != null) { if (offlineItem != null) {
if ((rosterEntry.getType() == RosterPacket.ItemType.NONE || rosterEntry.getType() == RosterPacket.ItemType.FROM) if ((rosterEntry.getType() == RosterPacket.ItemType.NONE || rosterEntry.getType() == RosterPacket.ItemType.FROM)
&& RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == rosterEntry.getStatus()) { && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == rosterEntry.getStatus()) {
// Remove from offlineItem and add to unfiledItem. // Remove from offlineItem and add to unfiledItem.
offlineGroup.removeContactItem(offlineItem); offlineGroup.removeContactItem(offlineItem);
unfiledGroup.addContactItem(offlineItem); unfiledGroup.addContactItem(offlineItem);
@ -1794,7 +1794,22 @@ public final class ContactList extends JPanel implements ActionListener, Contact
public void connectionClosed() { public void connectionClosed() {
// No reason to reconnect. // No reason to reconnect.
connectionClosedOnError(null); retryPanel.setClosedOnError(false);
// Show MainWindow
SparkManager.getMainWindow().setVisible(true);
// Flash That Window.
SparkManager.getAlertManager().flashWindowStopOnFocus(SparkManager.getMainWindow());
workspace.changeCardLayout(RETRY_PANEL);
String errorMessage = Res.getString("message.disconnected.error");
retryPanel.setDisconnectReason(errorMessage);
removeAllUsers();
} }
private void reconnect(final String message) { private void reconnect(final String message) {
@ -1813,7 +1828,19 @@ public final class ContactList extends JPanel implements ActionListener, Contact
public void clientReconnected() { public void clientReconnected() {
buildContactList(); buildContactList();
workspace.changeCardLayout(Workspace.WORKSPACE_PANE); workspace.changeCardLayout(Workspace.WORKSPACE_PANE);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
// Send presence to server.
final Presence presence = new Presence(Presence.Type.available, "Online", -1, Presence.Mode.available);
SparkManager.getSessionManager().changePresence(presence);
}
}, 3000);
} }
public void connectionClosedOnError(final Exception ex) { public void connectionClosedOnError(final Exception ex) {
@ -1835,6 +1862,7 @@ public final class ContactList extends JPanel implements ActionListener, Contact
final String message = errorMessage; final String message = errorMessage;
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
retryPanel.setClosedOnError(true);
reconnect(message); reconnect(message);
} }
}); });
@ -1859,11 +1887,11 @@ public final class ContactList extends JPanel implements ActionListener, Contact
retryPanel.setReconnectText("Attempting..."); retryPanel.setReconnectText("Attempting...");
} }
else { else {
retryPanel.setReconnectText("Reconnect..."); retryPanel.setReconnectText("Reconnecting in " + i + " seconds.");
} }
} }
public void reconectionSuccessful() { public void reconnectionSuccessful() {
clientReconnected(); clientReconnected();
} }

View File

@ -37,6 +37,7 @@ import java.awt.event.ActionListener;
public class RetryPanel extends JPanel { public class RetryPanel extends JPanel {
private JEditorPane pane; private JEditorPane pane;
private RolloverButton retryButton; private RolloverButton retryButton;
private boolean closedOnError = false;
/** /**
* Construct the RetryPanel. * Construct the RetryPanel.
@ -72,7 +73,12 @@ public class RetryPanel extends JPanel {
SwingWorker worker = new SwingWorker() { SwingWorker worker = new SwingWorker() {
public Object construct() { public Object construct() {
try { try {
SparkManager.getConnection().connect(); if(closedOnError){
SparkManager.getConnection().connect();
}
else {
SparkManager.getMainWindow().logout(false);
}
return true; return true;
} }
catch (Exception e) { catch (Exception e) {
@ -83,14 +89,7 @@ public class RetryPanel extends JPanel {
public void finished() { public void finished() {
retryButton.setEnabled(true); retryButton.setEnabled(true);
retryButton.setText("Reconnect...");
if ((Boolean)get()) {
ContactList list = SparkManager.getWorkspace().getContactList();
list.clientReconnected();
}
else {
retryButton.setText("Reconnect...");
}
} }
}; };
@ -143,4 +142,8 @@ public class RetryPanel extends JPanel {
public void showConflict() { public void showConflict() {
retryButton.setVisible(false); retryButton.setVisible(false);
} }
public void setClosedOnError(boolean onError){
closedOnError = onError;
}
} }

View File

@ -20,7 +20,7 @@ import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.spark.SparkManager; import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.UserManager; import org.jivesoftware.spark.UserManager;
import org.jivesoftware.spark.component.RolloverButton; import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.component.WrappedLabel; import org.jivesoftware.spark.component.TitlePanel;
import org.jivesoftware.spark.component.borders.ComponentTitledBorder; import org.jivesoftware.spark.component.borders.ComponentTitledBorder;
import org.jivesoftware.spark.util.ModelUtil; import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.ResourceUtils; import org.jivesoftware.spark.util.ResourceUtils;
@ -28,15 +28,8 @@ import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport; import org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.TransportUtils; import org.jivesoftware.sparkimpl.plugin.gateways.transports.TransportUtils;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JFrame; import javax.swing.JFrame;
@ -44,7 +37,13 @@ import javax.swing.JLabel;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.ImageIcon;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/** /**
* SubscriptionDialog handles all subscription requests. * SubscriptionDialog handles all subscription requests.
@ -53,7 +52,8 @@ import javax.swing.ImageIcon;
*/ */
public class SubscriptionDialog { public class SubscriptionDialog {
private final WrappedLabel messageLabel = new WrappedLabel(); private TitlePanel messageLabel;
private final RolloverButton acceptButton = new RolloverButton(); private final RolloverButton acceptButton = new RolloverButton();
private final RolloverButton viewInfoButton = new RolloverButton(); private final RolloverButton viewInfoButton = new RolloverButton();
private final RolloverButton denyButton = new RolloverButton(); private final RolloverButton denyButton = new RolloverButton();
@ -61,12 +61,15 @@ public class SubscriptionDialog {
private final JCheckBox rosterBox = new JCheckBox(); private final JCheckBox rosterBox = new JCheckBox();
private final JLabel nameLabel = new JLabel(); private final JLabel nicknameLabel = new JLabel();
private final JTextField nameField = new JTextField(); private final JTextField nicknameField = new JTextField();
private final JLabel groupLabel = new JLabel(); private final JLabel groupLabel = new JLabel();
private final JComboBox groupBox = new JComboBox(); private final JComboBox groupBox = new JComboBox();
private JLabel usernameLabel = new JLabel();
private JLabel usernameLabelValue = new JLabel();
private JFrame dialog; private JFrame dialog;
private String jid; private String jid;
@ -76,40 +79,44 @@ public class SubscriptionDialog {
mainPanel = new JPanel(); mainPanel = new JPanel();
mainPanel.setLayout(new GridBagLayout()); mainPanel.setLayout(new GridBagLayout());
messageLabel.setBackground(Color.white);
// Add Message Label
mainPanel.add(messageLabel, new GridBagConstraints(0, 0, 5, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
// Add Roster Addition // Add Roster Addition
final JPanel rosterPanel = new JPanel(); final JPanel rosterPanel = new JPanel();
rosterPanel.setLayout(new GridBagLayout()); rosterPanel.setLayout(new GridBagLayout());
// Add ResourceUtils // Add ResourceUtils
ResourceUtils.resLabel(nameLabel, nameField, Res.getString("label.username") + ":"); ResourceUtils.resLabel(usernameLabel, nicknameField, Res.getString("label.username") + ":");
ResourceUtils.resLabel(nicknameLabel, nicknameField, Res.getString("label.nickname") + ":");
ResourceUtils.resLabel(groupLabel, groupBox, Res.getString("label.group") + ":"); ResourceUtils.resLabel(groupLabel, groupBox, Res.getString("label.group") + ":");
rosterBox.setText("Add user to your roster"); rosterBox.setText("Add user to your roster");
rosterBox.setSelected(true); groupBox.setEditable(true);
rosterBox.addActionListener(new ActionListener() { rosterBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) { public void actionPerformed(ActionEvent actionEvent) {
nameField.setEnabled(rosterBox.isSelected()); nicknameField.setEnabled(rosterBox.isSelected());
groupBox.setEnabled(rosterBox.isSelected()); groupBox.setEnabled(rosterBox.isSelected());
} }
}); });
rosterBox.setSelected(true);
ComponentTitledBorder componentBorder = new ComponentTitledBorder(rosterBox, rosterPanel, BorderFactory.createEtchedBorder()); ComponentTitledBorder componentBorder = new ComponentTitledBorder(rosterBox, rosterPanel, BorderFactory.createEtchedBorder());
rosterPanel.add(nameLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
rosterPanel.add(nameField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
rosterPanel.add(groupLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); rosterPanel.add(usernameLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
rosterPanel.add(groupBox, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); rosterPanel.add(usernameLabelValue, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
rosterPanel.add(new JLabel(), new GridBagConstraints(1, 3, 1, 1, 1.0, 1.0, GridBagConstraints.SOUTH, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
rosterPanel.add(nicknameLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
rosterPanel.add(nicknameField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
rosterPanel.add(groupLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
rosterPanel.add(groupBox, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
rosterPanel.add(new JLabel(), new GridBagConstraints(1, 4, 1, 1, 1.0, 1.0, GridBagConstraints.SOUTH, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
// Add Roster Panel to mainPanel // Add Roster Panel to mainPanel
mainPanel.add(rosterPanel, new GridBagConstraints(2, 1, 5, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); mainPanel.add(rosterPanel, new GridBagConstraints(2, 1, 5, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
@ -158,10 +165,21 @@ public class SubscriptionDialog {
} }
String message = Res.getString("message.approve.subscription", UserManager.unescapeJID(jid)); String message = Res.getString("message.approve.subscription", UserManager.unescapeJID(jid));
messageLabel.setText(message); Transport transport = TransportUtils.getTransport(StringUtils.parseServer(jid));
Icon icon = null;
if (transport != null) {
icon = transport.getIcon();
}
messageLabel = new TitlePanel("", message, icon, true);
// Add Message Label
mainPanel.add(messageLabel, new GridBagConstraints(0, 0, 6, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
String username = StringUtils.parseName(UserManager.unescapeJID(jid)); String username = StringUtils.parseName(UserManager.unescapeJID(jid));
nameField.setText(username); usernameLabelValue.setText(UserManager.unescapeJID(jid));
nicknameField.setText(username);
acceptButton.addActionListener(new ActionListener() { acceptButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -204,16 +222,11 @@ public class SubscriptionDialog {
dialog = new JFrame("Subscription Request"); dialog = new JFrame("Subscription Request");
Transport transport = TransportUtils.getTransport(StringUtils.parseServer(jid));
if (transport != null) { dialog.setIconImage(SparkRes.getImageIcon(SparkRes.MAIN_IMAGE).getImage());
dialog.setIconImage(((ImageIcon)transport.getIcon()).getImage());
}
else {
dialog.setIconImage(SparkRes.getImageIcon(SparkRes.MAIN_IMAGE).getImage());
}
dialog.getContentPane().add(mainPanel); dialog.getContentPane().add(mainPanel);
dialog.pack(); dialog.pack();
dialog.setSize(350, 200); dialog.setSize(400, 225);
dialog.setLocationRelativeTo(SparkManager.getMainWindow()); dialog.setLocationRelativeTo(SparkManager.getMainWindow());
@ -226,13 +239,14 @@ public class SubscriptionDialog {
dialog.setState(Frame.ICONIFIED); dialog.setState(Frame.ICONIFIED);
dialog.setVisible(true); dialog.setVisible(true);
SparkManager.getAlertManager().flashWindowStopOnFocus(dialog); SparkManager.getAlertManager().flashWindowStopOnFocus(dialog);
dialog.setFocusableWindowState(true);
} }
} }
private boolean addEntry() { private boolean addEntry() {
String errorMessage = Res.getString("title.error"); String errorMessage = Res.getString("title.error");
String nickname = nameField.getText(); String nickname = nicknameField.getText();
String group = (String)groupBox.getSelectedItem(); String group = (String)groupBox.getSelectedItem();

View File

@ -0,0 +1,130 @@
/**
* $Revision$
* $Date$
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.sparkimpl.plugin.gateways;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.xmlpull.v1.XmlPullParser;
/**
*
*/
public class Gateway extends IQ {
private String jid;
private String username;
public String getJid() {
return jid;
}
public void setJid(String jid) {
this.jid = jid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
/**
* Element name of the packet extension.
*/
public static final String ELEMENT_NAME = "query";
/**
* Namespace of the packet extension.
*/
public static final String NAMESPACE = "jabber:iq:gateway";
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
buf.append("<query xmlns=\"" + NAMESPACE + "\">");
buf.append("<prompt>derek.demoro@hotmail.com</prompt>");
buf.append("</query>");
return buf.toString();
}
/**
* An IQProvider for Gateway packet.
*
* @author Derek DeMoro
*/
public static class Provider implements IQProvider {
public Provider() {
super();
}
public IQ parseIQ(XmlPullParser parser) throws Exception {
Gateway version = new Gateway();
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("jid")) {
version.setJid(parser.nextText());
}
else if (parser.getName().equals("username")) {
version.setUsername(parser.nextText());
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals(ELEMENT_NAME)) {
done = true;
}
}
}
return version;
}
}
public static void main(String args[]) throws Exception {
XMPPConnection.DEBUG_ENABLED = true;
XMPPConnection con = new XMPPConnection("jivesoftware.com", 5222);
con.connect();
con.login("test", "test");
System.out.println(StringUtils.unescapeNode("derek.demoro%hotmail.com"));
Gateway registration = new Gateway();
registration.setType(IQ.Type.SET);
registration.setTo("msn.jivesoftware.com");
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(registration.getPacketID()));
con.sendPacket(registration);
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("Server timed out");
}
if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException("Error registering user", response.getError());
}
}
}

View File

@ -0,0 +1,183 @@
/**
* $Revision$
* $Date$
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.sparkimpl.plugin.gateways;
import org.jivesoftware.resource.Res;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.ui.status.StatusBar;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.TransportUtils;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import java.awt.Component;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
*
*/
public class GatewayButton extends JPanel {
private final RolloverButton button = new RolloverButton();
private Transport transport;
private boolean signedIn;
public GatewayButton(final Transport transport) {
setLayout(new GridBagLayout());
setOpaque(false);
this.transport = transport;
final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
final JPanel commandPanel = statusBar.getCommandPanel();
button.setIcon(transport.getInactiveIcon());
button.setToolTipText(transport.getInstructions());
commandPanel.add(button);
statusBar.invalidate();
statusBar.validate();
statusBar.repaint();
button.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent mouseEvent) {
handlePopup(mouseEvent);
}
});
// Send directed presence if registered with this transport.
final boolean isRegistered = TransportUtils.isRegistered(SparkManager.getConnection(), transport);
if (isRegistered) {
// Check if auto login is set.
boolean autoJoin = TransportUtils.autoJoinService(transport.getServiceName());
if (autoJoin) {
Presence presence = statusBar.getPresence();
presence.setTo(transport.getServiceName());
SparkManager.getConnection().sendPacket(presence);
}
}
}
/**
* Handles the display of a popup menu when a transport button is clicked.
*
* @param event the MouseEvent.
*/
private void handlePopup(MouseEvent event) {
final JPopupMenu popupMenu = new JPopupMenu();
// Create action to sign off of transport.
final JMenuItem signOutMenu = new JMenuItem(Res.getString("menuitem.sign.out"));
signOutMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
final Presence offlinePresence = new Presence(Presence.Type.unavailable);
offlinePresence.setTo(transport.getServiceName());
SparkManager.getConnection().sendPacket(offlinePresence);
}
});
// Create menu to sign in.
final JMenuItem signInMenu = new JMenuItem(Res.getString("menuitem.sign.in"));
signInMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
final Presence onlinePresence = new Presence(Presence.Type.available);
onlinePresence.setTo(transport.getServiceName());
SparkManager.getConnection().sendPacket(onlinePresence);
}
});
// Create menu item to toggle signing in at startup.
final JCheckBoxMenuItem signInAtLoginMenu = new JCheckBoxMenuItem();
signInAtLoginMenu.setText(Res.getString("menuitem.sign.in.at.login"));
signInAtLoginMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
TransportUtils.setAutoJoin(transport.getServiceName(), signInAtLoginMenu.isSelected());
}
});
final JMenuItem registerMenu = new JMenuItem(Res.getString("menuitem.enter.login.information"));
registerMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
TransportRegistrationDialog registrationDialog = new TransportRegistrationDialog(transport.getServiceName());
registrationDialog.invoke();
}
});
// Create action to delete login information
final JMenuItem unregisterMenu = new JMenuItem(Res.getString("menuitem.delete.login.information"));
unregisterMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
try {
TransportUtils.unregister(SparkManager.getConnection(), transport.getServiceName());
}
catch (XMPPException e1) {
Log.error(e1);
}
}
}
});
// If user is not registered with the gateway
boolean reg = TransportUtils.isRegistered(SparkManager.getConnection(), transport);
if (!reg) {
popupMenu.add(registerMenu);
popupMenu.addSeparator();
signInMenu.setEnabled(false);
popupMenu.add(signInMenu);
signInAtLoginMenu.setEnabled(false);
popupMenu.add(signInAtLoginMenu);
popupMenu.show((Component)event.getSource(), event.getX(), event.getY());
return;
}
if (signedIn) {
popupMenu.add(signOutMenu);
}
else {
popupMenu.add(signInMenu);
}
boolean autoJoin = TransportUtils.autoJoinService(transport.getServiceName());
signInAtLoginMenu.setSelected(autoJoin);
popupMenu.add(signInAtLoginMenu);
popupMenu.addSeparator();
popupMenu.add(unregisterMenu);
popupMenu.show((Component)event.getSource(), event.getX(), event.getY());
}
public void signedIn(boolean signedIn) {
if (!signedIn) {
button.setIcon(transport.getInactiveIcon());
}
else {
button.setIcon(transport.getIcon());
}
this.signedIn = signedIn;
}
}

View File

@ -10,7 +10,6 @@
package org.jivesoftware.sparkimpl.plugin.gateways; package org.jivesoftware.sparkimpl.plugin.gateways;
import org.jivesoftware.resource.Res;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.Roster; import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
@ -26,14 +25,12 @@ import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.packet.DiscoverItems.Item; import org.jivesoftware.smackx.packet.DiscoverItems.Item;
import org.jivesoftware.spark.ChatManager; import org.jivesoftware.spark.ChatManager;
import org.jivesoftware.spark.SparkManager; import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.plugin.Plugin; import org.jivesoftware.spark.plugin.Plugin;
import org.jivesoftware.spark.ui.ContactGroup; import org.jivesoftware.spark.ui.ContactGroup;
import org.jivesoftware.spark.ui.ContactItem; import org.jivesoftware.spark.ui.ContactItem;
import org.jivesoftware.spark.ui.ContactItemHandler; import org.jivesoftware.spark.ui.ContactItemHandler;
import org.jivesoftware.spark.ui.ContactList; import org.jivesoftware.spark.ui.ContactList;
import org.jivesoftware.spark.ui.PresenceListener; import org.jivesoftware.spark.ui.PresenceListener;
import org.jivesoftware.spark.ui.status.StatusBar;
import org.jivesoftware.spark.util.SwingWorker; import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.log.Log; import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.AIMTransport; import org.jivesoftware.sparkimpl.plugin.gateways.transports.AIMTransport;
@ -44,11 +41,7 @@ import org.jivesoftware.sparkimpl.plugin.gateways.transports.TransportUtils;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.YahooTransport; import org.jivesoftware.sparkimpl.plugin.gateways.transports.YahooTransport;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -65,7 +58,7 @@ public class GatewayPlugin implements Plugin, ContactItemHandler {
*/ */
public static final String GATEWAY = "gateway"; public static final String GATEWAY = "gateway";
private Map<Transport, RolloverButton> uiMap = new HashMap<Transport, RolloverButton>(); private Map<Transport, GatewayButton> uiMap = new HashMap<Transport, GatewayButton>();
public void initialize() { public void initialize() {
@ -73,9 +66,6 @@ public class GatewayPlugin implements Plugin, ContactItemHandler {
public Object construct() { public Object construct() {
try { try {
populateTransports(SparkManager.getConnection()); populateTransports(SparkManager.getConnection());
for (final Transport transport : TransportUtils.getTransports()) {
addTransport(transport);
}
} }
catch (Exception e) { catch (Exception e) {
Log.error(e); Log.error(e);
@ -91,9 +81,12 @@ public class GatewayPlugin implements Plugin, ContactItemHandler {
return; return;
} }
for (final Transport transport : TransportUtils.getTransports()) {
addTransport(transport);
}
// Register presences. // Register presences.
registerPresenceListener(); registerPresenceListener();
} }
}; };
@ -157,54 +150,8 @@ public class GatewayPlugin implements Plugin, ContactItemHandler {
} }
private void addTransport(final Transport transport) { private void addTransport(final Transport transport) {
final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar(); final GatewayButton button = new GatewayButton(transport);
final JPanel commandPanel = statusBar.getCommandPanel();
final RolloverButton button = new RolloverButton();
button.setIcon(transport.getInactiveIcon());
button.setToolTipText(transport.getInstructions());
commandPanel.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
boolean reg = TransportUtils.isRegistered(SparkManager.getConnection(), transport);
if (!reg) {
TransportRegistrationDialog regDialog = new TransportRegistrationDialog(transport.getServiceName());
regDialog.invoke();
}
else {
int confirm = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.disable.transport"), Res.getString("title.disable.transport"), JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
try {
TransportUtils.unregister(SparkManager.getConnection(), transport.getServiceName());
}
catch (XMPPException e1) {
Log.error(e1);
}
}
}
}
});
uiMap.put(transport, button); uiMap.put(transport, button);
statusBar.invalidate();
statusBar.validate();
statusBar.repaint();
// Send directed presence if registered with this transport.
final boolean isRegistered = TransportUtils.isRegistered(SparkManager.getConnection(), transport);
if (isRegistered) {
Presence presence = statusBar.getPresence();
presence.setTo(transport.getServiceName());
SparkManager.getConnection().sendPacket(presence);
}
} }
private void registerPresenceListener() { private void registerPresenceListener() {
@ -217,13 +164,9 @@ public class GatewayPlugin implements Plugin, ContactItemHandler {
if (presence.getType() == Presence.Type.unavailable) { if (presence.getType() == Presence.Type.unavailable) {
registered = false; registered = false;
} }
RolloverButton button = uiMap.get(transport);
if (!registered) { GatewayButton button = uiMap.get(transport);
button.setIcon(transport.getInactiveIcon()); button.signedIn(registered);
}
else {
button.setIcon(transport.getIcon());
}
} }

View File

@ -0,0 +1,121 @@
/**
* $Revision$
* $Date$
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.sparkimpl.plugin.gateways;
import org.jivesoftware.smackx.packet.PrivateData;
import org.jivesoftware.smackx.provider.PrivateDataProvider;
import org.xmlpull.v1.XmlPullParser;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* Handle Gateway preferences through private data to persist through seperate locations of the client.
*
* @author Derek DeMoro
*/
public class GatewayPrivateData implements PrivateData {
private final Map<String, String> loginSettingsMap = new HashMap<String, String>();
public static final String ELEMENT = "gateway-settings";
public static final String NAMESPACE = "http://www.jivesoftware.org/spark";
public void addService(String serviceName, boolean autoLogin) {
loginSettingsMap.put(serviceName, Boolean.toString(autoLogin));
}
public boolean autoLogin(String serviceName) {
String str = loginSettingsMap.get(serviceName);
if(str == null){
return true;
}
return Boolean.parseBoolean(str);
}
public String getElementName() {
return ELEMENT;
}
public String getNamespace() {
return NAMESPACE;
}
public String toXML() {
StringBuffer buf = new StringBuffer();
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\">");
buf.append("<gateways>");
Iterator iter = loginSettingsMap.keySet().iterator();
while (iter.hasNext()) {
buf.append("<gateway>");
String serviceName = (String)iter.next();
String autoLogin = loginSettingsMap.get(serviceName);
buf.append("<serviceName>" + serviceName + "</serviceName>");
buf.append("<autoLogin>" + autoLogin + "</autoLogin>");
buf.append("</gateway>");
}
buf.append("</gateways>");
buf.append("</").append(getElementName()).append(">");
return buf.toString();
}
public static class ConferencePrivateDataProvider implements PrivateDataProvider {
public ConferencePrivateDataProvider() {
}
public PrivateData parsePrivateData(XmlPullParser parser) throws Exception {
GatewayPrivateData data = new GatewayPrivateData();
boolean done = false;
boolean isInstalled = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("gateways")) {
isInstalled = true;
}
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("gateway")) {
boolean gatewayDone = false;
String serviceName = null;
String autoLogin = null;
while (!gatewayDone) {
int eType = parser.next();
if (eType == XmlPullParser.START_TAG && parser.getName().equals("serviceName")) {
serviceName = parser.nextText();
}
else if (eType == XmlPullParser.START_TAG && parser.getName().equals("autoLogin")) {
autoLogin = parser.nextText();
}
else if (eType == XmlPullParser.END_TAG && parser.getName().equals("gateway")) {
data.addService(serviceName, Boolean.parseBoolean(autoLogin));
gatewayDone = true;
}
}
}
else if (eventType == XmlPullParser.END_TAG && parser.getName().equals("gateways")) {
done = true;
}
else if (!isInstalled) {
done = true;
}
}
return data;
}
}
}

View File

@ -66,7 +66,7 @@ public class TransportRegistrationDialog extends JPanel implements ActionListene
this.serviceName = serviceName; this.serviceName = serviceName;
ResourceUtils.resButton(registerButton, Res.getString("button.register")); ResourceUtils.resButton(registerButton, Res.getString("button.save"));
ResourceUtils.resButton(cancelButton, Res.getString("button.cancel")); ResourceUtils.resButton(cancelButton, Res.getString("button.cancel"));

View File

@ -16,23 +16,55 @@ import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter; import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.Registration; import org.jivesoftware.smack.packet.Registration;
import org.jivesoftware.smackx.PrivateDataManager;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.gateways.GatewayPrivateData;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* * Handles some basic handling of
*/ */
public class TransportUtils { public class TransportUtils {
private static Map<String, Transport> transports = new HashMap<String, Transport>(); private static Map<String, Transport> transports = new HashMap<String, Transport>();
private static GatewayPrivateData gatewayPreferences;
private TransportUtils() { private TransportUtils() {
}
static {
PrivateDataManager.addPrivateDataProvider(GatewayPrivateData.ELEMENT, GatewayPrivateData.NAMESPACE, new GatewayPrivateData.ConferencePrivateDataProvider());
PrivateDataManager pdm = SparkManager.getSessionManager().getPersonalDataManager();
try {
gatewayPreferences = (GatewayPrivateData)pdm.getPrivateData(GatewayPrivateData.ELEMENT, GatewayPrivateData.NAMESPACE);
}
catch (XMPPException e) {
Log.error("Unable to load private data for Gateways", e);
}
}
public static boolean autoJoinService(String serviceName) {
return gatewayPreferences.autoLogin(serviceName);
}
public static void setAutoJoin(String serviceName, boolean autoJoin) {
gatewayPreferences.addService(serviceName, autoJoin);
PrivateDataManager pdm = SparkManager.getSessionManager().getPersonalDataManager();
try {
pdm.setPrivateData(gatewayPreferences);
}
catch (XMPPException e) {
Log.error(e);
}
} }
public static Transport getTransport(String serviceName) { public static Transport getTransport(String serviceName) {
@ -52,20 +84,39 @@ public class TransportUtils {
return transports.values(); return transports.values();
} }
/**
* Checks if the user is registered with a gateway.
*
* @param con the XMPPConnection.
* @param transport the transport.
* @return true if the user is registered with the transport.
*/
public static boolean isRegistered(XMPPConnection con, Transport transport) { public static boolean isRegistered(XMPPConnection con, Transport transport) {
Presence presence = con.getRoster().getPresence(transport.getServiceName()); ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con);
boolean registered = presence != null && presence.getMode() != null; try {
if (presence == null || presence.getType() == Presence.Type.unavailable) { DiscoverInfo info = discoveryManager.discoverInfo(transport.getServiceName());
registered = false; return info.containsFeature("jabber:iq:registered");
} }
return registered; catch (XMPPException e) {
Log.error(e);
}
return false;
} }
/**
* Registers a user with a gateway.
*
* @param con the XMPPConnection.
* @param gatewayDomain the domain of the gateway (service name)
* @param username the username.
* @param password the password.
* @throws XMPPException thrown if there was an issue registering with the gateway.
*/
public static void registerUser(XMPPConnection con, String gatewayDomain, String username, String password) throws XMPPException { public static void registerUser(XMPPConnection con, String gatewayDomain, String username, String password) throws XMPPException {
Registration registration = new Registration(); Registration registration = new Registration();
registration.setType(IQ.Type.SET); registration.setType(IQ.Type.SET);
registration.setTo(gatewayDomain); registration.setTo(gatewayDomain);
registration.addExtension(new GatewayRegisterExtension());
Map<String, String> attributes = new HashMap<String, String>(); Map<String, String> attributes = new HashMap<String, String>();
attributes.put("username", username); attributes.put("username", username);
@ -86,6 +137,11 @@ public class TransportUtils {
} }
/**
* @param con
* @param gatewayDomain
* @throws XMPPException
*/
public static void unregister(XMPPConnection con, String gatewayDomain) throws XMPPException { public static void unregister(XMPPConnection con, String gatewayDomain) throws XMPPException {
Registration registration = new Registration(); Registration registration = new Registration();
registration.setType(IQ.Type.SET); registration.setType(IQ.Type.SET);
@ -106,7 +162,25 @@ public class TransportUtils {
if (response.getType() == IQ.Type.ERROR) { if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException("Error registering user", response.getError()); throw new XMPPException("Error registering user", response.getError());
} }
}
static class GatewayRegisterExtension implements PacketExtension {
public String getElementName() {
return "x";
}
public String getNamespace() {
return "jabber:iq:gateway:register";
}
public String toXML() {
StringBuilder builder = new StringBuilder();
builder.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
"\"/>");
return builder.toString();
}
} }
} }

View File

@ -124,7 +124,7 @@ public class ChatTranscriptPlugin implements ChatRoomListener {
public void reconnectingIn(int i) { public void reconnectingIn(int i) {
} }
public void reconectionSuccessful() { public void reconnectionSuccessful() {
} }
public void reconnectionFailed(Exception exception) { public void reconnectionFailed(Exception exception) {

View File

@ -61,6 +61,18 @@
## Added key: 'Broadcast' ## Added key: 'Broadcast'
## Added key: 'label.user.on.public.network' ## Added key: 'label.user.on.public.network'
## Added key: 'label.network' ## Added key: 'label.network'
##
##
## 2.0.6
## Added key: 'button.add.user'
## Added key: 'menuitem.sign.in'
## Added key: 'menuitem.sign.out'
## Added key: 'menuitem.sign.in.at.login'
## Added key: 'menuitem.enter.login.information'
## Added key: 'menuitem.delete.login.information'
## Added key: 'button.save'
ok = Ok ok = Ok
cancel = Cancel cancel = Cancel
@ -121,6 +133,8 @@ button.search = &Search
button.add.service = &Add Service button.add.service = &Add Service
button.quit = &Quit button.quit = &Quit
button.new = &New button.new = &New
button.add.user = &Add User
button.save = &Save
checkbox.save.password = &Save Password checkbox.save.password = &Save Password
checkbox.auto.login = &Auto Login checkbox.auto.login = &Auto Login
@ -233,8 +247,8 @@ message.supply.valid.timeout = Supply a valid time out value.
message.supply.valid.port = Supply a valid port. message.supply.valid.port = Supply a valid port.
message.supply.resource = Supply a valid resource. message.supply.resource = Supply a valid resource.
message.current.status = Let others know your current status or activity. message.current.status = Let others know your current status or activity.
message.disconnected.error = Disconnected from the server message.disconnected.error = Your connection was closed due to an error.
message.disconnected.conflict.error = User logged in from other location. message.disconnected.conflict.error = Your connection was closed due to the same user logging in from another location.
message.locked.workstation = User has locked their workstation. message.locked.workstation = User has locked their workstation.
message.away.idle = Away due to idle. message.away.idle = Away due to idle.
message.default.error = An error has been detected. Please report to support@jivesoftware.com. message.default.error = An error has been detected. Please report to support@jivesoftware.com.
@ -258,9 +272,9 @@ message.enter.broadcast.message = Enter message to broadcast to selected users.
message.name.of.group = Name of Group message.name.of.group = Name of Group
message.approve.subscription = Allow {0} to add you to their roster? message.approve.subscription = Allow {0} to add you to their roster?
message.add.user = Add user to your roster? message.add.user = Add user to your roster?
message.general.error = Disconnected from server due to {0} message.general.error = You have lost your connection to the server due to {0}.
message.add.a.contact = Add a contact. message.add.a.contact = Add a contact.
message.generic.reconnect.message = Disconnected from the server message.generic.reconnect.message = You have lost your connection to the server. To login again, click on the Reconnect button below.
message.select.one.or.more = Select one ore more users in your Roster. message.select.one.or.more = Select one ore more users in your Roster.
message.add.conference.service = Add a conference service. message.add.conference.service = Add a conference service.
message.service.already.exists = Service is already in your service list. message.service.already.exists = Service is already in your service list.
@ -359,14 +373,14 @@ message.unable.to.send.file = You were unable to send the file to {0}.
message.sending.file.to = Sending file to {0}. message.sending.file.to = Sending file to {0}.
message.you.have.sent = You have sent a file to {0}. message.you.have.sent = You have sent a file to {0}.
message.file.transfer.rejected = The file transfer was not accepted by {0}. message.file.transfer.rejected = The file transfer was not accepted by {0}.
message.disable.transport = Would you like to disable this active transport? message.disable.transport = Remove login information from gateway?
message.register.transports = Register with these available transports. message.register.transports = Register with these available transports.
message.enter.aim = Enter your AIM Screen Name and password below. message.enter.aim = Enter your AIM username and password below.
message.enter.msn = Enter your MSN Screen Name and password below. message.enter.msn = Enter your MSN username and password below.
message.enter.yahoo = Enter your Screen Name and password to connect to Yahoo. message.enter.yahoo = Enter your username and password to connect to Yahoo.
message.enter.icq = Enter your ICQ Screen Name and password below. message.enter.icq = Enter your ICQ username and password below.
message.username.password.error = Username and/or Password need to be supplied. message.username.password.error = Username and/or Password need to be supplied.
message.registration.transport.failed = Unable to register with Transport. message.registration.transport.failed = Unable to register with gateway.
message.client.information = Client information for {0} message.client.information = Client information for {0}
message.calling = Calling {0} message.calling = Calling {0}
message.number.to.call = Specify number to dial message.number.to.call = Specify number to dial
@ -466,13 +480,13 @@ title.start.chat = Start Chat
title.view.bookmarks = View Bookmarks title.view.bookmarks = View Bookmarks
title.downloads = Downloads title.downloads = Downloads
title.file.exists = File Exists title.file.exists = File Exists
title.disable.transport = Disable Transport title.disable.transport = Remove Login Information
title.available.transports = Available Transports title.available.transports = Available Transports
title.transports = Transports title.transports = Transports
title.aim.registration = AIM Registration title.aim.registration = AIM Account Credentials
title.msn.registration = MSN Registration title.msn.registration = MSN Account Credentials
title.yahoo.registration = Yahoo Registration title.yahoo.registration = Yahoo Account Credentials
title.icq.registration = ICQ Registration title.icq.registration = ICQ Account Credentials
title.registration.error = Registration Error title.registration.error = Registration Error
title.jabber.browser = Browser title.jabber.browser = Browser
title.version.and.time = Version and Time title.version.and.time = Version and Time
@ -581,6 +595,11 @@ menuitem.edit.my.profile = &Edit My Profile...
menuitem.lookup.profile = &Lookup Profile... menuitem.lookup.profile = &Lookup Profile...
menuitem.add.as.contact = Add as a contact menuitem.add.as.contact = Add as a contact
menuitem.chat = Chat menuitem.chat = Chat
menuitem.sign.in = Sign in
menuitem.sign.out = Sign out
menuitem.sign.in.at.login = Sign in at login
menuitem.enter.login.information = Enter login information
menuitem.delete.login.information = Delete login information
tree.conference.services = Conference Services tree.conference.services = Conference Services
tree.users.in.room = Users In Room tree.users.in.room = Users In Room