move the embedded file saving function to the GuiUtils

svn path=/trunk/KDE/kdegraphics/okular/; revision=797108
remotes/origin/KDE/4.1
Pino Toscano 18 years ago
parent 39463af93b
commit eed660ebd3
  1. 22
      ui/embeddedfilesdialog.cpp
  2. 25
      ui/guiutils.cpp
  3. 4
      ui/guiutils.h

@ -15,14 +15,14 @@
#include <QMenu>
#include <QTreeWidget>
#include <kfiledialog.h>
#include <kglobal.h>
#include <kicon.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kmimetype.h>
#include <kstandardguiitem.h>
#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"

@ -11,12 +11,15 @@
// qt/kde includes
#include <qtextdocument.h>
#include <kfiledialog.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kmessagebox.h>
// 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 ) );
}
}
}
}

@ -12,10 +12,12 @@
#include <QtCore/QString>
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 );
}

Loading…
Cancel
Save