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

marble

  • sources
  • kde-4.12
  • 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 {
16  myEngine.setProcessEventsInterval(10);//this lets the gui remain responsive
17 }
18 
19 jsonParser::~jsonParser()
20 {
21 }
22 
23 panoramioDataStructure jsonParser::parseObjectOnPosition(const QString &content , int requiredObjectPosition)
24 {
25  QString temp = "var myJSONObject =" + content;
26  myEngine.evaluate(temp);
27  myEngine.evaluate(QString("function count(){ return myJSONObject.count };"));
28  myEngine.evaluate(QString("function height(x){return myJSONObject.photos[x].height};"));
29  myEngine.evaluate(QString("function latitude(x){return myJSONObject.photos[x].latitude};"));
30  myEngine.evaluate(QString("function longitude (x){return myJSONObject.photos[x].longitude};"));
31  myEngine.evaluate(QString("function owner_id(x){return myJSONObject.photos[x].owner_id};"));
32  myEngine.evaluate(QString("function photo_file_url(x){return myJSONObject.photos[x].photo_file_url};"));
33  myEngine.evaluate(QString("function photo_title(x){return myJSONObject.photos[x].photo_title};"));
34  myEngine.evaluate(QString("function photo_id(x){return myJSONObject.photos[x].photo_id};"));
35  myEngine.evaluate(QString("function upload_date(x){return myJSONObject.photos[x].upload_date};"));
36  dataStorage.count = myEngine.evaluate("count();").toInteger();
37  myEngine.evaluate(QString("var x="+QString::number(requiredObjectPosition)));
38  dataStorage.longitude=myEngine.evaluate(QString("longitude(x)")).toNumber();
39  dataStorage.latitude=myEngine.evaluate(QString("latitude(x)")).toNumber();
40  dataStorage.photo_file_url=myEngine.evaluate(QString("photo_file_url(x)")).toString();
41  dataStorage.photo_title=myEngine.evaluate(QString("photo_title(x)")).toString();
42  dataStorage.photo_id=myEngine.evaluate(QString("photo_id(x)")).toNumber();
43 
44  // Getting the upload date of the image.
45  QString upload_date_string=myEngine.evaluate(QString("upload_date(x)")).toString();
46  QStringList date = upload_date_string.split( ' ' );
47  if( date.size() == 3 ) {
48  unsigned int day = date.at( 0 ).toUInt();
49  unsigned int month = 1;
50  if( date.at( 1 ).contains( "January" ) )
51  month = 1;
52  else if ( date.at( 1 ).contains( "February" ) )
53  month = 2;
54  else if ( date.at( 1 ).contains( "March" ) )
55  month = 3;
56  else if ( date.at( 1 ).contains( "April" ) )
57  month = 4;
58  else if ( date.at( 1 ).contains( "May" ) )
59  month = 5;
60  else if ( date.at( 1 ).contains( "June" ) )
61  month = 6;
62  else if ( date.at( 1 ).contains( "July" ) )
63  month = 7;
64  else if ( date.at( 1 ).contains( "August" ) )
65  month = 8;
66  else if ( date.at( 1 ).contains( "September" ) )
67  month = 9;
68  else if ( date.at( 1 ).contains( "October" ) )
69  month = 10;
70  else if ( date.at( 1 ).contains( "November" ) )
71  month = 11;
72  else if ( date.at( 1 ).contains( "December" ) )
73  month = 12;
74 
75  unsigned int year = date.at( 2 ).toUInt();
76 
77  dataStorage.upload_date = QDate( year, month, day );
78  }
79  else {
80  dataStorage.upload_date = QDate( 1970, 1, 1 );
81  }
82 
83 // mDebug()<<":::::::"<<__func__<<myEngine.evaluate("longitude(x)").toNumber();
84  return dataStorage;
85 }
86 
87 QList<panoramioDataStructure> jsonParser::parseAllObjects(const QString &content, int number)
88 {
89  QList <panoramioDataStructure> returnStructure;
90 
91  for( int i = 0; i < number; i++ ) {
92  returnStructure.append( parseObjectOnPosition( content, i ) );
93  }
94 
95  return returnStructure;
96 }
panoramioDataStructure::photo_id
long int photo_id
Definition: panoramio/jsonparser.h:32
panoramioDataStructure::upload_date
QDate upload_date
Definition: panoramio/jsonparser.h:40
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
jsonParser::~jsonParser
~jsonParser()
Definition: panoramio/jsonparser.cpp:19
panoramioDataStructure::count
long int count
Definition: panoramio/jsonparser.h:31
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:23
panoramioDataStructure::photo_file_url
QString photo_file_url
Definition: panoramio/jsonparser.h:35
jsonParser::parseAllObjects
QList< panoramioDataStructure > parseAllObjects(const QString &content, int number)
Definition: panoramio/jsonparser.cpp:87
jsonParser::jsonParser
jsonParser()
Definition: panoramio/jsonparser.cpp:14
jsonparser.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:50 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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