diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2011-07-13 06:38:41 -0400 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2011-07-13 06:38:41 -0400 |
commit | f7cfd9603c386434e0a113c5ac1b3bd0594de293 (patch) | |
tree | b5e9637dc96a7aafbfa24474022bb562ca19bddf | |
download | LocationTracker-f7cfd9603c386434e0a113c5ac1b3bd0594de293.tar.xz LocationTracker-f7cfd9603c386434e0a113c5ac1b3bd0594de293.zip |
The initial commit. Still unworking, but it's a sketch of what it should
do.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | LocationTracker.pro | 24 | ||||
-rw-r--r-- | Tracker.cpp | 101 | ||||
-rw-r--r-- | Tracker.h | 38 | ||||
-rw-r--r-- | main.cpp | 13 | ||||
-rw-r--r-- | qtc_packaging/debian_harmattan/README | 6 | ||||
-rw-r--r-- | qtc_packaging/debian_harmattan/changelog | 5 | ||||
-rw-r--r-- | qtc_packaging/debian_harmattan/compat | 1 | ||||
-rw-r--r-- | qtc_packaging/debian_harmattan/control | 14 | ||||
-rw-r--r-- | qtc_packaging/debian_harmattan/copyright | 40 | ||||
-rwxr-xr-x | qtc_packaging/debian_harmattan/rules | 91 |
11 files changed, 334 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a9d35c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.user diff --git a/LocationTracker.pro b/LocationTracker.pro new file mode 100644 index 0000000..00c01f7 --- /dev/null +++ b/LocationTracker.pro @@ -0,0 +1,24 @@ +QT = core network +CONFIG += mobility +MOBILITY = location +LIBS += -lqjson + +{ + target.path = /opt/LocationTracker/bin + INSTALLS += target +} + +OTHER_FILES += \ + qtc_packaging/debian_harmattan/rules \ + qtc_packaging/debian_harmattan/README \ + qtc_packaging/debian_harmattan/copyright \ + qtc_packaging/debian_harmattan/control \ + qtc_packaging/debian_harmattan/compat \ + qtc_packaging/debian_harmattan/changelog + +HEADERS += \ + Tracker.h + +SOURCES += \ + Tracker.cpp \ + main.cpp diff --git a/Tracker.cpp b/Tracker.cpp new file mode 100644 index 0000000..da36afd --- /dev/null +++ b/Tracker.cpp @@ -0,0 +1,101 @@ +#include "Tracker.h" +#include <QGeoPositionInfoSource> +#include <QVariantMap> +#include <QNetworkRequest> +#include <QNetworkConfigurationManager> +#include <QTimer> +#include <QSslError> +#include <QSslCertificate> +#include <QList> +#include <QDebug> + +using namespace QtMobility; + +Tracker::Tracker(const QString &server, const QString &serverPath, const QString &username, const QString &password, const QString &certPath, unsigned int serverPort, QObject *parent) : + QObject(parent), + m_session(QNetworkConfigurationManager().defaultConfiguration()), + m_isUploading(false) +{ + m_url.setPath(QString("%1/update.py").arg(serverPath)); + m_url.setScheme(QLatin1String("https")); + m_url.setHost(server); + m_url.setPort(serverPort); + m_url.setUserName(username); + m_url.setPassword(password); + + if (!certPath.isEmpty()) { + foreach (const QSslCertificate &cert, QSslCertificate::fromPath(certPath, QSsl::Der)) { + qDebug() << cert << cert.issuerInfo(QSslCertificate::CommonName); + m_expectedSslErrors.append(QSslError(QSslError::SelfSignedCertificate, cert)); + } + } + + QGeoPositionInfoSource *gps = QGeoPositionInfoSource::createDefaultSource(this); + if (!gps) + return; + connect(gps, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo))); + gps->setUpdateInterval(1000 * 60 * 15); + gps->startUpdates(); +} +void Tracker::positionUpdated(const QGeoPositionInfo &update) +{ + if (!update.isValid() || !update.coordinate().isValid()) + return; + QVariantMap map; + map.insert(QLatin1String("timestamp"), update.timestamp().toMSecsSinceEpoch()); + if (update.coordinate().type() == QGeoCoordinate::Coordinate3D) + map.insert(QLatin1String("altitude"), update.coordinate().altitude()); + map.insert(QLatin1String("latitude"), update.coordinate().latitude()); + map.insert(QLatin1String("longitude"), update.coordinate().longitude()); + if (update.hasAttribute(QGeoPositionInfo::Direction)) + map.insert(QLatin1String("direction"), update.attribute(QGeoPositionInfo::Direction)); + if (update.hasAttribute(QGeoPositionInfo::GroundSpeed)) + map.insert(QLatin1String("groundSpeed"), update.attribute(QGeoPositionInfo::GroundSpeed)); + if (update.hasAttribute(QGeoPositionInfo::VerticalSpeed)) + map.insert(QLatin1String("verticalSpeed"), update.attribute(QGeoPositionInfo::VerticalSpeed)); + if (update.hasAttribute(QGeoPositionInfo::MagneticVariation)) + map.insert(QLatin1String("magneticVariation"), update.attribute(QGeoPositionInfo::MagneticVariation)); + if (update.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) + map.insert(QLatin1String("horizontalAccuracy"), update.attribute(QGeoPositionInfo::HorizontalAccuracy)); + if (update.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) + map.insert(QLatin1String("verticalAccuracy"), update.attribute(QGeoPositionInfo::VerticalAccuracy)); + + m_positions.enqueue(m_json.serialize(map)); + upload(); +} +void Tracker::upload() +{ + if (m_isUploading) + return; + m_isUploading = true; + m_session.open(); + nextUpload(); +} +void Tracker::nextUpload() +{ + if (m_positions.empty()) { + m_session.close(); + m_isUploading = false; + return; + } + if (qobject_cast<QNetworkReply*>(sender())) { + m_positions.dequeue(); + sender()->deleteLater(); + } + + QNetworkRequest request(m_url); + request.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json")); + QNetworkReply *reply = m_network.post(request, m_positions.head()); + reply->ignoreSslErrors(m_expectedSslErrors); + connect(reply, SIGNAL(finished()), this, SLOT(nextUpload())); + connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(uploadError(QNetworkReply::NetworkError))); +} +void Tracker::uploadError(QNetworkReply::NetworkError) +{ + QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); + if (!reply) + return; + qDebug() << reply->errorString(); + reply->deleteLater(); + QTimer::singleShot(1000 * 60 * 5, this, SLOT(nextUpload())); +} diff --git a/Tracker.h b/Tracker.h new file mode 100644 index 0000000..51a319e --- /dev/null +++ b/Tracker.h @@ -0,0 +1,38 @@ +#ifndef TRACKER_H +#define TRACKER_H + +#include <QObject> +#include <QQueue> +#include <QGeoPositionInfo> +#include <QNetworkSession> +#include <QNetworkAccessManager> +#include <QNetworkReply> +#include <QSslError> +#include <qjson/serializer.h> + +using namespace QtMobility; + +class Tracker : public QObject +{ + Q_OBJECT +public: + Tracker(const QString &server, const QString &serverPath, const QString &username, const QString &password, const QString &certPath = QString(), unsigned int port = 443, QObject *parent = 0); + +private: + QUrl m_url; + QList<QSslError> m_expectedSslErrors; + QQueue<QByteArray> m_positions; + QJson::Serializer m_json; + QNetworkSession m_session; + QNetworkAccessManager m_network; + bool m_isUploading; + +private slots: + void positionUpdated(const QGeoPositionInfo &update); + void upload(); + void uploadError(QNetworkReply::NetworkError); + void nextUpload(); + +}; + +#endif // TRACKER_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..9ef8785 --- /dev/null +++ b/main.cpp @@ -0,0 +1,13 @@ +#include <QCoreApplication> +#include "Tracker.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + a.setApplicationName("Location Tracker"); + a.setOrganizationName("ZX2C4 Software"); + a.setOrganizationDomain("zx2c4.com"); + a.setApplicationVersion("0.1"); + Tracker tracker("zx2c4.com", "/projects/locationtracker", "n950", "tester1234", "/home/user/MyDocs/zx2c4.der"); + return a.exec(); +} diff --git a/qtc_packaging/debian_harmattan/README b/qtc_packaging/debian_harmattan/README new file mode 100644 index 0000000..ae31d2e --- /dev/null +++ b/qtc_packaging/debian_harmattan/README @@ -0,0 +1,6 @@ +The Debian Package locationtracker +---------------------------- + +Comments regarding the Package + + -- unknown <zx2c4@unknown> Wed, 13 Jul 2011 03:32:22 -0400 diff --git a/qtc_packaging/debian_harmattan/changelog b/qtc_packaging/debian_harmattan/changelog new file mode 100644 index 0000000..af53102 --- /dev/null +++ b/qtc_packaging/debian_harmattan/changelog @@ -0,0 +1,5 @@ +locationtracker (0.0.1) unstable; urgency=low + + * Initial Release. + + -- unknown <zx2c4@unknown> Wed, 13 Jul 2011 03:32:22 -0400 diff --git a/qtc_packaging/debian_harmattan/compat b/qtc_packaging/debian_harmattan/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/qtc_packaging/debian_harmattan/compat @@ -0,0 +1 @@ +7 diff --git a/qtc_packaging/debian_harmattan/control b/qtc_packaging/debian_harmattan/control new file mode 100644 index 0000000..a45ed48 --- /dev/null +++ b/qtc_packaging/debian_harmattan/control @@ -0,0 +1,14 @@ +Source: locationtracker +Section: user/other +Priority: optional +Maintainer: unknown <zx2c4@unknown> +Build-Depends: debhelper (>= 5), libqt4-dev +Standards-Version: 3.7.3 +Homepage: <insert the upstream URL, if relevant> + +Package: locationtracker +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: <insert up to 60 chars description> + <insert long description, indented with spaces> +XSBC-Maemo-Display-Name: LocationTracker diff --git a/qtc_packaging/debian_harmattan/copyright b/qtc_packaging/debian_harmattan/copyright new file mode 100644 index 0000000..7810f15 --- /dev/null +++ b/qtc_packaging/debian_harmattan/copyright @@ -0,0 +1,40 @@ +This package was debianized by unknown <zx2c4@unknown> on +Wed, 13 Jul 2011 03:32:22 -0400. + +It was downloaded from <url://example.com> + +Upstream Author(s): + + <put author's name and email here> + <likewise for another author> + +Copyright: + + <Copyright (C) YYYY Name OfAuthor> + <likewise for another author> + +License: + + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this package; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +On Debian systems, the complete text of the GNU General +Public License can be found in `/usr/share/common-licenses/GPL'. + +The Debian packaging is (C) 2011, unknown <zx2c4@unknown> and +is licensed under the GPL, see above. + + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. diff --git a/qtc_packaging/debian_harmattan/rules b/qtc_packaging/debian_harmattan/rules new file mode 100755 index 0000000..0fd08ef --- /dev/null +++ b/qtc_packaging/debian_harmattan/rules @@ -0,0 +1,91 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + + + + + +configure: configure-stamp +configure-stamp: + dh_testdir + # qmake PREFIX=/usr# Uncomment this line for use without Qt Creator + + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + # $(MAKE) # Uncomment this line for use without Qt Creator + #docbook-to-man debian/locationtracker.sgml > locationtracker.1 + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + $(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/locationtracker. + $(MAKE) INSTALL_ROOT="$(CURDIR)"/debian/locationtracker install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples +# dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip + dh_compress + dh_fixperms +# dh_perl +# dh_makeshlibs + dh_installdeb + # dh_shlibdeps # Uncomment this line for use without Qt Creator + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure |