• 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
  • twitter
twitterPlugin.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 Shashank Singh <shashank.personal@gmail.com>
9 //
10 
11 #include "twitterPlugin.h"
12 
13 #include <QColor>
14 #include <QPixmap>
15 #include <QRadialGradient>
16 #include <QSize>
17 #include <QRegExp>
18 
19 using namespace Marble;
20 
25 twitterPlugin::~twitterPlugin()
26 {
27 // delete m_storagePolicy;
28 }
29 
30 QStringList twitterPlugin::backendTypes() const
31 {
32  return QStringList("twitter");
33 }
34 
35 QString twitterPlugin::renderPolicy() const
36 {
37  return QString("ALWAYS");
38 }
39 
40 QStringList twitterPlugin::renderPosition() const
41 {
42  return QStringList("ALWAYS_ON_TOP");
43 }
44 
45 QString twitterPlugin::name() const
46 {
47  return tr("twitter ");
48 }
49 
50 QString twitterPlugin::guiString() const
51 {
52  return tr("&twitter");
53 }
54 
55 QString twitterPlugin::nameId() const
56 {
57  return QString("twitter");
58 }
59 
60 QString twitterPlugin::description() const
61 {
62  return tr("show public twitts in their places");
63 }
64 
65 QIcon twitterPlugin::icon() const
66 {
67  return QIcon();
68 }
69 
70 
71 void twitterPlugin::initialize()
72 {
73  privateFlagForRenderingTwitts = 0;
74  m_storagePolicy = new CacheStoragePolicy(MarbleDirs::localPath() + "/cache/");
75  m_downloadManager = new HttpDownloadManager(QUrl("http://twiter.com"), m_storagePolicy);
76  downloadtwitter(0, 0, 0.0, 0.0, 0.0, 0.0);
77  mDebug() << "twitter plugin was started";
78 }
79 
80 bool twitterPlugin::isInitialized() const
81 {
82  return true;
83 }
84 
85 bool twitterPlugin::render(GeoPainter *painter, ViewportParams *viewport,
86  const QString& renderPos, GeoSceneLayer * layer)
87 {
88  QBrush brush(QColor(99, 198, 198, 80));
89  painter->setPen(QColor(198, 99, 99, 255));
90  brush.setColor(QColor(255, 255, 255, 200));
91  brush.setStyle(Qt::SolidPattern);
92  painter->setBrush(brush);
93 
94  if (privateFlagForRenderingTwitts >= 1) {
95  for (int counter = 0;counter < 4;counter++)
96 //painter->drawAnnotation(GeoDataCoordinates(0.0,0.0),"hiiiiiiiiii");
97 
98 painter->drawAnnotation(twitsWithLocation[counter].location,
99  parsedData[counter].user + " said \n"
100  + parsedData[counter].text,
101  QSize(140, 140)) ;
102  } else {
103  painter->drawAnnotation(GeoDataCoordinates(0.0, 0.0, 0.0,
104  GeoDataCoordinates::Degree),
105  "Twitts are being Downlaoded @Twitter/Identi.CA Plugin");
106  }
107  return true;
108 }
109 
110 void twitterPlugin::slotJsonDownloadComplete(QString relativeUrlString, QString id)
111 {
112 static int counter=0;
113 twitterStructure temp;
114 //mDebug()<<"::::"<<temp.;
115 //temp.twit = parsedData[counter].text ;
116  parsedData = twitterJsonParser.parseAllObjects(QString::fromUtf8(m_storagePolicy->data(id)), 20);
117 mDebug()<<"::::::::::::::::slot"<<parsedData[0].text;
118  disconnect(m_downloadManager, SIGNAL(downloadComplete(QString,QString)), this, SLOT(slotJsonDownloadComplete(QString,QString)) );
119 
120  connect(m_downloadManager, SIGNAL(downloadComplete(QString,QString)), this, SLOT(slotGeoCodingReplyRecieved(QString,QString)) );
121  for (int counter = 0;counter < 10;counter++) {
122  if (parsedData[counter].location != "null") {
123  parsedData[counter].location.replace(QRegExp("[?,:!/\\s]+"), "+");//remove whitespace and replace it with + for query api
124  findLatLonOfStreetAddress(parsedData [ counter ].location) ; //this will set temp
125  }
126  }
127 }
128 
129 
130 void twitterPlugin::downloadtwitter(int rangeFrom , int rangeTo , qreal east , qreal west , qreal north , qreal south)
131 {
132 mDebug()<<"::::::downloading"<<rangeFrom ;
134  m_downloadManager->addJob(QUrl("http://twitter.com/statuses/public_timeline.json"), "twitter", "twitter");
135 // m_downloadManager->addJob(QUrl("http://identi.ca/api/statuses/public_timeline.json"), "identica", "identica");
136 
137  connect(m_downloadManager, SIGNAL(downloadComplete(QString,QString)), this, SLOT(slotJsonDownloadComplete(QString,QString)) );
138 
139 }
140 
141 
142 void twitterPlugin::findLatLonOfStreetAddress(QString streetAddress)
143 {
144  m_downloadManager->addJob("http://maps.google.com/maps/geo?q=" + streetAddress + "&output=json&key=ABQIAAAASD_v8YRzG0tBD18730KjmRTxoHoIpYL45xcSRJH0O7cH64DuXRT7rQeRcgCLAhjkteQ8vkWAATM_JQ", streetAddress, streetAddress);
145  mDebug() << "twitter added Geo Coding job for " << streetAddress;
146 }
147 
148 void twitterPlugin::slotGeoCodingReplyRecieved(QString relativeUrlString, QString id)
149 {
150  static int localCountOfTwitts = 0;
151  twitterStructure twitterData;
152  googleMapDataStructure geoCodedData;
153 
154  geoCodedData = twitterJsonParser.geoCodingAPIparseObject(QString::fromUtf8(m_storagePolicy->data(id))) ;
155  twitterData.twit = "hi" ;
156  twitterData.location = GeoDataCoordinates(geoCodedData.lat, geoCodedData.lon, 1.0, GeoDataCoordinates::Degree);
157  twitsWithLocation.append(twitterData);
158  localCountOfTwitts ++;
159 mDebug()<<"::::::::::::::::::::twitter count has value == " << localCountOfTwitts;
160  if (localCountOfTwitts >= 1)
161  privateFlagForRenderingTwitts = 1;//1 means unblock
162 }
163 
164 
165 
166 Q_EXPORT_PLUGIN2(twitterPlugin, Marble::twitterPlugin)
167 
168  #include "twitterPlugin.moc"
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::HttpDownloadManager::addJob
void addJob(const QUrl &sourceUrl, const QString &destFilename, const QString &id, const DownloadUsage usage)
Adds a new job with a sourceUrl, destination file name and given id.
Definition: HttpDownloadManager.cpp:129
Marble::twitterPlugin::guiString
QString guiString() const
String that should be displayed in GUI.
Definition: twitterPlugin.cpp:50
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::twitterPlugin::backendTypes
QStringList backendTypes() const
Returns the name(s) of the backend that the plugin can render This method should return the name of t...
Definition: twitterPlugin.cpp:30
Marble::twitterStructure
The class that specifies the a simple panormaio plugin.
Definition: twitterPlugin.h:37
twitterPlugin.h
Marble::twitterPlugin::slotGeoCodingReplyRecieved
void slotGeoCodingReplyRecieved(QString, QString)
Definition: twitterPlugin.cpp:148
Marble::twitterPlugin::icon
QIcon icon() const
Returns an icon for the plugin.
Definition: twitterPlugin.cpp:65
QBrush
Marble::MarbleDirs::localPath
static QString localPath()
Definition: MarbleDirs.cpp:223
jsonParser::geoCodingAPIparseObject
googleMapDataStructure geoCodingAPIparseObject(QString content)
Definition: twitter/jsonparser.cpp:61
Marble::twitterPlugin::nameId
QString nameId() const
Returns the unique name of the plugin.
Definition: twitterPlugin.cpp:55
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QBrush::setStyle
void setStyle(Qt::BrushStyle style)
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
Marble::CacheStoragePolicy
Definition: CacheStoragePolicy.h:25
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::twitterStructure::location
GeoDataCoordinates location
Definition: twitterPlugin.h:40
QRegExp
Marble::twitterPlugin::renderPolicy
QString renderPolicy() const
Return how the plugin settings should be used.
Definition: twitterPlugin.cpp:35
Marble::twitterPlugin::description
QString description() const
Returns a user description of the plugin.
Definition: twitterPlugin.cpp:60
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
QString::fromUtf8
QString fromUtf8(const char *str, int size)
Marble::twitterPlugin::slotJsonDownloadComplete
void slotJsonDownloadComplete(QString, QString)
Definition: twitterPlugin.cpp:110
Marble::twitterStructure::twit
QString twit
Definition: twitterPlugin.h:39
QPainter::setPen
void setPen(const QColor &color)
Marble::twitterPlugin
Definition: twitterPlugin.h:43
googleMapDataStructure::lat
qreal lat
Definition: twitter/jsonparser.h:39
Marble::twitterPlugin::isInitialized
bool isInitialized() const
Definition: twitterPlugin.cpp:80
QPainter::setBrush
void setBrush(const QBrush &brush)
Marble::GeoPainter::drawAnnotation
void drawAnnotation(const GeoDataCoordinates &position, const QString &text, QSizeF bubbleSize=QSizeF(130, 100), qreal bubbleOffsetX=-10, qreal bubbleOffsetY=-30, qreal xRnd=5, qreal yRnd=5)
Draws a text annotation that points to a geodesic position.
Definition: GeoPainter.cpp:197
Marble::twitterPlugin::~twitterPlugin
~twitterPlugin()
Right now this plugin displays public twit from Twitter , and gecocodes [i.e getting lat lon from a g...
Definition: twitterPlugin.cpp:25
QString
QColor
Marble::twitterPlugin::render
bool render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer=0)
Renders the content provided by the layer on the viewport.
Definition: twitterPlugin.cpp:85
QStringList
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Q_EXPORT_PLUGIN2
#define Q_EXPORT_PLUGIN2(a, b)
Definition: marble_export.h:34
QSize
QUrl
Marble::twitterPlugin::renderPosition
QStringList renderPosition() const
Preferred level in the layer stack for the rendering.
Definition: twitterPlugin.cpp:40
googleMapDataStructure::lon
qreal lon
Definition: twitter/jsonparser.h:40
Marble::twitterPlugin::initialize
void initialize()
Definition: twitterPlugin.cpp:71
Marble::CacheStoragePolicy::data
QByteArray data(const QString &fileName)
Returns the data of a file.
Definition: CacheStoragePolicy.cpp:56
jsonParser::parseAllObjects
QList< panoramioDataStructure > parseAllObjects(const QString &content, int number)
Definition: panoramio/jsonparser.cpp:88
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
googleMapDataStructure
Definition: twitter/jsonparser.h:37
QBrush::setColor
void setColor(const QColor &color)
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
QIcon
Marble::twitterPlugin::name
QString name() const
Returns the user-visible name of the plugin.
Definition: twitterPlugin.cpp:45
Marble::HttpDownloadManager
This class manages scheduled downloads.
Definition: HttpDownloadManager.h:44
QList::replace
void replace(int i, const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:42 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