Beispiel #1
0
class SetProfilePasswordScreen(CenteredWidget):

    def __init__(self, encrypt):
        super(SetProfilePasswordScreen, self).__init__()
        self._encrypt = encrypt
        self.initUI()
        self.retranslateUi()
        self.center()

    def initUI(self):
        self.setMinimumSize(QtCore.QSize(700, 200))
        self.setMaximumSize(QtCore.QSize(700, 200))
        self.password = LineEdit(self)
        self.password.setGeometry(QtCore.QRect(40, 10, 300, 30))
        self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
        self.confirm_password = LineEdit(self)
        self.confirm_password.setGeometry(QtCore.QRect(40, 50, 300, 30))
        self.confirm_password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
        self.set_password = QtGui.QPushButton(self)
        self.set_password.setGeometry(QtCore.QRect(40, 100, 300, 30))
        self.set_password.clicked.connect(self.new_password)
        self.not_match = QtGui.QLabel(self)
        self.not_match.setGeometry(QtCore.QRect(350, 50, 300, 30))
        self.not_match.setVisible(False)
        self.not_match.setStyleSheet('QLabel { color: #BC1C1C; }')
        self.warning = QtGui.QLabel(self)
        self.warning.setGeometry(QtCore.QRect(40, 160, 500, 30))
        self.warning.setStyleSheet('QLabel { color: #BC1C1C; }')

    def retranslateUi(self):
        self.setWindowTitle(QtGui.QApplication.translate("PasswordScreen", "Profile password", None,
                                                              QtGui.QApplication.UnicodeUTF8))
        self.password.setPlaceholderText(
            QtGui.QApplication.translate("PasswordScreen", "Password (at least 8 symbols)", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.confirm_password.setPlaceholderText(
            QtGui.QApplication.translate("PasswordScreen", "Confirm password", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.set_password.setText(
            QtGui.QApplication.translate("PasswordScreen", "Set password", None, QtGui.QApplication.UnicodeUTF8))
        self.not_match.setText(QtGui.QApplication.translate("PasswordScreen", "Passwords do not match", None,
                                                            QtGui.QApplication.UnicodeUTF8))
        self.warning.setText(
            QtGui.QApplication.translate("PasswordScreen", "There is no way to recover lost passwords", None,
                                         QtGui.QApplication.UnicodeUTF8))

    def new_password(self):
        if self.password.text() == self.confirm_password.text():
            if len(self.password.text()) >= 8:
                self._encrypt.set_password(self.password.text())
                self.close()
            else:
                self.not_match.setText(
                    QtGui.QApplication.translate("PasswordScreen", "Password must be at least 8 symbols", None,
                                                 QtGui.QApplication.UnicodeUTF8))
            self.not_match.setVisible(True)
        else:
            self.not_match.setText(QtGui.QApplication.translate("PasswordScreen", "Passwords do not match", None,
                                                                QtGui.QApplication.UnicodeUTF8))
            self.not_match.setVisible(True)
Beispiel #2
0
class SetProfilePasswordScreen(CenteredWidget):

    def __init__(self, encrypt):
        super(SetProfilePasswordScreen, self).__init__()
        self._encrypt = encrypt
        self.initUI()
        self.retranslateUi()
        self.center()

    def initUI(self):
        self.setMinimumSize(QtCore.QSize(700, 200))
        self.setMaximumSize(QtCore.QSize(700, 200))
        self.password = LineEdit(self)
        self.password.setGeometry(QtCore.QRect(40, 10, 300, 30))
        self.password.setEchoMode(QtWidgets.QLineEdit.Password)
        self.confirm_password = LineEdit(self)
        self.confirm_password.setGeometry(QtCore.QRect(40, 50, 300, 30))
        self.confirm_password.setEchoMode(QtWidgets.QLineEdit.Password)
        self.set_password = QtWidgets.QPushButton(self)
        self.set_password.setGeometry(QtCore.QRect(40, 100, 300, 30))
        self.set_password.clicked.connect(self.new_password)
        self.not_match = QtWidgets.QLabel(self)
        self.not_match.setGeometry(QtCore.QRect(350, 50, 300, 30))
        self.not_match.setVisible(False)
        self.not_match.setStyleSheet('QLabel { color: #BC1C1C; }')
        self.warning = QtWidgets.QLabel(self)
        self.warning.setGeometry(QtCore.QRect(40, 160, 500, 30))
        self.warning.setStyleSheet('QLabel { color: #BC1C1C; }')

    def retranslateUi(self):
        self.setWindowTitle(QtWidgets.QApplication.translate("PasswordScreen", "Profile password"))
        self.password.setPlaceholderText(
            QtWidgets.QApplication.translate("PasswordScreen", "Password (at least 8 symbols)"))
        self.confirm_password.setPlaceholderText(
            QtWidgets.QApplication.translate("PasswordScreen", "Confirm password"))
        self.set_password.setText(
            QtWidgets.QApplication.translate("PasswordScreen", "Set password"))
        self.not_match.setText(QtWidgets.QApplication.translate("PasswordScreen", "Passwords do not match"))
        self.warning.setText(
            QtWidgets.QApplication.translate("PasswordScreen", "There is no way to recover lost passwords"))

    def new_password(self):
        if self.password.text() == self.confirm_password.text():
            if len(self.password.text()) >= 8:
                self._encrypt.set_password(self.password.text())
                self.close()
            else:
                self.not_match.setText(
                    QtWidgets.QApplication.translate("PasswordScreen", "Password must be at least 8 symbols"))
            self.not_match.setVisible(True)
        else:
            self.not_match.setText(QtWidgets.QApplication.translate("PasswordScreen", "Passwords do not match"))
            self.not_match.setVisible(True)
class SearchScreen(QtGui.QWidget):
    def __init__(self, messages, width, *args):
        super().__init__(*args)
        self.setMaximumSize(width, 40)
        self.setMinimumSize(width, 40)
        self._messages = messages

        self.search_text = LineEdit(self)
        self.search_text.setGeometry(0, 0, width - 160, 40)

        self.search_button = ClickableLabel(self)
        self.search_button.setGeometry(width - 160, 0, 40, 40)
        pixmap = QtGui.QPixmap()
        pixmap.load(util.curr_directory() + '/images/search.png')
        self.search_button.setScaledContents(False)
        self.search_button.setAlignment(QtCore.Qt.AlignCenter)
        self.search_button.setPixmap(pixmap)
        self.connect(self.search_button, QtCore.SIGNAL('clicked()'),
                     self.search)

        font = QtGui.QFont()
        font.setPointSize(32)
        font.setBold(True)

        self.prev_button = QtGui.QPushButton(self)
        self.prev_button.setGeometry(width - 120, 0, 40, 40)
        self.prev_button.clicked.connect(self.prev)
        self.prev_button.setText('\u25B2')

        self.next_button = QtGui.QPushButton(self)
        self.next_button.setGeometry(width - 80, 0, 40, 40)
        self.next_button.clicked.connect(self.next)
        self.next_button.setText('\u25BC')

        self.close_button = QtGui.QPushButton(self)
        self.close_button.setGeometry(width - 40, 0, 40, 40)
        self.close_button.clicked.connect(self.close)
        self.close_button.setText('×')
        self.close_button.setFont(font)

        font.setPointSize(18)
        self.next_button.setFont(font)
        self.prev_button.setFont(font)

        self.retranslateUi()

    def retranslateUi(self):
        self.search_text.setPlaceholderText(
            QtGui.QApplication.translate("MainWindow", "Search", None,
                                         QtGui.QApplication.UnicodeUTF8))

    def show(self):
        super().show()
        self.search_text.setFocus()

    def search(self):
        Profile.get_instance().update()
        text = self.search_text.text()
        friend = Profile.get_instance().get_curr_friend()
        if text and friend and util.is_re_valid(text):
            index = friend.search_string(text)
            self.load_messages(index)

    def prev(self):
        friend = Profile.get_instance().get_curr_friend()
        if friend is not None:
            index = friend.search_prev()
            self.load_messages(index)

    def next(self):
        friend = Profile.get_instance().get_curr_friend()
        text = self.search_text.text()
        if friend is not None:
            index = friend.search_next()
            if index is not None:
                count = self._messages.count()
                index += count
                item = self._messages.item(index)
                self._messages.scrollToItem(item)
                self._messages.itemWidget(item).select_text(text)
            else:
                self.not_found(text)

    def load_messages(self, index):
        text = self.search_text.text()
        if index is not None:
            profile = Profile.get_instance()
            count = self._messages.count()
            while count + index < 0:
                profile.load_history()
                count = self._messages.count()
            index += count
            item = self._messages.item(index)
            self._messages.scrollToItem(item)
            self._messages.itemWidget(item).select_text(text)
        else:
            self.not_found(text)

    def closeEvent(self, *args):
        Profile.get_instance().update()
        self._messages.setGeometry(0, 0, self._messages.width(),
                                   self._messages.height() + 40)
        super().closeEvent(*args)

    @staticmethod
    def not_found(text):
        mbox = QtGui.QMessageBox()
        mbox_text = QtGui.QApplication.translate(
            "MainWindow", 'Text "{}" was not found', None,
            QtGui.QApplication.UnicodeUTF8)

        mbox.setText(mbox_text.format(text))
        mbox.setWindowTitle(
            QtGui.QApplication.translate("MainWindow", 'Not found', None,
                                         QtGui.QApplication.UnicodeUTF8))
        mbox.exec_()
Beispiel #4
0
class ProfileSettings(CenteredWidget):
    """Form with profile settings such as name, status, TOX ID"""
    def __init__(self):
        super(ProfileSettings, self).__init__()
        self.initUI()
        self.center()

    def initUI(self):
        self.setObjectName("ProfileSettingsForm")
        self.setMinimumSize(QtCore.QSize(700, 600))
        self.setMaximumSize(QtCore.QSize(700, 600))
        self.nick = LineEdit(self)
        self.nick.setGeometry(QtCore.QRect(30, 60, 350, 27))
        profile = Profile.get_instance()
        self.nick.setText(profile.name)
        self.status = QtGui.QComboBox(self)
        self.status.setGeometry(QtCore.QRect(400, 60, 200, 27))
        self.status_message = LineEdit(self)
        self.status_message.setGeometry(QtCore.QRect(30, 130, 350, 27))
        self.status_message.setText(profile.status_message)
        self.label = QtGui.QLabel(self)
        self.label.setGeometry(QtCore.QRect(40, 30, 91, 25))
        font = QtGui.QFont()
        font.setPointSize(18)
        font.setWeight(75)
        font.setBold(True)
        self.label.setFont(font)
        self.label_2 = QtGui.QLabel(self)
        self.label_2.setGeometry(QtCore.QRect(40, 100, 100, 25))
        self.label_2.setFont(font)
        self.label_3 = QtGui.QLabel(self)
        self.label_3.setGeometry(QtCore.QRect(40, 180, 100, 25))
        self.label_3.setFont(font)
        self.tox_id = QtGui.QLabel(self)
        self.tox_id.setGeometry(QtCore.QRect(15, 210, 685, 21))
        font.setPointSize(10)
        self.tox_id.setFont(font)
        s = profile.tox_id
        self.tox_id.setText(s)
        self.copyId = QtGui.QPushButton(self)
        self.copyId.setGeometry(QtCore.QRect(40, 250, 180, 30))
        self.copyId.clicked.connect(self.copy)
        self.export = QtGui.QPushButton(self)
        self.export.setGeometry(QtCore.QRect(230, 250, 180, 30))
        self.export.clicked.connect(self.export_profile)
        self.new_nospam = QtGui.QPushButton(self)
        self.new_nospam.setGeometry(QtCore.QRect(420, 250, 180, 30))
        self.new_nospam.clicked.connect(self.new_no_spam)

        self.new_avatar = QtGui.QPushButton(self)
        self.new_avatar.setGeometry(QtCore.QRect(40, 300, 180, 30))
        self.delete_avatar = QtGui.QPushButton(self)
        self.delete_avatar.setGeometry(QtCore.QRect(230, 300, 180, 30))
        self.delete_avatar.clicked.connect(self.reset_avatar)
        self.new_avatar.clicked.connect(self.set_avatar)
        self.profile_pass = QtGui.QLabel(self)
        self.profile_pass.setGeometry(QtCore.QRect(40, 340, 300, 30))
        font.setPointSize(18)
        self.profile_pass.setFont(font)
        self.password = LineEdit(self)
        self.password.setGeometry(QtCore.QRect(40, 380, 300, 30))
        self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
        self.leave_blank = QtGui.QLabel(self)
        self.leave_blank.setGeometry(QtCore.QRect(350, 380, 300, 30))
        self.confirm_password = LineEdit(self)
        self.confirm_password.setGeometry(QtCore.QRect(40, 420, 300, 30))
        self.confirm_password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
        self.set_password = QtGui.QPushButton(self)
        self.set_password.setGeometry(QtCore.QRect(40, 470, 300, 30))
        self.set_password.clicked.connect(self.new_password)
        self.not_match = QtGui.QLabel(self)
        self.not_match.setGeometry(QtCore.QRect(350, 420, 300, 30))
        self.not_match.setVisible(False)
        self.not_match.setStyleSheet('QLabel { color: #BC1C1C; }')
        self.warning = QtGui.QLabel(self)
        self.warning.setGeometry(QtCore.QRect(40, 510, 500, 30))
        self.warning.setStyleSheet('QLabel { color: #BC1C1C; }')
        self.default = QtGui.QPushButton(self)
        self.default.setGeometry(QtCore.QRect(40, 550, 620, 30))
        path, name = Settings.get_auto_profile()
        self.auto = path + name == ProfileHelper.get_path(
        ) + Settings.get_instance().name
        self.default.clicked.connect(self.auto_profile)
        self.retranslateUi()
        if profile.status is not None:
            self.status.setCurrentIndex(profile.status)
        else:
            self.status.setVisible(False)
        QtCore.QMetaObject.connectSlotsByName(self)

    def retranslateUi(self):
        self.export.setText(
            QtGui.QApplication.translate("ProfileSettingsForm",
                                         "Export profile", None,
                                         QtGui.QApplication.UnicodeUTF8))
        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))
        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))
        self.new_nospam.setText(
            QtGui.QApplication.translate("ProfileSettingsForm", "New NoSpam",
                                         None, QtGui.QApplication.UnicodeUTF8))
        self.profile_pass.setText(
            QtGui.QApplication.translate("ProfileSettingsForm",
                                         "Profile password", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.password.setPlaceholderText(
            QtGui.QApplication.translate("ProfileSettingsForm",
                                         "Password (at least 8 symbols)", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.confirm_password.setPlaceholderText(
            QtGui.QApplication.translate("ProfileSettingsForm",
                                         "Confirm password", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.set_password.setText(
            QtGui.QApplication.translate("ProfileSettingsForm", "Set password",
                                         None, QtGui.QApplication.UnicodeUTF8))
        self.not_match.setText(
            QtGui.QApplication.translate("ProfileSettingsForm",
                                         "Passwords do not match", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.leave_blank.setText(
            QtGui.QApplication.translate(
                "ProfileSettingsForm",
                "Leaving blank will reset current password", None,
                QtGui.QApplication.UnicodeUTF8))
        self.warning.setText(
            QtGui.QApplication.translate(
                "ProfileSettingsForm",
                "There is no way to recover lost passwords", None,
                QtGui.QApplication.UnicodeUTF8))
        self.status.addItem(
            QtGui.QApplication.translate("ProfileSettingsForm", "Online", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.status.addItem(
            QtGui.QApplication.translate("ProfileSettingsForm", "Away", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.status.addItem(
            QtGui.QApplication.translate("ProfileSettingsForm", "Busy", None,
                                         QtGui.QApplication.UnicodeUTF8))
        if self.auto:
            self.default.setText(
                QtGui.QApplication.translate("ProfileSettingsForm",
                                             "Mark as not default profile",
                                             None,
                                             QtGui.QApplication.UnicodeUTF8))
        else:
            self.default.setText(
                QtGui.QApplication.translate("ProfileSettingsForm",
                                             "Mark as default profile", None,
                                             QtGui.QApplication.UnicodeUTF8))

    def auto_profile(self):
        if self.auto:
            Settings.reset_auto_profile()
        else:
            Settings.set_auto_profile(ProfileHelper.get_path(),
                                      Settings.get_instance().name)
        self.auto = not self.auto
        if self.auto:
            self.default.setText(
                QtGui.QApplication.translate("ProfileSettingsForm",
                                             "Mark as not default profile",
                                             None,
                                             QtGui.QApplication.UnicodeUTF8))
        else:
            self.default.setText(
                QtGui.QApplication.translate("ProfileSettingsForm",
                                             "Mark as default profile", None,
                                             QtGui.QApplication.UnicodeUTF8))

    def new_password(self):
        if self.password.text() == self.confirm_password.text():
            if not len(self.password.text()) or len(self.password.text()) >= 8:
                e = toxencryptsave.LibToxEncryptSave.get_instance()
                e.set_password(self.password.text())
                self.close()
            else:
                self.not_match.setText(
                    QtGui.QApplication.translate(
                        "ProfileSettingsForm",
                        "Password must be at least 8 symbols", None,
                        QtGui.QApplication.UnicodeUTF8))
            self.not_match.setVisible(True)
        else:
            self.not_match.setText(
                QtGui.QApplication.translate("ProfileSettingsForm",
                                             "Passwords do not match", None,
                                             QtGui.QApplication.UnicodeUTF8))
            self.not_match.setVisible(True)

    def copy(self):
        clipboard = QtGui.QApplication.clipboard()
        profile = Profile.get_instance()
        clipboard.setText(profile.tox_id)
        pixmap = QtGui.QPixmap(curr_directory() + '/images/accept.png')
        icon = QtGui.QIcon(pixmap)
        self.copyId.setIcon(icon)
        self.copyId.setIconSize(QtCore.QSize(10, 10))

    def new_no_spam(self):
        self.tox_id.setText(Profile.get_instance().new_nospam())

    def reset_avatar(self):
        Profile.get_instance().reset_avatar()

    def set_avatar(self):
        choose = QtGui.QApplication.translate("ProfileSettingsForm",
                                              "Choose avatar", None,
                                              QtGui.QApplication.UnicodeUTF8)
        name = QtGui.QFileDialog.getOpenFileName(self, choose, None,
                                                 'Images (*.png)')
        if name[0]:
            bitmap = QtGui.QPixmap(name[0])
            bitmap.scaled(QtCore.QSize(128, 128),
                          aspectMode=QtCore.Qt.KeepAspectRatio,
                          mode=QtCore.Qt.SmoothTransformation)

            byte_array = QtCore.QByteArray()
            buffer = QtCore.QBuffer(byte_array)
            buffer.open(QtCore.QIODevice.WriteOnly)
            bitmap.save(buffer, 'PNG')
            Profile.get_instance().set_avatar(str(byte_array.data()))

    def export_profile(self):
        directory = QtGui.QFileDialog.getExistingDirectory() + '/'
        if directory != '/':
            ProfileHelper.get_instance().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())
        profile.set_status_message(self.status_message.text().encode('utf-8'))
        profile.set_status(self.status.currentIndex())
Beispiel #5
0
class AddContact(CenteredWidget):
    """Add contact form"""
    def __init__(self, tox_id=''):
        super(AddContact, self).__init__()
        self.initUI(tox_id)

    def initUI(self, tox_id):
        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")
        self.sendRequestButton.clicked.connect(self.add_friend)
        self.tox_id = LineEdit(self)
        self.tox_id.setGeometry(QtCore.QRect(50, 40, 471, 27))
        self.tox_id.setObjectName("lineEdit")
        self.tox_id.setText(tox_id)
        self.label = QtGui.QLabel(self)
        self.label.setGeometry(QtCore.QRect(50, 10, 80, 20))
        self.error_label = DataLabel(self)
        self.error_label.setGeometry(QtCore.QRect(120, 10, 420, 20))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setWeight(30)
        self.error_label.setFont(font)
        self.error_label.setStyleSheet("QLabel { color: #BC1C1C; }")
        self.label.setObjectName("label")
        self.message_edit = QtGui.QTextEdit(self)
        self.message_edit.setGeometry(QtCore.QRect(50, 110, 471, 151))
        self.message_edit.setObjectName("textEdit")
        self.message = QtGui.QLabel(self)
        self.message.setGeometry(QtCore.QRect(50, 70, 101, 31))
        self.message.setFont(font)
        self.message.setObjectName("label_2")
        self.retranslateUi()
        self.message_edit.setText('Hello! Add me to your contact list please')
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        self.label.setFont(font)
        self.message.setFont(font)
        QtCore.QMetaObject.connectSlotsByName(self)

    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
            self.error_label.setText(send)

    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.message.setText(
            QtGui.QApplication.translate('AddContact', "Message:", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.tox_id.setPlaceholderText(
            QtGui.QApplication.translate('AddContact',
                                         "TOX ID or public key of contact",
                                         None, QtGui.QApplication.UnicodeUTF8))
Beispiel #6
0
class ProfileSettings(CenteredWidget):
    """Form with profile settings such as name, status, TOX ID"""
    def __init__(self):
        super(ProfileSettings, self).__init__()
        self.initUI()
        self.center()

    def initUI(self):
        self.setObjectName("ProfileSettingsForm")
        self.setMinimumSize(QtCore.QSize(700, 600))
        self.setMaximumSize(QtCore.QSize(700, 600))
        self.nick = LineEdit(self)
        self.nick.setGeometry(QtCore.QRect(30, 60, 350, 27))
        profile = Profile.get_instance()
        self.nick.setText(profile.name)
        self.status = QtGui.QComboBox(self)
        self.status.setGeometry(QtCore.QRect(400, 60, 200, 27))
        self.status_message = LineEdit(self)
        self.status_message.setGeometry(QtCore.QRect(30, 130, 350, 27))
        self.status_message.setText(profile.status_message)
        self.label = QtGui.QLabel(self)
        self.label.setGeometry(QtCore.QRect(40, 30, 91, 25))
        font = QtGui.QFont()
        font.setPointSize(18)
        font.setWeight(75)
        font.setBold(True)
        self.label.setFont(font)
        self.label_2 = QtGui.QLabel(self)
        self.label_2.setGeometry(QtCore.QRect(40, 100, 100, 25))
        self.label_2.setFont(font)
        self.label_3 = QtGui.QLabel(self)
        self.label_3.setGeometry(QtCore.QRect(40, 180, 100, 25))
        self.label_3.setFont(font)
        self.tox_id = QtGui.QLabel(self)
        self.tox_id.setGeometry(QtCore.QRect(15, 210, 685, 21))
        font.setPointSize(10)
        self.tox_id.setFont(font)
        s = profile.tox_id
        self.tox_id.setText(s)
        self.copyId = QtGui.QPushButton(self)
        self.copyId.setGeometry(QtCore.QRect(40, 250, 180, 30))
        self.copyId.clicked.connect(self.copy)
        self.export = QtGui.QPushButton(self)
        self.export.setGeometry(QtCore.QRect(230, 250, 180, 30))
        self.export.clicked.connect(self.export_profile)
        self.new_nospam = QtGui.QPushButton(self)
        self.new_nospam.setGeometry(QtCore.QRect(420, 250, 180, 30))
        self.new_nospam.clicked.connect(self.new_no_spam)
        self.copy_pk = QtGui.QPushButton(self)
        self.copy_pk.setGeometry(QtCore.QRect(40, 300, 180, 30))
        self.copy_pk.clicked.connect(self.copy_public_key)
        self.new_avatar = QtGui.QPushButton(self)
        self.new_avatar.setGeometry(QtCore.QRect(230, 300, 180, 30))
        self.delete_avatar = QtGui.QPushButton(self)
        self.delete_avatar.setGeometry(QtCore.QRect(420, 300, 180, 30))
        self.delete_avatar.clicked.connect(self.reset_avatar)
        self.new_avatar.clicked.connect(self.set_avatar)
        self.profilepass = QtGui.QLabel(self)
        self.profilepass.setGeometry(QtCore.QRect(40, 340, 300, 30))
        font.setPointSize(18)
        self.profilepass.setFont(font)
        self.password = LineEdit(self)
        self.password.setGeometry(QtCore.QRect(40, 380, 300, 30))
        self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
        self.leave_blank = QtGui.QLabel(self)
        self.leave_blank.setGeometry(QtCore.QRect(350, 380, 300, 30))
        self.confirm_password = LineEdit(self)
        self.confirm_password.setGeometry(QtCore.QRect(40, 420, 300, 30))
        self.confirm_password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
        self.set_password = QtGui.QPushButton(self)
        self.set_password.setGeometry(QtCore.QRect(40, 470, 300, 30))
        self.set_password.clicked.connect(self.new_password)
        self.not_match = QtGui.QLabel(self)
        self.not_match.setGeometry(QtCore.QRect(350, 420, 300, 30))
        self.not_match.setVisible(False)
        self.not_match.setStyleSheet('QLabel { color: #BC1C1C; }')
        self.warning = QtGui.QLabel(self)
        self.warning.setGeometry(QtCore.QRect(40, 510, 500, 30))
        self.warning.setStyleSheet('QLabel { color: #BC1C1C; }')
        self.default = QtGui.QPushButton(self)
        self.default.setGeometry(QtCore.QRect(40, 550, 620, 30))
        path, name = Settings.get_auto_profile()
        self.auto = path + name == ProfileHelper.get_path() + Settings.get_instance().name
        self.default.clicked.connect(self.auto_profile)
        self.retranslateUi()
        if profile.status is not None:
            self.status.setCurrentIndex(profile.status)
        else:
            self.status.setVisible(False)
        QtCore.QMetaObject.connectSlotsByName(self)

    def retranslateUi(self):
        self.export.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Export profile", None, QtGui.QApplication.UnicodeUTF8))
        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))
        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))
        self.new_nospam.setText(QtGui.QApplication.translate("ProfileSettingsForm", "New NoSpam", None, QtGui.QApplication.UnicodeUTF8))
        self.profilepass.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Profile password", None, QtGui.QApplication.UnicodeUTF8))
        self.password.setPlaceholderText(QtGui.QApplication.translate("ProfileSettingsForm", "Password (at least 8 symbols)", None, QtGui.QApplication.UnicodeUTF8))
        self.confirm_password.setPlaceholderText(QtGui.QApplication.translate("ProfileSettingsForm", "Confirm password", None, QtGui.QApplication.UnicodeUTF8))
        self.set_password.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Set password", None, QtGui.QApplication.UnicodeUTF8))
        self.not_match.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Passwords do not match", None, QtGui.QApplication.UnicodeUTF8))
        self.leave_blank.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Leaving blank will reset current password", None, QtGui.QApplication.UnicodeUTF8))
        self.warning.setText(QtGui.QApplication.translate("ProfileSettingsForm", "There is no way to recover lost passwords", None, QtGui.QApplication.UnicodeUTF8))
        self.status.addItem(QtGui.QApplication.translate("ProfileSettingsForm", "Online", None, QtGui.QApplication.UnicodeUTF8))
        self.status.addItem(QtGui.QApplication.translate("ProfileSettingsForm", "Away", None, QtGui.QApplication.UnicodeUTF8))
        self.status.addItem(QtGui.QApplication.translate("ProfileSettingsForm", "Busy", None, QtGui.QApplication.UnicodeUTF8))
        self.copy_pk.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Copy public key", None, QtGui.QApplication.UnicodeUTF8))
        if self.auto:
            self.default.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Mark as not default profile", None, QtGui.QApplication.UnicodeUTF8))
        else:
            self.default.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Mark as default profile", None, QtGui.QApplication.UnicodeUTF8))

    def auto_profile(self):
        if self.auto:
            Settings.reset_auto_profile()
        else:
            Settings.set_auto_profile(ProfileHelper.get_path(), Settings.get_instance().name)
        self.auto = not self.auto
        if self.auto:
            self.default.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Mark as not default profile", None,
                                                              QtGui.QApplication.UnicodeUTF8))
        else:
            self.default.setText(
                QtGui.QApplication.translate("ProfileSettingsForm", "Mark as default profile", None,
                                             QtGui.QApplication.UnicodeUTF8))

    def new_password(self):
        if self.password.text() == self.confirm_password.text():
            if not len(self.password.text()) or len(self.password.text()) >= 8:
                e = toxencryptsave.ToxEncryptSave.get_instance()
                e.set_password(self.password.text())
                self.close()
            else:
                self.not_match.setText(
                    QtGui.QApplication.translate("ProfileSettingsForm", "Password must be at least 8 symbols", None,
                                                 QtGui.QApplication.UnicodeUTF8))
            self.not_match.setVisible(True)
        else:
            self.not_match.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Passwords do not match", None,
                                                                QtGui.QApplication.UnicodeUTF8))
            self.not_match.setVisible(True)

    def copy(self):
        clipboard = QtGui.QApplication.clipboard()
        profile = Profile.get_instance()
        clipboard.setText(profile.tox_id)
        pixmap = QtGui.QPixmap(curr_directory() + '/images/accept.png')
        icon = QtGui.QIcon(pixmap)
        self.copyId.setIcon(icon)
        self.copyId.setIconSize(QtCore.QSize(10, 10))

    def copy_public_key(self):
        clipboard = QtGui.QApplication.clipboard()
        profile = Profile.get_instance()
        clipboard.setText(profile.tox_id[:64])
        pixmap = QtGui.QPixmap(curr_directory() + '/images/accept.png')
        icon = QtGui.QIcon(pixmap)
        self.copy_pk.setIcon(icon)
        self.copy_pk.setIconSize(QtCore.QSize(10, 10))

    def new_no_spam(self):
        self.tox_id.setText(Profile.get_instance().new_nospam())

    def reset_avatar(self):
        Profile.get_instance().reset_avatar()

    def set_avatar(self):
        choose = QtGui.QApplication.translate("ProfileSettingsForm", "Choose avatar", None, QtGui.QApplication.UnicodeUTF8)
        name = QtGui.QFileDialog.getOpenFileName(self, choose, None, 'Images (*.png)',
                                                 options=QtGui.QFileDialog.DontUseNativeDialog)
        if name[0]:
            bitmap = QtGui.QPixmap(name[0])
            bitmap.scaled(QtCore.QSize(128, 128), aspectMode=QtCore.Qt.KeepAspectRatio,
                          mode=QtCore.Qt.SmoothTransformation)

            byte_array = QtCore.QByteArray()
            buffer = QtCore.QBuffer(byte_array)
            buffer.open(QtCore.QIODevice.WriteOnly)
            bitmap.save(buffer, 'PNG')
            Profile.get_instance().set_avatar(bytes(byte_array.data()))

    def export_profile(self):
        directory = QtGui.QFileDialog.getExistingDirectory(options=QtGui.QFileDialog.DontUseNativeDialog) + '/'
        if directory != '/':
            ProfileHelper.get_instance().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())
        profile.set_status_message(self.status_message.text().encode('utf-8'))
        profile.set_status(self.status.currentIndex())
Beispiel #7
0
class AddContact(CenteredWidget):
    """Add contact form"""

    def __init__(self, tox_id=''):
        super(AddContact, self).__init__()
        self.initUI(tox_id)
        self._adding = False

    def initUI(self, tox_id):
        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")
        self.sendRequestButton.clicked.connect(self.add_friend)
        self.tox_id = LineEdit(self)
        self.tox_id.setGeometry(QtCore.QRect(50, 40, 471, 27))
        self.tox_id.setObjectName("lineEdit")
        self.tox_id.setText(tox_id)
        self.label = QtGui.QLabel(self)
        self.label.setGeometry(QtCore.QRect(50, 10, 80, 20))
        self.error_label = DataLabel(self)
        self.error_label.setGeometry(QtCore.QRect(120, 10, 420, 20))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setWeight(30)
        self.error_label.setFont(font)
        self.error_label.setStyleSheet("QLabel { color: #BC1C1C; }")
        self.label.setObjectName("label")
        self.message_edit = QtGui.QTextEdit(self)
        self.message_edit.setGeometry(QtCore.QRect(50, 110, 471, 151))
        self.message_edit.setObjectName("textEdit")
        self.message = QtGui.QLabel(self)
        self.message.setGeometry(QtCore.QRect(50, 70, 101, 31))
        self.message.setFont(font)
        self.message.setObjectName("label_2")
        self.retranslateUi()
        self.message_edit.setText('Hello! Add me to your contact list please')
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        self.label.setFont(font)
        self.message.setFont(font)
        QtCore.QMetaObject.connectSlotsByName(self)

    def add_friend(self):
        if self._adding:
            return
        self._adding = True
        profile = Profile.get_instance()
        send = profile.send_friend_request(self.tox_id.text().strip(), self.message_edit.toPlainText())
        self._adding = False
        if send is True:
            # request was successful
            self.close()
        else:  # print error data
            self.error_label.setText(send)

    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.message.setText(QtGui.QApplication.translate('AddContact', "Message:", None, QtGui.QApplication.UnicodeUTF8))
        self.tox_id.setPlaceholderText(QtGui.QApplication.translate('AddContact', "TOX ID or public key of contact", None, QtGui.QApplication.UnicodeUTF8))
class SearchScreen(QtGui.QWidget):

    def __init__(self, messages, width, *args):
        super().__init__(*args)
        self.setMaximumSize(width, 40)
        self.setMinimumSize(width, 40)
        self._messages = messages

        self.search_text = LineEdit(self)
        self.search_text.setGeometry(0, 0, width - 160, 40)

        self.search_button = ClickableLabel(self)
        self.search_button.setGeometry(width - 160, 0, 40, 40)
        pixmap = QtGui.QPixmap()
        pixmap.load(util.curr_directory() + '/images/search.png')
        self.search_button.setScaledContents(False)
        self.search_button.setAlignment(QtCore.Qt.AlignCenter)
        self.search_button.setPixmap(pixmap)
        self.connect(self.search_button, QtCore.SIGNAL('clicked()'), self.search)

        font = QtGui.QFont()
        font.setPointSize(32)
        font.setBold(True)

        self.prev_button = QtGui.QPushButton(self)
        self.prev_button.setGeometry(width - 120, 0, 40, 40)
        self.prev_button.clicked.connect(self.prev)
        self.prev_button.setText('\u25B2')

        self.next_button = QtGui.QPushButton(self)
        self.next_button.setGeometry(width - 80, 0, 40, 40)
        self.next_button.clicked.connect(self.next)
        self.next_button.setText('\u25BC')

        self.close_button = QtGui.QPushButton(self)
        self.close_button.setGeometry(width - 40, 0, 40, 40)
        self.close_button.clicked.connect(self.close)
        self.close_button.setText('×')
        self.close_button.setFont(font)

        font.setPointSize(18)
        self.next_button.setFont(font)
        self.prev_button.setFont(font)

        self.retranslateUi()

    def retranslateUi(self):
        self.search_text.setPlaceholderText(QtGui.QApplication.translate("MainWindow", "Search", None,
                                                                         QtGui.QApplication.UnicodeUTF8))

    def show(self):
        super().show()
        self.search_text.setFocus()

    def search(self):
        Profile.get_instance().update()
        text = self.search_text.text()
        friend = Profile.get_instance().get_curr_friend()
        if text and friend and util.is_re_valid(text):
            index = friend.search_string(text)
            self.load_messages(index)

    def prev(self):
        friend = Profile.get_instance().get_curr_friend()
        if friend is not None:
            index = friend.search_prev()
            self.load_messages(index)

    def next(self):
        friend = Profile.get_instance().get_curr_friend()
        text = self.search_text.text()
        if friend is not None:
            index = friend.search_next()
            if index is not None:
                count = self._messages.count()
                index += count
                item = self._messages.item(index)
                self._messages.scrollToItem(item)
                self._messages.itemWidget(item).select_text(text)
            else:
                self.not_found(text)

    def load_messages(self, index):
        text = self.search_text.text()
        if index is not None:
            profile = Profile.get_instance()
            count = self._messages.count()
            while count + index < 0:
                profile.load_history()
                count = self._messages.count()
            index += count
            item = self._messages.item(index)
            self._messages.scrollToItem(item)
            self._messages.itemWidget(item).select_text(text)
        else:
            self.not_found(text)

    def closeEvent(self, *args):
        Profile.get_instance().update()
        self._messages.setGeometry(0, 0, self._messages.width(), self._messages.height() + 40)
        super().closeEvent(*args)

    @staticmethod
    def not_found(text):
        mbox = QtGui.QMessageBox()
        mbox_text = QtGui.QApplication.translate("MainWindow",
                                                 'Text "{}" was not found',
                                                 None,
                                                 QtGui.QApplication.UnicodeUTF8)

        mbox.setText(mbox_text.format(text))
        mbox.setWindowTitle(QtGui.QApplication.translate("MainWindow",
                                                         'Not found',
                                                         None,
                                                         QtGui.QApplication.UnicodeUTF8))
        mbox.exec_()