Added 'custom' notifications for chat settings

This commit is contained in:
Manuel Cortez 2018-12-12 12:24:05 -06:00
parent 1affb38cd5
commit 2699feada5
6 changed files with 35 additions and 5 deletions

View File

@ -4,6 +4,18 @@ from wxUI.dialogs import configuration as configurationUI
class configuration(object): class configuration(object):
def get_notification_type(self, value):
if value == _(u"Native"):
return "native"
else:
return "custom"
def get_notification_label(self, value):
if value == "native":
return _(u"Native")
else:
return _(u"Custom")
def __init__(self, session): def __init__(self, session):
self.session = session self.session = session
self.dialog = configurationUI.configurationDialog(_(u"Preferences")) self.dialog = configurationUI.configurationDialog(_(u"Preferences"))
@ -19,6 +31,7 @@ class configuration(object):
self.dialog.set_value("chat", "notify_offline", self.session.settings["chat"]["notify_offline"]) self.dialog.set_value("chat", "notify_offline", self.session.settings["chat"]["notify_offline"])
self.dialog.set_value("chat", "open_unread_conversations", self.session.settings["chat"]["open_unread_conversations"]) self.dialog.set_value("chat", "open_unread_conversations", self.session.settings["chat"]["open_unread_conversations"])
self.dialog.set_value("chat", "automove_to_conversations", self.session.settings["chat"]["automove_to_conversations"]) self.dialog.set_value("chat", "automove_to_conversations", self.session.settings["chat"]["automove_to_conversations"])
self.dialog.set_value("chat", "notifications", self.get_notification_label(self.session.settings["chat"]["notifications"]))
self.dialog.realize() self.dialog.realize()
self.response = self.dialog.get_response() self.response = self.dialog.get_response()
@ -29,4 +42,5 @@ class configuration(object):
self.session.settings["chat"]["notify_offline"] = self.dialog.get_value("chat", "notify_offline") self.session.settings["chat"]["notify_offline"] = self.dialog.get_value("chat", "notify_offline")
self.session.settings["chat"]["open_unread_conversations"] = self.dialog.get_value("chat", "open_unread_conversations") self.session.settings["chat"]["open_unread_conversations"] = self.dialog.get_value("chat", "open_unread_conversations")
self.session.settings["chat"]["automove_to_conversations"] = self.dialog.get_value("chat", "automove_to_conversations") self.session.settings["chat"]["automove_to_conversations"] = self.dialog.get_value("chat", "automove_to_conversations")
self.session.settings["chat"]["notifications"] = self.get_notification_type(self.dialog.get_value("chat", "notifications"))
self.session.settings.write() self.session.settings.write()

View File

@ -11,6 +11,7 @@ import posts
import profiles import profiles
import webbrowser import webbrowser
import logging import logging
import output
import longpollthread import longpollthread
import selector import selector
from vk_api.exceptions import LoginRequired, VkApiError from vk_api.exceptions import LoginRequired, VkApiError
@ -376,14 +377,16 @@ class Controller(object):
return return
user_name = self.session.get_user_name(event.user_id, "nom") user_name = self.session.get_user_name(event.user_id, "nom")
msg = _(u"{0} is online.").format(user_name,) msg = _(u"{0} is online.").format(user_name,)
self.window.notify(_("Socializer"), msg) sound = "friend_online.ogg"
self.notify(msg, sound, self.session.settings["chat"]["notifications"])
def user_offline(self, event): def user_offline(self, event):
if self.session.settings["chat"]["notify_offline"] == False: if self.session.settings["chat"]["notify_offline"] == False:
return return
user_name = self.session.get_user_name(event.user_id, "nom") user_name = self.session.get_user_name(event.user_id, "nom")
msg = _(u"{0} is offline.").format(user_name,) msg = _(u"{0} is offline.").format(user_name,)
self.window.notify(_("Socializer"), msg) sound = "friend_offline.ogg"
self.notify(msg, sound, self.session.settings["chat"]["notifications"])
def get_chat(self, obj=None): def get_chat(self, obj=None):
""" Searches or creates a chat buffer with the id of the user that is sending or receiving a message. """ Searches or creates a chat buffer with the id of the user that is sending or receiving a message.
@ -617,5 +620,11 @@ class Controller(object):
def view_my_profile_in_browser(self, *args, **kwargs): def view_my_profile_in_browser(self, *args, **kwargs):
webbrowser.open_new_tab("https://vk.com/id{id}".format(id=self.session.user_id,)) webbrowser.open_new_tab("https://vk.com/id{id}".format(id=self.session.user_id,))
def notify(self, message=""): def notify(self, message="", sound="", type="native"):
if type == "native":
self.window.notify(_("Socializer"), message) self.window.notify(_("Socializer"), message)
else:
if sound != "":
self.session.soundplayer.play(sound)
if message != "":
output.speak(message)

View File

@ -23,3 +23,4 @@ notify_online = boolean(default=True)
notify_offline = boolean(default=True) notify_offline = boolean(default=True)
open_unread_conversations = boolean(default=True) open_unread_conversations = boolean(default=True)
automove_to_conversations = boolean(default=True) automove_to_conversations = boolean(default=True)
notifications = string(default="custom")

Binary file not shown.

Binary file not shown.

View File

@ -36,6 +36,12 @@ class chat(wx.Panel, widgetUtils.BaseDialog):
sizer.Add(self.open_unread_conversations, 0, wx.ALL, 5) sizer.Add(self.open_unread_conversations, 0, wx.ALL, 5)
self.automove_to_conversations = wx.CheckBox(self, wx.NewId(), _(u"Move focus to new conversations")) self.automove_to_conversations = wx.CheckBox(self, wx.NewId(), _(u"Move focus to new conversations"))
sizer.Add(self.automove_to_conversations, 0, wx.ALL, 5) sizer.Add(self.automove_to_conversations, 0, wx.ALL, 5)
lbl = wx.StaticText(self, wx.NewId(), _(u"Notification type"))
self.notifications = wx.ComboBox(self, wx.NewId(), choices=[_(u"Native"), _(u"Custom"),], value=_(u"Native"), style=wx.CB_READONLY)
nbox = wx.BoxSizer(wx.HORIZONTAL)
nbox.Add(lbl, 0, wx.ALL, 5)
nbox.Add(self.notifications, 0, wx.ALL, 5)
sizer.Add(nbox, 0, wx.ALL, 5)
self.SetSizer(sizer) self.SetSizer(sizer)
class configurationDialog(widgetUtils.BaseDialog): class configurationDialog(widgetUtils.BaseDialog):