예제 #1
0
    def __init__(self, email, password, computer_id):
        QDialog.__init__(self)
        Ui_RestoreDialog.__init__(self)
        self.setupUi(self)

        self.email = email
        self.password = password
        self.computer_id = computer_id
        self.logger = get_logger()

        self.setWindowIcon(QIcon(LOGO_PATH))

        self.snapshot_tree_widget = QLazyTreeWidget()
        self.snapshot_tree_layout.addWidget(self.snapshot_tree_widget)

        self.snapshots_combo_box.currentTextChanged.connect(
            self.load_current_snapshot)
        self.restore_button.pressed.connect(self.restore)

        self.set_elements_enabled(False)
        self.setWindowTitle("Loading Backups. Please Wait...")
        self.snapshots_combo_box.clear()
        self.snapshots_thread = SnapshotsThread(email, password, computer_id)
        self.snapshots_thread.loaded.connect(self.snapshots_loaded)
        self.snapshots_thread.start()

        self.reset_loading_backup_dialog()
        self.restoring_dialog = LoadingDialog(
            self,
            "Restoring. Please Wait...",
        )

        self.logger.info("Restore dialog displayed.")
예제 #2
0
class ChangePasswordDialog(QDialog, Ui_ChangePasswordDialog):
    def __init__(self, email=None):
        QDialog.__init__(self)
        Ui_ChangePasswordDialog.__init__(self)
        self.setupUi(self)

        self.setWindowIcon(QIcon(LOGO_PATH))
        self.logger = get_logger()
        self.loading_dialog = LoadingDialog(
            self,
            "Changing Password. Please Wait...",
            "We're changing the password on your account and your backups. This might take a minute. Thanks for your patience :-)",
        )
        self.change_password_button.pressed.connect(self.change_password)

        if email:
            self.email_line_edit.setText(email)
            self.email_line_edit.setReadOnly(True)

        self.logger.info("Change password dialog displayed.")

    def change_password(self):
        self.set_elements_enabled(False)
        self.loading_dialog.show()
        self.change_password_thread = ChangePasswordThread(
            self.email_line_edit.text().strip(),
            self.password_line_edit.text().strip(),
            self.new_password_line_edit.text().strip(),
            self.confirm_new_password_line_edit.text().strip(),
        )
        self.change_password_thread.finished.connect(self.accept)
        self.change_password_thread.start()

    def accept(self, success, message):
        self.set_elements_enabled(True)
        self.loading_dialog.hide()
        if not success:
            QMessageBox.warning(self, "Change Password Failed", message)
            self.logger.info("Change password failed displayed")
            return
        self.logger.info("Changed password")
        QMessageBox.information(self, "Password Changed",
                                "Password successfully changed.")
        super().accept()

    def set_elements_enabled(self, value):
        self.email_line_edit.setEnabled(value)
        self.password_line_edit.setEnabled(value)
        self.new_password_line_edit.setEnabled(value)
        self.confirm_new_password_line_edit.setEnabled(value)
        self.change_password_button.setEnabled(value)
예제 #3
0
    def __init__(
        self,
        reauth=False,
        show_register_button=True,
        title="Sign In - Blobbackup",
        heading=None,
        sign_in_button_text=None,
        email=None,
    ):
        QDialog.__init__(self)
        Ui_LoginDialog.__init__(self)

        self.email = None
        self.password = None
        self.reauth = reauth
        self.title = title
        self.logger = get_logger()
        self.loading_dialog = LoadingDialog(
            self,
            "Re-authenticating. This might take a moment...",
        )

        self.setupUi(self)

        if not is_prod():
            self.title = self.title + " (Test)"

        self.setWindowIcon(QIcon(LOGO_PATH))
        self.setWindowTitle(self.title)

        self.logo_label.setPixmap(get_pixmap(LOGO_PATH, 32, 32))

        self.register_button.setVisible(show_register_button)
        self.register_button.linkActivated.connect(
            lambda: webbrowser.open(REGISTER_URL))

        self.change_password_button.setVisible(show_register_button)
        self.change_password_button.linkActivated.connect(self.change_password)

        self.sign_in_button.pressed.connect(self.login)
        if sign_in_button_text:
            self.sign_in_button.setText(sign_in_button_text)

        if heading:
            self.heading_label.setText(heading)
        if email:
            self.email_line_edit.setText(email)
            self.email_line_edit.setReadOnly(True)
            self.password_line_edit.setFocus()

        self.logger.info("Login dialog displayed.")
