예제 #1
0
    def ask_where_and_extract_selected_elements(self):
        """Ask the user for a destination folder and
        extract the selected elements to disk
        """
        try:
            selected_nodes = self.get_selected_tree_nodes()

            # Get the target directory from the user
            additional_dialog_options = 0
            if self.pyluggage_config.follow_sym_links:
                additional_dialog_options = QFileDialog.DontResolveSymlinks
            dialog = QFileDialog()
            selected_dir = dialog.getExistingDirectory(
                self,
                _translate("Select a folder where the {} selected items will be extracted".format(
                    len(selected_nodes))),
                "",
                QFileDialog.ShowDirsOnly | additional_dialog_options)
            selected_dir = unicode(selected_dir)
            if selected_dir == "":
                # The user cancelled
                return

            # Computed to give an accurate progress dialog only
            target_file_info_nodes = []
            for node in selected_nodes:
                if node.is_terminal:
                    target_file_info_nodes.append(node)
                else:
                    target_file_info_nodes += node.get_all_files_descendant()
            task_count = len(target_file_info_nodes)
            maximum_progress = sum([fileinfo.original_size_bytes for fileinfo in target_file_info_nodes])
            progress_dialog = ProgressDialog(
                parent=self,
                task_count=task_count,
                maximum_progress=maximum_progress,
                action_name=_translate("Extracting elements..."),
                cancelable=False,
                show_bar=True,
                show_task_count=True)
            progress_dialog.setVisible(True)

            worker = ExtractFilesToDiskWorker(
                files_frame=self,
                node_list=selected_nodes,
                target_path=selected_dir)
            worker.next_element.connect(progress_dialog.next_task)
            worker.finished.connect(progress_dialog.finish)
            worker.start()
            progress_dialog.exec_()
        finally:
            pass
예제 #2
0
    def open_luggage_query_pass(self, luggage_path):
        """Query the user for a password and open the luggage.
        Emit luggage_opened when successful
        """
        # Query user for password
        try:
            if luggage_path is None or luggage_path == "":
                return
            dialog = QueryPasswordDialog(parent=self, luggage_path=luggage_path)
            dialog.exec_()
            if dialog.accepted_password is None:
                return
            password = unicode(dialog.accepted_password)
            if not luggage.Luggage.is_valid_password(password):
                return

            # Open in background
            progress_dialog = ProgressDialog(
                parent=self,
                action_name=_translate("Opening Luggage"),
                target_name=luggage_path,
                cancelable=False,
                show_bar=False,
                show_task_count=False,
            )
            progress_dialog.setVisible(True)

            worker = OpenLuggageWorker(
                parent=self, path=luggage_path, password=password, pyluggage_config=self.pyluggage_config
            )
            worker.finished.connect(progress_dialog.finish)
            worker.start()

            progress_dialog.exec_()

            if worker.open_luggage is None:
                if worker.error is not None:
                    raise worker.error
                else:
                    raise Exception(_translate("Unknown error opening Luggage"))
            else:
                self.luggage_opened.emit(worker.open_luggage)
        except Exception as ex:
            qmessage = QMessageBox(self)
            qmessage.critical(
                self,
                _translate("Error opening Luggage"),
                _translate(
                    "Error opening the Luggage at '{path}'.\n" "Is the password correct? Is the path valid?"
                ).format(path=luggage_path, message=ex.message),
            )
 def run_optimization_with_progress_dialog(parent, luggage, message=_translate("Compacting Luggage")):
     progress_dialog = ProgressDialog(
         parent=parent,
         task_count=1,
         maximum_progress=100,
         action_name=message,
         cancelable=False,
         show_bar=False,
         show_task_count=False)
     progress_dialog.setVisible(True)
     worker = CompactLuggageWorker(parent=parent, luggage=luggage)
     worker.finished.connect(progress_dialog.finish)
     worker.start()
     progress_dialog.exec_()
 def getQImageListFromPDFWithProgressDialog(parent, pdf_data):
     """Obtain a list of QImage instances, one per page of the pdf_data (byte string) as argument
     """
     progress_dialog = ProgressDialog(
         parent=parent,
         action_name=_translate("Loading PDF Contents"),
         cancelable=False,
         show_bar=False,
         show_task_count=False)
     progress_dialog.setVisible(True)
     worker = WorkerGetQImageListFromPDF(pdf_data)
     worker.finished.connect(progress_dialog.finish)
     worker.start()
     progress_dialog.exec_()
     return worker.pdf_image_list
 def getInstanceAndMediaPlayerWithProgressDialog(parent):
     progress_dialog = ProgressDialog(
         parent=parent,
         task_count=1,
         maximum_progress=100,
         action_name=_translate("Loading Multimedia Player"),
         cancelable=False,
         show_bar=False,
         show_task_count=False)
     progress_dialog.setVisible(True)
     worker = WorkerGetVLCInstance()
     worker.finished.connect(progress_dialog.finish)
     worker.start()
     progress_dialog.exec_()
     return worker.vlc_instance, worker.vlc_mediaplayer
