Skip to content

Commit

Permalink
[qtcontacts-sqlite] Initial commit
Browse files Browse the repository at this point in the history
The qtcontacts-sqlite backend for the QtPIM and QtMobility Contacts
APIs stores contact information to an SQLite database.
  • Loading branch information
Chris Adams committed Apr 10, 2013
0 parents commit 4497d8f
Show file tree
Hide file tree
Showing 25 changed files with 9,136 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README
@@ -0,0 +1,2 @@
This repository contains a backend for the QtContacts API.
It stores contact information to a local SQLite database.
7 changes: 7 additions & 0 deletions qtcontacts-sqlite.pro
@@ -0,0 +1,7 @@
TEMPLATE = subdirs

SUBDIRS = \
src \
tests

tests.depends = src
45 changes: 45 additions & 0 deletions rpm/qtcontacts-sqlite.spec
@@ -0,0 +1,45 @@
Name: qtcontacts-sqlite
Version: 0.0.1
Release: 0
Summary: SQLite-based plugin for QtContacts
Group: System/Plugins
License: TBD
URL: TBD
Source0: %{name}-%{version}.tar.gz
BuildRequires: pkgconfig(QtCore)
BuildRequires: pkgconfig(QtSql)
BuildRequires: pkgconfig(QtDBus)
BuildRequires: pkgconfig(QtContacts)

%description
%{summary}.

%files
%defattr(-,root,root,-)
%{_libdir}/qt4/plugins/contacts/*.so*

%package tests
Summary: Unit tests for qtcontacts-sqlite
Group: System/Libraries
BuildRequires: pkgconfig(QtTest)
Requires: %{name} = %{version}-%{release}

%description tests
This package contains unit tests for the qtcontacts-sqlite library.

%files tests
%defattr(-,root,root,-)
/opt/tests/qtcontacts-sqlite/*


%prep
%setup -q -n %{name}-%{version}

%build
%qmake
make %{?jobs:-j%jobs}

%install
rm -rf %{buildroot}
%qmake_install

126 changes: 126 additions & 0 deletions src/engine/contactnotifier.cpp
@@ -0,0 +1,126 @@
/*
* Copyright (C) 2013 Jolla Ltd. <andrew.den.exter@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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 COPYRIGHT
* OWNER OR CONTRIBUTORS 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."
*/

#include "contactnotifier.h"

#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusMetaType>
#include <QVector>

#define NOTIFIER_PATH "/org/nemomobile/contacts/sqlite"
#define NOTIFIER_INTERFACE "org.nemomobile.contacts.sqlite"

Q_DECLARE_METATYPE(QVector<QContactLocalId>)
Q_DECLARE_METATYPE(QList<QContactLocalId>)

namespace ContactNotifier
{

void initialize()
{
qDBusRegisterMetaType<QVector<QContactLocalId> >();
qDBusRegisterMetaType<QList<QContactLocalId> >();
}

void contactsAdded(const QVector<QContactLocalId> &contactIds)
{
QDBusMessage message = QDBusMessage::createSignal(
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String("contactsAdded"));
message.setArguments(QVariantList() << QVariant::fromValue(contactIds));
QDBusConnection::sessionBus().send(message);
}

void contactsChanged(const QVector<QContactLocalId> &contactIds)
{
QDBusMessage message = QDBusMessage::createSignal(
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String("contactsChanged"));
message.setArguments(QVariantList() << QVariant::fromValue(contactIds));
QDBusConnection::sessionBus().send(message);
}

void contactsRemoved(const QList<QContactLocalId> &contactIds)
{
QDBusMessage message = QDBusMessage::createSignal(
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String("contactsRemoved"));
message.setArguments(QVariantList() << QVariant::fromValue(contactIds));
QDBusConnection::sessionBus().send(message);
}

void selfContactIdChanged(QContactLocalId oldId, QContactLocalId newId)
{
QDBusMessage message = QDBusMessage::createSignal(
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String("selfContactIdChanged"));
message.setArguments(QVariantList() << oldId << newId);
QDBusConnection::sessionBus().send(message);
}

void relationshipsAdded(const QSet<QContactLocalId> &contactIds)
{
QDBusMessage message = QDBusMessage::createSignal(
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String("relationshipsAdded"));
message.setArguments(QVariantList() << QVariant::fromValue(contactIds.toList()));
QDBusConnection::sessionBus().send(message);
}

void relationshipsRemoved(const QSet<QContactLocalId> &contactIds)
{
QDBusMessage message = QDBusMessage::createSignal(
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String("relationshipsRemoved"));
message.setArguments(QVariantList() << QVariant::fromValue(contactIds.toList()));
QDBusConnection::sessionBus().send(message);
}

bool connect(const char *name, const char *signature, QObject *receiver, const char *slot)
{
return QDBusConnection::sessionBus().connect(
QString(),
QLatin1String(NOTIFIER_PATH),
QLatin1String(NOTIFIER_INTERFACE),
QLatin1String(name),
QLatin1String(signature),
receiver,
slot);
}

}
54 changes: 54 additions & 0 deletions src/engine/contactnotifier.h
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2013 Jolla Ltd. <andrew.den.exter@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "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 COPYRIGHT
* OWNER OR CONTRIBUTORS 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."
*/

#ifndef QTCONTACTSSQLITE_CONTACTNOTIFIER_H
#define QTCONTACTSSQLITE_CONTACTNOTIFIER_H

#include <QContact>
#include <QObject>
#include <QSet>

QTM_USE_NAMESPACE

namespace ContactNotifier
{
void initialize();
void contactsAdded(const QVector<QContactLocalId> &contactIds);
void contactsChanged(const QVector<QContactLocalId> &contactIds);
void contactsRemoved(const QList<QContactLocalId> &contactIds);
void selfContactIdChanged(QContactLocalId oldId, QContactLocalId newId);
void relationshipsAdded(const QSet<QContactLocalId> &contactIds);
void relationshipsRemoved(const QSet<QContactLocalId> &contactIds);

bool connect(const char *name, const char *signature, QObject *receiver, const char *slot);
}

#endif

0 comments on commit 4497d8f

Please sign in to comment.