From 9c284ebedbc309a562063258811c6ddf70103ce1 Mon Sep 17 00:00:00 2001 From: itinerarium Date: Sun, 28 May 2017 11:49:34 -0400 Subject: [PATCH 1/2] Show size of current inter-VM clipboard in Ctrl-Shift-C notification message QubesOS/qubes-issues#2825 --- qubesmanager/clipboard.py | 18 ++++++++++++++++++ qubesmanager/main.py | 5 +++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/qubesmanager/clipboard.py b/qubesmanager/clipboard.py index 21e8e8e..a869a4b 100644 --- a/qubesmanager/clipboard.py +++ b/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' diff --git a/qubesmanager/main.py b/qubesmanager/main.py index 4ac0fa9..fff2e10 100755 --- a/qubesmanager/main.py +++ b/qubesmanager/main.py @@ -104,10 +104,11 @@ class QubesManagerFileWatcher(ProcessEvent): else: trayIcon.showMessage(unicode(app.tr( "Qubes Clipboard fetched from VM: '{0}'\n" + "Copied {1} to the clipboard.\n" "Press Ctrl-Shift-v to copy this clipboard into dest" " VM's clipboard.")).format( - src_vmname), msecs=3000) - src_info_file.close() + src_vmname, get_qubes_clipboard_formatted_size()), + msecs=3000) def process_IN_CREATE(self, event): if event.name == os.path.basename(qubes_clipboard_info_file): From c2a340698ec0fb33b80231a2150bca05cfe2652b Mon Sep 17 00:00:00 2001 From: itinerarium Date: Sun, 28 May 2017 12:12:25 -0400 Subject: [PATCH 2/2] Show size of current inter-VM clipboard in Ctrl-Shift-C notification message Fix copy/paste error QubesOS/qubes-issues#2825 --- qubesmanager/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/qubesmanager/main.py b/qubesmanager/main.py index fff2e10..68890a3 100755 --- a/qubesmanager/main.py +++ b/qubesmanager/main.py @@ -109,6 +109,7 @@ class QubesManagerFileWatcher(ProcessEvent): " VM's clipboard.")).format( src_vmname, get_qubes_clipboard_formatted_size()), msecs=3000) + src_info_file.close() def process_IN_CREATE(self, event): if event.name == os.path.basename(qubes_clipboard_info_file):