1 /*
2 SPDX-FileCopyrightText: 2007, 2008 Pino Toscano <pino@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "sourcereference.h"
8 #include "sourcereference_p.h"
9
10 #include <KLocalizedString>
11 #include <QString>
12 #include <QUrl>
13
14 using namespace Okular;
15
16 class SourceReference::Private
17 {
18 public:
Private()19 Private()
20 : row(0)
21 , column(0)
22 {
23 }
24
25 QString filename;
26 int row;
27 int column;
28 };
29
SourceReference(const QString & fileName,int row,int column)30 SourceReference::SourceReference(const QString &fileName, int row, int column)
31 : d(new Private)
32 {
33 d->filename = fileName;
34 d->row = row;
35 d->column = column;
36 }
37
~SourceReference()38 SourceReference::~SourceReference()
39 {
40 delete d;
41 }
42
fileName() const43 QString SourceReference::fileName() const
44 {
45 return d->filename;
46 }
47
row() const48 int SourceReference::row() const
49 {
50 return d->row;
51 }
52
column() const53 int SourceReference::column() const
54 {
55 return d->column;
56 }
57
extractLilyPondSourceReference(const QUrl & url,QString * file,int * row,int * col)58 bool Okular::extractLilyPondSourceReference(const QUrl &url, QString *file, int *row, int *col)
59 {
60 // Example URL is: textedit:///home/foo/bar.ly:42:42:42
61 // The three numbers are apparently: line:beginning of column:end of column
62
63 if (url.scheme() != QStringLiteral("textedit"))
64 return false;
65
66 // There can be more, in case the filename contains :
67 if (url.fileName().count(':') < 3) {
68 return false;
69 }
70
71 QStringList parts(url.path().split(':'));
72
73 bool ok;
74 // Take out the things we need
75 int columnEnd = parts.takeLast().toInt(&ok); // apparently we don't use this
76 Q_UNUSED(columnEnd);
77 if (!ok) {
78 return false;
79 }
80
81 *col = parts.takeLast().toInt(&ok);
82 if (!ok) {
83 return false;
84 }
85
86 *row = parts.takeLast().toInt(&ok);
87 if (!ok) {
88 return false;
89 }
90
91 // In case the path itself contains :, we need to reconstruct it after removing all the numbers
92 *file = parts.join(':');
93 return (!file->isEmpty());
94 }
95
sourceReferenceToolTip(const QString & source,int row,int col)96 QString Okular::sourceReferenceToolTip(const QString &source, int row, int col)
97 {
98 Q_UNUSED(row);
99 Q_UNUSED(col);
100 return i18nc("'source' is a source file", "Source: %1", source);
101 }
102