This commit is contained in:
Tim Bentley 2010-07-12 18:14:04 +01:00
commit 4d69120225
3 changed files with 192 additions and 69 deletions

View File

@ -53,22 +53,32 @@ class AdvancedTab(SettingsTab):
self.leftLayout = QtGui.QVBoxLayout(self.leftWidget)
self.leftLayout.setSpacing(8)
self.leftLayout.setMargin(0)
self.recentGroupBox = QtGui.QGroupBox(self.leftWidget)
self.recentGroupBox.setObjectName(u'recentGroupBox')
self.recentGroupBox.setGeometry(QtCore.QRect(0, 0, 220, 57))
self.recentGroupBox.setMaximumSize(QtCore.QSize(220, 57))
self.recentLayout = QtGui.QHBoxLayout(self.recentGroupBox)
self.uiGroupBox = QtGui.QGroupBox(self.leftWidget)
self.uiGroupBox.setObjectName(u'uiGroupBox')
self.uiGroupBox.setMaximumWidth(260)
self.uiLayout = QtGui.QVBoxLayout(self.uiGroupBox)
self.uiLayout.setSpacing(8)
self.uiLayout.setMargin(6)
self.uiLayout.setObjectName(u'uiLayout')
self.recentLayout = QtGui.QHBoxLayout()
self.recentLayout.setSpacing(8)
self.recentLayout.setMargin(6)
self.recentLayout.setMargin(0)
self.recentLayout.setObjectName(u'recentLayout')
self.recentLabel = QtGui.QLabel(self.recentGroupBox)
self.recentLabel = QtGui.QLabel(self.uiGroupBox)
self.recentLabel.setObjectName(u'recentLabel')
self.recentLayout.addWidget(self.recentLabel)
self.recentSpinBox = QtGui.QSpinBox(self.recentGroupBox)
self.recentSpinBox.setMinimum(0)
self.recentSpinBox = QtGui.QSpinBox(self.uiGroupBox)
self.recentSpinBox.setObjectName(u'recentSpinBox')
self.recentSpinBox.setMinimum(0)
self.recentLayout.addWidget(self.recentSpinBox)
self.leftLayout.addWidget(self.recentGroupBox)
self.recentSpacer = QtGui.QSpacerItem(50, 20,
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.recentLayout.addItem(self.recentSpacer)
self.uiLayout.addLayout(self.recentLayout)
self.mediaPluginCheckBox = QtGui.QCheckBox(self.uiGroupBox)
self.mediaPluginCheckBox.setObjectName(u'mediaPluginCheckBox')
self.uiLayout.addWidget(self.mediaPluginCheckBox)
self.leftLayout.addWidget(self.uiGroupBox)
# self.sharedDirGroupBox = QtGui.QGroupBox(self.leftWidget)
# self.sharedDirGroupBox.setObjectName(u'sharedDirGroupBox')
# self.sharedDirGroupBox.setGeometry(QtCore.QRect(0, 65, 500, 85))
@ -108,6 +118,8 @@ class AdvancedTab(SettingsTab):
# self.databaseLayout.setSpacing(8)
# self.databaseLayout.setMargin(8)
# self.rightLayout.addWidget(self.databaseGroupBox)
# self.rightSpacer = QtGui.QSpacerItem(20, 40,
# QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
# self.advancedTabLayout.addWidget(self.rightWidget)
# QtCore.QObject.connect(self.sharedCheckBox,
# QtCore.SIGNAL(u'stateChanged(int)'), self.onSharedCheckBoxChanged)
@ -116,9 +128,11 @@ class AdvancedTab(SettingsTab):
"""
Setup the interface translation strings.
"""
self.recentGroupBox.setTitle(translate('AdvancedTab', 'Recent Files'))
self.uiGroupBox.setTitle(translate('AdvancedTab', 'UI Settings'))
self.recentLabel.setText(
translate('AdvancedTab', 'Number of recent files to list:'))
translate('AdvancedTab', 'Number of recent files to display:'))
self.mediaPluginCheckBox.setText(translate('AdvancedTab',
'Save currently selected media manager plugin'))
# self.sharedDirGroupBox.setTitle(
# translate('AdvancedTab', 'Central Data Store'))
# self.sharedCheckBox.setText(
@ -140,6 +154,9 @@ class AdvancedTab(SettingsTab):
u'max recent files', QtCore.QVariant(20)).toInt()[0])
self.recentSpinBox.setValue(settings.value(u'recent file count',
QtCore.QVariant(4)).toInt()[0])
self.mediaPluginCheckBox.setChecked(
settings.value(u'save current plugin',
QtCore.QVariant(False)).toBool())
settings.endGroup()
def save(self):
@ -150,6 +167,8 @@ class AdvancedTab(SettingsTab):
settings.beginGroup(self.settingsSection)
settings.setValue(u'recent file count',
QtCore.QVariant(self.recentSpinBox.value()))
settings.setValue(u'save current plugin',
QtCore.QVariant(self.mediaPluginCheckBox.isChecked()))
settings.endGroup()
def onSharedCheckBoxChanged(self, checked):

