def goto_file_clicked(self): def _on_file_link_input_finished(return_code, file_link): if not return_code or 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")) 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"), on_finished=_on_file_link_input_finished, )
def rename_files(self): files = self.table_files.selected_files() if len(files) == 1: def _on_rename_one_file_finished(return_code, new_name): if return_code and new_name: self.jobs_ctx.submit_job( ThreadSafeQtSignal(self, "rename_success", QtToTrioJob), ThreadSafeQtSignal(self, "rename_error", QtToTrioJob), _do_rename, workspace_fs=self.workspace_fs, paths=[( self.current_directory / files[0].name, self.current_directory / new_name, files[0].uuid, )], ) get_text_input( self, _("TEXT_FILE_RENAME_TITLE"), _("TEXT_FILE_RENAME_INSTRUCTIONS"), placeholder=_("TEXT_FILE_RENAME_PLACEHOLDER"), default_text=files[0].name, button_text=_("ACTION_FILE_RENAME"), on_finished=_on_rename_one_file_finished, ) else: def _on_rename_multiple_files_finished(return_code, new_name): if return_code and new_name: self.jobs_ctx.submit_job( ThreadSafeQtSignal(self, "rename_success", QtToTrioJob), ThreadSafeQtSignal(self, "rename_error", QtToTrioJob), _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.uuid, ) for i, f in enumerate(files, 1)], ) 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"), button_text=_("ACTION_FILE_RENAME_MULTIPLE"), on_finished=_on_rename_multiple_files_finished, )
def create_workspace_clicked(self): def _on_workspace_name_input_finished(return_code, workspace_name): if return_code and workspace_name: self.jobs_ctx.submit_job( ThreadSafeQtSignal(self, "create_success", QtToTrioJob), ThreadSafeQtSignal(self, "create_error", QtToTrioJob), _do_workspace_create, client=self.client, workspace_name=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"), on_finished=_on_workspace_name_input_finished, )
def invite_user(self): def _on_user_email_input_finished(return_code, user_email): if return_code and user_email: self.jobs_ctx.submit_job( ThreadSafeQtSignal(self, "invite_user_success", QtToTrioJob), ThreadSafeQtSignal(self, "invite_user_error", QtToTrioJob), _do_invite_user, client=self.client, email=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"), on_finished=_on_user_email_input_finished, )
def create_folder_clicked(self): def _on_folder_name_finished(return_code, folder_name): if return_code and folder_name: 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, ) 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"), on_finished=_on_folder_name_finished, )
def rename_workspace(self, workspace_button): def _rename_dialog_finished(return_code, text): if not return_code or not text: return self.jobs_ctx.submit_job( ThreadSafeQtSignal(self, "rename_success", QtToTrioJob), ThreadSafeQtSignal(self, "rename_error", QtToTrioJob), _do_workspace_rename, client=self.client, workspace_id=workspace_button.workspace_fs.workspace_id, new_name=text, button=workspace_button, ) get_text_input( self, _("TEXT_WORKSPACE_RENAME_TITLE"), _("TEXT_WORKSPACE_RENAME_INSTRUCTIONS"), on_finished=_rename_dialog_finished, placeholder=_("TEXT_WORKSPACE_RENAME_PLACEHOLDER"), default_text=workspace_button.name, button_text=_("ACTION_WORKSPACE_RENAME_CONFIRM"), )
def _on_join_org_clicked(self): self.show_top() def _on_url_input_finished(return_code, url): if not return_code or url is None: return if url == "": show_error(self, _("TEXT_JOIN_ORG_INVALID_URL")) return action_addr = None try: action_addr = BackendActionAddr.from_url(url.strip()) except ValueError as exc: show_error(self, _("TEXT_INVALID_URL"), exception=exc) return if isinstance(action_addr, BackendOrganizationBootstrapAddr): self._on_bootstrap_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")) else: show_error(self, _("TEXT_INVALID_URL")) get_text_input( parent=self, title=_("TEXT_JOIN_ORG_URL_TITLE"), message=_("TEXT_JOIN_ORG_URL_INSTRUCTIONS"), placeholder=_("TEXT_JOIN_ORG_URL_PLACEHOLDER"), on_finished=_on_url_input_finished, )
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 def _on_finished(ret): if ret: self.reload_login_devices() self.try_login(ret[0], ret[1]) BootstrapOrganizationWidget.show_modal( jobs_ctx=self.jobs_ctx, config=self.config, addr=action_addr, parent=self, on_finished=_on_finished, )