Răsfoiți Sursa

Merge remote-tracking branch 'qubesos/pr/34'

* qubesos/pr/34:
  Show size of current inter-VM clipboard in Ctrl-Shift-C notification message
  Show size of current inter-VM clipboard in Ctrl-Shift-C notification message
Marek Marczykowski-Górecki 7 ani în urmă
părinte
comite
2a381227f2
2 a modificat fișierele cu 21 adăugiri și 1 ștergeri
  1. 18 0
      qubesmanager/clipboard.py
  2. 3 1
      qubesmanager/main.py

+ 18 - 0
qubesmanager/clipboard.py

@@ -24,6 +24,7 @@
 
 import os
 import fcntl
+from math import log
 
 from qubes.qubes import QubesException
 from PyQt4.QtGui import QApplication
@@ -57,3 +58,20 @@ def copy_text_to_qubes_clipboard(text):
                 QMessageBox.warning(None, "Warning!", "Error while writing to Qubes clipboard!")
             fcntl.flock(fd, fcntl.LOCK_UN)
         os.close(fd)
+
+def get_qubes_clipboard_formatted_size():
+    units = ['B', 'KiB', 'MiB', 'GiB']
+
+    try:
+        file_size = os.path.getsize(CLIPBOARD_CONTENTS)
+    except:
+        QMessageBox.warning(None, "Warning!", "Error while accessing Qubes clipboard!")
+    else:
+        formatted_bytes = '1 byte' if file_size == 1 else str(file_size) + ' bytes'
+        if file_size > 0:
+            magnitude = min(int(log(file_size)/log(2)*0.1), len(units)-1)
+            if magnitude > 0:
+                return '%s (%.1f %s)' % (formatted_bytes, file_size/(2.0**(10*magnitude)), units[magnitude])
+        return '%s' % (formatted_bytes)
+
+    return '? bytes'

+ 3 - 1
qubesmanager/main.py

@@ -104,9 +104,11 @@ class QubesManagerFileWatcher(ProcessEvent):
             else:
                 trayIcon.showMessage(unicode(app.tr(
                     "Qubes Clipboard fetched from VM: <b>'{0}'</b>\n"
+                    "Copied <b>{1}</b> to the clipboard.\n"
                     "<small>Press Ctrl-Shift-v to copy this clipboard into dest"
                     " VM's clipboard.</small>")).format(
-                        src_vmname), msecs=3000)
+                        src_vmname, get_qubes_clipboard_formatted_size()),
+                        msecs=3000)
             src_info_file.close()
 
     def process_IN_CREATE(self, event):