Fix parsing of lilypond URLs

frameworks
Martin T. H. Sandsmark 10 years ago
parent 3bcfb63d5c
commit a6ec5ea9de
  1. 55
      core/sourcereference.cpp

@ -59,33 +59,40 @@ int SourceReference::column() const
bool Okular::extractLilyPondSourceReference( const QUrl &url, QString *file, int *row, int *col ) 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") ) if ( url.scheme() != QStringLiteral("textedit") )
return false; return false;
#pragma message("KF5 fix LilyPond references") // There can be more, in case the filename contains :
return false; if (url.fileName().count(':') < 3) {
return false;
// *row = 0; }
// *col = 0;
// int lilyChar = 0; QStringList parts(url.path().split(':'));
// typedef int *IntPtr;
// const IntPtr int_data[] = { row, &lilyChar, col }; bool ok;
// int int_index = sizeof( int_data ) / sizeof( int* ) - 1; // Take out the things we need
// int index_last = -1; int columnEnd = parts.takeLast().toInt(&ok); // apparently we don't use this
// int index = url.lastIndexOf( QLatin1Char( ':' ), index_last ); Q_UNUSED(columnEnd);
// while ( index != -1 && int_index >= 0 ) if (!ok) {
// { return false;
// // 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(); *col = parts.takeLast().toInt(&ok);
// // find the previous "chunk" if (!ok) {
// index_last = index; return false;
// index = url.lastIndexOf( QLatin1Char( ':' ), index_last - 1 ); }
// --int_index;
// } *row = parts.takeLast().toInt(&ok);
// // NOTE: 11 is the length of "textedit://" if (!ok) {
// *file = QUrl::fromPercentEncoding( url.mid( 11, index_last != -1 ? index_last - 11 : -1 ).toUtf8() ); return false;
// return true; }
// 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 ) QString Okular::sourceReferenceToolTip( const QString &source, int row, int col )

Loading…
Cancel
Save