~ubuntu-branches/ubuntu/quantal/qgis/quantal

« back to all changes in this revision

Viewing changes to plugins/gps_importer/qgsgpsplugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve Halasz
  • Date: 2004-12-21 09:46:27 UTC
  • Revision ID: james.westby@ubuntu.com-20041221094627-r9lb6mlz2o3yp8gn
Tags: upstream-0.6.0
ImportĀ upstreamĀ versionĀ 0.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
  qgsgpsplugin.cpp - GPS related tools
 
3
   -------------------
 
4
  Date                 : Jan 21, 2004
 
5
  Copyright            : (C) 2004 by Tim Sutton
 
6
  Email                : tim@linfiniti.com
 
7
 
 
8
***************************************************************************/
 
9
 
 
10
/***************************************************************************
 
11
 *                                                                         *
 
12
 *   This program is free software; you can redistribute it and/or modify  *
 
13
 *   it under the terms of the GNU General Public License as published by  *
 
14
 *   the Free Software Foundation; either version 2 of the License, or     *
 
15
 *   (at your option) any later version.                                   *
 
16
 *                                                                         *
 
17
 ***************************************************************************/
 
18
/*  $Id: qgsgpsplugin.cpp,v 1.2.2.1 2004/12/03 17:17:27 gsherman Exp $ */
 
19
 
 
20
// includes
 
21
 
 
22
#include "../../src/qgisapp.h"
 
23
#include "../../src/qgsmaplayerregistry.h"
 
24
#include "../../src/qgsmaplayer.h"
 
25
#include "../../src/qgsvectorlayer.h"
 
26
#include "../../src/qgsdataprovider.h"
 
27
#include "qgsgpsplugin.h"
 
28
 
 
29
 
 
30
#include <qeventloop.h>
 
31
#include <qfiledialog.h>
 
32
#include <qtoolbar.h>
 
33
#include <qmenubar.h>
 
34
#include <qmessagebox.h>
 
35
#include <qpopupmenu.h>
 
36
#include <qlineedit.h>
 
37
#include <qaction.h>
 
38
#include <qapplication.h>
 
39
#include <qcursor.h>
 
40
#include <qprocess.h>
 
41
#include <qprogressdialog.h>
 
42
#include <qsettings.h>
 
43
#include <qstringlist.h>
 
44
 
 
45
//non qt includes
 
46
#include <cassert>
 
47
#include <fstream>
 
48
#include <iostream>
 
49
 
 
50
//the gui subclass
 
51
#include "qgsgpsplugingui.h"
 
52
 
 
53
// xpm for creating the toolbar icon
 
54
#include "icon.xpm"
 
55
 
 
56
#ifdef WIN32
 
57
#define QGISEXTERN extern "C" __declspec( dllexport )
 
58
#else
 
59
#define QGISEXTERN extern "C"
 
60
#endif
 
61
 
 
62
 
 
63
static const char * const ident_ = 
 
64
  "$Id: qgsgpsplugin.cpp,v 1.2.2.1 2004/12/03 17:17:27 gsherman Exp $";
 
65
static const char * const name_ = "GPS Tools";
 
66
static const char * const description_ = 
 
67
  "Tools for loading and importing GPS data.";
 
68
static const char * const version_ = "Version 0.1";
 
69
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
 
70
 
 
71
 
 
72
/**
 
73
 * Constructor for the plugin. The plugin is passed a pointer to the main app
 
74
 * and an interface object that provides access to exposed functions in QGIS.
 
75
 * @param qgis Pointer to the QGIS main window
 
76
 * @param _qI Pointer to the QGIS interface object
 
77
 */
 
78
QgsGPSPlugin::QgsGPSPlugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
 
79
  mMainWindowPointer(theQGisApp), 
 
80
  mQGisInterface(theQgisInterFace),
 
81
  QgisPlugin(name_,description_,version_,type_)
 
82
{
 
83
  setupBabel();
 
84
}
 
85
 
 
86
QgsGPSPlugin::~QgsGPSPlugin()
 
87
{
 
88
  // delete all our babel formats
 
89
  BabelMap::iterator iter;
 
90
  for (iter = mImporters.begin(); iter != mImporters.end(); ++iter)
 
91
    delete iter->second;
 
92
  for (iter = mDevices.begin(); iter != mDevices.end(); ++iter)
 
93
    delete iter->second;
 
94
}
 
95
 
 
96
 
 
97
/*
 
98
 * Initialize the GUI interface for the plugin 
 
99
 */
 
100
void QgsGPSPlugin::initGui()
 
101
{
 
102
  // add a menu with 2 items
 
103
  QPopupMenu *pluginMenu = new QPopupMenu(mMainWindowPointer);
 
104
  pluginMenu->insertItem(QIconSet(icon),"&Gps Tools", this, SLOT(run()));
 
105
  int menuId = pluginMenu->insertItem("&Create new GPX layer", this, SLOT(createGPX()));
 
106
  pluginMenu->setWhatsThis(menuId, "Creates a new GPX layer and displays it on the map canvas");
 
107
  mMenuBarPointer = ((QMainWindow *) mMainWindowPointer)->menuBar();
 
108
  mMenuId = mQGisInterface->addMenu("&Gps", pluginMenu);
 
109
 
 
110
  // add an action to the toolbar
 
111
  mQActionPointer = new QAction("Gps Tools", QIconSet(icon), "&Wmi",0, 
 
112
                                this, "run");
 
113
  mQActionPointer->setWhatsThis( "Creates a new GPX layer and displays it on the map canvas");
 
114
  connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run()));
 
115
  mQGisInterface->addToolBarIcon(mQActionPointer);
 
116
}
 
117
 
 
118
//method defined in interface
 
119
void QgsGPSPlugin::help()
 
120
{
 
121
  //implement me!
 
122
}
 
123
 
 
124
// Slot called when the buffer menu item is activated
 
125
void QgsGPSPlugin::run()
 
126
{
 
127
  // find all GPX layers
 
128
  std::vector<QgsVectorLayer*> gpxLayers;
 
129
  std::map<QString, QgsMapLayer*>::const_iterator iter;
 
130
  std::cerr<<"LAYERS: "<<mQGisInterface->getLayerRegistry()->
 
131
    mapLayers().size()<<std::endl;
 
132
  for (iter = mQGisInterface->getLayerRegistry()->mapLayers().begin();
 
133
       iter != mQGisInterface->getLayerRegistry()->mapLayers().end(); ++iter) {
 
134
    std::cerr<<iter->second->name()<<std::endl;
 
135
    if (iter->second->type() == QgsMapLayer::VECTOR) {
 
136
      QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>(iter->second);
 
137
      if (vLayer->providerType() == "gpx")
 
138
        gpxLayers.push_back(vLayer);
 
139
    }
 
140
  }
 
141
  std::cerr<<std::endl;
 
142
  
 
143
  QgsGPSPluginGui *myPluginGui = 
 
144
    new QgsGPSPluginGui(mImporters, mDevices, gpxLayers, mMainWindowPointer, 
 
145
                        "GPS Tools", true, 0);
 
146
  //listen for when the layer has been made so we can draw it
 
147
  connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), 
 
148
          this, SLOT(drawRasterLayer(QString)));
 
149
  connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), 
 
150
          this, SLOT(drawVectorLayer(QString,QString,QString)));
 
151
  connect(myPluginGui, SIGNAL(loadGPXFile(QString, bool, bool, bool)), 
 
152
          this, SLOT(loadGPXFile(QString, bool, bool, bool)));
 
153
  connect(myPluginGui, SIGNAL(importGPSFile(QString, QgsBabelFormat*, bool, 
 
154
                                            bool, bool, QString, QString)),
 
155
          this, SLOT(importGPSFile(QString, QgsBabelFormat*, bool, bool, 
 
156
                                   bool, QString, QString)));
 
157
  connect(myPluginGui, SIGNAL(downloadFromGPS(QString, QString, bool, bool,
 
158
                                              bool, QString, QString)),
 
159
          this, SLOT(downloadFromGPS(QString, QString, bool, bool, bool,
 
160
                                     QString, QString)));
 
161
  connect(myPluginGui, SIGNAL(uploadToGPS(QgsVectorLayer*, QString, QString)),
 
162
          this, SLOT(uploadToGPS(QgsVectorLayer*, QString, QString)));
 
163
  connect(this, SIGNAL(closeGui()), myPluginGui, SLOT(close()));
 
164
 
 
165
  myPluginGui->show();
 
166
}
 
