From fee7254d5588dd3349936eaac78be382f4ea16df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Mon, 1 Dec 2014 15:21:25 -0600 Subject: [PATCH] Configuration for autocompletion users --- src/Conf.defaults | 2 ++ src/extra/autocompletionUsers/settings.py | 13 +++++++++++-- src/extra/autocompletionUsers/storage.py | 14 +++++++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Conf.defaults b/src/Conf.defaults index 75fb4238..3c73f0ae 100644 --- a/src/Conf.defaults +++ b/src/Conf.defaults @@ -40,6 +40,8 @@ autoread_buffers = list(default=list()) [mysc] spelling_language = string(default="") +save_followers_in_autocompletion_db = boolean(default=False) +save_friends_in_autocompletion_db = boolean(default=False) [services] dropbox_token=string(default="") diff --git a/src/extra/autocompletionUsers/settings.py b/src/extra/autocompletionUsers/settings.py index 0737a121..cd19be8b 100644 --- a/src/extra/autocompletionUsers/settings.py +++ b/src/extra/autocompletionUsers/settings.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import storage import wx +import config import wx_settings import output from mysc.thread_utils import call_threaded @@ -10,20 +11,28 @@ class autocompletionSettings(object): super(autocompletionSettings, self).__init__() self.window = window self.dialog = wx_settings.autocompletionSettingsDialog() + self.dialog.friends_buffer.SetValue(config.main["mysc"]["save_friends_in_autocompletion_db"]) + self.dialog.followers_buffer.SetValue(config.main["mysc"]["save_followers_in_autocompletion_db"]) if self.dialog.ShowModal() == wx.ID_OK: call_threaded(self.add_users_to_database) def add_users_to_database(self): + config.main["mysc"]["save_friends_in_autocompletion_db"] = self.dialog.friends_buffer.GetValue() + config.main["mysc"]["save_followers_in_autocompletion_db"] = self.dialog.friends_buffer.GetValue() output.speak(_(u"Updating database... You can close this window now. A message will tell you when the process finishes.")) database = storage.storage() if self.dialog.followers_buffer.GetValue() == True: buffer = self.window.search_buffer("people", "followers") for i in buffer.db.settings[buffer.name_buffer]: - database.set_user(i["screen_name"], i["name"]) + database.set_user(i["screen_name"], i["name"], 1) + else: + database.remove_by_buffer(1) if self.dialog.friends_buffer.GetValue() == True: buffer = self.window.search_buffer("people", "friends") for i in buffer.db.settings[buffer.name_buffer]: - database.set_user(i["screen_name"], i["name"]) + database.set_user(i["screen_name"], i["name"], 2) + else: + database.remove_by_buffer(2) wx_settings.show_success_dialog() self.dialog.Destroy() \ No newline at end of file diff --git a/src/extra/autocompletionUsers/storage.py b/src/extra/autocompletionUsers/storage.py index b5eb410a..a2af1c1e 100644 --- a/src/extra/autocompletionUsers/storage.py +++ b/src/extra/autocompletionUsers/storage.py @@ -21,19 +21,27 @@ class storage(object): self.cursor.execute("""SELECT * FROM users WHERE user LIKE ?""", ('{}%'.format(term),)) return self.cursor.fetchall() - def set_user(self, screen_name, user_name): - self.cursor.execute("""insert or ignore into users values(?, ?)""", (screen_name, user_name)) + def set_user(self, screen_name, user_name, from_a_buffer): + self.cursor.execute("""insert or ignore into users values(?, ?, ?)""", (screen_name, user_name, from_a_buffer)) self.connection.commit() def remove_user(self, user): self.cursor.execute("""DELETE FROM users WHERE user = ?""", (user,)) + self.connection.commit() + return self.cursor.fetchone() + + def remove_by_buffer(self, bufferType): + """ Removes all users saved on a buffer. BufferType is 0 for no buffer, 1 for friends and 2 for followers""" + self.cursor.execute("""DELETE FROM users WHERE from_a_buffer = ?""", (bufferType,)) + self.connection.commit() return self.cursor.fetchone() def create_table(self): self.cursor.execute(""" create table users( user TEXT UNIQUE, -name TEXT +name TEXT, +from_a_buffer INTEGER )""") def __del__(self):