mirror of
https://github.com/igniterealtime/Spark.git
synced 2025-12-01 12:27:58 +00:00
SPARK-1358
new in default.properties:
FILE_TRANSFER_WARNING_SIZE = -1
FILE_TRANSFER_MAXIMUM_SIZE = -1
new locales:
message.file.transfer.file.too.big.error = The selected file is too big.\nThe maximum filezise is {0} the selected file has {1}
{0} = Maximum Size
{1] = Size of selected File
message.file.transfer.file.too.big.warning = The selected file is too big.\nProceed anyway?
git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@12449 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
committed by
wolf.posdorfer
parent
09117f007f
commit
f2cfe7c057
@ -69,6 +69,8 @@ public class Default {
|
||||
public static final String HELP_USER_GUIDE = "HELP_USER_GUIDE";
|
||||
public static final String BROADCAST_IN_CHATWINDOW = "BROADCAST_IN_CHATWINDOW";
|
||||
public static final String MENUBAR_TEXT = "MENUBAR_TEXT";
|
||||
public static final String FILE_TRANSFER_WARNING_SIZE = "FILE_TRANSFER_WARNING_SIZE";
|
||||
public static final String FILE_TRANSFER_MAXIMUM_SIZE = "FILE_TRANSFER_MAXIMUM_SIZE";
|
||||
|
||||
static ClassLoader cl = SparkRes.class.getClassLoader();
|
||||
|
||||
|
||||
@ -43,6 +43,27 @@ DISABLE_UPDATES =
|
||||
# users wont be able to shut down Spark
|
||||
DISABLE_EXIT =
|
||||
|
||||
#################################################
|
||||
################## File Transfer ################
|
||||
#################################################
|
||||
|
||||
# Specify a size on which Users will get a
|
||||
# warning of a possibly too big file
|
||||
# 10MB = 10485760
|
||||
# 100MB = 104857600
|
||||
# 1GB = 1073741824
|
||||
# default = -1 (infinity)
|
||||
# maximum is 9223372036854775806 byte = 8388608TB
|
||||
FILE_TRANSFER_WARNING_SIZE = -1
|
||||
|
||||
# Specify the Maximum file size to be permitted to send
|
||||
# 10MB = 10485760
|
||||
# 100MB = 104857600
|
||||
# 1GB = 1073741824
|
||||
# default = -1 (infinity)
|
||||
# maximum is 9223372036854775806 byte = 8.388.608 TB
|
||||
FILE_TRANSFER_MAXIMUM_SIZE = -1
|
||||
|
||||
|
||||
#################################################
|
||||
################## Main Window ##################
|
||||
|
||||
@ -66,6 +66,7 @@ import javax.swing.text.StyledDocument;
|
||||
|
||||
import org.jivesoftware.MainWindow;
|
||||
import org.jivesoftware.Spark;
|
||||
import org.jivesoftware.resource.Default;
|
||||
import org.jivesoftware.resource.Res;
|
||||
import org.jivesoftware.resource.SparkRes;
|
||||
import org.jivesoftware.smack.ConnectionListener;
|
||||
@ -103,6 +104,7 @@ import org.jivesoftware.spark.util.log.Log;
|
||||
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.filetransfer.transfer.ui.TransferUtils;
|
||||
import org.jivesoftware.sparkimpl.plugin.manager.Enterprise;
|
||||
|
||||
/**
|
||||
@ -538,6 +540,30 @@ public class SparkTransferManager {
|
||||
* @return the ChatRoom of the user.
|
||||
*/
|
||||
public ChatRoom sendFile(File file, String jid) {
|
||||
|
||||
long maxsize = Long.parseLong(Default.getString(Default.FILE_TRANSFER_MAXIMUM_SIZE));
|
||||
long warningsize = Long.parseLong(Default.getString(Default.FILE_TRANSFER_WARNING_SIZE));
|
||||
|
||||
|
||||
if(file.length()>= maxsize && maxsize != -1)
|
||||
{
|
||||
String maxsizeString = TransferUtils.getAppropriateByteWithSuffix(maxsize);
|
||||
String yoursizeString = TransferUtils.getAppropriateByteWithSuffix(file.length());
|
||||
String output = Res.getString("message.file.transfer.file.too.big.error", maxsizeString, yoursizeString);
|
||||
JOptionPane.showMessageDialog(null, output, Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
|
||||
return null;
|
||||
}
|
||||
|
||||
if(file.length() >= warningsize && warningsize != -1)
|
||||
{
|
||||
int result = JOptionPane.showConfirmDialog(null, Res.getString("message.file.transfer.file.too.big.warning"), Res.getString("title.error"), JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if(result != 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final ContactList contactList = SparkManager.getWorkspace().getContactList();
|
||||
String bareJID = StringUtils.parseBareAddress(jid);
|
||||
String fullJID = PresenceManager.getFullyQualifiedJID(jid);
|
||||
|
||||
@ -26,13 +26,13 @@ public class TransferUtils {
|
||||
if (kB < 1024) {
|
||||
String KB = Double.toString(kB);
|
||||
// Convert 3.1415926535897932384626433832795 to 3.1
|
||||
KB = KB.contains(".") ? KB.substring(0, KB.indexOf(".") + 2) : KB;
|
||||
KB = splitAtDot(KB, 1);
|
||||
|
||||
return KB + "kB/s";
|
||||
} else {
|
||||
String MB = Double.toString((kB / 1024.0));
|
||||
// Convert 3.1415926535897932384626433832795 to 3.1
|
||||
MB = MB.contains(".") ? MB.substring(0, MB.indexOf(".") + 2) : MB;
|
||||
MB = splitAtDot(MB, 1);
|
||||
|
||||
return MB + "MB/s";
|
||||
}
|
||||
@ -100,5 +100,59 @@ public class TransferUtils {
|
||||
return "(" + hh + ":" + mm + ":" + ss + ")";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a given Byte into KB or MB or GB if applicable
|
||||
* @param bytes
|
||||
* @return "12 KB" or "27 MB" etc
|
||||
*/
|
||||
public static String getAppropriateByteWithSuffix(long bytes)
|
||||
{
|
||||
if(bytes >= 1099511627776L)
|
||||
{
|
||||
String x = splitAtDot(""+(bytes/1099511627776L),2);
|
||||
return x +" TB";
|
||||
}
|
||||
else if(bytes >= 1073741824)
|
||||
{
|
||||
String x = splitAtDot(""+(bytes/1073741824L),2);
|
||||
return x +" GB";
|
||||
}
|
||||
else if(bytes >= 1048576)
|
||||
{
|
||||
String x = splitAtDot(""+(bytes/1048576L),2);
|
||||
return x +" MB";
|
||||
}
|
||||
else if(bytes >= 1024)
|
||||
{
|
||||
String x = splitAtDot(""+(bytes/1024L),2);
|
||||
return x +" KB";
|
||||
}
|
||||
else return bytes + " B";
|
||||
}
|
||||
/**
|
||||
* shorten a double or long with sig.digits<br>
|
||||
* splitAtDot("3.123",2) -> "3.12"<br>
|
||||
* does not round!
|
||||
* @param string
|
||||
* @param significantdigits
|
||||
* @return
|
||||
*/
|
||||
private static String splitAtDot(String string, int significantdigits) {
|
||||
if (string.contains(".")) {
|
||||
// no idea why but string.split doesnt like "."
|
||||
String s = string.replace(".", "T").split("T")[1];
|
||||
|
||||
if (s.length() >= significantdigits) {
|
||||
return string.substring(0, string.indexOf(".") + 1
|
||||
+ significantdigits);
|
||||
} else {
|
||||
return string
|
||||
.substring(0, string.indexOf(".") + 1 + s.length());
|
||||
}
|
||||
}
|
||||
else return string;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -680,6 +680,8 @@ message.file.transfer.rejected = The file transfer was not accepted by {0}
|
||||
message.file.transfer.notification = File transfer notification
|
||||
message.file.transfer.short.message = is sending you a file called\:
|
||||
message.file.transfer.chat.window = File transfer request:
|
||||
message.file.transfer.file.too.big.error = The selected file is too big.\nThe maximum filezise is {0} the selected file has {1}
|
||||
message.file.transfer.file.too.big.warning = The selected file is too big.\nProceed anyway?
|
||||
message.find.conference.services = Find conference services
|
||||
message.forbidden.error = Received a forbidden error from the server
|
||||
message.gateway.username.error = Username needs to be supplied
|
||||
|
||||
@ -473,6 +473,8 @@ message.transfer.cancelled = Der Dateitransfer wurde abgebrochen.
|
||||
message.transfer.complete = Der Dateitransfer war erfolgreich ({0})
|
||||
message.transfer.progressbar.text.received = {0} empfangen @ {1} {2}
|
||||
message.transfer.progressbar.text.sent = {0} gesendet @ {1} {2}
|
||||
message.file.transfer.file.too.big.error = Die ausgew<65>hlte Datei ist zu gro<72>.\nEs d<>rfen maximal {0} versandt werden, die ausgew<65>hlte Datei hat {1}
|
||||
message.file.transfer.file.too.big.warning = Die ausgew<65>hlte Datei ist zu gro<72>.\nDennoch fortfahren?
|
||||
message.file.exists.question = Die Datei existiert bereits. <20>berschreiben?
|
||||
message.transfer.waiting.on.user = {0} muss den Dateitransfer akzeptieren. Bitte warten...
|
||||
message.negotiation.file.transfer = Dateitransfer mit {0} wird initialisiert. Bitte warten...
|
||||
|
||||
Reference in New Issue
Block a user