File: sourcereference.cpp

package info (click to toggle)
okular 4%3A4.8.4-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,040 kB
  • sloc: cpp: 62,030; ansic: 3,964; xml: 66; sh: 22; makefile: 7
file content (93 lines) | stat: -rw-r--r-- 2,648 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/***************************************************************************
 *   Copyright (C) 2007,2008 by Pino Toscano <pino@kde.org>                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#include "sourcereference.h"
#include "sourcereference_p.h"

#include <QtCore/QString>
#include <QtCore/QUrl>
#include <klocale.h>

using namespace Okular;

class SourceReference::Private
{
    public:
        Private()
            : row( 0 ), column( 0 )
        {
        }

        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;
}

bool Okular::extractLilyPondSourceReference( const QString &url, QString *file, int *row, int *col )
{
    if ( !url.startsWith( QLatin1String( "textedit://" ) ) )
        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;
}

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 );
}