<commit_before>//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2008      <NAME> <<EMAIL>>
// Copyright 2009      <NAME> <<EMAIL>>
//

// Self
#include "PanoramioModel.h"
#include "jsonparser.h"

// Marble
#include "GeoDataLatLonAltBox.h"
#include "PanoramioWidget.h"

// Qt
#include <QUrl>
#include <QString>

using namespace Marble;

PanoramioModel::PanoramioModel( const MarbleModel *marbleModel, QObject *parent )
    : AbstractDataPluginModel( "panoramio", marbleModel, parent )
{
}

void PanoramioModel::getAdditionalItems( const GeoDataLatLonAltBox &box, qint32 number )
{
    // FIXME: Download a list of constant number, because the parser doesn't support
    // loading a file of an unknown length.
    QUrl jsonUrl( "http://www.panoramio.com/map/get_panoramas.php?from="
                  + QString::number( 0 )
                  + "&order=upload_date"
                  + "&set=public"
                  + "&to="   + QString::number( number )
//                   + "&to=" + QString::number( number )
                  + "&minx=" + QString::number( box.west() * RAD2DEG )
                  + "&miny=" + QString::number( box.south() * RAD2DEG )
                  + "&maxx=" + QString::number( box.east() * RAD2DEG )
                  + "&maxy=" + QString::number( box.north() * RAD2DEG )
                  + "&size=small");

    downloadDescriptionFile( jsonUrl );
}

void PanoramioModel::parseFile( const QByteArray &file )
{
    jsonParser panoramioJsonParser;
    QList<panoramioDataStructure> list
        = panoramioJsonParser.parseAllObjects( file,
                                               numberOfImagesPerFetch );
    
    QList<panoramioDataStructure>::iterator it;
    for ( it = list.begin(); it != list.end(); ++it ) {
        // Setting the meta information of the current image
        GeoDataCoordinates coordinates( (*it).longitude,
                                        (*it).latitude,
                                        0,
                                        GeoDataCoordinates::Degree );
                                        
        if( itemExists( QString::number( (*it).photo_id ) ) ) {
            continue;
        }
        
        PanoramioWidget *widget = new PanoramioWidget( this );
        widget->setTarget( "earth" );
        widget->setCoordinate( coordinates );
        widget->setId( QString::number( (*it).photo_id ) );
        widget->setUploadDate( (*it).upload_date );
        
        // We need to download the file from Panoramio if it doesn't exist already
        if ( !fileExists( widget->id(), standardImageSize ) ) {
            downloadItem( QUrl( (*it).photo_file_url ),
                                standardImageSize,
                                widget );
        }
        else {
            // If the file does exist, we can simply load it to our widget.
            QString filename = generateFilepath( widget->id(),
                                                 standardImageSize );
            widget->addDownloadedFile( filename,
                                       standardImageSize );
            
            addItemToList( widget );
        }
    }
}

#include "PanoramioModel.moc"<commit_msg>item needs to be added in any case<commit_after>//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2008      <NAME> <<EMAIL>>
// Copyright 2009      <NAME> <<EMAIL>>
//

// Self
#include "PanoramioModel.h"
#include "jsonparser.h"

// Marble
#include "GeoDataLatLonAltBox.h"
#include "PanoramioWidget.h"

// Qt
#include <QUrl>
#include <QString>

using namespace Marble;

PanoramioModel::PanoramioModel( const MarbleModel *marbleModel, QObject *parent )
    : AbstractDataPluginModel( "panoramio", marbleModel, parent )
{
}

void PanoramioModel::getAdditionalItems( const GeoDataLatLonAltBox &box, qint32 number )
{
    // FIXME: Download a list of constant number, because the parser doesn't support
    // loading a file of an unknown length.
    QUrl jsonUrl( "http://www.panoramio.com/map/get_panoramas.php?from="
                  + QString::number( 0 )
                  + "&order=upload_date"
                  + "&set=public"
                  + "&to="   + QString::number( number )
//                   + "&to=" + QString::number( number )
                  + "&minx=" + QString::number( box.west() * RAD2DEG )
                  + "&miny=" + QString::number( box.south() * RAD2DEG )
                  + "&maxx=" + QString::number( box.east() * RAD2DEG )
                  + "&maxy=" + QString::number( box.north() * RAD2DEG )
                  + "&size=small");

    downloadDescriptionFile( jsonUrl );
}

void PanoramioModel::parseFile( const QByteArray &file )
{
    jsonParser panoramioJsonParser;
    QList<panoramioDataStructure> list
        = panoramioJsonParser.parseAllObjects( file,
                                               numberOfImagesPerFetch );
    
    QList<panoramioDataStructure>::iterator it;
    for ( it = list.begin(); it != list.end(); ++it ) {
        // Setting the meta information of the current image
        GeoDataCoordinates coordinates( (*it).longitude,
                                        (*it).latitude,
                                        0,
                                        GeoDataCoordinates::Degree );
                                        
        if( itemExists( QString::number( (*it).photo_id ) ) ) {
            continue;
        }
        
        PanoramioWidget *widget = new PanoramioWidget( this );
        widget->setTarget( "earth" );
        widget->setCoordinate( coordinates );
        widget->setId( QString::number( (*it).photo_id ) );
        widget->setUploadDate( (*it).upload_date );
        
        // We need to download the file from Panoramio if it doesn't exist already
        if ( !fileExists( widget->id(), standardImageSize ) ) {
            downloadItem( QUrl( (*it).photo_file_url ),
                                standardImageSize,
                                widget );
        }
        else {
            // If the file does exist, we can simply load it to our widget.
            QString filename = generateFilepath( widget->id(),
                                                 standardImageSize );
            widget->addDownloadedFile( filename,
                                       standardImageSize );
        }

        addItemToList( widget );
    }
}

#include "PanoramioModel.moc"
{'fraction_non_alphanumeric': 0.11230973843653022, 'fraction_numerical': 0.00472883109206443, 'mean_word_length': 1.7647058823529411, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6263877', 'n_tokens_mistral': 1895, 'n_tokens_neox': 1811, 'n_words': 472}