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
html
Toxygen.egg-info
*.tox

View file

@ -9,7 +9,7 @@ except ImportError:
from bootstrap import node_generator
from mainscreen import MainWindow
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 platform
import toxencryptsave
@ -137,7 +137,7 @@ class Toxygen:
if reply == QtGui.QMessageBox.Yes:
path = Settings.get_default_path()
else:
path = curr_directory()
path = curr_directory() + '/'
ProfileHelper(path, name).save_profile(self.tox.get_savedata())
path = Settings.get_default_path()
settings = Settings(name)
@ -446,7 +446,7 @@ def clean():
def configure():
"""Removes unused libs"""
d = curr_directory() + '/libs/'
is_64bits = sys.maxsize > 2 ** 32
is_64bits = is_64_bit()
if not is_64bits:
if os.path.exists(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)
num = self.friends_list.indexFromItem(item).row()
friend = Profile.get_instance().get_friend(num)
if friend is None:
return
settings = Settings.get_instance()
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)

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)
if sorting & 4:
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
online_friends = filter(lambda x: x.status is not None, self._contacts)
count = len(list(online_friends))
part1 = self._contacts[:count]
part2 = self._contacts[count:]
part1 = sorted(part1, key=lambda x: x.name)
part2 = sorted(part2, key=lambda x: x.name)
part1 = sorted(part1, key=lambda x: x.name.lower())
part2 = sorted(part2, key=lambda x: x.name.lower())
self._contacts = part1 + part2
else: # sort by number
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]
def get_friend(self, num):
if num < 0 or num >= len(self._contacts):
return None
return self._contacts[num]
# -----------------------------------------------------------------------------------------------------------------

View file

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

View file

@ -1,6 +1,7 @@
import os
import time
import shutil
import sys
program_version = '0.2.6'
@ -43,6 +44,16 @@ def convert_time(t):
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:
_instance = None