I have made the following changes intended for : CE:MW:Shared / libcommhistory
Please review and accept or decline. BOSS has already run some checks on this request. See the "Messages from BOSS" section below. https://build.pub.meego.com//request/show/6761 Thank You, John Brooks [This message was auto-generated] --- Request # 6761: Messages from BOSS: State: review at 2012-09-21T00:35:22 by bossbot Reviews: accepted by bossbot : Prechecks succeeded. new for CE-maintainers : Please replace this text with a review and approve/reject the review (not the SR). BOSS will take care of the rest Changes: submit: home:special:branches:CE:MW:Shared / libcommhistory -> CE:MW:Shared / libcommhistory changes files: -------------- --- libcommhistory.changes +++ libcommhistory.changes @@ -0,0 +1,5 @@ +* Thu Sep 20 2012 John Brooks <[email protected]> - 1.4.0 +- Make EventModel and GroupModel QML friendly by exposing roles +- Add declarative plugin, currently just exposing models and constants +- Fix regression in ConversationModel::fetchMore from a previous patch + old: ---- 0001-Prevent-crash-from-early-ConversationModel-fetchMore.patch libcommhistory-1.3.12.6.tar.gz new: ---- libcommhistory-1.4.0.tar.bz2 spec files: ----------- --- libcommhistory.spec +++ libcommhistory.spec @@ -1,18 +1,18 @@ Name: libcommhistory Summary: Communications event history database API -Version: 1.3.12.6 +Version: 1.4.0 Release: 1 Group: System/Libraries License: LGPL -URL: http://gitorious.org/commhistory/libcommhistory -Source0: %{name}-%{version}.tar.gz +URL: https://github.com/nemomobile/libcommhistory +Source0: %{name}-%{version}.tar.bz2 Patch0: libcommhistory-1.3.12.6-fix-shared-static-lib-build-order.patch -Patch1: 0001-Prevent-crash-from-early-ConversationModel-fetchMore.patch BuildRequires: libqtcontacts-tracker-extensions-devel BuildRequires: pkgconfig(QtCore) >= 4.7.0 BuildRequires: pkgconfig(QtContacts) BuildRequires: pkgconfig(QtSparql) BuildRequires: pkgconfig(tracker-sparql-0.10) +BuildRequires: pkgconfig(QtDeclarative) %description Library for accessing the communications (IM, SMS and call) history database. @@ -32,6 +32,14 @@ %description tools Command line tools for the commhistory library. +%package declarative +Summary: QML plugin for libcommhistory +Group: System/Libraries +Requires: %{name} = %{version}-%{release} + +%description declarative +QML plugin for libcommhistory + %package devel Summary: Development files for libcommhistory Group: Development/Libraries @@ -50,10 +58,9 @@ %prep -%setup -q -n %{name}-%{version} +%setup -q -n %{name} %patch0 -p1 -%patch1 -p1 %build unset LD_AS_NEEDED @@ -78,6 +85,10 @@ %defattr(-,root,root,-) %{_bindir}/commhistory-tool +%files declarative +%defattr(-,root,root,-) +%{_libdir}/qt4/imports/org/nemomobile/commhistory/* + #files tests #defattr(-,root,root,-) %exclude %{_datadir}/libcommhistory-performance-tests/* other changes: -------------- ++++++ libcommhistory-1.3.12.6.tar.gz -> libcommhistory-1.4.0.tar.bz2 --- declarative +++ declarative +(directory) --- declarative/declarative.pro +++ declarative/declarative.pro @@ -0,0 +1,26 @@ +include( ../common-project-config.pri ) +include( ../common-vars.pri ) + +TARGET = commhistory-declarative +PLUGIN_IMPORT_PATH = org/nemomobile/commhistory +VERSION = $$PROJECT_VERSION + +LIBS += -L../src \ + ../src/libcommhistory.so +INCLUDEPATH += ../src + +SOURCES += src/plugin.cpp + +HEADERS += src/constants.h + +# do not edit below here, move this to a shared .pri? +TEMPLATE = lib +CONFIG += qt plugin hide_symbols +QT += declarative + +target.path = $$[QT_INSTALL_IMPORTS]/$$PLUGIN_IMPORT_PATH +INSTALLS += target + +qmldir.files += $$PWD/qmldir +qmldir.path += $$[QT_INSTALL_IMPORTS]/$$$$PLUGIN_IMPORT_PATH +INSTALLS += qmldir --- declarative/qmldir +++ declarative/qmldir @@ -0,0 +1 @@ +plugin commhistory-declarative --- declarative/src +++ declarative/src +(directory) --- declarative/src/constants.h +++ declarative/src/constants.h @@ -0,0 +1,85 @@ +/* Copyright (C) 2012 John Brooks <[email protected]> + * + * 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 COMMHISTORYCONSTANTS_H +#define COMMHISTORYCONSTANTS_H + +#include <QObject> + +/* Class for exposing constants and enums from libcommhistory to QML. + * Not instantiable. */ +class CommHistoryConstants : public QObject +{ + Q_OBJECT + Q_ENUMS(EventType EventDirection EventStatus EventReadStatus ChatType) + +public: + enum EventType { + UnknownType = 0, + IMEvent, + SMSEvent, + CallEvent, + VoicemailEvent, + StatusMessageEvent, + MMSEvent, + ClassZeroSMSEvent + }; + + enum EventDirection { + UnknownDirection = 0, + Inbound, + Outbound + }; + + enum EventStatus { + UnknownStatus = 0, + SendingStatus, + SentStatus, + DeliveredStatus, + FailedStatus, + TemporarilyFailedStatus = FailedStatus, + PermanentlyFailedStatus + }; + + enum EventReadStatus { + UnknownReadStatus = 0, + ReadStatusRead, + ReadStatusDeleted + }; + + enum ChatType { + ChatTypeP2P = 0, + ChatTypeUnnamed, + ChatTypeRoom + }; +}; + +#endif + --- declarative/src/plugin.cpp +++ declarative/src/plugin.cpp @@ -0,0 +1,64 @@ +/* Copyright (C) 2012 John Brooks <[email protected]> + * + * 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 <QtGlobal> +#include <QtDeclarative> +#include <QDeclarativeEngine> +#include <QDeclarativeExtensionPlugin> +#include "constants.h" +#include "eventmodel.h" +#include "groupmodel.h" +#include "conversationmodel.h" + +class Q_DECL_EXPORT CommHistoryPlugin : public QDeclarativeExtensionPlugin +{ +public: + virtual ~CommHistoryPlugin() { } + + void initializeEngine(QDeclarativeEngine *engine, const char *uri) + { + Q_ASSERT(uri == QLatin1String("org.nemomobile.commhistory")); + Q_UNUSED(uri); + Q_UNUSED(engine); + } + + void registerTypes(const char *uri) + { + Q_ASSERT(uri == QLatin1String("org.nemomobile.commhistory")); + + qmlRegisterUncreatableType<CommHistoryConstants>(uri, 1, 0, "CommHistory", "Constants-only type"); + qmlRegisterType<CommHistory::EventModel>(uri, 1, 0, "CommEventModel"); + qmlRegisterType<CommHistory::GroupModel>(uri, 1, 0, "CommGroupModel"); + qmlRegisterType<CommHistory::ConversationModel>(uri, 1, 0, "CommConversationModel"); + } +}; + +Q_EXPORT_PLUGIN2(commhistoryplugin, CommHistoryPlugin); + --- libcommhistory.pro +++ libcommhistory.pro @@ -25,6 +25,7 @@ TEMPLATE = subdirs CONFIG += ordered SUBDIRS = src \ + declarative \ tools \ tests --- src/conversationmodel.cpp +++ src/conversationmodel.cpp @@ -336,6 +336,10 @@ Q_UNUSED(parent); Q_D(ConversationModel); + // isModelReady() is true when there are no more events to request + if (d->isModelReady() || d->eventRootItem->childCount() < 1) + return; + EventsQuery query = d->buildQuery(); Event &event = d->eventRootItem->eventAt(d->eventRootItem->childCount() - 1); --- src/eventmodel.cpp +++ src/eventmodel.cpp @@ -44,6 +44,8 @@ connect(d_ptr, SIGNAL(modelReady(bool)), this, SIGNAL(modelReady(bool))); connect(d_ptr, SIGNAL(eventsCommitted(const QList<CommHistory::Event>&,bool)), this, SIGNAL(eventsCommitted(const QList<CommHistory::Event>&,bool))); + + setupRoles(); } EventModel::EventModel(EventModelPrivate &dd, QObject *parent) @@ -52,6 +54,8 @@ connect(d_ptr, SIGNAL(modelReady(bool)), this, SIGNAL(modelReady(bool))); connect(d_ptr, SIGNAL(eventsCommitted(const QList<CommHistory::Event>&,bool)), this, SIGNAL(eventsCommitted(const QList<CommHistory::Event>&,bool))); + + setupRoles(); } EventModel::~EventModel() @@ -59,6 +63,36 @@ delete d_ptr; } +void EventModel::setupRoles() +{ + QHash<int,QByteArray> roles = roleNames(); + roles[BaseRole + EventId] = "eventId"; + roles[BaseRole + EventType] = "eventType"; + roles[BaseRole + StartTime] = "startTime"; + roles[BaseRole + EndTime] = "endTime"; + roles[BaseRole + Direction] = "direction"; + roles[BaseRole + IsDraft] = "isDraft"; + roles[BaseRole + IsRead] = "isRead"; + roles[BaseRole + IsMissedCall] = "isMissedCall"; + roles[BaseRole + Status] = "status"; + roles[BaseRole + BytesReceived] = "bytesReceived"; + roles[BaseRole + LocalUid] = "localUid"; + roles[BaseRole + RemoteUid] = "remoteUid"; + roles[BaseRole + Contacts] = "contacts"; + roles[BaseRole + FreeText] = "freeText"; + roles[BaseRole + GroupId] = "groupId"; + roles[BaseRole + MessageToken] = "messageToken"; + roles[BaseRole + LastModified] = "lastModified"; + roles[BaseRole + EventCount] = "eventCount"; + roles[BaseRole + FromVCardFileName] = "fromVCardFileName"; + roles[BaseRole + FromVCardLabel] = "fromVCardLabel"; + roles[BaseRole + Encoding] = "encoding"; + roles[BaseRole + Charset] = "charset"; + roles[BaseRole + Language] = "language"; + roles[BaseRole + IsDeleted] = "isDeleted"; + setRoleNames(roles); +} + void EventModel::setPropertyMask(const Event::PropertySet &properties) { Q_D(EventModel); @@ -204,8 +238,14 @@ return QVariant::fromValue(event); } + int column = index.column(); + if (role >= BaseRole) { + column = role - BaseRole; + role = Qt::DisplayRole; + } + QVariant var; - switch (index.column()) { + switch (column) { case EventId: var = QVariant::fromValue(event.id()); break; @@ -279,7 +319,7 @@ var = QVariant::fromValue(event.isDeleted()); break; default: - qDebug() << __PRETTY_FUNCTION__ << ": invalid column id??" << index.column(); + qDebug() << __PRETTY_FUNCTION__ << ": invalid column id??" << column; var = QVariant(); break; } --- src/eventmodel.h +++ src/eventmodel.h @@ -62,6 +62,14 @@ Q_ENUMS(QueryMode) + Q_PROPERTY(bool treeMode READ isTree WRITE setTreeMode) + Q_PROPERTY(QueryMode queryMode READ queryMode WRITE setQueryMode) + Q_PROPERTY(uint chunkSize READ chunkSize WRITE setChunkSize) + Q_PROPERTY(uint firstChunkSize READ firstChunkSize WRITE setFirstChunkSize) + Q_PROPERTY(int limit READ limit WRITE setLimit) + Q_PROPERTY(int offset READ offset WRITE setOffset) + Q_PROPERTY(bool syncMode READ syncMode WRITE setSyncMode) + public: enum QueryMode { AsyncQuery, StreamedAsyncQuery, SyncQuery }; @@ -93,6 +101,10 @@ NumberOfColumns }; + enum { + BaseRole = Qt::UserRole + 1000 + }; + /*! * Model constructor. * @@ -376,6 +388,8 @@ private: Q_DECLARE_PRIVATE(EventModel); + + void setupRoles(); }; } --- src/eventtreeitem.cpp +++ src/eventtreeitem.cpp @@ -79,6 +79,7 @@ Event &EventTreeItem::eventAt(int row) { + Q_ASSERT(row >= 0 && row < children.count()); return children.value(row)->event(); } --- src/groupmodel.cpp +++ src/groupmodel.cpp @@ -629,6 +629,26 @@ : QAbstractTableModel(parent), d(new GroupModelPrivate(this)) { + QHash<int,QByteArray> roles = roleNames(); + roles[BaseRole + GroupId] = "groupId"; + roles[BaseRole + LocalUid] = "localUid"; + roles[BaseRole + RemoteUids] = "remoteUids"; + roles[BaseRole + ChatName] = "chatName"; + roles[BaseRole + EndTime] = "endTime"; + roles[BaseRole + TotalMessages] = "totalMessages"; + roles[BaseRole + UnreadMessages] = "unreadMessages"; + roles[BaseRole + SentMessages] = "sentMessages"; + roles[BaseRole + LastEventId] = "lastEventId"; + roles[BaseRole + Contacts] = "contacts"; + roles[BaseRole + LastMessageText] = "lastMessageText"; + roles[BaseRole + LastVCardFileName] = "lastVCardFileName"; + roles[BaseRole + LastVCardLabel] = "lastVCardLabel"; + roles[BaseRole + LastEventType] = "lastEventType"; + roles[BaseRole + LastEventStatus] = "lastEventStatus"; + roles[BaseRole + IsPermanent] = "isPermanent"; + roles[BaseRole + LastModified] = "lastModified"; + roles[BaseRole + StartTime] = "startTime"; + setRoleNames(roles); } GroupModel::~GroupModel() @@ -677,13 +697,7 @@ QVariant GroupModel::data(const QModelIndex &index, int role) const { - Q_UNUSED(role); - - if (!index.isValid()) { - return QVariant(); - } - - if (index.row() >= d->groups.count() || index.row() < 0) { + if (!index.isValid() || index.row() > d->groups.count() || index.row() < 0) { return QVariant(); } @@ -693,8 +707,14 @@ return QVariant::fromValue(group); } + int column = index.column(); + if (role >= BaseRole) { + column = role - BaseRole; + role = Qt::DisplayRole; + } + QVariant var; - switch (index.column()) { + switch (column) { case GroupId: var = QVariant::fromValue(group.id()); break; @@ -747,7 +767,7 @@ var = QVariant::fromValue(group.startTime()); break; default: - qDebug() << "Group::data: invalid column id??" << index.column(); + qDebug() << "Group::data: invalid column id??" << column; break; } --- src/groupmodel.h +++ src/groupmodel.h @@ -76,6 +76,7 @@ enum Role { GroupRole = Qt::UserRole, + BaseRole = Qt::UserRole + 1000 }; /*! ++++++ deleted files: --- 0001-Prevent-crash-from-early-ConversationModel-fetchMore.patch
