def open_get_text_large(self):
     custom_dialogs.get_text_input(
         self,
         title=SMALL_TEXT,
         message=LARGE_TEXT,
         placeholder="Placeholder",
         default_text="Default text",
         completion=[
             "Abcd", "Bcde", "Cdef", "Defg", "Efgh", "Fghi", "Ghij", "Hijk",
             "Ijkl"
         ],
         button_text="Go",
     )
Esempio n. 2
0
    def rename_files(self):
        files = self.table_files.selected_files()
        if len(files) == 1:
            new_name = get_text_input(
                self,
                _("TEXT_FILE_RENAME_TITLE"),
                _("TEXT_FILE_RENAME_INSTRUCTIONS"),
                placeholder=_("TEXT_FILE_RENAME_PLACEHOLDER"),
                default_text=files[0].name,
                validator=validators.FileNameValidator(),
                button_text=_("ACTION_FILE_RENAME"),
            )
            if not new_name:
                return
            self.jobs_ctx.submit_job(
                self.rename_success,
                self.rename_error,
                _do_rename,
                workspace_fs=self.workspace_fs,
                paths=[(
                    self.current_directory / files[0].name,
                    self.current_directory / new_name,
                    files[0].entry_id,
                )],
            )
        else:
            new_name = get_text_input(
                self,
                _("TEXT_FILE_RENAME_MULTIPLE_TITLE_count").format(
                    count=len(files)),
                _("TEXT_FILE_RENAME_MULTIPLE_INSTRUCTIONS_count").format(
                    count=len(files)),
                placeholder=_("TEXT_FILE_RENAME_MULTIPLE_PLACEHOLDER"),
                validator=validators.FileNameValidator(),
                button_text=_("ACTION_FILE_RENAME_MULTIPLE"),
            )
            if not new_name:
                return

            self.jobs_ctx.submit_job(
                self.rename_success,
                self.rename_error,
                _do_rename,
                workspace_fs=self.workspace_fs,
                paths=[(
                    self.current_directory / f.name,
                    self.current_directory / "{}_{}{}".format(
                        new_name, i, ".".join(pathlib.Path(f.name).suffixes)),
                    f.entry_id,
                ) for i, f in enumerate(files, 1)],
            )
Esempio n. 3
0
    def _on_join_org_clicked(self):
        url = get_text_input(
            parent=self,
            title=_("TEXT_JOIN_ORG_URL_TITLE"),
            message=_("TEXT_JOIN_ORG_URL_INSTRUCTIONS"),
            placeholder=_("TEXT_JOIN_ORG_URL_PLACEHOLDER"),
        )
        if url is None:
            return
        elif url == "":
            show_error(self, _("TEXT_JOIN_ORG_INVALID_URL"))
            return

        action_addr = None
        try:
            action_addr = BackendActionAddr.from_url(url)
        except ValueError as exc:
            show_error(self, _("TEXT_INVALID_URL"), exception=exc)
            return

        if isinstance(action_addr, BackendOrganizationBootstrapAddr):
            self._on_create_org_clicked(action_addr)
        elif isinstance(action_addr, BackendInvitationAddr):
            if action_addr.invitation_type == InvitationType.USER:
                self._on_claim_user_clicked(action_addr)
            elif action_addr.invitation_type == InvitationType.DEVICE:
                self._on_claim_device_clicked(action_addr)
            else:
                show_error(self, _("TEXT_INVALID_URL"))
                return
        else:
            show_error(self, _("TEXT_INVALID_URL"))
            return
Esempio n. 4
0
    def goto_file_clicked(self):
        file_link = get_text_input(
            self,
            _("TEXT_WORKSPACE_GOTO_FILE_LINK_TITLE"),
            _("TEXT_WORKSPACE_GOTO_FILE_LINK_INSTRUCTIONS"),
            placeholder=_("TEXT_WORKSPACE_GOTO_FILE_LINK_PLACEHOLDER"),
            default_text="",
            button_text=_("ACTION_GOTO_FILE_LINK"),
        )
        if not file_link:
            return

        url = None
        try:
            url = BackendOrganizationFileLinkAddr.from_url(file_link)
        except ValueError as exc:
            show_error(self,
                       _("TEXT_WORKSPACE_GOTO_FILE_LINK_INVALID_LINK"),
                       exception=exc)
            return

        for widget in self._iter_workspace_buttons():
            if widget.workspace_fs.workspace_id == url.workspace_id:
                self.load_workspace(widget.workspace_fs,
                                    path=url.path,
                                    selected=True)
                return
        show_error(self,
                   _("TEXT_WORKSPACE_GOTO_FILE_LINK_WORKSPACE_NOT_FOUND"))
