toxygen/src/menu.py

409 lines
19 KiB
Python
Raw Normal View History

2016-02-19 16:04:53 +01:00
from PySide import QtCore, QtGui
2016-04-03 22:51:46 +02:00
from settings import *
from profile import Profile
2016-03-18 17:33:54 +01:00
from util import get_style, curr_directory
2016-02-19 16:04:53 +01:00
2016-03-11 12:37:45 +01:00
class CenteredWidget(QtGui.QWidget):
2016-04-03 22:51:46 +02:00
2016-03-11 12:37:45 +01:00
def __init__(self):
super(CenteredWidget, self).__init__()
self.center()
def center(self):
qr = self.frameGeometry()
cp = QtGui.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
class AddContact(CenteredWidget):
2016-02-19 17:04:01 +01:00
"""Add contact form"""
2016-02-19 16:04:53 +01:00
def __init__(self):
super(AddContact, self).__init__()
self.initUI()
def initUI(self):
self.setObjectName('AddContact')
self.resize(568, 306)
self.sendRequestButton = QtGui.QPushButton(self)
self.sendRequestButton.setGeometry(QtCore.QRect(50, 270, 471, 31))
self.sendRequestButton.setMinimumSize(QtCore.QSize(0, 0))
self.sendRequestButton.setBaseSize(QtCore.QSize(0, 0))
self.sendRequestButton.setObjectName("sendRequestButton")
2016-03-09 19:11:36 +01:00
self.sendRequestButton.clicked.connect(self.add_friend)
self.tox_id = QtGui.QLineEdit(self)
self.tox_id.setGeometry(QtCore.QRect(50, 40, 471, 27))
self.tox_id.setObjectName("lineEdit")
2016-02-19 16:04:53 +01:00
self.label = QtGui.QLabel(self)
2016-03-12 16:34:10 +01:00
self.label.setGeometry(QtCore.QRect(30, 10, 80, 20))
2016-03-09 19:11:36 +01:00
self.error_label = QtGui.QLabel(self)
self.error_label.setGeometry(QtCore.QRect(120, 10, 400, 20))
2016-02-19 16:04:53 +01:00
font = QtGui.QFont()
font.setPointSize(16)
font.setWeight(75)
font.setBold(True)
self.label.setFont(font)
2016-03-09 19:11:36 +01:00
font.setPointSize(12)
font.setBold(False)
font.setWeight(40)
self.error_label.setFont(font)
self.error_label.setStyleSheet("QLabel { color: red; }")
2016-02-19 16:04:53 +01:00
self.label.setObjectName("label")
2016-03-09 19:11:36 +01:00
self.message_edit = QtGui.QTextEdit(self)
self.message_edit.setGeometry(QtCore.QRect(50, 110, 471, 151))
self.message_edit.setObjectName("textEdit")
2016-02-19 16:04:53 +01:00
self.label_2 = QtGui.QLabel(self)
self.label_2.setGeometry(QtCore.QRect(60, 70, 101, 31))
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
2016-03-09 19:11:36 +01:00
def add_friend(self):
profile = Profile.get_instance()
send = profile.send_friend_request(self.tox_id.text(), self.message_edit.toPlainText())
if send is True:
# request was successful
self.close()
else: # print error data
2016-03-12 16:34:10 +01:00
if len(send) > 40:
send = send[:40] + '...'
2016-03-09 19:11:36 +01:00
self.error_label.setText(send)
2016-02-19 16:04:53 +01:00
def retranslateUi(self):
self.setWindowTitle(QtGui.QApplication.translate('AddContact', "Add contact", None, QtGui.QApplication.UnicodeUTF8))
self.sendRequestButton.setText(QtGui.QApplication.translate("Form", "Send request", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate('AddContact', "TOX ID:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate('AddContact', "Message:", None, QtGui.QApplication.UnicodeUTF8))
2016-02-19 17:04:01 +01:00
2016-03-11 12:37:45 +01:00
class ProfileSettings(CenteredWidget):
2016-02-19 17:04:01 +01:00
"""Form with profile settings such as name, status, TOX ID"""
def __init__(self):
2016-02-19 17:04:01 +01:00
super(ProfileSettings, self).__init__()
self.initUI()
def initUI(self):
self.setObjectName("ProfileSettingsForm")
2016-03-11 12:37:45 +01:00
self.setMinimumSize(QtCore.QSize(650, 400))
self.setMaximumSize(QtCore.QSize(650, 400))
2016-02-19 17:04:01 +01:00
self.nick = QtGui.QLineEdit(self)
self.nick.setGeometry(QtCore.QRect(30, 60, 351, 27))
self.nick.setObjectName("nick")
profile = Profile.get_instance()
self.nick.setText(profile.name)
2016-02-19 17:04:01 +01:00
self.status = QtGui.QLineEdit(self)
self.status.setGeometry(QtCore.QRect(30, 130, 351, 27))
self.status.setObjectName("status")
self.status.setText(profile.status_message)
2016-02-19 17:04:01 +01:00
self.label = QtGui.QLabel(self)
self.label.setGeometry(QtCore.QRect(50, 30, 91, 21))
font = QtGui.QFont()
font.setPointSize(18)
font.setWeight(75)
font.setBold(True)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtGui.QLabel(self)
2016-03-22 10:50:18 +01:00
self.label_2.setGeometry(QtCore.QRect(40, 100, 100, 21))
2016-02-19 17:04:01 +01:00
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.label_3 = QtGui.QLabel(self)
2016-03-22 10:50:18 +01:00
self.label_3.setGeometry(QtCore.QRect(40, 170, 100, 21))
2016-02-19 17:04:01 +01:00
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.tox_id = QtGui.QLabel(self)
2016-02-25 09:32:40 +01:00
self.tox_id.setGeometry(QtCore.QRect(10, 210, self.width(), 21))
font.setPointSize(10)
2016-02-19 17:04:01 +01:00
self.tox_id.setFont(font)
self.tox_id.setObjectName("tox_id")
s = profile.tox_id
2016-02-25 09:32:40 +01:00
self.tox_id.setText(s)
2016-02-19 17:04:01 +01:00
self.copyId = QtGui.QPushButton(self)
2016-03-22 10:50:18 +01:00
self.copyId.setGeometry(QtCore.QRect(40, 250, 150, 30))
2016-02-19 17:04:01 +01:00
self.copyId.setObjectName("copyId")
2016-02-25 09:32:40 +01:00
self.copyId.clicked.connect(self.copy)
self.export = QtGui.QPushButton(self)
2016-03-22 10:50:18 +01:00
self.export.setGeometry(QtCore.QRect(200, 250, 150, 30))
self.export.setObjectName("export")
self.export.clicked.connect(self.export_profile)
2016-03-30 19:33:42 +02:00
self.lang_choose = QtGui.QComboBox(self)
self.lang_choose.setGeometry(QtCore.QRect(30, 350, 211, 27))
self.lang_choose.setObjectName("comboBox")
self.lang_choose.addItem('English')
self.lang = QtGui.QLabel(self)
self.lang.setGeometry(QtCore.QRect(40, 310, 121, 31))
2016-02-19 17:04:01 +01:00
font.setPointSize(18)
2016-03-30 19:33:42 +02:00
self.lang.setFont(font)
2016-03-11 12:37:45 +01:00
self.new_avatar = QtGui.QPushButton(self)
self.new_avatar.setGeometry(QtCore.QRect(400, 50, 200, 50))
self.delete_avatar = QtGui.QPushButton(self)
2016-03-22 10:50:18 +01:00
self.delete_avatar.setGeometry(QtCore.QRect(400, 120, 200, 50))
2016-03-11 12:37:45 +01:00
self.delete_avatar.clicked.connect(self.reset_avatar)
self.new_avatar.clicked.connect(self.set_avatar)
2016-02-19 17:04:01 +01:00
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
self.export.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Export profile", None, QtGui.QApplication.UnicodeUTF8))
2016-02-19 17:04:01 +01:00
self.setWindowTitle(QtGui.QApplication.translate("ProfileSettingsForm", "Profile settings", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Name:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Status:", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("ProfileSettingsForm", "TOX ID:", None, QtGui.QApplication.UnicodeUTF8))
self.copyId.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Copy TOX ID", None, QtGui.QApplication.UnicodeUTF8))
2016-03-30 19:33:42 +02:00
self.lang.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Language:", None, QtGui.QApplication.UnicodeUTF8))
2016-03-11 12:37:45 +01:00
self.new_avatar.setText(QtGui.QApplication.translate("ProfileSettingsForm", "New avatar", None, QtGui.QApplication.UnicodeUTF8))
self.delete_avatar.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Reset avatar", None, QtGui.QApplication.UnicodeUTF8))
2016-02-19 17:04:01 +01:00
2016-02-25 09:32:40 +01:00
def copy(self):
clipboard = QtGui.QApplication.clipboard()
profile = Profile.get_instance()
clipboard.setText(profile.tox_id)
2016-02-25 09:32:40 +01:00
2016-03-11 12:37:45 +01:00
def reset_avatar(self):
Profile.get_instance().reset_avatar()
def set_avatar(self):
2016-03-16 21:12:51 +01:00
name = QtGui.QFileDialog.getOpenFileName(self, 'Open file', None, 'Image Files (*.png)')
2016-03-11 12:37:45 +01:00
print name
if name[0]:
with open(name[0], 'rb') as f:
data = f.read()
Profile.get_instance().set_avatar(data)
def export_profile(self):
2016-03-13 13:06:06 +01:00
directory = QtGui.QFileDialog.getExistingDirectory() + '/'
2016-03-18 17:33:54 +01:00
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()
profile.set_name(self.nick.text().encode('utf-8'))
profile.set_status_message(self.status.text().encode('utf-8'))
2016-02-19 17:04:01 +01:00
2016-03-11 12:37:45 +01:00
class NetworkSettings(CenteredWidget):
2016-02-19 17:04:01 +01:00
"""Network settings form: UDP, Ipv6 and proxy"""
2016-03-15 18:05:19 +01:00
def __init__(self, reset):
2016-02-19 17:04:01 +01:00
super(NetworkSettings, self).__init__()
2016-03-15 18:05:19 +01:00
self.reset = reset
2016-02-19 17:04:01 +01:00
self.initUI()
def initUI(self):
self.setObjectName("NetworkSettings")
self.resize(300, 300)
self.setMinimumSize(QtCore.QSize(300, 300))
self.setMaximumSize(QtCore.QSize(300, 300))
self.setBaseSize(QtCore.QSize(300, 300))
self.ipv = QtGui.QCheckBox(self)
self.ipv.setGeometry(QtCore.QRect(20, 10, 97, 22))
self.ipv.setObjectName("ipv")
self.udp = QtGui.QCheckBox(self)
self.udp.setGeometry(QtCore.QRect(20, 50, 97, 22))
self.udp.setObjectName("udp")
self.proxy = QtGui.QCheckBox(self)
self.proxy.setGeometry(QtCore.QRect(20, 90, 97, 22))
self.proxy.setObjectName("proxy")
self.proxyip = QtGui.QLineEdit(self)
self.proxyip.setGeometry(QtCore.QRect(40, 160, 231, 27))
self.proxyip.setObjectName("proxyip")
self.proxyport = QtGui.QLineEdit(self)
self.proxyport.setGeometry(QtCore.QRect(40, 220, 231, 27))
self.proxyport.setObjectName("proxyport")
self.label = QtGui.QLabel(self)
self.label.setGeometry(QtCore.QRect(40, 130, 66, 17))
self.label.setObjectName("label")
self.label_2 = QtGui.QLabel(self)
self.label_2.setGeometry(QtCore.QRect(40, 190, 66, 17))
self.label_2.setObjectName("label_2")
2016-03-13 17:14:17 +01:00
settings = Settings.get_instance()
self.ipv.setChecked(settings['ipv6_enabled'])
self.udp.setChecked(settings['udp_enabled'])
self.proxy.setChecked(settings['proxy_type'] != 0)
self.proxyip.setText(settings['proxy_host'])
self.proxyport.setText(unicode(settings['proxy_port']))
2016-02-19 17:04:01 +01:00
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
self.setWindowTitle(QtGui.QApplication.translate("NetworkSettings", "Network settings", None, QtGui.QApplication.UnicodeUTF8))
self.ipv.setText(QtGui.QApplication.translate("Form", "IPv6", None, QtGui.QApplication.UnicodeUTF8))
self.udp.setText(QtGui.QApplication.translate("Form", "UDP", None, QtGui.QApplication.UnicodeUTF8))
self.proxy.setText(QtGui.QApplication.translate("Form", "Proxy", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Form", "IP:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("Form", "Port:", None, QtGui.QApplication.UnicodeUTF8))
2016-03-13 17:14:17 +01:00
def closeEvent(self, *args, **kwargs):
settings = Settings.get_instance()
2016-03-14 20:30:51 +01:00
old_data = str(settings['ipv6_enabled']) + str(settings['udp_enabled']) + str(bool(settings['proxy_type']))
new_data = str(self.ipv.isChecked()) + str(self.udp.isChecked()) + str(self.proxy.isChecked())
changed = old_data != new_data
2016-03-16 17:06:15 +01:00
if self.proxy.isChecked() and (self.proxyip.text() != settings['proxy_host'] or self.proxyport.text() != unicode(settings['proxy_port'])):
2016-03-14 20:30:51 +01:00
changed = True
if changed:
settings['ipv6_enabled'] = self.ipv.isChecked()
settings['udp_enabled'] = self.udp.isChecked()
settings['proxy_type'] = int(self.proxy.isChecked())
settings['proxy_host'] = self.proxyip.text()
2016-03-15 18:05:19 +01:00
settings['proxy_port'] = int(self.proxyport.text())
2016-03-14 20:30:51 +01:00
settings.save()
# recreate tox instance
2016-03-15 18:05:19 +01:00
Profile.get_instance().reset(self.reset)
2016-03-13 17:14:17 +01:00
2016-02-19 17:04:01 +01:00
2016-03-11 12:37:45 +01:00
class PrivacySettings(CenteredWidget):
2016-02-20 21:50:10 +01:00
"""Privacy settings form: history, typing notifications"""
def __init__(self):
super(PrivacySettings, self).__init__()
self.initUI()
def initUI(self):
self.setObjectName("privacySettings")
self.resize(350, 200)
self.setMinimumSize(QtCore.QSize(350, 200))
self.setMaximumSize(QtCore.QSize(350, 200))
self.setBaseSize(QtCore.QSize(350, 200))
self.saveHistory = QtGui.QCheckBox(self)
self.saveHistory.setGeometry(QtCore.QRect(40, 20, 291, 22))
self.saveHistory.setObjectName("saveHistory")
self.fileautoaccept = QtGui.QCheckBox(self)
self.fileautoaccept.setGeometry(QtCore.QRect(40, 60, 271, 22))
self.fileautoaccept.setObjectName("fileautoaccept")
self.typingNotifications = QtGui.QCheckBox(self)
2016-03-18 17:33:54 +01:00
self.typingNotifications.setGeometry(QtCore.QRect(40, 90, 350, 30))
2016-02-20 21:50:10 +01:00
self.typingNotifications.setObjectName("typingNotifications")
2016-03-18 17:33:54 +01:00
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))
2016-02-20 21:50:10 +01:00
self.retranslateUi()
2016-03-03 20:19:09 +01:00
settings = Settings.get_instance()
self.typingNotifications.setChecked(settings['typing_notifications'])
self.fileautoaccept.setChecked(settings['allow_auto_accept'])
self.saveHistory.setChecked(settings['save_history'])
2016-03-18 17:33:54 +01:00
self.path.setPlainText(settings['auto_accept_path'] or curr_directory())
self.change_path.clicked.connect(self.new_path)
2016-02-20 21:50:10 +01:00
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))
2016-03-18 17:33:54 +01:00
self.fileautoaccept.setText(QtGui.QApplication.translate("privacySettings", "Allow file auto accept", None, QtGui.QApplication.UnicodeUTF8))
2016-02-20 21:50:10 +01:00
self.typingNotifications.setText(QtGui.QApplication.translate("privacySettings", "Send typing notifications", None, QtGui.QApplication.UnicodeUTF8))
2016-03-18 17:33:54 +01:00
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))
2016-02-20 21:50:10 +01:00
def closeEvent(self, event):
2016-03-03 20:19:09 +01:00
settings = Settings.get_instance()
settings['typing_notifications'] = self.typingNotifications.isChecked()
settings['allow_auto_accept'] = self.fileautoaccept.isChecked()
2016-03-13 17:14:17 +01:00
if settings['save_history'] and not self.saveHistory.isChecked(): # clear history
2016-03-12 21:18:13 +01:00
Profile.get_instance().clear_history()
settings['save_history'] = self.saveHistory.isChecked()
2016-03-18 17:33:54 +01:00
settings['auto_accept_path'] = self.path.toPlainText()
settings.save()
2016-03-18 17:33:54 +01:00
def new_path(self):
directory = QtGui.QFileDialog.getExistingDirectory() + '/'
if directory != '/':
self.path.setPlainText(directory)
2016-02-20 21:50:10 +01:00
2016-03-11 12:37:45 +01:00
class NotificationsSettings(CenteredWidget):
2016-02-20 21:50:10 +01:00
"""Notifications settings form"""
def __init__(self):
super(NotificationsSettings, self).__init__()
self.initUI()
def initUI(self):
self.setObjectName("notificationsForm")
self.resize(300, 200)
self.setMinimumSize(QtCore.QSize(300, 200))
self.setMaximumSize(QtCore.QSize(300, 200))
self.setBaseSize(QtCore.QSize(300, 200))
self.enableNotifications = QtGui.QCheckBox(self)
self.enableNotifications.setGeometry(QtCore.QRect(30, 20, 241, 22))
self.enableNotifications.setObjectName("enableNotifications")
2016-02-25 12:22:15 +01:00
self.soundNotifications = QtGui.QCheckBox(self)
self.soundNotifications.setGeometry(QtCore.QRect(30, 100, 231, 22))
self.soundNotifications.setObjectName("sound_notifications")
2016-02-25 12:22:15 +01:00
self.callsSound = QtGui.QCheckBox(self)
self.callsSound.setGeometry(QtCore.QRect(30, 60, 231, 22))
self.callsSound.setObjectName("calls_sound")
2016-03-03 20:19:09 +01:00
s = Settings.get_instance()
2016-02-25 12:22:15 +01:00
self.enableNotifications.setChecked(s['notifications'])
self.soundNotifications.setChecked(s['sound_notifications'])
self.callsSound.setChecked(s['calls_sound'])
2016-02-20 21:50:10 +01:00
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
self.setWindowTitle(QtGui.QApplication.translate("notificationsForm", "Notification settings", None, QtGui.QApplication.UnicodeUTF8))
self.enableNotifications.setText(QtGui.QApplication.translate("notificationsForm", "Enable notifications", None, QtGui.QApplication.UnicodeUTF8))
self.callsSound.setText(QtGui.QApplication.translate("notificationsForm", "Enable call\'s sound", None, QtGui.QApplication.UnicodeUTF8))
self.soundNotifications.setText(QtGui.QApplication.translate("notificationsForm", "Enable sound notifications", None, QtGui.QApplication.UnicodeUTF8))
2016-02-25 12:22:15 +01:00
def closeEvent(self, *args, **kwargs):
2016-03-03 20:19:09 +01:00
settings = Settings.get_instance()
2016-02-25 12:22:15 +01:00
settings['notifications'] = self.enableNotifications.isChecked()
settings['sound_notifications'] = self.soundNotifications.isChecked()
settings['calls_sound'] = self.callsSound.isChecked()
settings.save()
2016-02-20 21:50:10 +01:00
2016-03-11 12:37:45 +01:00
class InterfaceSettings(CenteredWidget):
2016-02-20 21:50:10 +01:00
"""Interface settings form"""
def __init__(self):
super(InterfaceSettings, self).__init__()
self.initUI()
def initUI(self):
self.setObjectName("interfaceForm")
self.resize(300, 300)
self.setMinimumSize(QtCore.QSize(300, 300))
self.setMaximumSize(QtCore.QSize(300, 300))
self.setBaseSize(QtCore.QSize(300, 300))
self.label = QtGui.QLabel(self)
self.label.setGeometry(QtCore.QRect(30, 20, 91, 21))
font = QtGui.QFont()
font.setPointSize(16)
font.setWeight(75)
font.setBold(True)
self.label.setFont(font)
self.label.setObjectName("label")
self.themeSelect = QtGui.QComboBox(self)
self.themeSelect.setGeometry(QtCore.QRect(30, 60, 161, 31))
font = QtGui.QFont()
font.setPointSize(17)
self.themeSelect.setFont(font)
self.themeSelect.setObjectName("themeSelect")
list_of_themes = ['default', 'windows', 'gtk', 'cde', 'plastique', 'motif']
self.themeSelect.addItems(list_of_themes)
2016-03-03 20:19:09 +01:00
theme = Settings.get_instance()['theme']
index = list_of_themes.index(theme)
self.themeSelect.setCurrentIndex(index)
2016-02-20 21:50:10 +01:00
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
self.setWindowTitle(QtGui.QApplication.translate("interfaceForm", "Interface settings", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("interfaceForm", "Theme:", None, QtGui.QApplication.UnicodeUTF8))
def closeEvent(self, event):
2016-03-03 20:19:09 +01:00
settings = Settings.get_instance()
style = str(self.themeSelect.currentText())
settings['theme'] = style
settings.save()
QtGui.QApplication.setStyle(get_style(style))