--- /dev/null
+#include <QDebug>
+#include <QDir>
+#include <QSqlQuery>
+#include <QVariant>
+
+#include "database.h"
+
+Database::Database(QObject *parent) :
+ QObject(parent)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+Database::~Database()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+bool Database::addTag(int userId, const QString &tag)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ bool ret = false;
+
+ if (m_database.isOpen()) {
+ QSqlQuery tagQuery;
+
+ ret = tagQuery.exec(QString("INSERT INTO tag VALUES(NULL, '%1')")
+ .arg(tag));
+
+ qWarning() << tagQuery.lastError().number();
+ qWarning() << tagQuery.lastError().driverText();
+ qWarning() << tagQuery.lastError().text();
+
+ if (ret) {
+ int tagId = tagQuery.lastInsertId().toInt();
+
+ QSqlQuery userTagQuery;
+
+ ret = userTagQuery.exec(QString("INSERT INTO usertag VALUES(NULL, '%1', '%2')")
+ .arg(tagId).arg(userId));
+ qWarning() << userTagQuery.lastError().number();
+ qWarning() << userTagQuery.lastError().driverText();
+ qWarning() << userTagQuery.lastError().text();
+ }
+ }
+
+ qDebug() << ret;
+ return ret;
+}
+
+bool Database::createTagTable()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ bool created = false;
+
+ if (m_database.isOpen()) {
+
+ QSqlQuery query;
+ created = query.exec("CREATE TABLE IF NOT EXISTS tag ("
+ "id INTEGER PRIMARY KEY,"
+ "name VARCHAR(30)"
+ ")");
+
+ qWarning() << query.lastError().text();
+ }
+
+ qDebug() << created;
+ return created;
+}
+
+bool Database::createUserTagTable()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ bool created = false;
+
+ if (m_database.isOpen()) {
+
+ QSqlQuery query;
+ created = query.exec("CREATE TABLE IF NOT EXISTS usertag ("
+ "id INTEGER PRIMARY KEY,"
+ "userid INTEGER,"
+ "tagid INTEGER,"
+ "FOREIGN KEY(tagid) REFERENCES tag(id)"
+ ")");
+ qWarning() << query.lastError().text();
+ }
+
+ qDebug() << created;
+ return created;
+}
+
+QStringList Database::getTags(int userId)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QStringList tags;
+
+ QSqlQuery query(QString("SELECT * from usertag WHERE userid = '%1'").arg(userId));
+ qWarning() << query.lastError().text();
+ if (query.next()) {
+ qWarning() << query.value(0).toString();
+ qWarning() << query.value(1).toString();
+ qWarning() << query.value(2).toString();
+ }
+
+ return tags;
+}
+
+bool Database::openDatabase()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_database = QSqlDatabase::addDatabase("QSQLITE");
+
+ QString path(QDir::home().path());
+ path.append(QDir::separator()).append("my.db.sqlite");
+ path = QDir::toNativeSeparators(path);
+ m_database.setDatabaseName(path);
+
+ return m_database.open();
+}
+
+void Database::test()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ bool ret = false;
+
+// QSqlQuery query(QString("SELECT * from tag"))
+}
--- /dev/null
+#ifndef DATABASE_H
+#define DATABASE_H
+
+#include <QObject>
+
+#include <QSqlDatabase>
+#include <QSqlError>
+#include <QFile>
+#include <QStringList>
+
+class Database : public QObject
+{
+ Q_OBJECT
+public:
+ Database(QObject *parent = 0);
+ ~Database();
+
+ bool addTag(int userId, const QString &tag);
+ QStringList getTags(int userId);
+ bool openDatabase();
+ bool createTagTable();
+ bool createUserTagTable();
+ void test();
+
+private:
+ QSqlDatabase m_database;
+};
+
+#endif // DATABASE_H
}
tmpFriendsList.clear();
+ //get user tags and set tags to the user
+ m_user->setTags(getTags(m_user->userId()));
+
emit userDataChanged(m_user, m_friendsList);
// set silhouette image to imageUrlList for downloading
}
emit userDataChanged(m_user, m_friendsList);
}
+
+QStringList SituareService::getTags(const QString &userId)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+
+}
+
+void SituareService::updateTags(const QStringList &tags)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
*/
void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
+ /**
+ * @brief Updates tags to the Situare server
+ *
+ * CURRENTLY TAGS ARE UPDATED TO THE LOCAL DATABASE, NOT SITUARE SERVER
+ * @param tags list of user's tags
+ */
+ void updateTags(const QStringList &tags);
+
public slots:
/**
bool publish = false);
/**
+ * @brief Temporary method to get tags.
+ *
+ * Tags are fetch from local database instead of Situare server.
+ * @param userId
+ * @return QStringList list of tags
+ */
+ QStringList getTags(const QString &userId);
+
+ /**
* @brief Parses user and friend data from JSON string
*
* @param jsonReply JSON string
ui/routewaypointlistitem.cpp \
ui/routewaypointlistview.cpp \
user/user.cpp \
- ui/meetpeoplepanel.cpp
+ ui/meetpeoplepanel.cpp \
+ situareservice/database.cpp
HEADERS += application.h \
common.h \
coordinates/geocoordinate.h \
ui/routewaypointlistitem.h \
ui/routewaypointlistview.h \
user/user.h \
- ui/meetpeoplepanel.h
+ ui/meetpeoplepanel.h \
+ situareservice/database.h
QT += network \
- webkit
+ webkit \
+ sql
DEFINES += QT_NO_DEBUG_OUTPUT
User::User(const QString &address, const GeoCoordinate &coordinates, const QString &name,
const QString ¬e, const QUrl &imageUrl, const QString ×tamp, const bool &type,
- const QString &userId, const QString &units, const double &value)
+ const QString &userId, const QString &units, const double &value,
+ const QStringList &tags = QStringList())
: m_address(address)
, m_coordinates(coordinates)
, m_name(name)
, m_note(note)
, m_profileImageUrl(imageUrl)
+ , m_tags(tags)
, m_timestamp(timestamp)
, m_type(type)
, m_units(units)
, m_name()
, m_note()
, m_profileImageUrl()
+ , m_tags()
, m_timestamp()
, m_type()
, m_units()
m_profileImageUrl = imageUrl;
}
+void User::setTags(const QStringList &tags)
+{
+ m_tags = tags;
+}
+
void User::setTimestamp(const QString ×tamp)
{
m_timestamp = timestamp;
return m_profileImageUrl;
}
+const QStringList& User::tags() const
+{
+ return m_tags;
+}
+
const QString& User::timestamp() const
{
return m_timestamp;
void setProfileImageUrl(const QUrl &imageUrl);
/**
+ * @brief Sets user's tags.
+ *
+ * @param tags user's tags
+ */
+ void setTags(const QStringList &tags);
+
+ /**
* @brief Set timestamp for last status update, timestamp is in literal mode
*
* @param timestamp timestamp
const QUrl &profileImageUrl() const;
/**
+ * @brief Returns user's tags.
+ *
+ * @return QStringList list of tags
+ */
+ const QStringList &tags() const;
+
+ /**
* @brief Get timestamp of last status update
*
* @return QString timestamp
QString m_name; ///< placeholder for name
QString m_note; ///< placeholder for note
QUrl m_profileImageUrl; ///< placeholder for image url
+ QStringList m_tags; ///< placeholder for tags
QString m_timestamp; ///< placeholer for timestamp
bool m_type; ///< placeholder for user type
QString m_units; ///< placeholder for distance unit type