Esempio n. 5
0
    def _on_bootstrap_org_clicked(self, action_addr=None):
        if not action_addr:
            url = get_text_input(
                parent=self,
                title=_("TEXT_BOOTSTRAP_ORG_URL_TITLE"),
                message=_("TEXT_BOOTSTRAP_ORG_URL_INSTRUCTIONS"),
                placeholder=_("TEXT_BOOTSTRAP_ORG_URL_PLACEHOLDER"),
                validator=validators.BackendOrganizationBootstrapAddrValidator(),
            )
            if url is None:
                return
            elif url == "":
                show_error(self, _("TEXT_BOOTSTRAP_ORG_INVALID_URL"))
                return

            action_addr = None
            try:
                action_addr = BackendOrganizationBootstrapAddr.from_url(url)
            except ValueError as exc:
                show_error(self, _("TEXT_BOOTSTRAP_ORG_INVALID_URL"), exception=exc)
                return
        ret = BootstrapOrganizationWidget.exec_modal(
            jobs_ctx=self.jobs_ctx, config=self.config, addr=action_addr, parent=self
        )
        if ret:
            self.reload_login_devices()
            self.try_login(ret[0], ret[1])
    def goto_file_clicked(self):
        file_link = get_text_input(
            self,
            _("TEXT_WORKSPACE_GOTO_FILE_LINK_TITLE"),
            _("TEXT_WORKSPACE_GOTO_FILE_LINK_INSTRUCTIONS"),
            placeholder=_("TEXT_WORKSPACE_GOTO_FILE_LINK_PLACEHOLDER"),
            default_text="",
            button_text=_("ACTION_GOTO_FILE_LINK"),
        )
        if not file_link:
            return

        try:
            addr = BackendOrganizationFileLinkAddr.from_url(file_link, allow_http_redirection=True)
        except ValueError as exc:
            show_error(self, _("TEXT_WORKSPACE_GOTO_FILE_LINK_INVALID_LINK"), exception=exc)
            return

        button = self.get_workspace_button(addr.workspace_id)
        if button is not None:
            try:
                path = button.workspace_fs.decrypt_file_link_path(addr)
            except ValueError as exc:
                show_error(self, _("TEXT_WORKSPACE_GOTO_FILE_LINK_INVALID_LINK"), exception=exc)
                return
            self.load_workspace(button.workspace_fs, path=path, selected=True)
            return

        show_error(self, _("TEXT_WORKSPACE_GOTO_FILE_LINK_WORKSPACE_NOT_FOUND"))
Esempio n. 7
0
    def _on_claim_device_clicked(self, action_addr=None):
        if not action_addr:
            url = get_text_input(
                parent=self,
                title=_("TEXT_CLAIM_DEVICE_URL_TITLE"),
                message=_("TEXT_CLAIM_DEVICE_URL_INSTRUCTIONS"),
                placeholder=_("TEXT_CLAIM_DEVICE_URL_PLACEHOLDER"),
            )
            if url is None:
                return
            elif url == "":
                show_error(self, _("TEXT_CLAIM_DEVICE_INVALID_URL"))
                return

            action_addr = None
            try:
                action_addr = BackendOrganizationClaimDeviceAddr.from_url(url)
            except ValueError as exc:
                show_error(self, _("TEXT_CLAIM_DEVICE_INVALID_URL"), exception=exc)
                return
        ret = ClaimDeviceWidget.exec_modal(
            jobs_ctx=self.jobs_ctx, config=self.config, addr=action_addr, parent=self
        )
        if ret:
            self.reload_login_devices()
Esempio n. 8
0
 def create_workspace_clicked(self):
     workspace_name = get_text_input(
         parent=self,
         title=_("TEXT_WORKSPACE_NEW_TITLE"),
         message=_("TEXT_WORKSPACE_NEW_INSTRUCTIONS"),
         placeholder=_("TEXT_WORKSPACE_NEW_PLACEHOLDER"),
         button_text=_("ACTION_WORKSPACE_NEW_CREATE"),
     )
     if not workspace_name:
         return
     self.jobs_ctx.submit_job(
         ThreadSafeQtSignal(self, "create_success", QtToTrioJob),
         ThreadSafeQtSignal(self, "create_error", QtToTrioJob),
         _do_workspace_create,
         core=self.core,
         workspace_name=workspace_name,
     )
Esempio n. 9
0
 def create_workspace_clicked(self):
     workspace_name = get_text_input(
         parent=self,
         title=_("TEXT_WORKSPACE_NEW_TITLE"),
         message=_("TEXT_WORKSPACE_NEW_INSTRUCTIONS"),
         placeholder=_("TEXT_WORKSPACE_NEW_PLACEHOLDER"),
         button_text=_("ACTION_WORKSPACE_NEW_CREATE"),
         validator=validators.WorkspaceNameValidator(),
     )
     if not workspace_name:
         return
     self.jobs_ctx.submit_job(
         self.create_success,
         self.create_error,
         _do_workspace_create,
         core=self.core,
         workspace_name=workspace_name,
     )
