• 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
  • opencachingcom
OpenCachingComModel.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 2012 Anders Lund <anders@alweb.dk>
9 //
10 
11 #include "OpenCachingComModel.h"
12 #include "OpenCachingComItem.h"
13 
14 #include "MarbleGlobal.h"
15 #include "MarbleModel.h"
16 #include "GeoDataCoordinates.h"
17 #include "MarbleDebug.h"
18 
19 #include <QDebug>
20 #include <QString>
21 #include <QUrl>
22 #include <QScriptEngine>
23 #include <QScriptValue>
24 
25 namespace Marble {
26 
27 OpenCachingComModel::OpenCachingComModel( const MarbleModel *marbleModel, QObject *parent )
28  : AbstractDataPluginModel( "opencachingcom", marbleModel, parent )
29 {
30  // translate known values for tags and cache types
31  // What would be a nice place for this??? Put here, since this object is only
32  // constructed once.
33  // note to translators: "cache" in this context means "geocache",
34  // please refer to opencaching.com and wikipedia if in doubt.
35  tr("Boat required");
36  tr("Chirp");
37  tr("Diving");
38  tr("Exclusive");
39  tr("Historic site");
40  tr("Letterbox");
41  tr("Night");
42  tr("Tree climbing");
43  tr("UV light");
44 
45  tr("Traditional Cache");
46  tr("Multi-cache");
47  tr("Virtual Cache");
48  tr("Puzzle Cache");
49  tr("Unknown Cache");
50 }
51 
52 OpenCachingComModel::~OpenCachingComModel()
53 {
54 }
55 
56 void OpenCachingComModel::getAdditionalItems( const GeoDataLatLonAltBox& box, qint32 number )
57 {
58  if( marbleModel()->planetId() != "earth" )
59  {
60  return;
61  }
62 
63  if ( m_previousbox.contains( box ) )
64  {
65  return;
66  }
67 
68  QString url("http://www.opencaching.com/api/geocache/?Authorization=");
69  url += AUTHKEY + QString("&bbox=%1,%2,%3,%4")
70  .arg( box.south( GeoDataCoordinates::Degree ) )
71  .arg( box.west(GeoDataCoordinates::Degree ) )
72  .arg( box.north(GeoDataCoordinates::Degree ) )
73  .arg( box.east(GeoDataCoordinates::Degree ) );
74  if(!m_previousbox.isNull())
75  {
76  url += QString("&exclude_bbox=%1,%2,%3,%4")
77  .arg( m_previousbox.south( GeoDataCoordinates::Degree ) )
78  .arg( m_previousbox.west(GeoDataCoordinates::Degree ) )
79  .arg( m_previousbox.north(GeoDataCoordinates::Degree ) )
80  .arg( m_previousbox.east(GeoDataCoordinates::Degree ) );
81  }
82  url += "&limit=" + QString::number( number );
83  // TODO Limit to user set tags/types/difficulty - when there is a config dialog...
84 
85  m_previousbox = box;
86 
87 // qDebug()<<"Fetching more caches: "<<url;
88  downloadDescriptionFile( QUrl( url ) );
89 }
90 
91 void OpenCachingComModel::parseFile( const QByteArray& file )
92 {
93  QScriptEngine engine;
94 
95  // Qt requires parentheses around json code
96  QScriptValue data = engine.evaluate( '(' + QString::fromUtf8( file ) + ')' );
97  QVariantList caches = data.toVariant().toList();
98 
99 // qDebug()<<"parsing "<<caches.size()<<" items";
100  QList<AbstractDataPluginItem*> items;
101  while (!caches.isEmpty())
102  {
103  QVariantMap map = caches.takeFirst().toMap();
104  if ( !findItem( map["oxcode"].toString() ) )
105  {
106  items << new OpenCachingComItem( map, this );
107  }
108  }
109  addItemsToList(items);
110 }
111 
112 void OpenCachingComModel::fetchData(const QString& url, const QString &type, OpenCachingComItem *item)
113 {
114  downloadItem(url, type, item);
115 }
116 
117 const GeoDataCoordinates OpenCachingComModel::home() const
118 {
119  qreal lon, lat;
120  int zoom;
121  marbleModel()->home( lon, lat, zoom );
122  return GeoDataCoordinates(lon, lat, 0, GeoDataCoordinates::Degree);
123 }
124 
125 } // namespace Marble
126 
127 #include "OpenCachingComModel.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::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::OpenCachingComItem
Definition: OpenCachingComItem.h:32
QByteArray
OpenCachingComModel.h
QVariant::toList
QList< QVariant > toList() const
MarbleModel.h
This file contains the headers for MarbleModel.
QScriptValue
Marble::OpenCachingComModel::OpenCachingComModel
OpenCachingComModel(const MarbleModel *marbleModel, QObject *parent=0)
Definition: OpenCachingComModel.cpp:27
OpenCachingComItem.h
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
Marble::AbstractDataPluginModel::marbleModel
const MarbleModel * marbleModel() const
Definition: AbstractDataPluginModel.cpp:269
QScriptValue::toVariant
QVariant toVariant() const
Marble::GeoDataLatLonAltBox::contains
virtual bool contains(const GeoDataCoordinates &) const
Definition: GeoDataLatLonAltBox.cpp:170
MarbleDebug.h
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::GeoDataLatLonAltBox::isNull
bool isNull() const
Indicates whether the bounding box only contains a single 2D point ("singularity").
Definition: GeoDataLatLonAltBox.cpp:275
Marble::GeoDataLatLonBox::north
qreal north(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the northern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:93
QScriptEngine
Marble::AbstractDataPluginModel::downloadDescriptionFile
void downloadDescriptionFile(const QUrl &url)
Download the description file from the url.
Definition: AbstractDataPluginModel.cpp:392
Marble::GeoDataLatLonBox::east
qreal east(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the eastern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:135
AUTHKEY
#define AUTHKEY
Definition: OpenCachingComModel.h:20
QString::number
QString number(int n, int base)
QString::fromUtf8
QString fromUtf8(const char *str, int size)
QObject
Marble::MarbleModel::home
void home(qreal &lon, qreal &lat, int &zoom) const
get the home point
Definition: MarbleModel.cpp:446
Marble::OpenCachingComModel::home
const GeoDataCoordinates home() const
home location
Definition: OpenCachingComModel.cpp:117
QString
QList< AbstractDataPluginItem * >
Marble::AbstractDataPluginModel::findItem
AbstractDataPluginItem * findItem(const QString &id) const
Finds the item with id in the list.
Definition: AbstractDataPluginModel.cpp:552
MarbleGlobal.h
Marble::OpenCachingComModel::~OpenCachingComModel
~OpenCachingComModel()
Definition: OpenCachingComModel.cpp:52
QUrl
Marble::GeoDataLatLonBox::west
qreal west(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the western boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:156
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:97
Marble::OpenCachingComModel::fetchData
void fetchData(const QString &url, const QString &type, OpenCachingComItem *item)
Fetch a file for a cache.
Definition: OpenCachingComModel.cpp:112
Marble::OpenCachingComModel::parseFile
void parseFile(const QByteArray &file)
Parses the file which getAdditionalItems downloads and prepares the data for usage.
Definition: OpenCachingComModel.cpp:91
Marble::GeoDataLatLonBox::south
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:114
Marble::OpenCachingComModel::getAdditionalItems
virtual void getAdditionalItems(const GeoDataLatLonAltBox &box, qint32 number=numberOfItemsOnScreen)
Generates the download url for the description file from the web service depending on the box surroun...
Definition: OpenCachingComModel.cpp:56
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) 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
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