167
 
 
168
 
 
169
void QgsGPSPlugin::createGPX() {
 
170
  QString fileName = 
 
171
    QFileDialog::getSaveFileName("." , "GPS eXchange file (*.gpx)",
 
172
                                  mMainWindowPointer, "OpenFileDialog",
 
173
                                 "Save new GPX file as...");
 
174
  if (!fileName.isEmpty()) {
 
175
    QFileInfo fileInfo(fileName);
 
176
    std::ofstream ofs((const char*)fileName);
 
177
    if (!ofs) {
 
178
      QMessageBox::warning(NULL, "Could not create file",
 
179
                           "Unable to create a GPX file with the given name. "
 
180
                           "Try again with another name or in another "
 
181
                           "directory.");
 
182
      return;
 
183
    }
 
184
    ofs<<"<gpx></gpx>"<<std::endl;
 
185
    
 
186
    emit drawVectorLayer(fileName + "?type=track", 
 
187
                         fileInfo.baseName() + ", tracks", "gpx");
 
188
    emit drawVectorLayer(fileName + "?type=route", 
 
189
                         fileInfo.baseName() + ", routes", "gpx");
 
190
    emit drawVectorLayer(fileName + "?type=waypoint", 
 
191
                         fileInfo.baseName() + ", waypoints", "gpx");
 
192
  }
 
193
}
 
194
 
 
195
 
 
196
void QgsGPSPlugin::drawVectorLayer(QString thePathNameQString, 
 
197
                                   QString theBaseNameQString, 
 
198
                                   QString theProviderQString)
 
199
{
 
200
  mQGisInterface->addVectorLayer(thePathNameQString, theBaseNameQString, 
 
201
                                 theProviderQString);
 
202
}
 
203
 
 
204
// Unload the plugin by cleaning up the GUI
 
205
void QgsGPSPlugin::unload()
 
206
{
 
207
  // remove the GUI
 
208
  mMenuBarPointer->removeItem(mMenuId);
 
209
  mQGisInterface->removeToolBarIcon(mQActionPointer);
 
210
  delete mQActionPointer;
 
211
}
 
212
 
 
213
void QgsGPSPlugin::loadGPXFile(QString filename, bool loadWaypoints, bool loadRoutes,
 
214
                               bool loadTracks) {
 
215
 
 
216
  //check if input file is readable
 
217
  QFileInfo fileInfo(filename);
 
218
  if (!fileInfo.isReadable()) {
 
219
    QMessageBox::warning(NULL, "GPX Loader",
 
220
                         "Unable to read the selected file.\n"
 
221
                         "Please reselect a valid file." );
 
222
    return;
 
223
  }
 
224
  
 
225
  // remember the directory
 
226
  QSettings settings;
 
227
  settings.writeEntry("/qgis/gps/gpxdirectory", fileInfo.dirPath());
 
228
  
 
229
  // add the requested layers
 
230
  if (loadTracks)
 
231
    emit drawVectorLayer(filename + "?type=track", 
 
232
                         fileInfo.baseName() + ", tracks", "gpx");
 
233
  if (loadRoutes)
 
234
    emit drawVectorLayer(filename + "?type=route", 
 
235
                         fileInfo.baseName() + ", routes", "gpx");
 
236
  if (loadWaypoints)
 
237
    emit drawVectorLayer(filename + "?type=waypoint", 
 
238
                         fileInfo.baseName() + ", waypoints", "gpx");
 
239
  
 
240
  emit closeGui();
 
241
}
 
242
 
 
243
 
 
244
void QgsGPSPlugin::importGPSFile(QString inputFilename, QgsBabelFormat* importer, 
 
245
                                 bool importWaypoints, bool importRoutes, 
 
246
                                 bool importTracks, QString outputFilename, 
 
247
                                 QString layerName) {
 
248
 
 
249
  // what features does the user want to import?
 
250
  QString typeArg;
 
251
  if (importWaypoints)
 
252
    typeArg = "-w";
 
253
  else if (importRoutes)
 
254
    typeArg = "-r";
 
255
  else if (importTracks)
 
256
    typeArg = "-t";
 
257
  
 
258
  // try to start the gpsbabel process
 
259
  QStringList babelArgs = 
 
260
    importer->importCommand(mBabelPath, typeArg, 
 
261
                               inputFilename, outputFilename);
 
262
  QProcess babelProcess(babelArgs);
 
263
  if (!babelProcess.start()) {
 
264
    QMessageBox::warning(NULL, "Could not start process",
 
265
                         "Could not start GPSBabel!");
 
266
    return;
 
267
  }
 
268
  
 
269
  // wait for gpsbabel to finish (or the user to cancel)
 
270
  QProgressDialog progressDialog("Importing data...", "Cancel", 0,
 
271
                                 NULL, 0, true);
 
272
  progressDialog.show();
 
273
  for (int i = 0; babelProcess.isRunning(); ++i) {
 
274
    QApplication::eventLoop()->processEvents(0);
 
275
    progressDialog.setProgress(i/64);
 
276
    if (progressDialog.wasCancelled())
 
277
      return;
 
278
  }
 
279
  
 
280
  // did we get any data?
 
281
  if (babelProcess.exitStatus() != 0) {
 
282
    QString babelError(babelProcess.readStderr());
 
283
    QString errorMsg(QString("Could not import data from %1!\n\n")
 
284
                     .arg(inputFilename));
 
285
    errorMsg += babelError;
 
286
    QMessageBox::warning(NULL, "Error importing data", errorMsg);
 
287
    return;
 
288
  }
 
289
  
 
290
  // add the layer
 
291
  if (importTracks)
 
292
    emit drawVectorLayer(outputFilename + "?type=track", 
 
293
                         layerName, "gpx");
 
294
  if (importRoutes)
 
295
    emit drawVectorLayer(outputFilename + "?type=route", 
 
296
                         layerName, "gpx");
 
297
  if (importWaypoints)
 
298
    emit drawVectorLayer(outputFilename + "?type=waypoint", 
 
299
                         layerName, "gpx");
 
300
  
 
301
  emit closeGui();
 
302
}
 
