Added chat settings in the config dialog
This commit is contained in:
parent
6f9a5ce8d2
commit
b82c94bf51
@ -14,6 +14,11 @@ class configuration(object):
|
|||||||
self.dialog.set_value("general", "wall_buffer_count", self.session.settings["buffers"]["count_for_wall_buffers"])
|
self.dialog.set_value("general", "wall_buffer_count", self.session.settings["buffers"]["count_for_wall_buffers"])
|
||||||
self.dialog.set_value("general", "video_buffers_count", self.session.settings["buffers"]["count_for_video_buffers"])
|
self.dialog.set_value("general", "video_buffers_count", self.session.settings["buffers"]["count_for_video_buffers"])
|
||||||
self.dialog.set_value("general", "load_images", self.session.settings["general"]["load_images"])
|
self.dialog.set_value("general", "load_images", self.session.settings["general"]["load_images"])
|
||||||
|
self.dialog.create_chat()
|
||||||
|
self.dialog.set_value("chat", "notify_online", self.session.settings["chat"]["notify_online"])
|
||||||
|
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", "automove_to_conversations", self.session.settings["chat"]["automove_to_conversations"])
|
||||||
self.dialog.realize()
|
self.dialog.realize()
|
||||||
self.response = self.dialog.get_response()
|
self.response = self.dialog.get_response()
|
||||||
|
|
||||||
@ -21,4 +26,8 @@ class configuration(object):
|
|||||||
self.session.settings["buffers"]["count_for_audio_buffers"] = self.dialog.get_value("general", "audio_buffers_count")
|
self.session.settings["buffers"]["count_for_audio_buffers"] = self.dialog.get_value("general", "audio_buffers_count")
|
||||||
self.session.settings["buffers"]["count_for_video_buffers"] = self.dialog.get_value("general", "video_buffers_count")
|
self.session.settings["buffers"]["count_for_video_buffers"] = self.dialog.get_value("general", "video_buffers_count")
|
||||||
self.session.settings["general"]["load_images"] = self.dialog.get_value("general", "load_images")
|
self.session.settings["general"]["load_images"] = self.dialog.get_value("general", "load_images")
|
||||||
|
self.session.settings["chat"]["notify_online"] = self.dialog.get_value("chat", "notify_online")
|
||||||
|
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"]["automove_to_conversations"] = self.dialog.get_value("chat", "automove_to_conversations")
|
||||||
self.session.settings.write()
|
self.session.settings.write()
|
||||||
|
@ -377,11 +377,15 @@ class Controller(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def user_online(self, event):
|
def user_online(self, event):
|
||||||
|
if self.session.settings["chat"]["notify_online"] == False:
|
||||||
|
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)
|
self.window.notify(_("Socializer"), msg)
|
||||||
|
|
||||||
def user_offline(self, event):
|
def user_offline(self, event):
|
||||||
|
if self.session.settings["chat"]["notify_offline"] == False:
|
||||||
|
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)
|
self.window.notify(_("Socializer"), msg)
|
||||||
@ -389,15 +393,18 @@ class Controller(object):
|
|||||||
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.
|
||||||
obj vk_api.longpoll.EventType: an event wich defines some data from the vk's long poll server."""
|
obj vk_api.longpoll.EventType: an event wich defines some data from the vk's long poll server."""
|
||||||
|
# If someone else sends a message to the current user.
|
||||||
if obj.to_me:
|
if obj.to_me:
|
||||||
buffer = self.search_chat_buffer(obj.user_id)
|
buffer = self.search_chat_buffer(obj.user_id)
|
||||||
uid = obj.user_id
|
uid = obj.user_id
|
||||||
|
# If the current user sends a message to someone else.
|
||||||
else:
|
else:
|
||||||
buffer = self.search_chat_buffer(obj.peer_id)
|
buffer = self.search_chat_buffer(obj.peer_id)
|
||||||
uid = obj.peer_id
|
uid = obj.peer_id
|
||||||
|
# If there is no buffer, we must create one in a wxThread so it will not crash.
|
||||||
if buffer == None:
|
if buffer == None:
|
||||||
wx.CallAfter(self.chat_from_id, uid)
|
wx.CallAfter(self.chat_from_id, uid, setfocus=self.session.settings["chat"]["automove_to_conversations"])
|
||||||
self.session.soundplayer.play("chat.ogg")
|
self.session.soundplayer.play("message_received.ogg")
|
||||||
return
|
return
|
||||||
# If the chat already exists, let's create a dictionary wich will contains data of the received message.
|
# If the chat already exists, let's create a dictionary wich will contains data of the received message.
|
||||||
message = {"id": obj.message_id, "user_id": uid, "date": obj.timestamp, "body": obj.text, "attachments": obj.attachments}
|
message = {"id": obj.message_id, "user_id": uid, "date": obj.timestamp, "body": obj.text, "attachments": obj.attachments}
|
||||||
@ -407,7 +414,6 @@ class Controller(object):
|
|||||||
message_ids = message["id"]
|
message_ids = message["id"]
|
||||||
results = self.session.vk.client.messages.getById(message_ids=message_ids)
|
results = self.session.vk.client.messages.getById(message_ids=message_ids)
|
||||||
message = results["items"][0]
|
message = results["items"][0]
|
||||||
# If outbox it's true, it means that message["from_id"] should be the current user. If not, the obj.user_id should be taken.
|
|
||||||
if obj.from_me:
|
if obj.from_me:
|
||||||
message["from_id"] = self.session.user_id
|
message["from_id"] = self.session.user_id
|
||||||
else:
|
else:
|
||||||
@ -417,7 +423,7 @@ class Controller(object):
|
|||||||
# ToDo: Clean this code and test how is the database working with this set to True.
|
# ToDo: Clean this code and test how is the database working with this set to True.
|
||||||
num = self.session.order_buffer(buffer.name, data, True)
|
num = self.session.order_buffer(buffer.name, data, True)
|
||||||
buffer.insert(self.session.db[buffer.name]["items"][-1], False)
|
buffer.insert(self.session.db[buffer.name]["items"][-1], False)
|
||||||
self.session.soundplayer.play("chat.ogg")
|
self.session.soundplayer.play("message_received.ogg")
|
||||||
|
|
||||||
def set_online(self):
|
def set_online(self):
|
||||||
try:
|
try:
|
||||||
@ -432,6 +438,8 @@ class Controller(object):
|
|||||||
log.error("Error in setting offline status for the current user")
|
log.error("Error in setting offline status for the current user")
|
||||||
|
|
||||||
def create_unread_messages(self):
|
def create_unread_messages(self):
|
||||||
|
if self.session.settings["chat"]["open_unread_conversations"] == False:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
log.debug("Getting possible unread messages.")
|
log.debug("Getting possible unread messages.")
|
||||||
msgs = self.session.vk.client.messages.getDialogs(count=200, unread=1)
|
msgs = self.session.vk.client.messages.getDialogs(count=200, unread=1)
|
||||||
@ -456,7 +464,7 @@ class Controller(object):
|
|||||||
def get_audio_albums(self, user_id=None):
|
def get_audio_albums(self, user_id=None):
|
||||||
try:
|
try:
|
||||||
log.debug("Create audio albums...")
|
log.debug("Create audio albums...")
|
||||||
albums = self.session.vk.client.audio.getAlbums(owner_id=user_id)
|
albums = self.session.vk.client_audio.get_albums(owner_id=user_id)
|
||||||
except VkApiError as ex:
|
except VkApiError as ex:
|
||||||
if ex.code == 6:
|
if ex.code == 6:
|
||||||
log.exception("Something went wrong when getting albums. Waiting a second to retry")
|
log.exception("Something went wrong when getting albums. Waiting a second to retry")
|
||||||
@ -464,8 +472,8 @@ class Controller(object):
|
|||||||
return self.get_audio_albums(user_id=user_id)
|
return self.get_audio_albums(user_id=user_id)
|
||||||
elif ex.code == 10:
|
elif ex.code == 10:
|
||||||
return
|
return
|
||||||
self.session.audio_albums = albums["items"]
|
self.session.audio_albums = albums
|
||||||
for i in albums["items"]:
|
for i in albums:
|
||||||
buffer = buffers.audioAlbum(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=user_id, album_id=i["id"])
|
buffer = buffers.audioAlbum(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=user_id, album_id=i["id"])
|
||||||
buffer.can_get_items = False
|
buffer.can_get_items = False
|
||||||
# Translators: {0} Will be replaced with an audio album's title.
|
# Translators: {0} Will be replaced with an audio album's title.
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
user = string(default="")
|
user = string(default="")
|
||||||
password = string(default="")
|
password = string(default="")
|
||||||
token = string(default="")
|
token = string(default="")
|
||||||
|
|
||||||
[general]
|
[general]
|
||||||
reverse_timelines = boolean(default=False)
|
reverse_timelines = boolean(default=False)
|
||||||
load_images = boolean(default=True)
|
load_images = boolean(default=True)
|
||||||
@ -15,4 +16,10 @@ volume = float(default=1.0)
|
|||||||
input_device = string(default="Default")
|
input_device = string(default="Default")
|
||||||
output_device = string(default="Default")
|
output_device = string(default="Default")
|
||||||
session_mute = boolean(default=False)
|
session_mute = boolean(default=False)
|
||||||
current_soundpack = string(default="default")
|
current_soundpack = string(default="default")
|
||||||
|
|
||||||
|
[chat]
|
||||||
|
notify_online = boolean(default=True)
|
||||||
|
notify_offline = boolean(default=True)
|
||||||
|
open_unread_conversations = boolean(default=True)
|
||||||
|
automove_to_conversations = boolean(default=True)
|
BIN
src/sounds/default/message_unread.ogg
Normal file
BIN
src/sounds/default/message_unread.ogg
Normal file
Binary file not shown.
@ -24,6 +24,20 @@ class general(wx.Panel, widgetUtils.BaseDialog):
|
|||||||
sizer.Add(self.load_images, 0, wx.ALL, 5)
|
sizer.Add(self.load_images, 0, wx.ALL, 5)
|
||||||
self.SetSizer(sizer)
|
self.SetSizer(sizer)
|
||||||
|
|
||||||
|
class chat(wx.Panel, widgetUtils.BaseDialog):
|
||||||
|
def __init__(self, panel):
|
||||||
|
super(chat, self).__init__(panel)
|
||||||
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
self.notify_online = wx.CheckBox(self, wx.NewId(), _(u"Show notifications when users are online"))
|
||||||
|
sizer.Add(self.notify_online, 0, wx.ALL, 5)
|
||||||
|
self.notify_offline = wx.CheckBox(self, wx.NewId(), _(u"Show notifications when users are offline"))
|
||||||
|
sizer.Add(self.notify_offline, 0, wx.ALL, 5)
|
||||||
|
self.open_unread_conversations = wx.CheckBox(self, wx.NewId(), _(u"Open unread conversations at startup"))
|
||||||
|
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"))
|
||||||
|
sizer.Add(self.automove_to_conversations, 0, wx.ALL, 5)
|
||||||
|
self.SetSizer(sizer)
|
||||||
|
|
||||||
class configurationDialog(widgetUtils.BaseDialog):
|
class configurationDialog(widgetUtils.BaseDialog):
|
||||||
|
|
||||||
def __init__(self, title):
|
def __init__(self, title):
|
||||||
@ -37,6 +51,11 @@ class configurationDialog(widgetUtils.BaseDialog):
|
|||||||
self.notebook.AddPage(self.general, _(u"General"))
|
self.notebook.AddPage(self.general, _(u"General"))
|
||||||
self.general.SetFocus()
|
self.general.SetFocus()
|
||||||
|
|
||||||
|
def create_chat(self):
|
||||||
|
self.chat = chat(self.notebook)
|
||||||
|
self.notebook.AddPage(self.chat, _(u"Chat settings"))
|
||||||
|
|
||||||
|
|
||||||
def realize(self):
|
def realize(self):
|
||||||
self.sizer.Add(self.notebook, 0, wx.ALL, 5)
|
self.sizer.Add(self.notebook, 0, wx.ALL, 5)
|
||||||
ok_cancel_box = wx.BoxSizer(wx.HORIZONTAL)
|
ok_cancel_box = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
|
Loading…
Reference in New Issue
Block a user