Save configs when they change. Fixes #95

This commit is contained in:
Manuel Cortez 2017-01-14 06:11:41 -06:00
parent 6bb534d250
commit 4d5de6ca69
5 changed files with 26 additions and 8 deletions

View File

@ -74,6 +74,7 @@ class bufferController(object):
if hasattr(sound.URLPlayer, "stream"): if hasattr(sound.URLPlayer, "stream"):
sound.URLPlayer.stream.volume = self.session.settings["sound"]["volume"] sound.URLPlayer.stream.volume = self.session.settings["sound"]["volume"]
self.session.sound.play("volume_changed.ogg") self.session.sound.play("volume_changed.ogg")
self.session.settings.write()
def volume_up(self): def volume_up(self):
if self.session.settings["sound"]["volume"] < 1.0: if self.session.settings["sound"]["volume"] < 1.0:
@ -84,6 +85,7 @@ class bufferController(object):
if hasattr(sound.URLPlayer, "stream"): if hasattr(sound.URLPlayer, "stream"):
sound.URLPlayer.stream.volume = self.session.settings["sound"]["volume"] sound.URLPlayer.stream.volume = self.session.settings["sound"]["volume"]
self.session.sound.play("volume_changed.ogg") self.session.sound.play("volume_changed.ogg")
self.session.settings.write()
def start_stream(self, mandatory=False): def start_stream(self, mandatory=False):
if mandatory == True: if mandatory == True:
@ -148,6 +150,7 @@ class bufferController(object):
else: else:
call_threaded(self.post_with_media, text=text, attachments=tweet.attachments) call_threaded(self.post_with_media, text=text, attachments=tweet.attachments)
if hasattr(tweet.message, "destroy"): tweet.message.destroy() if hasattr(tweet.message, "destroy"): tweet.message.destroy()
self.session.settings.write()
def post_with_media(self, text, attachments): def post_with_media(self, text, attachments):
media_ids = [] media_ids = []
@ -209,6 +212,7 @@ class accountPanel(bufferController):
else: else:
self.buffer.change_autostart(False) self.buffer.change_autostart(False)
config.app["sessions"]["ignored_sessions"].append(self.account_id) config.app["sessions"]["ignored_sessions"].append(self.account_id)
config.app.write()
class emptyPanel(bufferController): class emptyPanel(bufferController):
def __init__(self, parent, name, account): def __init__(self, parent, name, account):
@ -356,6 +360,7 @@ class baseBufferController(bufferController):
if dlg == widgetUtils.YES: if dlg == widgetUtils.YES:
if self.name[:-9] in self.session.settings["other_buffers"]["timelines"]: if self.name[:-9] in self.session.settings["other_buffers"]["timelines"]:
self.session.settings["other_buffers"]["timelines"].remove(self.name[:-9]) self.session.settings["other_buffers"]["timelines"].remove(self.name[:-9])
self.session.settings.write()
self.session.db.pop(self.name) self.session.db.pop(self.name)
return True return True
elif dlg == widgetUtils.NO: elif dlg == widgetUtils.NO:
@ -366,6 +371,7 @@ class baseBufferController(bufferController):
if self.name[:-9] in self.session.settings["other_buffers"]["favourites_timelines"]: if self.name[:-9] in self.session.settings["other_buffers"]["favourites_timelines"]:
self.session.settings["other_buffers"]["favourites_timelines"].remove(self.name[:-9]) self.session.settings["other_buffers"]["favourites_timelines"].remove(self.name[:-9])
self.session.db.pop(self.name) self.session.db.pop(self.name)
self.session.settings.write()
return True return True
elif dlg == widgetUtils.NO: elif dlg == widgetUtils.NO:
return False return False
@ -525,6 +531,7 @@ class baseBufferController(bufferController):
params["media"] = message.file params["media"] = message.file
call_threaded(self.session.api_call, **params) call_threaded(self.session.api_call, **params)
if hasattr(message.message, "destroy"): message.message.destroy() if hasattr(message.message, "destroy"): message.message.destroy()
self.session.settings.write()
@_tweets_exist @_tweets_exist
def direct_message(self, *args, **kwargs): def direct_message(self, *args, **kwargs):
@ -720,6 +727,7 @@ class listBufferController(baseBufferController):
if self.name[:-5] in self.session.settings["other_buffers"]["lists"]: if self.name[:-5] in self.session.settings["other_buffers"]["lists"]:
self.session.settings["other_buffers"]["lists"].remove(self.name[:-5]) self.session.settings["other_buffers"]["lists"].remove(self.name[:-5])
self.session.db.pop(self.name) self.session.db.pop(self.name)
self.session.settings.write()
return True return True
elif dlg == widgetUtils.NO: elif dlg == widgetUtils.NO:
return False return False
@ -802,6 +810,7 @@ class peopleBufferController(baseBufferController):
if self.name[:-10] in self.session.settings["other_buffers"]["followers_timelines"]: if self.name[:-10] in self.session.settings["other_buffers"]["followers_timelines"]:
self.session.settings["other_buffers"]["followers_timelines"].remove(self.name[:-10]) self.session.settings["other_buffers"]["followers_timelines"].remove(self.name[:-10])
self.session.db.pop(self.name) self.session.db.pop(self.name)
self.session.settings.write()
return True return True
elif dlg == widgetUtils.NO: elif dlg == widgetUtils.NO:
return False return False
@ -811,6 +820,7 @@ class peopleBufferController(baseBufferController):
if self.name[:-8] in self.session.settings["other_buffers"]["friends_timelines"]: if self.name[:-8] in self.session.settings["other_buffers"]["friends_timelines"]:
self.session.settings["other_buffers"]["friends_timelines"].remove(self.name[:-8]) self.session.settings["other_buffers"]["friends_timelines"].remove(self.name[:-8])
self.session.db.pop(self.name) self.session.db.pop(self.name)
self.session.settings.write()
return True return True
elif dlg == widgetUtils.NO: elif dlg == widgetUtils.NO:
return False return False
@ -963,6 +973,7 @@ class searchBufferController(baseBufferController):
if dlg == widgetUtils.YES: if dlg == widgetUtils.YES:
if self.name[:-11] in self.session.settings["other_buffers"]["tweet_searches"]: if self.name[:-11] in self.session.settings["other_buffers"]["tweet_searches"]:
self.session.settings["other_buffers"]["tweet_searches"].remove(self.name[:-11]) self.session.settings["other_buffers"]["tweet_searches"].remove(self.name[:-11])
self.session.settings.write()
self.timer.cancel() self.timer.cancel()
self.session.db.pop(self.name) self.session.db.pop(self.name)
return True return True
@ -1004,6 +1015,7 @@ class searchPeopleBufferController(peopleBufferController):
if dlg == widgetUtils.YES: if dlg == widgetUtils.YES:
if self.name[:-11] in self.session.settings["other_buffers"]["tweet_searches"]: if self.name[:-11] in self.session.settings["other_buffers"]["tweet_searches"]:
self.session.settings["other_buffers"]["tweet_searches"].remove(self.name[:-11]) self.session.settings["other_buffers"]["tweet_searches"].remove(self.name[:-11])
self.session.settings.write()
self.timer.cancel() self.timer.cancel()
self.session.db.pop(self.name) self.session.db.pop(self.name)
return True return True
@ -1072,6 +1084,7 @@ class trendsBufferController(bufferController):
if dlg == widgetUtils.YES: if dlg == widgetUtils.YES:
if self.name[:-3] in self.session.settings["other_buffers"]["trending_topic_buffers"]: if self.name[:-3] in self.session.settings["other_buffers"]["trending_topic_buffers"]:
self.session.settings["other_buffers"]["trending_topic_buffers"].remove(self.name[:-3]) self.session.settings["other_buffers"]["trending_topic_buffers"].remove(self.name[:-3])
self.session.settings.write()
self.timer.cancel() self.timer.cancel()
self.session.db.pop(self.name) self.session.db.pop(self.name)
return True return True