303
 
 
304
 
 
305
void QgsGPSPlugin::downloadFromGPS(QString device, QString port,
 
306
                                   bool downloadWaypoints, bool downloadRoutes,
 
307
                                   bool downloadTracks, QString outputFilename,
 
308
                                   QString layerName) {
 
309
  
 
310
  // what does the user want to download?
 
311
  QString typeArg;
 
312
  if (downloadWaypoints)
 
313
    typeArg = "-w";
 
314
  else if (downloadRoutes)
 
315
    typeArg = "-r";
 
316
  else if (downloadTracks)
 
317
    typeArg = "-t";
 
318
  
 
319
  // try to start the gpsbabel process
 
320
  QStringList babelArgs = 
 
321
    mDevices[device]->importCommand(mBabelPath, typeArg, 
 
322
                                       port, outputFilename);
 
323
  QProcess babelProcess(babelArgs);
 
324
  if (!babelProcess.start()) {
 
325
    QMessageBox::warning(NULL, "Could not start process",
 
326
                         "Could not start GPSBabel!");
 
327
    return;
 
328
  }
 
329
  
 
330
  // wait for gpsbabel to finish (or the user to cancel)
 
331
  QProgressDialog progressDialog("Downloading data...", "Cancel", 0,
 
332
                                 NULL, 0, true);
 
333
  progressDialog.show();
 
334
  for (int i = 0; babelProcess.isRunning(); ++i) {
 
335
    QApplication::eventLoop()->processEvents(0);
 
336
    progressDialog.setProgress(i/64);
 
337
    if (progressDialog.wasCancelled())
 
338
      return;
 
339
  }
 
340
  
 
341
  // did we get any data?
 
342
  if (babelProcess.exitStatus() != 0) {
 
343
    QString babelError(babelProcess.readStderr());
 
344
    QString errorMsg("Could not download data from GPS!\n\n");
 
345
    errorMsg += babelError;
 
346
    QMessageBox::warning(NULL, "Error downloading data", errorMsg);
 
347
    return;
 
348
  }
 
349
  
 
350
  // add the layer
 
351
  if (downloadWaypoints)
 
352
    emit drawVectorLayer(outputFilename + "?type=waypoint", 
 
353
                         layerName, "gpx");
 
354
  if (downloadRoutes)
 
355
    emit drawVectorLayer(outputFilename + "?type=route", 
 
356
                         layerName, "gpx");
 
357
  if (downloadTracks)
 
358
    emit drawVectorLayer(outputFilename + "?type=track", 
 
359
                         layerName, "gpx");
 
360
  
 
361
  // everything was OK, remember the device and port for next time
 
362
  QSettings settings;
 
363
  settings.writeEntry("/qgis/gps/lastdldevice", device);
 
364
  settings.writeEntry("/qgis/gps/lastdlport", port);
 
365
  
 
366
  emit closeGui();
 
367
}
 
