Commit 1ae4accf authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

CPMT: Fix some url issues and switch to using QFileSystemWatcher for updating pages.

The filesystemwatcher allows us to also track whether files have been deleted/changed.
parent b734108f
......@@ -28,7 +28,7 @@ import shutil
import enum
from math import floor
import xml.etree.ElementTree as ET
from PyQt5.QtCore import QElapsedTimer, QSize, Qt, QRect
from PyQt5.QtCore import QElapsedTimer, QSize, Qt, QRect, QFileSystemWatcher
from PyQt5.QtGui import QStandardItem, QStandardItemModel, QImage, QIcon, QPixmap, QFontMetrics, QPainter, QPalette, QFont
from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QListView, QToolButton, QMenu, QAction, QPushButton, QSpacerItem, QSizePolicy, QWidget, QAbstractItemView, QProgressDialog, QDialog, QFileDialog, QDialogButtonBox, qApp, QSplitter, QSlider, QLabel, QStyledItemDelegate, QStyle, QMessageBox
import math
......@@ -197,6 +197,7 @@ class comics_project_manager_docker(DockWidget):
setupDictionary = {}
stringName = i18n("Comics Manager")
projecturl = None
pagesWatcher = None
def __init__(self):
super().__init__()
......@@ -332,8 +333,9 @@ class comics_project_manager_docker(DockWidget):
buttonLayout.addWidget(self.btn_project_url)
self.page_viewer_dialog = comics_project_page_viewer.comics_project_page_viewer()
Application.notifier().imageSaved.connect(self.slot_check_for_page_update)
self.pagesWatcher = QFileSystemWatcher()
self.pagesWatcher.fileChanged.connect(self.slot_check_for_page_update)
buttonLayout.addItem(QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.MinimumExpanding))
......@@ -368,6 +370,8 @@ class comics_project_manager_docker(DockWidget):
def fill_pages(self):
self.loadingPages = True
self.pagesModel.clear()
if len(self.pagesWatcher.files())>0:
self.pagesWatcher.removePaths(self.pagesWatcher.files())
pagesList = []
if "pages" in self.setupDictionary.keys():
pagesList = self.setupDictionary["pages"]
......@@ -377,6 +381,7 @@ class comics_project_manager_docker(DockWidget):
progress.setWindowTitle(i18n("Loading Pages..."))
for url in pagesList:
absurl = os.path.join(self.projecturl, url)
relative = os.path.relpath(absurl, self.projecturl)
if (os.path.exists(absurl)):
#page = Application.openDocument(absurl)
page = zipfile.ZipFile(absurl, "r")
......@@ -391,11 +396,12 @@ class comics_project_manager_docker(DockWidget):
pageItem.setEditable(False)
pageItem.setIcon(QIcon(QPixmap.fromImage(thumbnail)))
pageItem.setData(dataList[1], role = CPE.DESCRIPTION)
pageItem.setData(url, role = CPE.URL)
pageItem.setData(relative, role = CPE.URL)
self.pagesWatcher.addPath(absurl)
pageItem.setData(dataList[2], role = CPE.KEYWORDS)
pageItem.setData(dataList[3], role = CPE.LASTEDIT)
pageItem.setData(dataList[4], role = CPE.EDITOR)
pageItem.setToolTip(url)
pageItem.setToolTip(relative)
page.close()
self.pagesModel.appendRow(pageItem)
progress.setValue(progress.value() + 1)
......@@ -550,6 +556,7 @@ class comics_project_manager_docker(DockWidget):
newPageItem.setText(dataList[0].replace("_", " "))
newPageItem.setData(dataList[1], role = CPE.DESCRIPTION)
newPageItem.setData(relative, role = CPE.URL)
self.pagesWatcher.addPath(url)
newPageItem.setData(dataList[2], role = CPE.KEYWORDS)
newPageItem.setData(dataList[3], role = CPE.LASTEDIT)
newPageItem.setData(dataList[4], role = CPE.EDITOR)
......@@ -667,6 +674,7 @@ class comics_project_manager_docker(DockWidget):
while os.path.exists(absoluteUrl) is False:
qApp.processEvents()
self.pagesWatcher.addPath(absoluteUrl)
newPage.close()
# add item to page.
......@@ -821,6 +829,10 @@ class comics_project_manager_docker(DockWidget):
if relUrl in self.setupDictionary["pages"]:
index = self.pagesModel.index(self.setupDictionary["pages"].index(relUrl), 0)
if index.isValid():
if os.path.exists(url) is False:
# we cannot check from here whether the file in question has been renamed or deleted.
self.pagesModel.removeRow(index.row())
return
pageItem = self.pagesModel.itemFromIndex(index)
page = zipfile.ZipFile(url, "r")
dataList = self.get_description_and_title(page.read("documentinfo.xml"))
......@@ -830,7 +842,7 @@ class comics_project_manager_docker(DockWidget):
pageItem.setIcon(QIcon(QPixmap.fromImage(thumbnail)))
pageItem.setText(dataList[0])
pageItem.setData(dataList[1], role = CPE.DESCRIPTION)
pageItem.setData(url, role = CPE.URL)
pageItem.setData(relUrl, role = CPE.URL)
pageItem.setData(dataList[2], role = CPE.KEYWORDS)
pageItem.setData(dataList[3], role = CPE.LASTEDIT)
pageItem.setData(dataList[4], role = CPE.EDITOR)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment