Daemon.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. #ifndef DAEMON_H
  5. #define DAEMON_H
  6. #include <QObject>
  7. #include <QPointer>
  8. #include <QFile>
  9. #include <QTextStream>
  10. #include <QVariant>
  11. #include <QSettings>
  12. // QtMobility API headers
  13. #include <QGeoPositionInfoSource>
  14. #include <QGeoPositionInfo>
  15. // QtMobility namespace
  16. QTM_USE_NAMESPACE
  17. class Message;
  18. class Daemon: public QObject
  19. {
  20. Q_OBJECT
  21. public:
  22. Daemon(QObject *parent = 0);
  23. ~Daemon();
  24. // WhoWhereDaemon service interface
  25. public:
  26. // Enables GPS location tracking on
  27. Q_INVOKABLE void enableDaemon(QVariant enable);
  28. Q_INVOKABLE QVariant isDaemonEnabled();
  29. // Enables log
  30. Q_INVOKABLE void enableDaemonLog(QVariant enable);
  31. Q_INVOKABLE QVariant isLogEnabled();
  32. // Does GPS running always
  33. Q_INVOKABLE void keepGpsRunning(QVariant running);
  34. Q_INVOKABLE QVariant isGpsRunningEnabled();
  35. // GPS accuracy in meters
  36. Q_INVOKABLE void gpsAccuracy(QVariant meters);
  37. Q_INVOKABLE QVariant getGpsAccuracy();
  38. // Send your GPS location to phonenumber
  39. Q_INVOKABLE void sendLocationTo(QVariant number);
  40. // Store settings to file
  41. Q_INVOKABLE void storeSettings();
  42. // Kill daemon service
  43. Q_INVOKABLE void killDaemon();
  44. signals:
  45. // Server sends logs to Client
  46. void daemonLog(QString log);
  47. // GPS started
  48. void gpsInitialized();
  49. // GPS valid location readed
  50. void gpsLocationReceived();
  51. // GPS closed
  52. void gpsClosed();
  53. private:
  54. void createGPS();
  55. void deleteGPS();
  56. void reset();
  57. void readSettings();
  58. void saveSettings();
  59. private slots:
  60. // Signals from Messaging
  61. void friendAskLocationSMS(QString friendPhoneNumber);
  62. // Signals from QGeoPositionInfoSource
  63. void updateTimeout();
  64. void positionUpdated(QGeoPositionInfo);
  65. // Log messages into text file
  66. void log(QString str);
  67. void startGps();
  68. private:
  69. Message* m_message;
  70. QPointer<QGeoPositionInfoSource> m_location;
  71. QGeoPositionInfo m_YougeoPosInfo;
  72. QFile* m_file;
  73. QTextStream m_outStream;
  74. QString m_askingLocation;
  75. QSettings* m_settings;
  76. bool m_daemonEnabled;
  77. bool m_daemonLogEnabled;
  78. double m_accuracy;
  79. bool m_keepGpsRunning;
  80. };
  81. #endif // DAEMON_H