예제 #6
0
 def __bg_save_file_tree(self,
                         message=_translate("Saving the file tree"),
                         target=""):
     """Save the Luggage file tree in a background thread, locking the GUI meanwhile
     """
     progress_dialog = ProgressDialog(
         parent=self,
         task_count=1,
         current_task=1,
         action_name=message,
         target_name=target,
         cancelable=False,
         show_bar=False,
         show_task_count=False)
     worker = SaveFileTreeWorker(files_frame=self)
     worker.finished.connect(progress_dialog.finish)
     worker.start()
     progress_dialog.exec_()
    def create_and_close(self):
        """Create the luggage in the specified path and close if successful
        """
        try:
            progress_dialog = ProgressDialog(
                parent=self,
                action_name=_translate("Creating Luggage..."),
                target_name=self._selected_luggage_path,
                cancelable=False,
                show_bar=False,
                show_task_count=False)
            progress_dialog.setVisible(True)

            password = unicode(self.lineedit_password1.text())
            worker = CreateLuggageWorker(
                parent=self,
                path=self._selected_luggage_path,
                password=password,
                pyluggage_config=self.pyluggage_config)
            worker.finished.connect(progress_dialog.finish)
            worker.start()

            progress_dialog.exec_()
            if worker.new_luggage is None:
                if worker.error is not None:
                    raise worker.error
                else:
                    raise Exception(_translate("Unknown error creating Luggage"))
            else:
                self.new_luggage = worker.new_luggage
                self.close()
        except Exception as ex:
            qmessage = QMessageBox(self)
            qmessage.critical(
                self,
                _translate("Error creating Luggage"),
                _translate(
                    "Error creating luggage at '{path}'.\n"
                    "Message: {message}.\n"
                    "Check that parent folder exists and can be written")
                .format(path=self._selected_luggage_path, message=ex.message))
예제 #8
0
 def __bg_delete_files(self, set_file_info, set_folder_node):
     """Delete the set of files and folder nodes using a worker
     in a background thread, while blocking the GUI with a
     progress dialog
     """
     progress_dialog = ProgressDialog(
         parent=self,
         task_count=max(1, len(set_file_info)),
         current_task=1,
         action_name=_translate("Deleting..."),
         target_name=None,
         cancelable=False,
         show_bar=True,
         show_task_count=True)
     worker = DeleteElementsWorker(
         files_frame=self,
         file_node_set=set_file_info,
         folder_node_set=set_folder_node)
     worker.file_deleted.connect(progress_dialog.next_task)
     worker.finished.connect(progress_dialog.finish)
     worker.start()
     progress_dialog.exec_()
예제 #9
0
    def __bg_insert_paths(self, parent_node, paths_and_names_to_insert):
        """Insert the elements in the Luggage in a background thread,
        save the file tree and update the treewidget

        :return: a list of the newly inserted nodes (they are children of parent_node)
        """
        maximum_progress = 0
        task_count = 0
        for path_to_insert in [t[0] for t in paths_and_names_to_insert]:
            if os.path.islink(path_to_insert) and not self.pyluggage_config.follow_sym_links:
                # Ignore symlinks if configured to do so
                continue
            if os.path.isfile(path_to_insert):
                maximum_progress += os.path.getsize(path_to_insert)
                task_count += 1
            elif os.path.isdir(path_to_insert):
                for root, dirs, files in os.walk(path_to_insert, followlinks=self.pyluggage_config.follow_sym_links):
                    for file in files:
                        maximum_progress += os.path.getsize(os.path.join(root, file))
                        task_count += 1

        progress_dialog = ProgressDialog(
            parent=self,
            task_count=task_count,
            maximum_progress=maximum_progress,
            action_name=_translate("Inserting elements..."),
            cancelable=False)
        progress_dialog.setVisible(True)

        worker = InsertElementsWorker(
            files_frame=self,
            parent_node=parent_node,
            paths_and_names_to_insert=paths_and_names_to_insert)
        worker.next_element.connect(progress_dialog.next_task)
        worker.finished.connect(self.__update_treewidget_contents_and_update_selection)
        worker.finished.connect(progress_dialog.finish)
        worker.start()
        progress_dialog.exec_()