string recoding cleanups

This commit is contained in:
M2j 2010-06-06 01:05:53 +02:00
parent 262d125b00
commit 5a238e663b
2 changed files with 39 additions and 45 deletions

View File

@ -334,7 +334,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
def onTopicRemoveButtonClicked(self): def onTopicRemoveButtonClicked(self):
self.TopicRemoveButton.setEnabled(False) self.TopicRemoveButton.setEnabled(False)
item = self.TopicsListView.currentItem() item = self.TopicsListView.currentItem()
topic_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] topic_id = item.data(QtCore.Qt.UserRole).toInt()[0]
topic = self.songmanager.get_topic(topic_id) topic = self.songmanager.get_topic(topic_id)
self.song.topics.remove(topic) self.song.topics.remove(topic)
row = self.TopicsListView.row(item) row = self.TopicsListView.row(item)
@ -370,7 +370,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
item.setText(afterText) item.setText(afterText)
self.VerseListWidget.setRowCount( self.VerseListWidget.setRowCount(
self.VerseListWidget.rowCount() + 1) self.VerseListWidget.rowCount() + 1)
self.VerseListWidget.setItem(int(self.VerseListWidget.rowCount() - 1), 0, item) self.VerseListWidget.setItem(
int(self.VerseListWidget.rowCount() - 1), 0, item)
self.VerseListWidget.setColumnWidth(0, self.width) self.VerseListWidget.setColumnWidth(0, self.width)
self.VerseListWidget.resizeRowsToContents() self.VerseListWidget.resizeRowsToContents()
self.tagRows() self.tagRows()
@ -378,8 +379,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
def onVerseEditButtonClicked(self): def onVerseEditButtonClicked(self):
item = self.VerseListWidget.currentItem() item = self.VerseListWidget.currentItem()
if item: if item:
tempText = item.text() tempText = unicode(item.text())
verseId = unicode((item.data(QtCore.Qt.UserRole)).toString()) verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
self.verse_form.setVerse(tempText, True, verseId) self.verse_form.setVerse(tempText, True, verseId)
if self.verse_form.exec_(): if self.verse_form.exec_():
afterText, verse, subVerse = self.verse_form.getVerse() afterText, verse, subVerse = self.verse_form.getVerse()
@ -410,16 +411,16 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
if self.VerseListWidget.rowCount() > 0: if self.VerseListWidget.rowCount() > 0:
for row in range(0, self.VerseListWidget.rowCount()): for row in range(0, self.VerseListWidget.rowCount()):
item = self.VerseListWidget.item(row, 0) item = self.VerseListWidget.item(row, 0)
field = unicode((item.data(QtCore.Qt.UserRole)).toString()) field = unicode(item.data(QtCore.Qt.UserRole).toString())
verse_list += u'---[%s]---\n' % field verse_list += u'---[%s]---\n' % field
verse_list += item.text() verse_list += unicode(item.text())
verse_list += u'\n' verse_list += u'\n'
self.verse_form.setVerse(verse_list) self.verse_form.setVerse(verse_list)
else: else:
self.verse_form.setVerse(u'') self.verse_form.setVerse(u'')
if self.verse_form.exec_(): if self.verse_form.exec_():
verse_list = self.verse_form.getVerseAll() verse_list = unicode(self.verse_form.getVerseAll())
verse_list = unicode(verse_list.replace(u'\r\n', u'\n')) verse_list = verse_list.replace(u'\r\n', u'\n')
self.VerseListWidget.clear() self.VerseListWidget.clear()
self.VerseListWidget.setRowCount(0) self.VerseListWidget.setRowCount(0)
for row in self.findVerseSplit.split(verse_list): for row in self.findVerseSplit.split(verse_list):
@ -457,7 +458,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
""" """
log.debug(u'Validate Song') log.debug(u'Validate Song')
# Lets be nice and assume the data is correct. # Lets be nice and assume the data is correct.
if len(self.TitleEditItem.displayText()) == 0: if self.TitleEditItem.text().isEmpty():
self.SongTabWidget.setCurrentIndex(0) self.SongTabWidget.setCurrentIndex(0)
self.TitleEditItem.setFocus() self.TitleEditItem.setFocus()
return False, self.trUtf8('You need to enter a song title.') return False, self.trUtf8('You need to enter a song title.')
@ -469,11 +470,11 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.SongTabWidget.setCurrentIndex(1) self.SongTabWidget.setCurrentIndex(1)
self.AuthorsListView.setFocus() self.AuthorsListView.setFocus()
#split the verse list by space and mark lower case for testing #split the verse list by space and mark lower case for testing
taglist = unicode(self.trUtf8(' bitpeovc')) taglist = unicode(self.trUtf8(' bitpeo'))
for verse in unicode(self.VerseOrderEdit.text()).lower().split(u' '): for verse in unicode(self.VerseOrderEdit.text()).lower().split(u' '):
if len(verse) > 1: if len(verse) > 1:
if (verse[0:1] == u'%s' % self.trUtf8('v') or if (verse[0:1] == unicode(self.trUtf8('v')) or
verse[0:1] == u'%s' % self.trUtf8('c')) \ verse[0:1] == unicode(self.trUtf8('c')) \
and verse[1:].isdigit(): and verse[1:].isdigit():
pass pass
else: else:
@ -493,19 +494,19 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
return True, u'' return True, u''
def onTitleEditItemLostFocus(self): def onTitleEditItemLostFocus(self):
self.song.title = self.TitleEditItem.text() self.song.title = unicode(self.TitleEditItem.text())
def onVerseOrderEditLostFocus(self): def onVerseOrderEditLostFocus(self):
self.song.verse_order = self.VerseOrderEdit.text() self.song.verse_order = unicode(self.VerseOrderEdit.text())
def onCommentsEditLostFocus(self): def onCommentsEditLostFocus(self):
self.song.comments = self.CommentsEdit.text() self.song.comments = unicode(self.CommentsEdit.text())
def onCCLNumberEditLostFocus(self): def onCCLNumberEditLostFocus(self):
self.song.ccli_number = self.CCLNumberEdit.text() self.song.ccli_number = unicode(self.CCLNumberEdit.text())
def onCopyrightInsertButtonTriggered(self): def onCopyrightInsertButtonTriggered(self):
text = self.CopyrightEditItem.displayText() text = self.CopyrightEditItem.text()
pos = self.CopyrightEditItem.cursorPosition() pos = self.CopyrightEditItem.cursorPosition()
text = text[:pos] + u'©' + text[pos:] text = text[:pos] + u'©' + text[pos:]
self.CopyrightEditItem.setText(text) self.CopyrightEditItem.setText(text)
@ -524,8 +525,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
The Song is valid so as the plugin to add it to preview to see. The Song is valid so as the plugin to add it to preview to see.
""" """
log.debug(u'onPreview') log.debug(u'onPreview')
if button.text() == unicode(self.trUtf8('Save && Preview')) \ if button.text() == self.trUtf8('Save && Preview') and self.saveSong():
and self.saveSong():
Receiver.send_message(u'songs_preview') Receiver.send_message(u'songs_preview')
def closePressed(self): def closePressed(self):
@ -545,13 +545,13 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self, self.trUtf8('Error'), message, self, self.trUtf8('Error'), message,
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
return False return False
self.song.title = unicode(self.TitleEditItem.displayText()) self.song.title = unicode(self.TitleEditItem.text())
self.song.copyright = unicode(self.CopyrightEditItem.displayText()) self.song.copyright = unicode(self.CopyrightEditItem.text())
self.song.search_title = unicode(self.TitleEditItem.displayText()) + \ self.song.search_title = unicode(self.TitleEditItem.text()) + \
u'@'+ unicode(self.AlternativeEdit.displayText()) u'@' + unicode(self.AlternativeEdit.text())
self.song.comments = unicode(self.CommentsEdit.toPlainText()) self.song.comments = unicode(self.CommentsEdit.toPlainText())
self.song.verse_order = unicode(self.VerseOrderEdit.text()) self.song.verse_order = unicode(self.VerseOrderEdit.text())
self.song.ccli_number = unicode(self.CCLNumberEdit.displayText()) self.song.ccli_number = unicode(self.CCLNumberEdit.text())
self.processLyrics() self.processLyrics()
self.processTitle() self.processTitle()
self.songmanager.save_song(self.song) self.songmanager.save_song(self.song)
@ -566,7 +566,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
text = u' ' text = u' '
for i in range (0, self.VerseListWidget.rowCount()): for i in range (0, self.VerseListWidget.rowCount()):
item = self.VerseListWidget.item(i, 0) item = self.VerseListWidget.item(i, 0)
verseId = unicode((item.data(QtCore.Qt.UserRole)).toString()) verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
bits = verseId.split(u':') bits = verseId.split(u':')
sxml.add_verse_to_lyrics(bits[0], bits[1], unicode(item.text())) sxml.add_verse_to_lyrics(bits[0], bits[1], unicode(item.text()))
text = text + unicode(self.VerseListWidget.item(i, 0).text()) \ text = text + unicode(self.VerseListWidget.item(i, 0).text()) \
@ -580,7 +580,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
text = text.replace(u'{', u'') text = text.replace(u'{', u'')
text = text.replace(u'}', u'') text = text.replace(u'}', u'')
text = text.replace(u'?', u'') text = text.replace(u'?', u'')
self.song.search_lyrics = unicode(text) self.song.search_lyrics = text
self.song.lyrics = unicode(sxml.extract_xml(), u'utf-8') self.song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
except: except:
log.exception(u'Problem processing song Lyrics \n%s', log.exception(u'Problem processing song Lyrics \n%s',
@ -588,6 +588,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
def processTitle(self): def processTitle(self):
log.debug(u'processTitle') log.debug(u'processTitle')
self.song.search_title = unicode(self.song.search_title)
self.song.search_title = self.song.search_title.replace(u'\'', u'') self.song.search_title = self.song.search_title.replace(u'\'', u'')
self.song.search_title = self.song.search_title.replace(u'\"', u'') self.song.search_title = self.song.search_title.replace(u'\"', u'')
self.song.search_title = self.song.search_title.replace(u'`', u'') self.song.search_title = self.song.search_title.replace(u'`', u'')
@ -599,6 +600,4 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.song.search_title = self.song.search_title.replace(u'{', u'') self.song.search_title = self.song.search_title.replace(u'{', u'')
self.song.search_title = self.song.search_title.replace(u'}', u'') self.song.search_title = self.song.search_title.replace(u'}', u'')
self.song.search_title = self.song.search_title.replace(u'?', u'') self.song.search_title = self.song.search_title.replace(u'?', u'')
self.song.search_title = unicode(self.song.search_title)

View File

@ -151,7 +151,7 @@ class SongMediaItem(MediaManagerItem):
self.configUpdated() self.configUpdated()
def onSearchTextButtonClick(self): def onSearchTextButtonClick(self):
search_keywords = unicode(self.SearchTextEdit.displayText()) search_keywords = unicode(self.SearchTextEdit.text())
search_results = [] search_results = []
search_type = self.SearchTypeComboBox.currentIndex() search_type = self.SearchTypeComboBox.currentIndex()
if search_type == 0: if search_type == 0:
@ -187,12 +187,7 @@ class SongMediaItem(MediaManagerItem):
if author_list != u'': if author_list != u'':
author_list = author_list + u', ' author_list = author_list + u', '
author_list = author_list + author.display_name author_list = author_list + author.display_name
if not isinstance(author_list, unicode): song_title = unicode(song.title)
author_list = unicode(author_list, u'utf8')
if isinstance(song.title, unicode):
song_title = song.title
else:
song_title = unicode(song.title, u'utf8')
song_detail = u'%s (%s)' % (song_title, author_list) song_detail = u'%s (%s)' % (song_title, author_list)
song_name = QtGui.QListWidgetItem(song_detail) song_name = QtGui.QListWidgetItem(song_detail)
song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id)) song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
@ -203,8 +198,8 @@ class SongMediaItem(MediaManagerItem):
self.ListView.clear() self.ListView.clear()
for author in searchresults: for author in searchresults:
for song in author.songs: for song in author.songs:
song_detail = unicode(self.trUtf8('%s (%s)' % \ song_detail = unicode(self.trUtf8('%s (%s)')) % \
(unicode(author.display_name), unicode(song.title)))) (unicode(author.display_name), unicode(song.title))
song_name = QtGui.QListWidgetItem(song_detail) song_name = QtGui.QListWidgetItem(song_detail)
song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id)) song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
self.ListView.addItem(song_name) self.ListView.addItem(song_name)
@ -225,7 +220,7 @@ class SongMediaItem(MediaManagerItem):
search_length = 1 search_length = 1
if self.SearchTypeComboBox.currentIndex() == 1: if self.SearchTypeComboBox.currentIndex() == 1:
search_length = 7 search_length = 7
if len(text) > search_length: if text.size() > search_length:
self.onSearchTextButtonClick() self.onSearchTextButtonClick()
def onImportClick(self): def onImportClick(self):
@ -273,7 +268,7 @@ class SongMediaItem(MediaManagerItem):
def onEditClick(self): def onEditClick(self):
item = self.ListView.currentItem() item = self.ListView.currentItem()
if item: if item:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = item.data(QtCore.Qt.UserRole).toInt()[0]
self.edit_song_form.loadSong(item_id, False) self.edit_song_form.loadSong(item_id, False)
self.edit_song_form.exec_() self.edit_song_form.exec_()
@ -293,7 +288,7 @@ class SongMediaItem(MediaManagerItem):
if ans == QtGui.QMessageBox.Cancel: if ans == QtGui.QMessageBox.Cancel:
return return
for item in items: for item in items:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = item.data(QtCore.Qt.UserRole).toInt()[0]
self.parent.manager.delete_song(item_id) self.parent.manager.delete_song(item_id)
self.onSearchTextButtonClick() self.onSearchTextButtonClick()
@ -307,11 +302,11 @@ class SongMediaItem(MediaManagerItem):
item = self.ListView.currentItem() item = self.ListView.currentItem()
if item is None: if item is None:
return False return False
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = item.data(QtCore.Qt.UserRole).toInt()[0]
else: else:
item_id = self.remoteSong item_id = self.remoteSong
else: else:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = item.data(QtCore.Qt.UserRole).toInt()[0]
service_item.add_capability(ItemCapabilities.AllowsEdit) service_item.add_capability(ItemCapabilities.AllowsEdit)
service_item.add_capability(ItemCapabilities.AllowsPreview) service_item.add_capability(ItemCapabilities.AllowsPreview)
service_item.add_capability(ItemCapabilities.AllowsLoop) service_item.add_capability(ItemCapabilities.AllowsLoop)
@ -335,7 +330,8 @@ class SongMediaItem(MediaManagerItem):
break break
for verse in verseList: for verse in verseList:
if verse[1]: if verse[1]:
if order[1:]: if verse[0][u'type'] == u'Verse' or \
verse[0][u'type'] == u'Chorus':
if verse[0][u'type'][0] == order[0] and \ if verse[0][u'type'][0] == order[0] and \
verse[0][u'label'] == order[1:]: verse[0][u'label'] == order[1:]:
verseTag = u'%s:%s' % \ verseTag = u'%s:%s' % \
@ -343,8 +339,7 @@ class SongMediaItem(MediaManagerItem):
service_item.add_from_text\ service_item.add_from_text\
(verse[1][:30], verse[1], verseTag) (verse[1][:30], verse[1], verseTag)
else: else:
if verse[0][u'type'][0] == order[0] and \ if verse[0][u'type'][0] == order[0]:
verse[0][u'label'] == u'1':
verseTag = u'%s:%s' % \ verseTag = u'%s:%s' % \
(verse[0][u'type'], verse[0][u'label']) (verse[0][u'type'], verse[0][u'label'])
service_item.add_from_text\ service_item.add_from_text\