mirror of
https://invent.kde.org/graphics/okular
synced 2024-10-04 06:59:32 +00:00
move the FilePrinterPreview to the kpart (no need for it to be in the core library)
svn path=/trunk/KDE/kdegraphics/okular/; revision=744225
This commit is contained in:
parent
5b01430bb0
commit
bd294e1de6
|
@ -88,7 +88,7 @@ IF(APPLE)
|
|||
SET(OKULAR_IOKIT "-framework IOKit" CACHE STRING "Apple IOKit framework")
|
||||
ENDIF(APPLE)
|
||||
|
||||
target_link_libraries(okularcore ${OKULAR_IOKIT} ${KDE4_KIO_LIBS} ${KDE4_KUTILS_LIBS} ${KDE4_PHONON_LIBRARY} ${MATH_LIB} ${KDE4_THREADWEAVER_LIBRARY} )
|
||||
target_link_libraries(okularcore ${OKULAR_IOKIT} ${KDE4_KIO_LIBS} ${KDE4_PHONON_LIBRARY} ${MATH_LIB} ${KDE4_THREADWEAVER_LIBRARY} )
|
||||
|
||||
set_target_properties(okularcore PROPERTIES VERSION 1.0.0 SOVERSION 1 )
|
||||
|
||||
|
@ -118,6 +118,7 @@ set(okularpart_SRCS
|
|||
ui/annotationtools.cpp
|
||||
ui/annotationwidgets.cpp
|
||||
ui/bookmarklist.cpp
|
||||
ui/fileprinterpreview.cpp
|
||||
ui/findbar.cpp
|
||||
ui/formwidgets.cpp
|
||||
ui/ktreeviewsearchline.cpp
|
||||
|
@ -152,7 +153,7 @@ kde4_add_ui_files(okularpart_SRCS
|
|||
|
||||
kde4_add_plugin(okularpart ${okularpart_SRCS})
|
||||
|
||||
target_link_libraries(okularpart okularcore ${KDE4_KPARTS_LIBS} ${KDE4_KNEWSTUFF2_LIBS} ${MATH_LIB} ${BLITZ_LIBRARIES})
|
||||
target_link_libraries(okularpart okularcore ${KDE4_KPARTS_LIBS} ${KDE4_KUTILS_LIBS} ${KDE4_KNEWSTUFF2_LIBS} ${MATH_LIB} ${BLITZ_LIBRARIES})
|
||||
|
||||
install(TARGETS okularpart DESTINATION ${PLUGIN_INSTALL_DIR})
|
||||
|
||||
|
|
|
@ -25,11 +25,6 @@
|
|||
#include <KShell>
|
||||
#include <klocalsocket.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <kmimetypetrader.h>
|
||||
#include <kparts/part.h>
|
||||
#include <kpluginfactory.h>
|
||||
#include <kpluginloader.h>
|
||||
#include <kservice.h>
|
||||
#include <ktempdir.h>
|
||||
#include <kdebug.h>
|
||||
|
||||
|
@ -538,125 +533,4 @@ QStringList FilePrinter::optionCollateCopies( QPrinter &printer )
|
|||
return QStringList("-o") << "Collate=False";
|
||||
}
|
||||
|
||||
// This code copied from KPrintPreview by Alex Merry, adapted to do PS files instead of PDF
|
||||
|
||||
class Okular::FilePrinterPreviewPrivate
|
||||
{
|
||||
public:
|
||||
FilePrinterPreviewPrivate( FilePrinterPreview *host, const QString & _filename )
|
||||
: q(host)
|
||||
, mainWidget(new QWidget(host))
|
||||
, previewPart(0)
|
||||
, failMessage(0)
|
||||
{
|
||||
filename = _filename;
|
||||
}
|
||||
|
||||
void getPart();
|
||||
bool doPreview();
|
||||
void fail();
|
||||
|
||||
FilePrinterPreview *q;
|
||||
|
||||
QWidget *mainWidget;
|
||||
|
||||
QString filename;
|
||||
|
||||
KParts::ReadOnlyPart *previewPart;
|
||||
QWidget *failMessage;
|
||||
};
|
||||
|
||||
void FilePrinterPreviewPrivate::getPart()
|
||||
{
|
||||
if (previewPart) {
|
||||
kDebug(500) << "already got a part";
|
||||
return;
|
||||
}
|
||||
kDebug(500) << "querying trader for application/ps service";
|
||||
|
||||
KPluginFactory *factory(0);
|
||||
KService::List offers =
|
||||
KMimeTypeTrader::self()->query("application/postscript", "KParts/ReadOnlyPart");
|
||||
|
||||
KService::List::ConstIterator it = offers.begin();
|
||||
while (!factory && it != offers.end()) {
|
||||
KPluginLoader loader(**it);
|
||||
factory = loader.factory();
|
||||
if (!factory) {
|
||||
kDebug(500) << "Loading failed:" << loader.errorString();
|
||||
}
|
||||
++it;
|
||||
}
|
||||
if (factory) {
|
||||
kDebug(500) << "Trying to create a part";
|
||||
previewPart = factory->create<KParts::ReadOnlyPart>(q, (QVariantList() << "Print/Preview"));
|
||||
if (!previewPart) {
|
||||
kDebug(500) << "Part creation failed";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool FilePrinterPreviewPrivate::doPreview()
|
||||
{
|
||||
if (!QFile::exists(filename)) {
|
||||
kWarning() << "Nothing was produced to be previewed";
|
||||
return false;
|
||||
}
|
||||
|
||||
getPart();
|
||||
if (!previewPart) {
|
||||
//TODO: error dialog
|
||||
kWarning() << "Could not find a PS viewer for the preview dialog";
|
||||
fail();
|
||||
return false;
|
||||
} else {
|
||||
q->setMainWidget(previewPart->widget());
|
||||
return previewPart->openUrl(filename);
|
||||
}
|
||||
}
|
||||
|
||||
void FilePrinterPreviewPrivate::fail()
|
||||
{
|
||||
if (!failMessage) {
|
||||
failMessage = new QLabel(i18n("Could not load print preview part"), q);
|
||||
}
|
||||
q->setMainWidget(failMessage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FilePrinterPreview::FilePrinterPreview( const QString &filename, QWidget *parent )
|
||||
: KDialog( parent )
|
||||
, d( new FilePrinterPreviewPrivate( this, filename ) )
|
||||
{
|
||||
kDebug(500) << "kdeprint: creating preview dialog";
|
||||
|
||||
// Set up the dialog
|
||||
setCaption(i18n("Print Preview"));
|
||||
setButtons(KDialog::Close);
|
||||
}
|
||||
|
||||
FilePrinterPreview::~FilePrinterPreview()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void FilePrinterPreview::showEvent(QShowEvent *event)
|
||||
{
|
||||
if (!event->spontaneous()) {
|
||||
// being shown for the first time
|
||||
if (!d->doPreview()) {
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
KDialog::showEvent(event);
|
||||
}
|
||||
|
||||
#include "fileprinter.moc"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by John Layt <john@layt.net> *
|
||||
* *
|
||||
* FilePrinterPreview based on KPrintPreview (originally LGPL) *
|
||||
* Copyright (c) 2007 Alex Merry <huntedhacker@tiscali.co.uk> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
|
@ -20,8 +17,6 @@
|
|||
#include <QtCore/QList>
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include <kdialog.h>
|
||||
|
||||
#include <okular/core/okular_export.h>
|
||||
|
||||
class QPrinter;
|
||||
|
@ -168,31 +163,6 @@ protected:
|
|||
QStringList optionCollateCopies( QPrinter &printer );
|
||||
};
|
||||
|
||||
// This code copied from KPrintPreview by Alex Merry, adapted to do PS files instead of PDF
|
||||
|
||||
class FilePrinterPreviewPrivate;
|
||||
|
||||
class OKULAR_EXPORT FilePrinterPreview : public KDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a Print Preview dialog for a given file.
|
||||
*
|
||||
* @param printer file to print preview
|
||||
* @param parent pointer to the parent widget for the dialog
|
||||
*/
|
||||
explicit FilePrinterPreview( const QString &filename, QWidget *parent = 0 );
|
||||
virtual ~FilePrinterPreview();
|
||||
|
||||
protected:
|
||||
void showEvent( QShowEvent *event );
|
||||
|
||||
private:
|
||||
FilePrinterPreviewPrivate * const d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FILEPRINTER_H
|
||||
|
|
1
part.cpp
1
part.cpp
|
@ -73,6 +73,7 @@
|
|||
#include "ui/bookmarklist.h"
|
||||
#include "ui/findbar.h"
|
||||
#include "ui/sidebar.h"
|
||||
#include "ui/fileprinterpreview.h"
|
||||
#include "conf/preferencesdialog.h"
|
||||
#include "settings.h"
|
||||
#include "core/bookmarkmanager.h"
|
||||
|
|
146
ui/fileprinterpreview.cpp
Normal file
146
ui/fileprinterpreview.cpp
Normal file
|
@ -0,0 +1,146 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by John Layt <john@layt.net> *
|
||||
* *
|
||||
* FilePrinterPreview based on KPrintPreview (originally LGPL) *
|
||||
* Copyright (c) 2007 Alex Merry <huntedhacker@tiscali.co.uk> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
***************************************************************************/
|
||||
|
||||
#include "fileprinterpreview.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QSize>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QShowEvent>
|
||||
|
||||
#include <kmimetypetrader.h>
|
||||
#include <kparts/part.h>
|
||||
#include <kpluginfactory.h>
|
||||
#include <kpluginloader.h>
|
||||
#include <kservice.h>
|
||||
#include <kdebug.h>
|
||||
|
||||
using namespace Okular;
|
||||
|
||||
// This code copied from KPrintPreview by Alex Merry, adapted to do PS files instead of PDF
|
||||
|
||||
class Okular::FilePrinterPreviewPrivate
|
||||
{
|
||||
public:
|
||||
FilePrinterPreviewPrivate( FilePrinterPreview *host, const QString & _filename )
|
||||
: q(host)
|
||||
, mainWidget(new QWidget(host))
|
||||
, previewPart(0)
|
||||
, failMessage(0)
|
||||
{
|
||||
filename = _filename;
|
||||
}
|
||||
|
||||
void getPart();
|
||||
bool doPreview();
|
||||
void fail();
|
||||
|
||||
FilePrinterPreview *q;
|
||||
|
||||
QWidget *mainWidget;
|
||||
|
||||
QString filename;
|
||||
|
||||
KParts::ReadOnlyPart *previewPart;
|
||||
QWidget *failMessage;
|
||||
};
|
||||
|
||||
void FilePrinterPreviewPrivate::getPart()
|
||||
{
|
||||
if (previewPart) {
|
||||
kDebug(500) << "already got a part";
|
||||
return;
|
||||
}
|
||||
kDebug(500) << "querying trader for application/ps service";
|
||||
|
||||
KPluginFactory *factory(0);
|
||||
KService::List offers =
|
||||
KMimeTypeTrader::self()->query("application/postscript", "KParts/ReadOnlyPart");
|
||||
|
||||
KService::List::ConstIterator it = offers.begin();
|
||||
while (!factory && it != offers.end()) {
|
||||
KPluginLoader loader(**it);
|
||||
factory = loader.factory();
|
||||
if (!factory) {
|
||||
kDebug(500) << "Loading failed:" << loader.errorString();
|
||||
}
|
||||
++it;
|
||||
}
|
||||
if (factory) {
|
||||
kDebug(500) << "Trying to create a part";
|
||||
previewPart = factory->create<KParts::ReadOnlyPart>(q, (QVariantList() << "Print/Preview"));
|
||||
if (!previewPart) {
|
||||
kDebug(500) << "Part creation failed";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool FilePrinterPreviewPrivate::doPreview()
|
||||
{
|
||||
if (!QFile::exists(filename)) {
|
||||
kWarning() << "Nothing was produced to be previewed";
|
||||
return false;
|
||||
}
|
||||
|
||||
getPart();
|
||||
if (!previewPart) {
|
||||
//TODO: error dialog
|
||||
kWarning() << "Could not find a PS viewer for the preview dialog";
|
||||
fail();
|
||||
return false;
|
||||
} else {
|
||||
q->setMainWidget(previewPart->widget());
|
||||
return previewPart->openUrl(filename);
|
||||
}
|
||||
}
|
||||
|
||||
void FilePrinterPreviewPrivate::fail()
|
||||
{
|
||||
if (!failMessage) {
|
||||
failMessage = new QLabel(i18n("Could not load print preview part"), q);
|
||||
}
|
||||
q->setMainWidget(failMessage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FilePrinterPreview::FilePrinterPreview( const QString &filename, QWidget *parent )
|
||||
: KDialog( parent )
|
||||
, d( new FilePrinterPreviewPrivate( this, filename ) )
|
||||
{
|
||||
kDebug(500) << "kdeprint: creating preview dialog";
|
||||
|
||||
// Set up the dialog
|
||||
setCaption(i18n("Print Preview"));
|
||||
setButtons(KDialog::Close);
|
||||
}
|
||||
|
||||
FilePrinterPreview::~FilePrinterPreview()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void FilePrinterPreview::showEvent(QShowEvent *event)
|
||||
{
|
||||
if (!event->spontaneous()) {
|
||||
// being shown for the first time
|
||||
if (!d->doPreview()) {
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
KDialog::showEvent(event);
|
||||
}
|
||||
|
||||
#include "fileprinterpreview.moc"
|
47
ui/fileprinterpreview.h
Normal file
47
ui/fileprinterpreview.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by John Layt <john@layt.net> *
|
||||
* *
|
||||
* FilePrinterPreview based on KPrintPreview (originally LGPL) *
|
||||
* Copyright (c) 2007 Alex Merry <huntedhacker@tiscali.co.uk> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef FILEPRINTERPREVIEW_H
|
||||
#define FILEPRINTERPREVIEW_H
|
||||
|
||||
#include <kdialog.h>
|
||||
|
||||
namespace Okular {
|
||||
|
||||
// This code copied from KPrintPreview by Alex Merry, adapted to do PS files instead of PDF
|
||||
|
||||
class FilePrinterPreviewPrivate;
|
||||
|
||||
class FilePrinterPreview : public KDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a Print Preview dialog for a given file.
|
||||
*
|
||||
* @param printer file to print preview
|
||||
* @param parent pointer to the parent widget for the dialog
|
||||
*/
|
||||
explicit FilePrinterPreview( const QString &filename, QWidget *parent = 0 );
|
||||
virtual ~FilePrinterPreview();
|
||||
|
||||
protected:
|
||||
void showEvent( QShowEvent *event );
|
||||
|
||||
private:
|
||||
FilePrinterPreviewPrivate * const d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FILEPRINTER_H
|
Loading…
Reference in a new issue