2016-02-13 17:06:36 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-01-01 19:42:53 -06:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from builtins import range
|
2016-06-19 12:25:06 -05:00
|
|
|
import time
|
2016-04-04 11:18:42 -05:00
|
|
|
import os
|
|
|
|
import webbrowser
|
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
|
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
|
|
|
|
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
|
2016-02-25 05:49:18 -06:00
|
|
|
from wxUI import (mainWindow, commonMessages)
|
2016-03-23 13:52:43 -06:00
|
|
|
from wxUI.dialogs import search as searchDialogs
|
2019-01-09 05:14:35 -06:00
|
|
|
from wxUI.dialogs import 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):
|
|
|
|
|
|
|
|
def search(self, tab_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
|
|
|
|
|
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()
|
2016-02-23 05:48:05 -06:00
|
|
|
self.connect_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-01-14 01:59:32 -06:00
|
|
|
def create_buffer(self, buffer_type="baseBuffer", buffer_title="", parent_tab="posts", loadable=False, get_items=False, kwargs={}):
|
2019-01-11 16:08:49 -06:00
|
|
|
if not hasattr(buffers, buffer_type):
|
|
|
|
raise AttributeError("Specified buffer type does not exist.")
|
|
|
|
buffer = getattr(buffers, buffer_type)(**kwargs)
|
|
|
|
if loadable:
|
|
|
|
buffer.can_get_items = False
|
|
|
|
self.buffers.append(buffer)
|
|
|
|
self.window.insert_buffer(buffer.tab, buffer_title, self.window.search(parent_tab))
|
2019-01-14 01:59:32 -06:00
|
|
|
if get_items:
|
|
|
|
call_threaded(buffer.get_items)
|
2019-01-11 16:08:49 -06:00
|
|
|
|
|
|
|
def create_empty_buffer(self, buffer_type="empty", buffer_title="", parent_tab=None, kwargs={}):
|
|
|
|
if not hasattr(buffers, buffer_type):
|
|
|
|
raise AttributeError("Specified buffer type does not exist.")
|
|
|
|
buffer = getattr(buffers, buffer_type)(**kwargs)
|
|
|
|
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))
|
|
|
|
|
2016-02-13 17:06:36 -06:00
|
|
|
def create_controls(self):
|
2016-05-12 17:44:53 -05:00
|
|
|
log.debug("Creating controls for the window...")
|
2019-01-11 16:08:49 -06:00
|
|
|
pub.sendMessage("create_empty_buffer", buffer_title=_("Posts"), kwargs=dict(parent=self.window.tb, name="posts"))
|
|
|
|
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"]))
|
|
|
|
pub.sendMessage("create_empty_buffer", buffer_title=_("Music"), kwargs=dict(parent=self.window.tb, name="audios"))
|
|
|
|
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"]))
|
|
|
|
pub.sendMessage("create_empty_buffer", buffer_type="empty", buffer_title=_("Albums"), parent_tab="audios", kwargs=dict(parent=self.window.tb, name="albums"))
|
|
|
|
pub.sendMessage("create_empty_buffer", buffer_title=_("Video"), kwargs=dict(parent=self.window.tb, name="videos"))
|
|
|
|
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"]))
|
|
|
|
pub.sendMessage("create_empty_buffer", buffer_title=_("Albums"), parent_tab="videos", kwargs=dict(parent=self.window.tb, name="video_albums"))
|
|
|
|
pub.sendMessage("create_empty_buffer", buffer_title=_("People"), kwargs=dict(parent=self.window.tb, name="people"))
|
|
|
|
pub.sendMessage("create_buffer", buffer_type="peopleBuffer", buffer_title=_("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, fields="uid, first_name, last_name, last_seen"))
|
|
|
|
pub.sendMessage("create_empty_buffer", buffer_title=_("Friendship requests"), parent_tab="people", kwargs=dict(parent=self.window.tb, name="requests"))
|
|
|
|
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))
|
|
|
|
pub.sendMessage("create_empty_buffer", buffer_title=_("Communities"), kwargs=dict(parent=self.window.tb, name="communities"))
|
|
|
|
pub.sendMessage("create_empty_buffer", buffer_title=_("Chats"), kwargs=dict(parent=self.window.tb, name="chats"))
|
|
|
|
pub.sendMessage("create_empty_buffer", buffer_title=_("Timelines"), kwargs=dict(parent=self.window.tb, name="timelines"))
|
|
|
|
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()
|
2018-12-16 00:41:47 -06:00
|
|
|
self.readMarker = RepeatingTimer(60, self.mark_as_read)
|
2016-06-06 04:27:07 -05:00
|
|
|
self.readMarker.start()
|
2016-02-23 05:48:05 -06:00
|
|
|
|
|
|
|
def connect_events(self):
|
2016-05-12 17:44:53 -05:00
|
|
|
log.debug("Connecting events to responses...")
|
2016-02-13 17:06:36 -06:00
|
|
|
pub.subscribe(self.in_post, "posted")
|
2016-02-15 16:49:09 -06:00
|
|
|
pub.subscribe(self.download, "download-file")
|
2018-12-05 15:55:24 -06:00
|
|
|
pub.subscribe(self.play_audio, "play-audio")
|
2018-12-09 05:22:37 -06:00
|
|
|
pub.subscribe(self.play_audios, "play-audios")
|
2016-02-17 17:37:57 -06:00
|
|
|
pub.subscribe(self.view_post, "open-post")
|
2016-03-26 09:08:41 -06:00
|
|
|
pub.subscribe(self.update_status_bar, "update-status-bar")
|
2016-05-25 11:33:57 -05:00
|
|
|
pub.subscribe(self.chat_from_id, "new-chat")
|
2016-06-06 03:53:55 -05:00
|
|
|
pub.subscribe(self.authorisation_failed, "authorisation-failed")
|
2016-09-15 15:27:38 -05:00
|
|
|
pub.subscribe(self.user_profile, "user-profile")
|
2018-12-10 00:48:40 -06:00
|
|
|
pub.subscribe(self.user_online, "user-online")
|
|
|
|
pub.subscribe(self.user_offline, "user-offline")
|
2018-12-10 17:35:36 -06:00
|
|
|
pub.subscribe(self.notify, "notify")
|
2018-12-12 13:41:57 -06:00
|
|
|
pub.subscribe(self.handle_longpoll_read_timeout, "longpoll-read-timeout")
|
2019-01-11 16:08:49 -06:00
|
|
|
pub.subscribe(self.create_buffer, "create_buffer")
|
|
|
|
pub.subscribe(self.create_empty_buffer, "create_empty_buffer")
|
2019-01-11 17:00:58 -06:00
|
|
|
pub.subscribe(self.user_typing, "user-typing")
|
2016-02-23 05:48:05 -06:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.CLOSE_EVENT, self.exit)
|
2016-02-23 17:49:55 -06:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.update_buffer, menuitem=self.window.update_buffer)
|
2016-02-25 05:49:18 -06:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_for_updates, menuitem=self.window.check_for_updates)
|
2016-03-23 08:38:18 -06:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.window.about_dialog, menuitem=self.window.about)
|
2018-12-09 05:22:37 -06:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.search_audios, menuitem=self.window.search_audios)
|
2016-08-15 17:00:49 -05:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.search_videos, menuitem=self.window.search_videos)
|
2016-03-27 00:11:52 -06:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU,self.remove_buffer, menuitem=self.window.remove_buffer_)
|
2016-03-31 10:33:02 -06:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.get_more_items, menuitem=self.window.load_previous_items)
|
2016-04-04 11:18:42 -05:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.changelog, menuitem=self.window.changelog)
|
2016-04-04 17:54:59 -05:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.configuration, menuitem=self.window.settings_dialog)
|
2016-04-12 15:36:30 -05:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.new_timeline, menuitem=self.window.timeline)
|
2018-12-11 12:07:18 -06:00
|
|
|
# widgetUtils.connect_event(self.window, widgetUtils.MENU, self.create_audio_album, menuitem=self.window.audio_album)
|
2018-12-11 12:08:56 -06:00
|
|
|
# widgetUtils.connect_event(self.window, widgetUtils.MENU, self.delete_audio_album, menuitem=self.window.delete_audio_album)
|
2016-08-14 07:46:41 -05:00
|
|
|
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)
|
2016-06-29 13:16:35 -05:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_documentation, menuitem=self.window.documentation)
|
2018-12-09 05:22:37 -06:00
|
|
|
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)
|
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_stop, menuitem=self.window.player_stop)
|
|
|
|
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)
|
2016-05-17 12:46:57 -05:00
|
|
|
pub.subscribe(self.get_chat, "order-sent-message")
|
2018-09-06 10:47:10 -05:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.view_my_profile, menuitem=self.window.view_profile)
|
2018-09-06 13:07:55 -05:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.view_my_profile_in_browser, menuitem=self.window.open_in_browser)
|
2018-12-18 16:32:14 -06:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.set_status, menuitem=self.window.set_status)
|
2018-12-22 08:08:30 -06:00
|
|
|
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_report_error, menuitem=self.window.report)
|
2018-12-09 05:22:37 -06:00
|
|
|
|
2016-02-23 05:48:05 -06:00
|
|
|
def disconnect_events(self):
|
2016-05-12 17:44:53 -05:00
|
|
|
log.debug("Disconnecting some events...")
|
2016-02-23 05:48:05 -06:00
|
|
|
pub.unsubscribe(self.in_post, "posted")
|
2018-12-09 05:22:37 -06:00
|
|
|
pub.unsubscribe(self.download, "download-file")
|
|
|
|
pub.unsubscribe(self.play_audio, "play-audio")
|
2016-06-06 03:53:55 -05:00
|
|
|
pub.unsubscribe(self.authorisation_failed, "authorisation-failed")
|
2018-12-09 05:22:37 -06:00
|
|
|
pub.unsubscribe(self.play_audios, "play-audios")
|
2016-02-23 05:48:05 -06:00
|
|
|
pub.unsubscribe(self.view_post, "open-post")
|
2016-03-26 09:08:41 -06:00
|
|
|
pub.unsubscribe(self.update_status_bar, "update-status-bar")
|
2018-12-10 00:48:40 -06:00
|
|
|
pub.unsubscribe(self.user_online, "user-online")
|
|
|
|
pub.unsubscribe(self.user_offline, "user-offline")
|
2018-12-10 17:35:36 -06:00
|
|
|
pub.unsubscribe(self.notify, "notify")
|
2016-02-13 17:06:36 -06:00
|
|
|
|
2016-06-06 03:53:55 -05:00
|
|
|
def authorisation_failed(self):
|
|
|
|
commonMessages.bad_authorisation()
|
|
|
|
|
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")
|
|
|
|
|
2016-02-13 17:06:36 -06:00
|
|
|
def in_post(self, buffer):
|
|
|
|
buffer = self.search(buffer)
|
|
|
|
buffer.get_items()
|
|
|
|
buffer = self.search("home_timeline")
|
|
|
|
buffer.get_items()
|
|
|
|
|
|
|
|
def update_all_buffers(self):
|
2016-05-12 17:44:53 -05:00
|
|
|
log.debug("Updating buffers...")
|
2018-12-22 05:39:58 -06:00
|
|
|
self.get_audio_albums(self.session.user_id, create_buffers=False)
|
|
|
|
self.get_video_albums(self.session.user_id, create_buffers=False)
|
2016-02-13 17:06:36 -06:00
|
|
|
for i in self.buffers:
|
|
|
|
if hasattr(i, "get_items"):
|
|
|
|
i.get_items()
|
2019-01-01 19:42:53 -06:00
|
|
|
log.debug("Updated %s" % (i.name))
|
2016-02-15 16:49:09 -06:00
|
|
|
|
|
|
|
def download(self, url, filename):
|
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)
|
|
|
|
|
|
|
|
def play_audio(self, audio_object):
|
2018-12-16 00:53:02 -06:00
|
|
|
# Restricted audios does not include an URL paramether.
|
|
|
|
# Restriction can be due to licensed content to unauthorized countries.
|
|
|
|
if "url" in audio_object and audio_object["url"] =="":
|
2019-01-01 19:42:53 -06:00
|
|
|
self.notify(message=_("This file could not be played because it is not allowed in your country"))
|
2018-12-16 00:53:02 -06:00
|
|
|
return
|
2016-02-15 17:49:39 -06:00
|
|
|
call_threaded(player.player.play, audio_object)
|
2016-02-17 17:37:57 -06:00
|
|
|
|
2016-03-23 08:17:45 -06:00
|
|
|
def play_audios(self, audios):
|
2017-03-13 02:16:34 -06:00
|
|
|
player.player.play_all(audios, shuffle=self.window.player_shuffle.IsChecked())
|
2016-03-23 08:17:45 -06:00
|
|
|
|
2016-02-17 17:37:57 -06:00
|
|
|
def view_post(self, post_object, controller_):
|
2019-01-08 17:56:51 -06:00
|
|
|
p = getattr(presenters, controller_+"Presenter")(session=self.session, postObject=post_object, interactor=getattr(interactors, controller_+"Interactor")(), view=getattr(views, controller_)())
|
2016-02-23 05:48:05 -06:00
|
|
|
|
|
|
|
def exit(self, *args, **kwargs):
|
2016-05-12 17:44:53 -05:00
|
|
|
log.debug("Receibed an exit signal. closing...")
|
2018-12-10 13:25:30 -06:00
|
|
|
self.set_offline()
|
2016-02-23 05:48:05 -06:00
|
|
|
self.disconnect_events()
|
|
|
|
self.window.Destroy()
|
2016-03-23 13:52:43 -06:00
|
|
|
wx.GetApp().ExitMainLoop()
|
2016-02-23 17:49:55 -06:00
|
|
|
|
|
|
|
def update_buffer(self, *args, **kwargs):
|
|
|
|
b = self.get_current_buffer()
|
2016-02-25 04:52:02 -06:00
|
|
|
b.get_items()
|
2016-02-25 05:49:18 -06:00
|
|
|
|
2016-03-31 10:33:02 -06:00
|
|
|
def get_more_items(self, *args, **kwargs):
|
|
|
|
b = self.get_current_buffer()
|
|
|
|
b.get_more_items()
|
|
|
|
|
2016-02-25 05:49:18 -06:00
|
|
|
def check_for_updates(self, *args, **kwargs):
|
2018-12-27 11:11:30 -06:00
|
|
|
update = updater.do_update(update_type=self.session.settings["general"]["update_channel"])
|
2016-02-25 05:49:18 -06:00
|
|
|
if update == False:
|
|
|
|
commonMessages.no_update_available()
|
2016-03-23 13:52:43 -06:00
|
|
|
|
|
|
|
def search_audios(self, *args, **kwargs):
|
|
|
|
dlg = searchDialogs.searchAudioDialog()
|
|
|
|
if dlg.get_response() == widgetUtils.OK:
|
|
|
|
q = dlg.get("term").encode("utf-8")
|
2019-01-01 19:42:53 -06:00
|
|
|
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)
|
2016-03-23 13:52:43 -06:00
|
|
|
self.buffers.append(newbuff)
|
|
|
|
call_threaded(newbuff.get_items)
|
2016-06-29 10:56:41 -05:00
|
|
|
# Translators: {0} will be replaced with the search term.
|
2019-01-01 19:42:53 -06:00
|
|
|
self.window.insert_buffer(newbuff.tab, _("Search for {0}").format(q,), self.window.search("audios"))
|
2016-03-26 09:08:41 -06:00
|
|
|
|
2016-08-15 17:00:49 -05:00
|
|
|
def search_videos(self, *args, **kwargs):
|
|
|
|
dlg = searchDialogs.searchVideoDialog()
|
|
|
|
if dlg.get_response() == widgetUtils.OK:
|
|
|
|
params = {}
|
|
|
|
params["q"] = dlg.get("term").encode("utf-8")
|
|
|
|
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"
|
2019-01-01 19:42:53 -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)
|
2016-08-15 17:00:49 -05:00
|
|
|
self.buffers.append(newbuff)
|
|
|
|
call_threaded(newbuff.get_items)
|
|
|
|
# Translators: {0} will be replaced with the search term.
|
2019-01-01 19:42:53 -06:00
|
|
|
self.window.insert_buffer(newbuff.tab, _("Search for {0}").format(params["q"],), self.window.search("videos"))
|
2016-08-15 17:00:49 -05:00
|
|
|
|
2016-03-26 09:08:41 -06:00
|
|
|
def update_status_bar(self, status):
|
2016-03-27 00:11:52 -06:00
|
|
|
self.window.change_status(status)
|
|
|
|
|
2016-04-14 17:23:08 -05:00
|
|
|
def remove_buffer(self, event, mandatory=False, *args, **kwargs):
|
2016-03-27 00:11:52 -06:00
|
|
|
buffer = self.get_current_buffer()
|
|
|
|
buff = self.window.search(buffer.name)
|
2016-04-13 17:45:05 -05:00
|
|
|
answer = buffer.remove_buffer(mandatory)
|
2016-03-27 00:11:52 -06:00
|
|
|
if answer == False:
|
|
|
|
return
|
|
|
|
self.window.remove_buffer(buff)
|
|
|
|
self.buffers.remove(buffer)
|
2016-04-04 11:18:42 -05:00
|
|
|
del buffer
|
|
|
|
|
|
|
|
def changelog(self, *args, **kwargs):
|
|
|
|
os.chdir("documentation")
|
|
|
|
webbrowser.open("changelog.html")
|
|
|
|
os.chdir("../")
|
2016-04-04 17:54:59 -05:00
|
|
|
|
|
|
|
def configuration(self, *args, **kwargs):
|
|
|
|
""" Opens the global settings dialogue."""
|
2019-01-06 15:26:54 -06:00
|
|
|
presenter = presenters.configurationPresenter(session=self.session, view=views.configurationDialog(title=_("Preferences")), interactor=interactors.configurationInteractor())
|
2016-04-12 15:36:30 -05:00
|
|
|
|
|
|
|
def new_timeline(self, *args, **kwargs):
|
|
|
|
b = self.get_current_buffer()
|
2019-01-03 17:53:51 -06:00
|
|
|
# If executing this method from an empty buffer we should get the newsfeed buffer.
|
2016-04-15 09:06:18 -05:00
|
|
|
if not hasattr(b, "get_users"):
|
|
|
|
b = self.search("home_timeline")
|
2019-01-03 17:53:51 -06:00
|
|
|
# Get a list of (id, user) objects.
|
2016-04-12 15:36:30 -05:00
|
|
|
d = []
|
|
|
|
for i in self.session.db["users"]:
|
2019-01-11 04:22:53 -06:00
|
|
|
d.append((i, self.session.get_user(i)["user1_gen"]))
|
2019-01-03 17:53:51 -06:00
|
|
|
# Do the same for communities.
|
2016-04-12 15:36:30 -05:00
|
|
|
for i in self.session.db["groups"]:
|
2019-01-11 04:22:53 -06:00
|
|
|
d.append((-i, self.session.get_user(-i)["user1_nom"]))
|
2016-04-12 15:36:30 -05:00
|
|
|
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]
|
2019-01-03 17:53:51 -06:00
|
|
|
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"]
|
2016-04-12 15:59:22 -05:00
|
|
|
if buffertype == "audio":
|
2019-01-07 15:05:43 -06:00
|
|
|
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)
|
2019-01-11 04:22:53 -06:00
|
|
|
user = self.session.get_user(user_id, key="user1")
|
|
|
|
name_ = _("{user1_nom}'s audios").format(**user)
|
2016-04-14 17:23:08 -05:00
|
|
|
elif buffertype == "wall":
|
2019-01-07 15:05:43 -06:00
|
|
|
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)
|
2019-01-11 04:22:53 -06:00
|
|
|
user = self.session.get_user(user_id, key="user1")
|
|
|
|
name_ = _("{user1_nom}'s posts").format(**user)
|
2016-06-02 13:12:42 -05:00
|
|
|
elif buffertype == "friends":
|
2019-01-07 15:05:43 -06:00
|
|
|
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)
|
2019-01-11 04:22:53 -06:00
|
|
|
user = self.session.get_user(user_id, key="user1")
|
|
|
|
name_ = _("{user1_nom}'s friends").format(**user)
|
2019-01-07 15:05:43 -06:00
|
|
|
wx.CallAfter(self.complete_buffer_creation, buffer=buffer, name_=name_, position=self.window.search("timelines"))
|
2016-04-13 17:45:05 -05:00
|
|
|
|
|
|
|
def complete_buffer_creation(self, buffer, name_, position):
|
|
|
|
answer = buffer.get_items()
|
|
|
|
if answer is not True:
|
|
|
|
commonMessages.show_error_code(answer)
|
|
|
|
return
|
2019-01-07 15:05:43 -06:00
|
|
|
self.buffers.append(buffer)
|
2016-05-17 12:46:57 -05:00
|
|
|
self.window.insert_buffer(buffer.tab, name_, position)
|
|
|
|
|
|
|
|
def search_chat_buffer(self, user_id):
|
|
|
|
for i in self.buffers:
|
|
|
|
if "_messages" in i.name:
|
2019-01-07 17:52:14 -06:00
|
|
|
if "peer_id" in i.kwargs and i.kwargs["peer_id"] == user_id: return i
|
2016-05-17 12:46:57 -05:00
|
|
|
return None
|
|
|
|
|
2018-12-16 00:41:47 -06:00
|
|
|
def chat_from_id(self, user_id, setfocus=True, unread=False):
|
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")
|
|
|
|
name = _("Chat with {user1_nom}").format(**user)
|
2019-01-07 17:52:14 -06:00
|
|
|
elif user_id > 2000000000:
|
|
|
|
chat = self.session.vk.client.messages.getChat(chat_id=user_id-2000000000)
|
|
|
|
name = _("Chat in {chat_name}").format(chat_name=chat["title"],)
|
2019-01-14 01:59:32 -06: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", session=self.session, count=200, peer_id=user_id, rev=0, extended=True, fields="id, user_id, date, read_state, out, body, attachments, deleted"))
|
|
|
|
# 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
|
|
|
|
2018-12-10 00:48:40 -06:00
|
|
|
def user_online(self, event):
|
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"])
|
2018-12-10 00:48:40 -06:00
|
|
|
|
|
|
|
def user_offline(self, event):
|
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"])
|
2018-12-10 00:48:40 -06:00
|
|
|
|
2019-01-11 17:00:58 -06:00
|
|
|
def user_typing(self, obj):
|
|
|
|
buffer = self.search_chat_buffer(obj.user_id)
|
|
|
|
if buffer != None and buffer == self.get_current_buffer():
|
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.
|
2018-12-09 07:28:13 -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-01-07 17:52:14 -06:00
|
|
|
message.update(id=obj.message_id, user_id=uid, date=obj.timestamp, body=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.
|
|
|
|
# Todo: code improvements. We shouldn't need to request the same message again just for these attachments.
|
|
|
|
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-16 00:41:47 -06:00
|
|
|
message.update(read_state=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:
|
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.
|
|
|
|
num = self.session.order_buffer(buffer.name, data, True)
|
|
|
|
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")
|
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
|
|
|
|
2018-12-16 02:20:14 -06:00
|
|
|
def set_online(self, notify=False):
|
2016-07-12 05:00:07 -05:00
|
|
|
try:
|
|
|
|
r = self.session.vk.client.account.setOnline()
|
|
|
|
except:
|
|
|
|
log.error("Error in setting online for the current user")
|
2018-12-16 02:20:14 -06:00
|
|
|
if notify:
|
|
|
|
self.window.notify("Socializer", "online now!")
|
2016-06-03 10:24:35 -05:00
|
|
|
|
2018-12-10 13:25:30 -06:00
|
|
|
def set_offline(self):
|
|
|
|
try:
|
|
|
|
r = self.session.vk.client.account.setOffline()
|
|
|
|
except:
|
|
|
|
log.error("Error in setting offline status for the current user")
|
|
|
|
|
2016-06-03 10:24:35 -05:00
|
|
|
def create_unread_messages(self):
|
2018-12-11 11:45:38 -06:00
|
|
|
if self.session.settings["chat"]["open_unread_conversations"] == False:
|
|
|
|
return
|
2016-08-13 20:12:18 -05:00
|
|
|
try:
|
|
|
|
log.debug("Getting possible unread messages.")
|
2019-01-14 01:59:32 -06:00
|
|
|
msgs = self.session.vk.client.messages.getDialogs(count=200, unread=True)
|
2018-12-09 05:22:37 -06:00
|
|
|
except VkApiError as ex:
|
2016-08-13 20:12:18 -05:00
|
|
|
if ex.code == 6:
|
|
|
|
log.exception("Something went wrong when getting messages. Waiting a second to retry")
|
2016-06-03 10:24:35 -05:00
|
|
|
for i in msgs["items"]:
|
2019-01-14 01:59:32 -06:00
|
|
|
call_threaded(self.chat_from_id, i["message"]["user_id"], setfocus=False, unread=True)
|
2016-06-06 04:27:07 -05:00
|
|
|
|
|
|
|
def mark_as_read(self):
|
|
|
|
for i in self.buffers:
|
2018-12-16 00:41:47 -06:00
|
|
|
if hasattr(i, "reads") and len(i.reads) != 0:
|
2019-01-10 13:00:48 -06:00
|
|
|
response = self.session.vk.client.messages.markAsRead(peer_id=i.kwargs["peer_id"])
|
2018-12-20 15:36:32 -06:00
|
|
|
i.clear_reads()
|
2016-06-06 04:27:07 -05:00
|
|
|
i.reads = []
|
2018-12-16 00:41:47 -06:00
|
|
|
time.sleep(1)
|
2016-06-19 12:25:06 -05:00
|
|
|
|
2018-12-20 08:33:16 -06:00
|
|
|
def get_audio_albums(self, user_id=None, create_buffers=True):
|
2019-01-14 02:23:38 -06:00
|
|
|
if self.session.settings["load_at_startup"]["audio_albums"] == False:
|
|
|
|
return
|
2018-12-20 08:33:16 -06:00
|
|
|
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)
|
|
|
|
else:
|
|
|
|
albums = self.session.vk.client.audio.getPlaylists(owner_id=user_id)
|
|
|
|
albums = albums["items"]
|
2018-12-11 11:45:38 -06:00
|
|
|
self.session.audio_albums = albums
|
2018-12-20 08:33:16 -06:00
|
|
|
if create_buffers:
|
|
|
|
for i in albums:
|
2019-01-14 01:59:32 -06:00
|
|
|
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="audioAlbum", buffer_title=_("Album: {0}").format(i["title"],), parent_tab="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"]))
|
|
|
|
time.sleep(0.6)
|
2018-12-20 08:33:16 -06:00
|
|
|
|
|
|
|
def get_video_albums(self, user_id=None, create_buffers=True):
|
2019-01-14 02:23:38 -06:00
|
|
|
if self.session.settings["load_at_startup"]["video_albums"] == False:
|
|
|
|
return
|
2018-12-20 08:33:16 -06:00
|
|
|
log.debug("Create video albums...")
|
|
|
|
albums = self.session.vk.client.video.getAlbums(owner_id=user_id)
|
2016-08-14 07:46:41 -05:00
|
|
|
self.session.video_albums = albums["items"]
|
2018-12-20 08:33:16 -06:00
|
|
|
if create_buffers:
|
|
|
|
for i in albums["items"]:
|
2019-01-14 01:59:32 -06:00
|
|
|
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)
|
2018-12-30 10:41:47 -06:00
|
|
|
|
|
|
|
def get_communities(self, user_id=None, create_buffers=True):
|
2019-01-11 11:20:09 -06:00
|
|
|
if self.session.settings["vk"]["invited_to_group"] == False:
|
|
|
|
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))
|
2019-01-14 02:23:38 -06:00
|
|
|
if self.session.settings["load_at_startup"]["communities"] == False:
|
|
|
|
return
|
2018-12-30 10:41:47 -06:00
|
|
|
log.debug("Create community buffers...")
|
2019-01-11 11:20:09 -06:00
|
|
|
groups= self.session.vk.client.groups.get(user_id=user_id, extended=1, fields="city, country, place, description, wiki_page, members_count, counters, start_date, finish_date, can_post, can_see_all_posts, activity, status, contacts, links, fixed_post, verified, site, can_create_topic", count=1000)
|
2018-12-30 10:41:47 -06:00
|
|
|
self.session.groups=groups["items"]
|
|
|
|
# Let's feed the local database cache with new groups coming from here.
|
|
|
|
data= dict(profiles=[], groups=groups["items"])
|
|
|
|
self.session.process_usernames(data)
|
|
|
|
if create_buffers:
|
|
|
|
for i in groups["items"]:
|
2019-01-14 01:59:32 -06:00
|
|
|
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="communityBuffer", buffer_title=i["name"], parent_tab="communities", loadable=True, kwargs=dict(parent=self.window.tb, name="{0}_community".format(i["id"],), composefunc="render_status", session=self.session, endpoint="get", parent_endpoint="wall", count=self.session.settings["buffers"]["count_for_wall_buffers"], owner_id=-1*i["id"]))
|
|
|
|
time.sleep(0.15)
|
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") != "":
|
|
|
|
response = self.session.vk.client.audio.addAlbum(title=d.get("title"))
|
2019-01-01 19:42:53 -06:00
|
|
|
if ("album_id" in response) == False: return
|
2016-06-19 12:25:06 -05:00
|
|
|
album_id = response["album_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()
|
|
|
|
self.session.audio_albums = self.session.vk.client.audio.getAlbums(owner_id=self.session.user_id)["items"]
|
|
|
|
|
|
|
|
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
|
|
|
|
removal = self.session.vk.client.audio.deleteAlbum(album_id=answer.item)
|
|
|
|
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.session.audio_albums = self.session.vk.client.audio.getAlbums(owner_id=self.session.user_id)["items"]
|
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):
|
|
|
|
if player.player.check_is_playing() != False:
|
|
|
|
return player.player.pause()
|
|
|
|
b = self.get_current_buffer()
|
2016-09-15 15:27:38 -05:00
|
|
|
if hasattr(b, "play_next"):
|
2016-07-18 17:34:37 -05:00
|
|
|
b.play_audio()
|
|
|
|
else:
|
|
|
|
b = self.search("me_audio")
|
|
|
|
b.play_audio()
|
|
|
|
|
|
|
|
def menu_play_next(self, *args, **kwargs):
|
|
|
|
b = self.get_current_buffer()
|
|
|
|
if hasattr(b, "play_next"):
|
|
|
|
b.play_next()
|
|
|
|
else:
|
|
|
|
self.search("me_audio").play_next()
|
|
|
|
|
|
|
|
def menu_play_previous(self, *args, **kwargs):
|
|
|
|
b = self.get_current_buffer()
|
|
|
|
if hasattr(b, "play_previous"):
|
|
|
|
b.play_previous()
|
|
|
|
else:
|
|
|
|
self.search("me_audio").play_previous()
|
|
|
|
|
|
|
|
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_stop(self, *args, **kwargs):
|
|
|
|
player.player.stop()
|
|
|
|
|
|
|
|
def menu_volume_down(self, *args, **kwargs):
|
|
|
|
player.player.volume = player.player.volume-5
|
|
|
|
|
|
|
|
def menu_volume_up(self, *args, **kwargs):
|
|
|
|
player.player.volume = player.player.volume+5
|
|
|
|
|
|
|
|
def menu_mute(self, *args, **kwargs):
|
|
|
|
player.player.volume = 0
|
|
|
|
|
2016-09-15 15:27:38 -05:00
|
|
|
def user_profile(self, person):
|
2019-01-06 19:41:00 -06:00
|
|
|
p = presenters.userProfilePresenter(session=self.session, user_id=person, view=views.userProfileDialog(), interactor=interactors.userProfileInteractor())
|
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-12 12:24:05 -06:00
|
|
|
def notify(self, message="", sound="", type="native"):
|
|
|
|
if type == "native":
|
2019-01-14 01:59:32 -06:00
|
|
|
wx.CallAfter(self.window.notify, _("Socializer"), message)
|
2018-12-12 12:24:05 -06:00
|
|
|
else:
|
|
|
|
if sound != "":
|
|
|
|
self.session.soundplayer.play(sound)
|
|
|
|
if message != "":
|
2018-12-12 13:41:57 -06:00
|
|
|
output.speak(message)
|
|
|
|
|
|
|
|
def handle_longpoll_read_timeout(self):
|
|
|
|
if hasattr(self, "longpoll"):
|
2019-01-01 19:42:53 -06:00
|
|
|
self.notify(message=_("Chat disconnected. Trying to connect in 60 seconds"))
|
2018-12-12 13:41:57 -06:00
|
|
|
time.sleep(60)
|
|
|
|
if hasattr(self, "longpoll"):
|
|
|
|
del self.longpoll
|
2018-12-18 16:32:14 -06:00
|
|
|
self.create_longpoll_thread(notify=True)
|
|
|
|
|
|
|
|
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):
|
|
|
|
r = issueReporter.reportBug()
|