• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • plugins
  • render
  • panoramio
panoramio/jsonparser.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2008 Shashan Singh <shashank.personal@gmail.com>
9 // Copyright 2009 Bastian Holst <bastianholst@gmx.de>
10 //
11 
12 #include "jsonparser.h"
13 
14 jsonParser::jsonParser()
15  : dataStorage()
16 {
17  myEngine.setProcessEventsInterval(10);//this lets the gui remain responsive
18 }
19 
20 jsonParser::~jsonParser()
21 {
22 }
23 
24 panoramioDataStructure jsonParser::parseObjectOnPosition(const QString &content , int requiredObjectPosition)
25 {
26  QString temp = "var myJSONObject =" + content;
27  myEngine.evaluate(temp);
28  myEngine.evaluate(QString("function count(){ return myJSONObject.count };"));
29  myEngine.evaluate(QString("function height(x){return myJSONObject.photos[x].height};"));
30  myEngine.evaluate(QString("function latitude(x){return myJSONObject.photos[x].latitude};"));
31  myEngine.evaluate(QString("function longitude (x){return myJSONObject.photos[x].longitude};"));
32  myEngine.evaluate(QString("function owner_id(x){return myJSONObject.photos[x].owner_id};"));
33  myEngine.evaluate(QString("function photo_file_url(x){return myJSONObject.photos[x].photo_file_url};"));
34  myEngine.evaluate(QString("function photo_title(x){return myJSONObject.photos[x].photo_title};"));
35  myEngine.evaluate(QString("function photo_id(x){return myJSONObject.photos[x].photo_id};"));
36  myEngine.evaluate(QString("function upload_date(x){return myJSONObject.photos[x].upload_date};"));
37  dataStorage.count = myEngine.evaluate("count();").toInteger();
38  myEngine.evaluate(QString("var x="+QString::number(requiredObjectPosition)));
39  dataStorage.longitude=myEngine.evaluate(QString("longitude(x)")).toNumber();
40  dataStorage.latitude=myEngine.evaluate(QString("latitude(x)")).toNumber();
41  dataStorage.photo_file_url=myEngine.evaluate(QString("photo_file_url(x)")).toString();
42  dataStorage.photo_title=myEngine.evaluate(QString("photo_title(x)")).toString();
43  dataStorage.photo_id=myEngine.evaluate(QString("photo_id(x)")).toNumber();
44 
45  // Getting the upload date of the image.
46  QString upload_date_string=myEngine.evaluate(QString("upload_date(x)")).toString();
47  QStringList date = upload_date_string.split( ' ' );
48  if( date.size() == 3 ) {
49  unsigned int day = date.at( 0 ).toUInt();
50  unsigned int month = 1;
51  if( date.at( 1 ).contains( "January" ) )
52  month = 1;
53  else if ( date.at( 1 ).contains( "February" ) )
54  month = 2;
55  else if ( date.at( 1 ).contains( "March" ) )
56  month = 3;
57  else if ( date.at( 1 ).contains( "April" ) )
58  month = 4;
59  else if ( date.at( 1 ).contains( "May" ) )
60  month = 5;
61  else if ( date.at( 1 ).contains( "June" ) )
62  month = 6;
63  else if ( date.at( 1 ).contains( "July" ) )
64  month = 7;
65  else if ( date.at( 1 ).contains( "August" ) )
66  month = 8;
67  else if ( date.at( 1 ).contains( "September" ) )
68  month = 9;
69  else if ( date.at( 1 ).contains( "October" ) )
70  month = 10;
71  else if ( date.at( 1 ).contains( "November" ) )
72  month = 11;
73  else if ( date.at( 1 ).contains( "December" ) )
74  month = 12;
75 
76  unsigned int year = date.at( 2 ).toUInt();
77 
78  dataStorage.upload_date = QDate( year, month, day );
79  }
80  else {
81  dataStorage.upload_date = QDate( 1970, 1, 1 );
82  }
83 
84 // mDebug()<<":::::::"<<__func__<<myEngine.evaluate("longitude(x)").toNumber();
85  return dataStorage;
86 }
87 
88 QList<panoramioDataStructure> jsonParser::parseAllObjects(const QString &content, int number)
89 {
90  QList <panoramioDataStructure> returnStructure;
91 
92  for( int i = 0; i < number; i++ ) {
93  returnStructure.append( parseObjectOnPosition( content, i ) );
94  }
95 
96  return returnStructure;
97 }
panoramioDataStructure::photo_id
long int photo_id
Definition: panoramio/jsonparser.h:32
panoramioDataStructure::upload_date
QDate upload_date
Definition: panoramio/jsonparser.h:40
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QList::at
const T & at(int i) const
QScriptEngine::evaluate
QScriptValue evaluate(const QString &program, const QString &fileName, int lineNumber)
panoramioDataStructure::latitude
qreal latitude
Definition: panoramio/jsonparser.h:37
panoramioDataStructure
This is a generic class built up for parsing Json that is JavaScript Object Notification FIXME: the c...
Definition: panoramio/jsonparser.h:29
QScriptValue::toString
QString toString() const
QList::size
int size() const
jsonParser::~jsonParser
~jsonParser()
Definition: panoramio/jsonparser.cpp:20
QString::number
QString number(int n, int base)
QList::append
void append(const T &value)
panoramioDataStructure::count
long int count
Definition: panoramio/jsonparser.h:31
QDate
QString
QList< panoramioDataStructure >
QStringList
QScriptEngine::setProcessEventsInterval
void setProcessEventsInterval(int interval)
panoramioDataStructure::longitude
qreal longitude
Definition: panoramio/jsonparser.h:36
panoramioDataStructure::photo_title
QString photo_title
Definition: panoramio/jsonparser.h:33
jsonParser::parseObjectOnPosition
panoramioDataStructure parseObjectOnPosition(const QString &content, int requiredObjectPosition)
Definition: panoramio/jsonparser.cpp:24
panoramioDataStructure::photo_file_url
QString photo_file_url
Definition: panoramio/jsonparser.h:35
QScriptValue::toInteger
qsreal toInteger() const
jsonParser::parseAllObjects
QList< panoramioDataStructure > parseAllObjects(const QString &content, int number)
Definition: panoramio/jsonparser.cpp:88
jsonParser::jsonParser
jsonParser()
Definition: panoramio/jsonparser.cpp:14
jsonparser.h
QScriptValue::toNumber
qsreal toNumber() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal