Logo Search packages:      
Sourcecode: cb2bib version File versions

c2bExportDialog.cpp

/***************************************************************************
 *   Copyright (C) 2004-2009 by Pere Constans
 *   constans@molspaces.com
 *   cb2Bib version 1.3.0. Licensed under the GNU GPL version 3.
 *   See the LICENSE file that comes with this distribution.
 ***************************************************************************/
#include "c2bExportDialog.h"

#include "c2b.h"
#include "c2bExport.h"
#include "c2bFileDialog.h"
#include "c2bSettings.h"
#include "c2bUtils.h"

#include <QMessageBox>
#include <QPushButton>


c2bExportDialog::c2bExportDialog(const QString& fn, const QStringList& keys, QWidget* parentw) :
        QDialog(parentw), _bibtex_fn(fn), _bibtex_keys(keys)
{
    ui.setupUi(this);
    setWindowTitle(tr("Export Entries - cb2Bib"));
    QPushButton* buttonExport = new QPushButton(tr("Export"));
    ui.buttonBox->addButton(buttonExport, QDialogButtonBox::ActionRole);
    connect(buttonExport, SIGNAL(clicked()), this, SLOT(_export()));

    settings = c2bSettingsP;
    ui.ExportFile->setText(settings->value("c2bExportDialog/ExportFile", QString()).toString());
    ui.DocumentsDirectory->setText(settings->value("c2bExportDialog/DocumentsDirectory", QString()).toString());
    ui.CopyDocuments->setChecked(settings->value("c2bExportDialog/CopyDocuments").toBool());
    ui.RelativeDocumentDirectory->setChecked(settings->value("c2bExportDialog/RelativeDocumentDirectory").toBool());
    ui.DocumentsDirectoryBox->setEnabled(ui.CopyDocuments->isChecked());

    connect(ui.ExportFileDir, SIGNAL(clicked()), this, SLOT(getExportFile()));
    connect(ui.DocumentsDirectoryDir, SIGNAL(clicked()), this, SLOT(getDocumentsDirectory()));
    connect(ui.buttonBox, SIGNAL(helpRequested()), this, SLOT(help()));
}

c2bExportDialog::~c2bExportDialog()
{
    if (result() == QDialog::Accepted)
    {
        settings->setValue("c2bExportDialog/CopyDocuments", ui.CopyDocuments->isChecked());
        settings->setValue("c2bExportDialog/DocumentsDirectory", ui.DocumentsDirectory->text());
        settings->setValue("c2bExportDialog/ExportFile", ui.ExportFile->text());
        settings->setValue("c2bExportDialog/RelativeDocumentDirectory", ui.RelativeDocumentDirectory->isChecked());
    }
}


void c2bExportDialog::_export()
{
    c2bExport::export_data ed;
    ed.bibtex_fn = _bibtex_fn;
    ed.bibtex_keys = _bibtex_keys;
    ed.copy_documents = ui.CopyDocuments->isChecked();
    ed.documents_dir = ui.DocumentsDirectory->text();
    ed.export_fn = ui.ExportFile->text();
    ed.relative_dir = ui.RelativeDocumentDirectory->isChecked();

    // Check files
    if (QFileInfo(ed.export_fn).exists())
    {
        int button = QMessageBox::warning(this, tr("Warning - cb2Bib"),
                                          tr("File %1 already exists.\nDo you want to replace it?").arg(ed.export_fn),
                                          QMessageBox::Yes | QMessageBox::No);
        if (button == QMessageBox::No)
            return;
    }
    if (ed.copy_documents)
    {
        QString ddname = c2bUtils::documentAbsoluteName(ed.relative_dir, ed.export_fn, ed.documents_dir, "") + QDir::separator();
        QDir doc_dir(ddname);
        if (!doc_dir.exists())
            if (!doc_dir.mkpath(ddname))
            {
                QMessageBox::warning(this, tr("Warning - cb2Bib"),
                                     tr("Unable to create directory %1.").arg(ddname), QMessageBox::Ok);
                return;
            }
    }

    c2bExport e(this);
    e.exportEntries(ed);
    accept();
}

void c2bExportDialog::getExportFile()
{
    QString fn = ui.ExportFile->text();
    QString new_fn = c2bFileDialog::getFilename(this, tr("Select export filename"), fn, "BibTeX (*.bib)");
    if (!new_fn.isEmpty())
        ui.ExportFile->setText(new_fn);
}

void c2bExportDialog::getDocumentsDirectory()
{
    QString dir = c2bUtils::documentAbsoluteName(ui.RelativeDocumentDirectory->isChecked(), ui.ExportFile->text(),
                  ui.DocumentsDirectory->text(), "");
    QString new_dir = c2bFileDialog::getExistingDirectory(this, tr("Select documents directory"), dir);
    if (!new_dir.isEmpty())
    {
        new_dir = c2bUtils::documentDirName(ui.RelativeDocumentDirectory->isChecked(), ui.ExportFile->text(), new_dir);
        ui.DocumentsDirectory->setText(new_dir);
    }
}

void c2bExportDialog::help()
{
    c2bUtils::displayHelp("http://www.molspaces.com/d_cb2bib-c2beditor.php#export_entries");
}

Generated by  Doxygen 1.6.0   Back to index