[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [marble] tools: tools: use ParsingRunnerManager whenever possible
From: Thibaut Gridel <tgridel () free ! fr>
Date: 2014-01-14 21:31:32
Message-ID: E1W3Ba8-0002ud-IT () scm ! kde ! org
[Download RAW message or body]
Git commit 5b2ffd998ee6e7c463b03edb322f20fcc6762767 by Thibaut Gridel.
Committed on 14/01/2014 at 21:19.
Pushed by tgridel into branch 'master'.
tools: use ParsingRunnerManager whenever possible
M +28 -23 tools/kml2cache/kml2cache.cpp
M +35 -29 tools/kml2kml/kml2kml.cpp
M +0 -1 tools/poly2kml/main.cpp
http://commits.kde.org/marble/5b2ffd998ee6e7c463b03edb322f20fcc6762767
diff --git a/tools/kml2cache/kml2cache.cpp b/tools/kml2cache/kml2cache.cpp
index 30c1bdf..e896a50 100644
--- a/tools/kml2cache/kml2cache.cpp
+++ b/tools/kml2cache/kml2cache.cpp
@@ -11,14 +11,16 @@
// A simple tool to read a .kml file and write it back to a .cache file
-#include <MarbleWidget.h>
+#include <ParsingRunnerManager.h>
+#include <PluginManager.h>
#include <MarbleClock.h>
-#include <GeoDataParser.h>
#include <GeoDataDocument.h>
+#include <GeoDataFolder.h>
#include <GeoDataPlacemark.h>
#include <GeoDataExtendedData.h>
#include <GeoWriter.h>
+#include <QApplication>
#include <QDebug>
#include <QFile>
#include <iostream>
@@ -82,25 +84,28 @@ void saveFile( const QString& filename, GeoDataDocument* document )
int main(int argc, char** argv)
{
- if (argc != 3) {
- cout << "Usage: " << argv[0] << " input.kml output.cache" << endl;
- return 0;
- }
-
- QFile file(argv[1]);
- file.open(QIODevice::ReadOnly);
- GeoDataParser parser(GeoData_KML);
- if ( !parser.read( &file ) ) {
- cerr << "Error parsing '" << file.fileName().toStdString();
- cerr << "': '" << parser.errorString().toStdString() << "'" << endl;
- return 1;
- }
-
- GeoDataDocument* document = dynamic_cast<GeoDataDocument*>( parser.releaseDocument() );
- if (!document) {
- cerr << "Could not parse kml file. No error message available unfortunately" << endl;
- return 2;
- }
-
- saveFile( argv[2], document );
+ QApplication app(argc,argv);
+
+ QString inputFilename;
+ int inputIndex = app.arguments().indexOf( "-i" );
+ if ( inputIndex > 0 && inputIndex + 1 < argc ) {
+ inputFilename = app.arguments().at( inputIndex + 1 );
+ } else {
+ qDebug( " Syntax: kml2cache -i sourcefile [-o cache-targetfile]" );
+ return 1;
+ }
+
+ QString outputFilename = "output.cache";
+ int outputIndex = app.arguments().indexOf("-o");
+ if ( outputIndex > 0 && outputIndex + 1 < argc )
+ outputFilename = app.arguments().at( outputIndex + 1 );
+
+ ParsingRunnerManager* manager = new ParsingRunnerManager( new PluginManager );
+ GeoDataDocument* document = manager->openFile( inputFilename );
+ if (!document) {
+ qDebug() << "Could not parse input file. No error message available unfortunately";
+ return 2;
+ }
+
+ saveFile( outputFilename, document );
}
diff --git a/tools/kml2kml/kml2kml.cpp b/tools/kml2kml/kml2kml.cpp
index af3672a..4a63ed9 100644
--- a/tools/kml2kml/kml2kml.cpp
+++ b/tools/kml2kml/kml2kml.cpp
@@ -12,42 +12,48 @@
// Mainly useful to test the successful reading and writing of KML data
#include <MarbleWidget.h>
-#include <GeoDataParser.h>
+#include <ParsingRunnerManager.h>
+#include <PluginManager.h>
#include <GeoWriter.h>
+#include <QApplication>
#include <QFile>
-#include <iostream>
+#include <QDebug>
using namespace std;
using namespace Marble;
int main(int argc, char** argv)
{
- if (argc != 3) {
- cout << "Usage: " << argv[0] << " input.kml output.kml" << endl;
- return 0;
- }
-
- QFile file(argv[1]);
- file.open(QIODevice::ReadOnly);
- GeoDataParser parser(GeoData_KML);
- if ( !parser.read( &file ) ) {
- cerr << "Error parsing '" << file.fileName().toStdString();
- cerr << "': '" << parser.errorString().toStdString() << "'" << endl;
- return 1;
- }
-
- GeoDocument* document = parser.releaseDocument();
- if (!document) {
- cerr << "Could not parse kml file. No error message available unfortunately" << endl;
- return 2;
- }
-
- QFile output(argv[2]);
- if (!output.open(QIODevice::WriteOnly)) {
- cerr << "Unable to write to " << output.fileName().toStdString() << endl;
- return 3;
- }
-
- GeoWriter().write(&output, dynamic_cast<GeoDataFeature*>(document));
+ QApplication app(argc,argv);
+
+ QString inputFilename;
+ int inputIndex = app.arguments().indexOf( "-i" );
+ if ( inputIndex > 0 && inputIndex + 1 < argc ) {
+ inputFilename = app.arguments().at( inputIndex + 1 );
+ } else {
+ qDebug( " Syntax: kml2kml -i sourcefile [-o kml-targetfile]" );
+ return 1;
+ }
+
+ QString outputFilename = "output.kml";
+ int outputIndex = app.arguments().indexOf("-o");
+ if ( outputIndex > 0 && outputIndex + 1 < argc )
+ outputFilename = app.arguments().at( outputIndex + 1 );
+
+ ParsingRunnerManager* manager = new ParsingRunnerManager( new PluginManager );
+ GeoDataDocument* document = manager->openFile( inputFilename );
+ if (!document) {
+ qDebug() << "Could not parse input file. No error message available unfortunately";
+ return 2;
+ }
+
+
+ QFile output(outputFilename);
+ if (!output.open(QIODevice::WriteOnly)) {
+ qDebug() << "Unable to write to " << output.fileName();
+ return 3;
+ }
+
+ GeoWriter().write(&output, dynamic_cast<GeoDataFeature*>(document));
}
diff --git a/tools/poly2kml/main.cpp b/tools/poly2kml/main.cpp
index 0bdc5a3..356f58c 100644
--- a/tools/poly2kml/main.cpp
+++ b/tools/poly2kml/main.cpp
@@ -15,7 +15,6 @@
#include <QTime>
#include <QDebug>
-#include "geodata/parser/GeoDataParser.h"
#include "geodata/data/GeoDataLineString.h"
#include "geodata/data/GeoDataDocument.h"
#include "geodata/data/GeoDataFolder.h"
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic