QWhereabouts *NeoGpsPlugin::create(const QString &source) { qLog(Hardware) << __PRETTY_FUNCTION__; QString path = source; if (path.isEmpty()) { #ifdef NMEA_GPS_DEVICE path = NMEA_GPS_DEVICE; #endif QSettings cfg("Trolltech", "Whereabouts"); cfg.beginGroup("Hardware"); path = cfg.value("Device", path).toString(); } QFile *sourceFile = new QFile(path, this); if (!sourceFile->open(QIODevice::ReadOnly)) { QMessageBox::warning( 0,tr("Mappingdemo"),tr("Cannot open GPS device at %1").arg(path), QMessageBox::Ok, QMessageBox::Ok); qWarning() << "Cannot open GPS device at" << path; delete sourceFile; return 0; } QNmeaWhereabouts *whereabouts = new QNmeaWhereabouts(QNmeaWhereabouts::RealTimeMode, this); whereabouts->setSourceDevice(sourceFile); // QFile does not emit readyRead(), so we must call // newDataAvailable() when necessary QSocketNotifier *notifier = new QSocketNotifier(sourceFile->handle(), QSocketNotifier::Read, this); connect(notifier, SIGNAL(activated(int)), whereabouts, SLOT(newDataAvailable())); return whereabouts; }
QWhereabouts *NeoGpsPlugin::create(const QString &source) { qLog(Hardware) << __PRETTY_FUNCTION__; QString path = source; if (path.isEmpty()) { #ifdef NMEA_GPS_DEVICE path = NMEA_GPS_DEVICE; #endif QSettings cfg("Trolltech", "Whereabouts"); cfg.beginGroup("Hardware"); path = cfg.value("Device", path).toString(); } reader = new QProcess(this); reader->start("gpspipe", QStringList() << "-r", QIODevice::ReadWrite); if (!reader->waitForStarted()) { qWarning() << "couldnt start gpspipe -r: " + reader->errorString(); QMessageBox::warning(0, tr("GPS"), tr("Cannot start gpspipe -r"), QMessageBox::Ok, QMessageBox::Ok); delete reader; reader = 0; return 0; } QNmeaWhereabouts *whereabouts = new QNmeaWhereabouts(QNmeaWhereabouts::RealTimeMode, this); whereabouts->setSourceDevice(reader); return whereabouts; }