settings fix
This commit is contained in:
parent
0c590b01d7
commit
26fcc260df
12
src/main.py
12
src/main.py
@ -37,8 +37,8 @@ def main():
|
|||||||
"""
|
"""
|
||||||
app = QtGui.QApplication(sys.argv)
|
app = QtGui.QApplication(sys.argv)
|
||||||
app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
|
app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
|
||||||
settings = Settings()
|
auto_profile = Settings.get_auto_profile()
|
||||||
if not settings['auto_profile']:
|
if not auto_profile:
|
||||||
# show login screen if default profile not found
|
# show login screen if default profile not found
|
||||||
ls = LoginScreen()
|
ls = LoginScreen()
|
||||||
ls.setWindowIconText("Toxygen")
|
ls.setWindowIconText("Toxygen")
|
||||||
@ -53,19 +53,21 @@ def main():
|
|||||||
return
|
return
|
||||||
elif _login.t == 1: # create new profile
|
elif _login.t == 1: # create new profile
|
||||||
name = _login.name if _login.name else 'toxygen_user'
|
name = _login.name if _login.name else 'toxygen_user'
|
||||||
|
settings = Settings(name)
|
||||||
tox = tox_factory()
|
tox = tox_factory()
|
||||||
tox.self_set_name(_login.name if _login.name else 'Toxygen User')
|
tox.self_set_name(_login.name if _login.name else 'Toxygen User')
|
||||||
tox.self_set_status_message('Toxing on Toxygen')
|
tox.self_set_status_message('Toxing on Toxygen')
|
||||||
ProfileHelper.save_profile(tox.get_savedata(), name)
|
ProfileHelper.save_profile(tox.get_savedata(), name)
|
||||||
else: # load existing profile
|
else: # load existing profile
|
||||||
path, name = _login.get_data()
|
path, name = _login.get_data()
|
||||||
|
settings = Settings(name)
|
||||||
if _login.default:
|
if _login.default:
|
||||||
settings['auto_profile'] = (path, name)
|
Settings.set_auto_profile(path, name)
|
||||||
settings.save()
|
|
||||||
data = ProfileHelper.open_profile(path, name)
|
data = ProfileHelper.open_profile(path, name)
|
||||||
tox = tox_factory(data, settings)
|
tox = tox_factory(data, settings)
|
||||||
else:
|
else:
|
||||||
path, name = settings['auto_profile']
|
path, name = auto_profile
|
||||||
|
settings = Settings(name)
|
||||||
data = ProfileHelper.open_profile(path, name)
|
data = ProfileHelper.open_profile(path, name)
|
||||||
tox = tox_factory(data, settings)
|
tox = tox_factory(data, settings)
|
||||||
|
|
||||||
|
@ -101,6 +101,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
self.online_contacts = QtGui.QCheckBox(Form)
|
self.online_contacts = QtGui.QCheckBox(Form)
|
||||||
self.online_contacts.setGeometry(QtCore.QRect(0, 20, 141, 22))
|
self.online_contacts.setGeometry(QtCore.QRect(0, 20, 141, 22))
|
||||||
self.online_contacts.setObjectName("online_contacts")
|
self.online_contacts.setObjectName("online_contacts")
|
||||||
|
self.online_contacts.clicked.connect(self.filtering)
|
||||||
self.lineEdit = QtGui.QLineEdit(Form)
|
self.lineEdit = QtGui.QLineEdit(Form)
|
||||||
self.lineEdit.setGeometry(QtCore.QRect(0, 40, 140, 28))
|
self.lineEdit.setGeometry(QtCore.QRect(0, 40, 140, 28))
|
||||||
self.lineEdit.setObjectName("lineEdit")
|
self.lineEdit.setObjectName("lineEdit")
|
||||||
@ -170,7 +171,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
|
|
||||||
def setup_left_center(self, widget, profile_widget):
|
def setup_left_center(self, widget, profile_widget):
|
||||||
self.friends_list = QtGui.QListWidget(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()
|
count = self.tox.self_get_friend_list_size()
|
||||||
widgets = []
|
widgets = []
|
||||||
for i in xrange(count):
|
for i in xrange(count):
|
||||||
@ -186,7 +187,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
|
|
||||||
def setup_right_center(self, widget):
|
def setup_right_center(self, widget):
|
||||||
self.messages = QtGui.QListWidget(widget)
|
self.messages = QtGui.QListWidget(widget)
|
||||||
self.messages.setGeometry(0, 0, 500, 200)
|
self.messages.setGeometry(0, 0, 500, 250)
|
||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
self.setMinimumSize(800, 400)
|
self.setMinimumSize(800, 400)
|
||||||
@ -281,3 +282,6 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
self.profile.set_active(num)
|
self.profile.set_active(num)
|
||||||
self.update_active_friend()
|
self.update_active_friend()
|
||||||
self.messageEdit.clear()
|
self.messageEdit.clear()
|
||||||
|
|
||||||
|
def filtering(self):
|
||||||
|
self.profile.filtration(self.online_contacts.isChecked())
|
||||||
|
@ -107,8 +107,8 @@ class Friend(Contact):
|
|||||||
return self._visible
|
return self._visible
|
||||||
|
|
||||||
def set_visibility(self, value):
|
def set_visibility(self, value):
|
||||||
self._widget.setVisibility(value)
|
|
||||||
self._visible = value
|
self._visible = value
|
||||||
|
self._widget.setVisible(value)
|
||||||
|
|
||||||
visibility = property(get_visibility, set_visibility)
|
visibility = property(get_visibility, set_visibility)
|
||||||
|
|
||||||
@ -141,6 +141,7 @@ class Profile(Contact):
|
|||||||
self._name = tox.self_get_name()
|
self._name = tox.self_get_name()
|
||||||
self._status_message = tox.self_get_status_message()
|
self._status_message = tox.self_get_status_message()
|
||||||
self._status = None
|
self._status = None
|
||||||
|
self.show_online = Settings()['show_online_friends']
|
||||||
data = tox.self_get_friend_list()
|
data = tox.self_get_friend_list()
|
||||||
self._friends, num, self._active_friend = [], 0, -1
|
self._friends, num, self._active_friend = [], 0, -1
|
||||||
for i in data:
|
for i in data:
|
||||||
@ -151,6 +152,7 @@ class Profile(Contact):
|
|||||||
Profile._instance = self
|
Profile._instance = self
|
||||||
self.set_name(tox.self_get_name().encode('utf-8'))
|
self.set_name(tox.self_get_name().encode('utf-8'))
|
||||||
self.set_status_message(tox.self_get_status_message().encode('utf-8'))
|
self.set_status_message(tox.self_get_status_message().encode('utf-8'))
|
||||||
|
self.filtration(self.show_online)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_instance():
|
def get_instance():
|
||||||
@ -171,8 +173,10 @@ class Profile(Contact):
|
|||||||
self.tox.self_set_status_message(self._status_message.encode('utf-8'))
|
self.tox.self_set_status_message(self._status_message.encode('utf-8'))
|
||||||
|
|
||||||
def filtration(self, show_online=True, filter_str=''):
|
def filtration(self, show_online=True, filter_str=''):
|
||||||
|
# TODO: hide elements in list
|
||||||
for friend in self._friends:
|
for friend in self._friends:
|
||||||
friend.visibility = (friend.status is not None or not show_online) and (filter_str in friend.name)
|
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):
|
def get_friend_by_number(self, num):
|
||||||
return filter(lambda x: x.number == num, self._friends)[0]
|
return filter(lambda x: x.number == num, self._friends)[0]
|
||||||
|
@ -6,8 +6,8 @@ from util import Singleton
|
|||||||
|
|
||||||
class Settings(dict, Singleton):
|
class Settings(dict, Singleton):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, name=''):
|
||||||
self.path = Settings.get_default_path() + 'toxygen.json'
|
self.path = Settings.get_default_path() + str(name) + '.json'
|
||||||
if os.path.isfile(self.path):
|
if os.path.isfile(self.path):
|
||||||
with open(self.path) as fl:
|
with open(self.path) as fl:
|
||||||
data = fl.read()
|
data = fl.read()
|
||||||
@ -16,6 +16,24 @@ class Settings(dict, Singleton):
|
|||||||
super(self.__class__, self).__init__(Settings.get_default_settings())
|
super(self.__class__, self).__init__(Settings.get_default_settings())
|
||||||
self.save()
|
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
|
@staticmethod
|
||||||
def get_default_settings():
|
def get_default_settings():
|
||||||
return {
|
return {
|
||||||
@ -38,7 +56,6 @@ class Settings(dict, Singleton):
|
|||||||
'auto_accept_from_friends': [],
|
'auto_accept_from_friends': [],
|
||||||
'friends_aliases': [],
|
'friends_aliases': [],
|
||||||
'typing_notifications': True,
|
'typing_notifications': True,
|
||||||
'auto_profile': None,
|
|
||||||
'calls_sound': True
|
'calls_sound': True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user