"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2bCollectionIndex.cpp" (12 Feb 2021, 3537 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 "c2bCollectionIndex.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 "c2bCollectionIndex.h"
    8 
    9 #include "c2bSettings.h"
   10 #include "c2bUtils.h"
   11 
   12 #include <QPushButton>
   13 
   14 
   15 c2bCollectionIndex::c2bCollectionIndex(QWidget* parentw) : QDialog(parentw), _indexerP(0)
   16 {
   17     ui.setupUi(this);
   18     setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
   19     setWindowTitle(tr("Documents Indexing Log - cb2Bib"));
   20     ui.Log->setFont(c2bSettingsP->c2bMonoFont);
   21     ui.Log->setLineWrapMode(QPlainTextEdit::NoWrap);
   22     _buttonAbort = new QPushButton(tr("Abort"));
   23     ui.buttonBox->addButton(_buttonAbort, QDialogButtonBox::ActionRole);
   24     connect(_buttonAbort, SIGNAL(clicked()), this, SLOT(aborted()));
   25     connect(ui.buttonBox, SIGNAL(helpRequested()), this, SLOT(help()));
   26     resize(c2bSettingsP->value("c2bLogWidget/size", size()).toSize());
   27 }
   28 
   29 c2bCollectionIndex::~c2bCollectionIndex()
   30 {
   31     c2bSettingsP->setValue("c2bLogWidget/size", size());
   32 }
   33 
   34 
   35 void c2bCollectionIndex::index()
   36 {
   37     ui.Log->clear();
   38     ui.buttonBox->button(QDialogButtonBox::Close)->setEnabled(false);
   39     _indexerP = new QProcess(this);
   40     _indexerP->setProcessChannelMode(QProcess::MergedChannels);
   41     connect(_indexerP, SIGNAL(finished(int,QProcess::ExitStatus)), this,
   42             SLOT(indexingEnded(int,QProcess::ExitStatus)));
   43     connect(_indexerP, SIGNAL(readyReadStandardOutput()), this, SLOT(addToLog()));
   44     const QStringList flags(QStringList() << "--index" << c2bSettingsP->confCommandFlags());
   45     _indexerP->start(QCoreApplication::applicationFilePath(), flags);
   46     if (!_indexerP->waitForStarted())
   47     {
   48         ui.Log->appendPlainText(tr("Failed to call %1.").arg(QCoreApplication::applicationFilePath()));
   49         _buttonAbort->setEnabled(false);
   50         ui.buttonBox->button(QDialogButtonBox::Close)->setEnabled(true);
   51         ui.buttonBox->button(QDialogButtonBox::Close)->setFocus();
   52         delete _indexerP;
   53         _indexerP = 0;
   54     }
   55 }
   56 
   57 void c2bCollectionIndex::addToLog()
   58 {
   59     const QString log(QString::fromUtf8(_indexerP->readAllStandardOutput().trimmed()));
   60     if (log.isEmpty())
   61         return;
   62     ui.Log->appendPlainText(log);
   63 }
   64 
   65 void c2bCollectionIndex::indexingEnded(int exit_code, QProcess::ExitStatus exit_status)
   66 {
   67     _buttonAbort->setEnabled(false);
   68     ui.buttonBox->button(QDialogButtonBox::Close)->setEnabled(true);
   69     ui.buttonBox->button(QDialogButtonBox::Close)->setFocus();
   70     if (exit_code == 0 && exit_status == QProcess::NormalExit)
   71         ui.Log->appendPlainText(tr("\nIndexing ended\nRefresh cb2Bib Citer"));
   72     else
   73         ui.Log->appendPlainText(tr("\nAbnormal termination"));
   74     delete _indexerP;
   75     _indexerP = 0;
   76 }
   77 
   78 void c2bCollectionIndex::aborted()
   79 {
   80     if (_indexerP)
   81         _indexerP->kill();
   82     ui.Log->appendPlainText(tr("Aborting..."));
   83 }
   84 
   85 void c2bCollectionIndex::closeEvent(QCloseEvent* qevent)
   86 {
   87     if (!_indexerP || _indexerP->state() == QProcess::NotRunning)
   88         QDialog::closeEvent(qevent);
   89     else
   90         qevent->ignore();
   91 }
   92 
   93 void c2bCollectionIndex::reject()
   94 {
   95     if (!_indexerP || _indexerP->state() == QProcess::NotRunning)
   96         QDialog::reject();
   97 }
   98 
   99 void c2bCollectionIndex::help()
  100 {
  101     c2bUtils::displayHelp("https://www.molspaces.com/cb2bib/doc/c2bciter/");
  102 }