예제 #4
0
 def reset_loading_backup_dialog(self):
     title = "Loading File Tree. Please Wait..."
     message = None
     if not restic_cache_ready():
         title = "Retrieving Backups. Please Wait..."
         message = "We're retrieving your backups for the first time on this computer. Depending on your backup size and internet speed, this may take up to an hour. Thanks for your patience :-)"
     self.loading_backup_dialog = LoadingDialog(self, title, message)
예제 #5
0
    def __init__(self, email=None):
        QDialog.__init__(self)
        Ui_ChangePasswordDialog.__init__(self)
        self.setupUi(self)

        self.setWindowIcon(QIcon(LOGO_PATH))
        self.logger = get_logger()
        self.loading_dialog = LoadingDialog(
            self,
            "Changing Password. Please Wait...",
            "We're changing the password on your account and your backups. This might take a minute. Thanks for your patience :-)",
        )
        self.change_password_button.pressed.connect(self.change_password)

        if email:
            self.email_line_edit.setText(email)
            self.email_line_edit.setReadOnly(True)

        self.logger.info("Change password dialog displayed.")
예제 #6
0
class LoginDialog(QDialog, Ui_LoginDialog):
    def __init__(
        self,
        reauth=False,
        show_register_button=True,
        title="Sign In - Blobbackup",
        heading=None,
        sign_in_button_text=None,
        email=None,
    ):
        QDialog.__init__(self)
        Ui_LoginDialog.__init__(self)

        self.email = None
        self.password = None
        self.reauth = reauth
        self.title = title
        self.logger = get_logger()
        self.loading_dialog = LoadingDialog(
            self,
            "Re-authenticating. This might take a moment...",
        )

        self.setupUi(self)

        if not is_prod():
            self.title = self.title + " (Test)"

        self.setWindowIcon(QIcon(LOGO_PATH))
        self.setWindowTitle(self.title)

        self.logo_label.setPixmap(get_pixmap(LOGO_PATH, 32, 32))

        self.register_button.setVisible(show_register_button)
        self.register_button.linkActivated.connect(
            lambda: webbrowser.open(REGISTER_URL))

        self.change_password_button.setVisible(show_register_button)
        self.change_password_button.linkActivated.connect(self.change_password)

        self.sign_in_button.pressed.connect(self.login)
        if sign_in_button_text:
            self.sign_in_button.setText(sign_in_button_text)

        if heading:
            self.heading_label.setText(heading)
        if email:
            self.email_line_edit.setText(email)
            self.email_line_edit.setReadOnly(True)
            self.password_line_edit.setFocus()

        self.logger.info("Login dialog displayed.")

    def login(self):
        self.set_elements_enabled(False)
        if self.reauth:
            self.loading_dialog.show()
        self.setWindowTitle("Signing In. Please Wait...")
        self.email = self.email_line_edit.text().strip()
        self.password = self.password_line_edit.text().strip()
        self.login_thread = LoginThread(self.email, self.password, self.reauth)
        self.login_thread.trial_over.connect(self.show_trial_over_and_die)
        self.login_thread.finished.connect(self.accept)
        self.login_thread.start()

    def show_trial_over_and_die(self):
        QMessageBox.information(
            self,
            "Trial Over",
            "Your trial period is over. Please purchase Blobbackup to continue using it.",
        )
        self.logger.info("Trial over displayed.")
        webbrowser.open(PAYMENT_URL)
        sys.exit()

    def change_password(self):
        dialog = ChangePasswordDialog()
        dialog.exec()

    def accept(self, success):
        self.setWindowTitle(self.title)
        if self.reauth:
            self.loading_dialog.hide()
        self.set_elements_enabled(True)
        if not success:
            QMessageBox.warning(self, "Sign In Failed", "Invalid credentials.")
            self.logger.info("Login failed displayed")
            return
        self.logger.info("Login succeded")
        super().accept()

    def set_elements_enabled(self, value):
        self.email_line_edit.setEnabled(value)
        self.password_line_edit.setEnabled(value)
        self.sign_in_button.setEnabled(value)
