]> source.dussan.org Git - tigervnc.git/commitdiff
r5138 did not completely resolve the problem with clipboard data consuming too much...
authorBrian Hinz <bphinz@users.sourceforge.net>
Sat, 11 Jan 2014 23:07:42 +0000 (23:07 +0000)
committerBrian Hinz <bphinz@users.sourceforge.net>
Sat, 11 Jan 2014 23:07:42 +0000 (23:07 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@5155 3789f03b-4d11-0410-bbf8-ca57d06f2519

java/com/tigervnc/vncviewer/ClipboardDialog.java
java/com/tigervnc/vncviewer/DesktopWindow.java
java/com/tigervnc/vncviewer/VncViewer.java

index 2c9b7d0feab6dbd4bf1bac63f15cd9d0f40c2f33..d4cde6e1c9c7aaf0206460e9e606562432bb5bea 100644 (file)
@@ -57,6 +57,11 @@ class ClipboardDialog extends Dialog implements ActionListener {
     pack();
   }
 
+  public boolean compareContentsTo(String str) {
+    return str.equals(textArea.getText());
+
+  }
+
   public void setContents(String str) {
     textArea.setText(str);
   }
index 4175746f38c48ad273375bcf832b7fbf4c26c7f5..e78ee277eff8a778bce68c9d6b79c88bbf4f7fb6 100644 (file)
@@ -35,6 +35,8 @@ import java.awt.image.*;
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
 import java.awt.datatransfer.Clipboard;
+import java.io.BufferedReader;
+import java.nio.CharBuffer;
 import javax.swing.*;
 
 import com.tigervnc.rfb.*;
@@ -362,28 +364,28 @@ class DesktopWindow extends JPanel implements Runnable, MouseListener,
     try {
       if (sm != null) sm.checkSystemClipboardAccess();
       Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
-      if (cb == null) return;
-      Transferable t = cb.getContents(null);
-      if ((t != null) && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
-        try {
-          String newContents = new String("");
-          if (t.getTransferData(DataFlavor.stringFlavor) != null) {
-            int len = Math.min(cc.viewer.maxCutText.getValue(),
-                               ((String)t.getTransferData(DataFlavor.stringFlavor)).length());
-            newContents = 
-              ((String)t.getTransferData(DataFlavor.stringFlavor)).substring(0, len);
-          }
-          if (!newContents.equals(cc.clipboardDialog.getContents())) {
-            if (cc.viewer.sendClipboard.getValue())
-              cc.writeClientCutText(newContents, newContents.length());
-            cc.clipboardDialog.setContents(newContents);
-          }
-        } catch(java.lang.Exception e) {
-          vlog.debug("Exception getting clipboard data: " + e.getMessage());
+      if (cb != null) {
+        Transferable t = cb.getContents(null);
+        if (t == null) return;
+        DataFlavor flavor = 
+          DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors());
+        if (flavor == null) return;
+        BufferedReader br = new BufferedReader(flavor.getReaderForText(t));
+        CharBuffer cbuf =
+          CharBuffer.allocate(VncViewer.maxCutText.getValue());
+        br.read(cbuf);
+        cbuf.flip();
+        String newContents = cbuf.toString();
+        if (!cc.clipboardDialog.compareContentsTo(newContents)) {
+          cc.clipboardDialog.setContents(newContents);
+          if (cc.viewer.sendClipboard.getValue())
+            cc.writeClientCutText(newContents, newContents.length());
         }
+        br.close();
+        System.gc();
       }
-    } catch(SecurityException e) {
-      vlog.debug("Cannot access the system clipboard");
+    } catch(java.lang.Exception e) {
+      vlog.debug("Exception getting clipboard data: " + e.getMessage());
     }
   }
 
index 8d9b23a674c1b1e558007565e051ec0ed86b9b09..87820e3c1480d42ebd0c09464ee331b7254a1a90 100644 (file)
@@ -561,7 +561,7 @@ public class VncViewer extends javax.swing.JApplet
   = new BoolParameter("SendClipboard",
                       "Send clipboard changes to the server",
                       true);
-  IntParameter maxCutText
+  static IntParameter maxCutText
   = new IntParameter("MaxCutText",
                      "Maximum permitted length of an outgoing clipboard update",
                      262144);