368
 
 
369
 
 
370
void QgsGPSPlugin::uploadToGPS(QgsVectorLayer* gpxLayer, QString device,
 
371
                               QString port) {
 
372
  
 
373
  const QString& source(gpxLayer->getDataProvider()->getDataSourceUri());
 
374
  
 
375
  // what kind of data does the user want to upload?
 
376
  QString typeArg;
 
377
  if (source.right(8) == "waypoint")
 
378
    typeArg = "-w";
 
379
  else if (source.right(5) == "route")
 
380
    typeArg = "-r";
 
381
  else if (source.right(5) == "track")
 
382
    typeArg = "-t";
 
383
  else {
 
384
    std::cerr<<source.right(8)<<std::endl;
 
385
    assert(false);
 
386
  }
 
387
  
 
388
  // try to start the gpsbabel process
 
389
  QStringList babelArgs = 
 
390
    mDevices[device]->exportCommand(mBabelPath, typeArg, 
 
391
                                       source.left(source.findRev('?')), port);
 
392
  QProcess babelProcess(babelArgs);
 
393
  if (!babelProcess.start()) {
 
394
    QMessageBox::warning(NULL, "Could not start process",
 
395
                         "Could not start GPSBabel!");
 
396
    return;
 
397
  }
 
398
  
 
399
  // wait for gpsbabel to finish (or the user to cancel)
 
400
  QProgressDialog progressDialog("Uploading data...", "Cancel", 0,
 
401
                                 NULL, 0, true);
 
402
  progressDialog.show();
 
403
  for (int i = 0; babelProcess.isRunning(); ++i) {
 
404
    QApplication::eventLoop()->processEvents(0);
 
405
    progressDialog.setProgress(i/64);
 
406
    if (progressDialog.wasCancelled())
 
407
      return;
 
408
  }
 
409
  
 
410
  // did we get an error?
 
411
  if (babelProcess.exitStatus() != 0) {
 
412
    QString babelError(babelProcess.readStderr());
 
413
    QString errorMsg("Error while uploading data to GPS!\n\n");
 
414
    errorMsg += babelError;
 
415
    QMessageBox::warning(NULL, "Error uploading data", errorMsg);
 
416
    return;
 
417
  }
 
418
  
 
419
  // everything was OK, remember this device for next time
 
420
  QSettings settings;
 
421
  settings.writeEntry("/qgis/gps/lastuldevice", device);
 
422
  settings.writeEntry("/qgis/gps/lastulport", port);
 
423
  
 
424
  emit closeGui();
 
425
}
 
