summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAlex <qt-info@nokia.com>2010-06-16 17:38:46 +1000
committerAlex <qt-info@nokia.com>2010-06-16 17:38:46 +1000
commit2d520362f9b0de4fef56c6539635b1f6e884e082 (patch)
tree118696d7b9484d201b10bc9b70f65b933f727a42 /examples
parent30dfd947d80847b3924135b90368fb49a21ac1f1 (diff)
parent18e2adb8a924f6e38f025fff5f0a3c6233489756 (diff)
Merge branch '1.0' of ../qtmobility into 1.0
Diffstat (limited to 'examples')
-rw-r--r--examples/audiorecorder/audiorecorder.cpp121
-rw-r--r--examples/qmlcontacts/ScrollBar.qml4
-rw-r--r--examples/qmlcontacts/com/nokia/mobility/qmldir1
-rw-r--r--examples/qmlcontacts/contents/MediaButton.qml4
-rw-r--r--examples/qmlcontacts/example.qml60
-rw-r--r--examples/qmlcontacts/imageprovider.cpp111
-rw-r--r--examples/qmlcontacts/imageprovider.h65
-rw-r--r--examples/qmlcontacts/plugin.cpp77
-rw-r--r--examples/qmlcontacts/qmlcontact.cpp124
-rw-r--r--examples/qmlcontacts/qmlcontact.h67
-rw-r--r--examples/qmlcontacts/qmlcontactdetail.cpp111
-rw-r--r--examples/qmlcontacts/qmlcontactdetail.h77
-rw-r--r--examples/qmlcontacts/qmlcontactdetailfield.cpp (renamed from examples/qmlcontacts/main.cpp)58
-rw-r--r--examples/qmlcontacts/qmlcontactdetailfield.h72
-rw-r--r--examples/qmlcontacts/qmlcontactmodel.cpp58
-rw-r--r--examples/qmlcontacts/qmlcontactmodel.h13
-rw-r--r--examples/qmlcontacts/qmlcontacts.pro44
-rw-r--r--examples/qmlcontacts/qmlcontacts.qrc11
-rw-r--r--examples/sysinfo/sysinfo.pro2
19 files changed, 940 insertions, 140 deletions
diff --git a/examples/audiorecorder/audiorecorder.cpp b/examples/audiorecorder/audiorecorder.cpp
index a17abd2b70..63a6ddacdd 100644
--- a/examples/audiorecorder/audiorecorder.cpp
+++ b/examples/audiorecorder/audiorecorder.cpp
@@ -54,18 +54,9 @@ AudioRecorder::AudioRecorder()
audiosource = new QAudioCaptureSource;
capture = new QMediaRecorder(audiosource);
- if (capture->supportedAudioCodecs().size() > 0) {
- QAudioEncoderSettings audioSettings;
- audioSettings.setQuality(QtMultimediaKit::LowQuality);
- audioSettings.setEncodingMode(QtMultimediaKit::ConstantQualityEncoding);
- audioSettings.setCodec(capture->supportedAudioCodecs().first());
- capture->setEncodingSettings(audioSettings,QVideoEncoderSettings(),
- capture->supportedContainers().first());
- }
-
// set a default file
#ifdef Q_OS_SYMBIAN
- capture->setOutputLocation(recordPathAudio(QUrl()));
+ capture->setOutputLocation(recordPathAudio(QUrl()));
#else
capture->setOutputLocation(QUrl("test.raw"));
#endif
@@ -98,20 +89,20 @@ AudioRecorder::AudioRecorder()
codecLabel->setText(tr("Audio Codec"));
codecsBox = new QComboBox(this);
codecsBox->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Fixed);
- codecsBox->setMinimumSize(200,10);
-
+ codecsBox->setMinimumSize(200,10);
+
QLabel* sampleRateLabel = new QLabel;
sampleRateLabel->setText(tr("Sample Rate"));
sampleRateBox = new QComboBox(this);
sampleRateBox->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Fixed);
sampleRateBox->setMinimumSize(200,10);
-
+
QLabel* channelLabel = new QLabel;
channelLabel->setText(tr("Channel count"));
channelBox = new QComboBox(this);
channelBox->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Fixed);
channelBox->setMinimumSize(200,10);
-
+
QLabel* qualityLabel = new QLabel;
qualityLabel->setText(tr("Audio Quality"));
qualityBox = new QComboBox(this);
@@ -137,19 +128,19 @@ AudioRecorder::AudioRecorder()
for(int i = 0; i < containers.count(); i++)
containersBox->addItem(containers.at(i));
- QList<int> samplerates = capture->supportedAudioSampleRates();
- for(int i = 0; i < samplerates.count(); i++) {
+ QList<int> samplerates = capture->supportedAudioSampleRates();
+ for(int i = 0; i < samplerates.count(); i++) {
QString rateString = QString("%1").arg(samplerates.at(i));
- sampleRateBox->addItem(rateString, QVariant(samplerates.at(i)));
+ sampleRateBox->addItem(rateString, QVariant(samplerates.at(i)));
}
-
+
QList<int> channels;
- channels <<1<<2;
- for(int i = 0; i < channels.count(); i++) {
+ channels <<1<<2;
+ for(int i = 0; i < channels.count(); i++) {
QString channelString = QString("%1").arg(channels.at(i));
- channelBox->addItem(channelString, QVariant(channels.at(i)));
+ channelBox->addItem(channelString, QVariant(channels.at(i)));
}
-
+
qualityBox->addItem(tr("Low"));
qualityBox->addItem(tr("Medium"));
qualityBox->addItem(tr("High"));
@@ -182,25 +173,25 @@ AudioRecorder::AudioRecorder()
layout->addWidget(codecLabel,3,0,Qt::AlignHCenter);
connect(codecsBox,SIGNAL(activated(int)),SLOT(codecChanged(int)));
layout->addWidget(codecsBox,3,1,1,3,Qt::AlignLeft);
-
+
layout->addWidget(sampleRateLabel,4,0,Qt::AlignHCenter);
connect(sampleRateBox,SIGNAL(activated(int)),SLOT(sampleRateChanged(int)));
layout->addWidget(sampleRateBox,4,1,1,3,Qt::AlignLeft);
-
+
layout->addWidget(channelLabel,5,0,Qt::AlignHCenter);
connect(channelBox,SIGNAL(activated(int)),SLOT(channelCountChanged(int)));
layout->addWidget(channelBox,5,1,1,3,Qt::AlignLeft);
-
+
layout->addWidget(qualityLabel,6,0,Qt::AlignHCenter);
connect(qualityBox,SIGNAL(activated(int)),SLOT(qualityChanged(int)));
layout->addWidget(qualityBox,6,1,1,3,Qt::AlignLeft);
fileButton = new QPushButton(this);
- fileButton->setText(tr("Output File"));
+ fileButton->setText(tr("Output File"));
connect(fileButton,SIGNAL(clicked()),SLOT(selectOutputFile()));
layout->addWidget(fileButton,7,0,Qt::AlignHCenter);
-
- pauseButton = new QPushButton(this);
+
+ pauseButton = new QPushButton(this);
pauseButton->setText(tr("Pause"));
connect(pauseButton,SIGNAL(clicked()),SLOT(togglePause()));
layout->addWidget(pauseButton,7,1,Qt::AlignHCenter);
@@ -216,14 +207,14 @@ AudioRecorder::AudioRecorder()
statusLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
statusLabel->setLineWidth(1);
layout->addWidget(statusLabel,8,0,Qt::AlignHCenter);
-
+
QLabel* durationLabel = new QLabel;
durationLabel->setText(tr("Duration"));
layout->addWidget(durationLabel,8,1,Qt::AlignRight);
recTime = new QLabel;
layout->addWidget(recTime,8,2,Qt::AlignLeft);
-
+
window->setLayout(layout);
setCentralWidget(window);
window->show();
@@ -233,21 +224,21 @@ AudioRecorder::AudioRecorder()
}
QUrl AudioRecorder::recordPathAudio(QUrl filePath)
-{
+{
if (!filePath.isEmpty())
- return filePath;
-
+ return filePath;
+
QDir outputDir(QDir::rootPath());
-
- int lastImage = 0;
+
+ int lastImage = 0;
int fileCount = 0;
- foreach(QString fileName, outputDir.entryList(QStringList() << "testclip_*")) {
+ foreach(QString fileName, outputDir.entryList(QStringList() << "testclip_*")) {
int imgNumber = fileName.mid(5, fileName.size()-9).toInt();
lastImage = qMax(lastImage, imgNumber);
- if (outputDir.exists(fileName))
- fileCount+=1;
- }
- lastImage+=fileCount;
+ if (outputDir.exists(fileName))
+ fileCount+=1;
+ }
+ lastImage+=fileCount;
QUrl location(QDir::toNativeSeparators(outputDir.canonicalPath()+QString("/testclip_%1").arg(lastImage+1,4,10,QLatin1Char('0'))));
return location;
}
@@ -311,23 +302,23 @@ void AudioRecorder::codecChanged(int idx)
}
void AudioRecorder::sampleRateChanged(int idx)
-{
+{
QAudioEncoderSettings settings = capture->audioSettings();
settings.setSampleRate((sampleRateBox->itemData(idx).toInt()));
capture->setEncodingSettings(settings);
}
void AudioRecorder::channelCountChanged(int idx)
-{
+{
QAudioEncoderSettings settings = capture->audioSettings();
settings.setChannelCount((channelBox->itemData(idx).toInt()));
capture->setEncodingSettings(settings);
}
void AudioRecorder::qualityChanged(int idx)
-{
- QAudioEncoderSettings settings = capture->audioSettings();
-
+{
+ QAudioEncoderSettings settings = capture->audioSettings();
+
switch(idx) {
case 0:
settings.setQuality(QtMultimediaKit::LowQuality);
@@ -365,23 +356,23 @@ void AudioRecorder::toggleRecord()
recTime->setText("0");
currentTime = 0;
}
-#ifdef Q_OS_SYMBIAN
- if (!paused)
+#ifdef Q_OS_SYMBIAN
+ if (!paused)
capture->setOutputLocation(recordPathAudio(destination));
#endif
- capture->record();
+ capture->record();
active = true;
paused = false;
} else {
- capture->stop();
+ capture->stop();
active = false;
}
}
void AudioRecorder::togglePause()
{
- if(active && !paused) {
- capture->pause();
+ if(active && !paused) {
+ capture->pause();
active = false;
paused = true;
}
@@ -400,10 +391,10 @@ void AudioRecorder::selectOutputFile()
if(fileNames.size() > 0)
#ifdef Q_OS_SYMBIAN
destination = QUrl(fileNames.first());
-#else
+#else
capture->setOutputLocation(QUrl(fileNames.first()));
-
-#endif
+
+#endif
}
void AudioRecorder::errorChanged(QMediaRecorder::Error err)
@@ -417,17 +408,17 @@ void AudioRecorder::updateSamplerates(int idx)
{
QAudioEncoderSettings settings;
settings.setCodec(codecsBox->itemText(idx));
-
+
QList<int> supportedSampleRates = capture->supportedAudioSampleRates(settings);
- sampleRateBox->clear();
- for(int i = 0; i < supportedSampleRates.count(); i++) {
+ sampleRateBox->clear();
+ for(int i = 0; i < supportedSampleRates.count(); i++) {
QString rateString = QString("%1").arg(supportedSampleRates.at(i));
- sampleRateBox->addItem(rateString, QVariant(supportedSampleRates.at(i)));
- }
+ sampleRateBox->addItem(rateString, QVariant(supportedSampleRates.at(i)));
+ }
}
void AudioRecorder::updateChannelCount(int idx)
-{
+{
QMediaControl *control = audiosource->service()->requestControl(QAudioEncoderControl_iid);
if (!control)
return;
@@ -445,14 +436,14 @@ void AudioRecorder::updateChannelCount(int idx)
channels <<1<<2;
else
channels <<1;
- for(int i = 0; i < channels.count(); i++) {
+ for(int i = 0; i < channels.count(); i++) {
QString channelString = QString("%1").arg(channels.at(i));
- channelBox->addItem(channelString, QVariant(channels.at(i)));
- }
+ channelBox->addItem(channelString, QVariant(channels.at(i)));
+ }
}
void AudioRecorder::updateQuality(int idx)
-{
+{
QMediaControl *control = audiosource->service()->requestControl(QAudioEncoderControl_iid);
if (!control)
return;
@@ -472,5 +463,5 @@ void AudioRecorder::updateQuality(int idx)
qualityBox->addItem(tr("High"));
}else {
qualityBox->addItem(tr("Low"));
- }
+ }
}
diff --git a/examples/qmlcontacts/ScrollBar.qml b/examples/qmlcontacts/ScrollBar.qml
index e53b625ba9..1858059bb1 100644
--- a/examples/qmlcontacts/ScrollBar.qml
+++ b/examples/qmlcontacts/ScrollBar.qml
@@ -38,7 +38,7 @@
**
****************************************************************************/
-import Qt 4.6
+import Qt 4.7
Item {
id: scrollBar
@@ -49,7 +49,7 @@ Item {
// orientation can be either 'Vertical' or 'Horizontal'
property real position
property real pageSize
- property var orientation : "Vertical"
+ property string orientation : "Vertical"
property alias bgColor: background.color
property alias fgColor: thumb.color
diff --git a/examples/qmlcontacts/com/nokia/mobility/qmldir b/examples/qmlcontacts/com/nokia/mobility/qmldir
new file mode 100644
index 0000000000..7443f071c8
--- /dev/null
+++ b/examples/qmlcontacts/com/nokia/mobility/qmldir
@@ -0,0 +1 @@
+plugin qcontactqmlplugin
diff --git a/examples/qmlcontacts/contents/MediaButton.qml b/examples/qmlcontacts/contents/MediaButton.qml
index a07079cd4c..76a972bf82 100644
--- a/examples/qmlcontacts/contents/MediaButton.qml
+++ b/examples/qmlcontacts/contents/MediaButton.qml
@@ -38,10 +38,10 @@
**
****************************************************************************/
-import Qt 4.6
+import Qt 4.7
Item {
- property var text
+ property string text
signal clicked
id: container
diff --git a/examples/qmlcontacts/example.qml b/examples/qmlcontacts/example.qml
index a6819bd028..6db131fc25 100644
--- a/examples/qmlcontacts/example.qml
+++ b/examples/qmlcontacts/example.qml
@@ -38,8 +38,8 @@
**
****************************************************************************/
-import QmlContactModel 1.0
-import Qt 4.6
+import Qt 4.7
+import com.nokia.mobility 1.0
import "contents"
Rectangle {
@@ -52,7 +52,7 @@ Rectangle {
color: "#080808";
QmlContactModel {
- id: "myModel"
+ id: contactModel
manager: "memory"
}
@@ -127,6 +127,7 @@ Rectangle {
opacity: wrapper.detailsOpacity
height: childrenRect.height + 6;
width: childrenRect.width;
+
Column {
Text {
text: model.interestLabel + ": " + model.interest
@@ -136,12 +137,61 @@ Rectangle {
text: model.presenceAvailable ? model.presenceText + " [" + model.presenceMessage + "]" : " ";
color: details.textColor;
}
+ ListView {
+ width: details.width;
+ highlightFollowsCurrentItem: false
+ focus: true
+ //anchors.fill: parent
+ keyNavigationWraps: true
+
+ model:contactModel.details(contactId)
+ delegate: Component {
+ Item {
+ width: details.width;
+ property QtObject contactDetail : model.modelData;
+ Column {
+ Text {
+ width: details.width;
+ height: 20;
+ text: contactDetail.name;
+ color:details.textColor;
+ }
+ ListView {
+ width: details.width;
+ model:contactDetail.fields();
+ delegate: Component {
+ Item {
+ property QtObject field: model.modelData;
+ Row {
+ Text {
+ text:field.key;
+ color:details.textColor;
+ width: details.width;
+ height: 20;
+ }
+ TextInput {
+ width: details.width;
+ height: 20;
+ text:field.value;
+ color:details.textColor;
+ }
+ }
+ }
+ }//delegate
+
+ }//detail fields view
+
+ }
+ }
+
+ }//delegate
+ }//detail list view
}
}
}
Item {
- id: "buttonBox"
+ id: buttonBox
x: wrapper.width - 6 - childrenRect.width;
y: 4;
height:childrenRect.height
@@ -267,7 +317,7 @@ Rectangle {
ListView {
id: mainList
- model: myModel
+ model: contactModel
width: parent.width; height: parent.height
delegate: listdelegate
highlightFollowsCurrentItem: false
diff --git a/examples/qmlcontacts/imageprovider.cpp b/examples/qmlcontacts/imageprovider.cpp
new file mode 100644
index 0000000000..1712df97dc
--- /dev/null
+++ b/examples/qmlcontacts/imageprovider.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <qdeclarativeextensionplugin.h>
+
+#include <qdeclarativeengine.h>
+#include <qdeclarative.h>
+#include <qcontactmanager.h>
+#include <qcontactdetails.h>
+#include "imageprovider.h"
+
+
+QTM_USE_NAMESPACE
+
+// This is run in a low priority thread.
+QImage ContactThumbnailImageProvider::request(const QString &id, QSize *size, const QSize &req_size)
+{
+ if (m_thumbnails.contains(id)) {
+ if (size)
+ *size = req_size;
+ return m_thumbnails.value(id).scaled(req_size);
+ }
+
+ /* url format:
+ image://thumbnail/{manager.contactid}
+ */
+
+ QString managerName = id.split('.').first();
+ QString localId = id.split('.').last();
+
+ QContactManager* manager = 0;
+ if (m_managers.contains(managerName)) {
+ manager = m_managers.value(managerName);
+ } else {
+ manager = new QContactManager(managerName);
+ m_managers.insert(managerName, manager);
+ }
+
+ QContact c = manager->contact(localId.toInt());
+
+ QImage image(
+ req_size.width() > 0 ? req_size.width() : 100,
+ req_size.height() > 0 ? req_size.height() : 50,
+ QImage::Format_RGB32);
+
+ QContactThumbnail t = c.detail<QContactThumbnail>();
+ if (!t.thumbnail().isNull()) {
+ image = t.thumbnail().scaled(image.size());
+ } else {
+ QContactAvatar a = c.detail<QContactAvatar>();
+ QString imageUrl = a.imageUrl().isEmpty()? QString::fromLatin1("contents/default.svg") : a.imageUrl().toString();
+ image.load(imageUrl);
+ }
+
+ if (size)
+ *size = image.size();
+
+ m_thumbnails.insert(id, image);
+
+ return image;
+}
+
+ContactThumbnailImageProvider::~ContactThumbnailImageProvider()
+{
+ foreach(const QString& name, m_managers.keys()) {
+ delete m_managers.value(name);
+ }
+
+ m_managers.clear();
+}
+
+
diff --git a/examples/qmlcontacts/imageprovider.h b/examples/qmlcontacts/imageprovider.h
new file mode 100644
index 0000000000..be6418986f
--- /dev/null
+++ b/examples/qmlcontacts/imageprovider.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <qdeclarativeimageprovider.h>
+#include <QMap>
+#include "qcontactmanager.h"
+
+
+
+
+QTM_USE_NAMESPACE;
+
+
+class ContactThumbnailImageProvider : public QDeclarativeImageProvider
+{
+public:
+ // This is run in a low priority thread.
+ QImage request(const QString &id, QSize *size, const QSize &req_size);
+
+ ~ContactThumbnailImageProvider();
+
+private:
+ QMap<QString, QContactManager*> m_managers;
+ QMap<QString, QImage> m_thumbnails;
+};
+
diff --git a/examples/qmlcontacts/plugin.cpp b/examples/qmlcontacts/plugin.cpp
new file mode 100644
index 0000000000..d3c30c5fd6
--- /dev/null
+++ b/examples/qmlcontacts/plugin.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 Nokia Corporation and its Subsidiary(-ies) 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."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QApplication>
+#include <QtDeclarative>
+#include <QDeclarativeExtensionPlugin>
+#include <QDebug>
+#include "qmlcontactmodel.h"
+#include "qmlcontact.h"
+#include "qmlcontactdetail.h"
+#include "qmlcontactdetailfield.h"
+#include "imageprovider.h"
+
+QT_USE_NAMESPACE
+
+
+class QContactQmlPlugin : public QDeclarativeExtensionPlugin
+{
+ Q_OBJECT
+public:
+ void registerTypes(const char *uri)
+ {
+ Q_ASSERT(uri == QLatin1String("com.nokia.mobility"));
+ qmlRegisterType<QMLContactModel>(uri, 1, 0, "QmlContactModel");
+ qmlRegisterType<QMLContact>(uri, 1, 0, "QmlContact");
+ qmlRegisterType<QMLContactDetail>(uri, 1, 0, "QmlContactDetail");
+ qmlRegisterType<QMLContactDetailField>(uri, 1, 0, "QmlContactDetailField");
+ }
+
+ void initializeEngine(QDeclarativeEngine *engine, const char *uri) {
+ Q_UNUSED(uri);
+ engine->addImageProvider("thumbnail", new ContactThumbnailImageProvider);
+ }
+};
+
+#include "plugin.moc"
+
+Q_EXPORT_PLUGIN2(qcontactqmlplugin, QContactQmlPlugin);
+
diff --git a/examples/qmlcontacts/qmlcontact.cpp b/examples/qmlcontacts/qmlcontact.cpp
new file mode 100644
index 0000000000..23c6118d60
--- /dev/null
+++ b/examples/qmlcontacts/qmlcontact.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 Nokia Corporation and its Subsidiary(-ies) 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."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qcontactdetails.h>
+#include "qmlcontact.h"
+#include "qmlcontactdetail.h"
+#include <QDebug>
+
+static QString normalizePropertyName(const QString& name)
+{
+ if (!name.isEmpty())
+ return name.mid(1).prepend(name[0].toLower());
+ return QString();
+}
+
+
+QMLContact::QMLContact(QObject *parent)
+ :QObject(parent),
+ m_contactMap(0)
+{
+
+}
+
+void QMLContact::setContact(const QContact& c)
+{
+ m_contact = c;
+
+ if (m_contactMap) {
+ delete m_contactMap;
+ m_detailMaps.clear();
+ }
+
+ foreach (QObject* detail, m_details) {
+ delete detail;
+ }
+ m_details.clear();
+
+ m_contactMap = new QDeclarativePropertyMap(this);
+
+
+ QList<QContactDetail> details = m_contact.details();
+ foreach (const QContactDetail& detail, details) {
+ QMLContactDetail* qd = new QMLContactDetail(this);
+
+ QDeclarativePropertyMap* dm = new QDeclarativePropertyMap(m_contactMap);
+
+ connect(dm, SIGNAL(valueChanged(QString,QVariant)), qd, SLOT(detailChanged(QString,QVariant)));
+
+
+ QVariantMap values = detail.variantValues();
+ foreach (const QString& key, values.keys()) {
+ dm->insert(normalizePropertyName(key), values.value(key));
+ }
+ qd->setName(normalizePropertyName(detail.definitionName()));
+ m_details.append(qd);
+ qd->setDetailPropertyMap(dm);
+ m_detailMaps.append(dm);;
+ m_contactMap->insert(normalizePropertyName(detail.definitionName()), QVariant::fromValue(static_cast<QObject*>(dm)));
+ }
+}
+
+QContact QMLContact::contact() const
+{
+ QContact c(m_contact);
+ foreach (QObject* o, m_details) {
+ QMLContactDetail* d = qobject_cast<QMLContactDetail*>(o);
+ if (d && d->isDetailChanged()) {
+ QContactDetail detail = d->detail();
+ c.saveDetail(&detail);
+ }
+ }
+
+ return c;
+}
+
+QList<QObject*> QMLContact::details() const
+{
+ return m_details;
+}
+
+QVariant QMLContact::contactMap() const
+{
+ if (m_contactMap)
+ return QVariant::fromValue(static_cast<QObject*>(m_contactMap));
+ return QVariant();
+}
+
diff --git a/examples/qmlcontacts/qmlcontact.h b/examples/qmlcontacts/qmlcontact.h
new file mode 100644
index 0000000000..1a2f82f651
--- /dev/null
+++ b/examples/qmlcontacts/qmlcontact.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 Nokia Corporation and its Subsidiary(-ies) 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."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLCONTACT_H
+#define QMLCONTACT_H
+
+#include <QDeclarativePropertyMap>
+#include "qcontact.h"
+
+QTM_USE_NAMESPACE;
+
+class QMLContact : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QMLContact(QObject *parent = 0);
+ void setContact(const QContact& c);
+ QContact contact() const;
+ QVariant contactMap() const;
+ Q_INVOKABLE QList<QObject*> details() const;
+
+private:
+
+ QContact m_contact;
+ QDeclarativePropertyMap* m_contactMap;
+ QList<QDeclarativePropertyMap*> m_detailMaps;
+ QList<QObject*> m_details;
+};
+
+#endif // QMLCONTACT_H
diff --git a/examples/qmlcontacts/qmlcontactdetail.cpp b/examples/qmlcontacts/qmlcontactdetail.cpp
new file mode 100644
index 0000000000..238c1c923c
--- /dev/null
+++ b/examples/qmlcontacts/qmlcontactdetail.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 Nokia Corporation and its Subsidiary(-ies) 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."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmlcontactdetail.h"
+#include "qmlcontactdetailfield.h"
+#include <QDebug>
+
+
+static QString ToContactDetailName(const QString& name)
+{
+ if (!name.isEmpty())
+ return name.mid(1).prepend(name[0].toUpper());
+ return QString();
+}
+
+
+QMLContactDetail::QMLContactDetail(QObject* parent)
+ :QObject(parent),
+ m_contactChanged(false)
+{
+
+}
+
+QDeclarativePropertyMap* QMLContactDetail::propertyMap() const
+{
+ return m_map;
+}
+void QMLContactDetail::setDetailPropertyMap(QDeclarativePropertyMap* map)
+{
+ m_map = map;
+ qWarning() << "detail:" << m_detailName << " has " << m_map->count() << " fields.";
+ foreach (const QString& key, m_map->keys()) {
+ QMLContactDetailField* field = new QMLContactDetailField(this);
+ field->setDetailPropertyMap(m_map);
+ field->setKey(key);
+ m_fields.append(field);
+ qWarning() << " detail field:" << key << "='" << m_map->value(key) << "'";
+ }
+}
+
+QList<QObject*> QMLContactDetail::fields() const
+{
+ return m_fields;
+}
+
+QString QMLContactDetail::name() const
+{
+ return m_detailName;
+}
+
+void QMLContactDetail::setName(const QString& name)
+{
+ m_detailName = name;
+}
+
+bool QMLContactDetail::isDetailChanged() const
+{
+ return m_contactChanged;
+}
+
+QContactDetail QMLContactDetail::detail() const
+{
+ QContactDetail d(ToContactDetailName(name()));
+ foreach (const QString& key, m_map->keys()) {
+ d.setValue(ToContactDetailName(key), m_map->value(key));
+ }
+ return d;
+}
+
+void QMLContactDetail::detailChanged(const QString &key, const QVariant &value)
+{
+ qWarning() << "detailChanged field:" << key << " value:" << value;
+ m_contactChanged = true;
+}
diff --git a/examples/qmlcontacts/qmlcontactdetail.h b/examples/qmlcontacts/qmlcontactdetail.h
new file mode 100644
index 0000000000..f902a9d2e8
--- /dev/null
+++ b/examples/qmlcontacts/qmlcontactdetail.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 Nokia Corporation and its Subsidiary(-ies) 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."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLCONTACTDETAIL_H
+#define QMLCONTACTDETAIL_H
+
+#include <QDeclarativePropertyMap>
+#include "qcontact.h"
+#include "qcontactdetail.h"
+
+QTM_USE_NAMESPACE;
+
+class QMLContactDetail : public QObject
+{
+ Q_OBJECT
+public:
+ Q_PROPERTY(QString name READ name NOTIFY nameChanged)
+
+ explicit QMLContactDetail(QObject* parent = 0);
+ void setDetailPropertyMap(QDeclarativePropertyMap* map);
+ QDeclarativePropertyMap* propertyMap() const;
+ Q_INVOKABLE QList<QObject*> fields() const;
+ Q_INVOKABLE bool isDetailChanged() const;
+ QContactDetail detail() const;
+ QString name() const;
+ void setName(const QString& name);
+
+signals:
+ void nameChanged();
+private slots:
+ void detailChanged(const QString &key, const QVariant &value);
+
+private:
+ bool m_contactChanged;
+ QDeclarativePropertyMap* m_map;
+ QString m_detailName;
+ QList<QObject*> m_fields;
+};
+
+#endif // QMLCONTACTDETAIL_H
diff --git a/examples/qmlcontacts/main.cpp b/examples/qmlcontacts/qmlcontactdetailfield.cpp
index 7c133e9336..8df78fa923 100644
--- a/examples/qmlcontacts/main.cpp
+++ b/examples/qmlcontacts/qmlcontactdetailfield.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -38,38 +38,44 @@
**
****************************************************************************/
-#include <QApplication>
-#include <QtGui>
-#include <QDeclarativeEngine>
-#include <QDeclarativeComponent>
-#include <QDebug>
-#include <QDeclarativeView>
-#include <qcontactmanager.h>
-#include "qmlcontactmodel.h"
-QT_USE_NAMESPACE
-QTM_USE_NAMESPACE
+#include "qmlcontactdetailfield.h"
+#include <QDebug>
-int main(int argc, char ** argv)
+QMLContactDetailField::QMLContactDetailField(QObject* parent)
+ :QObject(parent),
+ m_map(0)
{
- QApplication app(argc, argv);
+}
- QDeclarativeEngine engine;
+void QMLContactDetailField::setDetailPropertyMap(QDeclarativePropertyMap* map)
+{
+ m_map = map;
+}
- qmlRegisterType<QMLContactModel>("QmlContactModel", 1, 0, "QmlContactModel");
+void QMLContactDetailField::setKey(const QString& key)
+{
+ m_key = key;
+}
- QWidget *b = new QWidget();
- QVBoxLayout *vbox = new QVBoxLayout;
- vbox->setMargin(0);
+QString QMLContactDetailField::key() const
+{
+ return m_key;
+}
- QDeclarativeView *view = new QDeclarativeView(b);
- view->setFocusPolicy(Qt::StrongFocus);
- view->setResizeMode(QDeclarativeView::SizeViewToRootObject);
- view->setSource(QUrl("qrc:/example.qml"));
- vbox->addWidget(view);
- b->setLayout(vbox);
- b->show();
+QVariant QMLContactDetailField::value() const
+{
+ if (m_map) {
+ qWarning() << "key:" << m_key << "value:" << m_map->value(m_key);
+ return m_map->value(m_key);
+ }
+ return QVariant();
+}
- return app.exec();
+void QMLContactDetailField::setValue(const QVariant& value)
+{
+ if (m_map && m_map->contains(m_key)) {
+ (*m_map)[m_key] = value;
+ }
}
diff --git a/examples/qmlcontacts/qmlcontactdetailfield.h b/examples/qmlcontacts/qmlcontactdetailfield.h
new file mode 100644
index 0000000000..bf4cc81e30
--- /dev/null
+++ b/examples/qmlcontacts/qmlcontactdetailfield.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 Nokia Corporation and its Subsidiary(-ies) 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."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLCONTACTDETAILFIELD_H
+#define QMLCONTACTDETAILFIELD_H
+
+#include <QDeclarativePropertyMap>
+
+
+
+class QMLContactDetailField : public QObject
+{
+ Q_OBJECT
+public:
+ Q_PROPERTY(QString key READ key NOTIFY keyChanged)
+ Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
+ QMLContactDetailField(QObject* parent = 0);
+
+ void setDetailPropertyMap(QDeclarativePropertyMap* map);
+
+ void setKey(const QString& key);
+ QString key() const;
+
+ QVariant value() const;
+ void setValue(const QVariant& value);
+signals:
+ void keyChanged();
+ void valueChanged();
+private:
+ QDeclarativePropertyMap* m_map;
+ QString m_key;
+};
+
+
+#endif // QMLCONTACTDETAILFIELD_H
diff --git a/examples/qmlcontacts/qmlcontactmodel.cpp b/examples/qmlcontacts/qmlcontactmodel.cpp
index 4927dc6fd6..ad36200da8 100644
--- a/examples/qmlcontacts/qmlcontactmodel.cpp
+++ b/examples/qmlcontacts/qmlcontactmodel.cpp
@@ -45,13 +45,13 @@
#include "qcontactdetailfilter.h"
#include "qversitreader.h"
#include "qversitcontactimporter.h"
-
#include <QColor>
#include <QHash>
#include <QDebug>
#include <QPixmap>
#include <QFile>
+
QMLContactModel::QMLContactModel(QObject *parent) :
QAbstractListModel(parent),
m_manager(0)
@@ -60,6 +60,8 @@ QMLContactModel::QMLContactModel(QObject *parent) :
roleNames = QAbstractItemModel::roleNames();
roleNames.insert(InterestLabelRole, "interestLabel");
roleNames.insert(InterestRole, "interest");
+ roleNames.insert(ContactRole, "contact");
+ roleNames.insert(ContactIdRole, "contactId");
roleNames.insert(AvatarRole, "avatar");
roleNames.insert(PresenceAvailableRole, "presenceSupported");
roleNames.insert(PresenceTextRole, "presenceText");
@@ -97,15 +99,33 @@ QStringList QMLContactModel::availableManagers() const
return QContactManager::availableManagers();
}
-QString QMLContactModel::manager()
+QString QMLContactModel::manager() const
{
return m_manager->managerName();
}
+QList<QObject*> QMLContactModel::details(int id) const
+{
+ if (m_contactMap.contains(id))
+ return m_contactMap.value(id)->details();
+ return QList<QObject*>();
+}
+void QMLContactModel::exposeContactsToQML()
+{
+ foreach (const QContact& c, m_contacts) {
+ if (!m_contactMap.contains(c.localId())) {
+ QMLContact* qc = new QMLContact(this);
+ qc->setContact(c);
+ m_contactMap.insert(c.localId(), qc);
+ } else {
+ m_contactMap.value(c.localId())->setContact(c);
+ }
+ }
+}
void QMLContactModel::fillContactsIntoMemoryEngine(QContactManager* manager)
{
QVersitReader reader;
- QFile file(":/contents/example.vcf");
+ QFile file("contents/example.vcf");
bool ok = file.open(QIODevice::ReadOnly);
if (ok) {
reader.setDevice(&file);
@@ -126,7 +146,14 @@ int QMLContactModel::rowCount(const QModelIndex &parent) const
void QMLContactModel::setManager(const QString& managerName)
{
- delete m_manager;
+ if (m_manager)
+ delete m_manager;
+
+ foreach (const QContactLocalId& id, m_contactMap.keys()) {
+ delete m_contactMap.value(id);
+ }
+ m_contactMap.clear();
+
m_manager = new QContactManager(managerName);
if (managerName == "memory" && m_manager->contactIds().isEmpty()) {
@@ -142,6 +169,7 @@ void QMLContactModel::setManager(const QString& managerName)
void QMLContactModel::resultsReceived()
{
int oldCount = m_contacts.count();
+
int newCount = m_contactsRequest.contacts().count();
if (newCount > oldCount) {
// Assuming the order is the same
@@ -155,6 +183,8 @@ void QMLContactModel::resultsReceived()
m_contacts = m_contactsRequest.contacts();
endInsertRows();
}
+
+ exposeContactsToQML();
}
void QMLContactModel::fetchAgain()
@@ -184,6 +214,8 @@ QPair<QString, QString> QMLContactModel::interestingDetail(const QContact&c) con
return qMakePair(QString(), QString());
}
+
+
QVariant QMLContactModel::data(const QModelIndex &index, int role) const
{
QContact c = m_contacts.value(index.row());
@@ -194,17 +226,15 @@ QVariant QMLContactModel::data(const QModelIndex &index, int role) const
return interestingDetail(c).first;
case InterestRole:
return interestingDetail(c).second;
+ case ContactRole:
+ if (m_contactMap.contains(c.localId())) {
+ return m_contactMap.value(c.localId())->contactMap();
+ }
+ case ContactIdRole:
+ return c.localId();
case AvatarRole:
- if (c.detail<QContactThumbnail>().isEmpty()) {
- QContactAvatar a = c.detail<QContactAvatar>();
- if (!a.imageUrl().isEmpty())
- return a.imageUrl();
- else
- return QString("qrc:/default.svg");
- } else {
- // We have a thumbnail, so return empty
- return QString("");
- }
+ //Just let the imager provider deal with it
+ return QString("image://thumbnail/%1.%2").arg(manager()).arg(c.localId());
case Qt::DecorationRole:
{
QContactThumbnail t = c.detail<QContactThumbnail>();
diff --git a/examples/qmlcontacts/qmlcontactmodel.h b/examples/qmlcontacts/qmlcontactmodel.h
index c91625c09d..506d6a7699 100644
--- a/examples/qmlcontacts/qmlcontactmodel.h
+++ b/examples/qmlcontacts/qmlcontactmodel.h
@@ -42,9 +42,11 @@
#define QMLCONTACTMODEL_H
#include <QAbstractListModel>
+#include <QDeclarativePropertyMap>
#include "qcontact.h"
#include "qcontactmanager.h"
#include "qcontactfetchrequest.h"
+#include "qmlcontact.h"
QTM_USE_NAMESPACE;
class QMLContactModel : public QAbstractListModel
@@ -58,6 +60,9 @@ public:
enum {
InterestRole = Qt::UserRole + 500,
InterestLabelRole,
+ ContactRole,
+ ContactIdRole,
+ DetailsRole,
AvatarRole,
PresenceAvailableRole,
PresenceTextRole,
@@ -67,11 +72,13 @@ public:
QStringList availableManagers() const;
- QString manager();
+ QString manager() const;
void setManager(const QString& manager);
int rowCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
+
+ Q_INVOKABLE QList<QObject*> details(int id) const;
signals:
public slots:
@@ -82,9 +89,11 @@ private slots:
private:
QPair<QString, QString> interestingDetail(const QContact&c) const;
-
+ void exposeContactsToQML();
void fillContactsIntoMemoryEngine(QContactManager* manager);
+
+ QMap<QContactLocalId, QMLContact*> m_contactMap;
QList<QContact> m_contacts;
QContactManager* m_manager;
QContactFetchHint m_fetchHint;
diff --git a/examples/qmlcontacts/qmlcontacts.pro b/examples/qmlcontacts/qmlcontacts.pro
index 74d495d0cd..f1567fae7c 100644
--- a/examples/qmlcontacts/qmlcontacts.pro
+++ b/examples/qmlcontacts/qmlcontacts.pro
@@ -1,8 +1,14 @@
-TEMPLATE = app
-TARGET = qmlcontacts
-CONFIG += mobility
+TEMPLATE = lib
+DESTDIR = com/nokia/mobility
+TARGET = qcontactqmlplugin
+
+CONFIG += qt plugin mobility
+QT += declarative
+
MOBILITY = contacts \
versit
+
+
DEPENDPATH += .
INCLUDEPATH += . \
../../include \
@@ -11,20 +17,34 @@ INCLUDEPATH += . \
../../src/contacts/details \
../../src/contacts/filters \
../../src/versit
-QT += declarative
-QT += script
# Input
-SOURCES += main.cpp \
- qmlcontactmodel.cpp
+HEADERS += qmlcontactmodel.h \
+ imageprovider.h \
+ qmlcontact.h \
+ qmlcontactdetail.h \
+ qmlcontactdetailfield.h
-HEADERS += qmlcontactmodel.h
+SOURCES += plugin.cpp \
+ qmlcontactmodel.cpp \
+ imageprovider.cpp \
+ qmlcontact.cpp \
+ qmlcontactdetail.cpp \
+ qmlcontactdetailfield.cpp
-RESOURCES += qmlcontacts.qrc
OTHER_FILES += example.qml \
contents/example.vcf \
contents/MediaButton.qml \
- ScrollBar.qml
-symbian::TARGET.CAPABILITY = ReadUserData \
- WriteUserData
+ ScrollBar.qml \
+ com/nokia/mobility/qmldir
+
+symbian:{
+ TARGET.EPOCALLOWDLLDATA=1
+ TARGET.CAPABILITY = ReadUserData \
+ WriteUserData \
+ ReadDeviceData \
+ WriteDeviceData \
+ SwEvent
+}
+
include(../examples.pri)
diff --git a/examples/qmlcontacts/qmlcontacts.qrc b/examples/qmlcontacts/qmlcontacts.qrc
deleted file mode 100644
index edab4f43c7..0000000000
--- a/examples/qmlcontacts/qmlcontacts.qrc
+++ /dev/null
@@ -1,11 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>example.qml</file>
- <file>contents/MediaButton.qml</file>
- <file>ScrollBar.qml</file>
- <file>contents/example.vcf</file>
- <file alias="default.svg">contents/default.svg</file>
- <file>contents/pics/button-pressed.png</file>
- <file>contents/pics/button.png</file>
- </qresource>
-</RCC>
diff --git a/examples/sysinfo/sysinfo.pro b/examples/sysinfo/sysinfo.pro
index 5ca26c8e0d..e50fd2048f 100644
--- a/examples/sysinfo/sysinfo.pro
+++ b/examples/sysinfo/sysinfo.pro
@@ -1,6 +1,6 @@
QT += network
-TARGET = sysinfo
+TARGET = qsysinfo
TEMPLATE = app