• 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
  • runner
  • gpsbabel
GpsbabelRunner.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 2013 Mohammed Nafees <nafees.technocool@gmail.com>
9 
10 #include "GpsbabelRunner.h"
11 
12 #include "GeoDataParser.h"
13 #include "GeoDataDocument.h"
14 
15 #include <QFile>
16 #include <QProcess>
17 #include <QFileInfo>
18 #include <QTemporaryFile>
19 #include <QDir>
20 #include <QMap>
21 
22 namespace Marble
23 {
24 
25 GpsbabelRunner::GpsbabelRunner( QObject *parent ) :
26  ParsingRunner( parent )
27 {
28 }
29 
30 void GpsbabelRunner::parseFile( const QString &fileName, DocumentRole role )
31 {
32  // Check and see if the file exists
33  if ( !QFileInfo( fileName ).exists() ) {
34  qWarning( "File does not exist!" );
35  emit parsingFinished( 0 );
36  return;
37  }
38 
39  // Inspect the filename suffix
40  QString const fileSuffix = QFileInfo( fileName ).suffix();
41 
42  // Determine if fileName suffix is supported by this plugin
43  QMap<QString,QString> fileTypes;
44  fileTypes["nmea"] = "nmea";
45  fileTypes["igc"] = "igc";
46  fileTypes["tiger"] = "tiger";
47  fileTypes["ov2"] = "tomtom";
48  fileTypes["garmin"] = "garmin_txt";
49  fileTypes["magellan"] = "magellan";
50  fileTypes["csv"] = "csv";
51  QString const inputFileType = fileTypes[fileSuffix];
52  if ( inputFileType.isEmpty() ) {
53  qWarning( "File type is not supported !" );
54  emit parsingFinished( 0 );
55  return;
56  }
57 
58  // Set up temporary file to hold output KML from gpsbabel executable
59  QTemporaryFile tempKmlFile( QDir::tempPath() + "/marble-gpsbabel-XXXXXX.kml" );
60  tempKmlFile.open();
61  QFile kmlFile( tempKmlFile.fileName() );
62 
63  // Set up gpsbabel command line
64  QString command = "gpsbabel -i " + inputFileType;
65  command += " -f " + fileName + " -o kml -F ";
66  command += tempKmlFile.fileName();
67 
68  // Execute gpsbabel to parse the input file
69  if ( QProcess::execute( command ) == 0 ) {
70  kmlFile.open( QIODevice::ReadWrite );
71  GeoDataParser parser( GeoData_KML );
72  parser.read( &kmlFile );
73  GeoDataDocument *document = dynamic_cast<GeoDataDocument*>( parser.releaseDocument() );
74  if ( !document ) {
75  emit parsingFinished( 0, "Unable to open " + fileName );
76  return;
77  }
78 
79  document->setDocumentRole( role );
80  emit parsingFinished( document );
81  } else {
82  emit parsingFinished( 0, "GPSBabel failed to parse the input file." );
83  }
84 }
85 
86 }
87 
88 #include "GpsbabelRunner.moc"
QProcess::execute
int execute(const QString &program, const QStringList &arguments)
GeoDataDocument.h
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:65
Marble::GeoDataParser
Definition: GeoDataParser.h:40
Marble::GeoDataDocument::setDocumentRole
void setDocumentRole(DocumentRole role)
Definition: GeoDataDocument.cpp:86
QMap< QString, QString >
GeoDataParser.h
QFile
Marble::ParsingRunner::parsingFinished
void parsingFinished(GeoDataDocument *document, const QString &error=QString())
File parsing is finished, result in the given document object.
Marble::GeoData_KML
Definition: GeoDataParser.h:36
Marble::GeoParser::read
bool read(QIODevice *)
Main API for reading the XML document.
Definition: GeoParser.cpp:74
QDir::tempPath
QString tempPath()
QObject
QString::isEmpty
bool isEmpty() const
Marble::GpsbabelRunner::GpsbabelRunner
GpsbabelRunner(QObject *parent=0)
Definition: GpsbabelRunner.cpp:25
QString
Marble::ParsingRunner
Definition: ParsingRunner.h:23
QFileInfo
QTemporaryFile::fileName
QString fileName() const
QFileInfo::suffix
QString suffix() const
Marble::GpsbabelRunner::parseFile
virtual void parseFile(const QString &fileName, DocumentRole role)
Start a file parsing.
Definition: GpsbabelRunner.cpp:30
GpsbabelRunner.h
QTemporaryFile
QTemporaryFile::open
bool open()
Marble::DocumentRole
DocumentRole
Definition: GeoDataDocument.h:39
Marble::GeoParser::releaseDocument
GeoDocument * releaseDocument()
retrieve the parsed document and reset the parser If parsing was successful, retrieve the resulting d...
Definition: GeoParser.cpp:205
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 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