• 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
  • kml
KmzHandler.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 2012 Dennis Nienhüser <earthwings@gentoo.org>
9 
10 #include "KmzHandler.h"
11 #include "MarbleDebug.h"
12 
13 #include <QTemporaryFile>
14 #include <QDir>
15 
16 #include <quazip/quazip.h>
17 #include <quazip/quazipfile.h>
18 
19 namespace Marble {
20 
21 bool KmzHandler::open( const QString &kmz )
22 {
23  QuaZip zip( kmz );
24  if ( !zip.open( QuaZip::mdUnzip ) ) {
25  mDebug() << "Failed to extract " << kmz;
26  return false;
27  }
28 
29  QTemporaryFile outputDir ( QDir::tempPath() + "/marble-kmz-XXXXXX" );
30  outputDir.setAutoRemove( false );
31  outputDir.open();
32  if ( !QFile::remove( outputDir.fileName() ) || !QDir("/").mkdir( outputDir.fileName() ) ) {
33  mDebug() << "Failed to create temporary storage for extracting " << kmz;
34  return false;
35  }
36 
37  m_kmzPath = outputDir.fileName();
38  QuaZipFile zipFile( &zip );
39  for ( bool moreFiles=zip.goToFirstFile(); moreFiles; moreFiles=zip.goToNextFile() ) {
40  QFileInfo output = QFileInfo( outputDir.fileName() + '/' + zip.getCurrentFileName() );
41  if ( !output.dir().exists() ) {
42  QDir::root().mkpath( output.dir().absolutePath() );
43  }
44 
45  QFile outputFile( output.absoluteFilePath() );
46  outputFile.open( QIODevice::WriteOnly );
47  zipFile.open( QIODevice::ReadOnly );
48  outputFile.write( zipFile.readAll() );
49  outputFile.close();
50  zipFile.close();
51  m_kmzFiles << output.absoluteFilePath();
52 
53  if ( output.suffix().toLower() == "kml" ) {
54  if ( !m_kmlFile.isEmpty() ) {
55  mDebug() << "File" << kmz << "contains more than one .kml files";
56  }
57  m_kmlFile = output.absoluteFilePath();
58  }
59  }
60  zip.close();
61  return true;
62 }
63 
64 QString KmzHandler::kmlFile() const
65 {
66  return m_kmlFile;
67 }
68 
69 QString KmzHandler::kmzPath() const
70 {
71  return m_kmzPath;
72 }
73 
74 QStringList KmzHandler::kmzFiles() const
75 {
76  return m_kmzFiles;
77 }
78 
79 }
Marble::KmzHandler::kmlFile
QString kmlFile() const
Definition: KmzHandler.cpp:64
QFile::remove
bool remove()
KmzHandler.h
QDir::root
QDir root()
MarbleDebug.h
QFile
QDir::exists
bool exists() const
QDir::tempPath
QString tempPath()
QTemporaryFile::setAutoRemove
void setAutoRemove(bool b)
QFileInfo::absoluteFilePath
QString absoluteFilePath() const
QString::isEmpty
bool isEmpty() const
QFileInfo::dir
QDir dir() const
QString
Marble::KmzHandler::open
bool open(const QString &file)
Definition: KmzHandler.cpp:21
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QStringList
Marble::KmzHandler::kmzPath
QString kmzPath() const
Definition: KmzHandler.cpp:69
Marble::KmzHandler::kmzFiles
QStringList kmzFiles() const
Definition: KmzHandler.cpp:74
QFileInfo
QString::toLower
QString toLower() const
QTemporaryFile::fileName
QString fileName() const
QDir
QFileInfo::suffix
QString suffix() const
QDir::absolutePath
QString absolutePath() const
QDir::mkdir
bool mkdir(const QString &dirName) const
QTemporaryFile
QTemporaryFile::open
bool open()
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
QDir::mkpath
bool mkpath(const QString &dirPath) const
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