Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions icons/notes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions qubesmanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog):
('devices', 3),
('applications', 4),
('services', 5),
('notes', 6),
))

# pylint: disable=too-many-positional-arguments
Expand Down Expand Up @@ -273,6 +274,9 @@ def __init__(self, vm_name, init_page="basic", qapp=None, qubesapp=None,
self.warn_template_missing_apps.setVisible(
self.app_list_manager.has_missing)

####### notes tab
self.__init_notes_tab__()

def setup_application(self):
self.qapp.setApplicationName(self.tr("Qube Settings"))
self.qapp.setWindowIcon(QtGui.QIcon.fromTheme("qubes-manager"))
Expand Down Expand Up @@ -354,6 +358,9 @@ def __save_changes__(self):
ret_tmp = self.__apply_services_tab__()
if ret_tmp:
ret += [self.tr("Sevices tab:")] + ret_tmp
ret_tmp = self.__apply_notes_tab__()
if ret_tmp:
ret += [self.tr("Notes tab:")] + ret_tmp
except qubesadmin.exc.QubesException as qex:
ret.append(self.tr('Error while saving changes: ') + str(qex))
except Exception as ex: # pylint: disable=broad-except
Expand Down Expand Up @@ -1587,6 +1594,23 @@ def __init_services_tab__(self):
self.service_line_edit.addItem(self.tr('(custom...)'))
self.service_line_edit.setEditText("")

def __init_notes_tab__(self):
try:
self.notes.setPlainText(self.vm.get_notes())
except qubesadmin.exc.QubesException:
self.notes.setPlainText(
"Could not retrieve notes for this qube "
)
self.notes.setEnabled(False)

def __apply_notes_tab__(self):
try:
if self.notes.isEnabled():
if self.notes.toPlainText() != self.vm.get_notes():
self.vm.set_notes(self.notes.toPlainText())
except qubesadmin.exc.QubesException as ex:
return str(ex)

def __add_service__(self):
srv = str(self.service_line_edit.currentText()).strip()

Expand Down
7 changes: 7 additions & 0 deletions qubesmanager/tests/test_vm_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def settings_fixture(request, qapp, test_qubes_app) -> Tuple[
page = 'basic'
with mock.patch('subprocess.check_output') as mock_subprocess:
mock_subprocess.side_effect = mock_subprocess_complex
expected_call = (vm.name, 'admin.vm.notes.Get', None, None)
test_qubes_app.expected_calls[expected_call] = b'0\x00Some Notes\x00'
vms = vm_settings.VMSettingsWindow(vm, page, qapp,
test_qubes_app)

Expand Down Expand Up @@ -1313,6 +1315,7 @@ def test_306_firewall_unlimit(settings_fixture):
def test_307_open_with_limit(mock_subprocess, qapp, test_qubes_app):
# this test is supposed to check if the settings open even when there is
# an unlimited FW access set
# It also checks if inaccessible qube note is disabled
mock_subprocess.result = []

# add 2 minutes to now
Expand All @@ -1330,6 +1333,9 @@ def test_307_open_with_limit(mock_subprocess, qapp, test_qubes_app):
name="test-vm-fw", qapp=test_qubes_app, label="green",
firewall_rules=fw_rules
)
expected_call = ("test-vm-fw", 'admin.vm.notes.Get', None, None)
test_qubes_app.expected_calls[expected_call] = \
'2\0QubesNotesException\0\0Notes not available!\0'
test_qubes_app.update_vm_calls()

settings_window = vm_settings.VMSettingsWindow(
Expand All @@ -1341,6 +1347,7 @@ def test_307_open_with_limit(mock_subprocess, qapp, test_qubes_app):

assert settings_window.temp_full_access.isChecked()
assert settings_window.tempFullAccessWidget.isEnabled()
assert not settings_window.notes.isEnabled()


@check_errors
Expand Down
1 change: 1 addition & 0 deletions resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<file alias="killvm">icons/kill.svg</file>
<file alias="log">icons/log.svg</file>
<file alias="networking">icons/netvm.svg</file>
<file alias="notes">icons/notes.svg</file>
<file alias="obsolete.svg">icons/obsolete.svg</file>
<file alias="outdated">icons/outdated.svg</file>
<file alias="paused">icons/paused.svg</file>
Expand Down
24 changes: 24 additions & 0 deletions ui/settingsdlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,30 @@ The qube must be running to disable seamless mode. This setting is not persisten
</item>
</layout>
</widget>
<widget class="QWidget" name="notes_tab">
<attribute name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/notes</normaloff>:/notes</iconset>
</attribute>
<attribute name="title">
<string>Notes</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_notes_tab">
<item>
<layout class="QVBoxLayout" name="verticalLayout_notes">
<item>
<widget class="QPlainTextEdit" name="notes">
<property name="placeholderText">
<string>Notes and comments (up to 256KB of clear text)
For user reference only.
</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
Expand Down