• 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
  • apps
  • marble-mobile
src/apps/marble-mobile/main.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 2006-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 //
11 
12 #include <QApplication>
13 #include <QFile>
14 #include <QDir>
15 #include <QLocale>
16 #include <QSettings>
17 #include <QTranslator>
18 #include <QProcessEnvironment>
19 
20 #include "MobileMainWindow.h"
21 
22 #include "GeoDataCoordinates.h"
23 #include "MarbleGlobal.h"
24 #include "MarbleDirs.h"
25 #include "MarbleDebug.h"
26 #include "MarbleLocale.h"
27 #include "MarbleWidget.h"
28 #include "MarbleTest.h"
29 
30 #ifdef STATIC_BUILD
31  #include <QtPlugin>
32  Q_IMPORT_PLUGIN(qjpeg)
33  Q_IMPORT_PLUGIN(qsvg)
34 #endif
35 
36 #ifdef Q_OS_MACX
37 //for getting app bundle path
38 #include <ApplicationServices/ApplicationServices.h>
39 #endif
40 
41 using namespace Marble;
42 
43 int main(int argc, char *argv[])
44 {
45 #if QT_VERSION < 0x050000
46  // The GraphicsSystem needs to be set before the instantiation of the
47  // QApplication. Therefore we need to parse the current setting
48  // in this unusual place :-/
49  QSettings graphicsSettings("KDE", "Marble Virtual Globe"); // keep the parameters here
50  QString const graphicsString = graphicsSettings.value("View/graphicsSystem", "raster").toString();
51  QApplication::setGraphicsSystem( graphicsString );
52 #endif
53 
54  QApplication app(argc, argv);
55  app.setApplicationName( "Marble Virtual Globe" );
56  app.setOrganizationName( "KDE" );
57  app.setOrganizationDomain( "kde.org" );
58  // Widget translation
59 
60 #ifdef Q_WS_MAEMO_5
61  // Work around http://bugreports.qt-project.org/browse/QTBUG-1313
62  QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
63  QString lang( "C" );
64  QStringList const locales = QStringList() << "LC_ALL" << "LC_MESSAGES" << "LANG" << "LANGUAGE";
65  foreach( const QString &locale, locales ) {
66  if ( env.contains( locale ) && !env.value( locale ).isEmpty() ) {
67  lang = env.value( locale, "C" );
68  break;
69  }
70  }
71 
72  lang = lang.section( '_', 0, 0 );
73 #else
74  QString lang = QLocale::system().name().section('_', 0, 0);
75 #endif
76  QTranslator translator;
77  translator.load( "marble-" + lang, MarbleDirs::path(QString("lang") ) );
78  app.installTranslator(&translator);
79 
80  // For non static builds on mac and win
81  // we need to be sure we can find the qt image
82  // plugins. In mac be sure to look in the
83  // application bundle...
84 
85 #ifdef Q_WS_WIN
86  QApplication::addLibraryPath( QApplication::applicationDirPath()
87  + QDir::separator() + "plugins" );
88 #endif
89 #ifdef Q_OS_MACX
90  QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus);
91  qDebug("Adding qt image plugins to plugin search path...");
92  CFURLRef myBundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
93  CFStringRef myMacPath = CFURLCopyFileSystemPath(myBundleRef, kCFURLPOSIXPathStyle);
94  const char *mypPathPtr = CFStringGetCStringPtr(myMacPath,CFStringGetSystemEncoding());
95  CFRelease(myBundleRef);
96  CFRelease(myMacPath);
97  QString myPath(mypPathPtr);
98  // if we are not in a bundle assume that the app is built
99  // as a non bundle app and that image plugins will be
100  // in system Qt frameworks. If the app is a bundle
101  // lets try to set the qt plugin search path...
102  if (myPath.contains(".app"))
103  {
104  myPath += "/Contents/plugins";
105  QApplication::addLibraryPath( myPath );
106  qDebug( "Added %s to plugin search path", qPrintable( myPath ) );
107  }
108 #endif
109 
110  QString marbleDataPath;
111  int dataPathIndex=0;
112  QString mapThemeId;
113  QString coordinatesString;
114  QString distanceString;
115  const MarbleGlobal::Profiles profiles = MarbleGlobal::SmallScreen | MarbleGlobal::HighResolution;
116 
117  QStringList args = QApplication::arguments();
118 
119  if ( args.contains( "-h" ) || args.contains( "--help" ) ) {
120  qWarning() << "Usage: marble [options] [files]";
121  qWarning();
122  qWarning() << "[files] can be zero, one or more .kml and/or .gpx files to load and show.";
123  qWarning();
124  qWarning() << "general options:";
125  qWarning() << " --marbledatapath=<path> .... Overwrite the compile-time path to map themes and other data";
126  qWarning() << " --latlon=<coordinates> ..... Show map at given lat lon coordinates";
127  qWarning() << " --distance=<value> ......... Set the distance of the observer to the globe (in km)";
128  qWarning() << " --map=<id> ................. Use map id (e.g. \"earth/openstreetmap/openstreetmap.dgml\")";
129  qWarning();
130  qWarning() << "debug options:";
131  qWarning() << " --debug-info ............... write (more) debugging information to the console";
132  qWarning() << " --fps ...................... Show the paint performance (paint rate) in the top left corner";
133  qWarning() << " --runtimeTrace.............. Show the time spent and other debug info of each layer";
134  qWarning() << " --tile-id................... Write the identifier of texture tiles on top of them";
135  qWarning() << " --timedemo ................. Measure the paint performance while moving the map and quit";
136 
137  return 0;
138  }
139 
140  for ( int i = 1; i < args.count(); ++i ) {
141  const QString arg = args.at(i);
142 
143  if ( arg == QLatin1String( "--debug-info" ) )
144  {
145  MarbleDebug::setEnabled( true );
146  }
147  else if ( arg.startsWith( QLatin1String( "--marbledatapath=" ), Qt::CaseInsensitive ) )
148  {
149  marbleDataPath = args.at(i).mid(17);
150  }
151  else if ( arg.compare( QLatin1String( "--marbledatapath" ), Qt::CaseInsensitive ) == 0 ) {
152  dataPathIndex = i + 1;
153  marbleDataPath = args.value( dataPathIndex );
154  ++i;
155  }
156  else if ( arg.startsWith( QLatin1String( "--latlon=" ), Qt::CaseInsensitive ) )
157  {
158  coordinatesString = arg.mid(9);
159  }
160  else if ( arg.compare( QLatin1String( "--latlon" ), Qt::CaseInsensitive ) == 0 ) {
161  ++i;
162  // TODO: misses an error check if there is a value at all
163  // and error reporting to user (problem also exists with marbledatapath)
164  coordinatesString = args.value( i );
165  }
166  else if ( arg.startsWith( QLatin1String( "--distance=" ), Qt::CaseInsensitive ) )
167  {
168  distanceString = arg.mid(11);
169  }
170  else if ( arg.compare( QLatin1String( "--distance" ), Qt::CaseInsensitive ) == 0 ) {
171  ++i;
172  // TODO: misses an error check if there is a value at all
173  // and error reporting to user (problem also exists with marbledatapath)
174  distanceString = args.value( i );
175  }
176  else if ( arg.startsWith( QLatin1String( "--map=" ), Qt::CaseInsensitive ) )
177  {
178  mapThemeId = arg.mid(6);
179  }
180  else if ( arg.compare( QLatin1String( "--map" ), Qt::CaseInsensitive ) == 0 ) {
181  ++i;
182  // TODO: misses an error check if there is a value at all
183  // and error reporting to user (problem also exists with marbledatapath)
184  mapThemeId = args.value( i );
185  }
186  }
187  MarbleGlobal::getInstance()->setProfiles( profiles );
188 
189  QLocale::MeasurementSystem const measurement = QLocale::system().measurementSystem();
190  MarbleGlobal::getInstance()->locale()->setMeasurementSystem( measurement );
191 
192  QVariantMap cmdLineSettings;
193  if ( !mapThemeId.isEmpty() ) {
194  cmdLineSettings.insert( QLatin1String("mapTheme"), QVariant(mapThemeId) );
195  }
196 
197  if ( !coordinatesString.isEmpty() ) {
198  bool success = false;
199  const GeoDataCoordinates coordinates = GeoDataCoordinates::fromString(coordinatesString, success);
200  if ( success ) {
201  QVariantList lonLat;
202  lonLat << QVariant( coordinates.longitude(GeoDataCoordinates::Degree) )
203  << QVariant( coordinates.latitude(GeoDataCoordinates::Degree) );
204  cmdLineSettings.insert( QLatin1String("lonlat"), QVariant(lonLat) );
205  }
206  }
207  if ( !distanceString.isEmpty() ) {
208  bool success = false;
209  const qreal distance = distanceString.toDouble(&success);
210  if ( success ) {
211  cmdLineSettings.insert( QLatin1String("distance"), QVariant(distance) );
212  }
213  }
214 
215  MainWindow *window = new MainWindow( marbleDataPath, cmdLineSettings );
216  window->setAttribute( Qt::WA_DeleteOnClose, true );
217 
218 // window->marbleWidget()->rotateTo( 0, 0, -90 );
219 // window->show();
220 
221  for ( int i = 1; i < args.count(); ++i ) {
222  const QString arg = args.at(i);
223  if ( arg == "--timedemo" )
224  {
225  window->resize(900, 640);
226  MarbleTest marbleTest( window->marbleWidget() );
227  marbleTest.timeDemo();
228  return 0;
229  }
230  else if( arg == "--fps" ) {
231  window->marbleWidget()->setShowFrameRate( true );
232  }
233  else if ( arg == "--tile-id" )
234  {
235  window->marbleWidget()->setShowTileId(true);
236  }
237  else if( arg == "--runtimeTrace" ) {
238  window->marbleWidget()->setShowRuntimeTrace( true );
239  }
240  else if ( i != dataPathIndex && QFile::exists( arg ) ) {
241  window->addGeoDataFile( QFileInfo( arg ).absoluteFilePath() );
242  }
243  }
244 
245  return app.exec();
246 }
GeoDataCoordinates.h
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::MarbleGlobal::setProfiles
void setProfiles(Profiles profiles)
Definition: MarbleGlobal.cpp:52
Marble::MarbleGlobal::HighResolution
Definition: MarbleGlobal.h:269
MobileMainWindow.h
Marble::MarbleDirs::path
static QString path(const QString &relativePath)
Definition: MarbleDirs.cpp:53
Marble::MarbleWidget::setShowRuntimeTrace
void setShowRuntimeTrace(bool visible)
Set whether the runtime tracing for layers gets shown.
Definition: MarbleWidget.cpp:1065
Marble::MarbleLocale::setMeasurementSystem
void setMeasurementSystem(QLocale::MeasurementSystem measurementSystem)
Definition: MarbleLocale.cpp:40
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
MarbleDebug.h
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
MarbleDirs.h
Marble::MarbleGlobal::locale
MarbleLocale * locale() const
Definition: MarbleGlobal.cpp:43
MarbleLocale.h
MarbleGlobal.h
Marble::MarbleTest
Definition: MarbleTest.h:24
main
int main(int argc, char *argv[])
Definition: src/apps/marble-mobile/main.cpp:43
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
Marble::MarbleGlobal::SmallScreen
Definition: MarbleGlobal.h:268
Marble::MarbleGlobal::getInstance
static MarbleGlobal * getInstance()
Definition: MarbleGlobal.cpp:37
MarbleTest.h
Marble::MainWindow
Definition: KdeMainWindow.h:26
Marble::MarbleTest::timeDemo
void timeDemo()
Definition: MarbleTest.cpp:31
Marble::MarbleWidget::setShowTileId
void setShowTileId(bool visible)
Set whether the is tile is visible NOTE: This is part of the transitional debug API and might be subj...
Definition: MarbleWidget.cpp:1070
MarbleWidget.h
This file contains the headers for MarbleWidget.
Marble::GeoDataCoordinates::fromString
static GeoDataCoordinates fromString(const QString &string, bool &successful)
try to parse the string into a coordinate pair
Definition: GeoDataCoordinates.cpp:909
Marble::MainWindow::marbleWidget
MarbleWidget * marbleWidget() const
Definition: KdeMainWindow.cpp:79
Marble::MarbleDebug::setEnabled
static void setEnabled(bool enabled)
setEnabled Toggle debug information output generation
Definition: MarbleDebug.cpp:47
Marble::MainWindow::addGeoDataFile
void addGeoDataFile(const QString &path)
Definition: MobileMainWindow.cpp:197
Marble::MarbleWidget::setShowFrameRate
void setShowFrameRate(bool visible)
Set whether the frame rate gets shown.
Definition: MarbleWidget.cpp:1051
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