profile creation fixes

This commit is contained in:
ingvar1995 2016-11-01 00:04:48 +03:00
parent 202c5a14a5
commit 137195c8f2
6 changed files with 24 additions and 7 deletions

1
.gitignore vendored
View File

@ -22,4 +22,5 @@ toxygen/__pycache__
/*.egg /*.egg
html html
Toxygen.egg-info Toxygen.egg-info
*.tox

View File

@ -9,7 +9,7 @@ except ImportError:
from bootstrap import node_generator from bootstrap import node_generator
from mainscreen import MainWindow from mainscreen import MainWindow
from callbacks import init_callbacks, stop, start from callbacks import init_callbacks, stop, start
from util import curr_directory, program_version, remove from util import curr_directory, program_version, remove, is_64_bit
import styles.style import styles.style
import platform import platform
import toxencryptsave import toxencryptsave
@ -137,7 +137,7 @@ class Toxygen:
if reply == QtGui.QMessageBox.Yes: if reply == QtGui.QMessageBox.Yes:
path = Settings.get_default_path() path = Settings.get_default_path()
else: else:
path = curr_directory() path = curr_directory() + '/'
ProfileHelper(path, name).save_profile(self.tox.get_savedata()) ProfileHelper(path, name).save_profile(self.tox.get_savedata())
path = Settings.get_default_path() path = Settings.get_default_path()
settings = Settings(name) settings = Settings(name)
@ -446,7 +446,7 @@ def clean():
def configure(): def configure():
"""Removes unused libs""" """Removes unused libs"""
d = curr_directory() + '/libs/' d = curr_directory() + '/libs/'
is_64bits = sys.maxsize > 2 ** 32 is_64bits = is_64_bit()
if not is_64bits: if not is_64bits:
if os.path.exists(d + 'libtox64.dll'): if os.path.exists(d + 'libtox64.dll'):
os.remove(d + 'libtox64.dll') os.remove(d + 'libtox64.dll')

View File

@ -554,6 +554,8 @@ class MainWindow(QtGui.QMainWindow, Singleton):
item = self.friends_list.itemAt(pos) item = self.friends_list.itemAt(pos)
num = self.friends_list.indexFromItem(item).row() num = self.friends_list.indexFromItem(item).row()
friend = Profile.get_instance().get_friend(num) friend = Profile.get_instance().get_friend(num)
if friend is None:
return
settings = Settings.get_instance() settings = Settings.get_instance()
allowed = friend.tox_id in settings['auto_accept_from_friends'] allowed = friend.tox_id in settings['auto_accept_from_friends']
auto = QtGui.QApplication.translate("MainWindow", 'Disallow auto accept', None, QtGui.QApplication.UnicodeUTF8) if allowed else QtGui.QApplication.translate("MainWindow", 'Allow auto accept', None, QtGui.QApplication.UnicodeUTF8) auto = QtGui.QApplication.translate("MainWindow", 'Disallow auto accept', None, QtGui.QApplication.UnicodeUTF8) if allowed else QtGui.QApplication.translate("MainWindow", 'Allow auto accept', None, QtGui.QApplication.UnicodeUTF8)

View File

@ -132,14 +132,14 @@ class Profile(basecontact.BaseContact, Singleton):
self._contacts = sorted(self._contacts, key=lambda x: int(x.status is not None), reverse=True) self._contacts = sorted(self._contacts, key=lambda x: int(x.status is not None), reverse=True)
if sorting & 4: if sorting & 4:
if not sorting & 2: if not sorting & 2:
self._contacts = sorted(self._contacts, key=lambda x: x.name) self._contacts = sorted(self._contacts, key=lambda x: x.name.lower())
else: # save results of prev sorting else: # save results of prev sorting
online_friends = filter(lambda x: x.status is not None, self._contacts) online_friends = filter(lambda x: x.status is not None, self._contacts)
count = len(list(online_friends)) count = len(list(online_friends))
part1 = self._contacts[:count] part1 = self._contacts[:count]
part2 = self._contacts[count:] part2 = self._contacts[count:]
part1 = sorted(part1, key=lambda x: x.name) part1 = sorted(part1, key=lambda x: x.name.lower())
part2 = sorted(part2, key=lambda x: x.name) part2 = sorted(part2, key=lambda x: x.name.lower())
self._contacts = part1 + part2 self._contacts = part1 + part2
else: # sort by number else: # sort by number
online_friends = filter(lambda x: x.status is not None, self._contacts) online_friends = filter(lambda x: x.status is not None, self._contacts)
@ -177,6 +177,8 @@ class Profile(basecontact.BaseContact, Singleton):
return list(filter(lambda x: x.number == num, self._contacts))[0] return list(filter(lambda x: x.number == num, self._contacts))[0]
def get_friend(self, num): def get_friend(self, num):
if num < 0 or num >= len(self._contacts):
return None
return self._contacts[num] return self._contacts[num]
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------

View File

@ -1,7 +1,7 @@
from platform import system from platform import system
import json import json
import os import os
from util import Singleton, curr_directory, log, copy from util import Singleton, curr_directory, log, copy, append_slash
import pyaudio import pyaudio
from toxencryptsave import ToxEncryptSave from toxencryptsave import ToxEncryptSave
import smileys import smileys
@ -232,6 +232,7 @@ class ProfileHelper(Singleton):
""" """
def __init__(self, path, name): def __init__(self, path, name):
Singleton.__init__(self) Singleton.__init__(self)
path = append_slash(path)
self._path = path + name + '.tox' self._path = path + name + '.tox'
self._directory = path self._directory = path
# create /avatars if not exists: # create /avatars if not exists:

View File

@ -1,6 +1,7 @@
import os import os
import time import time
import shutil import shutil
import sys
program_version = '0.2.6' program_version = '0.2.6'
@ -43,6 +44,16 @@ def convert_time(t):
return '%02d:%02d' % (h, m) return '%02d:%02d' % (h, m)
def append_slash(s):
if s[-1] not in ('\\', '/'):
s += '/'
return s
def is_64_bit():
return sys.maxsize > 2 ** 32
class Singleton: class Singleton:
_instance = None _instance = None