[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    export-to-pdf as command-line - Patch Review
From:       Ganesh Paramasivam <ganesh () crystalfab ! com>
Date:       2009-03-16 19:37:15
Message-ID: 9ecf537e0903161225x6c1fa011o235a1db863179470 () mail ! gmail ! com
[Download RAW message or body]

Hi all,

Please find attached the patch file ( generated from SVN diff ). It's
still a work-in-progress.. I do have some questions. More details
follow.This patch has been tested on the latest koffice SVN repository
and compiles and runs as designed.

1.  This patch enables the ability to export to PDF from the
command-line. It adds 2 new command-line arguments - export-to-pdf and
output-pdf-file which are to be used as follows

kword path/to/odt --export-to-pdf
This would show a dialog to select the pdf-file-path.

kword path/to/odt --export-to-pdf --output-pdf-file=/path/to/output.pdf
There would be no dialog shown and the export happens automatically to
output.pdf

Changes have been made to add new slots in KoMainWindow.cpp and add
command-line processing for the new options in KoApplication.cpp.

I had thought about re-using the --print option for this but decided
other-wise purely for user intuitiveness. i.e the option clearly tells
what it does.

2.  Renamed slotPrintAndSave() in KoMainWindow.cpp to slotExportToPDF()
This was purely to make the function name obvious as to what it really does..

3.  Fix for the --print hang (???? ) -
In KoApplication.cpp the call to the KoMainWindow.show() happens only
if --print is not enabled..

if(!print)
   shell->show();

So the mainWindow remains hidden if the --print is enabled.
This line causes the preparePage() of KoPrintingDialog hang endlessly
at shape->waitUntilReady()...

I'm not aware of the main rendering and layout of KWord to exactly
understand as to why this happens... Any help would be greatly
appreciated... As of now the patch always does a shell->show()..

4.  The main application never exits if --print is called ( there is
no call to mainWindow->close() if --print is enabled ).. Is this the
required behavior.. The command-line description for --print says that
the application has to exit after printing..

- Ganesh

["export-as-pdf.patch" (application/octet-stream)]

Index: libs/main/KoMainWindow.cpp
===================================================================
--- libs/main/KoMainWindow.cpp	(revision 940146)
+++ libs/main/KoMainWindow.cpp	(working copy)
@@ -250,7 +250,7 @@
     d->m_exportPdf  = new KAction(i18n("Export as PDF..."), this);
     d->m_exportPdf->setIcon(KIcon("application-pdf"));
     actionCollection()->addAction("file_export_pdf", d->m_exportPdf);
-    connect(d->m_exportPdf, SIGNAL(triggered()), this, SLOT(slotPrintAndSave()));
+    connect(d->m_exportPdf, SIGNAL(triggered()), this, SLOT(slotExportToPDF()));
 
     d->m_sendfile = actionCollection()->addAction(KStandardAction::Mail,  \
"file_send_file", this, SLOT(slotEmailFile()));  
@@ -1331,7 +1331,7 @@
     delete preview;
 }
 
-void KoMainWindow::slotPrintAndSave()
+void KoMainWindow::slotExportToPDF()
 {
     if (!rootView())
         return;
@@ -1344,13 +1344,18 @@
     KUrl url(dialog.selectedUrl());
     // TODO warn when overwriting
 
+    slotExportToPDF(url.toLocalFile());
+}
+
+void KoMainWindow::slotExportToPDF(QString pdfFileName)
+{
     KoPrintJob *printJob = rootView()->createPrintJob();
     if (printJob == 0)
         return;
     d->applyDefaultSettings(printJob->printer());
 
     // TODO for remote files we have to first save locally and then upload.
-    printJob->printer().setOutputFileName(url.toLocalFile());
+    printJob->printer().setOutputFileName(pdfFileName);
     printJob->startPrinting(KoPrintJob::DeleteWhenDone);
 }
 
Index: libs/main/KoMainWindow.h
===================================================================
--- libs/main/KoMainWindow.h	(revision 940146)
+++ libs/main/KoMainWindow.h	(working copy)
@@ -243,8 +243,10 @@
      */
     virtual void slotFilePrint();
     virtual void slotFilePrintPreview();
-    virtual void slotPrintAndSave();
 
+    virtual void slotExportToPDF();
+    virtual void slotExportToPDF(QString fileName);
+
     /**
      * Show a dialog with author and document information.
      */
Index: libs/main/KoApplication.cpp
===================================================================
--- libs/main/KoApplication.cpp	(revision 940146)
+++ libs/main/KoApplication.cpp	(working copy)
@@ -72,6 +72,8 @@
     options.add("print", ki18n("Only print and exit"));
     options.add("template", ki18n("Open a new document with a template"));
     options.add("dpi <dpiX,dpiY>", ki18n("Override display DPI"));
+    options.add("export-as-pdf", ki18n("Only Export the document as a pdf file and \
exit")); +    options.add("output-pdf-file <filename>", ki18n("File-Name for \
                export-to-pdf"));
     KCmdLineArgs::addCmdLineOptions(options, ki18n("KOffice"), "koffice", "kde");
     return true;
 }
@@ -149,6 +151,8 @@
         QObject::disconnect(doc, SIGNAL(sigProgress(int)), shell, \
SLOT(slotProgress(int)));  } else {
         bool print = koargs->isSet("print");
+        bool exportAsPDF = koargs->isSet("export-as-pdf");
+	    QString pdfFileName = koargs->getOption("output-pdf-file");
         bool doTemplate = koargs->isSet("template");
         koargs->clear();
 
@@ -163,7 +167,7 @@
             if (doc) {
                 // show a shell asap
                 KoMainWindow *shell = new KoMainWindow(doc->componentData());
-                if (!print)
+                //if (!print &&  !exportAsPDF )
                     shell->show();
                 // are we just trying to open a template?
                 if (doTemplate) {
@@ -213,7 +217,13 @@
                         shell->slotFilePrint();
                         // delete shell; done by ~KoDocument
                         nPrinted++;
-                    } else {
+                    }else if(exportAsPDF) {
+			            if(pdfFileName == "")
+			               shell->slotExportToPDF();
+			            else
+			               shell->slotExportToPDF(pdfFileName);
+			            nPrinted++;
+		            }else {
                         // Normal case, success
                         n++;
                     }
@@ -224,7 +234,7 @@
                 }
             }
         }
-        if (print)
+        if (print || exportAsPDF)
             return nPrinted > 0;
         if (n == 0) // no doc, e.g. all URLs were malformed
             return false;



_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic