From 883a30f806eae0afaca9472af73c7927611ca371 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Wed, 27 Jul 2016 17:13:57 +0300 Subject: [PATCH] portability updates --- toxygen/main.py | 16 ++++++++++++++-- toxygen/menu.py | 13 ++++++++++++- toxygen/profile.py | 9 ++++++--- toxygen/settings.py | 17 ++++++++++++----- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/toxygen/main.py b/toxygen/main.py index f5622f6..fc988f6 100644 --- a/toxygen/main.py +++ b/toxygen/main.py @@ -125,7 +125,19 @@ class Toxygen: set_pass.show() self.app.connect(self.app, QtCore.SIGNAL("lastWindowClosed()"), self.app, QtCore.SLOT("quit()")) 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() settings = Settings(name) if curr_lang in langs: @@ -424,7 +436,7 @@ def main(): else: # started with argument(s) arg = sys.argv[1] if arg == '--version': - print('Toxygen ' + program_version) + print('Toxygen v' + program_version) return elif arg == '--help': print('Usage:\ntoxygen path_to_profile\ntoxygen tox_id\ntoxygen --version') diff --git a/toxygen/menu.py b/toxygen/menu.py index 8c95ce3..e6a1156 100644 --- a/toxygen/menu.py +++ b/toxygen/menu.py @@ -269,11 +269,22 @@ class ProfileSettings(CenteredWidget): directory = QtGui.QFileDialog.getExistingDirectory(options=QtGui.QFileDialog.DontUseNativeDialog, dir=curr_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.export(directory) profile = Profile.get_instance() profile.export_history(directory) + ProfileHelper.get_instance().export_profile(directory, reply == QtGui.QMessageBox.Yes) def closeEvent(self, event): profile = Profile.get_instance() diff --git a/toxygen/profile.py b/toxygen/profile.py index cdaf19f..3b8c456 100644 --- a/toxygen/profile.py +++ b/toxygen/profile.py @@ -311,9 +311,12 @@ class Profile(contact.Contact, Singleton): Send typing notification to a friend """ if Settings.get_instance()['typing_notifications'] and self._active_friend + 1: - friend = self._friends[self._active_friend] - if friend.status is not None: - self._tox.self_set_typing(friend.number, typing) + try: + friend = self._friends[self._active_friend] + if friend.status is not None: + self._tox.self_set_typing(friend.number, typing) + except: + pass def friend_typing(self, friend_number, typing): """ diff --git a/toxygen/settings.py b/toxygen/settings.py index 770f848..cb54947 100644 --- a/toxygen/settings.py +++ b/toxygen/settings.py @@ -1,8 +1,7 @@ from platform import system import json import os -import locale -from util import Singleton, curr_directory, log +from util import Singleton, curr_directory, log, copy import pyaudio from toxencryptsave import ToxEncryptSave import smileys @@ -202,6 +201,9 @@ class Settings(dict, Singleton): with open(path + str(self.name) + '.json', 'w') as fl: fl.write(text) + def update_path(self): + self.path = ProfileHelper.get_path() + self.name + '.json' + @staticmethod def get_default_path(): if system() == 'Windows': @@ -244,13 +246,18 @@ class ProfileHelper(Singleton): fl.write(data) print('Profile saved successfully') - def export_profile(self, new_path): - new_path += os.path.basename(self._path) + def export_profile(self, new_path, use_new_path): + path = new_path + os.path.basename(self._path) with open(self._path, 'rb') as fin: data = fin.read() - with open(new_path, 'wb') as fout: + with open(path, 'wb') as fout: fout.write(data) 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 def find_profiles():