• 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
  • 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  updateHome();
31  connect(marbleModel, SIGNAL(homeChanged(GeoDataCoordinates)), SLOT(updateHome()));
32 
33  // translate known values for tags and cache types
34  // What would be a nice place for this??? Put here, since this object is only
35  // constructed once.
36  // note to translators: "cache" in this context means "geocache",
37  // please refer to opencaching.com and wikipedia if in doubt.
38  tr("Boat required");
39  tr("Chirp");
40  tr("Diving");
41  tr("Exclusive");
42  tr("Historic site");
43  tr("Letterbox");
44  tr("Night");
45  tr("Tree climbing");
46  tr("UV light");
47 
48  tr("Traditional Cache");
49  tr("Multi-cache");
50  tr("Virtual Cache");
51  tr("Puzzle Cache");
52  tr("Unknown Cache");
53 }
54 
55 OpenCachingComModel::~OpenCachingComModel()
56 {
57 }
58 
59 void OpenCachingComModel::getAdditionalItems( const GeoDataLatLonAltBox& box, qint32 number )
60 {
61  if( marbleModel()->planetId() != "earth" )
62  {
63  return;
64  }
65 
66  if ( m_previousbox.contains( box ) )
67  {
68  return;
69  }
70 
71  QString url("http://www.opencaching.com/api/geocache/?Authorization=");
72  url += AUTHKEY + QString("&bbox=%1,%2,%3,%4")
73  .arg( box.south( GeoDataCoordinates::Degree ) )
74  .arg( box.west(GeoDataCoordinates::Degree ) )
75  .arg( box.north(GeoDataCoordinates::Degree ) )
76  .arg( box.east(GeoDataCoordinates::Degree ) );
77  if(!m_previousbox.isNull())
78  {
79  url += QString("&exclude_bbox=%1,%2,%3,%4")
80  .arg( m_previousbox.south( GeoDataCoordinates::Degree ) )
81  .arg( m_previousbox.west(GeoDataCoordinates::Degree ) )
82  .arg( m_previousbox.north(GeoDataCoordinates::Degree ) )
83  .arg( m_previousbox.east(GeoDataCoordinates::Degree ) );
84  }
85  url += "&limit=" + QString::number( number );
86  // TODO Limit to user set tags/types/difficulty - when there is a config dialog...
87 
88  m_previousbox = box;
89 
90 // qDebug()<<"Fetching more caches: "<<url;
91  downloadDescriptionFile( QUrl( url ) );
92 }
93 
94 void OpenCachingComModel::parseFile( const QByteArray& file )
95 {
96  QScriptEngine engine;
97 
98  // Qt requires parentheses around json code
99  QScriptValue data = engine.evaluate( '(' + QString::fromUtf8( file ) + ')' );
100  QVariantList caches = data.toVariant().toList();
101 
102 // qDebug()<<"parsing "<<caches.size()<<" items";
103  QList<AbstractDataPluginItem*> items;
104  while (!caches.isEmpty())
105  {
106  QVariantMap map = caches.takeFirst().toMap();
107  if ( !findItem( map["oxcode"].toString() ) )
108  {
109  items << new OpenCachingComItem( map, this );
110  }
111  }
112  addItemsToList(items);
113 }
114 
115 void OpenCachingComModel::fetchData(const QString& url, const QString &type, OpenCachingComItem *item)
116 {
117  downloadItem(url, type, item);
118 }
119 
120 const GeoDataCoordinates OpenCachingComModel::home() const
121 {
122  return m_homeCoordinates;
123 }
124 
125 void OpenCachingComModel::updateHome()
126 {
127  qreal lon, lat;
128  int zoom;
129  marbleModel()->home( lon, lat, zoom );
130  m_homeCoordinates = GeoDataCoordinates(lon, lat, 0, GeoDataCoordinates::Degree);
131 }
132 
133 } // namespace Marble
134 
135 #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
OpenCachingComModel.h
MarbleModel.h
This file contains the headers for MarbleModel.
Marble::OpenCachingComModel::OpenCachingComModel
OpenCachingComModel(const MarbleModel *marbleModel, QObject *parent=0)
Definition: OpenCachingComModel.cpp:27
OpenCachingComItem.h
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
Marble::GeoDataLatLonAltBox::contains
virtual bool contains(const GeoDataCoordinates &) const
Definition: GeoDataLatLonAltBox.cpp:171
QObject
MarbleDebug.h
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:276
Marble::GeoDataLatLonBox::north
qreal north(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the northern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:93
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
Marble::MarbleModel::home
void home(qreal &lon, qreal &lat, int &zoom) const
get the home point
Definition: MarbleModel.cpp:376
Marble::OpenCachingComModel::home
const GeoDataCoordinates home() const
home location
Definition: OpenCachingComModel.cpp:120
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:55
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:96
Marble::OpenCachingComModel::fetchData
void fetchData(const QString &url, const QString &type, OpenCachingComItem *item)
Fetch a file for a cache.
Definition: OpenCachingComModel.cpp:115
Marble::OpenCachingComModel::parseFile
void parseFile(const QByteArray &file)
Parses the file which getAdditionalItems downloads and prepares the data for usage.
Definition: OpenCachingComModel.cpp:94
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:59
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-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:51 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