426
 
 
427
 
 
428
void QgsGPSPlugin::setupBabel() {
 
429
  
 
430
  // where is gpsbabel?
 
431
  QSettings settings;
 
432
  mBabelPath = settings.readEntry("/qgis/gps/gpsbabelpath");
 
433
  if (mBabelPath.isEmpty())
 
434
    mBabelPath = "gpsbabel";
 
435
  // the importable formats
 
436
  mImporters["Geocaching.com .loc"] =
 
437
    new QgsSimpleBabelFormat("geo", true, false, false);
 
438
  mImporters["Magellan Mapsend"] = 
 
439
    new QgsSimpleBabelFormat("mapsend", true, true, true);
 
440
  mImporters["Garmin PCX5"] = 
 
441
    new QgsSimpleBabelFormat("pcx", true, false, true);
 
442
  mImporters["Garmin Mapsource"] = 
 
443
    new QgsSimpleBabelFormat("mapsource", true, true, true);
 
444
  mImporters["GPSUtil"] = 
 
445
    new QgsSimpleBabelFormat("gpsutil", true, false, false);
 
446
  mImporters["PocketStreets 2002/2003 Pushpin"] = 
 
447
    new QgsSimpleBabelFormat("psp", true, false, false);
 
448
  mImporters["CoPilot Flight Planner"] = 
 
449
    new QgsSimpleBabelFormat("copilot", true, false, false);
 
450
  mImporters["Magellan Navigator Companion"] = 
 
451
    new QgsSimpleBabelFormat("magnav", true, false, false);
 
452
  mImporters["Holux"] = 
 
453
    new QgsSimpleBabelFormat("holux", true, false, false);
 
454
  mImporters["Topo by National Geographic"] = 
 
455
    new QgsSimpleBabelFormat("tpg", true, false, false);
 
456
  mImporters["TopoMapPro"] = 
 
457
    new QgsSimpleBabelFormat("tmpro", true, false, false);
 
458
  mImporters["GeocachingDB"] = 
 
459
    new QgsSimpleBabelFormat("gcdb", true, false, false);
 
460
  mImporters["Tiger"] = 
 
461
    new QgsSimpleBabelFormat("tiger", true, false, false);
 
462
  mImporters["EasyGPS Binary Format"] = 
 
463
    new QgsSimpleBabelFormat("easygps", true, false, false);
 
464
  mImporters["Delorme Routes"] = 
 
465
    new QgsSimpleBabelFormat("saroute", false, false, true);
 
466
  mImporters["Navicache"] = 
 
467
    new QgsSimpleBabelFormat("navicache", true, false, false);
 
468
  mImporters["PSITrex"] = 
 
469
    new QgsSimpleBabelFormat("psitrex", true, true, true);
 
470
  mImporters["Delorme GPS Log"] = 
 
471
    new QgsSimpleBabelFormat("gpl", false, false, true);
 
472
  mImporters["OziExplorer"] = 
 
473
    new QgsSimpleBabelFormat("ozi", true, false, false);
 
474
  mImporters["NMEA Sentences"] = 
 
475
    new QgsSimpleBabelFormat("nmea", true, false, true);
 
476
  mImporters["Delorme Street Atlas 2004 Plus"] = 
 
477
    new QgsSimpleBabelFormat("saplus", true, false, false);
 
478
  mImporters["Microsoft Streets and Trips"] = 
 
479
    new QgsSimpleBabelFormat("s_and_t", true, false, false);
 
480
  mImporters["NIMA/GNIS Geographic Names"] = 
 
481
    new QgsSimpleBabelFormat("nima", true, false, false);
 
482
  mImporters["Maptech"] = 
 
483
    new QgsSimpleBabelFormat("mxf", true, false, false);
 
484
  mImporters["Mapopolis.com Mapconverter Application"] = 
 
485
    new QgsSimpleBabelFormat("mapconverter", true, false, false);
 
486
  mImporters["GPSman"] = 
 
487
    new QgsSimpleBabelFormat("gpsman", true, false, false);
 
488
  mImporters["GPSDrive"] = 
 
489
    new QgsSimpleBabelFormat("gpsdrive", true, false, false);
 
490
  mImporters["Fugawi"] = 
 
491
    new QgsSimpleBabelFormat("fugawi", true, false, false);
 
492
  mImporters["DNA"] = 
 
493
    new QgsSimpleBabelFormat("dna", true, false, false);
 
494
 
 
495
  // and the GPS devices
 
496
  mDevices["Garmin serial"] = 
 
497
    new QgsBabelCommand("%babel -i garmin -o gpx /dev/ttyS0 %out",
 
498
                        "%babel -i gpx -o garmin %in /dev/ttyS0");
 
499
  QStringList deviceNames = settings.readListEntry("/qgis/gps/devicelist");
 
500
  QStringList::iterator iter;
 
501
  for (iter = deviceNames.begin(); iter != deviceNames.end(); ++iter) {
 
502
    QString download = settings.
 
503
      readEntry(QString("/qgis/gps/devices/%1/download").arg(*iter), "");
 
504
    QString upload = settings.
 
505
      readEntry(QString("/qgis/gps/devices/%1/upload").arg(*iter), "");
 
506
    mDevices[*iter] = new QgsBabelCommand(download, upload);
 
507
  }
 
508
}
 
509
 
 
510
 
 
511
 
 
512
 
 
513
/** 
 
514
 * Required extern functions needed  for every plugin 
 
515
 * These functions can be called prior to creating an instance
 
516
 * of the plugin class
 
517
 */
 
518
// Class factory to return a new instance of the plugin class
 
519
QGISEXTERN QgisPlugin * classFactory(QgisApp * theQGisAppPointer, 
 
520
                                     QgisIface * theQgisInterfacePointer)
 
521
{
 
522
  return new QgsGPSPlugin(theQGisAppPointer, theQgisInterfacePointer);
 
523
}
 
524
 
 
525
// Return the name of the plugin - note that we do not user class members as
 
526
// the class may not yet be insantiated when this method is called.
 
527
QGISEXTERN QString name()
 
528
{
 
529
  return name_;
 
530
}
 
531
 
 
532
// Return the description
 
533
QGISEXTERN QString description()
 
534
{
 
535
  return description_;
 
536
}
 
537
 
 
538
// Return the type (either UI or MapLayer plugin)
 
539
QGISEXTERN int type()
 
540
{
 
541
  return type_;
 
542
}
 
543
 
 
544
// Return the version number for the plugin
 
545
QGISEXTERN QString version()
 
546
{
 
547
  return version_;
 
548
}
 
549
 
 
550
// Delete ourself
 
551
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
 
552
{
 
553
  delete thePluginPointer;
 
554
}