SPARK-221 Sparkplugs not stick on restart on the Mac.

SPARK-293  	 Cancel of Spark Manager download does not actually close the inputstream.
SPARK-88  	 Updater should check for downloaded version of file in cases where the user does not want to restart.
SPARK-323  	 auto-away should change presence priority to 0
SPARK-324  	 Add presence status change on exit of Spark

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@4750 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2006-08-01 14:41:22 +00:00
committed by derek
parent 997a4bd14b
commit dff79629ed
8 changed files with 206 additions and 91 deletions

View File

@ -13,12 +13,14 @@ package org.jivesoftware;
import org.jivesoftware.resource.Default;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.util.BrowserLauncher;
import org.jivesoftware.spark.util.ResourceUtils;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.alerts.InputTextAreaDialog;
import org.jivesoftware.sparkimpl.settings.JiveInfo;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import org.jivesoftware.sparkimpl.updater.CheckUpdates;
@ -240,19 +242,57 @@ public final class MainWindow extends JFrame implements ActionListener {
* setting the Agent to be offline.
*/
public void logout() {
// Set auto-login to false;
final XMPPConnection con = SparkManager.getConnection();
if (con.isConnected()) {
final InputTextAreaDialog inputTextDialog = new InputTextAreaDialog();
String status = inputTextDialog.getInput("Status Message", "Let others know your current status or activity.",
SparkRes.getImageIcon(SparkRes.USER1_MESSAGE_24x24), this);
if (status != null) {
Presence presence = new Presence(Presence.Type.UNAVAILABLE);
presence.setStatus(status);
con.sendPacket(presence);
}
}
// Set auto-login to false
SettingsManager.getLocalPreferences().setAutoLogin(false);
// Notify all MainWindowListeners
try {
fireWindowShutdown();
setVisible(false);
}
finally {
final SwingWorker shutdownThread = new SwingWorker() {
public Object construct() {
try {
Thread.sleep(10);
}
catch (InterruptedException e) {
Log.error(e);
}
return true;
}
public void finished() {
closeConnectionAndInvoke();
}
};
shutdownThread.start();
}
}
private void closeConnectionAndInvoke() {
final XMPPConnection con = SparkManager.getConnection();
if (con.isConnected()) {
con.close();
}
}
finally {
try {
String command = "";
@ -271,7 +311,6 @@ public final class MainWindow extends JFrame implements ActionListener {
System.exit(1);
}
}
/**
* Setup the Main Toolbar with File, Tools and Help.

View File

@ -12,15 +12,8 @@ package org.jivesoftware;
import org.jivesoftware.resource.Default;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow;
import org.jivesoftware.spark.util.log.Log;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.jivesoftware.sparkimpl.settings.JiveInfo;
import java.awt.Color;
import java.awt.Font;
@ -28,6 +21,12 @@ import java.awt.Insets;
import java.io.File;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
/**
* In many cases, you will need to know the structure of the Spark installation, such as the directory structures, what
* type of system Spark is running on, and also the arguments which were passed into Spark on startup. The <code>Spark</code>
@ -60,10 +59,10 @@ public final class Spark {
* @param args - Will receive arguments from Java Web Start.
*/
public static void main(final String[] args) {
EnhancedDebuggerWindow.PERSISTED_DEBUGGER = true;
/*EnhancedDebuggerWindow.PERSISTED_DEBUGGER = true;
EnhancedDebuggerWindow.MAX_TABLE_ROWS = 10;
XMPPConnection.DEBUG_ENABLED = true;
*/
String current = System.getProperty("java.library.path");
String classPath = System.getProperty("java.class.path");
@ -116,7 +115,6 @@ public final class Spark {
System.setProperty("sun.java2d.noddraw", "true");
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// Start Application

View File

@ -30,8 +30,6 @@ import org.jivesoftware.sparkimpl.plugin.manager.Features;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import javax.swing.SwingUtilities;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@ -39,6 +37,8 @@ import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.SwingUtilities;
/**
* This manager is responsible for the handling of the XMPPConnection used within Spark. This is used
* for the changing of the users presence, the handling of connection errors and the ability to add
@ -62,6 +62,8 @@ public final class SessionManager implements ConnectionListener {
private boolean unavaliable = false;
private DiscoverItems discoverItems;
private int previousPriority = -1;
public SessionManager() {
}
@ -309,6 +311,10 @@ public final class SessionManager implements ConnectionListener {
else {
p.setStatus("Away due to idle.");
}
previousPriority = presence.getPriority();
p.setPriority(0);
SparkManager.getSessionManager().changePresence(p);
}
}
@ -337,6 +343,10 @@ public final class SessionManager implements ConnectionListener {
Workspace workspace = SparkManager.getWorkspace();
if (workspace != null) {
Presence presence = workspace.getStatusBar().getStatusItem("Online").getPresence();
if (previousPriority != -1) {
presence.setPriority(previousPriority);
}
SparkManager.getSessionManager().changePresence(presence);
unavaliable = false;
}

View File

@ -60,6 +60,7 @@ public class ConfirmDialog extends BackgroundPanel {
public void actionPerformed(ActionEvent actionEvent) {
if (listener != null) {
listener.yesOption();
listener = null;
}
dialog.dispose();
}

View File

@ -1925,7 +1925,7 @@ public final class ContactList extends JPanel implements ActionListener, Contact
public void connectionClosed() {
reconnect("The connection was closed.", false);
// No reason to reconnect.
}
private void reconnect(final String message, final boolean conflict) {

View File

@ -34,11 +34,13 @@ import java.beans.PropertyChangeListener;
/**
* <code>BroadcastDialog</code> class is used to create broadcast messages to be sent.
* <code>InputTextAreaDialog</code> class can be used for any input required that a simple text field could
* not handle.
*
* @author Derek DeMoro
* @version 1.0, 06/28/2005
*/
public final class BroadcastDialog implements PropertyChangeListener {
public final class InputTextAreaDialog implements PropertyChangeListener {
private JTextArea textArea;
private JTextField subjectField;
private JOptionPane optionPane;
@ -51,7 +53,7 @@ public final class BroadcastDialog implements PropertyChangeListener {
/**
* Empty Constructor.
*/
public BroadcastDialog() {
public InputTextAreaDialog() {
}
/**

View File

@ -17,7 +17,7 @@ public class JiveInfo {
}
public static String getVersion() {
return "1.1.9.5";
return "1.1.9.4";
}
public static String getOS() {

View File

@ -40,13 +40,6 @@ import org.jivesoftware.sparkimpl.settings.JiveInfo;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
@ -58,14 +51,18 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.TimerTask;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.text.html.HTMLEditorKit;
public class CheckUpdates {
private String mainUpdateURL;
private JProgressBar bar;
@ -224,33 +221,12 @@ public class CheckUpdates {
if (!cancel) {
downloadComplete = true;
ConfirmDialog confirm = new ConfirmDialog();
confirm.showConfirmDialog(SparkManager.getMainWindow(), "Download Complete",
"You will need to shut down the client to \n" +
"install the new version. Would you like to do that now?", "Yes", "No",
null);
confirm.setConfirmListener(new ConfirmListener() {
public void yesOption() {
try {
if (Spark.isWindows()) {
Runtime.getRuntime().exec(downloadedFile.getAbsolutePath());
promptForInstallation(downloadedFile, "Download Complete", "You will need to shut down the client to \n" +
"install the new version. Would you like to do that now?");
}
else if (Spark.isMac()) {
Runtime.getRuntime().exec("open " + downloadedFile.getCanonicalPath());
}
}
catch (IOException e) {
Log.error(e);
}
SparkManager.getMainWindow().shutdown();
}
public void noOption() {
}
});
else {
out.close();
downloadedFile.delete();
}
@ -362,13 +338,23 @@ public class CheckUpdates {
}
}
public void checkForUpdate(boolean forced) throws Exception {
/**
* Checks Spark Manager and/or Jive Software for the latest version of Spark.
*
* @param explicit true if the user explicitly asks for the latest version.
* @throws Exception
*/
public void checkForUpdate(boolean explicit) throws Exception {
if (UPDATING) {
return;
}
UPDATING = true;
if (isLocalBuildAvailable()) {
return;
}
LocalPreferences localPreferences = SettingsManager.getLocalPreferences();
Date lastChecked = localPreferences.getLastCheckForUpdates();
@ -389,7 +375,7 @@ public class CheckUpdates {
boolean dayOrLonger = weekAgo.getTime() >= lastChecked.getTime();
if (dayOrLonger || forced || sparkPluginInstalled) {
if (dayOrLonger || explicit || sparkPluginInstalled) {
// Check version on server.
lastChecked = new Date();
localPreferences.setLastCheckForUpdates(lastChecked);
@ -399,7 +385,7 @@ public class CheckUpdates {
if (serverVersion == null) {
UPDATING = false;
if (forced) {
if (explicit) {
JOptionPane.showMessageDialog(SparkManager.getMainWindow(), "There are no updates.", "No Updates", JOptionPane.INFORMATION_MESSAGE);
}
return;
@ -482,20 +468,16 @@ public class CheckUpdates {
* @return returns true if the first version is greater than the second.
*/
public boolean isGreater(String version1, String version2) {
List list = new ArrayList();
list.add(version1);
list.add(version2);
Collections.sort(list);
if (version1.equals(version2)) {
return false;
}
String topVersion = (String)list.get(1);
return topVersion.equals(version1);
return version1.compareTo(version2) >= 1;
}
/**
* Returns the latest version of Spark available via Spark Manager or Jive Software.
*
* @param connection the XMPPConnection to use.
* @return the information for about the latest Spark Client.
* @throws XMPPException
*/
public static SparkVersion getLatestVersion(XMPPConnection connection) throws XMPPException {
SparkVersion request = new SparkVersion();
request.setType(IQ.Type.GET);
@ -518,6 +500,13 @@ public class CheckUpdates {
return response;
}
/**
* Does a service discvery on the server to see if a Spark Manager
* is enabled.
*
* @param con the XMPPConnection to use.
* @return true if Spark Manager is available.
*/
public static boolean isSparkPluginInstalled(XMPPConnection con) {
if (!con.isConnected()) {
return false;
@ -542,5 +531,81 @@ public class CheckUpdates {
}
/**
* Prompts the user to install the latest Spark.
*
* @param downloadedFile the location of the latest downloaded client.
* @param title the title
* @param message the message
*/
private void promptForInstallation(final File downloadedFile, String title, String message) {
ConfirmDialog confirm = new ConfirmDialog();
confirm.showConfirmDialog(SparkManager.getMainWindow(), title,
message, "Yes", "No",
null);
confirm.setConfirmListener(new ConfirmListener() {
public void yesOption() {
try {
if (Spark.isWindows()) {
Runtime.getRuntime().exec(downloadedFile.getAbsolutePath());
}
else if (Spark.isMac()) {
Runtime.getRuntime().exec("open " + downloadedFile.getCanonicalPath());
}
}
catch (IOException e) {
Log.error(e);
}
SparkManager.getMainWindow().shutdown();
}
public void noOption() {
}
});
}
/**
* Checks to see if a new version of Spark has already been downloaded by not installed.
*
* @return true if a newer version exists.
*/
private boolean isLocalBuildAvailable() {
// Check the bin directory for previous downloads. If there is a
// newer version of Spark, ask if they wish to install.
if (Spark.isWindows()) {
File binDirectory = Spark.getBinDirectory();
File[] files = binDirectory.listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
String fileName = file.getName();
if (fileName.endsWith(".exe")) {
int index = fileName.indexOf("_");
// Add version number
String versionNumber = fileName.substring(index + 1);
int indexOfPeriod = versionNumber.indexOf(".");
versionNumber = versionNumber.substring(0, indexOfPeriod);
versionNumber = versionNumber.replaceAll("_", ".");
boolean isGreater = versionNumber.compareTo(JiveInfo.getVersion()) >= 1;
if (isGreater) {
// Prompt
promptForInstallation(file, "New Client Available", "You will need to shut down the client to \n" +
"install the new version.\n\n Would you like to do that now?");
return true;
}
else {
file.delete();
}
}
}
}
return false;
}
}