diff --git a/ui/embeddedfilesdialog.cpp b/ui/embeddedfilesdialog.cpp index 8947fb37a..4e8a94027 100644 --- a/ui/embeddedfilesdialog.cpp +++ b/ui/embeddedfilesdialog.cpp @@ -15,14 +15,14 @@ #include #include -#include #include #include #include -#include #include +#include #include "core/document.h" +#include "guiutils.h" Q_DECLARE_METATYPE( Okular::EmbeddedFile* ) @@ -118,23 +118,7 @@ void EmbeddedFilesDialog::attachViewContextMenu( const QPoint& /*pos*/ ) void EmbeddedFilesDialog::saveFile( Okular::EmbeddedFile* ef ) { - QString path = KFileDialog::getSaveFileName( ef->name(), QString(), this, i18n( "Where do you want to save %1?", ef->name() ) ); - if ( path.isEmpty() ) - return; - - QFile f(path); - if ( !f.exists() || KMessageBox::warningContinueCancel( this, i18n( "A file named \"%1\" already exists. Are you sure you want to overwrite it?", path ), QString(), KGuiItem( i18n( "Overwrite" ) ) ) == KMessageBox::Continue ) - { - if (f.open( QIODevice::WriteOnly )) - { - f.write( ef->data() ); - f.close(); - } - else - { - KMessageBox::error( this, i18n( "Could not open \"%1\" for writing. File was not saved.", path ) ); - } - } + GuiUtils::saveEmbeddedFile( ef, this ); } #include "embeddedfilesdialog.moc" diff --git a/ui/guiutils.cpp b/ui/guiutils.cpp index 0dc6815f7..e761126fb 100644 --- a/ui/guiutils.cpp +++ b/ui/guiutils.cpp @@ -11,12 +11,15 @@ // qt/kde includes #include +#include #include #include #include +#include // local includes #include "core/annotations.h" +#include "core/document.h" struct GuiUtilsHelper { @@ -160,4 +163,26 @@ KIconLoader* iconLoader() return s_data->il ? s_data->il : KIconLoader::global(); } +void saveEmbeddedFile( Okular::EmbeddedFile *ef, QWidget *parent ) +{ + const QString caption = i18n( "Where do you want to save %1?", ef->name() ); + const QString path = KFileDialog::getSaveFileName( ef->name(), QString(), parent, caption ); + if ( path.isEmpty() ) + return; + + QFile f( path ); + if ( !f.exists() || KMessageBox::warningContinueCancel( parent, i18n( "A file named \"%1\" already exists. Are you sure you want to overwrite it?", path ), QString(), KGuiItem( i18n( "Overwrite" ) ) ) == KMessageBox::Continue ) + { + if ( f.open( QIODevice::WriteOnly ) ) + { + f.write( ef->data() ); + f.close(); + } + else + { + KMessageBox::error( parent, i18n( "Could not open \"%1\" for writing. File was not saved.", path ) ); + } + } +} + } diff --git a/ui/guiutils.h b/ui/guiutils.h index 876822065..3cdb540c1 100644 --- a/ui/guiutils.h +++ b/ui/guiutils.h @@ -12,10 +12,12 @@ #include +class QWidget; class KIconLoader; namespace Okular { class Annotation; +class EmbeddedFile; } namespace GuiUtils @@ -35,6 +37,8 @@ namespace GuiUtils void setIconLoader( KIconLoader * loader ); KIconLoader* iconLoader(); + + void saveEmbeddedFile( Okular::EmbeddedFile *ef, QWidget *parent ); }