Exemplo n.º 1
0
    def slider_moved(self, val=None):
        """
        What to do, when the slider has been moved: check input fields and if the input is valid start the synchronisation
        between the two directories

        :param val:
        :return:
        """
        # user specified an new value for the slider
        if val and val == "off" or val == "Off":
            _value = 0
        elif val and val == "On" or val == "on":
            _value = 1
        # user did not specify a new value for the slider
        else:
            _value = self._slider.value()
        # stop synchronisation between the two directories
        if _value == 0:
            self._ui.core_ref.stop_sync()
            # unset the flag indicating that the synchronisation is running
            self._running = False
            # allow the user to modify settings again, now that the synchronisation has stopped
            self.unlock()
        # check if all the input needed to start the synchronisation is valid
        elif _value == 1:
            if self._input_clear is None or self._input_enc is None:
                self.ui.add_message("Geben sie für beide Ordner eine Pfad an")
                self._slider.setValue("Off")
                return
            if not self._verify_passwords():
                self._slider.setValue("Off")
                return
            # check if the passwords satisfy the security policy for passwords
            if not self._check_security_policy():
                self._settab_slider_slider.setValue("Off")
                return
            # check if the password is correct
            _user_pass = str(self._input_key1.text())
            if not self._ui.core_ref.is_password_correct(_user_pass):
                # password wrong
                self._ui.add_message(
                    self._tran.get_text('password_not_correct'))
                self._slider.setValue("Off")
                return
            # password correct -> delete messages claiming otherwise from the message area
            elif self._tran.get_text(
                    'password_not_correct') in self._ui.messages:
                self._ui.del_messages(
                    self._tran.get_text('password_not_correct'))
            # check if the directory paths are good
            _source = str(self._input_clear.text())
            _cloud = str(self._input_enc.text())
            if not os.path.exists(_source):
                # source directory path not good -> add message to message area
                self._ui.add_message(
                    self._tran.get_text('source_folder_not_exist'))
                self._slider.setValue("Off")
                return
            # source path correct -> delete message claiming otherwise from the message area
            elif self._tran.get_text(
                    'source_folder_not_exist') in self._ui.messages:
                self._ui.del_messages(
                    self._tran.get_text('source_folder_not_exist'))
            if not os.path.exists(_cloud):
                # cloud directory path not good -> add message to message area
                self._ui.add_message(
                    self._tran.get_text('cloud_folder_not_exist'))
                self._ui.slider.setValue("Off")
                return
            # cloud path correct -> delete message claiming otherwise from the message area
            elif self._tran.get_text(
                    'cloud_folder_not_exist') in self._ui.messages:
                self._ui.del_messages(
                    self._tran.get_text('cloud_folder_not_exist'))

            # all checks where successful -> start synchronisation
            self._thread = SyncThread(self._ui.core_ref, _source, _cloud,
                                      _user_pass)
            self._thread.start()
            # lock the ui, so that the user cannot change settings while the synchronisation is running
            self.lock()
            # set the flag indicating that the synchronisation is running
            self._running = True