Expose to the world the document archiving functions:

- loading: slightly edited the loading function to call the right open function of Document in case the file is a document archive (choosen normally in the "open" dialog)
- saving: added an entry in the "export to" formats (and shuffled some code for being more flexible)

probably not much ideal for an usability POV, but we can work on it.

svn path=/trunk/KDE/kdegraphics/okular/; revision=884852
This commit is contained in:
Pino Toscano 2008-11-16 01:23:31 +00:00
parent 938ed4acfa
commit bfa8bd7a5a
2 changed files with 39 additions and 4 deletions

View file

@ -509,6 +509,11 @@ m_cliPresentation(false), m_generatorGuiClient(0), m_keeper( 0 )
m_exportAsMenu->addAction( m_exportAsText );
m_exportAs->setEnabled( false );
m_exportAsText->setEnabled( false );
m_exportAsDocArchive = actionForExportFormat( Okular::ExportFormat(
i18nc( "A document format, Okular-specific", "Document Archive" ),
KMimeType::mimeType( "application/vnd.kde.okular-archive" ) ), m_exportAsMenu );
m_exportAsMenu->addAction( m_exportAsDocArchive );
m_exportAsDocArchive->setEnabled( false );
m_aboutBackend = ac->addAction("help_about_backend");
m_aboutBackend->setText(i18n("About Backend"));
@ -847,7 +852,10 @@ bool Part::openFile()
bool ok = false;
if ( uncompressOk )
{
ok = m_document->openDocument( fileNameToOpen, url(), mime );
if ( mime->is( "application/vnd.kde.okular-archive" ) )
ok = m_document->openDocumentArchive( fileNameToOpen, url() );
else
ok = m_document->openDocument( fileNameToOpen, url(), mime );
}
bool canSearch = m_document->supportsSearching();
@ -885,6 +893,7 @@ bool Part::openFile()
#endif
}
m_exportAsText->setEnabled( ok && m_document->canExportToText() );
m_exportAsDocArchive->setEnabled( ok );
m_exportAs->setEnabled( ok );
// update viewing actions
@ -973,11 +982,12 @@ bool Part::closeUrl()
m_showEmbeddedFiles->setEnabled( false );
m_exportAs->setEnabled( false );
m_exportAsText->setEnabled( false );
m_exportAsDocArchive->setEnabled( false );
m_exportFormats.clear();
QMenu *menu = m_exportAs->menu();
QList<QAction*> acts = menu->actions();
int num = acts.count();
for ( int i = 1; i < num; ++i )
for ( int i = 2; i < num; ++i )
{
menu->removeAction( acts.at(i) );
delete acts.at(i);
@ -1732,11 +1742,35 @@ void Part::slotExportAs(QAction * act)
if ( ( id < 0 ) || ( id >= acts.count() ) )
return;
QString filter = id == 0 ? "text/plain" : m_exportFormats.at( id - 1 ).mimeType()->name();
QString filter;
switch ( id )
{
case 0:
filter = "text/plain";
break;
case 1:
filter = "application/vnd.kde.okular-archive";
break;
default:
filter = m_exportFormats.at( id - 2 ).mimeType()->name();
break;
}
QString fileName = KFileDialog::getSaveFileName( url().isLocalFile() ? url().directory() : QString(), filter, widget() );
if ( !fileName.isEmpty() )
{
bool saved = id == 0 ? m_document->exportToText( fileName ) : m_document->exportTo( fileName, m_exportFormats.at( id - 1 ) );
bool saved = false;
switch ( id )
{
case 0:
saved = m_document->exportToText( fileName );
break;
case 1:
saved = m_document->saveDocumentArchive( fileName );
break;
default:
saved = m_document->exportTo( fileName, m_exportFormats.at( id - 2 ) );
break;
}
if ( !saved )
KMessageBox::information( widget(), i18n("File could not be saved in '%1'. Try to save it to another location.", fileName ) );
}

1
part.h
View file

@ -234,6 +234,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
KAction *m_showEmbeddedFiles;
KAction *m_exportAs;
QAction *m_exportAsText;
QAction *m_exportAsDocArchive;
KAction *m_showPresentation;
KToggleAction* m_showMenuBarAction;
KToggleAction* m_showLeftPanel;