2016-02-13 17:06:36 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-06-19 12:25:06 -05:00
|
|
|
import time
|
2016-04-04 11:18:42 -05:00
|
|
|
import os
|
|
|
|
import webbrowser
|
2019-02-13 16:48:00 -06:00
|
|
|
import subprocess
|
2016-05-12 17:44:53 -05:00
|
|
|
import logging
|
2019-01-03 12:56:59 -06:00
|
|
|
import wx
|
|
|
|
import widgetUtils
|
2018-12-12 12:24:05 -06:00
|
|
|
import output
|
2019-01-06 15:26:54 -06:00
|
|
|
import presenters
|
|
|
|
import interactors
|
|
|
|
import views
|
2019-01-22 17:49:18 -06:00
|
|
|
import config
|
2019-02-13 16:48:00 -06:00
|
|
|
import paths
|
2019-02-26 16:17:53 -06:00
|
|
|
import win32gui
|
2018-12-09 05:22:37 -06:00
|
|
|
from vk_api.exceptions import LoginRequired, VkApiError
|
2018-12-12 13:41:57 -06:00
|
|
|
from requests.exceptions import ConnectionError
|
2016-02-13 17:06:36 -06:00
|
|
|
from pubsub import pub
|
2019-02-12 17:49:33 -06:00
|
|
|
from mysc import restart
|
2016-02-13 17:06:36 -06:00
|
|
|
from mysc.repeating_timer import RepeatingTimer
|
2016-02-15 16:49:09 -06:00
|
|
|
from mysc.thread_utils import call_threaded
|
2016-06-29 13:16:35 -05:00
|
|
|
from mysc import localization
|
2018-12-13 12:05:48 -06:00
|
|
|
from sessionmanager import session, utils, renderers
|
2019-01-30 15:32:46 -06:00
|
|
|
from wxUI import (mainWindow, commonMessages, menus)
|
2016-03-23 13:52:43 -06:00
|
|
|
from wxUI.dialogs import search as searchDialogs
|
2019-01-26 18:42:50 -06:00
|
|
|
from wxUI.dialogs import creation, timeline
|
2016-02-25 05:49:18 -06:00
|
|
|
from update import updater
|
2018-12-22 08:08:30 -06:00
|
|
|
from issueReporter import issueReporter
|
2019-01-03 12:56:59 -06:00
|
|
|
from . import buffers
|
2019-01-06 19:58:33 -06:00
|
|
|
from presenters import player
|
2019-01-06 19:53:01 -06:00
|
|
|
from presenters import longpollthread
|
2019-01-03 12:56:59 -06:00
|
|
|
from . import selector
|
2016-02-13 17:06:36 -06:00
|
|
|
|
2016-05-12 17:44:53 -05:00
|
|
|
log = logging.getLogger("controller.main")
|
|
|
|
|
2016-02-13 17:06:36 -06:00
|
|
|
class Controller(object):
|
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
### utils
|
|
|
|
# Important utility functions for the program which are not used directly by anyone.
|
2016-02-13 17:06:36 -06:00
|
|
|
def search(self, tab_name):
|
2019-02-06 17:47:49 -06:00
|
|
|
""" Search a buffer by name. Name should be the buffer.name argument.
|
|
|
|
returns a buffer object matching the pased name or None name."""
|
2019-01-01 19:42:53 -06:00
|
|
|
for i in range(0, len(self.buffers)):
|
2016-02-13 17:06:36 -06:00
|
|
|
if self.buffers[i].name == tab_name:
|
|
|
|
return self.buffers[i]
|
|
|
|
return False
|
|
|
|
|
2016-02-23 17:49:55 -06:00
|
|
|
def get_current_buffer(self):
|
|
|
|
""" Get the current bufferObject"""
|
|
|
|
buffer = self.window.get_current_buffer()
|
|
|
|
if hasattr(buffer, "name"):
|
|
|
|
buffer = self.search(buffer.name)
|
|
|
|
return buffer
|
|
|
|
|
2019-01-30 15:32:46 -06:00
|
|
|
def get_all_buffers(self, contains):
|
2019-02-06 17:47:49 -06:00
|
|
|
""" Get all buffers containing the name passed as the only parameter. Similar to search, but this method returns a list with all buffers found. """
|
2019-01-30 15:32:46 -06:00
|
|
|
results = []
|
|
|
|
for i in self.buffers:
|
|
|
|
if contains in i.name:
|
|
|
|
results.append(i)
|
|
|
|
return results
|
|
|
|
|
2016-02-13 17:06:36 -06:00
|
|
|
def __init__(self):
|
|
|
|
super(Controller, self).__init__()
|
2016-05-12 17:44:53 -05:00
|
|
|
log.debug("Starting main controller...")
|
2016-02-13 17:06:36 -06:00
|
|
|
self.buffers = []
|
2016-02-15 17:49:39 -06:00
|
|
|
player.setup()
|
2016-02-13 17:06:36 -06:00
|
|
|
self.window = mainWindow.mainWindow()
|
2016-05-12 17:44:53 -05:00
|
|
|
log.debug("Main window created")
|
2019-01-01 19:42:53 -06:00
|
|
|
self.window.change_status(_("Ready"))
|
|
|
|
self.session = session.sessions[list(session.sessions.keys())[0]]
|
2016-02-13 17:06:36 -06:00
|
|
|
self.window.Show()
|
2019-02-06 17:47:49 -06:00
|
|
|
self.connect_pubsub_events()
|
|
|
|
self.connect_gui_events()
|
2019-01-11 16:08:49 -06:00
|
|
|
self.create_controls()
|
2018-12-27 11:11:30 -06:00
|
|
|
call_threaded(updater.do_update, update_type=self.session.settings["general"]["update_channel"])
|
2016-02-13 17:06:36 -06:00
|
|
|
|
2019-02-26 16:17:53 -06:00
|
|
|
def is_focused(self):
|
|
|
|
""" Return True if the Socializer Window is Focused. """
|
|
|
|
app_title = "socializer"
|
|
|
|
window_title = win32gui.GetWindowText(win32gui.GetForegroundWindow()).lower()
|
|
|
|
if app_title == window_title:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
### action function
|
|
|
|
# These functions are called by other parts of the program, and are not connected to any event at all.
|
2016-02-13 17:06:36 -06:00
|
|
|
def create_controls(self):
|
2019-02-06 17:47:49 -06:00
|
|
|
""" Create all buffers for Socializer."""
|
2016-05-12 17:44:53 -05:00
|
|
|
log.debug("Creating controls for the window...")
|
2019-02-06 11:35:38 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="emptyBuffer", buffer_title=_("Posts"), kwargs=dict(parent=self.window.tb, name="posts"))
|
2019-01-11 16:08:49 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="baseBuffer", buffer_title=_("Home"), parent_tab="posts", kwargs=dict(parent=self.window.tb, name="home_timeline", session=self.session, composefunc="render_newsfeed_item", endpoint="newsfeed", count=self.session.settings["buffers"]["count_for_wall_buffers"]))
|
|
|
|
pub.sendMessage("create_buffer", buffer_type="feedBuffer", buffer_title=_("My wall"), parent_tab="posts", kwargs=dict(parent=self.window.tb, name="me_feed", composefunc="render_status", session=self.session, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"]))
|
2019-02-06 11:35:38 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="emptyBuffer", buffer_title=_("Music"), kwargs=dict(parent=self.window.tb, name="audios"))
|
2019-01-11 16:08:49 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="audioBuffer", buffer_title=_("My audios"), parent_tab="audios", kwargs=dict(parent=self.window.tb, name="me_audio", composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio"))
|
|
|
|
if self.session.settings["vk"]["use_alternative_tokens"] == False:
|
|
|
|
pub.sendMessage("create_buffer", buffer_type="audioBuffer", buffer_title=_("Populars"), parent_tab="audios", kwargs=dict(parent=self.window.tb, name="popular_audio", composefunc="render_audio", session=self.session, endpoint="getPopular", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"]))
|
|
|
|
pub.sendMessage("create_buffer", buffer_type="audioBuffer", buffer_title=_("Recommendations"), parent_tab="audios", kwargs=dict(parent=self.window.tb, name="recommended_audio", composefunc="render_audio", session=self.session, endpoint="getRecommendations", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"]))
|
2019-02-25 15:42:59 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="emptyBuffer", buffer_title=_("Albums"), parent_tab="audios", kwargs=dict(parent=self.window.tb, name="audio_albums"))
|
2019-02-06 11:35:38 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="emptyBuffer", buffer_title=_("Video"), kwargs=dict(parent=self.window.tb, name="videos"))
|
2019-01-11 16:08:49 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="videoBuffer", buffer_title=_("My videos"), parent_tab="videos", kwargs=dict(parent=self.window.tb, name="me_video", composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"]))
|
2019-02-25 15:42:59 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="emptyBuffer", buffer_title=_("Albums"), parent_tab="videos", kwargs=dict(parent=self.window.tb, name="video_albums"))
|
2019-02-06 11:35:38 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="emptyBuffer", buffer_title=_("People"), kwargs=dict(parent=self.window.tb, name="people"))
|
2019-02-14 13:09:44 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="peopleBuffer", buffer_title=_("Online"), parent_tab="people", kwargs=dict(parent=self.window.tb, name="online_friends", composefunc="render_person", session=self.session, endpoint="getOnline", parent_endpoint="friends", count=5000, order="hints", fields="uid, first_name, last_name, last_seen"))
|
|
|
|
pub.sendMessage("create_buffer", buffer_type="peopleBuffer", buffer_title=_("All friends"), parent_tab="people", kwargs=dict(parent=self.window.tb, name="friends_", composefunc="render_person", session=self.session, endpoint="get", parent_endpoint="friends", count=5000, order="hints", fields="uid, first_name, last_name, last_seen"))
|
2019-02-06 11:35:38 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="emptyBuffer", buffer_title=_("Friendship requests"), parent_tab="people", kwargs=dict(parent=self.window.tb, name="requests"))
|
2019-01-11 16:08:49 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="requestsBuffer", buffer_title=_("Pending requests"), parent_tab="requests", kwargs=dict(parent=self.window.tb, name="friend_requests", composefunc="render_person", session=self.session, count=1000))
|
|
|
|
pub.sendMessage("create_buffer", buffer_type="requestsBuffer", buffer_title=_("I follow"), parent_tab="requests", kwargs=dict(parent=self.window.tb, name="friend_requests_sent", composefunc="render_person", session=self.session, count=1000, out=1))
|
2019-01-21 04:44:16 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="requestsBuffer", buffer_title=_("Subscribers"), parent_tab="requests", kwargs=dict(parent=self.window.tb, name="subscribers", composefunc="render_person", session=self.session, count=1000, need_viewed=1))
|
2019-02-06 11:35:38 -06:00
|
|
|
pub.sendMessage("create_buffer", buffer_type="documentBuffer", buffer_title=_("Documents"), parent_tab=None, loadable=True, kwargs=dict(parent=self.window.tb, name="documents", composefunc="render_document", session=self.session, endpoint="get", parent_endpoint="docs"))
|
|
|
|
pub.sendMessage("create_buffer", buffer_type="emptyBuffer", buffer_title=_("Groups"), kwargs=dict(parent=self.window.tb, name="communities"))
|
|
|
|
pub.sendMessage("create_buffer", buffer_type="emptyBuffer", buffer_title=_("Chats"), kwargs=dict(parent=self.window.tb, name="chats"))
|
|
|
|
pub.sendMessage("create_buffer", buffer_type="emptyBuffer", buffer_title=_("Timelines"), kwargs=dict(parent=self.window.tb, name="timelines"))
|
2019-01-11 16:08:49 -06:00
|
|
|
self.window.realize()
|
2018-12-16 00:41:47 -06:00
|
|
|
self.repeatedUpdate = RepeatingTimer(120, self.update_all_buffers)
|
2016-02-13 17:06:36 -06:00
|
|
|
self.repeatedUpdate.start()
|
2016-02-23 05:48:05 -06:00
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def complete_buffer_creation(self, buffer, name_, position):
|
|
|
|
answer = buffer.get_items()
|
|
|
|
if answer is not True:
|
|
|
|
commonMessages.show_error_code(answer)
|
|
|
|
return
|
|
|
|
self.buffers.append(buffer)
|
|
|
|
self.window.insert_buffer(buffer.tab, name_, position)
|
2018-12-09 05:22:37 -06:00
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def search_chat_buffer(self, user_id):
|
|
|
|
for i in self.buffers:
|
|
|
|
if "_messages" in i.name:
|
|
|
|
if "peer_id" in i.kwargs and i.kwargs["peer_id"] == user_id: return i
|
|
|
|
return None
|
2016-02-13 17:06:36 -06:00
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def set_online(self, notify=False):
|
|
|
|
try:
|
|
|
|
r = self.session.vk.client.account.setOnline()
|
|
|
|
except:
|
|
|
|
log.error("Error in setting online for the current user")
|
|
|
|
if notify:
|
|
|
|
self.window.notify("Socializer", "online now!")
|
|
|
|
|
|
|
|
def set_offline(self):
|
|
|
|
try:
|
|
|
|
r = self.session.vk.client.account.setOffline()
|
|
|
|
except:
|
|
|
|
log.error("Error in setting offline status for the current user")
|
|
|
|
|
|
|
|
def create_unread_messages(self):
|
|
|
|
if self.session.settings["chat"]["open_unread_conversations"] == False:
|
2019-01-30 15:32:46 -06:00
|
|
|
return
|
2019-02-06 17:47:49 -06:00
|
|
|
try:
|
|
|
|
log.debug("Getting possible unread messages.")
|
|
|
|
msgs = self.session.vk.client.messages.getConversations(count=200)
|
|
|
|
except VkApiError as ex:
|
|
|
|
if ex.code == 6:
|
|
|
|
log.exception("Something went wrong when getting messages. Waiting a second to retry")
|
|
|
|
for i in msgs["items"]:
|
|
|
|
call_threaded(self.chat_from_id, i["last_message"]["peer_id"], setfocus=False, unread=False)
|
|
|
|
time.sleep(0.6)
|
2019-02-05 12:20:50 -06:00
|
|
|
|
2019-02-25 15:42:59 -06:00
|
|
|
def get_audio_albums(self, user_id=None, create_buffers=True, force_action=False):
|
|
|
|
if self.session.settings["load_at_startup"]["audio_albums"] == False and force_action == False:
|
2019-02-06 17:47:49 -06:00
|
|
|
return
|
|
|
|
log.debug("Create audio albums...")
|
|
|
|
if self.session.settings["vk"]["use_alternative_tokens"]:
|
|
|
|
albums = self.session.vk.client_audio.get_albums(owner_id=user_id)
|
2019-01-30 15:32:46 -06:00
|
|
|
else:
|
2019-02-06 17:47:49 -06:00
|
|
|
albums = self.session.vk.client.audio.getPlaylists(owner_id=user_id)
|
|
|
|
albums = albums["items"]
|
|
|
|
self.session.audio_albums = albums
|
|
|
|
if create_buffers:
|
|
|
|
for i in albums:
|
2019-02-25 15:42:59 -06:00
|
|
|
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="audioAlbum", buffer_title=_("Album: {0}").format(i["title"],), parent_tab="audio_albums", loadable=True, kwargs=dict(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", owner_id=user_id, album_id=i["id"]))
|
2019-02-06 17:47:49 -06:00
|
|
|
time.sleep(0.6)
|
2019-01-30 15:32:46 -06:00
|
|
|
|
2019-02-25 15:42:59 -06:00
|
|
|
def get_video_albums(self, user_id=None, create_buffers=True, force_action=False):
|
|
|
|
if self.session.settings["load_at_startup"]["video_albums"] == False and force_action == False:
|
2019-02-06 17:47:49 -06:00
|
|
|
return
|
|
|
|
log.debug("Create video albums...")
|
|
|
|
albums = self.session.vk.client.video.getAlbums(owner_id=user_id)
|
|
|
|
self.session.video_albums = albums["items"]
|
|
|
|
if create_buffers:
|
|
|
|
for i in albums["items"]:
|
|
|
|
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="videoAlbum", buffer_title=_("Album: {0}").format(i["title"],), parent_tab="video_albums", loadable=True, kwargs=dict(parent=self.window.tb, name="{0}_video_album".format(i["id"],), composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], user_id=user_id, album_id=i["id"]))
|
|
|
|
time.sleep(0.15)
|
|
|
|
|
|
|
|
def get_communities(self, user_id=None, create_buffers=True, force_action=False):
|
|
|
|
if self.session.settings["vk"]["invited_to_group"] == False:
|
|
|
|
self.session.settings["vk"]["invited_to_group"] = True
|
|
|
|
self.session.settings.write()
|
|
|
|
socializer_group = self.session.vk.client.groups.getById(group_ids="175825000")[0]
|
|
|
|
if socializer_group["is_member"] ==False:
|
|
|
|
d = commonMessages.join_group()
|
|
|
|
self.session.settings["vk"]["invited_to_group"] = True
|
|
|
|
self.session.settings.write()
|
|
|
|
if d == widgetUtils.YES:
|
|
|
|
result = self.session.vk.client.groups.join(group_id=socializer_group["id"])
|
|
|
|
if result == 1:
|
|
|
|
commonMessages.group_joined()
|
|
|
|
else:
|
|
|
|
log.error("Invalid result when joining the Socializer's group: %d" % (result))
|
|
|
|
if self.session.settings["load_at_startup"]["communities"] == False and force_action == False:
|
|
|
|
return
|
|
|
|
log.debug("Create community buffers...")
|
2019-05-06 15:50:45 -05:00
|
|
|
groups= self.session.vk.client.groups.get(user_id=user_id, extended=1, count=1000, fields="can_post, can_create_topic")
|
2019-02-06 17:47:49 -06:00
|
|
|
self.session.groups=groups["items"]
|
|
|
|
# Let's feed the local database cache with new groups coming from here.
|
|
|
|
data= dict(profiles=[], groups=self.session.groups)
|
|
|
|
self.session.process_usernames(data)
|
|
|
|
if create_buffers:
|
|
|
|
for i in self.session.groups:
|
2019-05-06 15:50:45 -05:00
|
|
|
self.session.db["group_info"][i["id"]*-1] = i
|
|
|
|
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="communityBuffer", buffer_title=i["name"], parent_tab="communities", loadable=True, get_items=True, kwargs=dict(parent=self.window.tb, name="{0}_community".format(i["id"],), composefunc="render_status", session=self.session, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"], owner_id=-1*i["id"]))
|
2019-02-06 17:47:49 -06:00
|
|
|
time.sleep(0.15)
|
2016-06-06 03:53:55 -05:00
|
|
|
|
2016-02-13 17:06:36 -06:00
|
|
|
def login(self):
|
2019-01-01 19:42:53 -06:00
|
|
|
self.window.change_status(_("Logging in VK"))
|
2016-02-14 18:46:23 -06:00
|
|
|
self.session.login()
|
2019-01-01 19:42:53 -06:00
|
|
|
self.window.change_status(_("Ready"))
|
2016-02-13 17:06:36 -06:00
|
|
|
for i in self.buffers:
|
|
|
|
if hasattr(i, "get_items"):
|
2016-06-29 10:56:41 -05:00
|
|
|
# Translators: {0} will be replaced with the name of a buffer.
|
2019-01-01 19:42:53 -06:00
|
|
|
self.window.change_status(_("Loading items for {0}").format(i.name,))
|
2016-02-13 17:06:36 -06:00
|
|
|
i.get_items()
|
2019-01-01 19:42:53 -06:00
|
|
|
self.window.change_status(_("Ready"))
|
2019-01-14 01:59:32 -06:00
|
|
|
self.create_unread_messages()
|
2018-12-13 17:16:56 -06:00
|
|
|
self.status_setter = RepeatingTimer(280, self.set_online)
|
2016-06-03 10:24:35 -05:00
|
|
|
self.status_setter.start()
|
2019-01-11 16:08:49 -06:00
|
|
|
self.set_online(notify=True)
|
2019-01-14 01:59:32 -06:00
|
|
|
self.get_audio_albums(self.session.user_id)
|
|
|
|
self.get_video_albums(self.session.user_id)
|
|
|
|
self.get_communities(self.session.user_id)
|
2019-01-11 16:08:49 -06:00
|
|
|
self.create_longpoll_thread()
|
2016-06-19 12:25:06 -05:00
|
|
|
|
2018-12-12 13:41:57 -06:00
|
|
|
def create_longpoll_thread(self, notify=False):
|
|
|
|
try:
|
|
|
|
self.longpoll = longpollthread.worker(self.session)
|
|
|
|
self.longpoll.start()
|
|
|
|
if notify:
|
2019-01-01 19:42:53 -06:00
|
|
|
self.notify(message=_("Chat server reconnected"))
|
2018-12-12 13:41:57 -06:00
|
|
|
except ConnectionError:
|
|
|
|
pub.sendMessage("longpoll-read-timeout")
|
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def update_all_buffers(self):
|
|
|
|
log.debug("Updating buffers...")
|
|
|
|
self.get_audio_albums(self.session.user_id, create_buffers=False)
|
|
|
|
self.get_video_albums(self.session.user_id, create_buffers=False)
|
|
|
|
for i in self.buffers:
|
2019-02-14 13:09:44 -06:00
|
|
|
# Online friends buffer should not be updated, as chat LongPoll server already gives status about offline and online friends.
|
|
|
|
if hasattr(i, "get_items") and i.name != "online_friends":
|
2019-02-06 17:47:49 -06:00
|
|
|
i.get_items()
|
|
|
|
log.debug("Updated %s" % (i.name))
|
2019-02-14 13:09:44 -06:00
|
|
|
else:
|
|
|
|
i.update_online()
|
2019-02-06 17:47:49 -06:00
|
|
|
|
|
|
|
def reorder_buffer(self, buffer):
|
|
|
|
""" this puts the chat buffers at the top of the list when there are new incoming messages.
|
|
|
|
In order to do so, we search for the current buffer's tab, remove the page from the TreeCtrl (without destroying the associated tab)
|
|
|
|
and reinsert it as a new child of the chat buffer.
|
|
|
|
Lastly we ensure the user is focused in the same buffer than before."""
|
|
|
|
buffer_window = self.window.search(buffer.name)
|
|
|
|
# If buffer window is already in the first position after chat, we should not do anything here because calculations for moving buffers are expensive.
|
|
|
|
if buffer_window == self.window.search("chats")+1:
|
|
|
|
return
|
|
|
|
# Gets buffer title so we don't have to generate it again in future.
|
|
|
|
buffer_title = self.window.get_buffer_text(buffer_window)
|
|
|
|
# Determine if the current buffer is the buffer receiving a new message.
|
|
|
|
if buffer == self.get_current_buffer():
|
|
|
|
focused_buffer = True
|
|
|
|
else:
|
|
|
|
focused_buffer = False
|
|
|
|
# This call will not destroy the associated tab for the chat buffer, thus allowing us to readd it in other position.
|
|
|
|
self.window.remove_buffer_from_position(buffer_window)
|
|
|
|
self.window.insert_chat_buffer(buffer.tab, buffer_title, self.window.search("chats")+1)
|
|
|
|
# Let's manipulate focus so users will not notice the change in buffers.
|
|
|
|
if focused_buffer:
|
|
|
|
new_position = self.window.search(buffer.name)
|
|
|
|
self.window.change_buffer(new_position)
|
|
|
|
else:
|
|
|
|
new_position = self.window.search(self.get_current_buffer().name)
|
|
|
|
self.window.change_buffer(new_position)
|
|
|
|
|
|
|
|
### pubsub events
|
|
|
|
# All of these functions, except the first two, are responses to pubsub events.
|
|
|
|
def connect_pubsub_events(self):
|
|
|
|
log.debug("Connecting events to responses...")
|
|
|
|
pub.subscribe(self.in_post, "posted")
|
|
|
|
pub.subscribe(self.download, "download-file")
|
|
|
|
pub.subscribe(self.view_post, "open-post")
|
|
|
|
pub.subscribe(self.update_status_bar, "update-status-bar")
|
|
|
|
pub.subscribe(self.chat_from_id, "new-chat")
|
|
|
|
pub.subscribe(self.authorisation_failed, "authorisation-failed")
|
2019-02-14 08:36:31 -06:00
|
|
|
pub.subscribe(self.connection_error, "connection_error")
|
2019-02-06 17:47:49 -06:00
|
|
|
pub.subscribe(self.user_profile, "user-profile")
|
|
|
|
pub.subscribe(self.user_online, "user-online")
|
|
|
|
pub.subscribe(self.user_offline, "user-offline")
|
|
|
|
pub.subscribe(self.notify, "notify")
|
|
|
|
pub.subscribe(self.handle_longpoll_read_timeout, "longpoll-read-timeout")
|
|
|
|
pub.subscribe(self.create_buffer, "create_buffer")
|
|
|
|
pub.subscribe(self.user_typing, "user-typing")
|
|
|
|
pub.subscribe(self.get_chat, "order-sent-message")
|
|
|
|
|
|
|
|
def disconnect_events(self):
|
|
|
|
log.debug("Disconnecting some events...")
|
|
|
|
pub.unsubscribe(self.in_post, "posted")
|
|
|
|
pub.unsubscribe(self.download, "download-file")
|
|
|
|
pub.unsubscribe(self.authorisation_failed, "authorisation-failed")
|
|
|
|
pub.unsubscribe(self.view_post, "open-post")
|
|
|
|
pub.unsubscribe(self.update_status_bar, "update-status-bar")
|
|
|
|
pub.unsubscribe(self.user_online, "user-online")
|
|
|
|
pub.unsubscribe(self.user_offline, "user-offline")
|
|
|
|
pub.unsubscribe(self.notify, "notify")
|
|
|
|
|
2016-02-13 17:06:36 -06:00
|
|
|
def in_post(self, buffer):
|
2019-02-06 17:47:49 -06:00
|
|
|
""" This event is triggered whenever an user requires an update in their buffers. For example after sending a post successfully.
|
|
|
|
The function updates the main newsfeed buffer, and the buffer from where the post was sent.
|
|
|
|
@buffer str: name of the buffer where the post has been generated.
|
|
|
|
"""
|
2016-02-13 17:06:36 -06:00
|
|
|
buffer = self.search(buffer)
|
|
|
|
buffer.get_items()
|
|
|
|
buffer = self.search("home_timeline")
|
|
|
|
buffer.get_items()
|
|
|
|
|
2016-02-15 16:49:09 -06:00
|
|
|
def download(self, url, filename):
|
2019-02-06 17:47:49 -06:00
|
|
|
""" Download a file to te current user's computer.
|
|
|
|
@ url: The URl from where the file can be directly accessed.
|
|
|
|
@ filename: the current path to where the file will be saved.
|
|
|
|
The dowwload progress will be displayed in the status bar on the window.
|
|
|
|
"""
|
2019-04-16 15:45:25 -05:00
|
|
|
url = utils.transform_audio_url(url)
|
2019-01-01 19:42:53 -06:00
|
|
|
log.debug("downloading %s URL to %s filename" % (url, filename,))
|
2016-02-15 17:49:39 -06:00
|
|
|
call_threaded(utils.download_file, url, filename, self.window)
|
|
|
|
|
2019-04-15 17:50:56 -05:00
|
|
|
def view_post(self, post_object, controller_, vars=dict()):
|
2019-02-06 17:47:49 -06:00
|
|
|
""" Display the passed post in the passed post presenter.
|
|
|
|
@ post_object dict: A post representation returned by the VK api. The fields present in this dict are different depending on the presenter used to render it.
|
|
|
|
@controller_ string: Name of the post controller, this name will be used for calling interactors, views and presenters. For example, displayPost, displayAudio, etc.
|
|
|
|
"""
|
2019-04-15 17:50:56 -05:00
|
|
|
p = getattr(presenters, controller_+"Presenter")(session=self.session, postObject=post_object, interactor=getattr(interactors, controller_+"Interactor")(), view=getattr(views, controller_)(), **vars)
|
2016-02-23 05:48:05 -06:00
|
|
|
|
2016-03-26 09:08:41 -06:00
|
|
|
def update_status_bar(self, status):
|
2019-02-06 17:47:49 -06:00
|
|
|
""" Update the status bar present in the main Window.
|
|
|
|
@ status str: Text to be placed in the status bar.
|
|
|
|
"""
|
2016-03-27 00:11:52 -06:00
|
|
|
self.window.change_status(status)
|
|
|
|
|
2018-12-16 00:41:47 -06:00
|
|
|
def chat_from_id(self, user_id, setfocus=True, unread=False):
|
2019-02-06 17:47:49 -06:00
|
|
|
""" Create a conversation buffer for.
|
|
|
|
@ user_id: Vk user, chat or community ID to chat with.
|
|
|
|
@ setfocus boolean: If set to True, the buffer will receive focus automatically right after being created.
|
|
|
|
@ unread: if set to True, the last message of the buffer will be marked as unread
|
|
|
|
"""
|
2016-05-25 11:33:57 -05:00
|
|
|
b = self.search_chat_buffer(user_id)
|
|
|
|
if b != None:
|
|
|
|
pos = self.window.search(b.name)
|
2016-06-03 11:24:14 -05:00
|
|
|
if setfocus:
|
|
|
|
self.window.change_buffer(pos)
|
|
|
|
return b.tab.text.SetFocus()
|
|
|
|
return
|
2019-01-07 17:52:14 -06:00
|
|
|
# Get name based in the ID.
|
|
|
|
# for users.
|
|
|
|
if user_id > 0 and user_id < 2000000000:
|
2019-01-11 04:22:53 -06:00
|
|
|
user = self.session.get_user(user_id, key="user1")
|
2019-01-27 05:37:42 -06:00
|
|
|
name = user["user1_nom"]
|
2019-01-07 17:52:14 -06:00
|
|
|
elif user_id > 2000000000:
|
|
|
|
chat = self.session.vk.client.messages.getChat(chat_id=user_id-2000000000)
|
2019-01-27 05:37:42 -06:00
|
|
|
name = chat["title"]
|
2019-04-09 16:08:14 -05:00
|
|
|
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="chatBuffer", buffer_title=name, parent_tab="chats", get_items=True, kwargs=dict(parent=self.window.tb, name="{0}_messages".format(user_id,), composefunc="render_message", parent_endpoint="messages", endpoint="getHistory", session=self.session, unread=unread, count=200, peer_id=user_id, rev=0, extended=True, fields="id, user_id, date, read_state, out, body, attachments, deleted"))
|
2019-01-14 01:59:32 -06:00
|
|
|
# if setfocus:
|
|
|
|
# pos = self.window.search(buffer.name)
|
|
|
|
# self.window.change_buffer(pos)
|
|
|
|
# call_threaded(buffer.get_items, unread=unread)
|
|
|
|
# if setfocus: buffer.tab.text.SetFocus()
|
|
|
|
# return True
|
2016-05-17 12:46:57 -05:00
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def authorisation_failed(self):
|
|
|
|
""" display an informative message about a failed authorization process."""
|
|
|
|
commonMessages.bad_authorisation()
|
2019-02-12 17:49:33 -06:00
|
|
|
restart.restart_program()
|
2019-02-06 17:47:49 -06:00
|
|
|
|
2019-02-14 08:36:31 -06:00
|
|
|
def connection_error(self, *args, **kwargs):
|
|
|
|
commonMessages.connection_error()
|
|
|
|
self.disconnect_events()
|
|
|
|
volume = player.player.volume
|
|
|
|
config.app["sound"]["volume"] = volume
|
|
|
|
config.app.write()
|
|
|
|
self.window.Destroy()
|
|
|
|
wx.GetApp().ExitMainLoop()
|
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def user_profile(self, person):
|
|
|
|
""" display someone's profile. For now, only users are supported."""
|
|
|
|
p = presenters.userProfilePresenter(session=self.session, user_id=person, view=views.userProfileDialog(), interactor=interactors.userProfileInteractor())
|
|
|
|
|
2018-12-10 00:48:40 -06:00
|
|
|
def user_online(self, event):
|
2019-02-06 17:47:49 -06:00
|
|
|
""" Sends a notification of an user connecting to VK.
|
|
|
|
@ event vk_api.longpoll.event object: The event sent by the vk_api's longPoll module.
|
|
|
|
"""
|
2018-12-11 11:45:38 -06:00
|
|
|
if self.session.settings["chat"]["notify_online"] == False:
|
|
|
|
return
|
2019-01-11 04:22:53 -06:00
|
|
|
user_name = self.session.get_user(event.user_id)
|
|
|
|
msg = _("{user1_nom} is online.").format(**user_name)
|
2018-12-12 12:24:05 -06:00
|
|
|
sound = "friend_online.ogg"
|
|
|
|
self.notify(msg, sound, self.session.settings["chat"]["notifications"])
|
2019-02-14 13:09:44 -06:00
|
|
|
online_buffer = self.search("online_friends")
|
|
|
|
user = None
|
|
|
|
for i in self.session.db["friends_"]["items"]:
|
|
|
|
if i["id"] == event.user_id:
|
|
|
|
user = i
|
|
|
|
user["last_seen"]["time"] = time.time()
|
|
|
|
break
|
|
|
|
if user == None:
|
|
|
|
log.exception("Getting user manually...")
|
|
|
|
user = self.session.vk.client.users.get(user_ids=event.user_id, fields="last_seen")[0]
|
|
|
|
online_buffer.add_person(user)
|
2018-12-10 00:48:40 -06:00
|
|
|
|
|
|
|
def user_offline(self, event):
|
2019-02-06 17:47:49 -06:00
|
|
|
""" Sends a notification of an user logging off in VK.
|
|
|
|
@ event vk_api.longpoll.event object: The event sent by the vk_api's longPoll module.
|
|
|
|
"""
|
2018-12-11 11:45:38 -06:00
|
|
|
if self.session.settings["chat"]["notify_offline"] == False:
|
|
|
|
return
|
2019-01-11 04:22:53 -06:00
|
|
|
user_name = self.session.get_user(event.user_id)
|
|
|
|
msg = _("{user1_nom} is offline.").format(**user_name)
|
2018-12-12 12:24:05 -06:00
|
|
|
sound = "friend_offline.ogg"
|
|
|
|
self.notify(msg, sound, self.session.settings["chat"]["notifications"])
|
2019-02-14 13:09:44 -06:00
|
|
|
online_friends = self.search("online_friends")
|
|
|
|
online_friends.remove_person(event.user_id)
|
2018-12-10 00:48:40 -06:00
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def notify(self, message="", sound="", type="native"):
|
|
|
|
""" display a notification in Socializer.
|
|
|
|
@message str: Message to display in the notification.
|
|
|
|
@sound str: sound file to play in the notification, if type is set to custom.
|
|
|
|
@type str: notification type: native or custom.
|
|
|
|
Native notifications are made with WX and don't have sound, while custom notifications have sound but are not displayed in the window.
|
|
|
|
"""
|
|
|
|
if type == "native":
|
|
|
|
self.window.notify(_("Socializer"), message)
|
|
|
|
else:
|
|
|
|
if sound != "":
|
|
|
|
self.session.soundplayer.play(sound)
|
|
|
|
if message != "":
|
|
|
|
output.speak(message)
|
|
|
|
|
|
|
|
def handle_longpoll_read_timeout(self):
|
|
|
|
""" This function tries to reconnect the long poll module until when it will get a successful connection.
|
|
|
|
Due to the way this method has been implemented, the function will be repeatedly called until it will connect properly.
|
|
|
|
"""
|
|
|
|
if hasattr(self, "longpoll"):
|
|
|
|
self.notify(message=_("Chat disconnected. Trying to connect in 60 seconds"))
|
|
|
|
time.sleep(60)
|
|
|
|
if hasattr(self, "longpoll"):
|
|
|
|
del self.longpoll
|
|
|
|
self.create_longpoll_thread(notify=True)
|
|
|
|
|
|
|
|
def create_buffer(self, buffer_type="baseBuffer", buffer_title="", parent_tab=None, loadable=False, get_items=False, kwargs={}):
|
|
|
|
""" Create and insert a buffer in the specified place.
|
|
|
|
@buffer_type str: name of the buffer type to be created. This should be a class in the buffers.py module.
|
|
|
|
@buffer_title str: Buffer title to be used in the Treebook.
|
|
|
|
@parent_tab str or None: If set to None, the parent tab will be the root of the treebook. In all other cases, the parent tab will be searched in the treebook.
|
|
|
|
@loadable bool: If set to True, the new buffer will not be able to load contents until can_get_items will be set to True.
|
|
|
|
@get_items bool: If set to True, get_items will be called inmediately after creating the buffer.
|
|
|
|
"""
|
|
|
|
if not hasattr(buffers, buffer_type):
|
|
|
|
raise AttributeError("Specified buffer type does not exist: %s" % (buffer_type,))
|
|
|
|
buffer = getattr(buffers, buffer_type)(**kwargs)
|
|
|
|
if loadable:
|
|
|
|
buffer.can_get_items = False
|
|
|
|
self.buffers.append(buffer)
|
|
|
|
if parent_tab == None:
|
|
|
|
self.window.add_buffer(buffer.tab, buffer_title)
|
|
|
|
else:
|
|
|
|
self.window.insert_buffer(buffer.tab, buffer_title, self.window.search(parent_tab))
|
|
|
|
if get_items:
|
|
|
|
call_threaded(buffer.get_items)
|
|
|
|
|
2019-01-11 17:00:58 -06:00
|
|
|
def user_typing(self, obj):
|
2019-02-06 17:47:49 -06:00
|
|
|
""" Indicates when someone is typing.
|
|
|
|
@ event vk_api.longpoll.event object: The event sent by the vk_api's longPoll module.
|
|
|
|
"""
|
2019-01-11 17:00:58 -06:00
|
|
|
buffer = self.search_chat_buffer(obj.user_id)
|
2019-02-26 16:17:53 -06:00
|
|
|
if buffer != None and buffer == self.get_current_buffer() and self.is_focused():
|
2019-01-13 12:37:19 -06:00
|
|
|
user = self.session.get_user(obj.user_id)
|
2019-01-11 17:00:58 -06:00
|
|
|
output.speak(_("{user1_nom} is typing...").format(**user))
|
|
|
|
|
2016-05-17 12:46:57 -05:00
|
|
|
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.
|
2019-02-06 17:47:49 -06:00
|
|
|
@obj vk_api.longpoll.EventType: an event wich defines some data from the vk's long poll server."""
|
2018-12-17 17:47:15 -06:00
|
|
|
message = {}
|
2019-01-07 17:52:14 -06:00
|
|
|
uid = obj.peer_id
|
|
|
|
buffer = self.search_chat_buffer(uid)
|
|
|
|
if obj.from_me:
|
2018-12-17 17:47:15 -06:00
|
|
|
message.update(out=0)
|
2018-12-11 11:45:38 -06:00
|
|
|
# If there is no buffer, we must create one in a wxThread so it will not crash.
|
2016-05-17 12:46:57 -05:00
|
|
|
if buffer == None:
|
2018-12-16 00:41:47 -06:00
|
|
|
wx.CallAfter(self.chat_from_id, uid, setfocus=self.session.settings["chat"]["automove_to_conversations"], unread=True)
|
2018-12-12 12:38:01 -06:00
|
|
|
self.session.soundplayer.play("conversation_opened.ogg")
|
2016-05-17 12:46:57 -05:00
|
|
|
return
|
|
|
|
# If the chat already exists, let's create a dictionary wich will contains data of the received message.
|
2019-02-03 21:04:10 -06:00
|
|
|
message.update(id=obj.message_id, user_id=uid, date=obj.timestamp, body=utils.clean_text(obj.text), attachments=obj.attachments)
|
2017-03-13 02:16:34 -06:00
|
|
|
# if attachments is true, let's request for the full message with attachments formatted in a better way.
|
2019-01-16 17:54:29 -06:00
|
|
|
# ToDo: code improvements. We shouldn't need to request the same message again just for these attachments.
|
2017-03-13 02:16:34 -06:00
|
|
|
if len(message["attachments"]) != 0:
|
|
|
|
message_ids = message["id"]
|
|
|
|
results = self.session.vk.client.messages.getById(message_ids=message_ids)
|
|
|
|
message = results["items"][0]
|
2018-12-09 07:25:30 -06:00
|
|
|
if obj.from_me:
|
2016-05-17 12:46:57 -05:00
|
|
|
message["from_id"] = self.session.user_id
|
|
|
|
else:
|
2019-01-21 04:44:16 -06:00
|
|
|
message.update(read_state=0, out=0)
|
2018-12-09 07:25:30 -06:00
|
|
|
message["from_id"] = obj.user_id
|
2016-05-17 12:46:57 -05:00
|
|
|
data = [message]
|
|
|
|
# Let's add this to the buffer.
|
|
|
|
# ToDo: Clean this code and test how is the database working with this set to True.
|
2019-04-09 16:08:14 -05:00
|
|
|
buffer.session.db[buffer.name]["items"].append(message)
|
2016-05-17 12:46:57 -05:00
|
|
|
buffer.insert(self.session.db[buffer.name]["items"][-1], False)
|
2018-12-11 11:45:38 -06:00
|
|
|
self.session.soundplayer.play("message_received.ogg")
|
2019-01-22 16:20:37 -06:00
|
|
|
wx.CallAfter(self.reorder_buffer, buffer)
|
2018-12-13 12:05:48 -06:00
|
|
|
# Check if we have to read the message aloud
|
|
|
|
if buffer == self.get_current_buffer():
|
|
|
|
rendered_message = renderers.render_message(message, self.session)
|
|
|
|
output.speak(rendered_message[0])
|
2016-06-03 10:24:35 -05:00
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
### GUI events
|
|
|
|
# These functions are connected to GUI elements such as menus, buttons and so on.
|
|
|
|
def connect_gui_events(self):
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.CLOSE_EVENT, self.exit)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.update_buffer, menuitem=self.window.update_buffer)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_for_updates, menuitem=self.window.check_for_updates)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.window.about_dialog, menuitem=self.window.about)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.search_audios, menuitem=self.window.search_audios)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.search_videos, menuitem=self.window.search_videos)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU,self.remove_buffer, menuitem=self.window.remove_buffer_)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.get_more_items, menuitem=self.window.load_previous_items)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.changelog, menuitem=self.window.changelog)
|
2019-02-13 16:48:00 -06:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.open_logs, menuitem=self.window.open_logs)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.open_config, menuitem=self.window.open_config)
|
2019-02-06 17:47:49 -06:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.configuration, menuitem=self.window.settings_dialog)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.new_timeline, menuitem=self.window.timeline)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.create_audio_album, menuitem=self.window.audio_album)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.delete_audio_album, menuitem=self.window.delete_audio_album)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.create_video_album, menuitem=self.window.video_album)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.delete_video_album, menuitem=self.window.delete_video_album)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_documentation, menuitem=self.window.documentation)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_play_pause, menuitem=self.window.player_play)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_play_next, menuitem=self.window.player_next)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_play_previous, menuitem=self.window.player_previous)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_play_all, menuitem=self.window.player_play_all)
|
2019-04-17 11:46:26 -05:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.seek_left, menuitem=self.window.player_seek_left)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.seek_right, menuitem=self.window.player_seek_right)
|
2019-02-06 17:47:49 -06:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_volume_down, menuitem=self.window.player_volume_down)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_volume_up, menuitem=self.window.player_volume_up)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_mute, menuitem=self.window.player_mute)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.view_my_profile, menuitem=self.window.view_profile)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.view_my_profile_in_browser, menuitem=self.window.open_in_browser)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.set_status, menuitem=self.window.set_status)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_report_error, menuitem=self.window.report)
|
|
|
|
self.window.tb.Bind(wx.EVT_CONTEXT_MENU, self.on_context_menu)
|
|
|
|
|
|
|
|
def exit(self, *args, **kwargs):
|
|
|
|
""" Try to set offline in the current user's profile at VK, then closes the application. """
|
|
|
|
log.debug("Receibed an exit signal. closing...")
|
|
|
|
self.set_offline()
|
|
|
|
self.disconnect_events()
|
|
|
|
volume = player.player.volume
|
|
|
|
config.app["sound"]["volume"] = volume
|
|
|
|
config.app.write()
|
|
|
|
self.window.Destroy()
|
|
|
|
wx.GetApp().ExitMainLoop()
|
|
|
|
|
|
|
|
def update_buffer(self, *args, **kwargs):
|
|
|
|
""" Update the current buffer, getting the recent items."""
|
|
|
|
b = self.get_current_buffer()
|
|
|
|
b.get_items()
|
|
|
|
|
|
|
|
def check_for_updates(self, *args, **kwargs):
|
|
|
|
update = updater.do_update(update_type=self.session.settings["general"]["update_channel"])
|
|
|
|
if update == False:
|
|
|
|
commonMessages.no_update_available()
|
|
|
|
|
|
|
|
def search_audios(self, *args, **kwargs):
|
|
|
|
dlg = searchDialogs.searchAudioDialog()
|
|
|
|
if dlg.get_response() == widgetUtils.OK:
|
|
|
|
q = dlg.get("term")
|
|
|
|
auto_complete = True
|
|
|
|
count = 300
|
|
|
|
performer_only = dlg.get_state("title")
|
|
|
|
sort = dlg.get_sort_order()
|
|
|
|
newbuff = buffers.audioBuffer(parent=self.window.tb, name="{0}_audiosearch".format(q,), session=self.session, composefunc="render_audio", parent_endpoint="audio", endpoint="search", q=q, auto_complete=auto_complete, count=count, performer_only=performer_only, sort=sort)
|
|
|
|
self.buffers.append(newbuff)
|
|
|
|
call_threaded(newbuff.get_items)
|
|
|
|
# Translators: {0} will be replaced with the search term.
|
|
|
|
self.window.insert_buffer(newbuff.tab, _("Search for {0}").format(q,), self.window.search("audios"))
|
2016-06-03 10:24:35 -05:00
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def search_videos(self, *args, **kwargs):
|
|
|
|
dlg = searchDialogs.searchVideoDialog()
|
|
|
|
if dlg.get_response() == widgetUtils.OK:
|
|
|
|
params = {}
|
|
|
|
params["q"] = dlg.get("term")
|
|
|
|
params["count"] = 200
|
|
|
|
hd = dlg.get_checkable("hd")
|
|
|
|
if hd != 0:
|
|
|
|
params["hd"] = 1
|
|
|
|
params["adult"] = dlg.get_checkable("safe_search")
|
|
|
|
params["sort"] = dlg.get_sort_order()
|
|
|
|
# params["filters"] = "youtube, vimeo, short, long, mp4"
|
2019-02-14 13:09:44 -06:00
|
|
|
# print(params)
|
2019-02-06 17:47:49 -06:00
|
|
|
newbuff = buffers.videoBuffer(parent=self.window.tb, name="{0}_videosearch".format(params["q"],), session=self.session, composefunc="render_video", parent_endpoint="video", endpoint="search", **params)
|
|
|
|
self.buffers.append(newbuff)
|
|
|
|
call_threaded(newbuff.get_items)
|
|
|
|
# Translators: {0} will be replaced with the search term.
|
|
|
|
self.window.insert_buffer(newbuff.tab, _("Search for {0}").format(params["q"],), self.window.search("videos"))
|
2018-12-10 13:25:30 -06:00
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def remove_buffer(self, event, mandatory=False, *args, **kwargs):
|
|
|
|
buffer = self.get_current_buffer()
|
|
|
|
buff = self.window.search(buffer.name)
|
|
|
|
answer = buffer.remove_buffer(mandatory)
|
|
|
|
if answer == False:
|
2018-12-11 11:45:38 -06:00
|
|
|
return
|
2019-02-06 17:47:49 -06:00
|
|
|
self.window.remove_buffer(buff)
|
|
|
|
self.buffers.remove(buffer)
|
|
|
|
del buffer
|
2016-06-19 12:25:06 -05:00
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def get_more_items(self, *args, **kwargs):
|
|
|
|
b = self.get_current_buffer()
|
|
|
|
b.get_more_items()
|
2018-12-20 08:33:16 -06:00
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def changelog(self, *args, **kwargs):
|
|
|
|
lang = localization.get("documentation")
|
|
|
|
os.chdir("documentation/%s" % (lang,))
|
|
|
|
webbrowser.open("changelog.html")
|
|
|
|
os.chdir("../../")
|
|
|
|
def configuration(self, *args, **kwargs):
|
|
|
|
""" Opens the global settings dialogue."""
|
|
|
|
presenter = presenters.configurationPresenter(session=self.session, view=views.configurationDialog(title=_("Preferences")), interactor=interactors.configurationInteractor())
|
2018-12-30 10:41:47 -06:00
|
|
|
|
2019-02-13 16:48:00 -06:00
|
|
|
def open_logs(self, *args, **kwargs):
|
|
|
|
subprocess.call(["explorer", paths.logs_path()])
|
|
|
|
|
|
|
|
def open_config(self, *args, **kwargs):
|
|
|
|
subprocess.call(["explorer", paths.config_path()])
|
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def new_timeline(self, *args, **kwargs):
|
|
|
|
b = self.get_current_buffer()
|
|
|
|
# If executing this method from an empty buffer we should get the newsfeed buffer.
|
|
|
|
if not hasattr(b, "get_users"):
|
|
|
|
b = self.search("home_timeline")
|
|
|
|
# Get a list of (id, user) objects.
|
|
|
|
d = []
|
|
|
|
for i in self.session.db["users"]:
|
|
|
|
d.append((i, self.session.get_user(i)["user1_gen"]))
|
|
|
|
# Do the same for communities.
|
|
|
|
for i in self.session.db["groups"]:
|
|
|
|
d.append((-i, self.session.get_user(-i)["user1_nom"]))
|
|
|
|
a = timeline.timelineDialog([i[1] for i in d])
|
|
|
|
if a.get_response() == widgetUtils.OK:
|
|
|
|
user = a.get_user()
|
|
|
|
buffertype = a.get_buffer_type()
|
|
|
|
user_id = ""
|
|
|
|
for i in d:
|
|
|
|
if i[1] == user:
|
|
|
|
user_id = i[0]
|
|
|
|
if user_id == "":
|
|
|
|
user_data = self.session.vk.client.utils.resolveScreenName(screen_name=user)
|
|
|
|
if type(user_data) == list:
|
|
|
|
commonMessages.no_user_exist()
|
|
|
|
return
|
|
|
|
user_id = user_data["object_id"]
|
|
|
|
if buffertype == "audio":
|
|
|
|
buffer = buffers.audioBuffer(parent=self.window.tb, name="{0}_audio".format(user_id,), composefunc="render_audio", session=self.session, create_tab=False, endpoint="get", parent_endpoint="audio", owner_id=user_id)
|
|
|
|
user = self.session.get_user(user_id, key="user1")
|
|
|
|
name_ = _("{user1_nom}'s audios").format(**user)
|
|
|
|
elif buffertype == "wall":
|
|
|
|
buffer = buffers.feedBuffer(parent=self.window.tb, name="{0}_feed".format(user_id,), composefunc="render_status", session=self.session, create_tab=False, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"], owner_id=user_id)
|
|
|
|
user = self.session.get_user(user_id, key="user1")
|
|
|
|
name_ = _("{user1_nom}'s posts").format(**user)
|
|
|
|
elif buffertype == "friends":
|
|
|
|
buffer = buffers.peopleBuffer(parent=self.window.tb, name="friends_{0}".format(user_id,), composefunc="render_person", session=self.session, create_tab=False, endpoint="get", parent_endpoint="friends", count=5000, fields="uid, first_name, last_name, last_seen", user_id=user_id)
|
|
|
|
user = self.session.get_user(user_id, key="user1")
|
|
|
|
name_ = _("{user1_nom}'s friends").format(**user)
|
|
|
|
wx.CallAfter(self.complete_buffer_creation, buffer=buffer, name_=name_, position=self.window.search("timelines"))
|
2016-08-14 07:46:41 -05:00
|
|
|
|
2016-06-19 12:25:06 -05:00
|
|
|
def create_audio_album(self, *args, **kwargs):
|
|
|
|
d = creation.audio_album()
|
|
|
|
if d.get_response() == widgetUtils.OK and d.get("title") != "":
|
2019-01-26 18:42:50 -06:00
|
|
|
response = self.session.vk.client.audio.createPlaylist(owner_id=self.session.user_id, title=d.get("title"))
|
|
|
|
if "id" not in response:
|
|
|
|
return
|
|
|
|
album_id = response["id"]
|
2018-12-06 15:37:16 -06:00
|
|
|
buffer = buffers.audioAlbum(parent=self.window.tb, name="{0}_audio_album".format(album_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=self.session.user_id, album_id=album_id)
|
2016-06-29 12:33:09 -05:00
|
|
|
buffer.can_get_items = False
|
2016-06-29 10:56:41 -05:00
|
|
|
# Translators: {0} will be replaced with an audio album's title.
|
2019-01-01 19:42:53 -06:00
|
|
|
name_ = _("Album: {0}").format(d.get("title"),)
|
2016-06-19 12:25:06 -05:00
|
|
|
self.buffers.append(buffer)
|
|
|
|
self.window.insert_buffer(buffer.tab, name_, self.window.search("albums"))
|
2016-06-28 22:32:32 -05:00
|
|
|
buffer.get_items()
|
2019-01-26 18:42:50 -06:00
|
|
|
self.get_audio_albums(user_id=self.session.user_id, create_buffers=False)
|
2016-06-28 22:32:32 -05:00
|
|
|
|
|
|
|
def delete_audio_album(self, *args, **kwargs):
|
2019-01-11 10:03:51 -06:00
|
|
|
if len(self.session.audio_albums) == 0:
|
|
|
|
return commonMessages.no_audio_albums()
|
2019-01-01 19:42:53 -06:00
|
|
|
answer = selector.album(_("Select the album you want to delete"), self.session)
|
2016-06-28 22:32:32 -05:00
|
|
|
if answer.item == None:
|
|
|
|
return
|
|
|
|
response = commonMessages.delete_audio_album()
|
|
|
|
if response != widgetUtils.YES: return
|
2019-01-26 18:42:50 -06:00
|
|
|
removal = self.session.vk.client.audio.deletePlaylist(playlist_id=answer.item, owner_id=self.session.user_id)
|
|
|
|
if removal == 1:
|
|
|
|
buffer = self.search("{0}_audio_album".format(answer.item,))
|
|
|
|
buff = self.window.search(buffer.name)
|
|
|
|
self.window.remove_buffer(buff)
|
|
|
|
self.buffers.remove(buffer)
|
|
|
|
del buffer
|
|
|
|
self.get_audio_albums(user_id=self.session.user_id, create_buffers=False)
|
2016-06-29 13:16:35 -05:00
|
|
|
|
2016-08-14 07:46:41 -05:00
|
|
|
def create_video_album(self, *args, **kwargs):
|
|
|
|
d = creation.audio_album()
|
|
|
|
if d.get_response() == widgetUtils.OK and d.get("title") != "":
|
|
|
|
response = self.session.vk.client.video.addAlbum(title=d.get("title"))
|
2019-01-01 19:42:53 -06:00
|
|
|
if ("album_id" in response) == False: return
|
2016-08-14 07:46:41 -05:00
|
|
|
album_id = response["album_id"]
|
2018-12-06 15:37:16 -06:00
|
|
|
buffer = buffers.videoAlbum(parent=self.window.tb, name="{0}_video_album".format(album_id,), composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], user_id=self.session.user_id, album_id=album_id)
|
2016-08-14 07:46:41 -05:00
|
|
|
buffer.can_get_items = False
|
|
|
|
# Translators: {0} will be replaced with a video album's title.
|
2019-01-01 19:42:53 -06:00
|
|
|
name_ = _("Album: {0}").format(d.get("title"),)
|
2016-08-14 07:46:41 -05:00
|
|
|
self.buffers.append(buffer)
|
|
|
|
self.window.insert_buffer(buffer.tab, name_, self.window.search("video_albums"))
|
|
|
|
buffer.get_items()
|
|
|
|
self.session.video_albums = self.session.vk.client.video.getAlbums(owner_id=self.session.user_id)["items"]
|
|
|
|
|
|
|
|
def delete_video_album(self, *args, **kwargs):
|
2019-01-11 10:03:51 -06:00
|
|
|
if len(self.session.video_albums) == 0:
|
|
|
|
return commonMessages.no_video_albums()
|
2019-01-01 19:42:53 -06:00
|
|
|
answer = selector.album(_("Select the album you want to delete"), self.session, "video_albums")
|
2016-08-14 07:46:41 -05:00
|
|
|
if answer.item == None:
|
|
|
|
return
|
|
|
|
response = commonMessages.delete_audio_album()
|
|
|
|
if response != widgetUtils.YES: return
|
|
|
|
removal = self.session.vk.client.video.deleteAlbum(album_id=answer.item)
|
|
|
|
buffer = self.search("{0}_video_album".format(answer.item,))
|
|
|
|
buff = self.window.search(buffer.name)
|
|
|
|
self.window.remove_buffer(buff)
|
|
|
|
self.buffers.remove(buffer)
|
|
|
|
del buffer
|
|
|
|
self.session.video_albums = self.session.vk.client.video.getAlbums(owner_id=self.session.user_id)["items"]
|
|
|
|
|
2016-06-29 13:16:35 -05:00
|
|
|
def check_documentation(self, *args, **kwargs):
|
|
|
|
lang = localization.get("documentation")
|
|
|
|
os.chdir("documentation/%s" % (lang,))
|
|
|
|
webbrowser.open("manual.html")
|
|
|
|
os.chdir("../../")
|
2016-07-18 17:34:37 -05:00
|
|
|
|
|
|
|
def menu_play_pause(self, *args, **kwargs):
|
2019-01-21 16:48:51 -06:00
|
|
|
if player.player.stream != None:
|
2016-07-18 17:34:37 -05:00
|
|
|
return player.player.pause()
|
|
|
|
else:
|
2019-01-21 16:48:51 -06:00
|
|
|
b = self.get_current_buffer()
|
2019-01-22 17:41:39 -06:00
|
|
|
if hasattr(b, "play_all"):
|
|
|
|
b.play_all()
|
2019-01-21 16:48:51 -06:00
|
|
|
else:
|
2019-01-22 17:41:39 -06:00
|
|
|
self.search("me_audio").play_all()
|
2016-07-18 17:34:37 -05:00
|
|
|
|
|
|
|
def menu_play_next(self, *args, **kwargs):
|
2019-04-11 17:43:52 -05:00
|
|
|
pub.sendMessage("play-next")
|
2016-07-18 17:34:37 -05:00
|
|
|
|
|
|
|
def menu_play_previous(self, *args, **kwargs):
|
2019-04-11 17:43:52 -05:00
|
|
|
pub.sendMessage("play-previous")
|
2016-07-18 17:34:37 -05:00
|
|
|
|
|
|
|
def menu_play_all(self, *args, **kwargs):
|
|
|
|
b = self.get_current_buffer()
|
|
|
|
if hasattr(b, "play_all"):
|
|
|
|
b.play_all()
|
|
|
|
else:
|
|
|
|
self.search("me_audio").play_all()
|
|
|
|
|
|
|
|
def menu_volume_down(self, *args, **kwargs):
|
2019-03-25 16:35:28 -06:00
|
|
|
player.player.volume = player.player.volume-2
|
2016-07-18 17:34:37 -05:00
|
|
|
|
|
|
|
def menu_volume_up(self, *args, **kwargs):
|
2019-03-25 16:35:28 -06:00
|
|
|
player.player.volume = player.player.volume+2
|
2016-07-18 17:34:37 -05:00
|
|
|
|
|
|
|
def menu_mute(self, *args, **kwargs):
|
|
|
|
player.player.volume = 0
|
|
|
|
|
2019-04-17 11:46:26 -05:00
|
|
|
def seek_left(self, *args, **kwargs):
|
|
|
|
pub.sendMessage("seek", ms=-500000)
|
|
|
|
|
|
|
|
def seek_right(self, *args, **kwargs):
|
|
|
|
pub.sendMessage("seek", ms=500000)
|
|
|
|
|
2018-09-06 10:47:10 -05:00
|
|
|
def view_my_profile(self, *args, **kwargs):
|
2018-09-06 13:07:55 -05:00
|
|
|
self.user_profile(self.session.user_id)
|
|
|
|
|
|
|
|
def view_my_profile_in_browser(self, *args, **kwargs):
|
2018-12-10 17:35:36 -06:00
|
|
|
webbrowser.open_new_tab("https://vk.com/id{id}".format(id=self.session.user_id,))
|
|
|
|
|
2018-12-18 16:32:14 -06:00
|
|
|
def set_status(self, *args, **kwargs):
|
2019-01-01 19:42:53 -06:00
|
|
|
dlg = wx.TextEntryDialog(self.window, _("Write your status message"), _("Set status"))
|
2018-12-18 16:32:14 -06:00
|
|
|
if dlg.ShowModal() == widgetUtils.OK:
|
|
|
|
result = dlg.GetValue()
|
|
|
|
info = self.session.vk.client.account.saveProfileInfo(status=result)
|
|
|
|
commonMessages.updated_status()
|
2018-12-22 08:08:30 -06:00
|
|
|
dlg.Destroy()
|
|
|
|
|
|
|
|
def on_report_error(self, *args, **kwargs):
|
2019-01-22 16:20:37 -06:00
|
|
|
r = issueReporter.reportBug()
|
|
|
|
|
2019-02-06 17:47:49 -06:00
|
|
|
def on_context_menu(self, event, *args, **kwargs):
|
|
|
|
""" Handles context menu event in the tree buffers."""
|
|
|
|
# If the focus is not in the TreeCtrl of the Treebook, then we should not display any menu.
|
|
|
|
if isinstance(self.window.FindFocus(), wx.TreeCtrl) == False:
|
|
|
|
event.Skip()
|
2019-01-22 16:20:37 -06:00
|
|
|
return
|
2019-02-06 17:47:49 -06:00
|
|
|
menu = None
|
|
|
|
# Get the current buffer and let's choose a different menu depending on the selected buffer.
|
|
|
|
current_buffer = self.get_current_buffer()
|
|
|
|
# Deal with menu for community buffers.
|
|
|
|
if current_buffer.name.endswith("_community"):
|
|
|
|
menu = menus.communityBufferMenu()
|
|
|
|
# disable post loading if the community has already loaded posts.
|
|
|
|
if current_buffer.can_get_items:
|
|
|
|
menu.load_posts.Enable(False)
|
|
|
|
# Disable loading of audios, videos, documents or topics depending in two conditions.
|
|
|
|
# 1. If the buffer already exists, which means they are already loaded, or
|
|
|
|
# 2. If the group_info does not have counters for such items, which would indicate there are no items posted yet.
|
|
|
|
if self.search(current_buffer.name+"_audios") != False:
|
|
|
|
menu.load_audios.Enable(False)
|
2019-05-06 15:50:45 -05:00
|
|
|
elif "counters" in self.session.db["group_info"][current_buffer.group_id] and "audios" not in self.session.db["group_info"][current_buffer.group_id]["counters"]:
|
2019-02-06 17:47:49 -06:00
|
|
|
menu.load_audios.Enable(False)
|
|
|
|
if self.search(current_buffer.name+"_videos") != False:
|
|
|
|
menu.load_videos.Enable(False)
|
2019-05-06 15:50:45 -05:00
|
|
|
elif "counters" in self.session.db["group_info"][current_buffer.group_id] and "videos" not in self.session.db["group_info"][current_buffer.group_id]["counters"]:
|
2019-02-06 17:47:49 -06:00
|
|
|
menu.load_videos.Enable(False)
|
|
|
|
if self.search(current_buffer.name+"_topics") != False:
|
|
|
|
menu.load_topics.Enable(False)
|
2019-05-06 15:50:45 -05:00
|
|
|
elif "counters" in self.session.db["group_info"][current_buffer.group_id] and "topics" not in self.session.db["group_info"][current_buffer.group_id]["counters"]:
|
2019-02-06 17:47:49 -06:00
|
|
|
menu.load_topics.Enable(False)
|
|
|
|
if self.search(current_buffer.name+"_documents") != False:
|
|
|
|
menu.load_documents.Enable(False)
|
2019-05-06 15:50:45 -05:00
|
|
|
elif "counters" in self.session.db["group_info"][current_buffer.group_id] and "docs" not in self.session.db["group_info"][current_buffer.group_id]["counters"]:
|
2019-02-06 17:47:49 -06:00
|
|
|
menu.load_documents.Enable(False)
|
|
|
|
# Connect the rest of the functions.
|
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_posts, menuitem=menu.load_posts)
|
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_topics, menuitem=menu.load_topics)
|
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_audios, menuitem=menu.load_audios)
|
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_videos, menuitem=menu.load_videos)
|
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_documents, menuitem=menu.load_documents)
|
|
|
|
# Deal with the communities section itself.
|
2019-02-25 15:42:59 -06:00
|
|
|
elif current_buffer.name == "communities":
|
2019-02-06 17:47:49 -06:00
|
|
|
menu = wx.Menu()
|
|
|
|
# Insert a different option depending if group buffers are loaded or scheduled to be loaded or not.
|
|
|
|
if self.session.settings["load_at_startup"]["communities"] == False and not hasattr(self.session, "groups"):
|
|
|
|
option = menu.Append(wx.NewId(), _("Load groups"))
|
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_community_buffers, menuitem=option)
|
|
|
|
else:
|
|
|
|
option = menu.Append(wx.NewId(), _("Discard groups"))
|
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.unload_community_buffers, menuitem=option)
|
2019-04-09 17:55:05 -05:00
|
|
|
# Deal with video and audio albums' sections.
|
2019-02-25 15:42:59 -06:00
|
|
|
elif current_buffer.name == "audio_albums":
|
|
|
|
menu = wx.Menu()
|
|
|
|
if self.session.settings["load_at_startup"]["audio_albums"] == False and not hasattr(self.session, "audio_albums"):
|
|
|
|
option = menu.Append(wx.NewId(), _("Load audio albums"))
|
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_audio_album_buffers, menuitem=option)
|
|
|
|
else:
|
|
|
|
option = menu.Append(wx.NewId(), _("Discard audio albums"))
|
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.unload_audio_album_buffers, menuitem=option)
|
|
|
|
elif current_buffer.name == "video_albums":
|
|
|
|
menu = wx.Menu()
|
|
|
|
if self.session.settings["load_at_startup"]["video_albums"] == False and not hasattr(self.session, "video_albums"):
|
|
|
|
option = menu.Append(wx.NewId(), _("Load video albums"))
|
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.load_video_album_buffers, menuitem=option)
|
|
|
|
else:
|
|
|
|
option = menu.Append(wx.NewId(), _("Discard video albums"))
|
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.unload_video_album_buffers, menuitem=option)
|
2019-04-09 17:55:05 -05:00
|
|
|
elif current_buffer.name.endswith("_messages"):
|
|
|
|
menu = menus.conversationBufferMenu()
|
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, self.delete_conversation, menuitem=menu.delete)
|
2019-04-13 18:43:48 -05:00
|
|
|
widgetUtils.connect_event(menu, widgetUtils.MENU, current_buffer.open_in_browser, menuitem=menu.open_in_browser)
|
2019-02-06 17:47:49 -06:00
|
|
|
if menu != None:
|
|
|
|
self.window.PopupMenu(menu, self.window.FindFocus().GetPosition())
|
|
|
|
# If there are no available menus, let's indicate it.
|
2019-01-22 16:20:37 -06:00
|
|
|
else:
|
2019-02-06 17:47:49 -06:00
|
|
|
output.speak(_("menu unavailable for this buffer."))
|
2019-01-30 15:32:46 -06:00
|
|
|
|
|
|
|
def load_community_posts(self, *args, **kwargs):
|
2019-01-31 16:46:55 -06:00
|
|
|
""" Load community posts. It just calls to the needed method in the community buffer."""
|
2019-01-30 15:32:46 -06:00
|
|
|
current_buffer = self.get_current_buffer()
|
|
|
|
if current_buffer.name.endswith("_community"):
|
|
|
|
current_buffer.load_community()
|
|
|
|
|
|
|
|
def load_community_audios(self, *args, **kwargs):
|
2019-01-31 16:46:55 -06:00
|
|
|
""" Load community audios if they are not loaded already."""
|
2019-01-30 15:32:46 -06:00
|
|
|
current_buffer = self.get_current_buffer()
|
2019-01-31 16:46:55 -06:00
|
|
|
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
|
2019-05-06 15:50:45 -05:00
|
|
|
if current_buffer.group_id not in self.session.db["group_info"] or "counters" not in self.session.db["group_info"][current_buffer.group_id]:
|
2019-01-30 15:32:46 -06:00
|
|
|
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
|
2019-05-06 15:50:45 -05:00
|
|
|
self.session.db["group_info"][current_buffer.kwargs["owner_id"]] = group_info
|
|
|
|
if "audios" not in self.session.db["group_info"][current_buffer.group_id]["counters"]:
|
2019-01-30 15:32:46 -06:00
|
|
|
commonMessages.community_no_items()
|
|
|
|
return
|
|
|
|
new_name = current_buffer.name+"_audios"
|
|
|
|
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="audioBuffer", buffer_title=_("Audios"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", owner_id=current_buffer.kwargs["owner_id"]))
|
|
|
|
|
|
|
|
def load_community_videos(self, *args, **kwargs):
|
2019-01-31 16:46:55 -06:00
|
|
|
""" Load community videos if they are not loaded already."""
|
2019-01-30 15:32:46 -06:00
|
|
|
current_buffer = self.get_current_buffer()
|
2019-01-31 16:46:55 -06:00
|
|
|
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
|
2019-05-06 15:50:45 -05:00
|
|
|
if current_buffer.group_id not in self.session.db["group_info"] or "counters" not in self.session.db["group_info"][current_buffer.group_id]:
|
2019-01-30 15:32:46 -06:00
|
|
|
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
|
2019-05-06 15:50:45 -05:00
|
|
|
self.session.db["group_info"][current_buffer.kwargs["owner_id"]] = group_info
|
|
|
|
if "videos" not in self.session.db["group_info"][current_buffer.group_id]["counters"]:
|
2019-01-30 15:32:46 -06:00
|
|
|
commonMessages.community_no_items()
|
|
|
|
return
|
|
|
|
new_name = current_buffer.name+"_videos"
|
|
|
|
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="videoBuffer", buffer_title=_("Videos"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], owner_id=current_buffer.kwargs["owner_id"]))
|
|
|
|
|
|
|
|
def load_community_topics(self, *args, **kwargs):
|
2019-01-31 16:46:55 -06:00
|
|
|
""" Load community topics."""
|
|
|
|
current_buffer = self.get_current_buffer()
|
|
|
|
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
|
2019-05-06 15:50:45 -05:00
|
|
|
if current_buffer.group_id not in self.session.db["group_info"] or "counters" not in self.session.db["group_info"][current_buffer.group_id]:
|
2019-01-31 16:46:55 -06:00
|
|
|
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
|
2019-05-06 15:50:45 -05:00
|
|
|
self.session.db["group_info"][current_buffer.kwargs["owner_id"]] = group_info
|
|
|
|
if "topics" not in self.session.db["group_info"][current_buffer.group_id]["counters"]:
|
2019-01-31 16:46:55 -06:00
|
|
|
commonMessages.community_no_items()
|
|
|
|
return
|
|
|
|
new_name = current_buffer.name+"_topics"
|
|
|
|
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="topicBuffer", buffer_title=_("Topics"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_topic", session=self.session, endpoint="getTopics", parent_endpoint="board", count=100, group_id=-1*current_buffer.kwargs["owner_id"], extended=1))
|
2019-01-30 15:32:46 -06:00
|
|
|
|
2019-02-05 12:20:50 -06:00
|
|
|
def load_community_documents(self, *args, **kwargs):
|
|
|
|
current_buffer = self.get_current_buffer()
|
|
|
|
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
|
2019-05-06 15:50:45 -05:00
|
|
|
if current_buffer.group_id not in self.session.db["group_info"] or "counters" not in self.session.db["group_info"][current_buffer.group_id]:
|
2019-02-05 12:20:50 -06:00
|
|
|
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
|
2019-05-06 15:50:45 -05:00
|
|
|
self.session.db["group_info"][current_buffer.kwargs["owner_id"]] = group_info
|
|
|
|
if "docs" not in self.session.db["group_info"][current_buffer.group_id]["counters"]:
|
2019-02-05 12:20:50 -06:00
|
|
|
commonMessages.community_no_items()
|
|
|
|
return
|
|
|
|
new_name = current_buffer.name+"_documents"
|
2019-02-06 11:35:38 -06:00
|
|
|
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="documentCommunityBuffer", buffer_title=_("Documents"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_document", session=self.session, endpoint="get", parent_endpoint="docs", owner_id=current_buffer.kwargs["owner_id"]))
|
2019-02-05 12:20:50 -06:00
|
|
|
|
2019-01-30 15:32:46 -06:00
|
|
|
def load_community_buffers(self, *args, **kwargs):
|
2019-01-31 16:46:55 -06:00
|
|
|
""" Load all community buffers regardless of the setting present in optional buffers tab of the preferences dialog."""
|
2019-01-30 15:32:46 -06:00
|
|
|
call_threaded(self.get_communities, self.session.user_id, force_action=True)
|
|
|
|
|
|
|
|
def unload_community_buffers(self, *args, **kwargs):
|
2019-01-31 16:46:55 -06:00
|
|
|
""" Delete all buffers belonging to groups."""
|
2019-01-30 15:32:46 -06:00
|
|
|
communities = self.get_all_buffers("_community")
|
|
|
|
for buffer in communities:
|
|
|
|
buff = self.window.search(buffer.name)
|
|
|
|
self.window.remove_buffer(buff)
|
|
|
|
self.buffers.remove(buffer)
|
2019-02-25 15:42:59 -06:00
|
|
|
del self.session.groups
|
|
|
|
|
|
|
|
def load_audio_album_buffers(self, *args, **kwargs):
|
|
|
|
""" Load all audio album buffers regardless of the setting present in optional buffers tab of the preferences dialog."""
|
|
|
|
call_threaded(self.get_audio_albums, self.session.user_id, force_action=True)
|
|
|
|
|
|
|
|
def unload_audio_album_buffers(self, *args, **kwargs):
|
|
|
|
""" Delete all buffers belonging to audio albums."""
|
|
|
|
albums = self.get_all_buffers("_audio_album")
|
|
|
|
for buffer in albums:
|
|
|
|
buff = self.window.search(buffer.name)
|
|
|
|
self.window.remove_buffer(buff)
|
|
|
|
self.buffers.remove(buffer)
|
|
|
|
del self.session.audio_albums
|
|
|
|
|
|
|
|
def load_video_album_buffers(self, *args, **kwargs):
|
|
|
|
""" Load all video album buffers regardless of the setting present in optional buffers tab of the preferences dialog."""
|
|
|
|
call_threaded(self.get_video_albums, self.session.user_id, force_action=True)
|
|
|
|
|
|
|
|
def unload_video_album_buffers(self, *args, **kwargs):
|
|
|
|
""" Delete all buffers belonging to video albums."""
|
|
|
|
albums = self.get_all_buffers("_video_album")
|
|
|
|
for buffer in albums:
|
|
|
|
buff = self.window.search(buffer.name)
|
|
|
|
self.window.remove_buffer(buff)
|
|
|
|
self.buffers.remove(buffer)
|
2019-04-09 17:55:05 -05:00
|
|
|
del self.session.video_albums
|
|
|
|
|
|
|
|
def delete_conversation(self, *args, **kwargs):
|
|
|
|
current_buffer = self.get_current_buffer()
|
|
|
|
d = commonMessages.delete_conversation()
|
|
|
|
if d == widgetUtils.YES:
|
|
|
|
results = self.session.vk.client.messages.deleteConversation(peer_id=current_buffer.kwargs["peer_id"])
|
|
|
|
buff = self.window.search(current_buffer.name)
|
|
|
|
self.window.remove_buffer(buff)
|
|
|
|
self.buffers.remove(current_buffer)
|