def rename_workspace(self, workspace_button): current_file_path = os.path.join("/", workspace_button.name) new_name = get_text( self, QCoreApplication.translate("WorkspacesWidget", "New name"), QCoreApplication.translate("WorkspacesWidget", "Enter workspace new name"), placeholder=QCoreApplication.translate("WorkspacesWidget", "Workspace name"), ) if not new_name: return try: self.portal.run(self.core.fs.workspace_rename, current_file_path, os.path.join("/", new_name)) workspace_button.name = new_name except FileExistsError: show_warning( self, QCoreApplication.translate( "WorkspacesWidget", "A workspace with the same name already exists."), ) except: show_error( self, QCoreApplication.translate("WorkspacesWidget", "Can not rename the workspace."), )
def closeEvent(self, event): if not self.closing_allowed: show_warning( self, QCoreApplication.translate( "RegisterUserDialog", "Can not close this window while waiting for the new user to register. " "Please cancel first.", ), ) event.ignore() else: event.accept()
def register_device(self): def _run_registration(device_name, token): self.portal.run( _handle_invite_and_create_device, self.register_queue, self.on_registered, self.on_register_error, self.core, device_name, token, ) if not self.line_edit_device_name.text(): show_warning( self, QCoreApplication.translate("RegisterDeviceDialog", "Please enter a device name."), ) return try: token = generate_invitation_token() self.line_edit_device.setText(self.line_edit_device_name.text()) self.line_edit_device.setCursorPosition(0) self.line_edit_token.setText(token) self.line_edit_token.setCursorPosition(0) self.line_edit_url.setText(self.core.device.organization_addr) self.line_edit_url.setCursorPosition(0) self.button_cancel.setFocus() self.widget_registration.show() self.register_thread = threading.Thread( target=_run_registration, args=(self.line_edit_device_name.text(), token)) self.register_thread.start() self.cancel_scope = self.register_queue.get() self.button_cancel.show() self.line_edit_device_name.hide() self.button_register.hide() self.closing_allowed = False except: show_warning( self, QCoreApplication.translate("RegisterDeviceDialog", "Could not register the device."), )
def share_workspace(self, workspace_button): current_user = self.core.device.user_id user = get_user_name( portal=self.portal, core=self.core, parent=self, title=QCoreApplication.translate("WorkspacesWidget", "Share a workspace"), message=QCoreApplication.translate( "WorkspacesWidget", "Give a user name to share the workspace {} with.").format( workspace_button.name), exclude=[current_user], ) if not user: return try: self.portal.run(self.core.fs.share, "/" + workspace_button.name, user) show_info( self, QCoreApplication.translate("WorkspacesWidget", "The workspaces has been shared."), ) workspace_button.participants = workspace_button.participants + [ user ] except SharingRecipientError: show_warning( self, QCoreApplication.translate( "WorkspacesWidget", 'Can not share the workspace "{}" with this user.').format( workspace_button.name), ) except: show_error( self, QCoreApplication.translate( "WorkspacesWidget", 'Can not share the workspace "{}" with "{}".').format( workspace_button.name, user), )
def registration_error(self, status): self.register_thread.join() self.register_thread = None self.cancel_scope = None self.line_edit_token.setText("") self.line_edit_url.setText("") self.line_edit_user.setText("") self.widget_registration.hide() self.button_cancel.hide() self.checkbox_is_admin.show() self.button_register.show() self.line_edit_username.show() self.closing_allowed = True if status is None: show_warning( self, QCoreApplication.translate("RegisterUserDialog", "Unknown error.")) elif status == "invalid_role": show_warning( self, QCoreApplication.translate( "RegisterUserDialog", "Only admins can invite a new user."), ) else: show_warning( self, QCoreApplication.translate( "RegisterUserDialog", "Unhandled response {}".format(status)), )
def register_error(self, status): self.register_thread.join() self.register_thread = None self.cancel_scope = None self.line_edit_token.setText("") self.line_edit_url.setText("") self.line_edit_device.setText("") self.widget_registration.hide() self.button_cancel.hide() self.button_register.show() self.line_edit_device_name.show() self.closing_allowed = True if status is None: show_warning( self, QCoreApplication.translate("RegisterUserDialog", "Unknown error.")) elif status == "already_exists": show_warning( self, QCoreApplication.translate("RegisterDeviceDialog", "This device already exists."), ) else: show_warning( self, QCoreApplication.translate( "RegisterDeviceDialog", "Can not register this device ({}).").format(status), )
def register_user(self): def _run_registration(username, token, is_admin): self.portal.run( _handle_invite_and_create_user, self.register_queue, self.on_registered, self.on_register_error, self.core, username, token, is_admin, ) if not self.line_edit_username.text(): show_warning( self, QCoreApplication.translate("RegisterUserDialog", "Please enter a username.")) return users = self.portal.run(self.core.fs.backend_cmds.user_find, self.line_edit_username.text()) if len(users): show_warning( self, QCoreApplication.translate( "RegisterUserDialog", "A user with the same name already exists."), ) return try: token = generate_invitation_token() self.line_edit_user.setText(self.line_edit_username.text()) self.line_edit_user.setCursorPosition(0) self.line_edit_token.setText(token) self.line_edit_token.setCursorPosition(0) self.line_edit_url.setText(self.core.device.organization_addr) self.line_edit_url.setCursorPosition(0) self.button_cancel.setFocus() self.widget_registration.show() self.register_thread = threading.Thread( target=_run_registration, args=(self.line_edit_username.text(), token, self.checkbox_is_admin.isChecked()), ) self.register_thread.start() self.cancel_scope = self.register_queue.get() self.button_cancel.show() self.line_edit_username.hide() self.checkbox_is_admin.hide() self.button_register.hide() self.closing_allowed = False except: import traceback traceback.print_exc() show_warning( self, QCoreApplication.translate("RegisterUserDialog", "Could not register the user."), )
def delete_workspace(self, workspace_button): show_warning( self, QCoreApplication.translate("WorkspacesWidget", "Not yet implemented."))