~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/plugins/gps_importer/qgsgpsplugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *   (at your option) any later version.                                   *
16
16
 *                                                                         *
17
17
 ***************************************************************************/
18
 
/*  $Id: qgsgpsplugin.cpp 6301 2006-12-22 07:43:47Z g_j_m $ */
 
18
/*  $Id$ */
19
19
 
20
20
// includes
21
21
 
22
 
#include "qgisapp.h"
 
22
#include "qgisinterface.h"
23
23
#include "qgisgui.h"
 
24
#include "qgsapplication.h"
24
25
#include "qgsmaplayerregistry.h"
25
26
#include "qgsmaplayer.h"
26
27
#include "qgsvectorlayer.h"
27
28
#include "qgsdataprovider.h"
28
29
#include "qgsvectordataprovider.h"
29
30
#include "qgsgpsplugin.h"
30
 
 
 
31
#include "qgslogger.h"
31
32
 
32
33
#include <QFileDialog>
33
34
#include <QMessageBox>
34
35
#include <QAction>
35
 
#include <Q3Process>
36
 
#include <Q3ProgressDialog>
 
36
#include <QFile>
 
37
#include <QToolBar>
 
38
#include <QProcess>
 
39
#include <QProgressDialog>
37
40
#include <QSettings>
38
41
#include <QStringList>
39
42
 
40
43
//non qt includes
41
44
#include <cassert>
42
45
#include <fstream>
43
 
#include <iostream>
44
46
 
45
47
//the gui subclass
46
48
#include "qgsgpsplugingui.h"
47
 
 
48
 
// xpm for creating the toolbar icon
49
 
#include "icon.xpm"
50
 
 
51
 
#ifdef WIN32
52
 
#define QGISEXTERN extern "C" __declspec( dllexport )
53
 
#else
54
 
#define QGISEXTERN extern "C"
55
 
#endif
56
 
 
57
 
 
58
 
static const char * const ident_ = 
59
 
  "$Id: qgsgpsplugin.cpp 6301 2006-12-22 07:43:47Z g_j_m $";
60
 
static const QString name_ = QObject::tr("GPS Tools");
61
 
static const QString description_ = 
62
 
  QObject::tr("Tools for loading and importing GPS data");
63
 
static const QString version_ = QObject::tr("Version 0.1");
 
49
#include "qgslogger.h"
 
50
 
 
51
 
 
52
static const char * const ident_ = "$Id$";
 
53
static const QString name_ = QObject::tr( "GPS Tools" );
 
54
static const QString description_ = QObject::tr( "Tools for loading and importing GPS data" );
 
55
static const QString version_ = QObject::tr( "Version 0.1" );
64
56
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
65
57
 
66
58
 
70
62
 * @param qgis Pointer to the QGIS main window
71
63
 * @param _qI Pointer to the QGIS interface object
72
64
 */
73
 
QgsGPSPlugin::QgsGPSPlugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
74
 
  QgisPlugin(name_,description_,version_,type_),
75
 
  mMainWindowPointer(theQGisApp), 
76
 
  mQGisInterface(theQgisInterFace)
 
65
QgsGPSPlugin::QgsGPSPlugin( QgisInterface * theQgisInterFace ):
 
66
    QgisPlugin( name_, description_, version_, type_ ),
 
67
    mQGisInterface( theQgisInterFace )
77
68
{
78
69
  setupBabel();
79
70
}
82
73
{
83
74
  // delete all our babel formats
84
75
  BabelMap::iterator iter;
85
 
  for (iter = mImporters.begin(); iter != mImporters.end(); ++iter)
 
76
  for ( iter = mImporters.begin(); iter != mImporters.end(); ++iter )
86
77
    delete iter->second;
87
78
  std::map<QString, QgsGPSDevice*>::iterator iter2;
88
 
  for (iter2 = mDevices.begin(); iter2 != mDevices.end(); ++iter2)
 
79
  for ( iter2 = mDevices.begin(); iter2 != mDevices.end(); ++iter2 )
89
80
    delete iter2->second;
90
81
}
91
82
 
92
83
 
93
84
/*
94
 
 * Initialize the GUI interface for the plugin 
 
85
 * Initialize the GUI interface for the plugin
95
86
 */
96
87
void QgsGPSPlugin::initGui()
97
88
{
98
89
  // add an action to the toolbar
99
 
  mQActionPointer = new QAction(QIcon(icon), tr("&Gps Tools"), this);
100
 
  mCreateGPXAction = new QAction(QIcon(icon), tr("&Create new GPX layer"), this);
101
 
 
102
 
  mQActionPointer->setWhatsThis(tr("Creates a new GPX layer and displays it on the map canvas"));
103
 
  mCreateGPXAction->setWhatsThis(tr("Creates a new GPX layer and displays it on the map canvas"));
104
 
  connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run()));
105
 
  connect(mCreateGPXAction, SIGNAL(activated()), this, SLOT(createGPX()));
106
 
 
107
 
  mQGisInterface->addToolBarIcon(mQActionPointer);
108
 
  mQGisInterface->addPluginMenu(tr("&Gps"), mQActionPointer);
109
 
  mQGisInterface->addPluginMenu(tr("&Gps"), mCreateGPXAction);
 
90
  mQActionPointer = new QAction( QIcon(), tr( "&Gps Tools" ), this );
 
91
  mCreateGPXAction = new QAction( QIcon(), tr( "&Create new GPX layer" ), this );
 
92
  setCurrentTheme( "" );
 
93
 
 
94
  mQActionPointer->setWhatsThis( tr( "Creates a new GPX layer and displays it on the map canvas" ) );
 
95
  mCreateGPXAction->setWhatsThis( tr( "Creates a new GPX layer and displays it on the map canvas" ) );
 
96
  connect( mQActionPointer, SIGNAL( triggered() ), this, SLOT( run() ) );
 
97
  connect( mCreateGPXAction, SIGNAL( triggered() ), this, SLOT( createGPX() ) );
 
98
 
 
99
  mQGisInterface->layerToolBar()->addAction( mQActionPointer );
 
100
  mQGisInterface->addPluginToMenu( tr( "&Gps" ), mQActionPointer );
 
101
  mQGisInterface->addPluginToMenu( tr( "&Gps" ), mCreateGPXAction );
 
102
 
 
103
  // this is called when the icon theme is changed
 
104
  connect( mQGisInterface, SIGNAL( currentThemeChanged( QString ) ), this, SLOT( setCurrentTheme( QString ) ) );
110
105
}
111
106
 
112
107
//method defined in interface
115
110
  //implement me!
116
111
}
117
112
 
118
 
// Slot called when the buffer menu item is activated
 
113
// Slot called when the menu item is activated
119
114
void QgsGPSPlugin::run()
120
115
{
121
116
  // find all GPX layers
122
117
  std::vector<QgsVectorLayer*> gpxLayers;
123
 
  std::map<QString, QgsMapLayer*>::const_iterator iter;
124
 
  for (iter = mQGisInterface->getLayerRegistry()->mapLayers().begin();
125
 
       iter != mQGisInterface->getLayerRegistry()->mapLayers().end(); ++iter) {
126
 
    if (iter->second->type() == QgsMapLayer::VECTOR) {
127
 
      QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>(iter->second);
128
 
      if (vLayer->providerType() == "gpx")
129
 
        gpxLayers.push_back(vLayer);
 
118
  QMap<QString, QgsMapLayer*>::const_iterator iter;
 
119
  QgsMapLayerRegistry* registry = QgsMapLayerRegistry::instance();
 
120
  for ( iter =  registry->mapLayers().begin();
 
121
        iter != registry->mapLayers().end(); ++iter )
 
122
  {
 
123
    if ( iter.value()->type() == QgsMapLayer::VectorLayer )
 
124
    {
 
125
      QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( iter.value() );
 
126
      if ( vLayer->providerType() == "gpx" )
 
127
        gpxLayers.push_back( vLayer );
130
128
    }
131
129
  }
132
 
  
133
 
  QgsGPSPluginGui *myPluginGui = 
134
 
    new QgsGPSPluginGui(mImporters, mDevices, gpxLayers, mMainWindowPointer, 
135
 
                        QgisGui::ModalDialogFlags);
 
130
 
 
131
  QgsGPSPluginGui *myPluginGui =
 
132
    new QgsGPSPluginGui( mImporters, mDevices, gpxLayers, mQGisInterface->mainWindow(),
 
133
                         QgisGui::ModalDialogFlags );
 
134
  myPluginGui->setAttribute( Qt::WA_DeleteOnClose );
136
135
  //listen for when the layer has been made so we can draw it
137
 
  connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), 
138
 
          this, SLOT(drawVectorLayer(QString,QString,QString)));
139
 
  connect(myPluginGui, SIGNAL(loadGPXFile(QString, bool, bool, bool)), 
140
 
          this, SLOT(loadGPXFile(QString, bool, bool, bool)));
141
 
  connect(myPluginGui, SIGNAL(importGPSFile(QString, QgsBabelFormat*, bool, 
142
 
                                            bool, bool, QString, QString)),
143
 
          this, SLOT(importGPSFile(QString, QgsBabelFormat*, bool, bool, 
144
 
                                   bool, QString, QString)));
145
 
  connect(myPluginGui, SIGNAL(downloadFromGPS(QString, QString, bool, bool,
146
 
                                              bool, QString, QString)),
147
 
          this, SLOT(downloadFromGPS(QString, QString, bool, bool, bool,
148
 
                                     QString, QString)));
149
 
  connect(myPluginGui, SIGNAL(uploadToGPS(QgsVectorLayer*, QString, QString)),
150
 
          this, SLOT(uploadToGPS(QgsVectorLayer*, QString, QString)));
151
 
  connect(this, SIGNAL(closeGui()), myPluginGui, SLOT(close()));
 
136
  connect( myPluginGui, SIGNAL( drawVectorLayer( QString, QString, QString ) ),
 
137
           this, SLOT( drawVectorLayer( QString, QString, QString ) ) );
 
138
  connect( myPluginGui, SIGNAL( loadGPXFile( QString, bool, bool, bool ) ),
 
139
           this, SLOT( loadGPXFile( QString, bool, bool, bool ) ) );
 
140
  connect( myPluginGui, SIGNAL( importGPSFile( QString, QgsBabelFormat*, bool,
 
141
                                bool, bool, QString, QString ) ),
 
142
           this, SLOT( importGPSFile( QString, QgsBabelFormat*, bool, bool,
 
143
                                      bool, QString, QString ) ) );
 
144
  connect( myPluginGui, SIGNAL( convertGPSFile( QString, int,
 
145
                                QString, QString ) ),
 
146
           this, SLOT( convertGPSFile( QString, int,
 
147
                                       QString, QString ) ) );
 
148
  connect( myPluginGui, SIGNAL( downloadFromGPS( QString, QString, bool, bool,
 
149
                                bool, QString, QString ) ),
 
150
           this, SLOT( downloadFromGPS( QString, QString, bool, bool, bool,
 
151
                                        QString, QString ) ) );
 
152
  connect( myPluginGui, SIGNAL( uploadToGPS( QgsVectorLayer*, QString, QString ) ),
 
153
           this, SLOT( uploadToGPS( QgsVectorLayer*, QString, QString ) ) );
 
154
  connect( this, SIGNAL( closeGui() ), myPluginGui, SLOT( close() ) );
152
155
 
153
156
  myPluginGui->show();
154
157
}
155
158
 
156
159
 
157
 