View File

@ -658,6 +658,12 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
log.info(u'Load Themes')
self.ThemeManagerContents.loadThemes()
log.info(u'Load data from Settings')
if QtCore.QSettings().value(u'advanced/save current plugin',
QtCore.QVariant(False)).toBool():
savedPlugin = QtCore.QSettings().value(
u'advanced/current media plugin', QtCore.QVariant()).toInt()[0]
if savedPlugin != -1:
self.MediaToolBox.setCurrentIndex(savedPlugin)
self.settingsForm.postSetUp()
def setAutoLanguage(self, value):
@ -820,6 +826,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
"""
# Clean temporary files used by services
self.ServiceManagerContents.cleanUp()
if QtCore.QSettings().value(u'advanced/save current plugin',
QtCore.QVariant(False)).toBool():
QtCore.QSettings().setValue(u'advanced/current media plugin',
QtCore.QVariant(self.MediaToolBox.currentIndex()))
# Call the cleanup method to shutdown plugins.
log.info(u'cleanup plugins')
self.plugin_manager.finalise_plugins()

View File

@ -24,6 +24,7 @@
###############################################################################
from PyQt4 import QtGui, QtCore
from sqlalchemy.sql import and_
from openlp.core.lib import translate
from openlp.plugins.songs.forms import AuthorsForm, TopicsForm, SongBookForm
@ -97,6 +98,9 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
QtGui.QMessageBox.critical(self, dlg_title, sel_text)
def resetAuthors(self):
"""
Reloads the Authors list.
"""
self.AuthorsListWidget.clear()
authors = self.songmanager.get_all_objects(Author, Author.display_name)
for author in authors:
@ -109,6 +113,9 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
self.AuthorsListWidget.addItem(author_name)
def resetTopics(self):
"""
Reloads the Topics list.
"""
self.TopicsListWidget.clear()
topics = self.songmanager.get_all_objects(Topic, Topic.name)
for topic in topics:
@ -117,13 +124,88 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
self.TopicsListWidget.addItem(topic_name)
def resetBooks(self):
"""
Reloads the Books list.
"""
self.BooksListWidget.clear()
books = self.songmanager.get_all_objects(Book, Book.name)
for book in books:
book_name = QtGui.QListWidgetItem(book.name)
book_name = QtGui.QListWidgetItem(u'%s (%s)' % (book.name,
book.publisher))
book_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(book.id))
self.BooksListWidget.addItem(book_name)
def checkAuthor(self, new_author, edit=False):
"""
Returns False when the given Author is already in the list elsewise
True.
"""
authors = self.songmanager.get_all_objects_filtered(Author,
and_(
Author.first_name == new_author.first_name,
Author.last_name == new_author.last_name,
Author.display_name == new_author.display_name
)
)
if len(authors) > 0:
# If we edit an existing Author, we need to make sure that we do
# not return False when nothing has changed (because this would
# cause an error message later on).
if edit:
if authors[0].id == new_author.id:
return True
else:
return False
else:
return False
else:
return True
def checkTopic(self, new_topic, edit=False):
"""
Returns False when the given Topic is already in the list elsewise True.
"""
topics = self.songmanager.get_all_objects_filtered(Topic,
Topic.name == new_topic.name
)
if len(topics) > 0:
# If we edit an existing Topic, we need to make sure that we do
# not return False when nothing has changed (because this would
# cause an error message later on).
if edit:
if topics[0].id == new_topic.id:
return True
else:
return False
else:
return False
else:
return True
def checkBook(self, new_book, edit=False):
"""
Returns False when the given Book is already in the list elsewise True.
"""
books = self.songmanager.get_all_objects_filtered(Book,
and_(
Book.name == new_book.name,
Book.publisher == new_book.publisher
)
)
if len(books) > 0:
# If we edit an existing Book, we need to make sure that we do
# not return False when nothing has changed (because this would
# cause an error message later on).
if edit:
if books[0].id == new_book.id:
return True
else:
return False
else:
return False
else:
return True
def onAuthorAddButtonClick(self):
self.authorform.setAutoDisplayName(True)
if self.authorform.exec_():
@ -131,86 +213,93 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
first_name=unicode(self.authorform.FirstNameEdit.text()),
last_name=unicode(self.authorform.LastNameEdit.text()),
display_name=unicode(self.authorform.DisplayEdit.text()))
if self.songmanager.save_object(author):
self.resetAuthors()
if self.checkAuthor(author):
if self.songmanager.save_object(author):
self.resetAuthors()
else:
QtGui.QMessageBox.critical(
self, translate('SongsPlugin.SongMaintenanceForm',
'Error'),
QtGui.QMessageBox.critical(self,
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
translate('SongsPlugin.SongMaintenanceForm',
'Couldn\'t add your author.'))
'Could not add your author.'))
def onTopicAddButtonClick(self):
if self.topicform.exec_():
topic = Topic.populate(name=unicode(self.topicform.NameEdit.text()))
if self.songmanager.save_object(topic):
self.resetTopics()
if self.checkTopic(topic):
if self.songmanager.save_object(topic):
self.resetTopics()
else:
QtGui.QMessageBox.critical(
self, translate('SongsPlugin.SongMaintenanceForm',
'Error'),
QtGui.QMessageBox.critical(self,
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
translate('SongsPlugin.SongMaintenanceForm',
'Couldn\'t add your topic.'))
'Could not add your topic.'))
def onBookAddButtonClick(self):
if self.bookform.exec_():
book = Book.populate(
name=unicode(self.bookform.NameEdit.text()),
publisher=unicode(self.bookform.PublisherEdit.text()))
if self.songmanager.save_object(book):
self.resetBooks()
if self.checkBook(book):
if self.songmanager.save_object(book):
self.resetBooks()
else:
QtGui.QMessageBox.critical(
self, translate('SongsPlugin.SongMaintenanceForm',
'Error'),
QtGui.QMessageBox.critical(self,
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
translate('SongsPlugin.SongMaintenanceForm',
'Couldn\'t add your book.'))
'Could not add your book.'))
def onAuthorEditButtonClick(self):
author_id = self._getCurrentItemId(self.AuthorsListWidget)
if author_id != -1:
author = self.songmanager.get_object(Author, author_id)
# Just make sure none of the fields is None
if author.first_name is None:
author.first_name = u''
if author.last_name is None:
author.last_name = u''
if author.display_name is None:
author.display_name = u''
self.authorform.setAutoDisplayName(False)
self.authorform.FirstNameEdit.setText(author.first_name)
self.authorform.LastNameEdit.setText(author.last_name)
self.authorform.DisplayEdit.setText(author.display_name)
# Save the author's first and last name as well as the display name
# for the case that they have to be restored.
temp_first_name = author.first_name
temp_last_name = author.last_name
temp_display_name = author.display_name
if self.authorform.exec_(False):
author.first_name = unicode(
self.authorform.FirstNameEdit.text())
author.last_name = unicode(self.authorform.LastNameEdit.text())
author.display_name = unicode(
self.authorform.DisplayEdit.text())
if self.songmanager.save_object(author):
self.resetAuthors()
if self.checkAuthor(author, True):
if self.songmanager.save_object(author):
self.resetAuthors()
else:
QtGui.QMessageBox.critical(
self, translate('SongsPlugin.SongMaintenanceForm',
'Error'),
# We restore the author's old first and last name as well as
# his display name.
author.first_name = temp_first_name
author.last_name = temp_last_name
author.display_name = temp_display_name
QtGui.QMessageBox.critical(self,
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
translate('SongsPlugin.SongMaintenanceForm',
'Couldn\'t save your author.'))
'Could not save your author.'))
def onTopicEditButtonClick(self):
topic_id = self._getCurrentItemId(self.TopicsListWidget)
if topic_id != -1:
topic = self.songmanager.get_object(Topic, topic_id)
self.topicform.NameEdit.setText(topic.name)
# Save the topic's name for the case that he has to be restored.
temp_name = topic.name
if self.topicform.exec_(False):
topic.name = unicode(self.topicform.NameEdit.text())
if self.songmanager.save_object(topic):
self.resetTopics()
if self.checkTopic(topic, True):
if self.songmanager.save_object(topic):
self.resetTopics()
else:
QtGui.QMessageBox.critical(
self, translate('SongsPlugin.SongMaintenanceForm',
'Error'),
# We restore the topics's old name.
topic.name = temp_name
QtGui.QMessageBox.critical(self,
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
translate('SongsPlugin.SongMaintenanceForm',
'Couldn\'t save your topic.'))
'Could not save your topic.'))
def onBookEditButtonClick(self):
book_id = self._getCurrentItemId(self.BooksListWidget)
@ -218,17 +307,24 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
book = self.songmanager.get_object(Book, book_id)
self.bookform.NameEdit.setText(book.name)
self.bookform.PublisherEdit.setText(book.publisher)
# Save the book's name and publisher for the case that they have to
# be restored.
temp_name = book.name
temp_publisher = book.publisher
if self.bookform.exec_(False):
book.name = unicode(self.bookform.NameEdit.text())
book.publisher = unicode(self.bookform.PublisherEdit.text())
if self.songmanager.save_object(book):
self.resetBooks()
if self.checkBook(book, True):
if self.songmanager.save_object(book):
self.resetBooks()
else:
QtGui.QMessageBox.critical(
self, translate('SongsPlugin.SongMaintenanceForm',
'Error'),
# We restore the book's old name and publisher.
book.name = temp_name
book.publisher = temp_publisher
QtGui.QMessageBox.critical(self,
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
translate('SongsPlugin.SongMaintenanceForm',
'Couldn\'t save your book.'))
'Could not save your book.'))
def onAuthorDeleteButtonClick(self):
"""
@ -236,13 +332,12 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
"""
self._deleteItem(Author, self.AuthorsListWidget, self.resetAuthors,
translate('SongsPlugin.SongMaintenanceForm', 'Delete Author'),
translate('SongsPlugin.SongMaintenanceForm',
translate('SongsPlugin.SongMaintenanceForm',
'Are you sure you want to delete the selected author?'),
translate('SongsPlugin.SongMaintenanceForm',
'This author can\'t be deleted, they are currently '
'This author cannot be deleted, they are currently '
'assigned to at least one song.'),
translate('SongsPlugin.SongMaintenanceForm',
'No author selected!'))
translate('SongsPlugin.SongMaintenanceForm', 'No author selected!'))
def onTopicDeleteButtonClick(self):
"""
@ -250,13 +345,12 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
"""
self._deleteItem(Topic, self.TopicsListWidget, self.resetTopics,
translate('SongsPlugin.SongMaintenanceForm', 'Delete Topic'),
translate('SongsPlugin.SongMaintenanceForm',
'Are you sure you want to delete the selected topic?'),
translate('SongsPlugin.SongMaintenanceForm',
'This topic can\'t be deleted, it is currently '
'assigned to at least one song.'),
translate('SongsPlugin.SongMaintenanceForm',
'No topic selected!'))
'Are you sure you want to delete the selected topic?'),
translate('SongsPlugin.SongMaintenanceForm',
'This topic cannot be deleted, it is currently '
'assigned to at least one song.'),
translate('SongsPlugin.SongMaintenanceForm', 'No topic selected!'))
def onBookDeleteButtonClick(self):
"""
@ -266,7 +360,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
translate('SongsPlugin.SongMaintenanceForm', 'Delete Book'),
translate('SongsPlugin.SongMaintenanceForm',
'Are you sure you want to delete the selected book?'),
translate('SongsPlugin.SongMaintenanceForm',
'This book can\'t be deleted, it is currently '
translate('SongsPlugin.SongMaintenanceForm',
'This book cannot be deleted, it is currently '
'assigned to at least one song.'),
translate('SongsPlugin.SongMaintenanceForm', u'No book selected!'))
translate('SongsPlugin.SongMaintenanceForm', 'No book selected!'))