void FileAttachmentAnnotationWidget::save(bool open)
{
#ifndef HAS_POPPLER_24

    QMutexLocker mutexLocker(m_mutex);

#endif // HAS_POPPLER_24

    Poppler::EmbeddedFile* embeddedFile = m_annotation->embeddedFile();

    QString filePath = QFileDialog::getSaveFileName(0, tr("Save file attachment"), embeddedFile->name());

    if(!filePath.isEmpty())
    {
        QFile file(filePath);

        if(file.open(QIODevice::WriteOnly | QIODevice::Truncate))
        {
            file.write(embeddedFile->data());

            file.close();

            if(open)
            {
                QDesktopServices::openUrl(QUrl(filePath));
            }
        }
        else
        {
            QMessageBox::warning(0, tr("Warning"), tr("Could not save file attachment to '%1'.").arg(filePath));
        }
    }
}
void TestAttachments::checkAttach1()
{

    Poppler::Document *doc;
    doc = Poppler::Document::load("../../../test/unittestcases/WithAttachments.pdf");
    QVERIFY( doc );

    QVERIFY( doc->hasEmbeddedFiles() );

    QList<Poppler::EmbeddedFile*> fileList = doc->embeddedFiles();
    QCOMPARE( fileList.size(), 2 );

    Poppler::EmbeddedFile *embfile = fileList.at(0);
    QCOMPARE( embfile->name(), QString( "kroller.png" ) );
    QCOMPARE( embfile->description(), QString("/home/bradh/coding/svn-vers/KDE/kdeartwork/wallpapers/kroller.png") );
    QCOMPARE( embfile->createDate(), QDateTime( QDate(), QTime() ) );
    QCOMPARE( embfile->modDate(), QDateTime( QDate(), QTime() ) );

    QFile file( "../../../test/unittestcases/kroller.png" );
    QVERIFY(  file.open( QIODevice::ReadOnly ) );
    QByteArray krollerData = file.readAll();
    QByteArray embdata = embfile->data();
    QCOMPARE( krollerData, embdata );
	    

    Poppler::EmbeddedFile *embfile2 = fileList.at(1);
    QCOMPARE( embfile2->name(), QString("gnome-64.gif") );
    QCOMPARE( embfile2->description(), QString("/usr/share/gnome-about/gnome-64.gif") );
    QCOMPARE( embfile2->modDate(), QDateTime( QDate(), QTime() ) );
    QCOMPARE( embfile2->createDate(), QDateTime( QDate(), QTime() ) );

    QFile file2( "../../../test/unittestcases/gnome-64.gif" );
    QVERIFY(  file2.open( QIODevice::ReadOnly ) );
    QByteArray g64Data = file2.readAll();
    QByteArray emb2data = embfile2->data();
    QCOMPARE( g64Data, emb2data );

    delete doc;
}