View File

@ -438,6 +438,7 @@ class Controller(object):
if dlg.get("tweets") == True: if dlg.get("tweets") == True:
if term not in buffer.session.settings["other_buffers"]["tweet_searches"]: if term not in buffer.session.settings["other_buffers"]["tweet_searches"]:
buffer.session.settings["other_buffers"]["tweet_searches"].append(term) buffer.session.settings["other_buffers"]["tweet_searches"].append(term)
buffer.session.settings.write()
args = {"lang": dlg.get_language(), "result_type": dlg.get_result_type()} args = {"lang": dlg.get_language(), "result_type": dlg.get_result_type()}
search = buffersController.searchBufferController(self.view.nb, "search", "%s-searchterm" % (term,), buffer.session, buffer.session.db["user_name"], bufferType="searchPanel", q=term, count=buffer.session.settings["general"]["max_tweets_per_call"], **args) search = buffersController.searchBufferController(self.view.nb, "search", "%s-searchterm" % (term,), buffer.session, buffer.session.db["user_name"], bufferType="searchPanel", q=term, count=buffer.session.settings["general"]["max_tweets_per_call"], **args)
else: else:
@ -496,6 +497,7 @@ class Controller(object):
def edit_keystrokes(self, *args, **kwargs): def edit_keystrokes(self, *args, **kwargs):
editor = keystrokeEditor.KeystrokeEditor() editor = keystrokeEditor.KeystrokeEditor()
if editor.changed == True: if editor.changed == True:
config.keymap.write()
register = False register = False
# determines if we need to reassign the keymap. # determines if we need to reassign the keymap.
if self.showing == False: if self.showing == False:
@ -637,12 +639,8 @@ class Controller(object):
for i in self.buffers: i.save_positions() for i in self.buffers: i.save_positions()
log.debug("Exiting...") log.debug("Exiting...")
log.debug("Saving global configuration...") log.debug("Saving global configuration...")
config.app.write()
config.keymap.write()
for item in session_.sessions: for item in session_.sessions:
if session_.sessions[item].logged == False: continue if session_.sessions[item].logged == False: continue
log.debug("Saving config for %s session" % (session_.sessions[item].session_id,))
session_.sessions[item].settings.write()
log.debug("Disconnecting streams for %s session" % (session_.sessions[item].session_id,)) log.debug("Disconnecting streams for %s session" % (session_.sessions[item].session_id,))
if hasattr(session_.sessions[item], "main_stream"): session_.sessions[item].main_stream.disconnect() if hasattr(session_.sessions[item], "main_stream"): session_.sessions[item].main_stream.disconnect()
if hasattr(session_.sessions[item], "timelinesStream"): session_.sessions[item].timelinesStream.disconnect() if hasattr(session_.sessions[item], "timelinesStream"): session_.sessions[item].timelinesStream.disconnect()
@ -866,6 +864,7 @@ class Controller(object):
buff.session.sound.play("create_timeline.ogg") buff.session.sound.play("create_timeline.ogg")
else: else:
commonMessageDialogs.user_not_exist() commonMessageDialogs.user_not_exist()
buff.session.settings.write()
def open_conversation(self, *args, **kwargs): def open_conversation(self, *args, **kwargs):
buffer = self.get_current_buffer() buffer = self.get_current_buffer()
@ -910,6 +909,7 @@ class Controller(object):
timer = RepeatingTimer(300, buffer.start_stream) timer = RepeatingTimer(300, buffer.start_stream)
timer.start() timer.start()
buffer.session.settings["other_buffers"]["trending_topic_buffers"].append(woeid) buffer.session.settings["other_buffers"]["trending_topic_buffers"].append(woeid)
buffer.session.settings.write()
def reverse_geocode(self, event=None): def reverse_geocode(self, event=None):
try: try:
@ -1384,6 +1384,7 @@ class Controller(object):
self.view.insert_buffer(tl.buffer, name=_(u"List for {}").format(create), pos=self.view.search("lists", buff.session.db["user_name"])) self.view.insert_buffer(tl.buffer, name=_(u"List for {}").format(create), pos=self.view.search("lists", buff.session.db["user_name"]))
tl.start_stream() tl.start_stream()
buff.session.settings["other_buffers"]["lists"].append(create) buff.session.settings["other_buffers"]["lists"].append(create)
buff.session.settings.write()
pub.sendMessage("restart-streams", streams=["timelinesStream"], session=buff.session) pub.sendMessage("restart-streams", streams=["timelinesStream"], session=buff.session)
def restart_streams(self, streams=[], session=None): def restart_streams(self, streams=[], session=None):
@ -1438,6 +1439,7 @@ class Controller(object):
elif buffer.name in buffer.session.settings["other_buffers"]["autoread_buffers"]: elif buffer.name in buffer.session.settings["other_buffers"]["autoread_buffers"]:
buffer.session.settings["other_buffers"]["autoread_buffers"].remove(buffer.name) buffer.session.settings["other_buffers"]["autoread_buffers"].remove(buffer.name)
output.speak(_(u"The auto-reading of new tweets is disabled for this buffer"), True) output.speak(_(u"The auto-reading of new tweets is disabled for this buffer"), True)
buffer.session.settings.write()
def toggle_session_mute(self, *args, **kwargs): def toggle_session_mute(self, *args, **kwargs):
buffer = self.get_best_buffer() buffer = self.get_best_buffer()
@ -1447,6 +1449,7 @@ class Controller(object):
elif buffer.session.settings["sound"]["session_mute"] == True: elif buffer.session.settings["sound"]["session_mute"] == True:
buffer.session.settings["sound"]["session_mute"] = False buffer.session.settings["sound"]["session_mute"] = False
output.speak(_(u"Session mute off"), True) output.speak(_(u"Session mute off"), True)
buffer.session.settings.write()
def toggle_buffer_mute(self, *args, **kwargs): def toggle_buffer_mute(self, *args, **kwargs):
buffer = self.get_current_buffer() buffer = self.get_current_buffer()
@ -1457,6 +1460,7 @@ class Controller(object):
elif buffer.name in buffer.session.settings["other_buffers"]["muted_buffers"]: elif buffer.name in buffer.session.settings["other_buffers"]["muted_buffers"]:
buffer.session.settings["other_buffers"]["muted_buffers"].remove(buffer.name) buffer.session.settings["other_buffers"]["muted_buffers"].remove(buffer.name)
output.speak(_(u"Buffer mute off"), True) output.speak(_(u"Buffer mute off"), True)
buffer.session.settings.write()
def view_documentation(self, *args, **kwargs): def view_documentation(self, *args, **kwargs):
lang = localization.get("documentation") lang = localization.get("documentation")
@ -1488,9 +1492,6 @@ class Controller(object):
if i.session != None and i.session.session_id == session: if i.session != None and i.session.session_id == session:
i.start_stream() i.start_stream()
def __del__(self):
config.app.write()
def update_buffer(self, *args, **kwargs): def update_buffer(self, *args, **kwargs):
bf = self.get_current_buffer() bf = self.get_current_buffer()
if not hasattr(bf, "start_stream"): if not hasattr(bf, "start_stream"):

