Added "Set notification sound..." context menu on addressbook entry.
This commit is contained in:
parent
de531949e0
commit
1f47a4060e
|
@ -325,6 +325,10 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
_translate(
|
_translate(
|
||||||
"MainWindow", "Set avatar..."),
|
"MainWindow", "Set avatar..."),
|
||||||
self.on_action_AddressBookSetAvatar)
|
self.on_action_AddressBookSetAvatar)
|
||||||
|
self.actionAddressBookSetSound = \
|
||||||
|
self.ui.addressBookContextMenuToolbar.addAction(
|
||||||
|
_translate("MainWindow", "Set notification sound..."),
|
||||||
|
self.on_action_AddressBookSetSound)
|
||||||
self.actionAddressBookNew = self.ui.addressBookContextMenuToolbar.addAction(
|
self.actionAddressBookNew = self.ui.addressBookContextMenuToolbar.addAction(
|
||||||
_translate(
|
_translate(
|
||||||
"MainWindow", "Add New Address"), self.on_action_AddressBookNew)
|
"MainWindow", "Add New Address"), self.on_action_AddressBookNew)
|
||||||
|
@ -1205,9 +1209,9 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
soundFilename = None
|
soundFilename = None
|
||||||
|
|
||||||
def _choose_ext(basename):
|
def _choose_ext(basename):
|
||||||
for ext in ('.wav', '.mp3', '.oga'):
|
for ext in sound.extensions:
|
||||||
if os.path.isfile(basename + ext):
|
if os.path.isfile(os.extsep.join([basename, ext])):
|
||||||
return ext
|
return os.extsep + ext
|
||||||
|
|
||||||
# if the address had a known label in the address book
|
# if the address had a known label in the address book
|
||||||
if label:
|
if label:
|
||||||
|
@ -3175,6 +3179,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
self.popMenuAddressBook.addAction(self.actionAddressBookClipboard)
|
self.popMenuAddressBook.addAction(self.actionAddressBookClipboard)
|
||||||
self.popMenuAddressBook.addAction(self.actionAddressBookSubscribe)
|
self.popMenuAddressBook.addAction(self.actionAddressBookSubscribe)
|
||||||
self.popMenuAddressBook.addAction(self.actionAddressBookSetAvatar)
|
self.popMenuAddressBook.addAction(self.actionAddressBookSetAvatar)
|
||||||
|
self.popMenuAddressBook.addAction(self.actionAddressBookSetSound)
|
||||||
self.popMenuAddressBook.addSeparator()
|
self.popMenuAddressBook.addSeparator()
|
||||||
self.popMenuAddressBook.addAction(self.actionAddressBookNew)
|
self.popMenuAddressBook.addAction(self.actionAddressBookNew)
|
||||||
normal = True
|
normal = True
|
||||||
|
@ -3579,6 +3584,50 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def on_action_AddressBookSetSound(self):
|
||||||
|
widget = self.ui.tableWidgetAddressBook
|
||||||
|
self.setAddressSound(widget.item(widget.currentRow(), 0).text())
|
||||||
|
|
||||||
|
def setAddressSound(self, addr):
|
||||||
|
filters = [unicode(_translate(
|
||||||
|
"MainWindow", "Sound files (%s)" %
|
||||||
|
' '.join(['*%s%s' % (os.extsep, ext) for ext in sound.extensions])
|
||||||
|
))]
|
||||||
|
sourcefile = unicode(QtGui.QFileDialog.getOpenFileName(
|
||||||
|
self, _translate("MainWindow", "Set notification sound..."),
|
||||||
|
filter=';;'.join(filters)
|
||||||
|
))
|
||||||
|
|
||||||
|
if not sourcefile:
|
||||||
|
return
|
||||||
|
|
||||||
|
destdir = os.path.join(state.appdata, 'sounds')
|
||||||
|
destfile = unicode(addr) + os.path.splitext(sourcefile)[-1]
|
||||||
|
destination = os.path.join(destdir, destfile)
|
||||||
|
|
||||||
|
if sourcefile == destination:
|
||||||
|
return
|
||||||
|
|
||||||
|
pattern = destfile.lower()
|
||||||
|
for item in os.listdir(destdir):
|
||||||
|
if item.lower() == pattern:
|
||||||
|
overwrite = QtGui.QMessageBox.question(
|
||||||
|
self, _translate("MainWindow", "Message"),
|
||||||
|
_translate(
|
||||||
|
"MainWindow",
|
||||||
|
"You have already set a notification sound"
|
||||||
|
" for this address book entry."
|
||||||
|
" Do you really want to overwrite it?"),
|
||||||
|
QtGui.QMessageBox.Yes, QtGui.QMessageBox.No
|
||||||
|
) == QtGui.QMessageBox.Yes
|
||||||
|
if overwrite:
|
||||||
|
QtCore.QFile.remove(os.path.join(destdir, item))
|
||||||
|
break
|
||||||
|
|
||||||
|
if not QtCore.QFile.copy(sourcefile, destination):
|
||||||
|
logger.error(
|
||||||
|
'couldn\'t copy %s to %s', sourcefile, destination)
|
||||||
|
|
||||||
def on_context_menuYourIdentities(self, point):
|
def on_context_menuYourIdentities(self, point):
|
||||||
currentItem = self.getCurrentItem()
|
currentItem = self.getCurrentItem()
|
||||||
self.popMenuYourIdentities = QtGui.QMenu(self)
|
self.popMenuYourIdentities = QtGui.QMenu(self)
|
||||||
|
|
|
@ -17,3 +17,5 @@ def is_connection_sound(category):
|
||||||
SOUND_DISCONNECTED,
|
SOUND_DISCONNECTED,
|
||||||
SOUND_CONNECTION_GREEN
|
SOUND_CONNECTION_GREEN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
extensions = ('wav', 'mp3', 'oga')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user