• 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
  • 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  MarbleLocale::MeasurementSystem const measurement =
190  (MarbleLocale::MeasurementSystem)QLocale::system().measurementSystem();
191  MarbleGlobal::getInstance()->locale()->setMeasurementSystem( measurement );
192 
193  QVariantMap cmdLineSettings;
194  if ( !mapThemeId.isEmpty() ) {
195  cmdLineSettings.insert( QLatin1String("mapTheme"), QVariant(mapThemeId) );
196  }
197 
198  if ( !coordinatesString.isEmpty() ) {
199  bool success = false;
200  const GeoDataCoordinates coordinates = GeoDataCoordinates::fromString(coordinatesString, success);
201  if ( success ) {
202  QVariantList lonLat;
203  lonLat << QVariant( coordinates.longitude(GeoDataCoordinates::Degree) )
204  << QVariant( coordinates.latitude(GeoDataCoordinates::Degree) );
205  cmdLineSettings.insert( QLatin1String("lonlat"), QVariant(lonLat) );
206  }
207  }
208  if ( !distanceString.isEmpty() ) {
209  bool success = false;
210  const qreal distance = distanceString.toDouble(&success);
211  if ( success ) {
212  cmdLineSettings.insert( QLatin1String("distance"), QVariant(distance) );
213  }
214  }
215 
216  MainWindow *window = new MainWindow( marbleDataPath, cmdLineSettings );
217  window->setAttribute( Qt::WA_DeleteOnClose, true );
218 
219 // window->marbleWidget()->rotateTo( 0, 0, -90 );
220 // window->show();
221 
222  for ( int i = 1; i < args.count(); ++i ) {
223  const QString arg = args.at(i);
224  if ( arg == "--timedemo" )
225  {
226  window->resize(900, 640);
227  MarbleTest marbleTest( window->marbleWidget() );
228  marbleTest.timeDemo();
229  return 0;
230  }
231  else if( arg == "--fps" ) {
232  window->marbleWidget()->setShowFrameRate( true );
233  }
234  else if ( arg == "--tile-id" )
235  {
236  window->marbleWidget()->setShowTileId(true);
237  }
238  else if( arg == "--runtimeTrace" ) {
239  window->marbleWidget()->setShowRuntimeTrace( true );
240  }
241  else if ( i != dataPathIndex && QFile::exists( arg ) ) {
242  window->addGeoDataFile( QFileInfo( arg ).absoluteFilePath() );
243  }
244  }
245 
246  return app.exec();
247 }
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:288
MobileMainWindow.h
Marble::MarbleDirs::path
static QString path(const QString &relativePath)
Definition: MarbleDirs.cpp:59
QProcessEnvironment
Marble::MarbleWidget::setShowRuntimeTrace
void setShowRuntimeTrace(bool visible)
Set whether the runtime tracing for layers gets shown.
Definition: MarbleWidget.cpp:959
QList::at
const T & at(int i) const
QApplication
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QWidget::setAttribute
void setAttribute(Qt::WidgetAttribute attribute, bool on)
QCoreApplication::setOrganizationDomain
void setOrganizationDomain(const QString &orgDomain)
QCoreApplication::setAttribute
void setAttribute(Qt::ApplicationAttribute attribute, bool on)
QFile::exists
bool exists() const
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
QLocale::measurementSystem
MeasurementSystem measurementSystem() const
QProcessEnvironment::contains
bool contains(const QString &name) const
QString::toDouble
double toDouble(bool *ok) const
MarbleDebug.h
Marble::MarbleLocale::MeasurementSystem
MeasurementSystem
Definition: MarbleLocale.h:37
QDir::separator
QChar separator()
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
QProcessEnvironment::value
QString value(const QString &name, const QString &defaultValue) const
QCoreApplication::addLibraryPath
void addLibraryPath(const QString &path)
QLocale::system
QLocale system()
QList::value
T value(int i) const
QWidget::resize
void resize(int w, int h)
QList::count
int count(const T &value) const
MarbleDirs.h
QString::isEmpty
bool isEmpty() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QLocale::name
QString name() const
QCoreApplication::instance
QCoreApplication * instance()
Marble::MarbleGlobal::locale
MarbleLocale * locale() const
Definition: MarbleGlobal.cpp:43
QString
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
QStringList
QFileInfo
QSettings
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
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
Marble::MarbleGlobal::SmallScreen
Definition: MarbleGlobal.h:287
QTranslator::load
bool load(const QString &filename, const QString &directory, const QString &search_delimiters, const QString &suffix)
Marble::MarbleGlobal::getInstance
static MarbleGlobal * getInstance()
Definition: MarbleGlobal.cpp:37
MarbleTest.h
Marble::MainWindow
Definition: KdeMainWindow.h:29
QCoreApplication::installTranslator
void installTranslator(QTranslator *translationFile)
Marble::MarbleTest::timeDemo
void timeDemo()
Definition: MarbleTest.cpp:31
QSettings::value
QVariant value(const QString &key, const QVariant &defaultValue) const
QApplication::exec
int exec()
QString::mid
QString mid(int position, int n) const
QLatin1String
QApplication::setGraphicsSystem
void setGraphicsSystem(const QString &system)
QString::section
QString section(QChar sep, int start, int end, QFlags< QString::SectionFlag > flags) const
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:964
QTranslator
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
QProcessEnvironment::systemEnvironment
QProcessEnvironment systemEnvironment()
Marble::MainWindow::marbleWidget
MarbleWidget * marbleWidget() const
Definition: KdeMainWindow.cpp:153
Marble::MarbleDebug::setEnabled
static void setEnabled(bool enabled)
setEnabled Toggle debug information output generation
Definition: MarbleDebug.cpp:52
Marble::MarbleLocale::setMeasurementSystem
void setMeasurementSystem(MarbleLocale::MeasurementSystem measurementSystem)
Definition: MarbleLocale.cpp:40
QCoreApplication::arguments
QStringList arguments()
QCoreApplication::applicationDirPath
QString applicationDirPath()
QCoreApplication::setOrganizationName
void setOrganizationName(const QString &orgName)
QString::compare
int compare(const QString &other) const
Marble::MainWindow::addGeoDataFile
void addGeoDataFile(const QString &path)
Definition: MobileMainWindow.cpp:197
QVariant::toString
QString toString() const
Marble::MarbleWidget::setShowFrameRate
void setShowFrameRate(bool visible)
Set whether the frame rate gets shown.
Definition: MarbleWidget.cpp:945
QCoreApplication::setApplicationName
void setApplicationName(const QString &application)
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:40 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