def accept(self):

        progdialog = QtWidgets.QProgressDialog("", "Cancel", 0,
                                               len(self.rename_list), self)
        progdialog.setWindowTitle("Renaming Archives")
        progdialog.setWindowModality(QtCore.Qt.WindowModal)
        progdialog.setMinimumDuration(100)
        centerWindowOnParent(progdialog)
        # progdialog.show()
        QtCore.QCoreApplication.processEvents()

        for idx, item in enumerate(self.rename_list):

            QtCore.QCoreApplication.processEvents()
            if progdialog.wasCanceled():
                break
            idx += 1
            progdialog.setValue(idx)
            progdialog.setLabelText(item["new_name"])
            centerWindowOnParent(progdialog)
            QtCore.QCoreApplication.processEvents()

            folder = os.path.dirname(os.path.abspath(item["archive"].path))
            if self.settings.rename_move_dir and len(
                    self.settings.rename_dir.strip()) > 3:
                folder = self.settings.rename_dir.strip()

            new_abs_path = utils.unique_file(
                os.path.join(folder, item["new_name"]))

            if os.path.join(folder, item["new_name"]) == item["archive"].path:
                print(item["new_name"], "Filename is already good!")
                continue

            if not item["archive"].isWritable(check_rar_status=False):
                continue

            os.makedirs(os.path.dirname(new_abs_path), 0o777, True)
            os.rename(item["archive"].path, new_abs_path)

            item["archive"].rename(new_abs_path)

        progdialog.hide()
        QtCore.QCoreApplication.processEvents()

        QtWidgets.QDialog.accept(self)
Exemple #2
0
    def addPathList(self, pathlist):

        filelist = utils.get_recursive_filelist(pathlist)
        # we now have a list of files to add

        # Prog dialog on Linux flakes out for small range, so scale up
        progdialog = QProgressDialog("",
                                     "Cancel",
                                     0,
                                     len(filelist),
                                     parent=self)
        progdialog.setWindowTitle("Adding Files")
        progdialog.setWindowModality(Qt.ApplicationModal)
        progdialog.setMinimumDuration(300)
        centerWindowOnParent(progdialog)
        #QCoreApplication.processEvents()
        #progdialog.show()

        QCoreApplication.processEvents()
        firstAdded = None
        self.twList.setSortingEnabled(False)
        for idx, f in enumerate(filelist):
            QCoreApplication.processEvents()
            if progdialog.wasCanceled():
                break
            progdialog.setValue(idx + 1)
            progdialog.setLabelText(f)
            centerWindowOnParent(progdialog)
            QCoreApplication.processEvents()
            row = self.addPathItem(f)
            if firstAdded is None and row is not None:
                firstAdded = row

        progdialog.hide()
        QCoreApplication.processEvents()

        if (self.settings.show_no_unrar_warning
                and self.settings.unrar_lib_path == ""
                and not ComicTaggerSettings.haveOwnUnrarLib()):
            for f in filelist:
                ext = os.path.splitext(f)[1].lower()
                if ext == ".rar" or ext == ".cbr":
                    checked = OptionalMessageDialog.msg(
                        self, "No UnRAR Ability", """
                            It looks like you've tried to open at least one CBR or RAR file.<br><br>
                            In order for ComicTagger to read this kind of file, you will have to configure
                            the location of the unrar library in the settings.  Until then, ComicTagger
                            will not be able read these kind of files. See the "RAR Tools" tab in the
                            settings/preferences for more info.
                            """)
                    self.settings.show_no_unrar_warning = not checked
                    break

        if firstAdded is not None:
            self.twList.selectRow(firstAdded)
        else:
            if len(pathlist) == 1 and os.path.isfile(pathlist[0]):
                ext = os.path.splitext(pathlist[0])[1].lower()
                if ext == ".rar" or ext == ".cbr" and self.settings.unrar_lib_path == "":
                    QMessageBox.information(
                        self, self.tr("File Open"),
                        self.
                        tr("Selected file seems to be a rar file, "
                           "and can't be read until the unrar library is configured."
                           ))
                else:
                    QMessageBox.information(
                        self, self.tr("File Open"),
                        self.tr(
                            "Selected file doesn't seem to be a comic archive."
                        ))
            else:
                QMessageBox.information(
                    self, self.tr("File/Folder Open"),
                    self.tr("No readable comic archives were found."))

        self.twList.setSortingEnabled(True)

        # Adjust column size
        self.twList.resizeColumnsToContents()
        self.twList.setColumnWidth(FileSelectionList.CRFlagColNum, 35)
        self.twList.setColumnWidth(FileSelectionList.CBLFlagColNum, 35)
        self.twList.setColumnWidth(FileSelectionList.readonlyColNum, 35)
        self.twList.setColumnWidth(FileSelectionList.typeColNum, 45)
        if self.twList.columnWidth(FileSelectionList.fileColNum) > 250:
            self.twList.setColumnWidth(FileSelectionList.fileColNum, 250)
        if self.twList.columnWidth(FileSelectionList.folderColNum) > 200:
            self.twList.setColumnWidth(FileSelectionList.folderColNum, 200)
Exemple #3
0
    def addPathList(self, pathlist):

        filelist = utils.get_recursive_filelist(pathlist)
        # we now have a list of files to add

        progdialog = QProgressDialog("", "Cancel", 0, len(filelist), self)
        progdialog.setWindowTitle("Adding Files")
        # progdialog.setWindowModality(Qt.WindowModal)
        progdialog.setWindowModality(Qt.ApplicationModal)
        progdialog.show()

        firstAdded = None
        self.twList.setSortingEnabled(False)
        for idx, f in enumerate(filelist):
            QCoreApplication.processEvents()
            if progdialog.wasCanceled():
                break
            progdialog.setValue(idx)
            progdialog.setLabelText(f)
            centerWindowOnParent(progdialog)
            QCoreApplication.processEvents()
            row = self.addPathItem(f)
            if firstAdded is None and row is not None:
                firstAdded = row

        progdialog.close()
        if (self.settings.show_no_unrar_warning
                and self.settings.unrar_exe_path == ""
                and self.settings.rar_exe_path == ""
                and platform.system() != "Windows"):
            for f in filelist:
                ext = os.path.splitext(f)[1].lower()
                if ext == ".rar" or ext == ".cbr":
                    checked = OptionalMessageDialog.msg(
                        self, "No unrar tool", """
                            It looks like you've tried to open at least one CBR or RAR file.<br><br>
                            In order for ComicTagger to read this kind of file, you will have to configure
                            the location of the unrar tool in the settings.  Until then, ComicTagger
                            will not be able recognize these kind of files.
                            """)
                    self.settings.show_no_unrar_warning = not checked
                    break

        if firstAdded is not None:
            self.twList.selectRow(firstAdded)
        else:
            if len(pathlist) == 1 and os.path.isfile(pathlist[0]):
                QMessageBox.information(
                    self, self.tr("File Open"),
                    self.tr(
                        "Selected file doesn't seem to be a comic archive."))
            else:
                QMessageBox.information(
                    self, self.tr("File/Folder Open"),
                    self.tr("No comic archives were found."))

        self.twList.setSortingEnabled(True)

        # Adjust column size
        self.twList.resizeColumnsToContents()
        self.twList.setColumnWidth(FileSelectionList.CRFlagColNum, 35)
        self.twList.setColumnWidth(FileSelectionList.CBLFlagColNum, 35)
        self.twList.setColumnWidth(FileSelectionList.readonlyColNum, 35)
        self.twList.setColumnWidth(FileSelectionList.typeColNum, 45)
        if self.twList.columnWidth(FileSelectionList.fileColNum) > 250:
            self.twList.setColumnWidth(FileSelectionList.fileColNum, 250)
        if self.twList.columnWidth(FileSelectionList.folderColNum) > 200:
            self.twList.setColumnWidth(FileSelectionList.folderColNum, 200)
Exemple #4
0
    def addPathList(self, pathlist):

        filelist = utils.get_recursive_filelist(pathlist)
        # we now have a list of files to add

        # Prog dialog on Linux flakes out for small range, so scale up
        progdialog = QProgressDialog("",
                                     "Cancel",
                                     0,
                                     len(filelist),
                                     parent=self)
        progdialog.setWindowTitle("Adding Files")
        progdialog.setWindowModality(Qt.ApplicationModal)
        progdialog.setMinimumDuration(300)
        centerWindowOnParent(progdialog)
        #QCoreApplication.processEvents()
        #progdialog.show()

        QCoreApplication.processEvents()
        firstAdded = None
        self.twList.setSortingEnabled(False)
        for idx, f in enumerate(filelist):
            QCoreApplication.processEvents()
            if progdialog.wasCanceled():
                break
            progdialog.setValue(idx + 1)
            progdialog.setLabelText(f)
            centerWindowOnParent(progdialog)
            QCoreApplication.processEvents()
            row = self.addPathItem(f)
            if firstAdded is None and row is not None:
                firstAdded = row

        progdialog.hide()
        QCoreApplication.processEvents()

        if firstAdded is not None:
            self.twList.selectRow(firstAdded)
        else:
            if len(pathlist) == 1 and os.path.isfile(pathlist[0]):
                QMessageBox.information(
                    self, self.tr("File Open"),
                    self.tr(
                        "Selected file doesn't seem to be a comic archive."))
            else:
                QMessageBox.information(
                    self, self.tr("File/Folder Open"),
                    self.tr("No readable comic archives were found."))

        self.twList.setSortingEnabled(True)

        # Adjust column size
        self.twList.resizeColumnsToContents()
        self.twList.setColumnWidth(FileSelectionList.CRFlagColNum, 35)
        self.twList.setColumnWidth(FileSelectionList.CBLFlagColNum, 35)
        self.twList.setColumnWidth(FileSelectionList.readonlyColNum, 35)
        self.twList.setColumnWidth(FileSelectionList.typeColNum, 45)
        if self.twList.columnWidth(FileSelectionList.fileColNum) > 250:
            self.twList.setColumnWidth(FileSelectionList.fileColNum, 250)
        if self.twList.columnWidth(FileSelectionList.folderColNum) > 200:
            self.twList.setColumnWidth(FileSelectionList.folderColNum, 200)
Exemple #5
0
    def addPathList(self, pathlist):

        filelist = utils.get_recursive_filelist(pathlist)
        # we now have a list of files to add

        progdialog = QProgressDialog("", "Cancel", 0, len(filelist), self)
        progdialog.setWindowTitle("Adding Files")
        # progdialog.setWindowModality(Qt.WindowModal)
        progdialog.setWindowModality(Qt.ApplicationModal)
        progdialog.show()

        firstAdded = None
        self.twList.setSortingEnabled(False)
        for idx, f in enumerate(filelist):
            QCoreApplication.processEvents()
            if progdialog.wasCanceled():
                break
            progdialog.setValue(idx)
            progdialog.setLabelText(f)
            centerWindowOnParent(progdialog)
            QCoreApplication.processEvents()
            row = self.addPathItem(f)
            if firstAdded is None and row is not None:
                firstAdded = row

        progdialog.close()
        if (self.settings.show_no_unrar_warning and
                self.settings.unrar_exe_path == "" and
                self.settings.rar_exe_path == "" and
                platform.system() != "Windows"):
            for f in filelist:
                ext = os.path.splitext(f)[1].lower()
                if ext == ".rar" or ext == ".cbr":
                    checked = OptionalMessageDialog.msg(self, "No unrar tool",
                                                        """
                            It looks like you've tried to open at least one CBR or RAR file.<br><br>
                            In order for ComicTagger to read this kind of file, you will have to configure
                            the location of the unrar tool in the settings.  Until then, ComicTagger
                            will not be able recognize these kind of files.
                            """
                                                        )
                    self.settings.show_no_unrar_warning = not checked
                    break

        if firstAdded is not None:
            self.twList.selectRow(firstAdded)
        else:
            if len(pathlist) == 1 and os.path.isfile(pathlist[0]):
                QMessageBox.information(self, self.tr("File Open"), self.tr(
                    "Selected file doesn't seem to be a comic archive."))
            else:
                QMessageBox.information(
                    self,
                    self.tr("File/Folder Open"),
                    self.tr("No comic archives were found."))

        self.twList.setSortingEnabled(True)

        # Adjust column size
        self.twList.resizeColumnsToContents()
        self.twList.setColumnWidth(FileSelectionList.CRFlagColNum, 35)
        self.twList.setColumnWidth(FileSelectionList.CBLFlagColNum, 35)
        self.twList.setColumnWidth(FileSelectionList.readonlyColNum, 35)
        self.twList.setColumnWidth(FileSelectionList.typeColNum, 45)
        if self.twList.columnWidth(FileSelectionList.fileColNum) > 250:
            self.twList.setColumnWidth(FileSelectionList.fileColNum, 250)
        if self.twList.columnWidth(FileSelectionList.folderColNum) > 200:
            self.twList.setColumnWidth(FileSelectionList.folderColNum, 200)
