From a9bb5b7c951bd31c7dec8e36f274041a70a95fe8 Mon Sep 17 00:00:00 2001 From: Sune Vuorela Date: Wed, 19 Jun 2024 12:05:45 +0000 Subject: [PATCH] Replace unsigned open document with signed Rather than opening a new window/tab with an extra document when signing a document, replace current active unsigned document with the signed version. At least for some users, including me when testing, it gives annoyance or confusion. --- part/pageview.cpp | 2 +- part/pageview.h | 7 ++++++- part/pageviewannotator.cpp | 2 +- part/pageviewannotator.h | 7 ++++++- part/part.cpp | 8 +------- part/part.h | 6 ++++++ part/signaturepartutils.cpp | 2 +- shell/shell.cpp | 17 +++++++++++++++++ shell/shell.h | 12 ++++++++++++ 9 files changed, 51 insertions(+), 12 deletions(-) diff --git a/part/pageview.cpp b/part/pageview.cpp index 70a13c471..8178966a1 100644 --- a/part/pageview.cpp +++ b/part/pageview.cpp @@ -783,7 +783,7 @@ void PageView::setupActions(KActionCollection *ac) } }); connect(d->annotator, &PageViewAnnotator::toolActive, d->mouseAnnotation, &MouseAnnotation::reset); - connect(d->annotator, &PageViewAnnotator::requestOpenFile, this, &PageView::requestOpenFile); + connect(d->annotator, &PageViewAnnotator::requestOpenNewlySignedFile, this, &PageView::requestOpenNewlySignedFile); d->annotator->setupActions(ac); } diff --git a/part/pageview.h b/part/pageview.h index 8093e5d90..92773d65e 100644 --- a/part/pageview.h +++ b/part/pageview.h @@ -143,7 +143,12 @@ Q_SIGNALS: void escPressed(); void fitWindowToPage(const QSize pageViewPortSize, const QSize pageSize); void triggerSearch(const QString &text); - void requestOpenFile(const QString &filePath, int pageNumber); + /** + * Requests opening of a newly signed file + * \param filePath path to signed file + * \param pageNumber page to show (1-indexed) + */ + void requestOpenNewlySignedFile(const QString &filePath, int pageNumber); protected: bool event(QEvent *event) override; diff --git a/part/pageviewannotator.cpp b/part/pageviewannotator.cpp index 365f1561e..068d3e8fe 100644 --- a/part/pageviewannotator.cpp +++ b/part/pageviewannotator.cpp @@ -1043,7 +1043,7 @@ QRect PageViewAnnotator::performRouteMouseOrTabletEvent(const AnnotatorEngine::E if (!newFilePath.isEmpty()) { const bool success = static_cast(m_engine)->sign(newFilePath); if (success) { - Q_EMIT requestOpenFile(newFilePath, m_lockedItem->pageNumber() + 1); + Q_EMIT requestOpenNewlySignedFile(newFilePath, m_lockedItem->pageNumber() + 1); } else { KMessageBox::error(m_pageView, i18nc("%1 is a file path", "Could not sign. Invalid certificate password or could not write to '%1'", newFilePath)); } diff --git a/part/pageviewannotator.h b/part/pageviewannotator.h index 25780cd51..5a6f90f66 100644 --- a/part/pageviewannotator.h +++ b/part/pageviewannotator.h @@ -140,7 +140,12 @@ Q_SIGNALS: * This signal is emitted whenever an annotation tool is activated or all the tools get deactivated */ void toolActive(bool active); - void requestOpenFile(const QString &filePath, int pageNumber); + /** + * Requests opening of a newly signed file + * \param filePath path to signed file + * \param pageNumber page to show (1-indexed) + */ + void requestOpenNewlySignedFile(const QString &filePath, int pageNumber); private: void reparseBuiltinToolsConfig(); diff --git a/part/part.cpp b/part/part.cpp index df19fad6c..73f56dc55 100644 --- a/part/part.cpp +++ b/part/part.cpp @@ -504,13 +504,7 @@ Part::Part(QObject *parent, const QVariantList &args) connect(m_miniBar, &MiniBar::forwardKeyPressEvent, m_pageView, &PageView::externalKeyPressEvent); connect(m_pageView.data(), &PageView::escPressed, m_findBar, &FindBar::resetSearch); connect(m_pageNumberTool, &MiniBar::forwardKeyPressEvent, m_pageView, &PageView::externalKeyPressEvent); - connect(m_pageView.data(), &PageView::requestOpenFile, this, [this](const QString &filePath, int pageNumber) { - // We cheat a bit here reusing the urlsDropped signal, but at the end the output is the same, we want to open some files - // urlsDropped should have just had a different name - QUrl u = QUrl::fromLocalFile(filePath); - u.setFragment(QStringLiteral("page=%1").arg(pageNumber)); - Q_EMIT urlsDropped({u}); - }); + connect(m_pageView.data(), &PageView::requestOpenNewlySignedFile, this, &Part::requestOpenNewlySignedFile); connect(m_reviewsWidget.data(), &Reviews::openAnnotationWindow, m_pageView.data(), &PageView::openAnnotationWindow); diff --git a/part/part.h b/part/part.h index fde535ced..e54b01b0d 100644 --- a/part/part.h +++ b/part/part.h @@ -193,6 +193,12 @@ Q_SIGNALS: void mimeTypeChanged(const QMimeType &mimeType); void urlsDropped(const QList &urls); void fitWindowToPage(const QSize pageViewPortSize, const QSize pageSize); + /** + * Request to open a newly signed file + * \param path file to open + * \param pageNumber page to show (1-indexed) + */ + void requestOpenNewlySignedFile(const QString &path, int pageNumber); protected: // reimplemented from KParts::ReadWritePart diff --git a/part/signaturepartutils.cpp b/part/signaturepartutils.cpp index c8df9e3f5..f40a3cab2 100644 --- a/part/signaturepartutils.cpp +++ b/part/signaturepartutils.cpp @@ -469,7 +469,7 @@ void signUnsignedSignature(const Okular::FormFieldSignature *form, PageView *pag if (!newFilePath.isEmpty()) { const bool success = form->sign(data, newFilePath); if (success) { - Q_EMIT pageView->requestOpenFile(newFilePath, form->page()->number() + 1); + Q_EMIT pageView->requestOpenNewlySignedFile(newFilePath, form->page()->number() + 1); } else { KMessageBox::error(pageView, i18nc("%1 is a file path", "Could not sign. Invalid certificate password or could not write to '%1'", newFilePath)); } diff --git a/shell/shell.cpp b/shell/shell.cpp index 6865846d8..0ff9efebd 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -416,6 +416,22 @@ bool Shell::openDocument(const QString &urlString, const QString &serializedOpti return openDocument(QUrl(urlString), serializedOptions); } +void Shell::openNewlySignedFile(const QString &path, int pageNumber) +{ + // for now, this function just applies the "replace current document" + // strategy for opening. + // Given signing is slightly closer to annotating and saving, the over + // all user experience should not be that different + // The fact that we get a different file out of saving is a bit of a + // implementation detail that shouldn't leak that much onto the users + QUrl url = QUrl::fromLocalFile(path); + url.setFragment(QStringLiteral("page=%1").arg(pageNumber)); + + const int activeTab = m_tabWidget->currentIndex(); + KParts::ReadWritePart *const activePart = m_tabs[activeTab].part; + activePart->openUrl(url); +} + bool Shell::canOpenDocs(int numDocs, int desktop) { if (m_tabs.size() <= 0 || numDocs <= 0 || m_unique) { @@ -995,6 +1011,7 @@ void Shell::connectPart(const KParts::ReadWritePart *part) connect(part, SIGNAL(mimeTypeChanged(QMimeType)), this, SLOT(setTabIcon(QMimeType))); // clazy:exclude=old-style-connect connect(part, SIGNAL(urlsDropped(QList)), this, SLOT(handleDroppedUrls(QList))); // clazy:exclude=old-style-connect // clang-format off + connect(part, SIGNAL(requestOpenNewlySignedFile(QString,int)), this, SLOT(openNewlySignedFile(QString,int))); // clazy:exclude=old-style-connect // Otherwise the QSize,QSize gets turned into QSize, QSize that is not normalized signals and is slightly slower connect(part, SIGNAL(fitWindowToPage(QSize,QSize)), this, SLOT(slotFitWindowToPage(QSize,QSize))); // clazy:exclude=old-style-connect // clang-format on diff --git a/shell/shell.h b/shell/shell.h index 3ac9709a4..4e7738857 100644 --- a/shell/shell.h +++ b/shell/shell.h @@ -128,6 +128,18 @@ private Q_SLOTS: void setCloseEnabled(bool enabled); void setTabIcon(const QMimeType &mimeType); void handleDroppedUrls(const QList &urls); + /** + * Opens of a newly signed file + * + * This is separated out from the "normal" open url + * to be allowed to have different rules for this + * (rules could be open in tab, open in new window, replace + * current document) + * + * \param filePath path to signed file + * \param pageNumber page to show (1-indexed) + */ + void openNewlySignedFile(const QString &path, int pageNumber); // Tab event handlers void setActiveTab(int tab);