forked from openlp/openlp
Adds a dialouge asking if the user wants to replace an existing theme when importing.
It works, but I dont know, it just feels like my code is a little bit "rough 'n' ready" let me know what you think!
This commit is contained in:
parent
a2e40543ea
commit
e9caa194f5
@ -512,6 +512,20 @@ class ThemeManager(QtGui.QWidget):
|
||||
else:
|
||||
return self._createThemeFromXml(xml, self.path)
|
||||
|
||||
def overWriteMessageBox(self, themeName):
|
||||
ret = QtGui.QMessageBox.question(self,
|
||||
translate('OpenLP.ThemeManager', 'Theme Already Exists!'),
|
||||
translate('OpenLP.ThemeManager',
|
||||
'The theme %s already exists. Do you want to replace it?'
|
||||
% themeName),
|
||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes |
|
||||
QtGui.QMessageBox.No),
|
||||
QtGui.QMessageBox.No)
|
||||
if ret == QtGui.QMessageBox.Yes:
|
||||
return True
|
||||
elif ret == QtGui.QMessageBox.No:
|
||||
return False
|
||||
|
||||
def unzipTheme(self, filename, dir):
|
||||
"""
|
||||
Unzip the theme, remove the preview file if stored
|
||||
@ -533,10 +547,17 @@ class ThemeManager(QtGui.QWidget):
|
||||
xml_tree = ElementTree(element=XML(zip.read(xmlfile[0]))).getroot()
|
||||
v1_background = xml_tree.find(u'BackgroundType')
|
||||
if v1_background is not None:
|
||||
(themename, filexml, outfile) = self.unzipVersion122(dir, zip,
|
||||
(themename, filexml, outfile, abortimport) = self.unzipVersion122(dir, zip,
|
||||
xmlfile[0], xml_tree, v1_background, outfile)
|
||||
else:
|
||||
themename = xml_tree.find(u'name').text.strip()
|
||||
themefolder = os.path.join(dir, themename)
|
||||
themeexists = os.path.exists(themefolder)
|
||||
if themeexists and not self.overWriteMessageBox(themename):
|
||||
abortimport = True
|
||||
return
|
||||
else:
|
||||
abortimport = False
|
||||
for name in zip.namelist():
|
||||
try:
|
||||
uname = unicode(name, u'utf-8')
|
||||
@ -575,6 +596,7 @@ class ThemeManager(QtGui.QWidget):
|
||||
zip.close()
|
||||
if outfile:
|
||||
outfile.close()
|
||||
if not abortimport:
|
||||
# As all files are closed, we can create the Theme.
|
||||
if filexml:
|
||||
theme = self._createThemeFromXml(filexml, self.path)
|
||||
@ -596,6 +618,10 @@ class ThemeManager(QtGui.QWidget):
|
||||
"""
|
||||
themename = xml_tree.find(u'Name').text.strip()
|
||||
themename = self.bad_v1_name_chars.sub(u'', themename)
|
||||
themefolder = os.path.join(dir, themename)
|
||||
themeexists = os.path.exists(themefolder)
|
||||
if themeexists and not self.overWriteMessageBox(themename):
|
||||
return ( '', '', '', True)
|
||||
themedir = os.path.join(dir, themename)
|
||||
check_directory_exists(themedir)
|
||||
filexml = unicode(zip.read(xmlfile), u'utf-8')
|
||||
@ -617,7 +643,7 @@ class ThemeManager(QtGui.QWidget):
|
||||
log.exception(u'Theme file does not contain image file "%s"' %
|
||||
imagename.decode(u'utf-8', u'replace'))
|
||||
raise Exception(u'validation')
|
||||
return (themename, filexml, outfile)
|
||||
return (themename, filexml, outfile, False)
|
||||
|
||||
def checkIfThemeExists(self, themeName):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user