diff --git a/Pdf4QtDiff/main.cpp b/Pdf4QtDiff/main.cpp index 3f2c94c..4e505fd 100644 --- a/Pdf4QtDiff/main.cpp +++ b/Pdf4QtDiff/main.cpp @@ -16,6 +16,7 @@ // along with PDF4QT. If not, see . #include "pdfconstants.h" +#include "pdfdocumentreader.h" #include "mainwindow.h" #include @@ -44,5 +45,40 @@ int main(int argc, char *argv[]) pdfdiff::MainWindow mainWindow(nullptr); mainWindow.show(); + QStringList positionalArguments = parser.positionalArguments(); + + if (positionalArguments.size() >= 1) + { + bool leftDocumentIsOK = false; + bool rightDocumentIsOk = false; + + pdf::PDFDocumentReader reader(nullptr, [](bool* ok) { *ok = false; return QString(); }, true, false); + pdf::PDFDocument documentLeft = reader.readFromFile(positionalArguments.front()); + + if (reader.getReadingResult() == pdf::PDFDocumentReader::Result::OK) + { + leftDocumentIsOK = true; + mainWindow.setLeftDocument(std::move(documentLeft)); + } + + if (positionalArguments.size() >= 2) + { + pdf::PDFDocument documentRight = reader.readFromFile(positionalArguments[1]); + + if (reader.getReadingResult() == pdf::PDFDocumentReader::Result::OK) + { + rightDocumentIsOk = true; + mainWindow.setRightDocument(std::move(documentRight)); + } + } + + mainWindow.updateViewDocument(); + + if (leftDocumentIsOK && rightDocumentIsOk && mainWindow.canPerformOperation(pdfdiff::MainWindow::Operation::Compare)) + { + mainWindow.performOperation(pdfdiff::MainWindow::Operation::Compare); + } + } + return application.exec(); } diff --git a/Pdf4QtDiff/mainwindow.cpp b/Pdf4QtDiff/mainwindow.cpp index 41b3517..d3061a9 100644 --- a/Pdf4QtDiff/mainwindow.cpp +++ b/Pdf4QtDiff/mainwindow.cpp @@ -458,22 +458,7 @@ void MainWindow::performOperation(Operation operation) if (document) { clear(true, false); - m_leftDocument = std::move(*document); - - const size_t pageCount = m_leftDocument.getCatalog()->getPageCount(); - if (pageCount > 1) - { - m_settingsDockWidget->getLeftPageSelectionEdit()->setText(QString("1-%2").arg(pageCount)); - } - else if (pageCount == 1) - { - m_settingsDockWidget->getLeftPageSelectionEdit()->setText("1"); - } - else - { - m_settingsDockWidget->getLeftPageSelectionEdit()->clear(); - } - + setLeftDocument(std::move(*document)); updateViewDocument(); } @@ -489,22 +474,7 @@ void MainWindow::performOperation(Operation operation) if (document) { clear(false, true); - m_rightDocument = std::move(*document); - - const size_t pageCount = m_rightDocument.getCatalog()->getPageCount(); - if (pageCount > 1) - { - m_settingsDockWidget->getRightPageSelectionEdit()->setText(QString("1-%2").arg(pageCount)); - } - else if (pageCount == 1) - { - m_settingsDockWidget->getRightPageSelectionEdit()->setText("1"); - } - else - { - m_settingsDockWidget->getRightPageSelectionEdit()->clear(); - } - + setRightDocument(std::move(*document)); updateViewDocument(); } @@ -863,6 +833,44 @@ std::optional MainWindow::openDocument() return pdf::PDFDocument(); } +void MainWindow::setRightDocument(pdf::PDFDocument&& newRightDocument) +{ + m_rightDocument = newRightDocument; + + const size_t pageCount = m_rightDocument.getCatalog()->getPageCount(); + if (pageCount > 1) + { + m_settingsDockWidget->getRightPageSelectionEdit()->setText(QString("1-%2").arg(pageCount)); + } + else if (pageCount == 1) + { + m_settingsDockWidget->getRightPageSelectionEdit()->setText("1"); + } + else + { + m_settingsDockWidget->getRightPageSelectionEdit()->clear(); + } +} + +void MainWindow::setLeftDocument(pdf::PDFDocument&& newLeftDocument) +{ + m_leftDocument = newLeftDocument; + + const size_t pageCount = m_leftDocument.getCatalog()->getPageCount(); + if (pageCount > 1) + { + m_settingsDockWidget->getLeftPageSelectionEdit()->setText(QString("1-%2").arg(pageCount)); + } + else if (pageCount == 1) + { + m_settingsDockWidget->getLeftPageSelectionEdit()->setText("1"); + } + else + { + m_settingsDockWidget->getLeftPageSelectionEdit()->clear(); + } +} + void MainWindow::onProgressStarted(pdf::ProgressStartupInfo info) { #ifdef WIN_TASKBAR_BUTTON diff --git a/Pdf4QtDiff/mainwindow.h b/Pdf4QtDiff/mainwindow.h index 02ef950..21dd3e7 100644 --- a/Pdf4QtDiff/mainwindow.h +++ b/Pdf4QtDiff/mainwindow.h @@ -84,6 +84,14 @@ public: virtual void showEvent(QShowEvent* event) override; virtual void closeEvent(QCloseEvent* event) override; + void setLeftDocument(pdf::PDFDocument&& newLeftDocument); + void setRightDocument(pdf::PDFDocument&& newRightDocument); + + void updateViewDocument(); + + bool canPerformOperation(Operation operation) const; + void performOperation(Operation operation); + private slots: void updateActions(); void onSelectionChanged(size_t currentIndex); @@ -100,9 +108,6 @@ private: void loadSettings(); void saveSettings(); - bool canPerformOperation(Operation operation) const; - void performOperation(Operation operation); - void setViewDocument(pdf::PDFDocument* document, bool updateCustomPageLayout); ComparedDocumentMapper::Mode getDocumentViewMode() const; @@ -115,7 +120,6 @@ private: void updateAll(bool resetFilters); void updateFilteredResult(); - void updateViewDocument(); void updateCustomPageLayout(); void updateOverlayTransparency(); diff --git a/RELEASES.txt b/RELEASES.txt index 9668c84..890f68d 100644 --- a/RELEASES.txt +++ b/RELEASES.txt @@ -1,12 +1,16 @@ CURRENT: + - Issue #182: PDF4QT Document Diff command line cmd line arguments ignored - Issue #173: errors loading file Echoplex.pdf - Issue #172: access keys are missing from most menu items/action text strings - Issue #168: When opening a PDF file or merging some PDF files, stamp will disappear. + - Issue #166: Adding images to PDF? - Issue #164: Taskbar icon not shown in linux mint. - Issue #163: Unable to render probably valid PDF - Issue #161: Can it be possible to trust a certificate like in acrobat? - Issue #159: Offer 4 AppImage one for each App [enhancement] - Issue #123: Alternative software rendering backend (Blend2D) + - Issue #42: Is REAL pdf text editing planned ? + - Issue #26: Add pictures in PDF files V: 1.3.7 10.1.2024 - Issue #142: Cannot reach the top