SPARK-305 Add a preference option to specify a download folder.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@4751 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro 2006-08-01 17:19:26 +00:00 committed by derek
parent dff79629ed
commit e828c1d72c
9 changed files with 283 additions and 63 deletions

View File

@ -28,6 +28,8 @@ import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer;
import org.jivesoftware.spark.ChatManager;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.filetransfer.preferences.FileTransferPreference;
import org.jivesoftware.spark.preference.PreferenceManager;
import org.jivesoftware.spark.ui.ChatInputEditor;
import org.jivesoftware.spark.ui.ChatRoom;
import org.jivesoftware.spark.ui.ChatRoomButton;
@ -48,20 +50,8 @@ import org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.Downloads;
import org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui.ReceiveMessage;
import org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui.SendMessage;
import org.jivesoftware.sparkimpl.plugin.manager.Enterprise;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import java.awt.AWTException;
import java.awt.Component;
@ -85,6 +75,20 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
/**
* Responsible for the handling of File Transfer within Spark. You would use the SparkManager
* for sending of images, files, multiple files and adding your own transfer listeners for plugin work.
@ -126,6 +130,10 @@ public class SparkTransferManager {
return;
}
// Register Preferences
PreferenceManager prefManager = SparkManager.getPreferenceManager();
prefManager.addPreference(new FileTransferPreference());
final JMenu actionsMenu = SparkManager.getMainWindow().getMenuByName("Actions");
JMenuItem downloadsMenu = new JMenuItem("", SparkRes.getImageIcon(SparkRes.DOWNLOAD_16x16));
ResourceUtils.resButton(downloadsMenu, "&View Downloads");

View File

@ -0,0 +1,124 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.spark.filetransfer.preferences;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.preference.Preference;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import java.io.File;
import javax.swing.Icon;
import javax.swing.JComponent;
/**
*
*/
public class FileTransferPreference implements Preference {
private FileTransferPreferencePanel ui;
private LocalPreferences localPreferences;
public FileTransferPreference() {
localPreferences = SettingsManager.getLocalPreferences();
int timeout = localPreferences.getFileTransferTimeout();
timeout = timeout * 60 * 1000;
OutgoingFileTransfer.setResponseTimeout(timeout);
ui = new FileTransferPreferencePanel();
}
public String getTitle() {
return "File Transfer Preferences";
}
public Icon getIcon() {
return SparkRes.getImageIcon(SparkRes.SEND_FILE_24x24);
}
public String getTooltip() {
return "Preferences for File Transfer.";
}
public String getListName() {
return "File Transfer";
}
public String getNamespace() {
return "FILE_TRANSFER";
}
public JComponent getGUI() {
return ui;
}
public void load() {
File downloadedDir = new File(SparkManager.getUserDirectory(), "downloads");
String downloadDirectory = localPreferences.getDownloadDir();
if (downloadDirectory == null) {
downloadDirectory = downloadedDir.getAbsolutePath();
}
int timeout = localPreferences.getFileTransferTimeout();
ui.setDownloadDirectory(downloadDirectory);
ui.setTimeout(Integer.toString(timeout));
}
public void commit() {
LocalPreferences pref = SettingsManager.getLocalPreferences();
String downloadDir = ui.getDownloadDirectory();
if (ModelUtil.hasLength(downloadDir)) {
pref.setDownloadDir(downloadDir);
}
String timeout = ui.getTimeout();
if (ModelUtil.hasLength(timeout)) {
int tout = 1;
try {
tout = Integer.parseInt(timeout);
}
catch (NumberFormatException e) {
}
pref.setFileTransferTimeout(tout);
OutgoingFileTransfer.setResponseTimeout(tout);
}
SettingsManager.saveSettings();
}
public boolean isDataValid() {
return true;
}
public String getErrorMessage() {
return null;
}
public Object getData() {
return null;
}
public void shutdown() {
commit();
}
}

View File

@ -0,0 +1,107 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.spark.filetransfer.preferences;
import org.jivesoftware.Spark;
import org.jivesoftware.spark.util.ResourceUtils;
import org.jivesoftware.spark.util.WindowsFileSystemView;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
*/
public class FileTransferPreferencePanel extends JPanel {
private JTextField timeoutField;
private JTextField downloadDirectoryField;
private JFileChooser fc;
public FileTransferPreferencePanel() {
setLayout(new GridBagLayout());
timeoutField = new JTextField();
downloadDirectoryField = new JTextField();
JLabel timeoutLabel = new JLabel();
JLabel downloadDirectoryLabel = new JLabel();
ResourceUtils.resLabel(timeoutLabel, timeoutField, "&Transfer Timeout(min):");
ResourceUtils.resLabel(downloadDirectoryLabel, downloadDirectoryField, "&Download Directory:");
add(timeoutLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
add(timeoutField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 100, 0));
add(downloadDirectoryLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
add(downloadDirectoryField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
final JButton button = new JButton();
ResourceUtils.resButton(button, "&Browse...");
add(button, new GridBagConstraints(2, 1, 1, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
pickFile("Choose Directory", downloadDirectoryField);
}
});
}
public void setTimeout(String minutes) {
timeoutField.setText(minutes);
}
public String getTimeout() {
return timeoutField.getText();
}
public void setDownloadDirectory(String dir) {
downloadDirectoryField.setText(dir);
}
public String getDownloadDirectory() {
return downloadDirectoryField.getText();
}
private void pickFile(String title, JTextField field) {
if (fc == null) {
fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (Spark.isWindows()) {
fc.setFileSystemView(new WindowsFileSystemView());
}
}
fc.setDialogTitle(title);
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
field.setText(file.getAbsolutePath());
}
else {
}
}
}

View File

@ -63,7 +63,7 @@ public class RetryPanel extends JPanel {
descriptionLabel = new WrappedLabel();
retryButton = new RolloverButton(SparkRes.getImageIcon(SparkRes.SMALL_CHECK));
cancelButton = new RolloverButton("Log Out", SparkRes.getImageIcon(SparkRes.SMALL_CIRCLE_DELETE));
cancelButton = new RolloverButton("Login", SparkRes.getImageIcon(SparkRes.SMALL_CIRCLE_DELETE));
layoutComponents();

View File

@ -23,15 +23,6 @@ import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
@ -41,6 +32,15 @@ import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class Downloads {
final JPanel mainPanel = new JPanel();
File downloadedDir;
@ -51,6 +51,8 @@ public class Downloads {
private JDialog dlg;
private JFileChooser chooser;
private LocalPreferences pref;
/**
* Returns the singleton instance of <CODE>Downloads</CODE>,
* creating it if necessary.
@ -82,8 +84,8 @@ public class Downloads {
dlg.setLocationRelativeTo(frame);
LocalPreferences pref = SettingsManager.getLocalPreferences();
downloadedDir = new File(SparkManager.getUserDirectory(), "downloads");
pref = SettingsManager.getLocalPreferences();
downloadedDir = new File(pref.getDownloadDir());
downloadedDir.mkdirs();
pref.setDownloadDir(downloadedDir.getAbsolutePath());
@ -180,7 +182,7 @@ public class Downloads {
}
public void showDownloadsDirectory() {
downloadedDir = new File(SparkManager.getUserDirectory(), "downloads");
downloadedDir = new File(pref.getDownloadDir());
if (!downloadedDir.exists()) {
downloadedDir.mkdirs();
}

View File

@ -13,15 +13,6 @@ package org.jivesoftware.sparkimpl.preference.chat;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.VerticalFlowLayout;
import org.jivesoftware.spark.util.ResourceUtils;
import org.jivesoftware.spark.util.ModelUtil;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
@ -30,6 +21,13 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
/**
* The Preference UI used to handle changing of Chat Preferences.
*/
@ -48,10 +46,6 @@ public class ChatPreferencePanel extends JPanel implements ActionListener {
private JLabel confirmationPasswordLabel = new JLabel();
private JCheckBox hideChatHistory = new JCheckBox();
private JTextField fileTransferTimeoutField = new JTextField();
/**
* Constructor invokes UI setup.
*/
@ -87,13 +81,6 @@ public class ChatPreferencePanel extends JPanel implements ActionListener {
chatWindowPanel.add(hideChatHistory, new GridBagConstraints(0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
final JLabel label = new JLabel();
ResourceUtils.resLabel(label, fileTransferTimeoutField, "&Transfer Timeout(min):");
chatWindowPanel.add(label, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
chatWindowPanel.add(fileTransferTimeoutField, new GridBagConstraints(1, 4, 1, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 100, 0));
generalPanel.add(passwordLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
generalPanel.add(passwordField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 100, 0));
generalPanel.add(confirmationPasswordLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
@ -163,19 +150,6 @@ public class ChatPreferencePanel extends JPanel implements ActionListener {
return hideChatHistory.isSelected();
}
public void setFileTransferTimeout(int timeout){
fileTransferTimeoutField.setText(Integer.toString(timeout));
}
/*
public int getFileTransferTimeout(){
String value = fileTransferTimeoutField.getText();
if(ModelUtil.hasLength(value)){
}
}
*/
public void actionPerformed(ActionEvent actionEvent) {
if (hideChatHistory.isSelected()) {
int ok = JOptionPane.showConfirmDialog(this, "Delete all previous history?", "Delete Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

View File

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

View File

@ -10,6 +10,9 @@
package org.jivesoftware.sparkimpl.settings.local;
import org.jivesoftware.spark.SparkManager;
import java.io.File;
import java.util.Date;
import java.util.Properties;
@ -242,7 +245,9 @@ public class LocalPreferences {
}
public String getDownloadDir() {
return props.getProperty("downloadDirectory");
File downloadedDir = new File(SparkManager.getUserDirectory(), "downloads");
return props.getProperty("downloadDirectory", downloadedDir.getAbsolutePath());
}
public void setDownloadDir(String downloadDir) {

View File

@ -83,7 +83,7 @@ public class SettingsManager {
if (!file.exists()) {
file.mkdirs();
}
return new File(file, "spark-settings.xml");
return new File(file, "spark.properties");
}