openlp/openlp/plugins/songs/forms/songmaintenanceform.py

578 lines
26 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2022-12-31 15:54:46 +00:00
# Copyright (c) 2008-2023 OpenLP Developers #
2019-04-13 13:00:22 +00:00
# ---------------------------------------------------------------------- #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
2011-01-15 00:53:12 +00:00
import logging
2015-11-07 00:49:40 +00:00
from PyQt5 import QtCore, QtWidgets
2010-07-12 13:18:07 +00:00
from sqlalchemy.sql import and_
2009-10-24 16:40:36 +00:00
2018-10-02 04:39:42 +00:00
from openlp.core.common.i18n import UiStrings, get_natural_key, translate
2017-10-23 22:09:57 +00:00
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.registry import Registry
from openlp.core.lib.ui import critical_error_message_box
2013-03-07 12:34:35 +00:00
from openlp.plugins.songs.forms.authorsform import AuthorsForm
from openlp.plugins.songs.forms.songbookform import SongBookForm
2017-12-28 08:08:12 +00:00
from openlp.plugins.songs.forms.topicsform import TopicsForm
from openlp.plugins.songs.lib.db import Author, SongBook, Song, Topic, SongBookEntry
2018-10-02 04:39:42 +00:00
2013-08-31 18:17:38 +00:00
from .songmaintenancedialog import Ui_SongMaintenanceDialog
2018-10-02 04:39:42 +00:00
2011-01-15 00:53:12 +00:00
log = logging.getLogger(__name__)
2015-11-07 00:49:40 +00:00
class SongMaintenanceForm(QtWidgets.QDialog, Ui_SongMaintenanceDialog, RegistryProperties):
"""
Class documentation goes here.
"""
def __init__(self, manager, parent=None):
"""
Constructor
"""
super(SongMaintenanceForm, self).__init__(parent, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint |
QtCore.Qt.WindowCloseButtonHint)
self.setup_ui(self)
self.manager = manager
2013-03-14 22:22:18 +00:00
self.author_form = AuthorsForm(self)
self.topic_form = TopicsForm(self)
self.song_book_form = SongBookForm(self)
2011-01-19 20:27:43 +00:00
# Disable all edit and delete buttons, as there is no row selected.
2013-03-14 22:22:18 +00:00
self.delete_author_button.setEnabled(False)
self.edit_author_button.setEnabled(False)
self.delete_topic_button.setEnabled(False)
self.edit_topic_button.setEnabled(False)
self.delete_book_button.setEnabled(False)
self.edit_book_button.setEnabled(False)
2011-01-19 20:27:43 +00:00
# Signals
2013-03-14 22:22:18 +00:00
self.add_author_button.clicked.connect(self.on_add_author_button_clicked)
self.add_topic_button.clicked.connect(self.on_add_topic_button_clicked)
self.add_book_button.clicked.connect(self.on_add_book_button_clicked)
self.edit_author_button.clicked.connect(self.on_edit_author_button_clicked)
self.edit_topic_button.clicked.connect(self.on_edit_topic_button_clicked)
self.edit_book_button.clicked.connect(self.on_edit_book_button_clicked)
self.delete_author_button.clicked.connect(self.on_delete_author_button_clicked)
self.delete_topic_button.clicked.connect(self.on_delete_topic_button_clicked)
self.delete_book_button.clicked.connect(self.on_delete_book_button_clicked)
self.authors_list_widget.currentRowChanged.connect(self.on_authors_list_row_changed)
self.topics_list_widget.currentRowChanged.connect(self.on_topics_list_row_changed)
self.song_books_list_widget.currentRowChanged.connect(self.on_song_books_list_row_changed)
2015-11-07 00:49:40 +00:00
def exec(self, from_song_edit=False):
2012-05-26 19:56:12 +00:00
"""
Show the dialog.
2014-03-17 19:05:55 +00:00
:param from_song_edit: Indicates if the maintenance dialog has been opened from song edit
2012-05-26 19:56:12 +00:00
or from the media manager. Defaults to **False**.
"""
2013-03-14 22:22:18 +00:00
self.from_song_edit = from_song_edit
self.type_list_widget.setCurrentRow(0)
self.reset_authors()
self.reset_topics()
self.reset_song_books()
self.type_list_widget.setFocus()
2015-11-07 00:49:40 +00:00
return QtWidgets.QDialog.exec(self)
2013-03-14 22:22:18 +00:00
def _get_current_item_id(self, list_widget):
"""
Get the ID of the currently selected item.
2014-03-04 18:49:30 +00:00
:param list_widget: The list widget to examine.
"""
item = list_widget.currentItem()
2009-11-03 19:01:53 +00:00
if item:
2012-05-19 09:13:32 +00:00
item_id = (item.data(QtCore.Qt.UserRole))
return item_id
else:
return -1
2013-03-14 22:22:18 +00:00
def _delete_item(self, item_class, list_widget, reset_func, dlg_title, del_text, err_text):
"""
Delete an item.
"""
2013-03-14 22:22:18 +00:00
item_id = self._get_current_item_id(list_widget)
if item_id != -1:
2013-03-14 22:22:18 +00:00
item = self.manager.get_object(item_class, item_id)
if item and not item.songs:
2015-11-07 00:49:40 +00:00
if critical_error_message_box(dlg_title, del_text, self, True) == QtWidgets.QMessageBox.Yes:
2013-03-14 22:22:18 +00:00
self.manager.delete_object(item_class, item.id)
reset_func()
else:
2013-03-14 22:22:18 +00:00
critical_error_message_box(dlg_title, err_text)
else:
2013-03-14 22:22:18 +00:00
critical_error_message_box(dlg_title, UiStrings().NISs)
2013-03-14 22:22:18 +00:00
def reset_authors(self):
"""
Reloads the Authors list.
"""
def get_author_key(author):
"""Get the key to sort by"""
return get_natural_key(author.display_name)
2016-04-25 11:01:32 +00:00
2013-03-14 22:22:18 +00:00
self.authors_list_widget.clear()
authors = self.manager.get_all_objects(Author)
authors.sort(key=get_author_key)
for author in authors:
2009-11-03 19:01:53 +00:00
if author.display_name:
2015-11-07 00:49:40 +00:00
author_name = QtWidgets.QListWidgetItem(author.display_name)
else:
2015-11-07 00:49:40 +00:00
author_name = QtWidgets.QListWidgetItem(' '.join([author.first_name, author.last_name]))
2012-05-17 15:13:09 +00:00
author_name.setData(QtCore.Qt.UserRole, author.id)
2013-03-14 22:22:18 +00:00
self.authors_list_widget.addItem(author_name)
2013-03-14 22:22:18 +00:00
def reset_topics(self):
"""
Reloads the Topics list.
"""
def get_topic_key(topic):
"""Get the key to sort by"""
return get_natural_key(topic.name)
2016-04-25 11:01:32 +00:00
2013-03-14 22:22:18 +00:00
self.topics_list_widget.clear()
topics = self.manager.get_all_objects(Topic)
topics.sort(key=get_topic_key)
for topic in topics:
2015-11-07 00:49:40 +00:00
topic_name = QtWidgets.QListWidgetItem(topic.name)
2012-05-17 15:13:09 +00:00
topic_name.setData(QtCore.Qt.UserRole, topic.id)
2013-03-14 22:22:18 +00:00
self.topics_list_widget.addItem(topic_name)
2013-03-14 22:22:18 +00:00
def reset_song_books(self):
"""
Reloads the Books list.
"""
def get_book_key(book):
"""Get the key to sort by"""
return get_natural_key(book.name)
2016-04-25 11:01:32 +00:00
2013-03-14 22:22:18 +00:00
self.song_books_list_widget.clear()
books = self.manager.get_all_objects(SongBook)
books.sort(key=get_book_key)
for book in books:
book_name = QtWidgets.QListWidgetItem('{name} ({publisher})'.format(name=book.name,
publisher=book.publisher))
2012-05-17 15:13:09 +00:00
book_name.setData(QtCore.Qt.UserRole, book.id)
2013-03-14 22:22:18 +00:00
self.song_books_list_widget.addItem(book_name)
2013-03-14 22:22:18 +00:00
def check_author_exists(self, new_author, edit=False):
"""
2011-01-19 20:27:43 +00:00
Returns *False* if the given Author already exists, otherwise *True*.
2014-03-04 18:49:30 +00:00
:param new_author: The new Author.
:param edit: Are we editing the song?
"""
2013-03-14 22:22:18 +00:00
authors = self.manager.get_all_objects(
Author,
and_(
Author.first_name == new_author.first_name,
Author.last_name == new_author.last_name,
Author.display_name == new_author.display_name
)
)
return self._check_object_exists(authors, new_author, edit)
2013-03-14 22:22:18 +00:00
def check_topic_exists(self, new_topic, edit=False):
"""
2011-01-19 20:27:43 +00:00
Returns *False* if the given Topic already exists, otherwise *True*.
2014-03-04 18:49:30 +00:00
:param new_topic: The new Topic.
:param edit: Are we editing the song?
"""
2013-03-14 22:22:18 +00:00
topics = self.manager.get_all_objects(Topic, Topic.name == new_topic.name)
return self._check_object_exists(topics, new_topic, edit)
2013-03-14 22:22:18 +00:00
def check_song_book_exists(self, new_book, edit=False):
"""
2011-01-19 20:27:43 +00:00
Returns *False* if the given Topic already exists, otherwise *True*.
2014-03-04 18:49:30 +00:00
:param new_book: The new Book.
:param edit: Are we editing the song?
"""
2014-03-04 18:49:30 +00:00
books = self.manager.get_all_objects(
SongBook, and_(SongBook.name == new_book.name, SongBook.publisher == new_book.publisher))
return self._check_object_exists(books, new_book, edit)
2011-02-03 01:55:12 +00:00
def _check_object_exists(self, existing_objects, new_object, edit):
2011-02-03 01:55:12 +00:00
"""
Utility method to check for an existing object.
2014-03-04 18:49:30 +00:00
:param existing_objects: The objects reference
:param new_object: An individual object
:param edit: If we edit an item, this should be *True*.
2011-02-03 01:55:12 +00:00
"""
2013-03-14 22:22:18 +00:00
if existing_objects:
2011-02-03 01:55:12 +00:00
# If we edit an existing object, we need to make sure that we do
2011-01-19 20:27:43 +00:00
# not return False when nothing has changed.
2010-07-16 18:53:49 +00:00
if edit:
2013-03-14 22:22:18 +00:00
for existing_object in existing_objects:
if existing_object.id != new_object.id:
2011-01-19 03:46:53 +00:00
return False
return True
2010-07-16 18:53:49 +00:00
else:
return False
2010-07-12 13:18:07 +00:00
else:
return True
2013-03-14 22:22:18 +00:00
def on_add_author_button_clicked(self):
"""
Add an author to the list.
"""
2013-03-14 22:22:18 +00:00
self.author_form.auto_display_name = True
2015-11-07 00:49:40 +00:00
if self.author_form.exec():
author = Author(
2013-03-14 22:22:18 +00:00
first_name=self.author_form.first_name,
last_name=self.author_form.last_name,
display_name=self.author_form.display_name
)
2013-03-14 22:22:18 +00:00
if self.check_author_exists(author):
if self.manager.save_object(author):
2013-03-14 22:22:18 +00:00
self.reset_authors()
2010-07-16 09:00:20 +00:00
else:
2011-02-16 03:06:34 +00:00
critical_error_message_box(
2013-01-06 17:25:49 +00:00
message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your author.'))
else:
critical_error_message_box(
2013-01-06 17:25:49 +00:00
message=translate('SongsPlugin.SongMaintenanceForm', 'This author already exists.'))
2013-03-14 22:22:18 +00:00
def on_add_topic_button_clicked(self):
"""
Add a topic to the list.
"""
2015-11-07 00:49:40 +00:00
if self.topic_form.exec():
topic = Topic(name=self.topic_form.name)
2013-03-14 22:22:18 +00:00
if self.check_topic_exists(topic):
if self.manager.save_object(topic):
2013-03-14 22:22:18 +00:00
self.reset_topics()
2010-07-16 09:00:20 +00:00
else:
2011-02-16 03:06:34 +00:00
critical_error_message_box(
2013-01-06 17:25:49 +00:00
message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your topic.'))
else:
critical_error_message_box(
2013-01-06 17:25:49 +00:00
message=translate('SongsPlugin.SongMaintenanceForm', 'This topic already exists.'))
2013-03-14 22:22:18 +00:00
def on_add_book_button_clicked(self):
"""
Add a book to the list.
"""
2015-11-07 00:49:40 +00:00
if self.song_book_form.exec():
book = SongBook(name=self.song_book_form.name_edit.text(),
publisher=self.song_book_form.publisher_edit.text())
2013-03-14 22:22:18 +00:00
if self.check_song_book_exists(book):
if self.manager.save_object(book):
2013-03-14 22:22:18 +00:00
self.reset_song_books()
2010-07-16 09:00:20 +00:00
else:
2011-02-16 03:06:34 +00:00
critical_error_message_box(
2013-01-06 17:25:49 +00:00
message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your book.'))
else:
critical_error_message_box(
2013-01-06 17:25:49 +00:00
message=translate('SongsPlugin.SongMaintenanceForm', 'This book already exists.'))
2013-03-14 22:22:18 +00:00
def on_edit_author_button_clicked(self):
"""
Edit an author.
"""
2013-03-14 22:22:18 +00:00
author_id = self._get_current_item_id(self.authors_list_widget)
if author_id == -1:
return
author = self.manager.get_object(Author, author_id)
2013-03-14 22:22:18 +00:00
self.author_form.auto_display_name = False
self.author_form.first_name_edit.setText(author.first_name)
self.author_form.last_name_edit.setText(author.last_name)
self.author_form.display_edit.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
2015-11-07 00:49:40 +00:00
if self.author_form.exec(False):
2013-03-14 22:22:18 +00:00
author.first_name = self.author_form.first_name_edit.text()
author.last_name = self.author_form.last_name_edit.text()
author.display_name = self.author_form.display_edit.text()
if self.check_author_exists(author, True):
if self.manager.save_object(author):
2013-03-14 22:22:18 +00:00
self.reset_authors()
if not self.from_song_edit:
2013-08-31 18:17:38 +00:00
Registry().execute('songs_load_list')
else:
critical_error_message_box(
2013-01-06 17:25:49 +00:00
message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.'))
elif critical_error_message_box(
message=translate(
'SongsPlugin.SongMaintenanceForm',
'The author {original} already exists. Would you like to make songs with author {new} use the '
'existing author {original}?').format(original=author.display_name, new=temp_display_name),
parent=self, question=True) == QtWidgets.QMessageBox.Yes:
2014-03-04 18:49:30 +00:00
self._merge_objects(author, self.merge_authors, self.reset_authors)
else:
# 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
critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm',
2013-03-14 22:22:18 +00:00
'Could not save your modified author, because the author already exists.'))
2013-03-14 22:22:18 +00:00
def on_edit_topic_button_clicked(self):
"""
Edit a topic.
"""
2013-03-14 22:22:18 +00:00
topic_id = self._get_current_item_id(self.topics_list_widget)
if topic_id == -1:
return
topic = self.manager.get_object(Topic, topic_id)
2013-03-14 22:22:18 +00:00
self.topic_form.name = topic.name
# Save the topic's name for the case that he has to be restored.
temp_name = topic.name
2015-11-07 00:49:40 +00:00
if self.topic_form.exec(False):
2013-03-14 22:22:18 +00:00
topic.name = self.topic_form.name_edit.text()
if self.check_topic_exists(topic, True):
if self.manager.save_object(topic):
2013-03-14 22:22:18 +00:00
self.reset_topics()
else:
critical_error_message_box(
2013-01-06 17:25:49 +00:00
message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.'))
elif critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm',
'The topic {original} already exists. Would you like to make songs with '
'topic {new} use the existing topic {original}?').format(original=topic.name,
new=temp_name),
2015-11-07 00:49:40 +00:00
parent=self, question=True) == QtWidgets.QMessageBox.Yes:
2013-03-14 22:22:18 +00:00
self._merge_objects(topic, self.merge_topics, self.reset_topics)
else:
# We restore the topics's old name.
topic.name = temp_name
critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm',
2014-03-04 18:49:30 +00:00
'Could not save your modified topic, because it already exists.'))
2013-03-14 22:22:18 +00:00
def on_edit_book_button_clicked(self):
"""
Edit a book.
"""
2013-03-14 22:22:18 +00:00
book_id = self._get_current_item_id(self.song_books_list_widget)
if book_id == -1:
return
book = self.manager.get_object(SongBook, book_id)
if book.publisher is None:
2013-08-31 18:17:38 +00:00
book.publisher = ''
2013-03-14 22:22:18 +00:00
self.song_book_form.name_edit.setText(book.name)
self.song_book_form.publisher_edit.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
2015-11-07 00:49:40 +00:00
if self.song_book_form.exec(False):
2013-03-14 22:22:18 +00:00
book.name = self.song_book_form.name_edit.text()
book.publisher = self.song_book_form.publisher_edit.text()
if self.check_song_book_exists(book, True):
if self.manager.save_object(book):
2013-03-14 22:22:18 +00:00
self.reset_song_books()
else:
critical_error_message_box(
2013-01-06 17:25:49 +00:00
message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.'))
elif critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm',
'The book {original} already exists. Would you like to make songs with '
'book {new} use the existing book {original}?').format(original=book.name,
new=temp_name),
2015-11-07 00:49:40 +00:00
parent=self, question=True) == QtWidgets.QMessageBox.Yes:
2013-03-14 22:22:18 +00:00
self._merge_objects(book, self.merge_song_books, self.reset_song_books)
else:
# We restore the book's old name and publisher.
book.name = temp_name
book.publisher = temp_publisher
2013-03-14 22:22:18 +00:00
def _merge_objects(self, db_object, merge, reset):
2011-02-01 00:33:50 +00:00
"""
Utility method to merge two objects to leave one in the database.
"""
2013-02-03 19:23:12 +00:00
self.application.set_busy_cursor()
2013-03-14 22:22:18 +00:00
merge(db_object)
2011-02-01 00:33:50 +00:00
reset()
2013-03-14 22:22:18 +00:00
if not self.from_song_edit:
2013-08-31 18:17:38 +00:00
Registry().execute('songs_load_list')
2013-02-03 19:23:12 +00:00
self.application.set_normal_cursor()
2011-02-01 00:33:50 +00:00
2013-03-14 22:22:18 +00:00
def merge_authors(self, old_author):
"""
2010-07-17 15:10:46 +00:00
Merges two authors into one author.
:param old_author: The object, which was edited, that will be deleted
"""
2011-01-19 20:27:43 +00:00
# Find the duplicate.
2013-03-14 22:22:18 +00:00
existing_author = self.manager.get_object_filtered(
Author,
and_(
Author.first_name == old_author.first_name,
Author.last_name == old_author.last_name,
Author.display_name == old_author.display_name,
Author.id != old_author.id
)
)
# Find the songs, which have the old_author as author.
songs = self.manager.get_all_objects(Song, Song.authors.contains(old_author))
for song in songs:
for author_song in song.authors_songs:
song.add_author(existing_author, author_song.author_type)
song.remove_author(old_author, author_song.author_type)
self.manager.save_object(song)
2013-03-14 22:22:18 +00:00
self.manager.delete_object(Author, old_author.id)
2013-03-14 22:22:18 +00:00
def merge_topics(self, old_topic):
"""
2010-07-17 15:10:46 +00:00
Merges two topics into one topic.
2014-03-04 18:49:30 +00:00
:param old_topic: The object, which was edited, that will be deleted
"""
2011-01-19 20:27:43 +00:00
# Find the duplicate.
2013-03-14 22:22:18 +00:00
existing_topic = self.manager.get_object_filtered(
2014-03-04 18:49:30 +00:00
Topic, and_(Topic.name == old_topic.name, Topic.id != old_topic.id)
2013-03-14 22:22:18 +00:00
)
# Find the songs, which have the old_topic as topic.
songs = self.manager.get_all_objects(Song, Song.topics.contains(old_topic))
for song in songs:
2010-07-19 14:56:24 +00:00
# We check if the song has already existing_topic as topic. If that
# is not the case we add it.
if existing_topic not in song.topics:
song.topics.append(existing_topic)
2013-03-14 22:22:18 +00:00
song.topics.remove(old_topic)
self.manager.save_object(song)
2013-03-14 22:22:18 +00:00
self.manager.delete_object(Topic, old_topic.id)
2013-03-14 22:22:18 +00:00
def merge_song_books(self, old_song_book):
"""
2010-07-17 15:10:46 +00:00
Merges two books into one book.
2013-03-14 22:22:18 +00:00
``old_song_book``
2011-01-20 05:42:44 +00:00
The object, which was edited, that will be deleted
"""
2011-01-19 20:27:43 +00:00
# Find the duplicate.
2013-03-14 22:22:18 +00:00
existing_book = self.manager.get_object_filtered(
SongBook,
2013-03-14 22:22:18 +00:00
and_(
SongBook.name == old_song_book.name,
SongBook.publisher == old_song_book.publisher,
SongBook.id != old_song_book.id
2013-03-14 22:22:18 +00:00
)
)
2021-09-02 06:46:09 +00:00
if existing_book is None:
return False
# Find the songs which have the old_song_book as book, via matching entries in the songs_songbooks table
songbook_entries = self.manager.get_all_objects(SongBookEntry, SongBookEntry.songbook_id == old_song_book.id)
affected_songs = []
for songbook_entry in songbook_entries:
affected_songs.append(songbook_entry.song_id)
for song_id in affected_songs:
song = self.manager.get_object(Song, song_id)
# Go through the song's song/songbook link records to look for the link to the old songbook.
# Store the song number in that book so we can apply it in the link record to the existing songbook.
old_book_song_number = ''
for index, record in enumerate(song.songbook_entries):
if record.songbook_id == old_song_book.id:
old_book_song_number = record.entry
break
# Look through the same link records to see if there's a link to the duplicate (existing) songbook
# If so, transfer the song number in 'entry' field (if appropriate) ...
found = False
for record in song.songbook_entries:
if record.songbook_id == existing_book.id:
if not record.entry and old_book_song_number:
record.entry = old_book_song_number
found = True
break
# ... otherwise create a new link record
if not found:
new_songbook_entry = SongBookEntry()
new_songbook_entry.songbook_id = existing_book.id
new_songbook_entry.song_id = song.id
new_songbook_entry.entry = old_book_song_number
song.songbook_entries.append(new_songbook_entry)
self.manager.save_object(song)
2021-09-02 06:46:09 +00:00
self.manager.delete_object(SongBookEntry, (old_song_book.id, song_id, old_book_song_number))
self.manager.delete_object(SongBook, old_song_book.id)
2013-03-14 22:22:18 +00:00
def on_delete_author_button_clicked(self):
"""
Delete the author if the author is not attached to any songs.
"""
2013-03-14 22:22:18 +00:00
self._delete_item(Author, self.authors_list_widget, self.reset_authors,
2014-03-04 18:49:30 +00:00
translate('SongsPlugin.SongMaintenanceForm', 'Delete Author'),
translate('SongsPlugin.SongMaintenanceForm',
'Are you sure you want to delete the selected author?'),
translate('SongsPlugin.SongMaintenanceForm',
'This author cannot be deleted, they are currently assigned to at least one song'
'.'))
2013-03-14 22:22:18 +00:00
def on_delete_topic_button_clicked(self):
"""
2011-02-12 18:43:23 +00:00
Delete the Book if the Book is not attached to any songs.
"""
2013-03-14 22:22:18 +00:00
self._delete_item(Topic, self.topics_list_widget, self.reset_topics,
2014-03-04 18:49:30 +00:00
translate('SongsPlugin.SongMaintenanceForm', 'Delete Topic'),
translate('SongsPlugin.SongMaintenanceForm',
'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.'))
2013-03-14 22:22:18 +00:00
def on_delete_book_button_clicked(self):
"""
2011-02-12 18:43:23 +00:00
Delete the Book if the Book is not attached to any songs.
"""
self._delete_item(SongBook, self.song_books_list_widget, self.reset_song_books,
2014-03-04 18:49:30 +00:00
translate('SongsPlugin.SongMaintenanceForm', 'Delete Book'),
translate('SongsPlugin.SongMaintenanceForm',
'Are you sure you want to delete the selected book?'),
translate('SongsPlugin.SongMaintenanceForm',
'This book cannot be deleted, it is currently assigned to at least one song.'))
2011-01-19 20:27:43 +00:00
2013-03-14 22:22:18 +00:00
def on_authors_list_row_changed(self, row):
2011-01-19 20:27:43 +00:00
"""
2013-03-14 22:22:18 +00:00
Called when the *authors_list_widget*'s current row has changed.
2011-01-19 20:27:43 +00:00
"""
2013-03-14 22:22:18 +00:00
self._row_change(row, self.edit_author_button, self.delete_author_button)
2011-01-19 20:27:43 +00:00
2013-03-14 22:22:18 +00:00
def on_topics_list_row_changed(self, row):
2011-01-19 20:27:43 +00:00
"""
2013-03-14 22:22:18 +00:00
Called when the *topics_list_widget*'s current row has changed.
2011-01-19 20:27:43 +00:00
"""
2013-03-14 22:22:18 +00:00
self._row_change(row, self.edit_topic_button, self.delete_topic_button)
2011-01-19 20:27:43 +00:00
2013-03-14 22:22:18 +00:00
def on_song_books_list_row_changed(self, row):
2011-01-19 20:27:43 +00:00
"""
2013-03-14 22:22:18 +00:00
Called when the *song_books_list_widget*'s current row has changed.
2011-02-01 00:33:50 +00:00
"""
2013-03-14 22:22:18 +00:00
self._row_change(row, self.edit_book_button, self.delete_book_button)
2011-02-01 00:33:50 +00:00
2013-03-14 22:22:18 +00:00
def _row_change(self, row, edit_button, delete_button):
2011-02-01 00:33:50 +00:00
"""
Utility method to toggle if buttons are enabled.
2011-01-19 20:27:43 +00:00
``row``
The current row. If there is no current row, the value is -1.
"""
if row == -1:
2013-03-14 22:22:18 +00:00
delete_button.setEnabled(False)
edit_button.setEnabled(False)
2011-01-19 20:27:43 +00:00
else:
2013-03-14 22:22:18 +00:00
delete_button.setEnabled(True)
2014-03-21 21:38:08 +00:00
edit_button.setEnabled(True)