"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/c2bCoreCiter.cpp" between
cb2bib-2.0.0.tar.gz and cb2bib-2.0.1.tar.gz

About: cb2Bib is a multiplatform application for rapidly extracting unformatted, or unstandardized bibliographic references from email alerts, journal Web pages, and PDF files.

c2bCoreCiter.cpp  (cb2bib-2.0.0):c2bCoreCiter.cpp  (cb2bib-2.0.1)
/*************************************************************************** /***************************************************************************
* Copyright (C) 2004-2019 by Pere Constans * Copyright (C) 2004-2021 by Pere Constans
* constans@molspaces.com * constans@molspaces.com
* cb2Bib version 2.0.0. Licensed under the GNU GPL version 3. * cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
* See the LICENSE file that comes with this distribution. * See the LICENSE file that comes with this distribution.
* *
* The LyX pipe procedure in citeToLyXPipe has been adapted from Tellico * The LyX pipe procedure in citeToLyXPipe has been adapted from Tellico
* (Tellico (C) 2003-2005 by Robby Stephenson) * (Tellico (C) 2003-2005 by Robby Stephenson)
***************************************************************************/ ***************************************************************************/
#include "c2bCoreCiter.h" #include "c2bCoreCiter.h"
#include "c2bFileDialog.h" #include "c2bFileDialog.h"
#include <settings.h> #include <settings.h>
skipping to change at line 33 skipping to change at line 33
#include <unistd.h> #include <unistd.h>
c2bCoreCiter::c2bCoreCiter(QWidget* parentw) : QObject(parentw) c2bCoreCiter::c2bCoreCiter(QWidget* parentw) : QObject(parentw)
{ {
_parentWP = parentw; _parentWP = parentw;
_settingsP = settings::instance(); _settingsP = settings::instance();
_settingsP->setDefaultValue("c2bCoreCiter/LyXPipe", _settingsP->setDefaultValue("c2bCoreCiter/LyXPipe",
QDir::cleanPath(QDir::homePath() + QDir::separat or() + ".lyx/lyxpipe.in")); QDir::cleanPath(QDir::homePath() + QDir::separat or() + ".lyx/lyxpipe.in"));
_lyxpipe = _settingsP->value("c2bCoreCiter/LyXPipe").toString(); _lyxpipe = _settingsP->value("c2bCoreCiter/LyXPipe").toString();
_citeids = QRegExp("^([^<]*)<<([^\\|]*)\\|citeids\\|([^>]*)>>(.*)$");
} }
c2bCoreCiter::~c2bCoreCiter() {} c2bCoreCiter::~c2bCoreCiter() {}
void c2bCoreCiter::cite(const QStringList& keys) const void c2bCoreCiter::cite(const QStringList& keys)
{ {
QByteArray pipe = QFile::encodeName(_lyxpipe); if (keys.count() == 0)
if (QFile::exists(pipe)) return;
citeToLyXPipe(keys);
_command = _settingsP->value("cb2Bib/CiteCommandPattern").toString();
const QByteArray pipe(QFile::encodeName(_lyxpipe));
if (QFile::exists(pipe) && _command == C2B_CITE_COMMAND_PATTERN)
_cite_to_lyx_pipe(keys);
else else
citeToClipboard(keys); _cite_to_clipboard(keys);
} }
void c2bCoreCiter::citeToClipboard(const QStringList& keys) const void c2bCoreCiter::_cite_to_clipboard(const QStringList& keys) const
{ {
const QString c("\\cite{" + keys.join(", ").trimmed() + '}'); QString c;
QClipboard* cb = QApplication::clipboard(); if (_command.isEmpty() || _command == C2B_CITE_COMMAND_PATTERN)
cb->setText(c, QClipboard::Clipboard); c = QLatin1String("\\cite{") + keys.join(QLatin1String(", ")).trimmed()
+ QLatin1Char('}');
else if (_command.contains(QLatin1String("<<citeid>>")))
for (int i = 0; i < keys.count(); ++i)
c += QString(_command).replace(QLatin1String("<<citeid>>"), keys.at(
i)) + QLatin1Char(' ');
else if (_citeids.indexIn(_command) >= 0)
{
c = _citeids.cap(2) + keys.at(0); // Note keys.count() > 0
for (int i = 1; i < keys.count(); ++i)
c += _citeids.cap(3) + QLatin1Char(' ') + _citeids.cap(2) + keys.at(
i);
c = _citeids.cap(1) + c.trimmed() + _citeids.cap(4);
}
if (c.isEmpty())
{
QMessageBox::warning(_parentWP, tr("Warning - cb2Bib"), tr("Cite Command
Pattern is misspecified"),
QMessageBox::Ok);
return;
}
QClipboard* cb(QApplication::clipboard());
cb->setText(c.trimmed(), QClipboard::Clipboard);
} }
void c2bCoreCiter::citeToLyXPipe(const QStringList& keys) const void c2bCoreCiter::_cite_to_lyx_pipe(const QStringList& keys) const
{ {
// This procedure was adapted from Tellico // This procedure was adapted from Tellico
// Tellico (C) 2003-2005 by Robby Stephenson // Tellico (C) 2003-2005 by Robby Stephenson
QByteArray pipe = QFile::encodeName(_lyxpipe); const QByteArray pipe(QFile::encodeName(_lyxpipe));
const QString errorStr(tr("Unable to write to the server pipe at '%1'.").arg (QString(pipe))); const QString errorStr(tr("Unable to write to the server pipe at '%1'.").arg (QString(pipe)));
if (!QFile::exists(pipe)) if (!QFile::exists(pipe))
{ {
QMessageBox::warning(_parentWP, tr("Warning - cb2Bib"), errorStr, QMessa geBox::Ok); QMessageBox::warning(_parentWP, tr("Warning - cb2Bib"), errorStr, QMessa geBox::Ok);
return; return;
} }
int pipeFd = ::open(pipe, O_WRONLY); int pipeFd = ::open(pipe, O_WRONLY);
QFile file(QString::fromUtf8(pipe)); QFile file(QString::fromUtf8(pipe));
 End of changes. 10 change blocks. 
13 lines changed or deleted 43 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)