portability updates

This commit is contained in:
ingvar1995 2016-07-27 17:13:57 +03:00
parent 3bd7655203
commit 883a30f806
4 changed files with 44 additions and 11 deletions

View File

@ -125,7 +125,19 @@ class Toxygen:
set_pass.show() set_pass.show()
self.app.connect(self.app, QtCore.SIGNAL("lastWindowClosed()"), self.app, QtCore.SLOT("quit()")) self.app.connect(self.app, QtCore.SIGNAL("lastWindowClosed()"), self.app, QtCore.SLOT("quit()"))
self.app.exec_() self.app.exec_()
ProfileHelper(Settings.get_default_path(), name).save_profile(self.tox.get_savedata()) reply = QtGui.QMessageBox.question(None,
'Profile {}'.format(name),
QtGui.QApplication.translate("login",
'Do you want to save profile in default folder? If no, profile will be saved in program folder',
None,
QtGui.QApplication.UnicodeUTF8),
QtGui.QMessageBox.Yes,
QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
path = Settings.get_default_path()
else:
path = curr_directory()
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)
if curr_lang in langs: if curr_lang in langs:
@ -424,7 +436,7 @@ def main():
else: # started with argument(s) else: # started with argument(s)
arg = sys.argv[1] arg = sys.argv[1]
if arg == '--version': if arg == '--version':
print('Toxygen ' + program_version) print('Toxygen v' + program_version)
return return
elif arg == '--help': elif arg == '--help':
print('Usage:\ntoxygen path_to_profile\ntoxygen tox_id\ntoxygen --version') print('Usage:\ntoxygen path_to_profile\ntoxygen tox_id\ntoxygen --version')

View File

@ -269,11 +269,22 @@ class ProfileSettings(CenteredWidget):
directory = QtGui.QFileDialog.getExistingDirectory(options=QtGui.QFileDialog.DontUseNativeDialog, directory = QtGui.QFileDialog.getExistingDirectory(options=QtGui.QFileDialog.DontUseNativeDialog,
dir=curr_directory()) + '/' dir=curr_directory()) + '/'
if directory != '/': if directory != '/':
ProfileHelper.get_instance().export_profile(directory) reply = QtGui.QMessageBox.question(None,
QtGui.QApplication.translate("ProfileSettingsForm",
'Use new path',
None,
QtGui.QApplication.UnicodeUTF8),
QtGui.QApplication.translate("ProfileSettingsForm",
'Do you want to move your profile to this location?',
None,
QtGui.QApplication.UnicodeUTF8),
QtGui.QMessageBox.Yes,
QtGui.QMessageBox.No)
settings = Settings.get_instance() settings = Settings.get_instance()
settings.export(directory) settings.export(directory)
profile = Profile.get_instance() profile = Profile.get_instance()
profile.export_history(directory) profile.export_history(directory)
ProfileHelper.get_instance().export_profile(directory, reply == QtGui.QMessageBox.Yes)
def closeEvent(self, event): def closeEvent(self, event):
profile = Profile.get_instance() profile = Profile.get_instance()

View File

@ -311,9 +311,12 @@ class Profile(contact.Contact, Singleton):
Send typing notification to a friend Send typing notification to a friend
""" """
if Settings.get_instance()['typing_notifications'] and self._active_friend + 1: if Settings.get_instance()['typing_notifications'] and self._active_friend + 1:
try:
friend = self._friends[self._active_friend] friend = self._friends[self._active_friend]
if friend.status is not None: if friend.status is not None:
self._tox.self_set_typing(friend.number, typing) self._tox.self_set_typing(friend.number, typing)
except:
pass
def friend_typing(self, friend_number, typing): def friend_typing(self, friend_number, typing):
""" """

View File

@ -1,8 +1,7 @@
from platform import system from platform import system
import json import json
import os import os
import locale from util import Singleton, curr_directory, log, copy
from util import Singleton, curr_directory, log
import pyaudio import pyaudio
from toxencryptsave import ToxEncryptSave from toxencryptsave import ToxEncryptSave
import smileys import smileys
@ -202,6 +201,9 @@ class Settings(dict, Singleton):
with open(path + str(self.name) + '.json', 'w') as fl: with open(path + str(self.name) + '.json', 'w') as fl:
fl.write(text) fl.write(text)
def update_path(self):
self.path = ProfileHelper.get_path() + self.name + '.json'
@staticmethod @staticmethod
def get_default_path(): def get_default_path():
if system() == 'Windows': if system() == 'Windows':
@ -244,13 +246,18 @@ class ProfileHelper(Singleton):
fl.write(data) fl.write(data)
print('Profile saved successfully') print('Profile saved successfully')
def export_profile(self, new_path): def export_profile(self, new_path, use_new_path):
new_path += os.path.basename(self._path) path = new_path + os.path.basename(self._path)
with open(self._path, 'rb') as fin: with open(self._path, 'rb') as fin:
data = fin.read() data = fin.read()
with open(new_path, 'wb') as fout: with open(path, 'wb') as fout:
fout.write(data) fout.write(data)
print('Profile exported successfully') print('Profile exported successfully')
copy(self._directory + 'avatars', new_path + 'avatars')
if use_new_path:
self._path = new_path + os.path.basename(self._path)
self._directory = new_path
Settings.get_instance().update_path()
@staticmethod @staticmethod
def find_profiles(): def find_profiles():