File indexing completed on 2024-04-28 16:26:14

0001 /******************************************************************************
0002   Copyright (C) 2009-2011 by Holger Danielsson (holger.danielsson@versanet.de)
0003  ******************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or modify  *
0008  *   it under the terms of the GNU General Public License as published by  *
0009  *   the Free Software Foundation; either version 2 of the License, or     *
0010  *   (at your option) any later version.                                   *
0011  *                                                                         *
0012  ***************************************************************************/
0013 
0014 
0015 #ifndef PDFDIALOG_H
0016 #define PDFDIALOG_H
0017 
0018 #include <config.h>
0019 
0020 #if LIBPOPPLER_AVAILABLE
0021 #include <poppler-qt5.h>
0022 #endif
0023 
0024 #include <QBitArray>
0025 #include <QCheckBox>
0026 #include <QDialog>
0027 #include <QMap>
0028 #include <QProcess>
0029 #include <QTemporaryDir>
0030 #include <QVector>
0031 
0032 #include "widgets/outputview.h"
0033 #include "widgets/categorycombobox.h"
0034 #include "kiletool_enums.h"
0035 #include "kiletoolmanager.h"
0036 
0037 #include "ui_pdfdialog_base.h"
0038 
0039 class QDialogButtonBox;
0040 class QLineEdit;
0041 class KProcess;
0042 class KileErrorHandler;
0043 
0044 namespace KileDialog
0045 {
0046 
0047 class PdfDialog : public QDialog
0048 {
0049     Q_OBJECT
0050 
0051 public:
0052     PdfDialog(QWidget *parent,
0053               const QString &texfilename, const QString &startdir,
0054               const QString &latexextensions,
0055               KileTool::Manager *manager,
0056               KileErrorHandler *errorHandler, KileWidget::OutputView *output);
0057     ~PdfDialog();
0058 
0059 Q_SIGNALS:
0060     void output(const QString &);
0061 
0062 private Q_SLOTS:
0063     void slotInputfileChanged(const QString &text);
0064     void slotOutputfileChanged(const QString &text);
0065     void slotTaskChanged(int index);
0066     void slotOverwriteChanged(int state);
0067     void slotExecute();
0068     void slotShowHelp();
0069     void slotTabwidgetChanged(int index);
0070     void slotPrintingClicked();
0071     void slotAllClicked();
0072     void slotPermissionClicked(bool);
0073 
0074     void slotProcessOutput();
0075     void slotProcessExited(int exitCode, QProcess::ExitStatus exitStatus);
0076 
0077 private:
0078     enum PDF_Permission { AllowModify = 1,        // Allows to modify the document
0079                           AllowCopy = 2,          // Allows to copy the document
0080                           AllowPrint = 4,         // Allows to print the document
0081                           AllowNotes = 8,         // Allows to add annotations to the document
0082                           AllowFillForms = 16     // Allows to fill the forms in the document
0083                         };
0084 
0085     enum PDF_Action { PDF_PAGE_EMPTY=0,        PDF_PAGE_DUPLICATE=1, PDF_2UP=2,          PDF_2UP_LANDSCAPE=3,
0086                       PDF_4UP=4,               PDF_4UP_LANDSCAPE=5,  PDF_EVEN=6,         PDF_ODD=7,
0087                       PDF_EVEN_REV=8,          PDF_ODD_REV=9,        PDF_REVERSE=10,     PDF_DECRYPT=11,
0088                       PDF_SELECT=12,           PDF_DELETE=13,
0089                       PDF_PDFTK_BACKGROUND=14, PDF_PDFTK_BGCOLOR=15, PDF_PDFTK_STAMP=16,
0090                       PDF_PDFTK_FREE=17,       PDF_PDFPAGES_FREE=18
0091                     };
0092 
0093     enum PDF_ScriptMode { PDF_SCRIPTMODE_TOOLS=0,      PDF_SCRIPTMODE_ACTION=1,
0094                           PDF_SCRIPTMODE_PROPERTIES=2, PDF_SCRIPTMODE_PERMISSIONS=3,
0095 #if !LIBPOPPLER_AVAILABLE
0096                           PDF_SCRIPTMODE_NUMPAGES_PDFTK=4,
0097                           PDF_SCRIPTMODE_NUMPAGES_IMAGEMAGICK=5,
0098                           PDF_SCRIPTMODE_NUMPAGES_GHOSTSCRIPT=6
0099 #endif
0100                         };
0101 
0102     QString m_inputfile;
0103     QString m_outputfile;
0104     QStringList m_tasklist;
0105 
0106     void executeAction();
0107     void executeProperties();
0108     void executePermissions();
0109 
0110     bool checkParameter();
0111     bool checkProperties();
0112     bool checkPermissions();
0113     bool checkInputFile();
0114     bool checkPassword();
0115 
0116     bool isParameterTask(int task);
0117     bool isOverlayTask(int task);
0118     bool isBackgroundColor(int task);
0119     bool isFreeTask(int task);
0120 
0121     QString buildActionCommand();
0122     QString buildLatexFile(const QString &param);
0123     QString buildPdfBackgroundFile(QColor *color);
0124     QString buildPageRange(int type);
0125     QString buildPageList(bool even);
0126     QString buildReversPageList(bool even);
0127     QString buildSelectPageList();
0128     QString buildDeletePageList();
0129 
0130     int searchPages(QBitArray *arr, int page, int lastpage, bool value);
0131     QString getOutfileName(const QString &infile);
0132     void showError(const QString &text);
0133 
0134     void executeScript(const QString &command, const QString &dir, int scriptmode);
0135     void showLogs(const QString &title, const QString &inputfile, const QString &param);
0136 
0137     void initUtilities();
0138     void finishPdfAction(bool state);
0139     void runViewer();
0140     void updateDialog();
0141     void updateOwnerPassword(bool infile_exists);
0142     void updateToolsInfo();
0143     void updateTasks();
0144     int taskIndex();
0145     void clearDocumentInfo();
0146     void setPermissions(bool print,bool other);
0147     QString readPermissions();
0148     void setNumberOfPages(int numpages);
0149 
0150 #if LIBPOPPLER_AVAILABLE
0151     QSize allPagesSize(Poppler::Document *doc);
0152     bool isAllowed(Poppler::Document *doc, PDF_Permission permission) const;
0153 #endif
0154 
0155     void pdfParser(const QString &filename);
0156 
0157     QString m_startdir;
0158     KileTool::Manager *m_manager;
0159     KileErrorHandler *m_errorHandler;
0160     KileWidget::OutputView *m_output;
0161     KileWidget::CategoryComboBox *m_cbTask;
0162 
0163     int m_scriptmode;
0164     QString m_outputtext;
0165     bool m_execLatex;
0166     QString m_param;
0167     bool m_scriptrunning;
0168 
0169     QTemporaryDir *m_tempdir;
0170     QStringList m_move_filelist;
0171 
0172     bool m_poppler;
0173     bool m_pdftk;
0174     bool m_pdfpages;
0175 
0176     int  m_numpages;
0177     bool  m_encrypted;
0178     QSize m_pagesize;
0179 
0180     QStringList m_pdfInfoKeys;
0181     QMap<QString,QString> m_pdfInfo;
0182     QMap<QString,QLineEdit *> m_pdfInfoWidget;
0183     QMap<QString,QString> m_pdfInfoPdftk;
0184 
0185     QVector<int> m_pdfPermissionKeys;
0186     QVector<QCheckBox *> m_pdfPermissionWidgets;
0187     QVector<QString> m_pdfPermissionPdftk;
0188     QVector<bool> m_pdfPermissionState;
0189 
0190     KProcess* m_proc;
0191 
0192     QPushButton *m_rearrangeButton;
0193     QDialogButtonBox *m_buttonBox;
0194     Ui::PdfDialog m_PdfDialog;
0195 
0196 #if !LIBPOPPLER_AVAILABLE
0197     int m_imagemagick;
0198     int m_numpagesMode;
0199     void determineNumberOfPages(const QString &filename, bool askForPasswor);
0200     void readNumberOfPages(int scriptmode, const QString &output);
0201     bool readEncryption(const QString &filename);
0202 #endif
0203 };
0204 
0205 }
0206 
0207 #endif