File indexing completed on 2024-04-28 04:32:45
0001 /* 0002 SPDX-FileCopyrightText: 2007, 2008 Pino Toscano <pino@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "sourcereference.h" 0008 #include "sourcereference_p.h" 0009 0010 #include <KLocalizedString> 0011 #include <QString> 0012 #include <QUrl> 0013 0014 using namespace Okular; 0015 0016 class SourceReference::Private 0017 { 0018 public: 0019 Private() 0020 : row(0) 0021 , column(0) 0022 { 0023 } 0024 0025 QString filename; 0026 int row; 0027 int column; 0028 }; 0029 0030 SourceReference::SourceReference(const QString &fileName, int row, int column) 0031 : d(new Private) 0032 { 0033 d->filename = fileName; 0034 d->row = row; 0035 d->column = column; 0036 } 0037 0038 SourceReference::~SourceReference() 0039 { 0040 delete d; 0041 } 0042 0043 QString SourceReference::fileName() const 0044 { 0045 return d->filename; 0046 } 0047 0048 int SourceReference::row() const 0049 { 0050 return d->row; 0051 } 0052 0053 int SourceReference::column() const 0054 { 0055 return d->column; 0056 } 0057 0058 bool Okular::extractLilyPondSourceReference(const QUrl &url, QString *file, int *row, int *col) 0059 { 0060 // Example URL is: textedit:///home/foo/bar.ly:42:42:42 0061 // The three numbers are apparently: line:beginning of column:end of column 0062 0063 if (url.scheme() != QStringLiteral("textedit")) { 0064 return false; 0065 } 0066 0067 // There can be more, in case the filename contains : 0068 if (url.fileName().count(QLatin1Char(':')) < 3) { 0069 return false; 0070 } 0071 0072 QStringList parts(url.path().split(QLatin1Char(':'))); 0073 0074 bool ok; 0075 // Take out the things we need 0076 int columnEnd = parts.takeLast().toInt(&ok); // apparently we don't use this 0077 Q_UNUSED(columnEnd); 0078 if (!ok) { 0079 return false; 0080 } 0081 0082 *col = parts.takeLast().toInt(&ok); 0083 if (!ok) { 0084 return false; 0085 } 0086 0087 *row = parts.takeLast().toInt(&ok); 0088 if (!ok) { 0089 return false; 0090 } 0091 0092 // In case the path itself contains :, we need to reconstruct it after removing all the numbers 0093 *file = parts.join(QLatin1Char(':')); 0094 return (!file->isEmpty()); 0095 } 0096 0097 QString Okular::sourceReferenceToolTip(const QString &source, int row, int col) 0098 { 0099 Q_UNUSED(row); 0100 Q_UNUSED(col); 0101 return i18nc("'source' is a source file", "Source: %1", source); 0102 }