1
0
Fork 0

Fix creation of copied system profile

This commit is contained in:
Tomas Korbar 2018-11-22 15:17:56 +01:00
parent bc9ae26787
commit 8cb5f9948e
3 changed files with 127 additions and 10 deletions

View file

@ -230,6 +230,74 @@
<action-widget response="-1">buttonCloseAddPlugin</action-widget>
</action-widgets>
</object>
<object class="GtkDialog" id="dialogYesNo">
<property name="can_focus">False</property>
<property name="type_hint">dialog</property>
<child>
<placeholder/>
</child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="margin_left">66</property>
<property name="layout_style">spread</property>
<child>
<object class="GtkButton" id="buttonPositiveYesNoDialog">
<property name="label" translatable="yes">Yes</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="buttonNegativeYesNoDialog">
<property name="label" translatable="yes">No</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="labelQuestionYesNoDialog">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="1">buttonPositiveYesNoDialog</action-widget>
<action-widget response="0">buttonNegativeYesNoDialog</action-widget>
</action-widgets>
</object>
<object class="GtkWindow" id="mainWindow">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Tuned Manager</property>

View file

@ -60,6 +60,7 @@ import tuned.gtk.gui_profile_loader
import tuned.gtk.gui_plugin_loader
import tuned.profiles.profile as profile
import tuned.utils.global_config
from tuned.gtk.tuned_dialog import TunedDialog
from tuned.gtk.managerException import ManagerException
@ -365,7 +366,13 @@ class Base(object):
'Please close edit window and try again.'
)
return
self.manager.remove_profile(profile, is_admin=self.is_admin)
try:
self.manager.remove_profile(profile, is_admin=self.is_admin)
except ManagerException:
self.error_dialog('failed to authorize', '')
return
for item in self.treestore_profiles:
if item[0] == profile:
iter = self.treestore_profiles.get_iter(item.path)
@ -484,7 +491,12 @@ class Base(object):
except KeyError:
raise KeyError('this cant happen')
self.manager.update_profile(profile_name, prof, self.is_admin)
try:
self.manager.update_profile(profile_name, prof, self.is_admin)
except ManagerException:
self.error_dialog('failed to authorize', '')
return
if self.manager.is_profile_factory(prof.name):
prefix = consts.PREFIX_PROFILE_FACTORY
else:
@ -517,7 +529,11 @@ class Base(object):
# try:
prof = self.data_to_profile_config()
self.manager.save_profile(prof)
try:
self.manager.save_profile(prof)
except ManagerException:
self.error_dialog('failed to authorize', '')
return
self.manager._load_all_profiles()
self.treestore_profiles.append([prof.name, consts.PREFIX_PROFILE_USER])
self._gobj('windowProfileEditor').hide()
@ -561,17 +577,28 @@ class Base(object):
if not self.manager.is_profile_removable(self.editing_profile_name):
if not self.manager.get_profile(
self.editing_profile_name + '-modified'):
self.error_dialog(
'Factory profile can not be modified',
'but you can use its copy')
if not TunedDialog('System profile can not be modified '
+ 'but you can create its copy',
'create copy',
'cancel'
).run():
return
copied_profile = self.manager.get_profile(
self.editing_profile_name)
copied_profile.name = self.editing_profile_name + '-modified'
self.manager.save_profile(copied_profile)
try:
self.manager.save_profile(copied_profile)
except ManagerException:
self.error_dialog('failed to authorize', '')
return
else:
self.error_dialog(
'Factory profile can not be modified',
'You can use its already existing copy')
if not TunedDialog('System profile can not be modified '
+ 'but you can use its copy',
'open copy',
'cancel'
).run():
return
copied_profile = self.manager.get_profile(
self.editing_profile_name + '-modified')
self._update_profile_list()

22
tuned/gtk/tuned_dialog.py Normal file
View file

@ -0,0 +1,22 @@
from gi.repository import Gtk
GLADEUI = '/usr/share/tuned/ui/tuned-gui.glade'
class TunedDialog():
def __init__(self, msg, yes_button_text, no_button_text):
self._builder = Gtk.Builder()
self._builder.add_from_file(GLADEUI)
self._builder.get_object("labelQuestionYesNoDialog").set_text(msg)
self._builder.get_object("buttonPositiveYesNoDialog").set_label(
yes_button_text
)
self._builder.get_object("buttonNegativeYesNoDialog").set_label(
no_button_text
)
def run(self):
val = self._builder.get_object("dialogYesNo").run()
self._builder.get_object("dialogYesNo").hide()
return val