2021-05-24 07:25:56 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2007, 2008 Pino Toscano <pino@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2007-01-02 17:45:32 +00:00
|
|
|
|
|
|
|
#include "sourcereference.h"
|
2008-09-22 13:41:28 +00:00
|
|
|
#include "sourcereference_p.h"
|
2007-01-02 17:45:32 +00:00
|
|
|
|
2014-10-07 21:04:36 +00:00
|
|
|
#include <KLocalizedString>
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <QString>
|
|
|
|
#include <QUrl>
|
2007-04-19 18:30:20 +00:00
|
|
|
|
2007-01-02 17:45:32 +00:00
|
|
|
using namespace Okular;
|
|
|
|
|
|
|
|
class SourceReference::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private()
|
|
|
|
: row(0)
|
|
|
|
, column(0)
|
|
|
|
{
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-02 17:45:32 +00:00
|
|
|
QString filename;
|
|
|
|
int row;
|
|
|
|
int column;
|
|
|
|
};
|
|
|
|
|
|
|
|
SourceReference::SourceReference(const QString &fileName, int row, int column)
|
|
|
|
: d(new Private)
|
|
|
|
{
|
|
|
|
d->filename = fileName;
|
|
|
|
d->row = row;
|
|
|
|
d->column = column;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceReference::~SourceReference()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SourceReference::fileName() const
|
|
|
|
{
|
|
|
|
return d->filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SourceReference::row() const
|
|
|
|
{
|
|
|
|
return d->row;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SourceReference::column() const
|
|
|
|
{
|
|
|
|
return d->column;
|
|
|
|
}
|
|
|
|
|
2014-08-10 18:36:41 +00:00
|
|
|
bool Okular::extractLilyPondSourceReference(const QUrl &url, QString *file, int *row, int *col)
|
2008-09-22 13:41:28 +00:00
|
|
|
{
|
2016-07-24 18:27:04 +00:00
|
|
|
// Example URL is: textedit:///home/foo/bar.ly:42:42:42
|
|
|
|
// The three numbers are apparently: line:beginning of column:end of column
|
|
|
|
|
2014-08-10 18:36:41 +00:00
|
|
|
if (url.scheme() != QStringLiteral("textedit")) {
|
2008-09-22 13:41:28 +00:00
|
|
|
return false;
|
2022-03-08 10:10:43 +00:00
|
|
|
}
|
2008-09-22 13:41:28 +00:00
|
|
|
|
2016-07-24 18:27:04 +00:00
|
|
|
// There can be more, in case the filename contains :
|
2022-04-02 21:21:33 +00:00
|
|
|
if (url.fileName().count(QLatin1Char(':')) < 3) {
|
2016-07-24 18:27:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:21:33 +00:00
|
|
|
QStringList parts(url.path().split(QLatin1Char(':')));
|
2016-07-24 18:27:04 +00:00
|
|
|
|
|
|
|
bool ok;
|
|
|
|
// Take out the things we need
|
|
|
|
int columnEnd = parts.takeLast().toInt(&ok); // apparently we don't use this
|
|
|
|
Q_UNUSED(columnEnd);
|
|
|
|
if (!ok) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*col = parts.takeLast().toInt(&ok);
|
|
|
|
if (!ok) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*row = parts.takeLast().toInt(&ok);
|
|
|
|
if (!ok) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In case the path itself contains :, we need to reconstruct it after removing all the numbers
|
2022-04-02 21:21:33 +00:00
|
|
|
*file = parts.join(QLatin1Char(':'));
|
2016-07-24 18:27:04 +00:00
|
|
|
return (!file->isEmpty());
|
2008-09-22 13:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Okular::sourceReferenceToolTip(const QString &source, int row, int col)
|
|
|
|
{
|
|
|
|
Q_UNUSED(row);
|
|
|
|
Q_UNUSED(col);
|
|
|
|
return i18nc("'source' is a source file", "Source: %1", source);
|
|
|
|
}
|