• 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
  • photo
PhotoPluginModel.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 2009 Bastian Holst <bastianholst@gmx.de>
9 // Copyright 2012 Mohammed Nafees <nafees.technocool@gmail.com>
10 //
11 
12 // Self
13 #include "PhotoPluginModel.h"
14 
15 // Photo Plugin
16 #include "FlickrParser.h"
17 #include "PhotoPluginItem.h"
18 #include "PhotoPlugin.h"
19 
20 // Marble
21 #include "AbstractDataPluginItem.h"
22 #include "GeoDataLatLonAltBox.h"
23 #include "MarbleModel.h"
24 #include "MarbleDebug.h"
25 #include "MarbleWidget.h"
26 
27 // Qt
28 #include <QHash>
29 #include <QString>
30 #include <QUrl>
31 
32 using namespace Marble;
33 
34 const QString flickrApiKey( "620131a1b82b000c9582b94effcdc636" );
35 
36 PhotoPluginModel::PhotoPluginModel( const MarbleModel *marbleModel, QObject *parent )
37  : AbstractDataPluginModel( "photo", marbleModel, parent ),
38  m_marbleWidget( 0 )
39 {
40 }
41 
42 QUrl PhotoPluginModel::generateUrl( const QString& service,
43  const QString& method,
44  const QHash<QString,QString>& options )
45 {
46  QString url( "" );
47 
48  if( service == "flickr" )
49  url += "https://www.flickr.com/services/rest/";
50  else
51  return QUrl();
52 
53  url += "?method=";
54  url += method;
55  url += "&format=rest";
56  url += "&api_key=";
57  url += flickrApiKey;
58 
59  QHash<QString,QString>::const_iterator it = options.constBegin();
60  QHash<QString,QString>::const_iterator const end = options.constEnd();
61  for (; it != end; ++it ) {
62  url += '&';
63  url += it.key();
64  url += '=';
65  url += it.value();
66  }
67 
68  return QUrl( url );
69 }
70 
71 void PhotoPluginModel::getAdditionalItems( const GeoDataLatLonAltBox& box,
72  qint32 number )
73 {
74  // Flickr only supports images for earth
75  if( marbleModel()->planetId() != "earth" ) {
76  return;
77  }
78 
79  if( box.west() <= box.east() ) {
80  QString bbox( "" );
81  bbox += QString::number( box.west() * RAD2DEG ) + ',';
82  bbox += QString::number( box.south() * RAD2DEG ) + ',';
83  bbox += QString::number( box.east() * RAD2DEG ) + ',';
84  bbox += QString::number( box.north() * RAD2DEG );
85 
86  QHash<QString,QString> options;
87  options.insert( "per_page", QString::number( number ) );
88  options.insert( "bbox", bbox );
89  options.insert( "sort", "interestingness-desc" );
90  options.insert( "license", m_licenses );
91 
92  downloadDescriptionFile( generateUrl( "flickr", "flickr.photos.search", options ) );
93  }
94  else {
95  // Flickr api doesn't support bboxes with west > east so we have to split in two boxes
96  QString bboxWest( "" );
97  bboxWest += QString::number( box.west() * RAD2DEG ) + ',';
98  bboxWest += QString::number( box.south() * RAD2DEG ) + ',';
99  bboxWest += QString::number( 180 ) + ',';
100  bboxWest += QString::number( box.north() * RAD2DEG );
101 
102  QHash<QString,QString> optionsWest;
103  optionsWest.insert( "per_page", QString::number( number/2 ) );
104  optionsWest.insert( "bbox", bboxWest );
105  optionsWest.insert( "sort", "interestingness-desc" );
106  optionsWest.insert( "license", m_licenses );
107 
108  downloadDescriptionFile( generateUrl( "flickr", "flickr.photos.search", optionsWest ) );
109 
110 
111  QString bboxEast( "" );
112  bboxEast += QString::number( -180 ) + ',';
113  bboxEast += QString::number( box.south() * RAD2DEG ) + ',';
114  bboxEast += QString::number( box.east() * RAD2DEG ) + ',';
115  bboxEast += QString::number( box.north() * RAD2DEG );
116 
117  QHash<QString,QString> optionsEast;
118  optionsEast.insert( "per_page", QString::number( number/2 ) );
119  optionsEast.insert( "bbox", bboxEast );
120  optionsEast.insert( "sort", "interestingness-desc" );
121  optionsEast.insert( "license", m_licenses );
122 
123  downloadDescriptionFile( generateUrl( "flickr", "flickr.photos.search", optionsEast ) );
124  }
125 }
126 
127 void PhotoPluginModel::parseFile( const QByteArray& file )
128 {
129  QList<PhotoPluginItem*> list;
130  FlickrParser parser( m_marbleWidget, &list, this );
131 
132  parser.read( file );
133 
134  QList<PhotoPluginItem*>::iterator it;
135  QList<AbstractDataPluginItem*> items;
136 
137  for( it = list.begin(); it != list.end(); ++it ) {
138  if( itemExists( (*it)->id() ) ) {
139  delete (*it);
140  continue;
141  }
142 
143  // Currently all Flickr images with geotags are on earth
144  (*it)->setTarget( "earth" );
145  downloadItem( (*it)->photoUrl(), "thumbnail", (*it) );
146  downloadItem( (*it)->infoUrl(), "info", (*it) );
147  items << *it;
148  }
149  addItemsToList( items );
150 }
151 
152 void PhotoPluginModel::setMarbleWidget( MarbleWidget *widget )
153 {
154  m_marbleWidget = widget;
155 }
156 
157 void PhotoPluginModel::setLicenseValues( const QString &licenses )
158 {
159  m_licenses = licenses;
160 }
161 
162 #include "PhotoPluginModel.moc"
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
QHash::insert
iterator insert(const Key &key, const T &value)
QHash::key
const Key key(const T &value) const
QByteArray
flickrApiKey
const QString flickrApiKey("620131a1b82b000c9582b94effcdc636")
Marble::AbstractDataPluginModel::itemExists
bool itemExists(const QString &id) const
Testing the existence of the item id in the list.
Definition: AbstractDataPluginModel.cpp:563
Marble::PhotoPluginModel::parseFile
void parseFile(const QByteArray &file)
The reimplementation has to parse the file and should generate items.
Definition: PhotoPluginModel.cpp:127
MarbleModel.h
This file contains the headers for MarbleModel.
Marble::PhotoPluginModel::getAdditionalItems
void getAdditionalItems(const GeoDataLatLonAltBox &box, qint32 number=10)
Generates the download url for the description file from the web service depending on the box surroun...
Definition: PhotoPluginModel.cpp:71
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::FlickrParser
Definition: FlickrParser.h:26
MarbleDebug.h
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:104
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
QString::number
QString number(int n, int base)
QHash::constEnd
const_iterator constEnd() const
QHash< QString, QString >
QObject
PhotoPluginModel.h
Marble::PhotoPluginModel::setMarbleWidget
void setMarbleWidget(MarbleWidget *widget)
Definition: PhotoPluginModel.cpp:152
QString
QList
Marble::FlickrParser::read
bool read(QByteArray data)
Definition: FlickrParser.cpp:32
Marble::PhotoPluginModel::generateUrl
static QUrl generateUrl(const QString &service, const QString &method, const QHash< QString, QString > &options)
Definition: PhotoPluginModel.cpp:42
QList::iterator
QList::end
iterator end()
QHash::value
const T value(const Key &key) const
QUrl
Marble::PhotoPluginModel::PhotoPluginModel
PhotoPluginModel(const MarbleModel *marbleModel, QObject *parent=0)
Definition: PhotoPluginModel.cpp:36
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
QHash::constBegin
const_iterator constBegin() const
Marble::PhotoPluginModel::setLicenseValues
void setLicenseValues(const QString &licenses)
Definition: PhotoPluginModel.cpp:157
FlickrParser.h
PhotoPlugin.h
GeoDataLatLonAltBox.h
Marble::GeoDataLatLonBox::south
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:114
MarbleWidget.h
This file contains the headers for MarbleWidget.
PhotoPluginItem.h
QList::begin
iterator begin()
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
AbstractDataPluginItem.h
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