@@ -0,0 +1,115 @@
/*
* Copyright 2010-2011 Vasily Romanikhin 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.
*/

/*! ---------------------------------------------------------------
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

package ru.spb.osll.GDS;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

public class LocationService extends Service {

public static String LOG = "GDS-LocationService";

private LocationManager myLocationManager;

@Override
public void onCreate() {
super.onCreate();
Log.v(LOG, "location service create");

myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}

@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Log.v(LOG, "location service start");
}

@Override
public void onDestroy() {
super.onDestroy();
Log.v(LOG, "location service destroy");
myLocationManager.removeUpdates(locationListener);
}

@Override
public IBinder onBind(Intent intent) {
return null;
}

private LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
if (location != null){
Log.v(LOG, "onLocationChanged " + location.toString());
}
}

public void onStatusChanged(String provider, int status, Bundle extras) {
Log.v(LOG, "onStatusChanged " + provider + " " + status + " " + extras);
}

public void onProviderEnabled(String provider) {
//Log.v(TrackerActivity.LOG, "onProviderEnabled " + provider);
}

public void onProviderDisabled(String provider) {
//Log.v(TrackerActivity.LOG, "onProviderDisabled " + provider);
}
};

public static Location getLocation(Context context) {
Location location = null;
String provider = LocationManager.NETWORK_PROVIDER;
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

if (locationManager != null) {
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
provider = LocationManager.GPS_PROVIDER;
}
location = locationManager.getLastKnownLocation(provider);
}
return location;
}

}
@@ -44,7 +44,6 @@
import ru.spb.osll.json.IRequest.IResponse;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
@@ -60,6 +59,8 @@ public class LoginActivity extends Activity {
public static final int SETTINGS_ID = Menu.FIRST;

public static final String AUTH_TOKEN = "auth_token";
public static final String LOGIN = "login";
public static final String CHANNEL = "channel";

private EditText m_loginEdit;
private EditText m_passwordEdit;
@@ -93,11 +94,14 @@ protected void onDestroy() {
@Override
protected void onPause() {
super.onPause();
Log.v(IGDSSettings.LOG, "LoginActivity onPause");
}

@Override
protected void onResume() {
super.onResume();
Log.v(IGDSSettings.LOG, "LoginActivity onResume");
initViews();
}

@Override
@@ -119,10 +123,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

private void initViews() {
final SharedPreferences settings = new Settings(this).getPreferences();
m_loginEdit.setText(settings.getString(IGDSSettings.LOGIN, "?????"));
m_passwordEdit.setText(settings.getString(IGDSSettings.PASSWORD, "?????"));
m_rememberCheck.setChecked(settings.getBoolean(IGDSSettings.REMEMBER, false));
Settings settings = new Settings(this);
if (settings.isRememberMe()) {
m_loginEdit.setText(settings.getLogin());
m_passwordEdit.setText(settings.getPassword());
m_rememberCheck.setChecked(true);
} else {
m_loginEdit.setText("");
m_passwordEdit.setText("");
m_rememberCheck.setChecked(false);
}
}

private void initButtons() {
@@ -148,12 +158,15 @@ private void signIn() {

String login = m_loginEdit.getText().toString();
String password = m_passwordEdit.getText().toString();
String serverUrl = new Settings(this).getPreferences().getString(
IGDSSettings.SERVER_URL, "");
String channel = login;
Settings settings = new Settings(this);
String serverUrl = settings.getServerUrl();
//String serverUrl = new Settings(this).getPreferences().getString(
// IGDSSettings.SERVER_URL, "");
String authToken = "";

JSONObject JSONResponse = null;
for(int i = 0; i < IGDSSettings.ATTEMPTS; i++){
for(int i = 0; i < 1; i++){
JSONResponse = new JsonLoginRequest(login, password, serverUrl).doRequest();
if (JSONResponse != null)
break;
@@ -176,12 +189,18 @@ private void signIn() {
return;
}

// If remember checkbox is checked then save login and password
// else save them as empty
// TODO
if (m_rememberCheck.isChecked()) {
settings.setLogin(m_loginEdit.getText().toString());
settings.setPassword(m_passwordEdit.getText().toString());
settings.setRememberMe(true);
} else {
settings.setRememberMe(false);
}

Intent i = new Intent(this, MainActivity.class);
i.putExtra(AUTH_TOKEN, authToken);
i.putExtra(LOGIN, login);
i.putExtra(CHANNEL, channel);
startActivity(i);
}

@@ -31,63 +31,121 @@

package ru.spb.osll.GDS;

import java.util.Date;

import org.json.JSONObject;

import ru.spb.osll.GDS.exception.ExceptionHandler;
import ru.spb.osll.GDS.preferences.Settings;
import ru.spb.osll.GDS.preferences.SettingsActivity;
import ru.spb.osll.GDS.preferences.Settings.IGDSSettings;
import android.app.Activity;
import ru.spb.osll.GDS.tracking.TrackingManager;
import ru.spb.osll.GDS.tracking.TrackingReceiver;
import ru.spb.osll.GDS.utils.GDSUtil;
import ru.spb.osll.json.JsonApplyMarkRequest;
import ru.spb.osll.json.JsonBaseResponse;
import ru.spb.osll.json.IRequest.IResponse;
import android.app.ProgressDialog;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CheckBox;
import android.widget.EditText;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
public class MainActivity extends TabActivity {

public static final int SETTINGS_ID = Menu.FIRST;
public static final int SIGNOUT_ID = Menu.FIRST + 1;

public static final int INTERVAL = 7;

private Settings m_settings;
private String m_authToken = null;
private LocationManager m_locationManager;
private boolean m_isDeviceReady = false;
private Thread m_trackThread;
private String m_login = null;
private String m_channel = null;
private TabHost m_TabHost;
private TrackingManager m_trackingManager;
private Button m_trackingButton;
private TextView m_logView;
private TextView m_statusView;
private ProgressDialog m_progress;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
registerReceiver(m_trackingReceiver, new IntentFilter(TrackingReceiver.ACTION_TRACKING));

m_settings = new Settings(this);
Bundle extras = getIntent().getExtras();
if (extras != null) {
m_authToken = extras.getString(LoginActivity.AUTH_TOKEN);
m_login = extras.getString(LoginActivity.LOGIN);
m_channel = extras.getString(LoginActivity.CHANNEL);
}
if (m_authToken == null) {
Log.v(IGDSSettings.LOG, "problem with auth_token extracting");
if (m_authToken == null || m_login == null || m_channel == null) {
Log.v(IGDSSettings.LOG, "problem with extracting data");
Toast.makeText(this, "Can't sign in", Toast.LENGTH_LONG).show();
finish();
return;
}

m_locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
m_locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
getLocation();
m_TabHost = getTabHost();
m_TabHost.addTab(m_TabHost.newTabSpec("tab1").setIndicator("SOS").setContent(R.id.sos_tab));
((Button) findViewById(R.id.sos_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sos();
}
});

TabSpec tabSpec = m_TabHost.newTabSpec("tab2");
tabSpec.setIndicator("Map");
Context ctx = this.getApplicationContext();
Intent i = new Intent(ctx, MapTabActivity.class);
i.putExtra(LoginActivity.AUTH_TOKEN, m_authToken);
tabSpec.setContent(i);
m_TabHost.addTab(tabSpec);
m_TabHost.setCurrentTab(0);
m_TabHost.addTab(m_TabHost.newTabSpec("tab3").setIndicator("Tracking").setContent(R.id.tracking_tab));
m_trackingButton = (Button) findViewById(R.id.tracking_button);
m_trackingButton.setText("Start tracking");
m_trackingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MainActivity.this.changeTrackingMode();
}
});
m_logView = (TextView) findViewById(R.id.tracking_log);
m_statusView = (TextView) findViewById(R.id.tracking_status);
m_statusView.setText("Tracking stoped");

startService(new Intent(this, LocationService.class));
LocationService.getLocation(MainActivity.this);

m_trackingManager = new TrackingManager(m_authToken, m_channel);

}

@Override
protected void onDestroy() {
stopTracking();
stopService(new Intent(this, LocationService.class));
unregisterReceiver(m_trackingReceiver);
super.onDestroy();
}

@@ -122,6 +180,104 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

private void sos() {
m_progress = ProgressDialog.show(this, "SOS", "Sending SOS", true, false);
Thread thread = new Thread(new Thread() {
@Override
public void run() {
SystemClock.sleep(2 * 1000);
Log.v(IGDSSettings.LOG, "SOS thread started");
Location location = LocationService.getLocation(MainActivity.this);
while (location == null) {
Log.v(IGDSSettings.LOG, "can't get location, trying again...");
SystemClock.sleep(2 * 1000);
location = LocationService.getLocation(MainActivity.this);
}
Log.v(IGDSSettings.LOG, "location determined! sending location...");
String serverUrl = m_settings.getServerUrl();
JSONObject JSONResponse = null;
for(int i = 0; i < IGDSSettings.ATTEMPTS; i++){
JSONResponse = new JsonApplyMarkRequest(m_authToken, "Events", "SOS", "",
"SOS", location.getLatitude(), location.getLongitude(), 0,
GDSUtil.getTime(new Date()), serverUrl).doRequest();
if (JSONResponse != null)
break;
}
if (JSONResponse != null) {
int errno = JsonBaseResponse.parseErrno(JSONResponse);
if (errno == IResponse.geo2tagError.SUCCESS.ordinal()) {
Log.v(IGDSSettings.LOG, "Mark sent successfully");
//broadcastMarkSent(location);
} else {
//handleError(errno);
return;
}
} else {
Log.v(TrackingManager.LOG, "response failed");
//broadcastError("Failed to send location");
return;
}
m_handler.sendEmptyMessage(0);
}
});
thread.start();
}

private Handler m_handler = new Handler() {
@Override
public void handleMessage(Message msg) {
m_progress.dismiss();
Log.v(IGDSSettings.LOG, "SOS have been sent!");
Toast.makeText(MainActivity.this, "SOS have been sent!", Toast.LENGTH_LONG).show();
}
};

private TrackingReceiver m_trackingReceiver = new TrackingReceiver() {
@Override
public void onMarkSent(String lonlat) {
runOnUiThread(new Runnable() {
@Override
public void run() {
m_statusView.setText("Tracking started");
m_trackingButton.setText("Stop tracking");
}
});
appendToLogView("send mark: " + lonlat);
}
@Override
public void onErrorOccured(String error) {
runOnUiThread(new Runnable() {
@Override
public void run() {
checkTrackingMode();
}
});
appendToLogView(error);
}
};

private void changeTrackingMode() {
if (m_trackingManager.isTracking(this)) {
m_trackingManager.stopTracking(this);
m_statusView.setText("Tracking stoped");
m_trackingButton.setText("Start tracking");
} else {
m_trackingManager.startTracking(this);
m_statusView.setText("Starting tracking...");
m_trackingButton.setText("Stop tracking");
}
}

private void checkTrackingMode() {
if (m_trackingManager.isTracking(this)) {
m_statusView.setText("Tracking stoped");
m_trackingButton.setText("Start tracking");
} else {
m_trackingManager.startTracking(this);
m_trackingButton.setText("Stop tracking");
}
}

private void showSettings() {
Log.v(IGDSSettings.LOG, "opening settings");
startActivity(new Intent(this, SettingsActivity.class));
@@ -133,66 +289,34 @@ private void signOut() {

}

public Location getLocation() {
Location location = null;
String provider = LocationManager.NETWORK_PROVIDER;
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

if (locationManager != null) {
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
provider = LocationManager.GPS_PROVIDER;
}
location = locationManager.getLastKnownLocation(provider);
}
return location;
}

protected void onLocationDeviceStatusChanged(boolean isReady) {
Log.v(IGDSSettings.LOG, "onLocationDeviceStatusChanged: " + isReady);
if (isReady) {
startTracking();
} else {
stopTracking();

private static int lineCount = 0;
private static final int maxLines = 20;
public void appendToLogView(final String mess){
if (lineCount > maxLines){
clearLogView();
lineCount = 0;
}
appendToLogViewInternal(mess);
lineCount++;
}

private LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
if (!m_isDeviceReady && location != null){
m_isDeviceReady = true;
onLocationDeviceStatusChanged(true);
} else if (m_isDeviceReady && location == null) {
m_isDeviceReady = false;
onLocationDeviceStatusChanged(false);
private void appendToLogViewInternal(final String mess){
runOnUiThread(new Runnable() {
@Override
public void run() {
m_logView.append("\n" + mess);
}
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};

protected void stopTracking(){
if (m_trackThread != null){
m_trackThread.interrupt();
}
});
}

protected void startTracking(){
if (m_trackThread != null){
m_trackThread.interrupt();
}
m_trackThread = new Thread(new Runnable() {

private void clearLogView(){
runOnUiThread(new Runnable() {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()){
Location location = getLocation();
Log.v(IGDSSettings.LOG, "coords: " + location.getLatitude()
+ ", " + location.getLongitude());
SystemClock.sleep(INTERVAL * 1000);
}
m_logView.setText("");
}
});
m_trackThread.start();
}

}
@@ -0,0 +1,82 @@
package ru.spb.osll.GDS;

import ru.spb.osll.GDS.events.EventsManager;
import ru.spb.osll.GDS.events.EventsReceiver;
import ru.spb.osll.GDS.preferences.Settings.IGDSSettings;
import ru.spb.osll.objects.Mark;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class MapTabActivity extends MapActivity {

EventsManager m_eventsManager;
String m_authToken;
MapView m_mapView;

@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.map_tab_view);

Bundle extras = getIntent().getExtras();
if (extras != null) {
m_authToken = extras.getString(LoginActivity.AUTH_TOKEN);
}
if (m_authToken == null) {
Log.v(IGDSSettings.LOG, "problem with extracting data in MapTabActivity");
Toast.makeText(this, "Can't create events tab", Toast.LENGTH_LONG).show();
finish();
return;
}

registerReceiver(m_eventsReceiver, new IntentFilter(EventsReceiver.ACTION_EVENTS));

m_mapView = (MapView) findViewById(R.id.mapview);
m_mapView.setVisibility(View.GONE);
m_mapView.setBuiltInZoomControls(true);

m_eventsManager = new EventsManager();
m_eventsManager.setData(m_authToken);
m_eventsManager.startEventsService(this);
}

@Override
protected void onDestroy() {
super.onDestroy();
m_eventsManager.stopEventsService(this);
unregisterReceiver(m_eventsReceiver);
}

@Override
protected boolean isRouteDisplayed() {
return false;
}

private EventsReceiver m_eventsReceiver = new EventsReceiver() {
@Override
public void onEvents(final Mark[] marks) {
runOnUiThread(new Runnable() {
@Override
public void run() {
for (Mark mark : marks) {
Log.v(IGDSSettings.LOG, mark.toString());
}
}
});
}
@Override
public void onErrorOccured(String error) {
runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
}
};
}
@@ -0,0 +1,44 @@
package ru.spb.osll.GDS.events;

import ru.spb.osll.GDS.utils.GDSUtil;
import android.content.Context;
import android.content.Intent;

public class EventsManager {

public static final String LOG = "GDS_Events_service";
public static final String AUTH_TOKEN = "auth_token";
public static final String EVENTS_CHANNEL = "Events";
public static final int INTERVAL = 7;
public static final int RADIUS = 30;
public static final int RELEVANT_PERIOD_IN_HOURS = 240;

private String m_authToken;

public EventsManager() {
m_authToken = "";
}

public EventsManager(String authToken) {
m_authToken = authToken;
}

public void setData(String authToken) {
m_authToken = authToken;
}

public void startEventsService(Context c) {
Intent i = new Intent(c, EventsService.class);
i.putExtra(AUTH_TOKEN, m_authToken);
c.startService(i);
}

public void stopEventsService(Context c) {
c.stopService(new Intent(c, EventsService.class));
}

public boolean isEventsServieRunning(Context c) {
return GDSUtil.isServiceRunning(c, EventsService.class.getName());
}

}
@@ -0,0 +1,43 @@
package ru.spb.osll.GDS.events;

import ru.spb.osll.objects.Mark;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;

public abstract class EventsReceiver extends BroadcastReceiver {

public static final String ACTION_EVENTS = "osll.gds.events";

public static final String TYPE_OPERATION = "gds.type";
public static final int TYPE_ERROR = 0;
public static final int TYPE_EVENTS = 1;

public static final String ERROR = "type.error";
public static final String EVENTS = "type.events";
public static final String LONLAT = "type.lonlat";

@Override
public void onReceive(Context context, Intent intent) {
int type = intent.getIntExtra(TYPE_OPERATION, -1);
switch (type) {
case TYPE_ERROR:
onErrorOccured(intent.getStringExtra(ERROR));
break;
case TYPE_EVENTS:
Parcelable[] result = intent.getParcelableArrayExtra(EVENTS);
Mark[] marks = new Mark[result.length];
for (int i = 0; i < result.length; ++i) {
marks[i] = (Mark) result[i];
}
onEvents(marks);
break;
}
}

public abstract void onErrorOccured(String error);

public abstract void onEvents(Mark[] mark);

}
@@ -0,0 +1,199 @@
package ru.spb.osll.GDS.events;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.json.JSONObject;

import ru.spb.osll.GDS.LocationService;
import ru.spb.osll.GDS.exception.ExceptionHandler;
import ru.spb.osll.GDS.preferences.Settings;
import ru.spb.osll.GDS.preferences.Settings.IGDSSettings;
import ru.spb.osll.GDS.utils.GDSUtil;
import ru.spb.osll.json.IRequest.IResponse;
import ru.spb.osll.json.JsonFilterCircleRequest;
import ru.spb.osll.json.JsonFilterResponse;
import ru.spb.osll.objects.Channel;
import ru.spb.osll.objects.Mark;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.os.Bundle;
import android.os.IBinder;
import android.os.SystemClock;
import android.util.Log;

public class EventsService extends Service {

private String m_authToken = null;
private Thread m_eventsThread;
private InternalReceiver m_internalReceiver = new InternalReceiver();
private Settings m_settings;

@Override
public IBinder onBind(Intent arg0) {
return null;
}

@Override
public void onCreate() {
Log.v(EventsManager.LOG, "EventsService create");

super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));

m_settings = new Settings(this);
registerReceiver(m_internalReceiver, new IntentFilter(InternalReceiver.ACTION));
LocationService.getLocation(this);
}

@Override
public void onStart(Intent intent, int startId) {
Log.v(EventsManager.LOG, "EventsService start");
super.onStart(intent, startId);

Bundle extras =intent.getExtras();
if (extras != null) {
m_authToken = extras.getString(EventsManager.AUTH_TOKEN);
}
if (m_authToken == null) {
Log.v(EventsManager.LOG, "problem with extracting data");
broadcastError("Failed to start tracking");
stopSelf();
return;
}

startEventsThread();
}

@Override
public void onDestroy() {
Log.v(EventsManager.LOG, "EventsService destroy");
super.onDestroy();
stopEventsTread();
unregisterReceiver(m_internalReceiver);
}

protected void stopEventsTread(){
if (m_eventsThread != null){
m_eventsThread.interrupt();
}
}

protected void startEventsThread(){
if (m_eventsThread != null){
m_eventsThread.interrupt();
}
m_eventsThread = new Thread(new Runnable() {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()){
Location location = LocationService.getLocation(EventsService.this);
if (location == null) {
Log.v(EventsManager.LOG, "can't get location");
} else {
Log.v(EventsManager.LOG, "coords: " + location.getLatitude()
+ ", " + location.getLongitude());
requestEvents(location);
}

SystemClock.sleep(EventsManager.INTERVAL * 1000);
}
}
});
m_eventsThread.start();
}

private void requestEvents(Location location) {
String serverUrl = m_settings.getServerUrl();
JSONObject JSONResponse = null;
for(int i = 0; i < IGDSSettings.ATTEMPTS; i++){
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.YEAR, 1); // just in case
String timeTo = GDSUtil.getTime(calendar.getTime());
calendar.add(Calendar.YEAR, -1); // return current date
calendar.add(Calendar.HOUR, - EventsManager.RELEVANT_PERIOD_IN_HOURS);
String timeFrom = GDSUtil.getTime(calendar.getTime());
JSONResponse = new JsonFilterCircleRequest(m_authToken,
location.getLatitude(), location.getLongitude(),
EventsManager.RADIUS, timeFrom, timeTo,
serverUrl).doRequest();
if (JSONResponse != null)
break;
}
if (JSONResponse != null) {
int errno = JsonFilterResponse.parseErrno(JSONResponse);
if (errno == IResponse.geo2tagError.SUCCESS.ordinal()) {
Log.v(EventsManager.LOG, "Events received successfully");
JsonFilterResponse response = new JsonFilterResponse();
response.parseJson(JSONResponse);
List<Channel> channels = response.getChannelsData();
for (Channel channel : channels) {
if (channel.getName().compareTo("Events") == 0) {
broadcastEvents(channel);
}
}
} else {
handleError(errno);
return;
}
} else {
Log.v(EventsManager.LOG, "response failed");
broadcastError("Failed to send location");
return;
}
}

private void handleError(int errno) {
if (errno < 0) {
Log.v(EventsManager.LOG, "bad response received");
} else if (errno >= IResponse.geo2tagError.values().length) {
Log.v(EventsManager.LOG, "unknown error");
} else if (errno > 0) {
String error = IResponse.geo2tagError.values()[errno].name();
Log.v(EventsManager.LOG, "error: " + error);
}
broadcastError("Failed to send location");
}



public class InternalReceiver extends BroadcastReceiver {
public static final String ACTION = "osll.gds.events.internal";
public static final String TYPE_SIGNAL = "osll.gds.signal";

public static final int SIGNAL_UPDATE_SETTINGS = 0;

@Override
public void onReceive(Context context, Intent intent) {
int type = intent.getIntExtra(TYPE_SIGNAL, -1);
switch (type) {
case SIGNAL_UPDATE_SETTINGS:
//refreshSCache();
//onSettingUpdated();
break;
}
}
}

private void broadcastError(String error) {
Intent intent = new Intent(EventsReceiver.ACTION_EVENTS);
intent.putExtra(EventsReceiver.TYPE_OPERATION, EventsReceiver.TYPE_ERROR);
intent.putExtra(EventsReceiver.ERROR, error);
sendBroadcast(intent);
}

private void broadcastEvents(Channel eventsChannel) {
Intent intent = new Intent(EventsReceiver.ACTION_EVENTS);
intent.putExtra(EventsReceiver.TYPE_OPERATION, EventsReceiver.TYPE_EVENTS);
Mark[] marks = eventsChannel.getMarks().toArray(new Mark[0]);
intent.putExtra(EventsReceiver.EVENTS, marks);
sendBroadcast(intent);
}

}
@@ -85,6 +85,46 @@ private void loadFromXMLFile(Editor configEditor) {
"loadFromXMLFile - exception: " + e.getMessage());
}
}

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

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

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

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

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

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

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

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


public static SharedPreferences getPreferences(Context c){
@@ -36,20 +36,15 @@
package ru.spb.osll.GDS.preferences;

import ru.spb.osll.GDS.R;
//import ru.spb.osll.gui.RadioButtonDialog;
import ru.spb.osll.GDS.preferences.Settings.IGDSSettings;
//import ru.spb.osll.utils.TrackerUtil;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class SettingsActivity extends Activity implements IGDSSettings {

@@ -0,0 +1,46 @@
package ru.spb.osll.GDS.tracking;

import ru.spb.osll.GDS.utils.GDSUtil;
import android.content.Context;
import android.content.Intent;

public class TrackingManager {

public static final String LOG = "GDS_Tracking_service";
public static final String AUTH_TOKEN = "auth_token";
public static final String CHANNEL = "channel";

private String m_authToken;
private String m_channel;

public TrackingManager() {
m_authToken = "";
m_channel = "";
}

public TrackingManager(String authToken, String channel) {
m_authToken = authToken;
m_channel = channel;
}

public void setData(String authToken, String channel) {
m_authToken = authToken;
m_channel = channel;
}

public void startTracking(Context c) {
Intent i = new Intent(c, TrackingService.class);
i.putExtra(AUTH_TOKEN, m_authToken);
i.putExtra(CHANNEL, m_channel);
c.startService(i);
}

public void stopTracking(Context c) {
c.stopService(new Intent(c, TrackingService.class));
}

public boolean isTracking(Context c) {
return GDSUtil.isServiceRunning(c, TrackingService.class.getName());
}

}
@@ -0,0 +1,35 @@
package ru.spb.osll.GDS.tracking;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public abstract class TrackingReceiver extends BroadcastReceiver {

public static final String ACTION_TRACKING = "osll.gds.tracking";

public static final String TYPE_OPERATION = "gds.type";
public static final int TYPE_ERROR = 0;
public static final int TYPE_MARK_SENT = 1;

public static final String ERROR = "type.error";
public static final String LONLAT = "type.lonlat";

@Override
public void onReceive(Context context, Intent intent) {
int type = intent.getIntExtra(TYPE_OPERATION, -1);
switch (type) {
case TYPE_ERROR:
onErrorOccured(intent.getStringExtra(ERROR));
break;
case TYPE_MARK_SENT:
onMarkSent(intent.getStringExtra(LONLAT));
break;
}
}

public abstract void onErrorOccured(String error);

public abstract void onMarkSent(String lonlat);

}
@@ -0,0 +1,236 @@
package ru.spb.osll.GDS.tracking;

import java.util.Date;

import org.json.JSONObject;

import ru.spb.osll.GDS.exception.ExceptionHandler;
import ru.spb.osll.GDS.preferences.Settings;
import ru.spb.osll.GDS.preferences.Settings.IGDSSettings;
import ru.spb.osll.GDS.utils.GDSUtil;
import ru.spb.osll.json.JsonApplyMarkRequest;
import ru.spb.osll.json.JsonBaseResponse;
import ru.spb.osll.json.IRequest.IResponse;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.SystemClock;
import android.util.Log;

public class TrackingService extends Service {

public static final int INTERVAL = 7;

private String m_authToken = null;
private String m_channel = null;
private LocationManager m_locationManager;
private boolean m_isDeviceReady = false;
private Thread m_trackThread;
private InternalReceiver m_internalReceiver = new InternalReceiver();
private Settings m_settings;

@Override
public IBinder onBind(Intent arg0) {
return null;
}

@Override
public void onCreate() {
Log.v(TrackingManager.LOG, "TrackingService create");

super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));

m_settings = new Settings(this);
m_locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
m_locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, m_locationListener);
registerReceiver(m_internalReceiver, new IntentFilter(InternalReceiver.ACTION));
getLocation();
}

@Override
public void onStart(Intent intent, int startId) {
Log.v(TrackingManager.LOG, "TrackingService start");
super.onStart(intent, startId);
m_isDeviceReady = false; // TODO check device

Bundle extras =intent.getExtras();
if (extras != null) {
m_authToken = extras.getString(TrackingManager.AUTH_TOKEN);
m_channel = extras.getString(TrackingManager.CHANNEL);
}
if (m_authToken == null || m_channel == null) {
Log.v(TrackingManager.LOG, "problem with extracting data");
broadcastError("Failed to start tracking");
stopSelf();
return;
}

//startTracking(); // TODO for testing on AVD
}

@Override
public void onDestroy() {
Log.v(TrackingManager.LOG, "TrackingService destroy");
super.onDestroy();

stopTracking();
m_locationManager.removeUpdates(m_locationListener);
unregisterReceiver(m_internalReceiver);
}

private LocationListener m_locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
if (!m_isDeviceReady && location != null){
m_isDeviceReady = true;
onLocationDeviceStatusChanged(true);
} else if (m_isDeviceReady && location == null) {
m_isDeviceReady = false;
onLocationDeviceStatusChanged(false);
}
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};

public Location getLocation() {
Location location = null;
String provider = LocationManager.NETWORK_PROVIDER;
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

if (locationManager != null) {
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
provider = LocationManager.GPS_PROVIDER;
}
location = locationManager.getLastKnownLocation(provider);
}
return location;
}

protected void onLocationDeviceStatusChanged(boolean isReady) {
Log.v(TrackingManager.LOG, "onLocationDeviceStatusChanged: " + isReady);
if (isReady) {
startTracking();
} else {
stopTracking();
}
}

protected void stopTracking(){
if (m_trackThread != null){
m_trackThread.interrupt();
}
}

protected void startTracking(){
if (m_trackThread != null){
m_trackThread.interrupt();
}
m_trackThread = new Thread(new Runnable() {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()){
Location location = getLocation();
Log.v(TrackingManager.LOG, "coords: " + location.getLatitude()
+ ", " + location.getLongitude());

sendMark(location);

SystemClock.sleep(INTERVAL * 1000);
}
}
});
m_trackThread.start();
}

private void sendMark(Location location) {
String serverUrl = m_settings.getServerUrl();
JSONObject JSONResponse = null;
for(int i = 0; i < IGDSSettings.ATTEMPTS; i++){
JSONResponse = new JsonApplyMarkRequest(m_authToken, m_channel, "gds tracker", "",
"gds tracker", location.getLatitude(), location.getLongitude(), 0,
GDSUtil.getTime(new Date()), serverUrl).doRequest();
if (JSONResponse != null)
break;
}
if (JSONResponse != null) {
int errno = JsonBaseResponse.parseErrno(JSONResponse);
if (errno == IResponse.geo2tagError.SUCCESS.ordinal()) {
Log.v(TrackingManager.LOG, "Mark sent successfully");
broadcastMarkSent(location);
} else {
handleError(errno);
return;
}
} else {
Log.v(TrackingManager.LOG, "response failed");
broadcastError("Failed to send location");
return;
}
}

private void handleError(int errno) {
if (errno < 0) {
Log.v(TrackingManager.LOG, "bad response received");
} else if (errno >= IResponse.geo2tagError.values().length) {
Log.v(TrackingManager.LOG, "unknown error");
} else if (errno > 0) {
String error = IResponse.geo2tagError.values()[errno].name();
Log.v(TrackingManager.LOG, "error: " + error);
}
broadcastError("Failed to send location");
}



public class InternalReceiver extends BroadcastReceiver {
public static final String ACTION = "osll.gds.tracking.internal";
public static final String TYPE_SIGNAL = "osll.gds.signal";

public static final int SIGNAL_UPDATE_SETTINGS = 0;
public static final int SIGNAL_SEND_HISTORY = 1;
public static final int SIGNAL_SEND_COORDINATE = 2;

@Override
public void onReceive(Context context, Intent intent) {
int type = intent.getIntExtra(TYPE_SIGNAL, -1);
switch (type) {
case SIGNAL_UPDATE_SETTINGS:
//refreshSCache();
//onSettingUpdated();
break;
case SIGNAL_SEND_HISTORY:
//refreshSCache();
//sendHistory();
break;
case SIGNAL_SEND_COORDINATE:
//refreshSCache();
//sendLastCoordinate();
break;
}
}
}

private void broadcastError(String error) {
Intent intent = new Intent(TrackingReceiver.ACTION_TRACKING);
intent.putExtra(TrackingReceiver.TYPE_OPERATION, TrackingReceiver.TYPE_ERROR);
intent.putExtra(TrackingReceiver.ERROR, error);
sendBroadcast(intent);
}

private void broadcastMarkSent(Location location) {
Intent intent = new Intent(TrackingReceiver.ACTION_TRACKING);
intent.putExtra(TrackingReceiver.TYPE_OPERATION, TrackingReceiver.TYPE_MARK_SENT);
intent.putExtra(TrackingReceiver.LONLAT, GDSUtil.convertLocation(location));
sendBroadcast(intent);
}

}
@@ -0,0 +1,46 @@
package ru.spb.osll.GDS.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import ru.spb.osll.objects.Mark;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.location.Location;

public class GDSUtil {
private static DateFormat dateFormat = new SimpleDateFormat("dd MM yyyy HH:MM:ss.SSS");
public static String getTime(Date date){
return dateFormat.format(date);
}

@SuppressWarnings("static-access")
public static boolean isServiceRunning(Context c, String serviceName){
ActivityManager manager = (ActivityManager) c.getSystemService(c.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceName.equals(service.service.getClassName())) {
return true;
}
}
return false;
}

public static String convertLocation(Mark mark){
return convertLocation(mark.getLatitude(), mark.getLongitude(), 0.0);
}

public static String convertLocation(Location loc){
double alt = loc.hasAltitude() ? loc.getAltitude() : 0.0;
return convertLocation(loc.getLatitude(), loc.getLongitude(), alt);
}

public static String convertLocation(double lat, double lon, double alt){
StringBuffer strBuffer = new StringBuffer();
strBuffer.append("lat: ").append(Location.convert(lat, Location.FORMAT_MINUTES)).
append(" lon: ").append(Location.convert(lon, Location.FORMAT_MINUTES)).
append(" alt: ").append(Location.convert(alt, Location.FORMAT_DEGREES));
return strBuffer.toString();
}

}
@@ -38,21 +38,21 @@
public interface IRequest {

public interface ILogin{
String REQUEST = "/login";
String REQUEST = "/service/login";

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

public interface IAddUser{
String REQUEST = "/addUser";
String REQUEST = "/service/addUser";

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

public interface IApplyChannel{
String REQUEST = "/addChannel";
String REQUEST = "/service/addChannel";

String AUTH_TOKEN = "auth_token";
String NAME = "name";
@@ -62,7 +62,7 @@ public interface IRequest {
}

public interface IApplyMark{
String REQUEST = "/apply";
String REQUEST = "/service/writeTag";

String AUTH_TOKEN = "auth_token";
String CHANNEL = "channel";
@@ -72,6 +72,14 @@ public interface IRequest {
String LATITUDE = "latitude";
String LONGITUDE = "longitude";
String TIME = "time";
String ALTITUDE = "altitude";
}

public interface ISubscribeChannel {
String REQUEST = "/service/subscribe";

String AUTH_TOKEN = "auth_token";
String CHANNEL = "channel";
}

public interface IResponse{
@@ -55,18 +55,21 @@ public class JsonApplyMarkRequest extends JsonBaseRequest {
private String m_description;
private double m_latitude;
private double m_longitude;
private double m_altitude;
private String m_time;
private String m_serverUrl;

public JsonApplyMarkRequest(String authToken, String channel, String title, String link,
String description, double latitude, double longitude, String time, String serverUrl){
String description, double latitude, double longitude, double altitude,
String time, String serverUrl){
m_authToken = authToken;
m_channel = channel;
m_title = title;
m_link = link;
m_description = description;
m_latitude = latitude;
m_longitude = longitude;
m_altitude = altitude;
m_time = time;
m_serverUrl = serverUrl;
}
@@ -83,6 +86,7 @@ protected JSONObject doRequestInternal() throws JSONException, IOException,
jsonObject.put(DESCRIPTION, m_description);
jsonObject.put(LATITUDE, m_latitude);
jsonObject.put(LONGITUDE, m_longitude);
jsonObject.put(ALTITUDE, m_altitude);
jsonObject.put(TIME, m_time);
Log.v(JSON_LOG, jsonObject.toString());

@@ -63,7 +63,7 @@ protected JSONObject getJsonObject() throws JSONException {

@Override
protected String getRequest() {
return "/filterCircle";
return "/service/filterCircle";
}

}
@@ -67,6 +67,7 @@ public void parseJson(JSONObject obj) {

Mark mark = new Mark();
mark.setChannel(channelName);
//mark.setId(jmark.getLong("id"));
mark.setUser(jmark.getString("user"));
mark.setTitle(jmark.getString("title"));
mark.setLink(jmark.getString("link"));
@@ -0,0 +1,67 @@
/*
* Copyright 2012 Ivan Bezyazychnyy ivan.bezyazychnyy@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.
*/

