2015-01-20 15:40:33 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-01-25 02:38:17 -06:00
|
|
|
import os
|
2021-12-21 13:21:58 -06:00
|
|
|
import logging
|
2015-01-25 02:38:17 -06:00
|
|
|
import paths
|
2015-01-20 15:40:33 -06:00
|
|
|
import config
|
|
|
|
import languageHandler
|
2015-05-12 18:30:44 -05:00
|
|
|
import application
|
2021-12-21 13:21:58 -06:00
|
|
|
from pubsub import pub
|
|
|
|
from mysc import autostart as autostart_windows
|
2015-01-20 15:40:33 -06:00
|
|
|
from wxUI.dialogs import configuration
|
2015-02-01 00:49:03 -06:00
|
|
|
from wxUI import commonMessageDialogs
|
2021-12-21 13:21:58 -06:00
|
|
|
|
2015-01-20 15:40:33 -06:00
|
|
|
log = logging.getLogger("Settings")
|
|
|
|
|
|
|
|
class globalSettingsController(object):
|
2021-06-16 16:18:41 -05:00
|
|
|
def __init__(self):
|
|
|
|
super(globalSettingsController, self).__init__()
|
|
|
|
self.dialog = configuration.configurationDialog()
|
|
|
|
self.create_config()
|
|
|
|
self.needs_restart = False
|
|
|
|
self.is_started = True
|
2015-01-25 02:38:17 -06:00
|
|
|
|
2021-06-16 16:18:41 -05:00
|
|
|
def make_kmmap(self):
|
|
|
|
res={}
|
|
|
|
for i in os.listdir(os.path.join(paths.app_path(), 'keymaps')):
|
|
|
|
if ".keymap" not in i:
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
res[i[:-7]] =i
|
|
|
|
except:
|
|
|
|
log.exception("Exception while loading keymap " + i)
|
|
|
|
return res
|
2015-06-08 05:41:48 -05:00
|
|
|
|
2021-06-16 16:18:41 -05:00
|
|
|
def create_config(self):
|
|
|
|
self.kmmap=self.make_kmmap()
|
|
|
|
self.langs = languageHandler.getAvailableLanguages()
|
|
|
|
langs = []
|
|
|
|
[langs.append(i[1]) for i in self.langs]
|
|
|
|
self.codes = []
|
|
|
|
[self.codes.append(i[0]) for i in self.langs]
|
|
|
|
id = self.codes.index(config.app["app-settings"]["language"])
|
|
|
|
self.kmfriendlies=[]
|
|
|
|
self.kmnames=[]
|
|
|
|
for k,v in list(self.kmmap.items()):
|
|
|
|
self.kmfriendlies.append(k)
|
|
|
|
self.kmnames.append(v)
|
|
|
|
self.kmid=self.kmnames.index(config.app['app-settings']['load_keymap'])
|
|
|
|
self.dialog.create_general(langs,self.kmfriendlies)
|
|
|
|
self.dialog.general.language.SetSelection(id)
|
|
|
|
self.dialog.general.km.SetSelection(self.kmid)
|
|
|
|
if paths.mode == "installed":
|
|
|
|
self.dialog.set_value("general", "autostart", config.app["app-settings"]["autostart"])
|
|
|
|
else:
|
|
|
|
self.dialog.general.autostart.Enable(False)
|
|
|
|
self.dialog.set_value("general", "ask_at_exit", config.app["app-settings"]["ask_at_exit"])
|
|
|
|
self.dialog.set_value("general", "no_streaming", config.app["app-settings"]["no_streaming"])
|
|
|
|
self.dialog.set_value("general", "play_ready_sound", config.app["app-settings"]["play_ready_sound"])
|
|
|
|
self.dialog.set_value("general", "speak_ready_msg", config.app["app-settings"]["speak_ready_msg"])
|
|
|
|
self.dialog.set_value("general", "handle_longtweets", config.app["app-settings"]["handle_longtweets"])
|
|
|
|
self.dialog.set_value("general", "use_invisible_shorcuts", config.app["app-settings"]["use_invisible_keyboard_shorcuts"])
|
|
|
|
self.dialog.set_value("general", "disable_sapi5", config.app["app-settings"]["voice_enabled"])
|
|
|
|
self.dialog.set_value("general", "hide_gui", config.app["app-settings"]["hide_gui"])
|
|
|
|
self.dialog.set_value("general", "update_period", config.app["app-settings"]["update_period"])
|
|
|
|
self.dialog.set_value("general", "check_for_updates", config.app["app-settings"]["check_for_updates"])
|
|
|
|
self.dialog.set_value("general", "remember_mention_and_longtweet", config.app["app-settings"]["remember_mention_and_longtweet"])
|
|
|
|
proxyTypes = [_("System default"), _("HTTP"), _("SOCKS v4"), _("SOCKS v4 with DNS support"), _("SOCKS v5"), _("SOCKS v5 with DNS support")]
|
|
|
|
self.dialog.create_proxy(proxyTypes)
|
|
|
|
try:
|
|
|
|
self.dialog.proxy.type.SetSelection(config.app["proxy"]["type"])
|
|
|
|
except:
|
|
|
|
self.dialog.proxy.type.SetSelection(0)
|
|
|
|
self.dialog.set_value("proxy", "server", config.app["proxy"]["server"])
|
|
|
|
self.dialog.set_value("proxy", "port", config.app["proxy"]["port"])
|
|
|
|
self.dialog.set_value("proxy", "user", config.app["proxy"]["user"])
|
|
|
|
self.dialog.set_value("proxy", "password", config.app["proxy"]["password"])
|
2016-04-27 16:33:51 -05:00
|
|
|
|
2021-06-16 16:18:41 -05:00
|
|
|
self.dialog.realize()
|
|
|
|
self.response = self.dialog.get_response()
|
2015-01-20 15:40:33 -06:00
|
|
|
|
2021-06-16 16:18:41 -05:00
|
|
|
def save_configuration(self):
|
|
|
|
if self.codes[self.dialog.general.language.GetSelection()] != config.app["app-settings"]["language"]:
|
|
|
|
config.app["app-settings"]["language"] = self.codes[self.dialog.general.language.GetSelection()]
|
|
|
|
languageHandler.setLanguage(config.app["app-settings"]["language"])
|
|
|
|
self.needs_restart = True
|
2021-12-21 15:35:35 -06:00
|
|
|
log.debug("Triggered app restart due to interface language changes.")
|
2021-06-16 16:18:41 -05:00
|
|
|
if self.kmnames[self.dialog.general.km.GetSelection()] != config.app["app-settings"]["load_keymap"]:
|
|
|
|
config.app["app-settings"]["load_keymap"] =self.kmnames[self.dialog.general.km.GetSelection()]
|
|
|
|
kmFile = open(os.path.join(paths.config_path(), "keymap.keymap"), "w")
|
|
|
|
kmFile.close()
|
2021-12-21 15:35:35 -06:00
|
|
|
log.debug("Triggered app restart due to a keymap change.")
|
2021-06-16 16:18:41 -05:00
|
|
|
self.needs_restart = True
|
|
|
|
if config.app["app-settings"]["autostart"] != self.dialog.get_value("general", "autostart") and paths.mode == "installed":
|
|
|
|
config.app["app-settings"]["autostart"] = self.dialog.get_value("general", "autostart")
|
|
|
|
autostart_windows.setAutoStart(application.name, enable=self.dialog.get_value("general", "autostart"))
|
|
|
|
if config.app["app-settings"]["use_invisible_keyboard_shorcuts"] != self.dialog.get_value("general", "use_invisible_shorcuts"):
|
|
|
|
config.app["app-settings"]["use_invisible_keyboard_shorcuts"] = self.dialog.get_value("general", "use_invisible_shorcuts")
|
|
|
|
pub.sendMessage("invisible-shorcuts-changed", registered=self.dialog.get_value("general", "use_invisible_shorcuts"))
|
|
|
|
if config.app["app-settings"]["no_streaming"] != self.dialog.get_value("general", "no_streaming"):
|
|
|
|
config.app["app-settings"]["no_streaming"] = self.dialog.get_value("general", "no_streaming")
|
|
|
|
self.needs_restart = True
|
2021-12-21 15:35:35 -06:00
|
|
|
log.debug("Triggered app restart due to change in streaming availability.")
|
2021-06-16 16:18:41 -05:00
|
|
|
if config.app["app-settings"]["update_period"] != self.dialog.get_value("general", "update_period"):
|
|
|
|
config.app["app-settings"]["update_period"] = self.dialog.get_value("general", "update_period")
|
|
|
|
self.needs_restart = True
|
2021-12-21 15:35:35 -06:00
|
|
|
log.debug("Triggered app restart due to changes in update period.")
|
2021-06-16 16:18:41 -05:00
|
|
|
config.app["app-settings"]["voice_enabled"] = self.dialog.get_value("general", "disable_sapi5")
|
|
|
|
config.app["app-settings"]["hide_gui"] = self.dialog.get_value("general", "hide_gui")
|
|
|
|
config.app["app-settings"]["ask_at_exit"] = self.dialog.get_value("general", "ask_at_exit")
|
|
|
|
config.app["app-settings"]["handle_longtweets"] = self.dialog.get_value("general", "handle_longtweets")
|
|
|
|
config.app["app-settings"]["play_ready_sound"] = self.dialog.get_value("general", "play_ready_sound")
|
|
|
|
config.app["app-settings"]["speak_ready_msg"] = self.dialog.get_value("general", "speak_ready_msg")
|
|
|
|
config.app["app-settings"]["check_for_updates"] = self.dialog.get_value("general", "check_for_updates")
|
|
|
|
config.app["app-settings"]["remember_mention_and_longtweet"] = self.dialog.get_value("general", "remember_mention_and_longtweet")
|
|
|
|
if config.app["proxy"]["type"]!=self.dialog.get_value("proxy", "type") or config.app["proxy"]["server"] != self.dialog.get_value("proxy", "server") or config.app["proxy"]["port"] != self.dialog.get_value("proxy", "port") or config.app["proxy"]["user"] != self.dialog.get_value("proxy", "user") or config.app["proxy"]["password"] != self.dialog.get_value("proxy", "password"):
|
|
|
|
if self.is_started == True:
|
|
|
|
self.needs_restart = True
|
2021-12-21 15:35:35 -06:00
|
|
|
log.debug("Triggered app restart due to change in proxy settings.")
|
2021-06-16 16:18:41 -05:00
|
|
|
config.app["proxy"]["type"] = self.dialog.proxy.type.Selection
|
|
|
|
config.app["proxy"]["server"] = self.dialog.get_value("proxy", "server")
|
|
|
|
config.app["proxy"]["port"] = self.dialog.get_value("proxy", "port")
|
|
|
|
config.app["proxy"]["user"] = self.dialog.get_value("proxy", "user")
|
|
|
|
config.app["proxy"]["password"] = self.dialog.get_value("proxy", "password")
|
|
|
|
config.app.write()
|