Esempio n. 10
0
    def create_folder_clicked(self):
        folder_name = get_text_input(
            self,
            _("TEXT_FILE_CREATE_FOLDER_TITLE"),
            _("TEXT_FILE_CREATE_FOLDER_INSTRUCTIONS"),
            placeholder=_("TEXT_FILE_CREATE_FOLDER_PLACEHOLDER"),
            button_text=_("ACTION_FILE_CREATE_FOLDER"),
        )
        if not folder_name:
            return

        self.jobs_ctx.submit_job(
            ThreadSafeQtSignal(self, "folder_create_success", QtToTrioJob),
            ThreadSafeQtSignal(self, "folder_create_error", QtToTrioJob),
            _do_folder_create,
            workspace_fs=self.workspace_fs,
            path=self.current_directory / folder_name,
        )
Esempio n. 11
0
    def invite_user(self):
        user_email = get_text_input(
            self,
            _("TEXT_USER_INVITE_EMAIL"),
            _("TEXT_USER_INVITE_EMAIL_INSTRUCTIONS"),
            placeholder=_("TEXT_USER_INVITE_EMAIL_PLACEHOLDER"),
            button_text=_("ACTION_USER_INVITE_DO_INVITE"),
            validator=validators.EmailValidator(),
        )
        if not user_email:
            return

        self.jobs_ctx.submit_job(
            ThreadSafeQtSignal(self, "invite_user_success", QtToTrioJob),
            ThreadSafeQtSignal(self, "invite_user_error", QtToTrioJob),
            _do_invite_user,
            core=self.core,
            email=user_email,
        )
Esempio n. 12
0
    def create_folder_clicked(self):
        folder_name = get_text_input(
            self,
            _("TEXT_FILE_CREATE_FOLDER_TITLE"),
            _("TEXT_FILE_CREATE_FOLDER_INSTRUCTIONS"),
            placeholder=_("TEXT_FILE_CREATE_FOLDER_PLACEHOLDER"),
            button_text=_("ACTION_FILE_CREATE_FOLDER"),
            validator=validators.FileNameValidator(),
        )
        if not folder_name:
            return

        self.jobs_ctx.submit_job(
            self.folder_create_success,
            self.folder_create_error,
            _do_folder_create,
            workspace_fs=self.workspace_fs,
            path=self.current_directory / folder_name,
        )
Esempio n. 13
0
 def rename_workspace(self, workspace_button):
     new_name = get_text_input(
         self,
         _("TEXT_WORKSPACE_RENAME_TITLE"),
         _("TEXT_WORKSPACE_RENAME_INSTRUCTIONS"),
         placeholder=_("TEXT_WORKSPACE_RENAME_PLACEHOLDER"),
         default_text=workspace_button.name,
         button_text=_("ACTION_WORKSPACE_RENAME_CONFIRM"),
     )
     if not new_name:
         return
     self.jobs_ctx.submit_job(
         ThreadSafeQtSignal(self, "rename_success", QtToTrioJob),
         ThreadSafeQtSignal(self, "rename_error", QtToTrioJob),
         _do_workspace_rename,
         core=self.core,
         workspace_id=workspace_button.workspace_fs.workspace_id,
         new_name=new_name,
         button=workspace_button,
     )
Esempio n. 14
0
 def rename_workspace(self, workspace_button):
     new_name = get_text_input(
         self,
         _("TEXT_WORKSPACE_RENAME_TITLE"),
         _("TEXT_WORKSPACE_RENAME_INSTRUCTIONS"),
         placeholder=_("TEXT_WORKSPACE_RENAME_PLACEHOLDER"),
         default_text=workspace_button.name.str,
         button_text=_("ACTION_WORKSPACE_RENAME_CONFIRM"),
         validator=validators.WorkspaceNameValidator(),
     )
     if not new_name:
         return
     self.jobs_ctx.submit_job(
         self.rename_success,
         self.rename_error,
         _do_workspace_rename,
         core=self.core,
         workspace_id=workspace_button.workspace_fs.workspace_id,
         new_name=new_name,
         button=workspace_button,
     )
