• 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
  • opendesktop
OpenDesktopModel.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 2010 Utku Aydın <utkuaydin34@gmail.com>
9 // Copyright 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
10 //
11 
12 
13 #include "OpenDesktopModel.h"
14 #include "OpenDesktopItem.h"
15 #include "MarbleGlobal.h"
16 #include "MarbleModel.h"
17 #include "GeoDataCoordinates.h"
18 #include <QString>
19 #include <QUrl>
20 #include <QScriptEngine>
21 #include <QScriptValue>
22 #include <QScriptValueIterator>
23 
24 using namespace Marble;
25 
26 
27 OpenDesktopModel::OpenDesktopModel( const MarbleModel *marbleModel, QObject *parent )
28  : AbstractDataPluginModel( "opendesktop", marbleModel, parent )
29 {
30  // Nothing to do...
31 }
32 
33 OpenDesktopModel::~OpenDesktopModel()
34 {
35  // Nothing to do...
36 }
37 
38 void OpenDesktopModel::setMarbleWidget(MarbleWidget *widget)
39 {
40  m_marbleWidget = widget;
41 }
42 
43 void OpenDesktopModel::getAdditionalItems( const GeoDataLatLonAltBox& box, qint32 number )
44 {
45  Q_UNUSED( number )
46 
47  if( marbleModel()->planetId() != "earth" )
48  return;
49 
50  GeoDataCoordinates coords = box.center();
51 
52  QString openDesktopUrl( "http://api.opendesktop.org/v1/person/data" );
53  openDesktopUrl += "?latitude=" + QString::number(coords.latitude() * RAD2DEG);
54  openDesktopUrl += "&longitude=" + QString::number(coords.longitude() * RAD2DEG);
55  openDesktopUrl += "&format=json";
56 
57  downloadDescriptionFile( QUrl( openDesktopUrl ) );
58 }
59 
60 void OpenDesktopModel::parseFile( const QByteArray& file )
61 {
62  QScriptValue data;
63  QScriptEngine engine;
64  data = engine.evaluate( '(' + QString(file) + ')' );
65 
66  // Parse if any result exists
67  if ( data.property( "data" ).isArray() )
68  {
69  QScriptValueIterator iterator( data.property( "data" ) );
70  // Add items to the list
71  QList<AbstractDataPluginItem*> items;
72  while ( iterator.hasNext() )
73  {
74  iterator.next();
75  // Convert profile's properties from QScriptValue to appropriate types
76  QString personid = iterator.value().property( "personid" ).toString();
77  QString firstName = iterator.value().property( "firstname" ).toString();
78  QString lastName = iterator.value().property( "lastname" ).toString();
79  QString city = iterator.value().property( "city" ).toString();
80  QString country = iterator.value().property( "country" ).toString();
81  QString role = iterator.value().property( "communityrole" ).toString();
82  double longitude = iterator.value().property( "longitude" ).toNumber();
83  double latitude = iterator.value().property( "latitude" ).toNumber();
84  QUrl avatarUrl( iterator.value().property( "avatarpic" ).toString() );
85 
86  if( !itemExists( personid ) )
87  {
88  // If it does not exists, create it
89  GeoDataCoordinates coor(longitude * DEG2RAD, latitude * DEG2RAD);
90  OpenDesktopItem *item = new OpenDesktopItem( this );
91  item->setMarbleWidget(m_marbleWidget);
92  item->setId( personid );
93  item->setCoordinate( coor );
94  item->setTarget( "earth" );
95  item->setFullName( QString( "%1 %2" ).arg( firstName ).arg( lastName ) );
96  item->setLocation( QString( "%1, %2" ).arg( city ).arg( country ) );
97  item->setRole( !role.isEmpty() ? role : QString( "nothing" ) );
98  downloadItem( avatarUrl, "avatar", item );
99  items << item;
100  }
101  }
102 
103  addItemsToList( items );
104  }
105 }
106 
107 #include "OpenDesktopModel.moc"
GeoDataCoordinates.h
Marble::AbstractDataPluginModel::items
QList< AbstractDataPluginItem * > items(const ViewportParams *viewport, qint32 number=10)
Get the items on the viewport Returns the currently downloaded images in the viewport.
Definition: AbstractDataPluginModel.cpp:274
Marble::RAD2DEG
const qreal RAD2DEG
Definition: MarbleGlobal.h:220
Marble::OpenDesktopItem::setLocation
void setLocation(const QString location)
Definition: OpenDesktopItem.cpp:131
Marble::OpenDesktopModel::OpenDesktopModel
OpenDesktopModel(const MarbleModel *marbleModel, QObject *parent=0)
Definition: OpenDesktopModel.cpp:27
Marble::AbstractDataPluginItem::setTarget
void setTarget(const QString &target)
Definition: AbstractDataPluginItem.cpp:66
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
QByteArray
Marble::OpenDesktopModel::setMarbleWidget
void setMarbleWidget(MarbleWidget *widget)
Definition: OpenDesktopModel.cpp:38
Marble::AbstractDataPluginModel::itemExists
bool itemExists(const QString &id) const
Testing the existence of the item id in the list.
Definition: AbstractDataPluginModel.cpp:563
MarbleModel.h
This file contains the headers for MarbleModel.
Marble::AbstractDataPluginItem::setId
void setId(const QString &id)
Definition: AbstractDataPluginItem.cpp:86
QScriptValue
QScriptEngine::evaluate
QScriptValue evaluate(const QString &program, const QString &fileName, int lineNumber)
Marble::AbstractDataPluginModel
An abstract data model (not based on QAbstractModel) for a AbstractDataPlugin.
Definition: AbstractDataPluginModel.h:45
QScriptValueIterator
Marble::AbstractDataPluginModel::marbleModel
const MarbleModel * marbleModel() const
Definition: AbstractDataPluginModel.cpp:269
Marble::GeoDataCoordinates::latitude
qreal latitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
Definition: GeoDataCoordinates.cpp:751
Marble::OpenDesktopItem::setRole
void setRole(const QString role)
Definition: OpenDesktopItem.cpp:142
Marble::OpenDesktopItem
Definition: OpenDesktopItem.h:26
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:104
QScriptEngine
Marble::AbstractDataPluginModel::downloadDescriptionFile
void downloadDescriptionFile(const QUrl &url)
Download the description file from the url.
Definition: AbstractDataPluginModel.cpp:392
QString::number
QString number(int n, int base)
QObject
OpenDesktopModel.h
QString::isEmpty
bool isEmpty() const
Marble::OpenDesktopModel::getAdditionalItems
void getAdditionalItems(const Marble::GeoDataLatLonAltBox &box, qint32 number=10)
Generates the download url for the description file from the web service depending on the box surroun...
Definition: OpenDesktopModel.cpp:43
QString
QList< AbstractDataPluginItem * >
MarbleGlobal.h
Marble::OpenDesktopModel::parseFile
void parseFile(const QByteArray &file)
Parses the file which getAdditionalItems downloads and prepares the data for usage.
Definition: OpenDesktopModel.cpp:60
Marble::DEG2RAD
const qreal DEG2RAD
Definition: MarbleGlobal.h:219
QScriptValue::property
QScriptValue property(const QString &name, const ResolveFlags &mode) const
Marble::GeoDataCoordinates::longitude
qreal longitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
Definition: GeoDataCoordinates.cpp:739
QUrl
Marble::GeoDataLatLonAltBox::center
virtual GeoDataCoordinates center() const
returns the center of this box
Definition: GeoDataLatLonAltBox.cpp:151
Marble::OpenDesktopItem::setMarbleWidget
void setMarbleWidget(MarbleWidget *widget)
Definition: OpenDesktopItem.cpp:148
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:97
Marble::OpenDesktopItem::setFullName
void setFullName(const QString fullName)
Definition: OpenDesktopItem.cpp:120
Marble::OpenDesktopModel::~OpenDesktopModel
~OpenDesktopModel()
Definition: OpenDesktopModel.cpp:33
Marble::BillboardGraphicsItem::setCoordinate
void setCoordinate(const GeoDataCoordinates &coordinates)
Definition: BillboardGraphicsItem.cpp:98
QScriptValue::isArray
bool isArray() const
Marble::AbstractDataPluginModel::downloadItem
void downloadItem(const QUrl &url, const QString &type, AbstractDataPluginItem *item)
Downloads the file from url.
Definition: AbstractDataPluginModel.cpp:378
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
Marble::AbstractDataPluginModel::addItemsToList
void addItemsToList(const QList< AbstractDataPluginItem * > &items)
Adds the items to the list of initialized items.
Definition: AbstractDataPluginModel.cpp:408
OpenDesktopItem.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:41 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