Port of Revision 443451

Refractor the text export into the kviewshell.
This has the additional benefit that text export is now also available for DjVu files.

svn path=/trunk/KDE/kdegraphics/kdvi/; revision=443454
This commit is contained in:
Wilfried Huss 2005-08-06 11:20:54 +00:00
parent 4a9320d08e
commit 3ff30b06a0
4 changed files with 6 additions and 59 deletions

View file

@ -74,7 +74,6 @@ KDVIMultiPage::KDVIMultiPage(QWidget *parentWidget, const char *widgetName, QObj
new KAction(i18n("Enable All Warnings && Messages"), 0, this, SLOT(doEnableWarnings()), actionCollection(), "enable_msgs");
exportPSAction = new KAction(i18n("PostScript..."), 0, &DVIRenderer, SLOT(exportPS()), actionCollection(), "export_postscript");
exportPDFAction = new KAction(i18n("PDF..."), 0, &DVIRenderer, SLOT(exportPDF()), actionCollection(), "export_pdf");
exportTextAction = new KAction(i18n("Text..."), 0, this, SLOT(doExportText()), actionCollection(), "export_text");
KStdAction::tipOfDay(this, SLOT(showTip()), actionCollection(), "help_tipofday");
@ -95,7 +94,6 @@ KDVIMultiPage::~KDVIMultiPage()
delete embedPSAction;
delete exportPSAction;
delete exportPDFAction;
delete exportTextAction;
writeSettings();
Prefs::writeConfig();
@ -410,7 +408,6 @@ void KDVIMultiPage::enableActions(bool b)
docInfoAction->setEnabled(b);
exportPSAction->setEnabled(b);
exportPDFAction->setEnabled(b);
exportTextAction->setEnabled(b);
setEmbedPostScriptAction();
}

View file

@ -88,7 +88,6 @@ private:
KAction *docInfoAction;
KAction *embedPSAction;
KAction *exportPDFAction;
KAction *exportTextAction;
KAction *exportPSAction;
};

View file

@ -66,53 +66,5 @@ void KDVIMultiPage::doExportText(void)
"warning_export_to_text_may_not_work") == KMessageBox::Cancel)
return;
// Generate a suggestion for a reasonable file name
QString suggestedName = DVIRenderer.dviFile->filename;
suggestedName = suggestedName.left(suggestedName.find(".")) + ".txt";
QString fileName = KFileDialog::getSaveFileName(suggestedName, i18n("*.txt|Plain Text (Latin 1) (*.txt)"), scrollView(), i18n("Export File As"));
if (fileName.isEmpty())
return;
QFileInfo finfo(fileName);
if (finfo.exists()) {
int r = KMessageBox::warningContinueCancel (scrollView(), i18n("The file %1\nexists. Do you want to overwrite that file?").arg(fileName),
i18n("Overwrite File"), i18n("Overwrite"));
if (r == KMessageBox::Cancel)
return;
}
QFile textFile(fileName);
textFile.open( QIODevice::WriteOnly );
QTextStream stream( &textFile );
Q3ProgressDialog progress( i18n("Exporting to text..."), i18n("Abort"), DVIRenderer.totalPages(), scrollView(), "export_text_progress", TRUE );
progress.setMinimumDuration(300);
RenderedDocumentPagePixmap dummyPage;
dummyPage.resize(1,1);
for(int page=1; page <= DVIRenderer.totalPages(); page++) {
progress.setProgress( page );
// Funny. The manual to QT tells us that we need to call
// qApp->processEvents() regularly to keep the application from
// freezing. However, the application crashes immediately if we
// uncomment the following line and works just fine as it is. Wild
// guess: Could that be related to the fact that we are linking
// agains qt-mt?
// qApp->processEvents();
if ( progress.wasCanceled() )
break;
dummyPage.setPageNumber(page);
DVIRenderer.drawPage(100.0, &dummyPage); // We gracefully ingore any errors (bad dvi-file, etc.) which may occur during draw_page()
for(int i=0; i<dummyPage.textBoxList.size(); i++)
stream << dummyPage.textBoxList[i].text << endl;
}
// Switch off the progress dialog, etc.
progress.setProgress( DVIRenderer.totalPages() );
return;
KMultiPage::doExportText();
}

View file

@ -1,12 +1,11 @@
<!DOCTYPE kpartgui>
<kpartgui name="kdvi_part" version="3">
<kpartgui name="kdvi_part" version="4">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
<Action name="info_dvi" group="file_print"/>
<Menu name="export" group="file_save" ><text>Export As</text>
<Action name="export_postscript"/>
<Action name="export_pdf"/>
<Action name="export_text"/>
<Action name="info_dvi" group="info_merge"/>
<Menu name="export" group="print_merge" ><text>Export As</text>
<Action name="export_postscript" group="export_merge"/>
<Action name="export_pdf" group="export_merge"/>
</Menu>
</Menu>