dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
kmlexportplugin.cpp
Go to the documentation of this file.
1 
10 /*
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  * for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, see <http://www.gnu.org/licenses/>
23  */
24 
25 #include "kmlexportplugin.h"
26 #include <QDebug>
27 #include <QtPlugin>
28 #include <QStringList>
29 #include <QDir>
30 #include <QFileDialog>
31 #include <QList>
32 #include <QMessageBox>
33 #include <QWriteLocker>
34 
36 #include <QKeySequence>
38 
39 #include "kmlexport.h"
40 
41 KmlExportPlugin::KmlExportPlugin() {}
42 
46 bool KmlExportPlugin::initialize(const QStringList &args, QString *errMsg)
47 {
48  Q_UNUSED(args);
49  Q_UNUSED(errMsg);
50 
51  // Add Menu entry
54 
55  // Command to convert log file to KML
56  exportToKmlCmd = am->registerAction(new QAction(this), "KmlExport.ExportToKML",
58  exportToKmlCmd->action()->setText("Export logfile to KML");
59 
60  ac->menu()->addSeparator();
61  ac->appendGroup("KML Export");
62  ac->addAction(exportToKmlCmd, "KML Export");
63 
64  connect(exportToKmlCmd->action(), SIGNAL(triggered(bool)), this, SLOT(exportToKML()));
65 
66  return true;
67 }
68 
73 void KmlExportPlugin::exportToKML()
74 {
75  // Get input file
76  //
77  QString inputFileName = QFileDialog::getOpenFileName(
78  static_cast<QWidget *>(Core::ICore::instance)()->mainWindow(), tr("Open file"), QString(""),
79  tr("dRonin Log Files (*.drlog *.tll)"));
80 
81  if (inputFileName.isEmpty())
82  return;
83 
84  // Set up input filter.
85  QString filters = tr("Keyhole Markup Language (compressed) (*.kmz);; Keyhole Markup Language "
86  "(uncompressed) (*.kml)");
87  bool proceed_flag = false;
88  QString outputFileName;
89  QString localizedOutputFileName;
90 
91  // Get output file. Suggest to user that output have same base name and location as input file.
92  while (proceed_flag == false) {
93  outputFileName = QFileDialog::getSaveFileName(
94  static_cast<QWidget *>(Core::ICore::instance)()->mainWindow(), tr("Export log"),
95  inputFileName.split(".", QString::SkipEmptyParts).at(0), filters);
96 
97  if (outputFileName.isEmpty()) {
98  qDebug() << "No KML file name given.";
99  return;
100  } else if (QFileInfo(outputFileName).suffix() == NULL) {
101  qDebug() << "No KML file extension: " << outputFileName;
102  QMessageBox::critical(new QWidget(), "No file extension",
103  "Filename must have .kml or .kmz extension.");
104  } else if (QFileInfo(outputFileName).suffix().toLower() != "kml"
105  && QFileInfo(outputFileName).suffix().toLower() != "kmz") {
106  qDebug() << "Incorrect KML file extension: " << QFileInfo(outputFileName).suffix();
107  QMessageBox::critical(new QWidget(), "Incorrect file extension",
108  "Filename must have .kml or .kmz extension.");
109  } else if (outputFileName.toLocal8Bit() == (QByteArray)NULL) {
110  qDebug() << "Unsupported characters in path: " << outputFileName;
111  QMessageBox::critical(new QWidget(), "Unsupported characters",
112  "Not all uni-code characters are supported. Please choose a path "
113  "and file name that uses only the standard latin alphabet.");
114  } else {
115  proceed_flag = true;
116 
117  // Due to limitations in the KML library, we must convert the output file name into
118  // local 8-bit characters.
119  localizedOutputFileName = outputFileName.toLocal8Bit();
120  }
121  }
122 
123  // Create kmlExport instance, and trigger export
124  KmlExport kmlExport(inputFileName, localizedOutputFileName);
125  kmlExport.exportToKML();
126 }
127 
129 
130 void KmlExportPlugin::shutdown()
131 {
132  // Do nothing
133 }
134 
virtual void extensionsInitialized()=0
virtual QAction * action() const =0
virtual Command * registerAction(QAction *action, const QString &id, const QList< int > &context)=0
Makes an action known to the system under the specified string id.
const char *const M_TOOLS
Definition: coreconstants.h:83
virtual ActionContainer * actionContainer(const QString &id) const =0
Returns the IActionContainter object that is know to the system under the given string id...
virtual ActionManager * actionManager() const =0
Returns the application's action manager.
virtual QMenu * menu() const =0
const int C_GLOBAL_ID
Definition: coreconstants.h:90
static ICore * instance()
Definition: coreimpl.cpp:46
virtual void appendGroup(const QString &group)=0
virtual void addAction(Core::Command *action, const QString &group=QString())=0
The action manager is responsible for registration of menus and menu items and keyboard shortcuts...
Definition: actionmanager.h:47