autoaccept of files added

This commit is contained in:
ingvar1995 2016-03-18 19:33:54 +03:00
parent 976a6c139d
commit ff8aeef8af
4 changed files with 71 additions and 25 deletions

View file

@ -288,38 +288,51 @@ class MainWindow(QtGui.QMainWindow):
def friend_right_click(self, pos):
item = self.friends_list.itemAt(pos)
num = self.friends_list.indexFromItem(item).row()
friend = Profile.get_instance().get_friend_by_number(num)
settings = Settings.get_instance()
allowed = friend.tox_id in settings['auto_accept_from_friends']
auto = 'Disallow auto accept' if allowed else 'Allow auto accept'
if item is not None:
self.listMenu = QtGui.QMenu()
set_alias_item = self.listMenu.addAction('Set alias')
clear_history_item = self.listMenu.addAction('Clear history')
copy_key_item = self.listMenu.addAction('Copy public key')
auto_accept_item = self.listMenu.addAction(auto)
remove_item = self.listMenu.addAction('Remove friend')
self.connect(set_alias_item, QtCore.SIGNAL("triggered()"), lambda: self.set_alias(item))
self.connect(remove_item, QtCore.SIGNAL("triggered()"), lambda: self.remove_friend(item))
self.connect(copy_key_item, QtCore.SIGNAL("triggered()"), lambda: self.copy_friend_key(item))
self.connect(clear_history_item, QtCore.SIGNAL("triggered()"), lambda: self.clear_history(item))
self.connect(set_alias_item, QtCore.SIGNAL("triggered()"), lambda: self.set_alias(num))
self.connect(remove_item, QtCore.SIGNAL("triggered()"), lambda: self.remove_friend(num))
self.connect(copy_key_item, QtCore.SIGNAL("triggered()"), lambda: self.copy_friend_key(num))
self.connect(clear_history_item, QtCore.SIGNAL("triggered()"), lambda: self.clear_history(num))
self.connect(auto_accept_item, QtCore.SIGNAL("triggered()"), lambda: self.auto_accept(num, not allowed))
parent_position = self.friends_list.mapToGlobal(QtCore.QPoint(0, 0))
self.listMenu.move(parent_position + pos)
self.listMenu.show()
def set_alias(self, item):
num = self.friends_list.indexFromItem(item).row()
def set_alias(self, num):
self.profile.set_alias(num)
def remove_friend(self, item):
num = self.friends_list.indexFromItem(item).row()
def remove_friend(self, num):
self.profile.delete_friend(num)
def copy_friend_key(self, item):
num = self.friends_list.indexFromItem(item).row()
def copy_friend_key(self, num):
tox_id = self.profile.friend_public_key(num)
clipboard = QtGui.QApplication.clipboard()
clipboard.setText(tox_id)
def clear_history(self, item):
num = self.friends_list.indexFromItem(item).row()
def clear_history(self, num):
self.profile.clear_history(num)
def auto_accept(self, num, value):
settings = Settings.get_instance()
tox_id = self.profile.friend_public_key(num)
if value:
settings['auto_accept_from_friends'].append(tox_id)
else:
index = settings['auto_accept_from_friends'].index(tox_id)
del settings['auto_accept_from_friends'][index]
settings.save()
# -----------------------------------------------------------------------------------------------------------------
# Functions which called when user click somewhere else
# -----------------------------------------------------------------------------------------------------------------

View file

