Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
donob4n committed Feb 29, 2020
2 parents 2756864 + da2826d commit 103c572
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
11 changes: 6 additions & 5 deletions qubesmanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,15 @@ def check_mem_changes(self):
# Linux specific limit: init memory must not be below
# max_mem_size/10.79 in order to allow scaling up to
# max_mem_size (or else "add_memory() failed: -17" problem)
if self.init_mem.value() * 10 < self.max_mem_size.value():
if self.vm.features.check_with_template('os', None) == 'Linux' and \
self.init_mem.value() * 10 < self.max_mem_size.value():
self.init_mem.setValue((self.max_mem_size.value() + 9) // 10)
QtWidgets.QMessageBox.warning(
self,
self.tr("Warning!"),
self.tr("Initial memory can not be less than one tenth "
"Max memory.<br>Setting initial memory to the minimum "
"allowed value."))
self.init_mem.setValue((self.max_mem_size.value() + 9) // 10)
self.tr("For Linux qubes, Initial memory can not be less than "
"one tenth Max memory.<br>Setting initial memory "
"to the minimum allowed value."))

def check_warn_dispvmnetvm(self):
if not hasattr(self.vm, 'default_dispvm'):
Expand Down
35 changes: 32 additions & 3 deletions qubesmanager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,44 @@
import quamash
from qubesadmin import events

from PyQt5 import QtWidgets, QtCore # pylint: disable=import-error
from PyQt5.QtGui import QIcon # pylint: disable=import-error
from PyQt5 import QtWidgets, QtCore, QtGui # pylint: disable=import-error


def _filter_internal(vm):
return (not vm.klass == 'AdminVM'
and not vm.features.get('internal', False))


class SizeSpinBox(QtWidgets.QSpinBox):
# pylint: disable=invalid-name, no-self-use
def __init__(self, *args, **kwargs):
super(SizeSpinBox, self).__init__(*args, **kwargs)

self.pattern = r'(\d+\.?\d?) ?(GB|MB)'
self.regex = re.compile(self.pattern)
self.validator = QtGui.QRegExpValidator(QtCore.QRegExp(
self.pattern), self)

def textFromValue(self, v: int) -> str:
if v > 1024:
return '{:.1f} GB'.format(v / 1024)

return '{} MB'.format(v)

def validate(self, text: str, pos: int):
return self.validator.validate(text, pos)

def valueFromText(self, text: str) -> int:
value, unit = self.regex.fullmatch(text.strip()).groups()

if unit == 'GB':
multiplier = 1024
else:
multiplier = 1

return int(float(value) * multiplier)


def prepare_choice(widget, holder, propname, choice, default,
filter_function=None, *,
icon_getter=None, allow_internal=None, allow_default=False,
Expand Down Expand Up @@ -171,7 +200,7 @@ def prepare_label_choice(widget, holder, propname, default, *args, **kwargs):
sorted(app.labels.values(), key=lambda l: l.index),
default, *args,
icon_getter=(lambda label:
QIcon.fromTheme(label.icon)),
QtGui.QIcon.fromTheme(label.icon)),
**kwargs)


Expand Down
23 changes: 15 additions & 8 deletions ui/settingsdlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@
<number>15</number>
</property>
<item row="1" column="1">
<widget class="QSpinBox" name="root_resize">
<widget class="SizeSpinBox" name="root_resize">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Values displayed using the binary definition of gigabyte and megabyte, i.e. 1024&lt;span style=&quot; vertical-align:super;&quot;&gt;3&lt;/span&gt; and 1024&lt;span style=&quot; vertical-align:super;&quot;&gt;2 &lt;/span&gt;bytes respectively.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="suffix">
<string>MiB</string>
</property>
<property name="maximum">
<number>1048576</number>
</property>
Expand All @@ -129,16 +129,16 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="max_priv_storage">
<widget class="SizeSpinBox" name="max_priv_storage">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Values displayed using the binary definition of gigabyte and megabyte, i.e. 1024&lt;span style=&quot; vertical-align:super;&quot;&gt;3&lt;/span&gt; and 1024&lt;span style=&quot; vertical-align:super;&quot;&gt;2 &lt;/span&gt;bytes respectively.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="suffix">
<string>MiB</string>
</property>
<property name="minimum">
<number>0</number>
</property>
Expand Down Expand Up @@ -1556,6 +1556,13 @@ The qube must be running to disable seamless mode; this setting is not persisten
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SizeSpinBox</class>
<extends>QSpinBox</extends>
<header>qubesmanager/utils.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>vmname</tabstop>
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.4
4.1.6

0 comments on commit 103c572

Please sign in to comment.