예제 #7
0
class RestoreDialog(QDialog, Ui_RestoreDialog):
    def __init__(self, email, password, computer_id):
        QDialog.__init__(self)
        Ui_RestoreDialog.__init__(self)
        self.setupUi(self)

        self.email = email
        self.password = password
        self.computer_id = computer_id
        self.logger = get_logger()

        self.setWindowIcon(QIcon(LOGO_PATH))

        self.snapshot_tree_widget = QLazyTreeWidget()
        self.snapshot_tree_layout.addWidget(self.snapshot_tree_widget)

        self.snapshots_combo_box.currentTextChanged.connect(
            self.load_current_snapshot)
        self.restore_button.pressed.connect(self.restore)

        self.set_elements_enabled(False)
        self.setWindowTitle("Loading Backups. Please Wait...")
        self.snapshots_combo_box.clear()
        self.snapshots_thread = SnapshotsThread(email, password, computer_id)
        self.snapshots_thread.loaded.connect(self.snapshots_loaded)
        self.snapshots_thread.start()

        self.reset_loading_backup_dialog()
        self.restoring_dialog = LoadingDialog(
            self,
            "Restoring. Please Wait...",
        )

        self.logger.info("Restore dialog displayed.")

    def snapshots_loaded(self, snapshots):
        if len(snapshots) == 0:
            self.setWindowTitle("No Backups Found")
            return
        for snapshot in snapshots:
            time_obj = datetime.datetime.fromisoformat(snapshot["time"][:19])
            pretty_time = time_obj.strftime("%b %d %Y %I:%M:%S %p")
            self.snapshots_combo_box.addItem(pretty_time,
                                             userData=snapshot["id"])

    def load_current_snapshot(self):
        self.loading_backups_gui_state()
        self.snapshot_tree_widget.clear()
        snapshot_id = self.snapshots_combo_box.currentData()
        self.snapshot_thread = SnapshotThread(self.email, self.password,
                                              snapshot_id, self.computer_id)
        self.snapshot_thread.loaded.connect(self.snapshot_loaded)
        self.snapshot_thread.failed.connect(self.snapshot_load_failed)
        self.snapshot_thread.start()

    def snapshot_loaded(self, tree):
        computer = get_computer(self.email, self.password, self.computer_id)
        self.snapshot_tree_widget.initialize(tree, computer["name"])
        self.reset_gui_state()

    def snapshot_load_failed(self):
        QMessageBox.warning(self, "Load failed", "Failed to load backups.")
        self.reset_gui_state()

    def restore(self):
        path = QFileDialog.getExistingDirectory()
        if path:
            reply = QMessageBox.information(
                self,
                "Start Restore?",
                f"You are about to restore to {path}. Blobbackup will OVERWRITE any conflicting files. Continue?",
                QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
                QMessageBox.StandardButton.No,
            )
            if reply == QMessageBox.StandardButton.Yes:
                snapshot_id = self.snapshots_combo_box.currentData()
                self.restoring_gui_state()
                self.restore_thread = RestoreThread(
                    self.email,
                    self.password,
                    self.computer_id,
                    snapshot_id,
                    path,
                    self.snapshot_tree_widget,
                )
                self.restore_thread.restored.connect(self.restored)
                self.restore_thread.failed.connect(self.restore_failed)
                self.restore_thread.start()

    def restored(self, target):
        self.reset_gui_state()
        QMessageBox.information(self, "Restore Complete",
                                f"Your files have been restored to {target}.")

    def loading_backups_gui_state(self):
        self.set_elements_enabled(False)
        self.loading_backup_dialog.show()
        self.setWindowTitle("Loading File Tree. Please Wait...")

    def restoring_gui_state(self):
        self.set_elements_enabled(False)
        self.restoring_dialog.show()
        self.setWindowTitle("Restoring. Please Wait...")

    def reset_gui_state(self):
        self.setWindowTitle("Restore Files - Blobbackup")
        self.restoring_dialog.hide()
        self.loading_backup_dialog.hide()
        self.reset_loading_backup_dialog()
        self.set_elements_enabled(True)

    def reset_loading_backup_dialog(self):
        title = "Loading File Tree. Please Wait..."
        message = None
        if not restic_cache_ready():
            title = "Retrieving Backups. Please Wait..."
            message = "We're retrieving your backups for the first time on this computer. Depending on your backup size and internet speed, this may take up to an hour. Thanks for your patience :-)"
        self.loading_backup_dialog = LoadingDialog(self, title, message)

    def set_elements_enabled(self, value):
        self.snapshots_combo_box.setEnabled(value)
        self.snapshot_tree_widget.setEnabled(value)
        self.restore_button.setEnabled(value)

    def restore_failed(self):
        self.setWindowTitle("Restore Files - Blobbackup")
        self.set_elements_enabled(True)
        QMessageBox.information(
            self, "Restore Failed",
            "Blobbackup was unable to restore your files.")