void QgsGPSPlugin::createGPX() {
158
 
  QString fileName = 
159
 
    QFileDialog::getSaveFileName(mMainWindowPointer,
160
 
                 tr("Save new GPX file as..."), "." , tr("GPS eXchange file (*.gpx)"));
161
 
  if (!fileName.isEmpty()) {
162
 
    QFileInfo fileInfo(fileName);
163
 
    std::ofstream ofs((const char*)fileName);
164
 
    if (!ofs) {
165
 
      QMessageBox::warning(NULL, tr("Could not create file"),
166
 
                           tr("Unable to create a GPX file with the given name. ")+
167
 
                           tr("Try again with another name or in another ")+
168
 
                           tr("directory."));
 
160
void QgsGPSPlugin::createGPX()
 
161
{
 
162
  QString fileName =
 
163
    QFileDialog::getSaveFileName( mQGisInterface->mainWindow(),
 
164
                                  tr( "Save new GPX file as..." ),
 
165
                                  ".",
 
166
                                  tr( "GPS eXchange file (*.gpx)" ) );
 
167
  if ( !fileName.isEmpty() )
 
168
  {
 
169
    QFileInfo fileInfo( fileName );
 
170
    std::ofstream ofs( fileName.toUtf8() );
 
171
    if ( !ofs )
 
172
    {
 
173
      QMessageBox::warning( NULL, tr( "Could not create file" ),
 
174
                            tr( "Unable to create a GPX file with the given name. " ) +
 
175
                            tr( "Try again with another name or in another " ) +
 
176
                            tr( "directory." ) );
169
177
      return;
170
178
    }
171
 
    ofs<<"<gpx></gpx>"<<std::endl;
172
 
    
173
 
    emit drawVectorLayer(fileName + "?type=track", 
174
 
                         fileInfo.baseName() + ", tracks", "gpx");
175
 
    emit drawVectorLayer(fileName + "?type=route", 
176
 
                         fileInfo.baseName() + ", routes", "gpx");
177
 
    emit drawVectorLayer(fileName + "?type=waypoint", 
178
 
                         fileInfo.baseName() + ", waypoints", "gpx");
 
179
    ofs << "<gpx></gpx>" << std::endl;
 
180
 
 
181
    emit drawVectorLayer( fileName + "?type=track",
 
182
                          fileInfo.baseName() + ", tracks", "gpx" );
 
183
    emit drawVectorLayer( fileName + "?type=route",
 
184
                          fileInfo.baseName() + ", routes", "gpx" );
 
185
    emit drawVectorLayer( fileName + "?type=waypoint",
 
186
                          fileInfo.baseName() + ", waypoints", "gpx" );
179
187
  }
180
188
}
181
189
 
182
190
 
183
 
void QgsGPSPlugin::drawVectorLayer(QString thePathNameQString, 
184
 
                                   QString theBaseNameQString, 
185
 
                                   QString theProviderQString)
 
191
void QgsGPSPlugin::drawVectorLayer( QString thePathNameQString,
 
192
                                    QString theBaseNameQString,
 
193
                                    QString theProviderQString )
186
194
{
187
 
  mQGisInterface->addVectorLayer(thePathNameQString, theBaseNameQString, 
188
 
                                 theProviderQString);
 
195
  mQGisInterface->addVectorLayer( thePathNameQString, theBaseNameQString,
 
196
                                  theProviderQString );
189
197
}
190
198
 
191
199
// Unload the plugin by cleaning up the GUI
192
200
void QgsGPSPlugin::unload()
193
201
{
194
202
  // remove the GUI
195
 
  mQGisInterface->removePluginMenu(tr("&Gps"),mQActionPointer);
196
 
  mQGisInterface->removePluginMenu(tr("&Gps"),mCreateGPXAction);
197
 
  mQGisInterface->removeToolBarIcon(mQActionPointer);
 
203
  mQGisInterface->removePluginMenu( tr( "&Gps" ), mQActionPointer );
 
204
  mQGisInterface->removePluginMenu( tr( "&Gps" ), mCreateGPXAction );
 
205
  mQGisInterface->removeToolBarIcon( mQActionPointer );
198
206
  delete mQActionPointer;
199
207
}
200
208
 
201
 
void QgsGPSPlugin::loadGPXFile(QString filename, bool loadWaypoints, bool loadRoutes,
202
 
                               bool loadTracks) {
 
209
void QgsGPSPlugin::loadGPXFile( QString fileName, bool loadWaypoints, bool loadRoutes,
 
210
                                bool loadTracks )
 
211
{
203
212
 
204
213
  //check if input file is readable
205
 
  QFileInfo fileInfo(filename);
206
 
  if (!fileInfo.isReadable()) {
207
 
    QMessageBox::warning(NULL, tr("GPX Loader"),
208
 
                         tr("Unable to read the selected file.\n")+
209
 
                         tr("Please reselect a valid file.") );
 
214
  QFileInfo fileInfo( fileName );
 
215
  if ( !fileInfo.isReadable() )
 
216
  {
 
217
    QMessageBox::warning( NULL, tr( "GPX Loader" ),
 
218
                          tr( "Unable to read the selected file.\n"
 
219
                              "Please reselect a valid file." ) );
210
220
    return;
211
221
  }
212
 
  
 
222
 
213
223
  // remember the directory
214
224
  QSettings settings;
215
 
  settings.writeEntry("/Plugin-GPS/gpxdirectory", fileInfo.dirPath());
216
 
  
 
225
  settings.setValue( "/Plugin-GPS/gpxdirectory", fileInfo.path() );
 
226
 
217
227
  // add the requested layers
218
 
  if (loadTracks)
219
 
    emit drawVectorLayer(filename + "?type=track", 
220
 
                         fileInfo.baseName() + ", tracks", "gpx");
221
 
  if (loadRoutes)
222
 
    emit drawVectorLayer(filename + "?type=route", 
223
 
                         fileInfo.baseName() + ", routes", "gpx");
224
 
  if (loadWaypoints)
225
 
    emit drawVectorLayer(filename + "?type=waypoint", 
226
 
                         fileInfo.baseName() + ", waypoints", "gpx");
227
 
  
 
228
  if ( loadTracks )
 
229
    emit drawVectorLayer( fileName + "?type=track",
 
230
                          fileInfo.baseName() + ", tracks", "gpx" );
 
231
  if ( loadRoutes )
 
232
    emit drawVectorLayer( fileName + "?type=route",
 
233
                          fileInfo.baseName() + ", routes", "gpx" );
 
234
  if ( loadWaypoints )
 
235
    emit drawVectorLayer( fileName + "?type=waypoint",
 
236
                          fileInfo.baseName() + ", waypoints", "gpx" );
 
237
 
228
238
  emit closeGui();
229
239
}
230
240
 
231
241
 
232
 
void QgsGPSPlugin::importGPSFile(QString inputFilename, QgsBabelFormat* importer, 
233
 
                                 bool importWaypoints, bool importRoutes, 
234
 
                                 bool importTracks, QString outputFilename, 
235
 
                                 QString layerName) {
 
242
void QgsGPSPlugin::importGPSFile( QString inputFileName, QgsBabelFormat* importer,
 
243
                                  bool importWaypoints, bool importRoutes,
 
244
                                  bool importTracks, QString outputFileName,
 
245
                                  QString layerName )
 
246
{
236
247
 
237
248
  // what features does the user want to import?
238
249
  QString typeArg;
239
 
  if (importWaypoints)
 
250
  if ( importWaypoints )
240
251
    typeArg = "-w";
241
 
  else if (importRoutes)
 
252
  else if ( importRoutes )
242
253
    typeArg = "-r";
243
 
  else if (importTracks)
 
254
  else if ( importTracks )
244
255
    typeArg = "-t";
245
 
  
246
 
  // try to start the gpsbabel process
247
 
  QStringList babelArgs = 
248
 
    importer->importCommand(mBabelPath, typeArg, 
249
 
                               inputFilename, outputFilename);
250
 
  Q3Process babelProcess(babelArgs);
251
 
  if (!babelProcess.start()) {
252
 
    QMessageBox::warning(NULL, tr("Could not start process"),
253
 
                         tr("Could not start GPSBabel!"));
254
 
    return;
255
 
  }
256
 
  
257
 
  // wait for gpsbabel to finish (or the user to cancel)
258
 
  Q3ProgressDialog progressDialog(tr("Importing data..."), tr("Cancel"), 0,
259
 
                                 NULL, 0, true);
260
 
  progressDialog.show();
261
 
  for (int i = 0; babelProcess.isRunning(); ++i) {
262
 
    QCoreApplication::processEvents();
263
 
 
264
 
    progressDialog.setProgress(i/64);
265
 
    if (progressDialog.wasCanceled())
266
 
      return;
267
 
  }
268
 
  
269
 
  // did we get any data?
270
 
  if (babelProcess.exitStatus() != 0) {
271
 
    QString babelError(babelProcess.readStderr());
272
 
    QString errorMsg(tr("Could not import data from %1!\n\n")
273
 
                     .arg(inputFilename));
274
 
    errorMsg += babelError;
275
 
    QMessageBox::warning(NULL, tr("Error importing data"), errorMsg);
276
 
    return;
277
 
  }
278
 
  
279
 
  // add the layer
280
 
  if (importTracks)
281
 
    emit drawVectorLayer(outputFilename + "?type=track", 
282
 
                         layerName, "gpx");
283
 
  if (importRoutes)
284
 
    emit drawVectorLayer(outputFilename + "?type=route", 
285
 
                         layerName, "gpx");
286
 
  if (importWaypoints)
287
 
    emit drawVectorLayer(outputFilename + "?type=waypoint", 
288
 
                         layerName, "gpx");
289
 
  
290
 
  emit closeGui();
291
 
}
292
 
 
293
 
 
294
 
void QgsGPSPlugin::downloadFromGPS(QString device, QString port,
295
 
                                   bool downloadWaypoints, bool downloadRoutes,
296
 
                                   bool downloadTracks, QString outputFilename,
297
 
                                   QString layerName) {
298
 
  
 
256
 
 
257
  // try to start the gpsbabel process
 
258
  QStringList babelArgs =
 
259
    importer->importCommand( mBabelPath, typeArg,
 
260
                             inputFileName, outputFileName );
 
261
 
 
262
  QgsDebugMsg( QString( "Import command: " ) + babelArgs.join( "|" ) );
 
263
 
 
264
  QProcess babelProcess;
 
265
  babelProcess.start( babelArgs.join( " " ) );
 
266
  if ( !babelProcess.waitForStarted() )
 
267
  {
 
268
    QMessageBox::warning( NULL, tr( "Could not start process" ),
 
269
                          tr( "Could not start GPSBabel!" ) );
 
270
    return;
 
271
  }
 
272
 
 
273
  // wait for gpsbabel to finish (or the user to cancel)
 
274
  QProgressDialog progressDialog( tr( "Importing data..." ), tr( "Cancel" ), 0, 0 );
 
275
  progressDialog.setWindowModality( Qt::WindowModal );
 
276
  for ( int i = 0; babelProcess.state() == QProcess::Running; ++i )
 
277
  {
 
278
    progressDialog.setValue( i / 64 );
 
279
    if ( progressDialog.wasCanceled() )
 
280
      return;
 
281
  }
 
282
 
 
283
  // did we get any data?
 
284
  if ( babelProcess.exitStatus() != 0 )
 
285
  {
 
286
    QString babelError( babelProcess.readAllStandardError() );
 
287
    QString errorMsg( tr( "Could not import data from %1!\n\n" )
 
288
                      .arg( inputFileName ) );
 
289
    errorMsg += babelError;
 
290
    QMessageBox::warning( NULL, tr( "Error importing data" ), errorMsg );
 
291
    return;
 
292
  }
 
293
 
 
294
  // add the layer
 
295
  if ( importTracks )
 
296
    emit drawVectorLayer( outputFileName + "?type=track",
 
297
                          layerName, "gpx" );
 
298
  if ( importRoutes )
 
299
    emit drawVectorLayer( outputFileName + "?type=route",
 
300
                          layerName, "gpx" );
 
301
  if ( importWaypoints )
 
302
    emit drawVectorLayer( outputFileName + "?type=waypoint",
 
303
                          layerName, "gpx" );
 
304
 
 
305
  emit closeGui();
 
306
}
 
307
 
 
308
 
 
309
void QgsGPSPlugin::convertGPSFile( QString inputFileName,
 
310
                                   int convertType,
 
311
                                   QString outputFileName,
 
312
                                   QString layerName )
 
313
{
 
314
 
 
315
  // what features does the user want to import?
 
316
 
 
317
  QStringList convertStrings;
 
318
 
 
319
  switch ( convertType )
 
320
  {
 
321
    case 0:
 
322
      convertStrings << "-x" << "transform,wpt=rte,del"; break;
 
323
    case 1:
 
324
      convertStrings << "-x" << "transform,rte=wpt,del"; break;
 
325
    default:
 
326
      QgsDebugMsg( "Illegal conversion index!" );
 
327
      return;
 
328
  }
 
329
 
 
330
  // try to start the gpsbabel process
 
331
  QStringList babelArgs;
 
332
  babelArgs << mBabelPath << "-i" << "gpx" << "-f" << QString( "\"%1\"" ).arg( inputFileName )
 
333
  << convertStrings << "-o" << "gpx" << "-F" << QString( "\"%1\"" ).arg( outputFileName );
 
334
  QgsDebugMsg( QString( "Conversion command: " ) + babelArgs.join( "|" ) );
 
335
 
 
336
  QProcess babelProcess;
 
337
  babelProcess.start( babelArgs.join( " " ) );
 
338
  if ( !babelProcess.waitForStarted() )
 
339
  {
 
340
    QMessageBox::warning( NULL, tr( "Could not start process" ),
 
341
                          tr( "Could not start GPSBabel!" ) );
 
342
    return;
 
343
  }
 
344
 
 
345
  // wait for gpsbabel to finish (or the user to cancel)
 
346
  QProgressDialog progressDialog( tr( "Importing data..." ), tr( "Cancel" ), 0, 0 );
 
347
  progressDialog.setWindowModality( Qt::WindowModal );
 
348
  for ( int i = 0; babelProcess.state() == QProcess::Running; ++i )
 
349
  {
 
350
    progressDialog.setValue( i / 64 );
 
351
    if ( progressDialog.wasCanceled() )
 
352
      return;
 
353
  }
 
354
 
 
355
  // did we get any data?
 
356
  if ( babelProcess.exitStatus() != 0 )
 
357
  {
 
358
    QString babelError( babelProcess.readAllStandardError() );
 
359
    QString errorMsg( tr( "Could not convert data from %1!\n\n" )
 
360
                      .arg( inputFileName ) );
 
361
    errorMsg += babelError;
 
362
    QMessageBox::warning( NULL, tr( "Error converting data" ), errorMsg );
 
363
    return;
 
364
  }
 
365
 
 
366
  // add the layer
 
367
  switch ( convertType )
 
368
  {
 
369
    case 0:
 
370
      emit drawVectorLayer( outputFileName + "?type=waypoint",
 
371
                            layerName, "gpx" );
 
372
      break;
 
373
    case 1:
 
374
      emit drawVectorLayer( outputFileName + "?type=route",
 
375
                            layerName, "gpx" );
 
376
      break;
 
377
    default:
 
378
      QgsDebugMsg( "Illegal conversion index!" );
 
379
      return;
 
380
  }
 
381
 
 
382
  emit closeGui();
 
383
}
 
384
 
 
385
void QgsGPSPlugin::downloadFromGPS( QString device, QString port,
 
386
                                    bool downloadWaypoints, bool downloadRoutes,
 
387
                                    bool downloadTracks, QString outputFileName,
 
388
                                    QString layerName )
 
389
{
 
390
 
299
391
  // what does the user want to download?
300
392
  QString typeArg, features;
301
 
  if (downloadWaypoints) {
 
393
  if ( downloadWaypoints )
 
394
  {
302
395
    typeArg = "-w";
303
396
    features = "waypoints";
304
397
  }
305
 
  else if (downloadRoutes) {
 
398
  else if ( downloadRoutes )
 
399
  {
306
400
    typeArg = "-r";
307
401
    features = "routes";
308
402
  }
309
 
  else if (downloadTracks) {
 
403
  else if ( downloadTracks )
 
404
  {
310
405
    typeArg = "-t";
311
406
    features = "tracks";
312
407
  }
313
 
  
 
408
 
314
409
  // try to start the gpsbabel process
315
 
  QStringList babelArgs = 
316
 
    mDevices[device]->importCommand(mBabelPath, typeArg, 
317
 
                                    port, outputFilename);
318
 
  if (babelArgs.isEmpty()) {
319
 
    QMessageBox::warning(NULL, tr("Not supported"),
320
 
                         QString(tr("This device does not support downloading ") +
321
 
                                 tr("of ")) + features + ".");
322
 
    return;
323
 
  }
324
 
  Q3Process babelProcess(babelArgs);
325
 
  if (!babelProcess.start()) {
326
 
    QMessageBox::warning(NULL, tr("Could not start process"),
327
 
                         tr("Could not start GPSBabel!"));
328
 
    return;
329
 
  }
330
 
  
 
410
  QStringList babelArgs =
 
411
    mDevices[device]->importCommand( mBabelPath, typeArg,
 
412
                                     port, outputFileName );
 
413
  if ( babelArgs.isEmpty() )
 
414
  {
 
415
    QMessageBox::warning( NULL, tr( "Not supported" ),
 
416
                          tr( "This device does not support downloading of %1." )
 
417
                          .arg( features ) );
 
418
    return;
 
419
  }
 
420
 
 
421
 
 
422
  QgsDebugMsg( QString( "Download command: " ) + babelArgs.join( "|" ) );
 
423
 
 
424
  QProcess babelProcess;
 
425
  babelProcess.start( babelArgs.join( " " ) );
 
426
  if ( !babelProcess.waitForStarted() )
 
427
  {
 
428
    QMessageBox::warning( NULL, tr( "Could not start process" ),
 
429
                          tr( "Could not start GPSBabel!" ) );
 
430
    return;
 
431
  }
 
432
 
331
433
  // wait for gpsbabel to finish (or the user to cancel)
332
 
  Q3ProgressDialog progressDialog(tr("Downloading data..."), tr("Cancel"), 0,
333
 
                                 NULL, 0, true);
334
 
  progressDialog.show();
335
 
  for (int i = 0; babelProcess.isRunning(); ++i) {
336
 
    QCoreApplication::processEvents();
337
 
 
338
 
    progressDialog.setProgress(i/64);
339
 
    if (progressDialog.wasCanceled())
 
434
  QProgressDialog progressDialog( tr( "Downloading data..." ), tr( "Cancel" ), 0, 0 );
 
435
  progressDialog.setWindowModality( Qt::WindowModal );
 
436
  for ( int i = 0; babelProcess.state() == QProcess::Running; ++i )
 
437
  {
 
438
    progressDialog.setValue( i / 64 );
 
439
    if ( progressDialog.wasCanceled() )
340
440
      return;
341
441
  }
342
 
  
 
442
 
343
443
  // did we get any data?
344
 
  if (babelProcess.exitStatus() != 0) {
345
 
    QString babelError(babelProcess.readStderr());
346
 
    QString errorMsg(tr("Could not download data from GPS!\n\n"));
 
444
  if ( babelProcess.exitStatus() != 0 )
 
445
  {
 
446
    QString babelError( babelProcess.readAllStandardError() );
 
447
    QString errorMsg( tr( "Could not download data from GPS!\n\n" ) );
347
448
    errorMsg += babelError;
348
 
    QMessageBox::warning(NULL, tr("Error downloading data"), errorMsg);
 
449
    QMessageBox::warning( NULL, tr( "Error downloading data" ), errorMsg );
349
450
    return;
350
451
  }
351
 
  
 
452
 
352
453
  // add the layer
353
 
  if (downloadWaypoints)
354
 
    emit drawVectorLayer(outputFilename + "?type=waypoint", 
355
 
                         layerName, "gpx");
356
 
  if (downloadRoutes)
357
 
    emit drawVectorLayer(outputFilename + "?type=route", 
358
 
                         layerName, "gpx");
359
 
  if (downloadTracks)
360
 
    emit drawVectorLayer(outputFilename + "?type=track", 
361
 
                         layerName, "gpx");
362
 
  
 
454
  if ( downloadWaypoints )
 
455
    emit drawVectorLayer( outputFileName + "?type=waypoint",
 
456
                          layerName, "gpx" );
 
457
  if ( downloadRoutes )
 
458
    emit drawVectorLayer( outputFileName + "?type=route",
 
459
                          layerName, "gpx" );
 
460
  if ( downloadTracks )
 
461
    emit drawVectorLayer( outputFileName + "?type=track",
 
462
                          layerName, "gpx" );
 
463
 
363
464
  // everything was OK, remember the device and port for next time
364
465
  QSettings settings;
365
 
  settings.writeEntry("/Plugin-GPS/lastdldevice", device);
366
 
  settings.writeEntry("/Plugin-GPS/lastdlport", port);
367
 
  
 
466
  settings.setValue( "/Plugin-GPS/lastdldevice", device );
 
467
  settings.setValue( "/Plugin-GPS/lastdlport", port );
 
468
 
368
469
  emit closeGui();
369
470
}
370
471
 
371
472
 
372
 
void QgsGPSPlugin::uploadToGPS(QgsVectorLayer* gpxLayer, QString device,
373
 
                               QString port) {
374
 
  
375
 
  const QString& source(gpxLayer->getDataProvider()->getDataSourceUri());
376
 
  
 
473
void QgsGPSPlugin::uploadToGPS( QgsVectorLayer* gpxLayer, QString device,
 
474
                                QString port )
 
475
{
 
476
 
 
477
  const QString& source( gpxLayer->dataProvider()->dataSourceUri() );
 
478
 
377
479
  // what kind of data does the user want to upload?
378
480
  QString typeArg, features;
379
 
  if (source.right(8) == "waypoint") {
 
481
  if ( source.right( 8 ) == "waypoint" )
 
482
  {
380
483
    typeArg = "-w";
381
484
    features = "waypoints";
382
485
  }
383
 
  else if (source.right(5) == "route") {
 
486
  else if ( source.right( 5 ) == "route" )
 
487
  {
384
488
    typeArg = "-r";
385
489
    features = "routes";
386
490
  }
387
 
  else if (source.right(5) == "track") {
 
491
  else if ( source.right( 5 ) == "track" )
 
492
  {
388
493
    typeArg = "-t";
389
494
    features = "tracks";
390
495
  }
391
 
  else {
392
 
    std::cerr << source.right(8).toLocal8Bit().data() << std::endl;
393
 
    assert(false);
 
496
  else
 
497
  {
 
498
    QgsDebugMsg( source.right( 8 ) );
 
499
    assert( false );
394
500
  }
395
 
  
 
501
 
396
502
  // try to start the gpsbabel process
397
 
  QStringList babelArgs = 
398
 
    mDevices[device]->exportCommand(mBabelPath, typeArg, 
399
 
                                       source.left(source.findRev('?')), port);
400
 
  if (babelArgs.isEmpty()) {
401
 
    QMessageBox::warning(NULL, tr("Not supported"),
402
 
                         QString(tr("This device does not support uploading of "))+
403
 
                         features + ".");
404
 
    return;
405
 
  }
406
 
  Q3Process babelProcess(babelArgs);
407
 
  if (!babelProcess.start()) {
408
 
    QMessageBox::warning(NULL, tr("Could not start process"),
409
 
                         tr("Could not start GPSBabel!"));
410
 
    return;
411
 
  }
412
 
  
 
503
  QStringList babelArgs =
 
504
    mDevices[device]->exportCommand( mBabelPath, typeArg,
 
505
                                     source.left( source.lastIndexOf( '?' ) ), port );
 
506
  if ( babelArgs.isEmpty() )
 
507
  {
 
508
    QMessageBox::warning( NULL, tr( "Not supported" ),
 
509
                          tr( "This device does not support uploading of %1." )
 
510
                          .arg( features ) );
 
511
    return;
 
512
  }
 
513
 
 
514
  QgsDebugMsg( QString( "Upload command: " ) + babelArgs.join( "|" ) );
 
515
 
 
516
  QProcess babelProcess;
 
517
  babelProcess.start( babelArgs.join( " " ) );
 
518
  if ( !babelProcess.waitForStarted() )
 
519
  {
 
520
    QMessageBox::warning( NULL, tr( "Could not start process" ),
 
521
                          tr( "Could not start GPSBabel!" ) );
 
522
    return;
 
523
  }
 
524
 
413
525
  // wait for gpsbabel to finish (or the user to cancel)
414
 
  Q3ProgressDialog progressDialog(tr("Uploading data..."), tr("Cancel"), 0,
415
 
                                 NULL, 0, true);
416
 
  progressDialog.show();
417
 
  for (int i = 0; babelProcess.isRunning(); ++i) {
418
 
    QCoreApplication::processEvents();
419
 
 
420
 
    progressDialog.setProgress(i/64);
421
 
    if (progressDialog.wasCanceled())
 
526
  QProgressDialog progressDialog( tr( "Uploading data..." ), tr( "Cancel" ), 0, 0 );
 
527
  progressDialog.setWindowModality( Qt::WindowModal );
 
528
  for ( int i = 0; babelProcess.state() == QProcess::Running; ++i )
 
529
  {
 
530
    progressDialog.setValue( i / 64 );
 
531
    if ( progressDialog.wasCanceled() )
422
532
      return;
423
533
  }
424
 
  
 
534
 
425
535
  // did we get an error?
426
 
  if (babelProcess.exitStatus() != 0) {
427
 
    QString babelError(babelProcess.readStderr());
428
 
    QString errorMsg(tr("Error while uploading data to GPS!\n\n"));
 
536
  if ( babelProcess.exitStatus() != 0 )
 
537
  {
 
538
    QString babelError( babelProcess.readAllStandardError() );
 
539
    QString errorMsg( tr( "Error while uploading data to GPS!\n\n" ) );
429
540
    errorMsg += babelError;
430
 
    QMessageBox::warning(NULL, tr("Error uploading data"), errorMsg);
 
541
    QMessageBox::warning( NULL, tr( "Error uploading data" ), errorMsg );
431
542
    return;
432
543
  }
433
 
  
 
544
 
434
545
  // everything was OK, remember this device for next time
435
546
  QSettings settings;
436
 
  settings.writeEntry("/Plugin-GPS/lastuldevice", device);
437
 
  settings.writeEntry("/Plugin-GPS/lastulport", port);
438
 
  
 
547
  settings.setValue( "/Plugin-GPS/lastuldevice", device );
 
548
  settings.setValue( "/Plugin-GPS/lastulport", port );
 
549
 
439
550
  emit closeGui();
440
551
}
441
552
 
442
553
 
443
 
void QgsGPSPlugin::setupBabel() {
444
 
  
 
554
void QgsGPSPlugin::setupBabel()
 
555
{
 
556
 
445
557
  // where is gpsbabel?
446
558
  QSettings settings;
447
 
  mBabelPath = settings.value("/Plugin-GPS/gpsbabelpath", "").toString();
448
 
  if (mBabelPath.isEmpty())
 
559
  mBabelPath = settings.value( "/Plugin-GPS/gpsbabelpath", "" ).toString();
 
560
  if ( mBabelPath.isEmpty() )
449
561
    mBabelPath = "gpsbabel";
450
562
  // the importable formats
 
563
  mImporters["Shapefile"] =
 
564
    new QgsSimpleBabelFormat( "shape", true, true, true );
451
565
  mImporters["Geocaching.com .loc"] =
452
 
    new QgsSimpleBabelFormat("geo", true, false, false);
453
 
  mImporters["Magellan Mapsend"] = 
454
 
    new QgsSimpleBabelFormat("mapsend", true, true, true);
455
 
  mImporters["Garmin PCX5"] = 
456
 
    new QgsSimpleBabelFormat("pcx", true, false, true);
457
 
  mImporters["Garmin Mapsource"] = 
458
 
    new QgsSimpleBabelFormat("mapsource", true, true, true);
459
 
  mImporters["GPSUtil"] = 
460
 
    new QgsSimpleBabelFormat("gpsutil", true, false, false);
461
 
  mImporters["PocketStreets 2002/2003 Pushpin"] = 
462
 
    new QgsSimpleBabelFormat("psp", true, false, false);
463
 
  mImporters["CoPilot Flight Planner"] = 
464
 
    new QgsSimpleBabelFormat("copilot", true, false, false);
465
 
  mImporters["Magellan Navigator Companion"] = 
466
 
    new QgsSimpleBabelFormat("magnav", true, false, false);
467
 
  mImporters["Holux"] = 
468
 
    new QgsSimpleBabelFormat("holux", true, false, false);
469
 
  mImporters["Topo by National Geographic"] = 
470
 
    new QgsSimpleBabelFormat("tpg", true, false, false);
471
 
  mImporters["TopoMapPro"] = 
472
 
    new QgsSimpleBabelFormat("tmpro", true, false, false);
473
 
  mImporters["GeocachingDB"] = 
474
 
    new QgsSimpleBabelFormat("gcdb", true, false, false);
475
 
  mImporters["Tiger"] = 
476
 
    new QgsSimpleBabelFormat("tiger", true, false, false);
477
 
  mImporters["EasyGPS Binary Format"] = 
478
 
    new QgsSimpleBabelFormat("easygps", true, false, false);
479
 
  mImporters["Delorme Routes"] = 
480
 
    new QgsSimpleBabelFormat("saroute", false, false, true);
481
 
  mImporters["Navicache"] = 
482
 
    new QgsSimpleBabelFormat("navicache", true, false, false);
483
 
  mImporters["PSITrex"] = 
484
 
    new QgsSimpleBabelFormat("psitrex", true, true, true);
485
 
  mImporters["Delorme GPS Log"] = 
486
 
    new QgsSimpleBabelFormat("gpl", false, false, true);
487
 
  mImporters["OziExplorer"] = 
488
 
    new QgsSimpleBabelFormat("ozi", true, false, false);
489
 
  mImporters["NMEA Sentences"] = 
490
 
    new QgsSimpleBabelFormat("nmea", true, false, true);
491
 
  mImporters["Delorme Street Atlas 2004 Plus"] = 
492
 
    new QgsSimpleBabelFormat("saplus", true, false, false);
493
 
  mImporters["Microsoft Streets and Trips"] = 
494
 
    new QgsSimpleBabelFormat("s_and_t", true, false, false);
495
 
  mImporters["NIMA/GNIS Geographic Names"] = 
496
 
    new QgsSimpleBabelFormat("nima", true, false, false);
497
 
  mImporters["Maptech"] = 
498
 
    new QgsSimpleBabelFormat("mxf", true, false, false);
499
 
  mImporters["Mapopolis.com Mapconverter Application"] = 
500
 
    new QgsSimpleBabelFormat("mapconverter", true, false, false);
501
 
  mImporters["GPSman"] = 
502
 
    new QgsSimpleBabelFormat("gpsman", true, false, false);
503
 
  mImporters["GPSDrive"] = 
504
 
    new QgsSimpleBabelFormat("gpsdrive", true, false, false);
505
 
  mImporters["Fugawi"] = 
506
 
    new QgsSimpleBabelFormat("fugawi", true, false, false);
507
 
  mImporters["DNA"] = 
508
 
    new QgsSimpleBabelFormat("dna", true, false, false);
 
566
    new QgsSimpleBabelFormat( "geo", true, false, false );
 
567
  mImporters["Magellan Mapsend"] =
 
568
    new QgsSimpleBabelFormat( "mapsend", true, true, true );
 
569
  mImporters["Garmin PCX5"] =
 
570
    new QgsSimpleBabelFormat( "pcx", true, false, true );
 
571
  mImporters["Garmin Mapsource"] =
 
572
    new QgsSimpleBabelFormat( "mapsource", true, true, true );
 
573
  mImporters["GPSUtil"] =
 
574
    new QgsSimpleBabelFormat( "gpsutil", true, false, false );
 
575
  mImporters["PocketStreets 2002/2003 Pushpin"] =
 
576
    new QgsSimpleBabelFormat( "psp", true, false, false );
 
577
  mImporters["CoPilot Flight Planner"] =
 
578
    new QgsSimpleBabelFormat( "copilot", true, false, false );
 
579
  mImporters["Magellan Navigator Companion"] =
 
580
    new QgsSimpleBabelFormat( "magnav", true, false, false );
 
581
  mImporters["Holux"] =
 
582
    new QgsSimpleBabelFormat( "holux", true, false, false );
 
583
  mImporters["Topo by National Geographic"] =
 
584
    new QgsSimpleBabelFormat( "tpg", true, false, false );
 
585
  mImporters["TopoMapPro"] =
 
586
    new QgsSimpleBabelFormat( "tmpro", true, false, false );
 
587
  mImporters["GeocachingDB"] =
 
588
    new QgsSimpleBabelFormat( "gcdb", true, false, false );
 
589
  mImporters["Tiger"] =
 
590
    new QgsSimpleBabelFormat( "tiger", true, false, false );
 
591
  mImporters["EasyGPS Binary Format"] =
 
592
    new QgsSimpleBabelFormat( "easygps", true, false, false );
 
593
  mImporters["Delorme Routes"] =
 
594
    new QgsSimpleBabelFormat( "saroute", false, false, true );
 
595
  mImporters["Navicache"] =
 
596
    new QgsSimpleBabelFormat( "navicache", true, false, false );
 
597
  mImporters["PSITrex"] =
 
598
    new QgsSimpleBabelFormat( "psitrex", true, true, true );
 
599
  mImporters["Delorme GPS Log"] =
 
600
    new QgsSimpleBabelFormat( "gpl", false, false, true );
 
601
  mImporters["OziExplorer"] =
 
602
    new QgsSimpleBabelFormat( "ozi", true, false, false );
 
603
  mImporters["NMEA Sentences"] =
 
604
    new QgsSimpleBabelFormat( "nmea", true, false, true );
 
605
  mImporters["Delorme Street Atlas 2004 Plus"] =
 
606
    new QgsSimpleBabelFormat( "saplus", true, false, false );
 
607
  mImporters["Microsoft Streets and Trips"] =
 
608
    new QgsSimpleBabelFormat( "s_and_t", true, false, false );
 
609
  mImporters["NIMA/GNIS Geographic Names"] =
 
610
    new QgsSimpleBabelFormat( "nima", true, false, false );
 
611
  mImporters["Maptech"] =
 
612
    new QgsSimpleBabelFormat( "mxf", true, false, false );
 
613
  mImporters["Mapopolis.com Mapconverter Application"] =
 
614
    new QgsSimpleBabelFormat( "mapconverter", true, false, false );
 
615
  mImporters["GPSman"] =
 
616
    new QgsSimpleBabelFormat( "gpsman", true, false, false );
 
617
  mImporters["GPSDrive"] =
 
618
    new QgsSimpleBabelFormat( "gpsdrive", true, false, false );
 
619
  mImporters["Fugawi"] =
 
620
    new QgsSimpleBabelFormat( "fugawi", true, false, false );
 
621
  mImporters["DNA"] =
 
622
    new QgsSimpleBabelFormat( "dna", true, false, false );
509
623
 
510
624
  // and the GPS devices
511
 
  mDevices["Garmin serial"] = 
512
 
    new QgsGPSDevice("%babel -w -i garmin -o gpx %in %out",
513
 
                     "%babel -w -i gpx -o garmin %in %out",
514
 
                     "%babel -r -i garmin -o gpx %in %out",
515
 
                     "%babel -r -i gpx -o garmin %in %out",
516
 
                     "%babel -t -i garmin -o gpx %in %out",
517
 
                     "%babel -t -i gpx -o garmin %in %out");
518
 
  QStringList deviceNames = settings.value("/Plugin-GPS/devicelist").
519
 
                             toStringList();
 
625
  mDevices["Garmin serial"] =
 
626
    new QgsGPSDevice( "%babel -w -i garmin -o gpx %in %out",
 
627
                      "%babel -w -i gpx -o garmin %in %out",
 
628
                      "%babel -r -i garmin -o gpx %in %out",
 
629
                      "%babel -r -i gpx -o garmin %in %out",
 
630
                      "%babel -t -i garmin -o gpx %in %out",
 
631
                      "%babel -t -i gpx -o garmin %in %out" );
 
632
  QStringList deviceNames = settings.value( "/Plugin-GPS/devicelist" ).
 
633
                            toStringList();
520
634
 
521
635
  QStringList::const_iterator iter;
522
636
 
523
 
  for (iter = deviceNames.begin(); iter != deviceNames.end(); ++iter) {
 
637
  for ( iter = deviceNames.begin(); iter != deviceNames.end(); ++iter )
 
638
  {
524
639
    QString wptDownload = settings.
525
 
      value(QString("/Plugin-GPS/devices/%1/wptdownload").
526
 
       arg(*iter), "").toString();
 
640
                          value( QString( "/Plugin-GPS/devices/%1/wptdownload" ).
 
641
                                 arg( *iter ), "" ).toString();
527
642
    QString wptUpload = settings.
528
 
      value(QString("/Plugin-GPS/devices/%1/wptupload").arg(*iter), "").
529
 
       toString();
 
643
                        value( QString( "/Plugin-GPS/devices/%1/wptupload" ).arg( *iter ), "" ).
 
644
                        toString();
530
645
    QString rteDownload = settings.
531
 
      value(QString("/Plugin-GPS/devices/%1/rtedownload").arg(*iter), "").
532
 
       toString();
 
646
                          value( QString( "/Plugin-GPS/devices/%1/rtedownload" ).arg( *iter ), "" ).
 
647
                          toString();
533
648
    QString rteUpload = settings.
534
 
      value(QString("/Plugin-GPS/devices/%1/rteupload").arg(*iter), "").
535
 
       toString();
 
649
                        value( QString( "/Plugin-GPS/devices/%1/rteupload" ).arg( *iter ), "" ).
 
650
                        toString();
536
651
    QString trkDownload = settings.
537
 
      value(QString("/Plugin-GPS/devices/%1/trkdownload").arg(*iter), "").
538
 
       toString();
 
652
                          value( QString( "/Plugin-GPS/devices/%1/trkdownload" ).arg( *iter ), "" ).
 
653
                          toString();
539
654
    QString trkUpload = settings.
540
 
      value(QString("/Plugin-GPS/devices/%1/trkupload").arg(*iter), "").
541
 
       toString();
542
 
    mDevices[*iter] = new QgsGPSDevice(wptDownload, wptUpload,
543
 
                                       rteDownload, rteUpload,
544
 
                                       trkDownload, trkUpload);
545
 
  }
546
 
}
547
 
 
548
 
 
549
 
 
550
 
 
551
 
/** 
552
 
 * Required extern functions needed  for every plugin 
 
655
                        value( QString( "/Plugin-GPS/devices/%1/trkupload" ).arg( *iter ), "" ).
 
656
                        toString();
 
657
    mDevices[*iter] = new QgsGPSDevice( wptDownload, wptUpload,
 
658
                                        rteDownload, rteUpload,
 
659
                                        trkDownload, trkUpload );
 
660
  }
 
661
}
 
662
 
 
663
//! Set icons to the current theme
 
664
void QgsGPSPlugin::setCurrentTheme( QString theThemeName )
 
665
{
 
666
  QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/gps_importer.png";
 
667
  QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/gps_importer.png";
 
668
  QString myQrcPath = ":/gps_importer.png";
 
669
  if ( QFile::exists( myCurThemePath ) )
 
670
  {
 
671
    mQActionPointer->setIcon( QIcon( myCurThemePath ) );
 
672
    mCreateGPXAction->setIcon( QIcon( myCurThemePath ) );
 
673
  }
 
674
  else if ( QFile::exists( myDefThemePath ) )
 
675
  {
 
676
    mQActionPointer->setIcon( QIcon( myDefThemePath ) );
 
677
    mCreateGPXAction->setIcon( QIcon( myDefThemePath ) );
 
678
  }
 
679
  else if ( QFile::exists( myQrcPath ) )
 
680
  {
 
681
    mQActionPointer->setIcon( QIcon( myQrcPath ) );
 
682
    mCreateGPXAction->setIcon( QIcon( myQrcPath ) );
 
683
  }
 
684
  else
 
685
  {
 
686
    mQActionPointer->setIcon( QIcon() );
 
687
    mCreateGPXAction->setIcon( QIcon() );
 
688
  }
 
689
}
 
690
 
 
691
/**
 
692
 * Required extern functions needed  for every plugin
553
693
 * These functions can be called prior to creating an instance
554
694
 * of the plugin class
555
695
 */
556
696
// Class factory to return a new instance of the plugin class
557
 
QGISEXTERN QgisPlugin * classFactory(QgisApp * theQGisAppPointer, 
558
 
                                     QgisIface * theQgisInterfacePointer)
 
697
QGISEXTERN QgisPlugin * classFactory( QgisInterface * theQgisInterfacePointer )
559
698
{
560
 
  return new QgsGPSPlugin(theQGisAppPointer, theQgisInterfacePointer);
 
699
  return new QgsGPSPlugin( theQgisInterfacePointer );
561
700
}
562
701
 
563
702
// Return the name of the plugin - note that we do not user class members as
586
725
}
587
726
 
588
727
// Delete ourself
589
 
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
 
728
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
590
729
{
591
730
  delete thePluginPointer;
592
731
}