From e828c1d72c954e9cae37132e37eafc19127c6c7e Mon Sep 17 00:00:00 2001 From: Derek DeMoro Date: Tue, 1 Aug 2006 17:19:26 +0000 Subject: [PATCH] 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 --- .../filetransfer/SparkTransferManager.java | 36 +++-- .../preferences/FileTransferPreference.java | 124 ++++++++++++++++++ .../FileTransferPreferencePanel.java | 107 +++++++++++++++ .../org/jivesoftware/spark/ui/RetryPanel.java | 2 +- .../filetransfer/transfer/Downloads.java | 26 ++-- .../preference/chat/ChatPreferencePanel.java | 40 +----- .../sparkimpl/settings/JiveInfo.java | 2 +- .../settings/local/LocalPreferences.java | 7 +- .../settings/local/SettingsManager.java | 2 +- 9 files changed, 283 insertions(+), 63 deletions(-) create mode 100644 src/java/org/jivesoftware/spark/filetransfer/preferences/FileTransferPreference.java create mode 100644 src/java/org/jivesoftware/spark/filetransfer/preferences/FileTransferPreferencePanel.java diff --git a/src/java/org/jivesoftware/spark/filetransfer/SparkTransferManager.java b/src/java/org/jivesoftware/spark/filetransfer/SparkTransferManager.java index 358e6436..dd835237 100644 --- a/src/java/org/jivesoftware/spark/filetransfer/SparkTransferManager.java +++ b/src/java/org/jivesoftware/spark/filetransfer/SparkTransferManager.java @@ -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"); diff --git a/src/java/org/jivesoftware/spark/filetransfer/preferences/FileTransferPreference.java b/src/java/org/jivesoftware/spark/filetransfer/preferences/FileTransferPreference.java new file mode 100644 index 00000000..df48baf2 --- /dev/null +++ b/src/java/org/jivesoftware/spark/filetransfer/preferences/FileTransferPreference.java @@ -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(); + } +} diff --git a/src/java/org/jivesoftware/spark/filetransfer/preferences/FileTransferPreferencePanel.java b/src/java/org/jivesoftware/spark/filetransfer/preferences/FileTransferPreferencePanel.java new file mode 100644 index 00000000..87495a24 --- /dev/null +++ b/src/java/org/jivesoftware/spark/filetransfer/preferences/FileTransferPreferencePanel.java @@ -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 { + + } + } + +} diff --git a/src/java/org/jivesoftware/spark/ui/RetryPanel.java b/src/java/org/jivesoftware/spark/ui/RetryPanel.java index 502ab742..ee9711b7 100644 --- a/src/java/org/jivesoftware/spark/ui/RetryPanel.java +++ b/src/java/org/jivesoftware/spark/ui/RetryPanel.java @@ -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(); diff --git a/src/java/org/jivesoftware/sparkimpl/plugin/filetransfer/transfer/Downloads.java b/src/java/org/jivesoftware/sparkimpl/plugin/filetransfer/transfer/Downloads.java index 8a3b8292..c7518377 100644 --- a/src/java/org/jivesoftware/sparkimpl/plugin/filetransfer/transfer/Downloads.java +++ b/src/java/org/jivesoftware/sparkimpl/plugin/filetransfer/transfer/Downloads.java @@ -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 Downloads, * 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(); } diff --git a/src/java/org/jivesoftware/sparkimpl/preference/chat/ChatPreferencePanel.java b/src/java/org/jivesoftware/sparkimpl/preference/chat/ChatPreferencePanel.java index 3fc877a0..de59bc76 100644 --- a/src/java/org/jivesoftware/sparkimpl/preference/chat/ChatPreferencePanel.java +++ b/src/java/org/jivesoftware/sparkimpl/preference/chat/ChatPreferencePanel.java @@ -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); diff --git a/src/java/org/jivesoftware/sparkimpl/settings/JiveInfo.java b/src/java/org/jivesoftware/sparkimpl/settings/JiveInfo.java index 4987c3f8..f8820e6f 100644 --- a/src/java/org/jivesoftware/sparkimpl/settings/JiveInfo.java +++ b/src/java/org/jivesoftware/sparkimpl/settings/JiveInfo.java @@ -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() { diff --git a/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferences.java b/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferences.java index cfd87077..3bb7a645 100644 --- a/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferences.java +++ b/src/java/org/jivesoftware/sparkimpl/settings/local/LocalPreferences.java @@ -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) { diff --git a/src/java/org/jivesoftware/sparkimpl/settings/local/SettingsManager.java b/src/java/org/jivesoftware/sparkimpl/settings/local/SettingsManager.java index 0218872f..a48e165a 100644 --- a/src/java/org/jivesoftware/sparkimpl/settings/local/SettingsManager.java +++ b/src/java/org/jivesoftware/sparkimpl/settings/local/SettingsManager.java @@ -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"); }