autoaccept of files added
This commit is contained in:
parent
976a6c139d
commit
ff8aeef8af
@ -288,38 +288,51 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
|
|
||||||
def friend_right_click(self, pos):
|
def friend_right_click(self, pos):
|
||||||
item = self.friends_list.itemAt(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:
|
if item is not None:
|
||||||
self.listMenu = QtGui.QMenu()
|
self.listMenu = QtGui.QMenu()
|
||||||
set_alias_item = self.listMenu.addAction('Set alias')
|
set_alias_item = self.listMenu.addAction('Set alias')
|
||||||
clear_history_item = self.listMenu.addAction('Clear history')
|
clear_history_item = self.listMenu.addAction('Clear history')
|
||||||
copy_key_item = self.listMenu.addAction('Copy public key')
|
copy_key_item = self.listMenu.addAction('Copy public key')
|
||||||
|
auto_accept_item = self.listMenu.addAction(auto)
|
||||||
remove_item = self.listMenu.addAction('Remove friend')
|
remove_item = self.listMenu.addAction('Remove friend')
|
||||||
self.connect(set_alias_item, QtCore.SIGNAL("triggered()"), lambda: self.set_alias(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(item))
|
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(item))
|
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(item))
|
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))
|
parent_position = self.friends_list.mapToGlobal(QtCore.QPoint(0, 0))
|
||||||
self.listMenu.move(parent_position + pos)
|
self.listMenu.move(parent_position + pos)
|
||||||
self.listMenu.show()
|
self.listMenu.show()
|
||||||
|
|
||||||
def set_alias(self, item):
|
def set_alias(self, num):
|
||||||
num = self.friends_list.indexFromItem(item).row()
|
|
||||||
self.profile.set_alias(num)
|
self.profile.set_alias(num)
|
||||||
|
|
||||||
def remove_friend(self, item):
|
def remove_friend(self, num):
|
||||||
num = self.friends_list.indexFromItem(item).row()
|
|
||||||
self.profile.delete_friend(num)
|
self.profile.delete_friend(num)
|
||||||
|
|
||||||
def copy_friend_key(self, item):
|
def copy_friend_key(self, num):
|
||||||
num = self.friends_list.indexFromItem(item).row()
|
|
||||||
tox_id = self.profile.friend_public_key(num)
|
tox_id = self.profile.friend_public_key(num)
|
||||||
clipboard = QtGui.QApplication.clipboard()
|
clipboard = QtGui.QApplication.clipboard()
|
||||||
clipboard.setText(tox_id)
|
clipboard.setText(tox_id)
|
||||||
|
|
||||||
def clear_history(self, item):
|
def clear_history(self, num):
|
||||||
num = self.friends_list.indexFromItem(item).row()
|
|
||||||
self.profile.clear_history(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
|
# Functions which called when user click somewhere else
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
35
src/menu.py
35
src/menu.py
@ -1,7 +1,7 @@
|
|||||||
from PySide import QtCore, QtGui
|
from PySide import QtCore, QtGui
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
from profile import Profile, ProfileHelper
|
from profile import Profile, ProfileHelper
|
||||||
from util import get_style
|
from util import get_style, curr_directory
|
||||||
|
|
||||||
|
|
||||||
class CenteredWidget(QtGui.QWidget):
|
class CenteredWidget(QtGui.QWidget):
|
||||||
@ -174,11 +174,12 @@ class ProfileSettings(CenteredWidget):
|
|||||||
|
|
||||||
def export_profile(self):
|
def export_profile(self):
|
||||||
directory = QtGui.QFileDialog.getExistingDirectory() + '/'
|
directory = QtGui.QFileDialog.getExistingDirectory() + '/'
|
||||||
ProfileHelper.export_profile(directory)
|
if directory != '/':
|
||||||
settings = Settings.get_instance()
|
ProfileHelper.export_profile(directory)
|
||||||
settings.export(directory)
|
settings = Settings.get_instance()
|
||||||
profile = Profile.get_instance()
|
settings.export(directory)
|
||||||
profile.export_history(directory)
|
profile = Profile.get_instance()
|
||||||
|
profile.export_history(directory)
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
@ -275,22 +276,30 @@ class PrivacySettings(CenteredWidget):
|
|||||||
self.fileautoaccept.setGeometry(QtCore.QRect(40, 60, 271, 22))
|
self.fileautoaccept.setGeometry(QtCore.QRect(40, 60, 271, 22))
|
||||||
self.fileautoaccept.setObjectName("fileautoaccept")
|
self.fileautoaccept.setObjectName("fileautoaccept")
|
||||||
self.typingNotifications = QtGui.QCheckBox(self)
|
self.typingNotifications = QtGui.QCheckBox(self)
|
||||||
self.typingNotifications.setGeometry(QtCore.QRect(40, 90, 350, 31))
|
self.typingNotifications.setGeometry(QtCore.QRect(40, 90, 350, 30))
|
||||||
self.typingNotifications.setBaseSize(QtCore.QSize(350, 200))
|
|
||||||
self.typingNotifications.setObjectName("typingNotifications")
|
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()
|
self.retranslateUi()
|
||||||
settings = Settings.get_instance()
|
settings = Settings.get_instance()
|
||||||
self.typingNotifications.setChecked(settings['typing_notifications'])
|
self.typingNotifications.setChecked(settings['typing_notifications'])
|
||||||
self.fileautoaccept.setChecked(settings['allow_auto_accept'])
|
self.fileautoaccept.setChecked(settings['allow_auto_accept'])
|
||||||
self.saveHistory.setChecked(settings['save_history'])
|
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)
|
QtCore.QMetaObject.connectSlotsByName(self)
|
||||||
|
|
||||||
def retranslateUi(self):
|
def retranslateUi(self):
|
||||||
self.setWindowTitle(QtGui.QApplication.translate("privacySettings", "Privacy settings", None, QtGui.QApplication.UnicodeUTF8))
|
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.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.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):
|
def closeEvent(self, event):
|
||||||
settings = Settings.get_instance()
|
settings = Settings.get_instance()
|
||||||
@ -299,8 +308,14 @@ class PrivacySettings(CenteredWidget):
|
|||||||
if settings['save_history'] and not self.saveHistory.isChecked(): # clear history
|
if settings['save_history'] and not self.saveHistory.isChecked(): # clear history
|
||||||
Profile.get_instance().clear_history()
|
Profile.get_instance().clear_history()
|
||||||
settings['save_history'] = self.saveHistory.isChecked()
|
settings['save_history'] = self.saveHistory.isChecked()
|
||||||
|
settings['auto_accept_path'] = self.path.toPlainText()
|
||||||
settings.save()
|
settings.save()
|
||||||
|
|
||||||
|
def new_path(self):
|
||||||
|
directory = QtGui.QFileDialog.getExistingDirectory() + '/'
|
||||||
|
if directory != '/':
|
||||||
|
self.path.setPlainText(directory)
|
||||||
|
|
||||||
|
|
||||||
class NotificationsSettings(CenteredWidget):
|
class NotificationsSettings(CenteredWidget):
|
||||||
"""Notifications settings form"""
|
"""Notifications settings form"""
|
||||||
|
@ -705,9 +705,16 @@ class Profile(Contact, Singleton):
|
|||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def incoming_file_transfer(self, friend_number, file_number, size, file_name):
|
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)
|
settings = Settings.get_instance()
|
||||||
self._file_transfers[(friend_number, file_number)] = rt
|
friend = self.get_friend_by_number(friend_number)
|
||||||
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME'])
|
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):
|
def incoming_avatar(self, friend_number, file_number, size):
|
||||||
"""
|
"""
|
||||||
@ -748,6 +755,16 @@ class Profile(Contact, Singleton):
|
|||||||
if transfer.state:
|
if transfer.state:
|
||||||
del self._file_transfers[(friend_number, file_number)]
|
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):
|
def tox_factory(data=None, settings=None):
|
||||||
"""
|
"""
|
||||||
|
@ -53,6 +53,7 @@ class Settings(Singleton, dict):
|
|||||||
'save_history': False,
|
'save_history': False,
|
||||||
'allow_inline': True,
|
'allow_inline': True,
|
||||||
'allow_auto_accept': False,
|
'allow_auto_accept': False,
|
||||||
|
'auto_accept_path': None,
|
||||||
'show_online_friends': False,
|
'show_online_friends': False,
|
||||||
'auto_accept_from_friends': [],
|
'auto_accept_from_friends': [],
|
||||||
'friends_aliases': [],
|
'friends_aliases': [],
|
||||||
|
Loading…
Reference in New Issue
Block a user