@ -1,7 +1,7 @@
from PySide import QtCore, QtGui
from settings import Settings
from profile import Profile, ProfileHelper
from util import get_style
from util import get_style, curr_directory
class CenteredWidget(QtGui.QWidget):
@ -174,11 +174,12 @@ class ProfileSettings(CenteredWidget):
def export_profile(self):
directory = QtGui.QFileDialog.getExistingDirectory() + '/'
ProfileHelper.export_profile(directory)
settings = Settings.get_instance()
settings.export(directory)
profile = Profile.get_instance()
profile.export_history(directory)
if directory != '/':
ProfileHelper.export_profile(directory)
settings = Settings.get_instance()
settings.export(directory)
profile = Profile.get_instance()
profile.export_history(directory)
def closeEvent(self, event):
profile = Profile.get_instance()
@ -275,22 +276,30 @@ class PrivacySettings(CenteredWidget):
self.fileautoaccept.setGeometry(QtCore.QRect(40, 60, 271, 22))
self.fileautoaccept.setObjectName("fileautoaccept")
self.typingNotifications = QtGui.QCheckBox(self)
self.typingNotifications.setGeometry(QtCore.QRect(40, 90, 350, 31))
self.typingNotifications.setBaseSize(QtCore.QSize(350, 200))
self.typingNotifications.setGeometry(QtCore.QRect(40, 90, 350, 30))
self.typingNotifications.setObjectName("typingNotifications")
self.auto_path = QtGui.QLabel(self)
self.auto_path.setGeometry(QtCore.QRect(40, 120, 350, 30))
self.path = QtGui.QPlainTextEdit(self)
self.path.setGeometry(QtCore.QRect(10, 160, 330, 30))
self.change_path = QtGui.QPushButton(self)
self.change_path.setGeometry(QtCore.QRect(230, 120, 100, 30))
self.retranslateUi()
settings = Settings.get_instance()
self.typingNotifications.setChecked(settings['typing_notifications'])
self.fileautoaccept.setChecked(settings['allow_auto_accept'])
self.saveHistory.setChecked(settings['save_history'])
self.path.setPlainText(settings['auto_accept_path'] or curr_directory())
self.change_path.clicked.connect(self.new_path)
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
self.setWindowTitle(QtGui.QApplication.translate("privacySettings", "Privacy settings", None, QtGui.QApplication.UnicodeUTF8))
self.saveHistory.setText(QtGui.QApplication.translate("privacySettings", "Save chat history", None, QtGui.QApplication.UnicodeUTF8))
self.fileautoaccept.setText(QtGui.QApplication.translate("privacySettings", "Allow file autoaccept", None, QtGui.QApplication.UnicodeUTF8))
self.fileautoaccept.setText(QtGui.QApplication.translate("privacySettings", "Allow file auto accept", None, QtGui.QApplication.UnicodeUTF8))
self.typingNotifications.setText(QtGui.QApplication.translate("privacySettings", "Send typing notifications", None, QtGui.QApplication.UnicodeUTF8))
self.auto_path.setText(QtGui.QApplication.translate("privacySettings", "Auto accept default path:", None, QtGui.QApplication.UnicodeUTF8))
self.change_path.setText(QtGui.QApplication.translate("privacySettings", "Change", None, QtGui.QApplication.UnicodeUTF8))
def closeEvent(self, event):
settings = Settings.get_instance()
@ -299,8 +308,14 @@ class PrivacySettings(CenteredWidget):
if settings['save_history'] and not self.saveHistory.isChecked(): # clear history
Profile.get_instance().clear_history()
settings['save_history'] = self.saveHistory.isChecked()
settings['auto_accept_path'] = self.path.toPlainText()
settings.save()
def new_path(self):
directory = QtGui.QFileDialog.getExistingDirectory() + '/'
if directory != '/':
self.path.setPlainText(directory)
class NotificationsSettings(CenteredWidget):
"""Notifications settings form"""

View file

@ -705,9 +705,16 @@ class Profile(Contact, Singleton):
# -----------------------------------------------------------------------------------------------------------------
def incoming_file_transfer(self, friend_number, file_number, size, file_name):
rt = ReceiveTransfer(Settings.get_default_path() + file_name, self._tox, friend_number, file_number)
self._file_transfers[(friend_number, file_number)] = rt
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME'])
settings = Settings.get_instance()
friend = self.get_friend_by_number(friend_number)
if settings['allow_auto_accept'] and friend.tox_id in settings['auto_accept_from_friends']:
path = settings['auto_accept_path'] or curr_directory()
rt = ReceiveTransfer(path + '/' + file_name, self._tox, friend_number, file_number)
self._file_transfers[(friend_number, file_number)] = rt
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME'])
else:
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL'])
# TODO: show info about incoming transfer
def incoming_avatar(self, friend_number, file_number, size):
"""
@ -748,6 +755,16 @@ class Profile(Contact, Singleton):
if transfer.state:
del self._file_transfers[(friend_number, file_number)]
def reset_avatar(self):
super(Profile, self).reset_avatar()
for friend in filter(lambda x: x.status is not None, self._friends):
self.send_avatar(friend.number)
def set_avatar(self, data):
super(Profile, self).set_avatar(data)
for friend in filter(lambda x: x.status is not None, self._friends):
self.send_avatar(friend.number)
def tox_factory(data=None, settings=None):
"""

View file

@ -53,6 +53,7 @@ class Settings(Singleton, dict):
'save_history': False,
'allow_inline': True,
'allow_auto_accept': False,
'auto_accept_path': None,
'show_online_friends': False,
'auto_accept_from_friends': [],
'friends_aliases': [],