Commit b3a4b279 authored by Pino Toscano's avatar Pino Toscano

New skeleton for giving the generators the possibility to export the document...

New skeleton for giving the generators the possibility to export the document they open in some format they support.
The text exporting option is detached from that other options and always visible (disabled if not supported), so it could be easier for the user to find it out.

svn path=/trunk/playground/graphics/okular/; revision=556922
parent aa109c9e
...@@ -575,6 +575,26 @@ QStringList KPDFDocument::paperSizes() const ...@@ -575,6 +575,26 @@ QStringList KPDFDocument::paperSizes() const
return generator ? generator->paperSizes() : QStringList(); return generator ? generator->paperSizes() : QStringList();
} }
bool KPDFDocument::canExportToText() const
{
return generator ? generator->canExportToText() : false;
}
bool KPDFDocument::exportToText( const QString& fileName ) const
{
return generator ? generator->exportToText( fileName ) : false;
}
QList<ExportEntry*> KPDFDocument::exportFormats() const
{
return generator ? generator->exportFormats() : QList<ExportEntry*>();
}
bool KPDFDocument::exportTo( const QString& fileName, const KMimeType::Ptr& mime ) const
{
return generator ? generator->exportTo( fileName, mime ) : false;
}
bool KPDFDocument::historyAtBegin() const bool KPDFDocument::historyAtBegin() const
{ {
return d->viewportIterator == d->viewportHistory.begin(); return d->viewportIterator == d->viewportHistory.begin();
......
...@@ -40,6 +40,7 @@ class KActionCollection; ...@@ -40,6 +40,7 @@ class KActionCollection;
class QToolBox; class QToolBox;
class NotifyRequest; class NotifyRequest;
class VisiblePageRect; class VisiblePageRect;
class ExportEntry;
/** IDs for seaches. Globally defined here. **/ /** IDs for seaches. Globally defined here. **/
#define PART_SEARCH_ID 1 #define PART_SEARCH_ID 1
...@@ -104,6 +105,10 @@ class OKULAR_EXPORT KPDFDocument : public QObject ...@@ -104,6 +105,10 @@ class OKULAR_EXPORT KPDFDocument : public QObject
bool supportsRotation() const; bool supportsRotation() const;
bool supportsPaperSizes() const; bool supportsPaperSizes() const;
QStringList paperSizes() const; QStringList paperSizes() const;
bool canExportToText() const;
bool exportToText( const QString& fileName ) const;
QList<ExportEntry*> exportFormats() const;
bool exportTo( const QString& fileName, const KMimeType::Ptr& mime ) const;
// might be useful later // might be useful later
// bool hasFonts() const; // bool hasFonts() const;
bool historyAtBegin() const; bool historyAtBegin() const;
......
...@@ -21,8 +21,10 @@ ...@@ -21,8 +21,10 @@
#include <qobject.h> #include <qobject.h>
#include <qvector.h> #include <qvector.h>
#include <qlist.h>
#include <qstring.h> #include <qstring.h>
#include <ostream> #include <ostream>
#include <kmimetype.h>
#include "document.h" #include "document.h"
#include "textpage.h" #include "textpage.h"
class KPrinter; class KPrinter;
...@@ -30,6 +32,7 @@ class KPDFPage; ...@@ -30,6 +32,7 @@ class KPDFPage;
class KPDFLink; class KPDFLink;
class PixmapRequest; class PixmapRequest;
class KConfigDialog; class KConfigDialog;
class ExportEntry;
/* Note: on contents generation and asyncronous queries. /* Note: on contents generation and asyncronous queries.
* Many observers may want to request data syncronously or asyncronously. * Many observers may want to request data syncronously or asyncronously.
...@@ -118,6 +121,12 @@ class OKULAR_EXPORT Generator : public QObject ...@@ -118,6 +121,12 @@ class OKULAR_EXPORT Generator : public QObject
virtual void addPages( KConfigDialog* /*dlg*/ ) {;}; virtual void addPages( KConfigDialog* /*dlg*/ ) {;};
// virtual void setConfigurationPointer( KConfigDialog* /*dlg*/) { ; } ; // virtual void setConfigurationPointer( KConfigDialog* /*dlg*/) { ; } ;
// support for exporting to text and to other formats
virtual bool canExportToText() { return false; };
virtual bool exportToText( const QString & /*fileName*/ ) { return false; };
virtual QList<ExportEntry*> exportFormats() { return QList<ExportEntry*>(); };
virtual bool exportTo( const QString & /*fileName*/, const KMimeType::Ptr & /*mime*/ ) { return false; };
// capture events // capture events
// return false if you don't wish okular to use its event handlers // return false if you don't wish okular to use its event handlers
// in the pageview after your handling (use with caution) // in the pageview after your handling (use with caution)
...@@ -169,4 +178,23 @@ struct OKULAR_EXPORT PixmapRequest ...@@ -169,4 +178,23 @@ struct OKULAR_EXPORT PixmapRequest
QTextStream& operator<< (QTextStream& str, const PixmapRequest *req); QTextStream& operator<< (QTextStream& str, const PixmapRequest *req);
/**
* @short Defines an entry for the export menu
*/
struct OKULAR_EXPORT ExportEntry
{
ExportEntry( const QString & desc, const KMimeType::Ptr & _mime )
: description( desc ), mime( _mime ) {};
ExportEntry( const QString & _icon, const QString & desc, const KMimeType::Ptr & _mime )
: description( desc ), mime( _mime ), icon( _icon ) {};
// the description to be shown in the Export menu
QString description;
// the mime associated
KMimeType::Ptr mime;
// the icon to be shown in the menu item
QString icon;
};
#endif #endif
...@@ -294,6 +294,13 @@ Part::Part(QWidget *parentWidget, ...@@ -294,6 +294,13 @@ Part::Part(QWidget *parentWidget,
m_showPresentation->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_P ) ); m_showPresentation->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_P ) );
m_showPresentation->setEnabled( false ); m_showPresentation->setEnabled( false );
m_exportAs = new KAction(i18n("E&xport As"), ac, "file_export_as");
QMenu *menu = new QMenu();
connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(slotExportAs(QAction *)));
m_exportAs->setMenu( menu );
m_exportAsText = menu->addAction( KIcon( "text" ), i18n( "Text..." ) );
m_exportAsText->setEnabled( false );
// attach the actions of the children widgets too // attach the actions of the children widgets too
m_pageView->setupActions( ac ); m_pageView->setupActions( ac );
...@@ -546,6 +553,26 @@ bool Part::openFile() ...@@ -546,6 +553,26 @@ bool Part::openFile()
m_showProperties->setEnabled( ok ); m_showProperties->setEnabled( ok );
m_showEmbeddedFiles->setEnabled( ok && m_document->embeddedFiles() && m_document->embeddedFiles()->count() > 0); m_showEmbeddedFiles->setEnabled( ok && m_document->embeddedFiles() && m_document->embeddedFiles()->count() > 0);
m_showPresentation->setEnabled( ok ); m_showPresentation->setEnabled( ok );
if ( ok )
{
m_exportItems = m_document->exportFormats();
QList<ExportEntry*>::ConstIterator it = m_exportItems.constBegin();
QList<ExportEntry*>::ConstIterator itEnd = m_exportItems.constEnd();
QMenu *menu = m_exportAs->menu();
for ( ; it != itEnd; ++it )
{
ExportEntry* cur = *it;
if ( !cur->icon.isEmpty() )
{
menu->addAction( KIcon( cur->icon ), cur->description );
}
else
{
menu->addAction( cur->description );
}
}
}
m_exportAsText->setEnabled( ok && m_document->canExportToText() );
// update viewing actions // update viewing actions
updateViewActions(); updateViewActions();
...@@ -606,6 +633,16 @@ bool Part::closeURL() ...@@ -606,6 +633,16 @@ bool Part::closeURL()
m_printPreview->setEnabled( false ); m_printPreview->setEnabled( false );
m_showProperties->setEnabled( false ); m_showProperties->setEnabled( false );
m_showEmbeddedFiles->setEnabled( false ); m_showEmbeddedFiles->setEnabled( false );
m_exportAsText->setEnabled( false );
m_exportItems.clear();
QMenu *menu = m_exportAs->menu();
QList<QAction*> acts = menu->actions();
int num = acts.count();
for ( int i = 1; i < num; ++i )
{
menu->removeAction( acts.at(i) );
delete acts.at(i);
}
m_showPresentation->setEnabled( false ); m_showPresentation->setEnabled( false );
emit setWindowCaption(""); emit setWindowCaption("");
emit enablePrintAction(false); emit enablePrintAction(false);
...@@ -1080,6 +1117,23 @@ void Part::slotHidePresentation() ...@@ -1080,6 +1117,23 @@ void Part::slotHidePresentation()
delete (PresentationWidget*) m_presentationWidget; delete (PresentationWidget*) m_presentationWidget;
} }
void Part::slotExportAs(QAction * act)
{
QList<QAction*> acts = m_exportAs->menu() ? m_exportAs->menu()->actions() : QList<QAction*>();
int id = acts.indexOf( act );
if ( ( id < 0 ) || ( id >= acts.count() ) )
return;
QString filter = id == 0 ? "text/plain" : m_exportItems.at( id - 1 )->mime->name();
QString fileName = KFileDialog::getSaveFileName( url().isLocalFile() ? url().fileName() : QString::null, filter, widget() );
if ( !fileName.isEmpty() )
{
bool saved = id == 0 ? m_document->exportToText( fileName ) : m_document->exportTo( fileName, m_exportItems.at( id - 1 )->mime );
if ( !saved )
KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) );
}
}
void Part::slotPrint() void Part::slotPrint()
{ {
if (m_document->pages() == 0) return; if (m_document->pages() == 0) return;
......
...@@ -18,12 +18,14 @@ ...@@ -18,12 +18,14 @@
#include <kparts/browserextension.h> #include <kparts/browserextension.h>
#include <kparts/part.h> #include <kparts/part.h>
#include <qlist.h>
#include <qpointer.h> #include <qpointer.h>
#include "core/observer.h" #include "core/observer.h"
#include "core/document.h" #include "core/document.h"
#include <dbus/qdbus.h> #include <dbus/qdbus.h>
class QAction;
class QWidget; class QWidget;
class QSplitter; class QSplitter;
class QToolBox; class QToolBox;
...@@ -46,6 +48,7 @@ class PresentationWidget; ...@@ -46,6 +48,7 @@ class PresentationWidget;
class SearchWidget; class SearchWidget;
class TOC; class TOC;
class MiniBar; class MiniBar;
class ExportEntry;
namespace okular { namespace okular {
...@@ -121,6 +124,7 @@ protected slots: ...@@ -121,6 +124,7 @@ protected slots:
void slotShowLeftPanel(); void slotShowLeftPanel();
void slotShowPresentation(); void slotShowPresentation();
void slotHidePresentation(); void slotHidePresentation();
void slotExportAs(QAction *);
bool slotImportPSFile(); bool slotImportPSFile();
void close(); void close();
void cannotQuit(); void cannotQuit();
...@@ -179,6 +183,8 @@ private: ...@@ -179,6 +183,8 @@ private:
KAction *m_printPreview; KAction *m_printPreview;
KAction *m_showProperties; KAction *m_showProperties;
KAction *m_showEmbeddedFiles; KAction *m_showEmbeddedFiles;
KAction *m_exportAs;
QAction *m_exportAsText;
KAction *m_showPresentation; KAction *m_showPresentation;
KToggleAction* m_showMenuBarAction; KToggleAction* m_showMenuBarAction;
KToggleAction* m_showLeftPanel; KToggleAction* m_showLeftPanel;
...@@ -194,6 +200,7 @@ private: ...@@ -194,6 +200,7 @@ private:
QStringList m_generatorsWithSettings; QStringList m_generatorsWithSettings;
QStringList m_supportedMimeTypes; QStringList m_supportedMimeTypes;
KSelectAction * m_confGens; KSelectAction * m_confGens;
QList<ExportEntry*> m_exportItems;
private slots: private slots:
void slotGeneratorPreferences(); void slotGeneratorPreferences();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<Action name="file_print_preview" group="file_print"/> <Action name="file_print_preview" group="file_print"/>
<Action name="properties" group="file_print"/> <Action name="properties" group="file_print"/>
<Action name="embeddedFiles" group="file_print"/> <Action name="embeddedFiles" group="file_print"/>
<Action name="file_export_as" group="file_print"/>
</Menu> </Menu>
<Menu name="edit"><text>&amp;Edit</text> <Menu name="edit"><text>&amp;Edit</text>
<Action name="find"/> <Action name="find"/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment