summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-24 18:27:04 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-24 18:27:04 (GMT)
commita6ec5ea9de36a24f44998887d34f631bebd59864 (patch)
tree9a7ce9e96bf414024bf146ee32d1149f5a00a449
parent3bcfb63d5c0153bc1578c0df4f094ceb63274b7c (diff)
Fix parsing of lilypond URLs
-rw-r--r--core/sourcereference.cpp55
1 files changed, 31 insertions, 24 deletions
diff --git a/core/sourcereference.cpp b/core/sourcereference.cpp
index a9d72d6..bde8bc1 100644
--- a/core/sourcereference.cpp
+++ b/core/sourcereference.cpp
@@ -59,33 +59,40 @@ int SourceReference::column() const
bool Okular::extractLilyPondSourceReference( const QUrl &url, QString *file, int *row, int *col )
{
+ // Example URL is: textedit:///home/foo/bar.ly:42:42:42
+ // The three numbers are apparently: line:beginning of column:end of column
+
if ( url.scheme() != QStringLiteral("textedit") )
return false;
-#pragma message("KF5 fix LilyPond references")
- return false;
-
-// *row = 0;
-// *col = 0;
-// int lilyChar = 0;
-// typedef int *IntPtr;
-// const IntPtr int_data[] = { row, &lilyChar, col };
-// int int_index = sizeof( int_data ) / sizeof( int* ) - 1;
-// int index_last = -1;
-// int index = url.lastIndexOf( QLatin1Char( ':' ), index_last );
-// while ( index != -1 && int_index >= 0 )
-// {
-// // read the current "chunk"
-// const QStringRef ref = url.midRef( index + 1, index_last - index - 1 );
-// *int_data[ int_index ] = QString::fromRawData( ref.data(), ref.count() ).toInt();
-// // find the previous "chunk"
-// index_last = index;
-// index = url.lastIndexOf( QLatin1Char( ':' ), index_last - 1 );
-// --int_index;
-// }
-// // NOTE: 11 is the length of "textedit://"
-// *file = QUrl::fromPercentEncoding( url.mid( 11, index_last != -1 ? index_last - 11 : -1 ).toUtf8() );
-// return true;
+ // There can be more, in case the filename contains :
+ if (url.fileName().count(':') < 3) {
+ return false;
+ }
+
+ QStringList parts(url.path().split(':'));
+
+ 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
+ *file = parts.join(':');
+ return (!file->isEmpty());
}
QString Okular::sourceReferenceToolTip( const QString &source, int row, int col )