View File

@ -234,6 +234,7 @@ class accountSettingsController(globalSettingsController):
self.buffer.session.sound.config = self.config["sound"] self.buffer.session.sound.config = self.config["sound"]
self.buffer.session.sound.check_soundpack() self.buffer.session.sound.check_soundpack()
self.config["sound"]["sndup_api_key"] = self.dialog.get_value("services", "apiKey") self.config["sound"]["sndup_api_key"] = self.dialog.get_value("services", "apiKey")
self.config.write()
def toggle_state(self,*args,**kwargs): def toggle_state(self,*args,**kwargs):
return self.dialog.buffers.change_selected_item() return self.dialog.buffers.change_selected_item()

View File

@ -77,3 +77,4 @@ class userActionsController(object):
client = re.sub(r"(?s)<.*?>", "", tweet["source"]) client = re.sub(r"(?s)<.*?>", "", tweet["source"])
if client not in self.session.settings["twitter"]["ignored_clients"]: if client not in self.session.settings["twitter"]["ignored_clients"]:
self.session.settings["twitter"]["ignored_clients"].append(client) self.session.settings["twitter"]["ignored_clients"].append(client)
self.session.settings.write()

View File

@ -95,6 +95,8 @@ class sessionManagerController(object):
s.authorise() s.authorise()
self.sessions.append(location) self.sessions.append(location)
self.view.add_new_session_to_list() self.view.add_new_session_to_list()
s.settings.write()
config.write()
# except: # except:
# log.exception("Error authorising the session") # log.exception("Error authorising the session")
# self.view.show_unauthorised_error() # self.view.show_unauthorised_error()