Esempio n. 15
0
    async def show_modal(cls, core, jobs_ctx, parent, on_finished=None):
        available_device = get_available_device(core.config.config_dir,
                                                core.device)
        loaded_device = None

        try:
            if available_device.type == DeviceFileType.PASSWORD:
                password = get_text_input(
                    parent,
                    _("TEXT_DEVICE_UNLOCK_TITLE"),
                    _("TEXT_DEVICE_UNLOCK_FOR_AUTH_CHANGE_LABEL"),
                    placeholder="",
                    default_text="",
                    completion=None,
                    button_text=None,
                    validator=None,
                    hidden=True,
                )
                if not password:
                    return
                loaded_device = load_device_with_password(
                    available_device.key_file_path, password)
            else:
                loaded_device = await load_device_with_smartcard(
                    available_device.key_file_path)
        except LocalDeviceError:
            show_error(parent, _("TEXT_LOGIN_ERROR_AUTHENTICATION_FAILED"))
            return

        w = cls(core=core, jobs_ctx=jobs_ctx, loaded_device=loaded_device)
        d = GreyedDialog(w,
                         title=_("TEXT_CHANGE_AUTHENTICATION_TITLE"),
                         parent=parent)
        w.dialog = d

        if on_finished:
            d.finished.connect(on_finished)
        # Unlike exec_, show is asynchronous and works within the main Qt loop
        d.show()
        return w
Esempio n. 16
0
    def _on_join_org_clicked(self) -> None:
        url = get_text_input(
            parent=self,
            title=_("TEXT_JOIN_ORG_URL_TITLE"),
            message=_("TEXT_JOIN_ORG_URL_INSTRUCTIONS"),
            placeholder=_("TEXT_JOIN_ORG_URL_PLACEHOLDER"),
            validator=validators.BackendActionAddrValidator(),
        )
        if url is None:
            return
        elif url == "":
            show_error(self, _("TEXT_JOIN_ORG_INVALID_URL"))
            return

        action_addr = None
        try:
            action_addr = BackendActionAddr.from_url(url, allow_http_redirection=True)
        except ValueError as exc:
            show_error(self, _("TEXT_INVALID_URL"), exception=exc)
            return

        if isinstance(action_addr, BackendOrganizationBootstrapAddr):
            self._on_create_org_clicked(action_addr)
        elif isinstance(action_addr, BackendInvitationAddr):
            if action_addr.invitation_type == InvitationType.USER:
                self._on_claim_user_clicked(action_addr)
            elif action_addr.invitation_type == InvitationType.DEVICE:
                self._on_claim_device_clicked(action_addr)
        elif isinstance(action_addr, BackendPkiEnrollmentAddr):
            if not is_pki_enrollment_available():
                show_error(self, _("TEXT_PKI_ENROLLMENT_NOT_AVAILABLE"))
                return
            self._on_claim_pki_clicked(action_addr)
        else:
            show_error(self, _("TEXT_INVALID_URL"))
            return
    async def _on_validate_clicked(self):
        if isinstance(self.current_page, DeviceRecoveryExportPage1Widget):
            self.button_validate.setEnabled(False)
            selected_device = self.current_page.get_selected_device()
            save_path = self.current_page.get_save_path()
            device = None

            if isinstance(selected_device, LocalDevice):
                selected_device = get_available_device(self.config.config_dir,
                                                       selected_device)

            if selected_device.type == DeviceFileType.PASSWORD:
                password = get_text_input(
                    self,
                    translate("TEXT_DEVICE_UNLOCK_TITLE"),
                    translate("TEXT_DEVICE_UNLOCK_FOR_RECOVERY_LABEL"),
                    placeholder="",
                    default_text="",
                    completion=None,
                    button_text=None,
                    validator=None,
                    hidden=True,
                )
                if password is None:
                    self.button_validate.setEnabled(True)
                    return
                try:
                    device = load_device_with_password(
                        selected_device.key_file_path, password)
                except LocalDeviceError:
                    show_error(
                        self,
                        translate("TEXT_LOGIN_ERROR_AUTHENTICATION_FAILED"))
                    self.button_validate.setEnabled(True)
                    return
            elif selected_device.type == DeviceFileType.SMARTCARD:
                try:
                    device = await load_device_with_smartcard(
                        selected_device.key_file_path)
                except LocalDeviceError as exc:
                    show_error(
                        self,
                        translate("TEXT_LOGIN_ERROR_AUTHENTICATION_FAILED"),
                        exception=exc)
                    self.button_validate.setEnabled(True)
                    return
                except ModuleNotFoundError as exc:
                    show_error(
                        self,
                        translate("TEXT_UNLOCK_ERROR_SMARTCARD_NOT_AVAILABLE"),
                        exception=exc)
                    self.button_validate.setEnabled(True)
                    return
            self.jobs_ctx.submit_job(
                self.export_success,
                self.export_failure,
                self._export_recovery_device,
                config_dir=self.config.config_dir,
                device=device,
                export_path=save_path,
            )
        else:
            self.dialog.accept()