"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2bExportDialog.cpp" (12 Feb 2021, 4828 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "c2bExportDialog.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #include "c2bExportDialog.h"
    8 
    9 #include "c2b.h"
   10 #include "c2bFileDialog.h"
   11 #include "c2bSettings.h"
   12 #include "c2bUtils.h"
   13 
   14 #include <QMessageBox>
   15 #include <QPushButton>
   16 
   17 
   18 c2bExportDialog::c2bExportDialog(const QString& fn, const QString& contents, const QStringList& keys, QWidget* parentw)
   19     : QDialog(parentw)
   20 {
   21     setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
   22     _ed.bibtex_fn = fn;
   23     if (contents.isEmpty())
   24         _ed.bibtex_contents = c2bUtils::fileToString(fn);
   25     else
   26         _ed.bibtex_contents = contents;
   27     _ed.bibtex_keys = keys;
   28     ui.setupUi(this);
   29     setWindowTitle(tr("Export Entries - cb2Bib"));
   30     QPushButton* buttonExport = new QPushButton(tr("Export"));
   31     ui.buttonBox->addButton(buttonExport, QDialogButtonBox::ActionRole);
   32     buttonExport->setAutoDefault(true);
   33     buttonExport->setDefault(true);
   34     connect(buttonExport, SIGNAL(clicked()), this, SLOT(_export()));
   35 
   36     settings = c2bSettingsP;
   37     ui.ExportFile->setText(settings->value("c2bExportDialog/ExportFile", QString()).toString());
   38     ui.DocumentsDirectory->setText(settings->value("c2bExportDialog/DocumentsDirectory", QString()).toString());
   39     ui.CopyDocuments->setChecked(settings->value("c2bExportDialog/CopyDocuments").toBool());
   40     ui.RelativeDocumentDirectory->setChecked(settings->value("c2bExportDialog/RelativeDocumentDirectory").toBool());
   41     ui.DocumentsDirectoryBox->setEnabled(ui.CopyDocuments->isChecked());
   42 
   43     connect(ui.ExportFileDir, SIGNAL(clicked()), this, SLOT(getExportFile()));
   44     connect(ui.DocumentsDirectoryDir, SIGNAL(clicked()), this, SLOT(getDocumentsDirectory()));
   45     connect(ui.buttonBox, SIGNAL(helpRequested()), this, SLOT(help()));
   46 }
   47 
   48 c2bExportDialog::~c2bExportDialog()
   49 {
   50     if (result() == QDialog::Accepted)
   51     {
   52         settings->setValue("c2bExportDialog/CopyDocuments", ui.CopyDocuments->isChecked());
   53         settings->setValue("c2bExportDialog/DocumentsDirectory", ui.DocumentsDirectory->text());
   54         settings->setValue("c2bExportDialog/ExportFile", ui.ExportFile->text());
   55         settings->setValue("c2bExportDialog/RelativeDocumentDirectory", ui.RelativeDocumentDirectory->isChecked());
   56     }
   57 }
   58 
   59 
   60 void c2bExportDialog::_export()
   61 {
   62     _ed.copy_documents = ui.CopyDocuments->isChecked();
   63     _ed.documents_dir = ui.DocumentsDirectory->text();
   64     _ed.export_fn = ui.ExportFile->text();
   65     _ed.relative_dir = ui.RelativeDocumentDirectory->isChecked();
   66 
   67     // Check files
   68     if (QFileInfo::exists(_ed.export_fn))
   69     {
   70         const int button(QMessageBox::warning(
   71                              this, tr("Warning - cb2Bib"), tr("File %1 already exists.\nDo you want to replace it?").arg(_ed.export_fn),
   72                              QMessageBox::Yes | QMessageBox::No));
   73         if (button == QMessageBox::No)
   74             return;
   75     }
   76     if (_ed.copy_documents)
   77     {
   78         const QString ddname(
   79             c2bUtils::documentAbsoluteName(_ed.relative_dir, _ed.export_fn, _ed.documents_dir, QString()) +
   80             QDir::separator());
   81         QDir doc_dir(ddname);
   82         if (!doc_dir.exists())
   83             if (!doc_dir.mkpath(ddname))
   84             {
   85                 QMessageBox::warning(this, tr("Warning - cb2Bib"), tr("Unable to create directory %1.").arg(ddname),
   86                                      QMessageBox::Ok);
   87                 return;
   88             }
   89     }
   90     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
   91     c2bExport e(this);
   92     e.exportEntries(_ed);
   93     QApplication::restoreOverrideCursor();
   94     accept();
   95 }
   96 
   97 void c2bExportDialog::getExportFile()
   98 {
   99     const QString fn(ui.ExportFile->text());
  100     const QString new_fn(c2bFileDialog::getFilename(this, tr("Select export filename"), fn, "BibTeX (*.bib)"));
  101     if (!new_fn.isEmpty())
  102         ui.ExportFile->setText(new_fn);
  103 }
  104 
  105 void c2bExportDialog::getDocumentsDirectory()
  106 {
  107     const QString dir(c2bUtils::documentAbsoluteName(ui.RelativeDocumentDirectory->isChecked(), ui.ExportFile->text(),
  108                       ui.DocumentsDirectory->text(), QString()));
  109     QString new_dir(c2bFileDialog::getExistingDirectory(this, tr("Select documents directory"), dir));
  110     if (!new_dir.isEmpty())
  111     {
  112         new_dir = c2bUtils::documentDirName(ui.RelativeDocumentDirectory->isChecked(), ui.ExportFile->text(), new_dir);
  113         ui.DocumentsDirectory->setText(new_dir);
  114     }
  115 }
  116 
  117 void c2bExportDialog::help()
  118 {
  119     c2bUtils::displayHelp("https://www.molspaces.com/cb2bib/doc/bibeditor/#export-selected-entries");
  120 }