settings fix

This commit is contained in:
ingvar1995 2016-03-02 19:05:03 +03:00
parent 0c590b01d7
commit 26fcc260df
4 changed files with 38 additions and 11 deletions

View file

@ -37,8 +37,8 @@ def main():
"""
app = QtGui.QApplication(sys.argv)
app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
settings = Settings()
if not settings['auto_profile']:
auto_profile = Settings.get_auto_profile()
if not auto_profile:
# show login screen if default profile not found
ls = LoginScreen()
ls.setWindowIconText("Toxygen")
@ -53,19 +53,21 @@ def main():
return
elif _login.t == 1: # create new profile
name = _login.name if _login.name else 'toxygen_user'
settings = Settings(name)
tox = tox_factory()
tox.self_set_name(_login.name if _login.name else 'Toxygen User')
tox.self_set_status_message('Toxing on Toxygen')
ProfileHelper.save_profile(tox.get_savedata(), name)
else: # load existing profile
path, name = _login.get_data()
settings = Settings(name)
if _login.default:
settings['auto_profile'] = (path, name)
settings.save()
Settings.set_auto_profile(path, name)
data = ProfileHelper.open_profile(path, name)
tox = tox_factory(data, settings)
else:
path, name = settings['auto_profile']
path, name = auto_profile
settings = Settings(name)
data = ProfileHelper.open_profile(path, name)
tox = tox_factory(data, settings)

View file

@ -101,6 +101,7 @@ class MainWindow(QtGui.QMainWindow):
self.online_contacts = QtGui.QCheckBox(Form)
self.online_contacts.setGeometry(QtCore.QRect(0, 20, 141, 22))
self.online_contacts.setObjectName("online_contacts")
self.online_contacts.clicked.connect(self.filtering)
self.lineEdit = QtGui.QLineEdit(Form)
self.lineEdit.setGeometry(QtCore.QRect(0, 40, 140, 28))
self.lineEdit.setObjectName("lineEdit")
@ -170,7 +171,7 @@ class MainWindow(QtGui.QMainWindow):
def setup_left_center(self, widget, profile_widget):
self.friends_list = QtGui.QListWidget(widget)
self.friends_list.setGeometry(0, 0, 250, 150)
self.friends_list.setGeometry(0, 0, 250, 250)
count = self.tox.self_get_friend_list_size()
widgets = []
for i in xrange(count):
@ -186,7 +187,7 @@ class MainWindow(QtGui.QMainWindow):
def setup_right_center(self, widget):
self.messages = QtGui.QListWidget(widget)
self.messages.setGeometry(0, 0, 500, 200)
self.messages.setGeometry(0, 0, 500, 250)
def initUI(self):
self.setMinimumSize(800, 400)
@ -281,3 +282,6 @@ class MainWindow(QtGui.QMainWindow):
self.profile.set_active(num)
self.update_active_friend()
self.messageEdit.clear()
def filtering(self):
self.profile.filtration(self.online_contacts.isChecked())

View file

@ -107,8 +107,8 @@ class Friend(Contact):
return self._visible
def set_visibility(self, value):
self._widget.setVisibility(value)
self._visible = value
self._widget.setVisible(value)
visibility = property(get_visibility, set_visibility)
@ -141,6 +141,7 @@ class Profile(Contact):
self._name = tox.self_get_name()
self._status_message = tox.self_get_status_message()
self._status = None
self.show_online = Settings()['show_online_friends']
data = tox.self_get_friend_list()
self._friends, num, self._active_friend = [], 0, -1
for i in data:
@ -151,6 +152,7 @@ class Profile(Contact):
Profile._instance = self
self.set_name(tox.self_get_name().encode('utf-8'))
self.set_status_message(tox.self_get_status_message().encode('utf-8'))
self.filtration(self.show_online)
@staticmethod
def get_instance():
@ -171,8 +173,10 @@ class Profile(Contact):
self.tox.self_set_status_message(self._status_message.encode('utf-8'))
def filtration(self, show_online=True, filter_str=''):
# TODO: hide elements in list
for friend in self._friends:
friend.visibility = (friend.status is not None or not show_online) and (filter_str in friend.name)
self.show_online, self.filter_string = show_online, filter_str
def get_friend_by_number(self, num):
return filter(lambda x: x.number == num, self._friends)[0]

View file

@ -6,8 +6,8 @@ from util import Singleton
class Settings(dict, Singleton):
def __init__(self):
self.path = Settings.get_default_path() + 'toxygen.json'
def __init__(self, name=''):
self.path = Settings.get_default_path() + str(name) + '.json'
if os.path.isfile(self.path):
with open(self.path) as fl:
data = fl.read()
@ -16,6 +16,24 @@ class Settings(dict, Singleton):
super(self.__class__, self).__init__(Settings.get_default_settings())
self.save()
@staticmethod
def get_auto_profile():
path = Settings.get_default_path() + 'toxygen.json'
if os.path.isfile(path):
with open(path) as fl:
data = fl.read()
auto = json.loads(data)
return auto['path'], auto['name']
else:
return None
@staticmethod
def set_auto_profile(path, name):
p = Settings.get_default_path() + 'toxygen.json'
data = json.dumps({'path': path, 'name': name})
with open(p, 'w') as fl:
fl.write(data)
@staticmethod
def get_default_settings():
return {
@ -38,7 +56,6 @@ class Settings(dict, Singleton):
'auto_accept_from_friends': [],
'friends_aliases': [],
'typing_notifications': True,
'auto_profile': None,
'calls_sound': True
}