package ru.spb.osll.json;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import static ru.spb.osll.json.IRequest.ISubscribeChannel.*;

public class JsonSubscribeRequest extends JsonBaseRequest {
private String m_authToken;
private String m_channel;
private String m_serverUrl;

public JsonSubscribeRequest(String authToken, String channel, String serverUrl){
m_authToken = authToken;
m_channel = channel;
m_serverUrl = serverUrl;
}


@Override
protected JSONObject doRequestInternal() throws JSONException, IOException,
URISyntaxException {
JSONObject jsonObject = new JSONObject();
jsonObject.put(AUTH_TOKEN, m_authToken);
jsonObject.put(CHANNEL, m_channel);
Log.v(JSON_LOG, jsonObject.toString());

return JsonBase.instance().doRequest(jsonObject, new URI(m_serverUrl + REQUEST));
}
}
@@ -0,0 +1,36 @@
/*
* Copyright 2012 Ivan Bezyazychnyy ivan.bezyazychnyy@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.
*/

package ru.spb.osll.json;

public class JsonSubscribeResponse extends JsonOldResponse {

}
@@ -35,7 +35,10 @@

package ru.spb.osll.objects;

public class Mark {
import android.os.Parcel;
import android.os.Parcelable;

public class Mark implements Parcelable {
private long id;
private String authToken;
private String channel;
@@ -48,6 +51,10 @@ public class Mark {
private String time;
private String user;

public Mark() {

}

public String getUser() {
return user;
}
@@ -120,5 +127,51 @@ public String toString() {
+ channel + "\n, title=" + title + "\n, link=" + link
+ "\n, description=" + description + "\n, latitude=" + latitude
+ "\n, longitude=" + longitude + "\n, time=" + time + "]";
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(authToken);
dest.writeString(channel);
dest.writeString(title);
dest.writeString(link);
dest.writeString(description);
dest.writeDouble(latitude);
dest.writeDouble(longitude);
dest.writeDouble(altitude);
dest.writeString(time);
dest.writeString(user);
}

// this is used to regenerate your object. All Parcelables must have a CREATOR that implements these two methods
public static final Parcelable.Creator<Mark> CREATOR = new Parcelable.Creator<Mark>() {
public Mark createFromParcel(Parcel in) {
return new Mark(in);
}

public Mark[] newArray(int size) {
return new Mark[size];
}
};

// example constructor that takes a Parcel and gives you an object populated with it's values
private Mark(Parcel in) {
id = in.readLong();
authToken = in.readString();
channel = in.readString();
title = in.readString();
link = in.readString();
description = in.readString();
latitude = in.readDouble();
longitude = in.readDouble();
altitude = in.readDouble();
time = in.readString();
user = in.readString();
}
}
@@ -0,0 +1,11 @@
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Name=HelloWorld
Exec=/opt/HelloWorld/bin/HelloWorld
Icon=HelloWorld64
X-Window-Icon=
X-HildonDesk-ShowInToolbar=true
X-Osso-Type=application/x-executable
@@ -0,0 +1,122 @@
# Add files and directories to ship with the application
# by adapting the examples below.
# file1.source = myfile
# dir1.source = mydir
DEPLOYMENTFOLDERS = # file1 dir1

QT += network

symbian:TARGET.UID3 = 0xE6691141

# Smart Installer package's UID
# This UID is from the protected range
# and therefore the package will fail to install if self-signed
# By default qmake uses the unprotected range value if unprotected UID is defined for the application
# and 0x2002CCCF value if protected UID is given to the application
#symbian:DEPLOYMENT.installer_header = 0x2002CCCF

# Allow network access on Symbian
symbian:TARGET.CAPABILITY += NetworkServices Location

CONFIG += mobility
MOBILITY += location

INCLUDEPATH += . inc

SOURCES += src/main.cpp \
src/mainwindow.cpp \
src/GDSService.cpp \
src/LoginWidget.cpp \
src/MainWidget.cpp \
src/CreateAccountWidget.cpp \
src/Settings.cpp \
src/SettingsWidget.cpp
HEADERS += inc/defines.h \
inc/mainwindow.h \
inc/GDSService.h \
inc/LoginWidget.h \
inc/MainWidget.h \
inc/CreateAccountWidget.h \
inc/Settings.h \
inc/SettingsWidget.h

# qsjon library
SOURCES += ../../../3rdparty/qjson-0.7.1/src/serializerrunnable.cpp \
../../../3rdparty/qjson-0.7.1/src/serializer.cpp \
../../../3rdparty/qjson-0.7.1/src/qobjecthelper.cpp \
../../../3rdparty/qjson-0.7.1/src/parserrunnable.cpp \
../../../3rdparty/qjson-0.7.1/src/parser.cpp \
../../../3rdparty/qjson-0.7.1/src/json_scanner.cpp \
../../../3rdparty/qjson-0.7.1/src/json_parser.cc
HEADERS += ../../../3rdparty/qjson-0.7.1/src/parser.h \
../../../3rdparty/qjson-0.7.1/src/serializerrunnable.h \
../../../3rdparty/qjson-0.7.1/src/serializer.h \
../../../3rdparty/qjson-0.7.1/src/qobjecthelper.h \
../../../3rdparty/qjson-0.7.1/src/qjson_export.h \
../../../3rdparty/qjson-0.7.1/src/qjson_debug.h \
../../../3rdparty/qjson-0.7.1/src/parser_p.h \
../../../3rdparty/qjson-0.7.1/src/json_scanner.h \
../../../3rdparty/qjson-0.7.1/src/parserrunnable.h \
../../../3rdparty/qjson-0.7.1/src/json_parser.hh \
../../../3rdparty/qjson-0.7.1/src/stack.hh \
../../../3rdparty/qjson-0.7.1/src/location.hh \
../../../3rdparty/qjson-0.7.1/src/position.hh

# geo2tag requests library
INCLUDEPATH += http_requests/inc json/inc common/inc
SOURCES += http_requests/src/DefaultQuery.cpp \
http_requests/src/LoginQuery.cpp \
http_requests/src/WriteTagQuery.cpp \
json/src/JsonSerializer.cpp \
json/src/LoginResponseJSON.cpp \
json/src/LoginRequestJSON.cpp \
json/src/JsonUser.cpp \
json/src/WriteTagResponseJSON.cpp \
json/src/WriteTagRequestJSON.cpp \
json/src/JsonDataMark.cpp \
json/src/JsonChannel.cpp \
common/src/User.cpp \
common/src/TimeSlot.cpp \
common/src/DataMarks.cpp \
common/src/Channel.cpp
#./../common/src/GpsInfo.cpp \
#../../common/src/GpsModeller.cpp \
#./../common/src/MobilityGps.cpp \

HEADERS += http_requests/inc/DefaultQuery.h \
http_requests/inc/LoginQuery.h \
http_requests/inc/WriteTagQuery.h \
json/inc/JsonSerializer.h \
json/inc/LoginResponseJSON.h \
json/inc/LoginRequestJSON.h \
json/inc/JsonUser.h \
#../../json/inc/JsonTimeSlot.h \
json/inc/JsonDataMark.h \
json/inc/JsonChannel.h \
json/inc/WriteTagResponseJSON.h \
json/inc/WriteTagRequestJSON.h \
json/inc/DefaultResponseJSON.h \
common/inc/ErrnoTypes.h \
common/inc/User.h \
common/inc/TimeSlot.h \
common/inc/DataMarks.h \
common/inc/Channel.h
#./../common/inc/ConcurrentVector.h \
#./../common/inc/defines.h \
#../../common/inc/DataChannel.h \
#../../common/inc/symbian.h \
#../../common/inc/GpsInfo.h \
#../../common/inc/GpsModeller.h \
#../../common/inc/MobilityGps.h \


# Please do not modify the following two lines. Required for deployment.
include(deployment.pri)
qtcAddDeployment()







Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,11 @@
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Name=HelloWorld
Exec=/usr/bin/single-instance /opt/HelloWorld/bin/HelloWorld
Icon=/usr/share/icons/hicolor/80x80/apps/HelloWorld80.png
X-Window-Icon=
X-HildonDesk-ShowInToolbar=true
X-Osso-Type=application/x-executable
@@ -0,0 +1,63 @@
/*
* Copyright 2011 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 AltitudeFilter.h
* \brief Header of AltitudeFilter
* \todo add comment here
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */


#ifndef _AltitudeFilter_H_89C1C268_7B22_4E8A_B078_B4C7EC6FA5D6_INCLUDED_
#define _AltitudeFilter_H_89C1C268_7B22_4E8A_B078_B4C7EC6FA5D6_INCLUDED_

#include "Filter.h"

class AltitudeFilter : public Filter
{
double m_alt1;
double m_alt2;

public:
AltitudeFilter(double alt1, double alt2);

~AltitudeFilter();

bool filtrate(const QSharedPointer<DataMark> &mark);

}; // class AltitudeFilter


#endif //_AltitudeFilter_H_89C1C268_7B22_4E8A_B078_B4C7EC6FA5D6_INCLUDED_
@@ -0,0 +1,99 @@
/*
* Copyright 2010 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.
*/
/*!
* \file Channel.h
* \brief Header of Channel
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#ifndef _Channel_H_480D4E41_537B_41D1_A67C_326A700DDC2D_INCLUDED_
#define _Channel_H_480D4E41_537B_41D1_A67C_326A700DDC2D_INCLUDED_

#include <QString>
#include <QVector>
#include <QSharedPointer>

//#include "ConcurrentVector.h"
#include "TimeSlot.h"

class Channel: public QObject
{
Q_OBJECT //!< channel name
QString m_name; //!< Description for channel
QString m_description; //!< URL for mark
QString m_url; //< Radius for visible marks
double m_activeRadius; //!< Displayed on the UI
bool m_isDisplayed;
QSharedPointer<TimeSlot> m_timeSlot;
bool m_timeSlotIsDefault;

public:

static const qulonglong DEFAULT_TIME_SLOT_VALUE_MIN;

Channel(const QString &name, const QString &description, const QString& url="");

virtual qlonglong getId() const;

const QString& getDescription() const;

const QString& getName() const;

const QString& getUrl() const;

void setDescription(const QString& description);

void setUrl(const QString& url);

void setRadius(const double &radius);
double getRadius() const;

bool isDisplayed() const;
void setDisplayed(bool);

void setTimeSlot(QSharedPointer<TimeSlot> timeSlot);
QSharedPointer<TimeSlot> getTimeSlot() const;

bool timeSlotIsDefault() const;
void setDefaultTimeSlot(bool);

virtual ~Channel();
// class Channel
};

typedef ConcurrentVector<Channel> Channels;
//_Channel_H_480D4E41_537B_41D1_A67C_326A700DDC2D_INCLUDED_
#endif

/* ===[ End of file ]=== */
@@ -0,0 +1,53 @@
/*
* Copyright 2010-2011 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
* ---------------------------------------------------------------- */

#ifndef CHANNELACTION_H
#define CHANNELACTION_H

#include "User.h"

class ChannelActions: public QObject
{
Q_OBJECT
int m_user;
int m_channel;
int m_action;

public:
ChannelActions(int user, int channel, int action);

virtual ~ChannelActions();

};
#endif // CHANNELACTION_H
@@ -0,0 +1,151 @@
/*
* Copyright 2010-2011 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
* ---------------------------------------------------------------- */

#ifndef CONCURRENTVECTOR_H
#define CONCURRENTVECTOR_H

#include <QVector>
#include <QSharedPointer>
#include <QMutex>
#include <QMutexLocker>
#include <QMap>

template<typename T>
class ConcurrentVector
{
mutable QMutex m_lock;

QVector<QSharedPointer<T> > m_container;
QMap<qlonglong, QSharedPointer<T> > m_map;

public:

typedef typename QVector<QSharedPointer<T> >::iterator iterator;
typedef typename QVector<QSharedPointer<T> >::const_iterator const_iterator;

ConcurrentVector(const QVector<QSharedPointer<T> > &container=QVector<QSharedPointer<T> >()):
m_container(container)
{
}

ConcurrentVector(const ConcurrentVector<T>& obj):m_container(obj.m_container)
{
}

void push_back(const QSharedPointer<T>& obj)
{
QMutexLocker locker(&m_lock);
if(!m_map.contains(obj->getId()))
{
m_container.push_back(obj);
m_map.insert(obj->getId(), obj);
}
}

const QSharedPointer<T>& at(int i) const
{
QMutexLocker locker(&m_lock);
return m_container.at(i);
}

const QSharedPointer<T>& operator [](int i) const
{
QMutexLocker locker(&m_lock);
return m_container[i];
}

QSharedPointer<T>& operator [](int i)
{
QMutexLocker locker(&m_lock);
return m_container[i];
}

int size() const
{
QMutexLocker locker(&m_lock);
return m_container.size();
}

bool exist(qlonglong objectId) const
{
QMutexLocker locker(&m_lock);
return m_map.contains(objectId);
}

const QSharedPointer<T>& item(qlonglong id) const
{
QMutexLocker locker(&m_lock);
return m_map.value(id);
}

QSharedPointer<T>& item(qlonglong id)
{
QMutexLocker locker(&m_lock);
return m_map[id];
}

void merge(const ConcurrentVector<T>& vector)
{
for(int i=0; i<vector.size(); i++)
{
if(exist(vector.at(i)->getId()))
continue;
push_back(vector.at(i));
}
}

void erase(const QSharedPointer<T> &val)
{
QMutexLocker locker(&m_lock);
int i = m_container.indexOf(val);
if(i != -1)
m_container.remove(i);
}

QVector<QSharedPointer<T> > vector() const
{
QMutexLocker locker(&m_lock);
return m_container;
}

void clear()
{
QMutexLocker locker(&m_lock);
m_container.clear();
m_map.clear();
}

};
// CONCURRENTVECTOR_H
#endif
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2011 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
* ---------------------------------------------------------------- */

#ifndef DATACHANNEL_H
#define DATACHANNEL_H

#include <QMultiHash>
#include "Channel.h"
#include "DataMarks.h"

typedef QMultiMap<QSharedPointer<Channel>, QSharedPointer<DataMark> > DataChannels;
// DATACHANNEL_H
#endif
@@ -0,0 +1,123 @@
/*
* Copyright 2010 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.
*/
/* */
/*!
* \file DataMarks.h
* \brief Header of DataMarks
* \todo add comment here
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#ifndef _DataMarks_H_E8A2619E_0BF6_4AE8_BB61_F09B92F73637_INCLUDED_
#define _DataMarks_H_E8A2619E_0BF6_4AE8_BB61_F09B92F73637_INCLUDED_

//#include <QString>
#include <QVector>
#include <QSharedPointer>
#include <QDateTime>
#include "User.h"
#include "ConcurrentVector.h"
//#include "Channel.h"

class DataMark: public QObject
{
Q_OBJECT
double m_altitude;
double m_latitude;
double m_longitude;

QString m_label;
QString m_description;
QString m_url;
QDateTime m_time;

QSharedPointer<common::User> m_user;

QSharedPointer<Channel> m_channel;

QSharedPointer<TimeSlot> m_timeSlot;

public:

DataMark(double altitude, double latitude, double longitude, QString label,
QString description, QString url, QDateTime time); // TODO add altitude to constructor

void setUser(QSharedPointer<common::User> user);

void setChannel(QSharedPointer<Channel> channel);

public:

virtual qlonglong getId() const;

void setDescription(const QString&);
const QString& getDescription() const;

double getLatitude() const;
void setLatitude(const double&);

double getLongitude() const;
void setLongitude(const double&);

double getAltitude() const;
void setAltitude(const double&);

const QString& getLabel() const;
void setLabel(const QString&);

const QString& getUrl() const;
void setUrl(const QString&);

const QDateTime& getTime() const;
void setTime(const QDateTime& time=QDateTime::currentDateTime().toUTC());

QSharedPointer<common::User> getUser() const;

QSharedPointer<Channel> getChannel() const;
static double getDistance(double lat1, double lon1, double lat2, double lon2);

void setTimeSlot(QSharedPointer<TimeSlot> timeSlot);
QSharedPointer<TimeSlot> getTimeSlot() const;
bool timeSlotIsNull() const;

virtual ~DataMark();
};

bool operator<(const QSharedPointer<DataMark> &a, const QSharedPointer<DataMark> &b);

typedef ConcurrentVector<DataMark> DataMarks;
//_DataMarks_H_E8A2619E_0BF6_4AE8_BB61_F09B92F73637_INCLUDED_
#endif

/* ===[ End of file ]=== */
@@ -0,0 +1,72 @@
/*
* Copyright 2010 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.
*/
/* */
/*!
* \file DefaultException.h
* \brief Header of DefaultException
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */

#ifndef _DefaultException_H_B503B3CC_1500_4544_8732_F56CD8A9F61B_INCLUDED_
#define _DefaultException_H_B503B3CC_1500_4544_8732_F56CD8A9F61B_INCLUDED_

#include <QString>

namespace exception
{
/*!
* Default exception. All exception will be ingerited from this one
*/
class DefaultException
{
public:
DefaultException();

virtual QString getDescription() const=0;

virtual ~DefaultException();

private:
DefaultException(const DefaultException& obj);
DefaultException& operator=(const DefaultException& obj);

// class DefaultException
};

// namespace exception
}


//_DefaultException_H_B503B3CC_1500_4544_8732_F56CD8A9F61B_INCLUDED_
#endif

/* ===[ End of file ]=== */
@@ -0,0 +1,71 @@
/*
* Copyright 2011 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 ErrnoTypes.h
* \brief Header of ErrnoTypes
* \todo add comment here
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */


#ifndef _ErrnoTypes_H_9465846A_3F83_4512_8C8B_EE2A40A357F9_INCLUDED_
#define _ErrnoTypes_H_9465846A_3F83_4512_8C8B_EE2A40A357F9_INCLUDED_

#include <QString>

enum geo2tagError
{
SUCCESS ,
WRONG_TOKEN_ERROR ,
USER_ALREADY_EXIST_ERROR ,
USER_DOES_NOT_EXIST_ERROR ,
CHANNEL_ALREADY_EXIST_ERROR ,
CHANNEL_DOES_NOT_EXIST_ERROR ,
SUBSCRIPTION_ALREADY_EXIST ,
INTERNAL_DB_ERROR ,
INCORRECT_QUERY_NAME_ERROR ,
INCORRECT_JSON_ERROR ,
INCORRECT_CREDENTIALS_ERROR ,
CHANNEL_NOT_SUBCRIBED_ERROR ,
CHANNEL_ALREADY_SUBSCRIBED_ERROR ,
TAG_DOES_NOT_EXIST_ERROR ,
TAG_ALREADY_EXIST_ERROR ,
NULL_TIMESLOT_ERROR ,
UNKNOWN_ERROR
};

const QString getErrorByCode(int error);

#endif //_ErrnoTypes_H_9465846A_3F83_4512_8C8B_EE2A40A357F9_INCLUDED_
@@ -0,0 +1,56 @@
/*
* Copyright 2011 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 FShape.h
* \brief Header of FShape
* \todo add comment here
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */


#ifndef _FShape_H_2055D9DC_F9B0_419F_A486_DF9A5459E64B_INCLUDED_
#define _FShape_H_2055D9DC_F9B0_419F_A486_DF9A5459E64B_INCLUDED_

#include <QSharedPointer>
#include "DataMarks.h"

class FShape
{
public:
virtual bool filtrate(const QSharedPointer<DataMark> &mark) = 0;

}; // class Filter

#endif //_FShape_H_2055D9DC_F9B0_419F_A486_DF9A5459E64B_INCLUDED_
@@ -0,0 +1,62 @@
/*
* Copyright 2011 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 FShapeCircle.h
* \brief Header of FShapeCircle
* \todo add comment here
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */


#ifndef _FShapeCircle_H_685324AD_3719_4618_BE1B_F0221ABB524D_INCLUDED_
#define _FShapeCircle_H_685324AD_3719_4618_BE1B_F0221ABB524D_INCLUDED_

#include <QSharedPointer>
#include "FShape.h"

class FShapeCircle : public FShape
{
double m_lat;
double m_lon;
double m_radius;

public:
FShapeCircle(double lat, double lon, double r);
~FShapeCircle();
bool filtrate(const QSharedPointer<DataMark> &mark);

}; // class FShapeCircle

#endif //_FShapeCircle_H_685324AD_3719_4618_BE1B_F0221ABB524D_INCLUDED_
@@ -0,0 +1,62 @@
/*
* Copyright 2011 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 FShapePolygon.h
* \brief Header of FShapePolygon
* \todo add comment here
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */


#ifndef _FShapePolygon_H_A08ADAEE_DA07_4E75_A64D_F4F86290B7D1_INCLUDED_
#define _FShapePolygon_H_A08ADAEE_DA07_4E75_A64D_F4F86290B7D1_INCLUDED_

#include "FShape.h"
#include <QPointF>

class FShapePolygon : public FShape
{
QList<QPointF> m_points;

public:
FShapePolygon();

void addPoint(int idx, double lat, double lon);

bool filtrate(const QSharedPointer<DataMark> &mark);

}; // class FShapePolygon

#endif //_FShapePolygon_H_A08ADAEE_DA07_4E75_A64D_F4F86290B7D1_INCLUDED_
@@ -0,0 +1,56 @@
/*
* Copyright 2011 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 FShapeRectangle.h
* \brief Header of FShapeRectangle
* \todo add comment here
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */


#ifndef _FShapeRectangle_H_551E8083_C487_48C6_A778_26A3143C34A8_INCLUDED_
#define _FShapeRectangle_H_551E8083_C487_48C6_A778_26A3143C34A8_INCLUDED_

#include "FShapePolygon.h"

class FShapeRectangle : public FShapePolygon
{
public:
FShapeRectangle(double lat1, double lon1, double lat2, double lon2);

}; // class FShapeRectangle


#endif //_FShapeRectangle_H_551E8083_C487_48C6_A778_26A3143C34A8_INCLUDED_
@@ -0,0 +1,56 @@
/*
* Copyright 2011 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 Filter.h
* \brief Header of Filter
* \todo add comment here
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */


#ifndef _Filter_H_F1B0F887_FC25_4557_B002_AC962387F3F9_INCLUDED_
#define _Filter_H_F1B0F887_FC25_4557_B002_AC962387F3F9_INCLUDED_

#include <QSharedPointer>
#include "DataMarks.h"

class Filter
{
public:
virtual bool filtrate(const QSharedPointer<DataMark> &mark) = 0;

}; // class Filter

#endif //_Filter_H_F1B0F887_FC25_4557_B002_AC962387F3F9_INCLUDED_
@@ -0,0 +1,65 @@
/*
* Copyright 2011 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 Filtration.h
* \brief Header of Filtration
* \todo add comment here
*
* File description
*
* PROJ: OSLL/geo2tag
* ---------------------------------------------------------------- */


#ifndef _Filtration_H_A12E4622_FC1F_4AA0_8E00_D4E6B6E36300_INCLUDED_
#define _Filtration_H_A12E4622_FC1F_4AA0_8E00_D4E6B6E36300_INCLUDED_

#include <QList>
#include <QSharedPointer>
#include "Filter.h"

class Filtration
{
QList<QSharedPointer<Filter> > m_filters;

public:
Filtration();

~Filtration();

void addFilter(const QSharedPointer<Filter> & filter);

QList<QSharedPointer<DataMark> > filtrate(const QList<QSharedPointer<DataMark> > tags);

}; // class Filtration

#endif //_Filtration_H_A12E4622_FC1F_4AA0_8E00_D4E6B6E36300_INCLUDED_