Exemple #6
0
    def load_files(self, file_list):
        # Progress dialog on Linux flakes out for small range, so scale up
        dialog = QtWidgets.QProgressDialog("",
                                           "Cancel",
                                           0,
                                           len(file_list),
                                           parent=self)
        dialog.setWindowTitle("Reading Comics")
        dialog.setWindowModality(QtCore.Qt.ApplicationModal)
        dialog.setMinimumDuration(300)
        dialog.setMinimumWidth(400)
        centerWindowOnParent(dialog)

        comic_list = []
        max_name_len = 2
        for filename in file_list:
            QtCore.QCoreApplication.processEvents()
            if dialog.wasCanceled():
                break
            dialog.setValue(dialog.value() + 1)
            dialog.setLabelText(filename)
            ca = ComicArchive(
                filename,
                self.settings.rar_exe_path,
                default_image_path=
                "/home/timmy/build/source/comictagger-test/comictaggerlib/graphics/nocover.png",
            )
            if ca.seemsToBeAComicArchive() and ca.hasMetadata(self.style):
                fmt_str = "{{0:{0}}}".format(max_name_len)
                print(fmt_str.format(filename) + "\r", end="", file=sys.stderr)
                sys.stderr.flush()
                md = ca.readMetadata(self.style)
                cover = ca.getPage(0)
                comic_list.append((make_key(md), filename, md, cover))
                max_name_len = len(filename)
        print()

        comic_list.sort(key=itemgetter(0), reverse=False)

        # look for duplicate blocks
        dupe_set = list()
        prev_key = ""

        dialog.setWindowTitle("Finding Duplicates")
        dialog.setMaximum(len(comic_list))
        dialog.setValue(dialog.minimum())

        set_list = list()
        for new_key, filename, md, cover in comic_list:
            dialog.setValue(dialog.value() + 1)
            QtCore.QCoreApplication.processEvents()
            if dialog.wasCanceled():
                break
            dialog.setLabelText(filename)

            # if the new key same as the last, add to to dupe set
            if new_key == prev_key:
                dupe_set.append((filename, md, cover))
            # else we're on a new potential block
            else:
                # only add if the dupe list has 2 or more
                if len(dupe_set) > 1:
                    set_list.append(dupe_set)
                dupe_set = list()
                dupe_set.append((filename, md, cover))

            prev_key = new_key

        # Final dupe_set
        if len(dupe_set) > 1:
            set_list.append(dupe_set)

        for d_set in set_list:
            new_set = list()
            for filename, md, cover in d_set:
                new_set.append(Duplicate(filename, md, cover))
            self.dupe_set_list.append(new_set)

        self.dupe_set_qlist.setModel(Tree(self.dupe_set_list))
        dialog.close()