def _inner_rename(): new_name = get_text( self, QCoreApplication.translate("FilesWidget", "New name"), QCoreApplication.translate("FilesWidget", "Enter file new name"), placeholder="File name", default_text=name_item.text(), ) if not new_name: return try: if type_item.data(Qt.UserRole) == FileType.Folder: self.portal.run( self.core.fs.move, os.path.join("/", self.workspace, self.current_directory, name_item.text()), os.path.join("/", self.workspace, self.current_directory, new_name), ) else: self.portal.run( self.core.fs.move, os.path.join("/", self.workspace, self.current_directory, name_item.text()), os.path.join("/", self.workspace, self.current_directory, new_name), ) except: show_error( self, QCoreApplication.translate("FilesWidget", "Can not rename."))
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 delete_item(self, row): name_item = self.table_files.item(row, 1) type_item = self.table_files.item(row, 0) QCoreApplication.processEvents() result = ask_question( self, QCoreApplication.translate("FilesWidget", "Confirmation"), QCoreApplication.translate( "FilesWidget", 'Are you sure you want to delete "{}" ?').format( name_item.text()), ) if not result: return path = os.path.join("/", self.workspace, self.current_directory, name_item.text()) try: if type_item.data(Qt.UserRole) == FileType.Folder: self._delete_folder(path) else: self.portal.run(self.core.fs.delete, path) self.table_files.removeRow(row) except: show_error( self, QCoreApplication.translate('Can not delete "{}"').format( name_item.text()))
def _create_folder(self, folder_name): try: self.portal.run( self.core.fs.folder_create, os.path.join("/", self.workspace, self.current_directory, folder_name), ) return True except FileExistsError: show_error( self, QCoreApplication.translate( "FilesWidget", "A folder with the same name already exists."), ) return False
def import_folder_clicked(self): path = QFileDialog.getExistingDirectory( self, QCoreApplication.translate("FilesWidget", "Select a directory to import"), str(pathlib.Path.home()), ) if not path: return p = pathlib.Path(path) err = self._import_folder( p, os.path.join("/", self.workspace, self.current_directory, p.name)) if err: show_error( self, QCoreApplication.translate( "FilesWidget", "The folder could not be imported."))
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 choose_mountpoint(self): while True: path = QFileDialog.getExistingDirectory( self, QCoreApplication.translate("GlobalSettingsWidget", "Choose a mountpoint"), str(pathlib.Path.home()), ) if not path: return path_info = QFileInfo(path) if not path_info.isDir() or not path_info.isWritable(): show_error( self, QCoreApplication.translate( "GlobalSettingsWidget", "The choosen folder is not writable."), ) else: self.line_edit_mountpoint.setText(path_info.absoluteFilePath()) return
def claim_error(self, status): self.claim_thread.join() self.claim_thread = None self.cancel_scope = None self.trio_portal = None self.button_cancel.hide() self.button_claim.setDisabled(False) self.check_infos("") if status == "not_found": show_error( self, QCoreApplication.translate( "ClaimUserWidget", "No invitation found for this user."), ) else: show_error( self, QCoreApplication.translate( "ClaimUserWidget", "Can not claim this user ({}).").format(status), )
def create_workspace_clicked(self): workspace_name = get_text( self, QCoreApplication.translate("WorkspacesWidget", "New workspace"), QCoreApplication.translate("WorkspacesWidget", "Enter new workspace name"), QCoreApplication.translate("WorkspacesWidget", "Workspace name"), ) if not workspace_name: return try: self.portal.run(self.core.fs.workspace_create, os.path.join("/", workspace_name)) except FileExistsError: show_error( self, QCoreApplication.translate( "WorkspacesWidget", "A workspace with the same name already exists."), ) return
def claim_clicked(self): use_pkcs11 = True if self.check_box_use_pkcs11.checkState() == Qt.Unchecked: use_pkcs11 = False if (len(self.line_edit_password.text()) > 0 or len(self.line_edit_password_check.text()) > 0): if self.line_edit_password.text( ) != self.line_edit_password_check.text(): show_error( self, QCoreApplication.translate("ClaimUserWidget", "Passwords don't match")) return try: backend_addr = BackendOrganizationAddr(self.line_edit_url.text()) device_id = DeviceID("{}@{}".format(self.line_edit_login.text(), self.line_edit_device.text())) except: show_error( self, QCoreApplication.translate("ClaimUserWidget", "URL or device is invalid.")) return try: args = None if use_pkcs11: args = ( backend_addr, device_id, self.line_edit_token.text(), True, None, int(self.line_edit_pkcs11_token.text()), int(self.line_edit_pkcs11.key.text()), ) else: args = ( backend_addr, device_id, self.line_edit_token.text(), False, self.line_edit_password.text(), ) self.button_cancel.show() self.claim_thread = threading.Thread( target=self._thread_claim_user, args=args) self.claim_thread.start() self.trio_portal = self.claim_queue.get() self.cancel_scope = self.claim_queue.get() self.button_claim.setDisabled(True) except: import traceback traceback.print_exc() show_error( self, QCoreApplication.translate("ClaimUserWidget", "Can not register the new user."), )
def import_files_clicked(self): paths, _ = QFileDialog.getOpenFileNames( self, QCoreApplication.translate("FilesWidget", "Select files to import"), str(pathlib.Path.home()), ) if not paths: return err = False for path in paths: p = pathlib.Path(path) try: self.file_queue.put_nowait( (str(p), os.path.join("/", self.workspace, self.current_directory, p.name))) except queue.Full: err = True if err: show_error( self, QCoreApplication.translate( "FilesWidget", "Some files could not be imported."))
def login_with_pkcs11(self, organization_id, device_id, pkcs11_pin, pkcs11_key, pkcs11_token): try: self.current_device = load_device_with_pkcs11( self.core_config.config_dir, organization_id, device_id ) self.start_core() self.show_central_widget() except DeviceManagerError: show_error(self, QCoreApplication.translate("MainWindow", "Authentication failed.")) except BackendHandshakeError: show_error( self, QCoreApplication.translate("MainWindow", "User not registered in the backend."), ) except RuntimeError: show_error(self, QCoreApplication.translate("MainWindow", "Mountpoint already in use."))