@@ -46,15 +46,28 @@
import android.util.Log;

public class Settings {
private Context m_context;

private static final String GDS_SETTINGS = "gds_settings";
private static final String SETTINGS_STATUS = "settings_status";

/* From settings activity: */
private static final String DESCRIPTION = "description";
private static final String SERVER_URL = "server_url";

/* Application internal settings */
private static final String AUTH_TOKEN = "auth_token";
private static final String LOGIN = "login";
private static final String PASSWORD = "password";
private static final String REMEMBER = "remember";

private Context m_context;

public Settings(Context context){
m_context = context;
}

public SharedPreferences getPreferences(){
return m_context.getSharedPreferences(IGDSSettings.GDS_SETTINGS, 0);
return m_context.getSharedPreferences(GDS_SETTINGS, 0);
}

public Editor getPreferencesEditor(){
@@ -79,7 +92,7 @@ private void loadFromXMLFile(Editor configEditor) {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader xmlreader = parser.getXMLReader();
xmlreader.setContentHandler(new ConfigFeedParser(configEditor));
xmlreader.setContentHandler(new ConfigFeedParser(this));
xmlreader.parse(is);
} catch (Exception e) {
if (GDSUtil.DEBUG) {
@@ -90,75 +103,68 @@ private void loadFromXMLFile(Editor configEditor) {
}

public String getAuthToken() {
SharedPreferences prefs = m_context.getSharedPreferences(IGDSSettings.GDS_SETTINGS, 0);
return prefs.getString(IGDSSettings.AUTH_TOKEN, "");
SharedPreferences prefs = m_context.getSharedPreferences(GDS_SETTINGS, 0);
return prefs.getString(AUTH_TOKEN, "");
}

public void setAuthToken(String authToken) {
SharedPreferences prefs = m_context.getSharedPreferences(IGDSSettings.GDS_SETTINGS, 0);
prefs.edit().putString(IGDSSettings.AUTH_TOKEN, authToken).commit();
SharedPreferences prefs = m_context.getSharedPreferences(GDS_SETTINGS, 0);
prefs.edit().putString(AUTH_TOKEN, authToken).commit();
}

public String getLogin() {
SharedPreferences prefs = m_context.getSharedPreferences(IGDSSettings.GDS_SETTINGS, 0);
return prefs.getString(IGDSSettings.LOGIN, "");
SharedPreferences prefs = m_context.getSharedPreferences(GDS_SETTINGS, 0);
return prefs.getString(LOGIN, "");
}

public void setLogin(String login) {
SharedPreferences prefs = m_context.getSharedPreferences(IGDSSettings.GDS_SETTINGS, 0);
prefs.edit().putString(IGDSSettings.LOGIN, login).commit();
SharedPreferences prefs = m_context.getSharedPreferences(GDS_SETTINGS, 0);
prefs.edit().putString(LOGIN, login).commit();
}

public String getPassword() {
SharedPreferences prefs = m_context.getSharedPreferences(IGDSSettings.GDS_SETTINGS, 0);
return prefs.getString(IGDSSettings.PASSWORD, "");
SharedPreferences prefs = m_context.getSharedPreferences(GDS_SETTINGS, 0);
return prefs.getString(PASSWORD, "");
}

public void setPassword(String password) {
SharedPreferences prefs = m_context.getSharedPreferences(IGDSSettings.GDS_SETTINGS, 0);
prefs.edit().putString(IGDSSettings.PASSWORD, password).commit();
SharedPreferences prefs = m_context.getSharedPreferences(GDS_SETTINGS, 0);
prefs.edit().putString(PASSWORD, password).commit();
}

public boolean isRememberMe() {
SharedPreferences prefs = m_context.getSharedPreferences(IGDSSettings.GDS_SETTINGS, 0);
return prefs.getBoolean(IGDSSettings.REMEMBER, false);
SharedPreferences prefs = m_context.getSharedPreferences(GDS_SETTINGS, 0);
return prefs.getBoolean(REMEMBER, false);
}

public void setRememberMe(boolean status) {
SharedPreferences prefs = m_context.getSharedPreferences(IGDSSettings.GDS_SETTINGS, 0);
prefs.edit().putBoolean(IGDSSettings.REMEMBER, status).commit();
SharedPreferences prefs = m_context.getSharedPreferences(GDS_SETTINGS, 0);
prefs.edit().putBoolean(REMEMBER, status).commit();
}

public String getDescription() {
SharedPreferences prefs = m_context.getSharedPreferences(GDS_SETTINGS, 0);
return prefs.getString(DESCRIPTION, "");
}

public void setDescription(String description) {
SharedPreferences prefs = m_context.getSharedPreferences(GDS_SETTINGS, 0);
prefs.edit().putString(DESCRIPTION, description).commit();
}

public String getServerUrl() {
SharedPreferences prefs = m_context.getSharedPreferences(IGDSSettings.GDS_SETTINGS, 0);
return prefs.getString(IGDSSettings.SERVER_URL, "");
SharedPreferences prefs = m_context.getSharedPreferences(GDS_SETTINGS, 0);
return prefs.getString(SERVER_URL, "");
}

public void setServerUrl(String serverUrl) {
SharedPreferences prefs = m_context.getSharedPreferences(IGDSSettings.GDS_SETTINGS, 0);
prefs.edit().putString(IGDSSettings.SERVER_URL, serverUrl).commit();
SharedPreferences prefs = m_context.getSharedPreferences(GDS_SETTINGS, 0);
prefs.edit().putString(SERVER_URL, serverUrl).commit();
}


public static SharedPreferences getPreferences(Context c){
return new Settings(c).getPreferences();
}

public interface IGDSSettings{
String GDS_SETTINGS = "gds_settings";

String AUTH_TOKEN = "auth_token";
String LOGIN = "login";
String PASSWORD = "password";
String REMEMBER = "remember";
String CHANNEL = "channel";
String CHANNEL_KEY = "channel_key";
String SERVER_URL = "server_url";
String TIME_TICK = "time_request";
String RADIUS = "radius";
String URI = "uri";
String IS_SHOW_TICKS = "is_show_ticks";
String IS_HIDE_APP = "is_hide_app";
}


}
@@ -36,7 +36,7 @@
package ru.spb.osll.GDS.preferences;

import ru.spb.osll.GDS.R;
import ru.spb.osll.GDS.preferences.Settings.IGDSSettings;
import ru.spb.osll.GDS.exception.ExceptionHandler;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
@@ -46,16 +46,25 @@
import android.widget.CheckBox;
import android.widget.EditText;

public class SettingsActivity extends Activity implements IGDSSettings {
public class SettingsActivity extends Activity {

private Settings m_settings;
private EditText m_descriptionEdit;
private EditText m_serverUrlEdit;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));

setTitle("GeoDoctorSearch settings");

m_settings = new Settings(this);
m_descriptionEdit = (EditText) findViewById(R.id.edit_description);
m_serverUrlEdit = (EditText) findViewById(R.id.edit_server_address);

initializeFields();
//initializeTimeTickBtn();

Button btnOk = (Button) findViewById(R.id.button_ok);
btnOk.setOnClickListener(new View.OnClickListener() {
@@ -75,45 +84,15 @@ public void onClick(View v) {
}
});
}

private int m_timeTick;

private void initializeFields(){
//initField(LOGIN, R.id.edit_login);
//initField(PASSWORD, R.id.edit_password);
//initField(CHANNEL, R.id.edit_channel);
//initField(CHANNEL_KEY, R.id.edit_key);
initField(SERVER_URL, R.id.edit_server_address);

//initCheckBox(IS_HIDE_APP, R.id.checkbox_hide);
//initCheckBox(IS_SHOW_TICKS, R.id.checkbox_tick);
m_descriptionEdit.setText(m_settings.getDescription());
m_serverUrlEdit.setText(m_settings.getServerUrl());
}

// private void initializeTimeTickBtn(){
// m_timeTick = new Settings(this).getPreferences().getInt(TIME_TICK, 0);
//
// Button btnTick = (Button) findViewById(R.id.button_settings_tick);
// btnTick.setText(Integer.toString(m_timeTick));
// btnTick.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// //new TimeTickDialog(SettingsActivity.this, getIdx(m_timeTick)).show();
// }
// });
// }

private void savePreferences(){
Editor prefEditor = new Settings(this).getPreferencesEditor();
//saveField(LOGIN, R.id.edit_login, prefEditor);
//saveField(PASSWORD, R.id.edit_password, prefEditor);
//saveField(CHANNEL, R.id.edit_channel, prefEditor);
//saveField(CHANNEL_KEY, R.id.edit_key, prefEditor);
//saveField(SERVER_URL, R.id.edit_server_address, prefEditor);
prefEditor.putInt(TIME_TICK, m_timeTick);

//saveCheckBox(IS_HIDE_APP, R.id.checkbox_hide, prefEditor);
//saveCheckBox(IS_SHOW_TICKS, R.id.checkbox_tick, prefEditor);

prefEditor.commit();
m_settings.setDescription(m_descriptionEdit.getText().toString().trim());
m_settings.setServerUrl(m_serverUrlEdit.getText().toString().trim());
}

private Runnable m_saveToast = new Runnable() {
@@ -123,28 +102,16 @@ public void run() {
}
};

private void initField(String key, int idField){
SharedPreferences settings = new Settings(this).getPreferences();
String str = settings.getString(key, "?????");
((EditText) findViewById(idField)).setText(str);
}

private void initCheckBox(String key, int id){
SharedPreferences settings = new Settings(this).getPreferences();
((CheckBox) findViewById(id)).setChecked(settings.getBoolean(key, false));
}

private void saveField(String key, int idField, Editor prefEditor){
String str = ((EditText) findViewById(idField)).getText().toString().trim();
prefEditor.putString(key, str);
}

private void saveCheckBox(String key, int id, Editor prefEditor){
boolean status = ((CheckBox) findViewById(id)).isChecked();
prefEditor.putBoolean(key, status);
}


String[] args = {"1", "2", "3", "4", "5", "10", "20", "30", "40", "50", "60"};
private int getIdx(int val){
for (int i = 0; i < args.length; i++){
@@ -153,6 +120,22 @@ private int getIdx(int val){
}
return 0;
}

//private int m_timeTick;

// private void initializeTimeTickBtn(){
// m_timeTick = new Settings(this).getPreferences().getInt(TIME_TICK, 0);
//
// Button btnTick = (Button) findViewById(R.id.button_settings_tick);
// btnTick.setText(Integer.toString(m_timeTick));
// btnTick.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// //new TimeTickDialog(SettingsActivity.this, getIdx(m_timeTick)).show();
// }
// });
//}

/*
class TimeTickDialog extends RadioButtonDialog{
public TimeTickDialog(Context context, int selectedItem) {
@@ -166,7 +166,7 @@ private void sendMark(Location location) {
for(int i = 0; i < GDSUtil.ATTEMPTS; i++){
JSONResponse = new JsonApplyMarkRequest(m_authToken, m_channel, "gds tracker", "",
"gds tracker", location.getLatitude(), location.getLongitude(), 0,
GDSUtil.getTime(new Date()), serverUrl).doRequest();
GDSUtil.getUtcTime(new Date()), serverUrl).doRequest();
if (JSONResponse != null)
break;
}
@@ -49,6 +49,7 @@ public interface IRequest {

String LOGIN = "login";
String PASSWORD = "password";
String EMAIL = "email";
}

public interface IApplyChannel{
@@ -49,11 +49,13 @@
public class JsonAddUserRequest extends JsonBaseRequest {
private String m_login;
private String m_password;
private String m_email;
private String m_serverUrl;

public JsonAddUserRequest(String login, String password, String serverUrl){
public JsonAddUserRequest(String login, String password, String email, String serverUrl){
m_login = login;
m_password = password;
m_email = email;
m_serverUrl = serverUrl;
}

@@ -63,6 +65,7 @@ protected JSONObject doRequestInternal() throws JSONException, IOException,
JSONObject jsonObject = new JSONObject();
jsonObject.put(LOGIN, m_login);
jsonObject.put(PASSWORD, m_password);
jsonObject.put(EMAIL, m_email);
Log.v(JSON_LOG, jsonObject.toString());
return JsonBase.instance().doRequest(jsonObject, new URI(m_serverUrl + REQUEST));
}
@@ -4,7 +4,7 @@
# dir1.source = mydir
DEPLOYMENTFOLDERS = # file1 dir1

QT += network
QT += network phonon

symbian:TARGET.UID3 = 0xE6691141

@@ -36,10 +36,10 @@
#include <QSet>
#include <QList>
#include <QSharedPointer>
#include <QMediaPlayer>
#include "LocationManager.h"
#include "FilterCircleQuery.h"
#include "User.h"
#include <phonon>

QTM_USE_NAMESPACE

@@ -54,7 +54,7 @@ class EventsService : public QObject
FilterCircleQuery *m_filterCircleQuery;
QSharedPointer<common::User> m_user;
QSet<int> m_eventsIds;
QMediaPlayer *m_mediaPlayer;
Phonon::MediaObject *m_mediaPlayer;

public:
explicit EventsService(LocationManager *locationManager, QObject *parent = 0);
@@ -43,8 +43,10 @@ class LocationManager : public QObject
{
Q_OBJECT

QGeoPositionInfoSource *m_source;
QGeoPositionInfo m_info;
QGeoPositionInfoSource *m_satelliteSource;
QGeoPositionInfoSource *m_nonSatelliteSource;
QGeoPositionInfo m_satelliteInfo;
QGeoPositionInfo m_nonSatelliteInfo;
QMutex m_infoMutex;

public:
@@ -56,7 +58,8 @@ class LocationManager : public QObject
signals:

public slots:
void positionUpdated(const QGeoPositionInfo &info);
void satellitePositionUpdated(const QGeoPositionInfo &info);
void nonSatellitePositionUpdated(const QGeoPositionInfo &info);

};

@@ -55,6 +55,7 @@ class MainWidget : public QTabWidget

public:
explicit MainWidget(QWidget *parent = 0);
~MainWidget();

signals:

@@ -10,6 +10,7 @@
#define REMEMBER "remember"
#define SERVER_URL "server_url"
#define AUTH_TOKEN "auth_token"
#define DESCRIPTION "description"

class Settings
{
@@ -31,6 +32,8 @@ class Settings
QString getAuthToken();
void setAuthToken(const QString& password);

QString getDescription();
void setDescription(const QString& description);
QString getServerUrl();
void setServerUrl(const QString& serverUrl);

@@ -4,6 +4,7 @@
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QTextEdit>
#include "Settings.h"

class SettingsWidget : public QWidget
@@ -13,6 +14,7 @@ class SettingsWidget : public QWidget
Settings m_settings;

// GUI
QTextEdit *m_description;
QLineEdit *m_serverUrlEdit;
QPushButton *m_okButton;
QPushButton *m_cancelButton;
@@ -10,8 +10,10 @@
#define DEFAULT_LOCATION_TIMEOUT 10
#define EVENTS_CHANNEL "Events"
#define EVENTS_RADIUS 30
#define DEFAULT_EVENTS_PERIOD 15
#define RELEVANT_PERIOD_IN_HOURS 240
#define NOT_RECEIVE_OWN_EVENTS true
#define DEFAULT_SOS_PERIOD 10

#define SUBSCRIBE_HTTP_URL "/service/subscribe"
#define UNSUBSCRIBE_HTTP_URL QString(DEFAULT_URL)+QString("service/unsubscribe")
@@ -41,16 +41,17 @@
EventsService::EventsService(LocationManager *locationManager, QObject *parent) :
QObject(parent),
m_locationManager(locationManager),
m_filterCircleQuery(0)
m_filterCircleQuery(0),
m_mediaPlayer(0)
{
m_mediaPlayer = new QMediaPlayer(this);
m_mediaPlayer->setMedia(QUrl::fromLocalFile(":/data/siren.wav"));
m_mediaPlayer->setVolume(50);
}

EventsService::~EventsService()
{
//delete m_mediaPlayer;
if (m_mediaPlayer) {
m_mediaPlayer->stop();
m_mediaPlayer->deleteLater();
}
}

void EventsService::startService(QString name, QString password, QString authToken, QString serverUrl)
@@ -94,7 +95,7 @@ void EventsService::requestEvents()
m_filterCircleQuery->doRequest();
} else {
qDebug() << "invalid geo info, waitin and trying again";
QTimer::singleShot(5 * 1000, this, SLOT(requestEvents()));
QTimer::singleShot(DEFAULT_EVENTS_PERIOD * 1000, this, SLOT(requestEvents()));
}
}

@@ -141,9 +142,16 @@ void EventsService::onTagsReceived()
}
if (newEvents) {
// play alert
m_mediaPlayer->stop();
if (m_mediaPlayer) {
m_mediaPlayer->stop();
m_mediaPlayer->deleteLater();
}
qDebug() << "start player";
using namespace Phonon;
#ifdef Q_OS_SYMBIAN
m_mediaPlayer = createPlayer(MusicCategory, MediaSource(":/data/siren.wav"));
m_mediaPlayer->play();
#endif
qDebug() << "player finished";
}
if (newEvents || expiredEvents) {
@@ -152,12 +160,12 @@ void EventsService::onTagsReceived()
}
}

QTimer::singleShot(5 * 1000, this, SLOT(requestEvents()));
QTimer::singleShot(DEFAULT_EVENTS_PERIOD * 1000, this, SLOT(requestEvents()));
}

void EventsService::onError(QString error)
{
qDebug() << "EventsService::onErrorOccured error: " << error;
emit errorOccured(error);
QTimer::singleShot(5 * 1000, this, SLOT(requestEvents()));
QTimer::singleShot(DEFAULT_EVENTS_PERIOD * 1000, this, SLOT(requestEvents()));
}
@@ -116,7 +116,11 @@ void EventsWidget::onMapWidgetClicked(QPointF pos)
(pos.y() > (center.y() - delta)) &&
(pos.y() < (center.y() + delta)))
{
QMessageBox::information(this, "SOS message", m_events[i]->getDescription());
QString message = QString("%1 (%2):\n%3")
.arg(m_events[i]->getUser()->getLogin(),
m_events[i]->getTime().toLocalTime().toString(),
m_events[i]->getDescription());
QMessageBox::information(this, "SOS message", message);
break;
}
}
@@ -1,34 +1,69 @@
#include "inc/LocationManager.h"
#include <QDebug>
#include <QStringList>
#include "defines.h"

LocationManager::LocationManager(QObject *parent) :
QObject(parent)
{
m_source = QGeoPositionInfoSource::createDefaultSource(this);
if (m_source) {
connect(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(positionUpdated(QGeoPositionInfo)));
m_source->setUpdateInterval(DEFAULT_LOCATION_TIMEOUT * 1000);
m_source->startUpdates();
m_satelliteSource = QGeoPositionInfoSource::createDefaultSource(this);
qDebug() << "satellite source: " << m_satelliteSource;
if (m_satelliteSource) {
connect(m_satelliteSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(satellitePositionUpdated(QGeoPositionInfo)));
m_satelliteSource->setPreferredPositioningMethods(
QGeoPositionInfoSource::SatellitePositioningMethods);
m_satelliteSource->startUpdates();
} else {
qDebug() << "Can't get geo source";
qDebug() << "Can't get satellite source";
}

m_nonSatelliteSource = QGeoPositionInfoSource::createDefaultSource(this);
qDebug() << "non satellite source: " << m_nonSatelliteSource;
if (m_nonSatelliteSource) {
connect(m_nonSatelliteSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(nonSatellitePositionUpdated(QGeoPositionInfo)));
m_nonSatelliteSource->setPreferredPositioningMethods(
QGeoPositionInfoSource::NonSatellitePositioningMethods);
m_nonSatelliteSource->startUpdates();
} else {
qDebug() << "Can't get non satellite source";
}

}

QGeoPositionInfo LocationManager::getInfo()
{
m_infoMutex.lock();
QGeoPositionInfo info = m_info;
QGeoPositionInfo info;
if (m_satelliteInfo.isValid() && !m_nonSatelliteInfo.isValid()) {
info = m_satelliteInfo;
} else if (!m_satelliteInfo.isValid() && m_nonSatelliteInfo.isValid()) {
info = m_nonSatelliteInfo;
} else if (m_satelliteInfo.isValid() && m_nonSatelliteInfo.isValid()) {
if (m_satelliteInfo.timestamp() >= m_nonSatelliteInfo.timestamp().addSecs(-60)) {
info = m_satelliteInfo;
} else {
info = m_nonSatelliteInfo;
}
}
m_infoMutex.unlock();
return info;
}

void LocationManager::positionUpdated(const QtMobility::QGeoPositionInfo &info)
void LocationManager::satellitePositionUpdated(const QtMobility::QGeoPositionInfo &info)
{
m_infoMutex.lock();
m_satelliteInfo = info;
//qDebug() << "Satellite position updated:" << m_satelliteInfo;
m_infoMutex.unlock();
}

void LocationManager::nonSatellitePositionUpdated(const QtMobility::QGeoPositionInfo &info)
{
m_infoMutex.lock();
m_info = info;
qDebug() << "Position updated:" << m_info;
m_nonSatelliteInfo = info;
//qDebug() << "Non satellite position updated:" << m_nonSatelliteInfo;
m_infoMutex.unlock();
}

@@ -14,6 +14,14 @@ MainWidget::MainWidget(QWidget *parent) :
initGUI();
}

MainWidget::~MainWidget()
{
qDebug() << "Stoping other threads";
m_eventsWidget->stopEventsService();
m_trackingWidget->stopTracking();
qDebug() << "stoped";
}

void MainWidget::initGUI()
{
this->addTab(m_sosWidget, "SOS");
@@ -70,3 +70,13 @@ void Settings::setServerUrl(const QString &serverUrl)
{
m_settings.setValue(SERVER_URL, serverUrl);
}

QString Settings::getDescription()
{
return m_settings.value(DESCRIPTION, "").toString();
}

void Settings::setDescription(const QString &description)
{
m_settings.setValue(DESCRIPTION, description);
}
@@ -6,6 +6,7 @@
SettingsWidget::SettingsWidget(QWidget *parent) :
QWidget(parent)
{
m_description = new QTextEdit(this);
m_serverUrlEdit = new QLineEdit(this);
m_okButton = new QPushButton("Ok", this);
m_cancelButton = new QPushButton("Cancel", this);
@@ -21,6 +22,9 @@ SettingsWidget::SettingsWidget(QWidget *parent) :
void SettingsWidget::initGUI()
{
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addWidget(new QLabel("User description:", this));
//m_description->setMinimumHeight();
mainLayout->addWidget(m_description);
mainLayout->addWidget(new QLabel("Server URL", this));
mainLayout->addWidget(m_serverUrlEdit);
QHBoxLayout *btnsLayout = new QHBoxLayout();
@@ -33,11 +37,13 @@ void SettingsWidget::initGUI()

void SettingsWidget::fill()
{
m_description->setText(m_settings.getDescription());
m_serverUrlEdit->setText(m_settings.getServerUrl());
}

void SettingsWidget::onOkClicked()
{
m_settings.setDescription(m_description->toPlainText());
m_settings.setServerUrl(m_serverUrlEdit->text());
emit saved();
}
@@ -70,8 +70,11 @@ void SosWidget::sos()
{
qDebug() << "sos clicked";
QSharedPointer<DataMark> sosMark;
QString description = m_settings.getDescription();
if (description.isEmpty())
description = "no description";
sosMark = QSharedPointer<DataMark>(
new DataMark(0, 0, 0, "SOS", "SOS", "", QDateTime::currentDateTime()));
new DataMark(0, 0, 0, "SOS", description, "", QDateTime::currentDateTime()));

QGeoPositionInfo info = m_locationManager->getInfo();
if (info.isValid()) {
@@ -91,7 +94,7 @@ void SosWidget::sos()
m_writeSosQuery->doRequest();
} else {
qDebug() << "invalid geo info, waiting and trying again";
QTimer::singleShot(3 * 1000, this, SLOT(sos()));
QTimer::singleShot(DEFAULT_SOS_PERIOD * 1000, this, SLOT(sos()));
}
}

@@ -105,7 +108,7 @@ void SosWidget::onError(QString error)
{
qDebug() << "error occured during sos, error: " << error;
// TODO: add to SOS status!
QTimer::singleShot(3 * 1000, this, SLOT(sos()));
QTimer::singleShot(DEFAULT_SOS_PERIOD * 1000, this, SLOT(sos()));
}


@@ -54,7 +54,7 @@ void TrackingService::startTracking(QString name, QString password, QString auth
m_writeTagQuery = new WriteTagQuery(this);
m_writeTagQuery->setTag(m_dataMark);
connect(m_writeTagQuery, SIGNAL(tagAdded()), this, SLOT(onMarkSent()));
connect(m_writeTagQuery, SIGNAL(errorOccured(int)), this, SLOT(onErrorOccured(int)));
connect(m_writeTagQuery, SIGNAL(errorOccured(QString)), this, SLOT(onError(QString)));

m_user = QSharedPointer<JsonUser>(new JsonUser(name, password, authToken));
m_channel = QSharedPointer<Channel>(new Channel(name, name + "'s channel", ""));
@@ -16,6 +16,7 @@ int main(int argc, char *argv[])
#endif

QApplication app(argc, argv);
app.setApplicationName("GeoDoctorSearch");

QFile file(":/data/SliderStyleSheet.qss");
if (!file.open(QFile::ReadOnly)) {
@@ -46,7 +46,8 @@ HEADERS += \
inc/FShapePolygon.h \
inc/FShapeRectangle.h \
inc/Region.h \
inc/signals.h
inc/signals.h \
inc/SettingsStorage.h

SOURCES += \
src/TimeSlot.cpp \
@@ -64,7 +65,8 @@ SOURCES += \
src/FShapePolygon.cpp \
src/FShapeRectangle.cpp \
src/Region.cpp \
src/signals.cpp
src/signals.cpp \
src/SettingsStorage.cpp

linux: {
HEADERS += inc/GpsModeller.h
@@ -1,3 +1,18 @@
[Mail_Settings]
subject=Geo2tag Registration Confirmation
body=Hello new user!
body=Hello new user!

[General_Settings]
server_url=http://tracks.osll.spb.ru:81/
server_port=81
geo2tag_version=0.16
database_name=geo2tag
config_file=/usr/share/wikigps/wikigps.conf

[Registration_Settings]
tmp_user_timelife=2 days

[Tracker_Settings]
tracker_tag_label=tracker's tag
tracker_msecs_timeout=500

File renamed without changes.
@@ -47,15 +47,12 @@ QString getServerUrl();
void setServerUrl(QString serverUrl);
int getServerPort();
void setServerPort(int port);
#define DEFAULT_SERVER "http://tracks.osll.spb.ru:81/"
#define DEFAULT_PORT 81

// "demo"
#define SETTINGS_STORAGE_FILENAME "/opt/geo2tag/geo2tag.conf"

#define GEO2TAG_VERSION "0.16"

#define DATABASE_NAME "geo2tag"
//#define GEO2TAG_VERSION "0.16"
//#define DATABASE_NAME "geo2tag"

#define SUBSCRIBE_HTTP_URL getServerUrl()+QString("service/subscribe")
#define UNSUBSCRIBE_HTTP_URL getServerUrl()+QString("service/unsubscribe")
@@ -70,26 +67,28 @@ void setServerPort(int port);
#define VERSION_HTTP_URL getServerUrl()+QString("service/version")

#define GPS_MODELLER_FILE "/usr/share/wikigps/helsinki.gpx"
#define CONFIG_FILE "/usr/share/wikigps/wikigps.conf"
//#define CONFIG_FILE "/usr/share/wikigps/wikigps.conf"

// Default values
#define DEFAULT_SERVER "http://tracks.osll.spb.ru:81/"
#define DEFAULT_PORT 81

#define DEFAULT_RADIUS 30
#define DEFAULT_USER_NAME "Mark"
#define DEFAULT_USER_PASSWORD "test"
#define DEFAULT_CHANNEL "default"
#define DEFAULT_CHANNEL "default"
#define DEFAULT_TOKEN "2154086390Ivan1128557755"

#define DEFAULT_TMP_USER_TIMELIFE "2 days"

#define TRACKER_TAG_LABEL "tracker's tag"
#define DEFAULT_TMP_USER_TIMELIFE "2 days"

#define DEFAULT_LATITUDE ((double) 59.91446)
#define DEFAULT_LONGITUDE ((double) 30.489442)

#define TRACKER_MSECS_TIMEOUT 500
//#define TRACKER_TAG_LABEL "tracker's tag"
//#define TRACKER_MSECS_TIMEOUT 500

// for email settings
#define DEFAULT_EMAIL_SUBJECT "Registration confirmation"
#define DEFAULT_EMAIL_BODY "This will go into the body of the mail."
#define DEFAULT_EMAIL_SUBJECT "Registration confirmation"
#define DEFAULT_EMAIL_BODY "This will go into the body of the mail."

#ifndef Q_WS_SYMBIAN
extern uint qHash(const QPoint & p);
@@ -74,3 +74,4 @@ QVariant SettingsStorage::getValue(const QString &key, const QVariant &defaultVa
SettingsStorage::~SettingsStorage()
{
}

@@ -1,22 +1,14 @@
#include <QSettings>
#include <QDebug>
#include "defines.h"
#include "SettingsStorage.h"


QString getServerUrl()
{
QSettings settings(QSettings::SystemScope,"osll","libs");
if (settings.value("server_url").toString().isEmpty())
{
return DEFAULT_SERVER;
}

QString serverUrl=settings.value("server_url").toString();
SettingsStorage storage(SETTINGS_STORAGE_FILENAME);

if(serverUrl == "")
{
serverUrl = DEFAULT_SERVER;
setServerUrl(serverUrl);
}
QString serverUrl = storage.getValue("General_Settings/server_url", QVariant(DEFAULT_SERVER)).toString();

return serverUrl;
}
@@ -31,13 +23,9 @@ void setServerUrl(QString serverUrl)

int getServerPort()
{
QSettings settings(QSettings::SystemScope,"osll","libs");
if (settings.value("server_port").toInt()==0)
{
return DEFAULT_PORT;
}
int serverPort = DEFAULT_PORT;
setServerPort(serverPort);
SettingsStorage storage(SETTINGS_STORAGE_FILENAME);

int serverPort = storage.getValue("General_Settings/server_port", QVariant(DEFAULT_PORT)).toInt();

return serverPort;
}
@@ -37,6 +37,20 @@

#include "LoginRequestJSON.h"

typedef LoginRequestJSON AddUserRequestJSON;
//typedef LoginRequestJSON AddUserRequestJSON;

class AddUserRequestJSON : public JsonSerializer
{
public:
AddUserRequestJSON(QObject *parent=0);

QByteArray getJson() const;

bool parseJson(const QByteArray&);
};




// ADDUSERREQUESTJSON_H
#endif
@@ -0,0 +1,66 @@
/*
* Copyright 2012 bac1ca bac1ca89@gmail.com
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/

/*! ---------------------------------------------------------------
* \file FilterChannelRequestJSON.h
* \brief Header of FilterChannelRequestJSON
* \todo add comment here
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */


#ifndef _FilterChannelRequestJSON_H_796EB5EC_74E0_4EA2_A43C_7F6F850122D5_INCLUDED_
#define _FilterChannelRequestJSON_H_796EB5EC_74E0_4EA2_A43C_7F6F850122D5_INCLUDED_

#include "JsonSerializer.h"

class FilterChannelRequestJSON: public JsonSerializer
{
private:
QString m_channel;
int m_amount;

public:
FilterChannelRequestJSON(QObject *parent = 0);

QByteArray getJson() const;

bool parseJson(const QByteArray&);

QString getChannelName();

int getAmount();
};

#endif //_FilterChannelRequestJSON_H_796EB5EC_74E0_4EA2_A43C_7F6F850122D5_INCLUDED_
@@ -0,0 +1,64 @@
/*
* Copyright 2012 bac1ca bac1ca89@gmail.com
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/

/*! ---------------------------------------------------------------
* \file FilterChannelResponseJSON.h
* \brief Header of FilterChannelResponseJSON
* \todo add comment here
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */


#ifndef _FilterChannelResponseJSON_H_D06843F4_D6CB_4B9E_B538_74F7B2E8D42A_INCLUDED_
#define _FilterChannelResponseJSON_H_D06843F4_D6CB_4B9E_B538_74F7B2E8D42A_INCLUDED_

#include "JsonSerializer.h"

class FilterChannelResponseJSON: public JsonSerializer
{
private:
QList<QSharedPointer<DataMark> > m_tags;
QSharedPointer<Channel> m_channel;

public:
FilterChannelResponseJSON(QObject *parent = 0);

QByteArray getJson() const;

bool parseJson(const QByteArray&);

void setData(QSharedPointer<Channel> channel, QList<QSharedPointer<DataMark> > tags);
};

#endif //_FilterChannelResponseJSON_H_D06843F4_D6CB_4B9E_B538_74F7B2E8D42A_INCLUDED_
@@ -59,7 +59,9 @@ HEADERS += \
inc/RegisterUserRequestJSON.h \
inc/RegisterUserResponseJSON.h \
inc/ErrnoInfoResponseJSON.h \
inc/VersionResponseJSON.h
inc/VersionResponseJSON.h \
inc/FilterChannelRequestJSON.h \
inc/FilterChannelResponseJSON.h

SOURCES += \
src/AvailableChannelsResponseJSON.cpp \
@@ -95,7 +97,11 @@ SOURCES += \
src/RegisterUserRequestJSON.cpp \
src/RegisterUserResponseJSON.cpp \
src/ErrnoInfoResponseJSON.cpp \
src/VersionResponseJSON.cpp
src/VersionResponseJSON.cpp \
src/AddUserRequestJSON.cpp \
src/FilterChannelRequestJSON.cpp \
src/FilterChannelResponseJSON.cpp


LIBS += -lcommon -lqjson

@@ -0,0 +1,74 @@
/*
* Copyright 2010-2012 OSLL osll@osll.spb.ru
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/
/*----------------------------------------------------------------- !
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#include "AddUserRequestJSON.h"
#include "JsonUser.h"

#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_SIMULATOR)
#include <qjson/parser.h>
#include <qjson/serializer.h>
#else
#include "parser.h"
#include "serializer.h"
#endif

AddUserRequestJSON::AddUserRequestJSON(QObject *parent) : JsonSerializer(parent)
{
}

QByteArray AddUserRequestJSON::getJson() const
{
QJson::Serializer serializer;
QVariantMap obj;
obj.insert("email", m_usersContainer->at(0)->getEmail());
obj.insert("login", m_usersContainer->at(0)->getLogin());
obj.insert("password", m_usersContainer->at(0)->getPassword());
return serializer.serialize(obj);
}

bool AddUserRequestJSON::parseJson(const QByteArray &data)
{
clearContainers();

QJson::Parser parser;
bool ok;
QVariantMap result = parser.parse(data, &ok).toMap();
if (!ok) return false;

QString email = result["email"].toString();
QString login = result["login"].toString();
QString password = result["password"].toString();
m_usersContainer->push_back(QSharedPointer<common::User>(new JsonUser(login, password, "unknown",email)));
return true;
}
@@ -0,0 +1,91 @@
/*
* Copyright 2012 bac1ca bac1ca89@gmail.com
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/

/*! ---------------------------------------------------------------
*
* \file FilterChannelRequestJSON.cpp
* \brief FilterChannelRequestJSON implementation
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#include "FilterChannelRequestJSON.h"

#include "JsonUser.h"

#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_SIMULATOR)
#include <qjson/parser.h>
#include <qjson/serializer.h>
#else
#include "parser.h"
#include "serializer.h"
#endif

FilterChannelRequestJSON::FilterChannelRequestJSON(QObject *parent) : JsonSerializer(parent)
{
}


QByteArray FilterChannelRequestJSON::getJson() const
{
// TODO TBD
return NULL;
}


bool FilterChannelRequestJSON::parseJson(const QByteArray&data)
{
clearContainers();

QJson::Parser parser;
bool ok;
QVariantMap result = parser.parse(data, &ok).toMap();
if (!ok) return false;

QString authToken = result["auth_token"].toString();
m_usersContainer->push_back(QSharedPointer<common::User>(new JsonUser("none", "none", authToken)));

m_channel = result["channel"].toString();
m_amount = result["amount"].toInt(&ok);
return ok;
}

QString FilterChannelRequestJSON::getChannelName()
{
return m_channel;
}

int FilterChannelRequestJSON::getAmount()
{
return m_amount;
}
@@ -0,0 +1,103 @@
/*
* Copyright 2012 bac1ca bac1ca89@gmail.com
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* The advertising clause requiring mention in adverts must never be included.
*/

/*! ---------------------------------------------------------------
*
* \file FilterChannelResponseJSON.cpp
* \brief FilterChannelResponseJSON implementation
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#include "FilterChannelResponseJSON.h"

#include "JsonUser.h"

#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_SIMULATOR)
#include <qjson/parser.h>
#include <qjson/serializer.h>
#else
#include "parser.h"
#include "serializer.h"
#endif

FilterChannelResponseJSON::FilterChannelResponseJSON(QObject *parent) : JsonSerializer(parent)
{
}


QByteArray FilterChannelResponseJSON::getJson() const
{
QJson::Serializer serializer;
QVariantMap obj;

QVariantList jtags;
QVariantMap jchannel;
QVariantMap channel;

for(int i = 0; i < m_tags.size(); i++)
{
QSharedPointer<DataMark> tag = m_tags.at(i);
QVariantMap jtag;
jtag["id"] = tag->getId();
jtag["title"] = tag->getLabel();
jtag["link"] = tag->getUrl();
jtag["description"] = tag->getDescription();
jtag["latitude"] = tag->getLatitude();
jtag["longitude"] = tag->getLongitude();
jtag["altitude"] = tag->getAltitude();
jtag["user"] = tag->getUser()->getLogin();
jtag["pubDate"] = tag->getTime().toString("dd MM yyyy HH:mm:ss.zzz");
jtags.append(jtag);
}
channel["items"] = jtags;
channel["name"] = m_channel.isNull() ? "" : m_channel->getName();

obj["channel"] = channel;
obj["errno"] = getErrno();
return serializer.serialize(obj);
}


bool FilterChannelResponseJSON::parseJson(const QByteArray&)
{
// TODO TBD
return false;
}

void FilterChannelResponseJSON::setData(QSharedPointer<Channel> channel,
QList<QSharedPointer<DataMark> > tags)
{
m_channel = channel;
m_tags = tags;
}
@@ -126,6 +126,7 @@ bool FilterDefaultResponseJSON::parseJson(const QByteArray& data)
QString userName = markMap["user"].toString();
QString timeStr = markMap["pubDate"].toString();
QDateTime time = QDateTime::fromString(timeStr, "dd MM yyyy HH:mm:ss.zzz");
time.setTimeSpec(Qt::UTC);

QVector<QSharedPointer<common::User> > v = m_usersContainer->vector();
QSharedPointer<common::User> user(new JsonUser(userName));
@@ -46,7 +46,6 @@
#include <QtSql>
#include <QThread>
#include <QMap>
#include <QSettings>
//#include </usr/include/qt4/QtSql/qsql_psql.h>
#include "DataMarks.h"
#include "Channel.h"
@@ -114,6 +113,8 @@ namespace common
QByteArray processFilterRectangleQuery(const QByteArray&);
QByteArray processFilterBoxQuery(const QByteArray&);
QByteArray processFilterFenceQuery(const QByteArray&);
QByteArray processFilterChannelQuery(const QByteArray&);


// void processSendConfirmationLetter(const QString &address);

@@ -53,8 +53,7 @@ HEADERS += \
inc/DbSession.h \
inc/UpdateThread.h \
inc/QueryExecutor.h \
inc/TimeSlotInternal.h \
inc/SettingsStorage.h
inc/TimeSlotInternal.h


SOURCES += src/main.cpp \
@@ -66,8 +65,7 @@ SOURCES += src/main.cpp \
src/DbSession.cpp \
src/UpdateThread.cpp \
src/QueryExecutor.cpp \
src/TimeSlotInternal.cpp \
src/SettingsStorage.cpp
src/TimeSlotInternal.cpp

LIBS += -lcommon -lfcgi -lwikigpsJson -lpq
OBJECTS_DIR = .obj
@@ -42,6 +42,7 @@
#include <syslog.h>
#include <stdlib.h>
#include "defines.h"
#include "SettingsStorage.h"
#include "DbSession.h"

#include "LoginRequestJSON.h"
@@ -106,6 +107,9 @@
#include "FilterBoxRequestJSON.h"
#include "FilterFenceRequestJSON.h"

#include "FilterChannelRequestJSON.h"
#include "FilterChannelResponseJSON.h"

#include "ErrnoInfoResponseJSON.h"

#include "VersionResponseJSON.h"
@@ -158,6 +162,7 @@ namespace common
m_processors.insert("filterRectangle", &DbObjectsCollection::processFilterRectangleQuery);
m_processors.insert("filterBox", &DbObjectsCollection::processFilterBoxQuery);
m_processors.insert("filterFence", &DbObjectsCollection::processFilterFenceQuery);
m_processors.insert("filterChannel", &DbObjectsCollection::processFilterChannelQuery);
// Here also should be something like
// m_processors.insert("confirmRegistration-*", &DbObjectsCollection::processFilterFenceQuery);

@@ -605,6 +610,7 @@ namespace common
// Look for user with the same name
QSharedPointer<User> dummyUser = request.getUsers()->at(0);
QVector<QSharedPointer<User> > currentUsers = m_usersContainer->vector();

for(int i=0; i<currentUsers.size(); i++)
{
if(currentUsers.at(i)->getLogin() == dummyUser->getLogin())
@@ -616,6 +622,12 @@ namespace common
}
}

if(m_queryExecutor->doesUserWithGivenEmailExist(dummyUser)) {
response.setErrno(EMAIL_ALREADY_EXIST_ERROR);
answer.append(response.getJson());
return answer;
}

syslog(LOG_INFO, "Sending sql request for AddUser");
QSharedPointer<User> addedUser = m_queryExecutor->insertNewUser(dummyUser);
if(!addedUser)
@@ -1373,8 +1385,64 @@ namespace common
VersionResponseJSON response;
QByteArray answer("Status: 200 OK\r\nContent-Type: text/html\r\n\r\n");

SettingsStorage storage(SETTINGS_STORAGE_FILENAME);
QString version = storage.getValue("General_Settings/geo2tag_version").toString();

response.setErrno(SUCCESS);
response.setVersion(version);
answer.append(response.getJson());
syslog(LOG_INFO, "answer: %s", answer.data());
return answer;
}

QByteArray DbObjectsCollection::processFilterChannelQuery(const QByteArray& data)
{
FilterChannelRequestJSON request;
FilterChannelResponseJSON response;
QByteArray answer("Status: 200 OK\r\nContent-Type: text/html\r\n\r\n");

if (!request.parseJson(data))
{
response.setErrno(INCORRECT_JSON_ERROR);
answer.append(response.getJson());
return answer;
}
syslog(LOG_INFO, "point_1");

QSharedPointer<User> dummyUser = request.getUsers()->at(0);
QSharedPointer<User> realUser = findUserFromToken(dummyUser);
syslog(LOG_INFO, "point_2");
if(realUser.isNull())
{
syslog(LOG_INFO, "point_3");

response.setErrno(WRONG_TOKEN_ERROR);
answer.append(response.getJson());
return answer;
}
syslog(LOG_INFO, "point_4");

QSharedPointer<Channels> channels = realUser->getSubscribedChannels();
QSharedPointer<Channel> channel;
for(int i = 0; i<channels->size(); i++)
{
if (channels->at(i)->getName() == request.getChannelName()){
channel = channels->at(i);
break;
}
}
if (channel.isNull()){
response.setErrno(CHANNEL_DOES_NOT_EXIST_ERROR);
answer.append(response.getJson());
return answer;
}

QList<QSharedPointer<DataMark> > tags = m_dataChannelsMap->values(channel);
int amount = request.getAmount();
tags = tags.count() > amount ? tags.mid(0, amount) : tags;

response.setData(channel, tags);
response.setErrno(SUCCESS);
response.setVersion(GEO2TAG_VERSION);
answer.append(response.getJson());
syslog(LOG_INFO, "answer: %s", answer.data());
return answer;
@@ -333,8 +333,12 @@ void UpdateThread::checkTmpUsers()

// Deleting old signups
QString strQuery;

SettingsStorage storage(SETTINGS_STORAGE_FILENAME);
QString timelife = storage.getValue("Registration_Settings/tmp_user_timelife", QVariant(DEFAULT_TMP_USER_TIMELIFE)).toString();

strQuery.append("select id from signups where (now() - datetime) >= INTERVAL '");
strQuery.append(DEFAULT_TMP_USER_TIMELIFE);
strQuery.append(timelife);
strQuery.append("';");
checkQuery.exec(strQuery.toStdString().c_str());
while (checkQuery.next()) {
@@ -24,6 +24,7 @@ MarksHistory_TestObj.h \
../../../../common/inc/Channel.h \
../../../../common/inc/ConcurrentVector.h \
../../../../common/inc/defines.h \
../../../../common/inc/SettingsStorage.h \
../../../../common/inc/DataChannel.h

SOURCES += main.cpp \
@@ -33,6 +34,7 @@ SOURCES += main.cpp \
../../../../common/src/DataMarks.cpp \
../../../../common/src/Channel.cpp \
../../../../common/src/defines.cpp \
../../../../common/src/SettingsStorage.cpp \
../../../../json/src/JsonSerializer.cpp \
../../../../json/src/JsonUser.cpp \
../../../../json/src/JsonDataMark.cpp \
@@ -50,6 +50,7 @@
#endif

#include "defines.h"
#include "SettingsStorage.h"

#define DAEMON_PORT 34243

@@ -108,8 +109,11 @@ void TrackerDaemon::run()

qDebug() << "Read from QSettings " << login << " ,"<< password << " ," <<m_channelName;

SettingsStorage storage(SETTINGS_STORAGE_FILENAME);
QString tracker_tag_label = storage.getValue("Tracker_Settings/tracker_tag_label").toString();

if(m_visibleName.isEmpty())
m_visibleName = TRACKER_TAG_LABEL;
m_visibleName = tracker_tag_label;

if(login.isEmpty())
login = DEFAULT_USER_NAME;