<commit_before> 
/*
 * share-ui -- Handset UX Share user interface
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * Contact: <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "ShareUI/FileItem"
#include "fileitem_p.h"
#include <QtSparql>
#include <QFileInfo>
#include <QDebug>

using namespace ShareUI;

#define STREAM_PREFIX "FileItem:"
#define DBG_STREAM qDebug() << STREAM_PREFIX
#define WARN_STREAM qWarning() << STREAM_PREFIX
#define CRIT_STREAM qCritical() << STREAM_PREFIX


FileItem::FileItem (const QString & constructInfo, QObject * parent) :
    Item (constructInfo, parent), d_ptr (new FileItemPrivate()) {

    connect (d_ptr, SIGNAL(ready()), this, SIGNAL(ready()));
    connect (d_ptr, SIGNAL (thumbnail(QPixmap)), this,
        SIGNAL (thumbnail(QPixmap)));
}

FileItem::~FileItem () {
    delete d_ptr;
}

SharedItem FileItem::create (const QString & constructInfo) {

    QStringList constructInfoList;
    constructInfoList << constructInfo;

    QList<SharedItem> list = createList (constructInfoList);
    SharedItem item;
    // Ideally, list should never have size more than 1
    if (list.size () >= 1) {
        item = list [0];
    }

    return item;
}

QList<QSharedPointer<Item> > FileItem::createList (
    const QStringList & constructInfoList) {

    QList<QSharedPointer<Item> > list;

    static QSparqlConnection connection("QTRACKER");
    if (!connection.isValid()) {
        CRIT_STREAM << "Tracker driver for QtSparql not found";
        return list;
    }

    DBG_STREAM << __FUNCTION__ << "start";

    QStringList fileUrlList;
    QString fileUrls;
    QList<QUrl> trackerUriList;
    QString trackerUris;
    bool hasTrackerUriAlternative = false;
    bool hasFileUrlAlternative = false;
    
    int alternativeSize = 0;
    // For each item in constructInfoList, check if it is a tracker IRI or a
    // fileURI
    for (int i = 0; i < constructInfoList.count(); ++i) {
        
        bool isTrackerIri = true;
    
        QUrl fUrl (constructInfoList [i]);
        
        if (constructInfoList [i].startsWith ("/") == true) {
            // Input wasn't url, use fromLocalFile to fix this
            fUrl = QUrl::fromLocalFile (constructInfoList [i]);
            isTrackerIri = false;
        
        } else if (constructInfoList [i].startsWith ("file://") == true) {
            isTrackerIri = false;
            
        } else if (constructInfoList [i].startsWith ("urn:") == false) {
            qDebug() << constructInfoList[i]
                << "is not tracker file address or file path/uri";
            continue;
        }
    
        if (isTrackerIri == true) {
            trackerUriList.append (fUrl);
            trackerUris.append (QString("'%1',").arg(fUrl.toString()));
            if (hasTrackerUriAlternative == false) alternativeSize++;
            hasTrackerUriAlternative = true;
        } else {
            //Make sure URI has proper encoding
            // QUrl::toEncoded does not work since it does not encode the ';'
            // character (bug 226163). Instead use toPercentEncoding to
            // converting everything possible, except for the ':' and '/'
            // characters to the corresponding percent encoding
            QByteArray encodedUrl = 
                QUrl::toPercentEncoding (fUrl.toString (), ":/()");
            fileUrlList.append (encodedUrl);
            DBG_STREAM << "Searching tracker for file:" << encodedUrl;
            fileUrls.append (QString("'%1',").arg(QString(encodedUrl)));
            if (hasFileUrlAlternative == false) alternativeSize++;
            hasFileUrlAlternative = true;
        }
    }
    
    // Nothing to query
    if (trackerUriList.isEmpty() == true && fileUrlList.isEmpty() == true) {
        return list;
    }

    // Remove the last ',' from the strings
    trackerUris.chop(1);
    fileUrls.chop(1);
<commit_msg>Fixed some more special character handling towards bug 226163. The thumbnailer seems to be causing issues though for some of them<commit_after> 
/*
 * share-ui -- Handset UX Share user interface
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * Contact: <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "ShareUI/FileItem"
#include "fileitem_p.h"
#include <QtSparql>
#include <QFileInfo>
#include <QDebug>

using namespace ShareUI;

#define STREAM_PREFIX "FileItem:"
#define DBG_STREAM qDebug() << STREAM_PREFIX
#define WARN_STREAM qWarning() << STREAM_PREFIX
#define CRIT_STREAM qCritical() << STREAM_PREFIX


FileItem::FileItem (const QString & constructInfo, QObject * parent) :
    Item (constructInfo, parent), d_ptr (new FileItemPrivate()) {

    connect (d_ptr, SIGNAL(ready()), this, SIGNAL(ready()));
    connect (d_ptr, SIGNAL (thumbnail(QPixmap)), this,
        SIGNAL (thumbnail(QPixmap)));
}

FileItem::~FileItem () {
    delete d_ptr;
}

SharedItem FileItem::create (const QString & constructInfo) {

    QStringList constructInfoList;
    constructInfoList << constructInfo;

    QList<SharedItem> list = createList (constructInfoList);
    SharedItem item;
    // Ideally, list should never have size more than 1
    if (list.size () >= 1) {
        item = list [0];
    }

    return item;
}

QList<QSharedPointer<Item> > FileItem::createList (
    const QStringList & constructInfoList) {

    QList<QSharedPointer<Item> > list;

    static QSparqlConnection connection("QTRACKER");
    if (!connection.isValid()) {
        CRIT_STREAM << "Tracker driver for QtSparql not found";
        return list;
    }

    DBG_STREAM << __FUNCTION__ << "start";

    QStringList fileUrlList;
    QString fileUrls;
    QList<QUrl> trackerUriList;
    QString trackerUris;
    bool hasTrackerUriAlternative = false;
    bool hasFileUrlAlternative = false;
    
    int alternativeSize = 0;
    // For each item in constructInfoList, check if it is a tracker IRI or a
    // fileURI
    for (int i = 0; i < constructInfoList.count(); ++i) {
        
        bool isTrackerIri = true;
    
        QUrl fUrl (constructInfoList [i]);
        
        if (constructInfoList [i].startsWith ("/") == true) {
            // Input wasn't url, use fromLocalFile to fix this
            fUrl = QUrl::fromLocalFile (constructInfoList [i]);
            isTrackerIri = false;
        
        } else if (constructInfoList [i].startsWith ("file://") == true) {
            isTrackerIri = false;
            
        } else if (constructInfoList [i].startsWith ("urn:") == false) {
            qDebug() << constructInfoList[i]
                << "is not tracker file address or file path/uri";
            continue;
        }
    
        if (isTrackerIri == true) {
            trackerUriList.append (fUrl);
            trackerUris.append (QString("'%1',").arg(fUrl.toString()));
            if (hasTrackerUriAlternative == false) alternativeSize++;
            hasTrackerUriAlternative = true;
        } else {
            //Make sure URI has proper encoding
            // QUrl::toEncoded does not work since it does not encode the ';'
            // character (bug 226163). Instead use toPercentEncoding to
            // converting everything possible, except for the characters given
            // in the except list to the corresponding percent encoding
            QByteArray encodedUrl = 
                QUrl::toPercentEncoding (fUrl.toString (), ":/()=&@'!,");
            if (encodedUrl.indexOf ('\'') >= 0) {
                encodedUrl.insert (encodedUrl.indexOf ('\''), "\\");
                qDebug() << "Escaped the \' character";
            }
            fileUrlList.append (encodedUrl);
            DBG_STREAM << "Searching tracker for file:" << encodedUrl;
            fileUrls.append (QString("'%1',").arg(QString(encodedUrl)));
            if (hasFileUrlAlternative == false) alternativeSize++;
            hasFileUrlAlternative = true;
        }
    }
    
    // Nothing to query
    if (trackerUriList.isEmpty() == true && fileUrlList.isEmpty() == true) {
        return list;
    }

    // Remove the last ',' from the strings
    trackerUris.chop(1);
    fileUrls.chop(1);

{'fraction_non_alphanumeric': 0.10733206187751643, 'fraction_numerical': 0.007522780250052977, 'mean_word_length': 2.7161417322834644, 'pattern_counts': {'":': 2, '<': 75, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6624345', 'n_tokens_mistral': 2747, 'n_tokens_neox': 2620, 'n_words': 857}