diff options
author | axis <qt-info@nokia.com> | 2009-04-24 11:34:15 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-04-24 11:34:15 (GMT) |
commit | 8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76 (patch) | |
tree | a17e1a767a89542ab59907462206d7dcf2e504b2 /examples/activeqt/qutlook | |
download | Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.zip Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.tar.gz Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.tar.bz2 |
Long live Qt for S60!
Diffstat (limited to 'examples/activeqt/qutlook')
-rw-r--r-- | examples/activeqt/qutlook/addressview.cpp | 289 | ||||
-rw-r--r-- | examples/activeqt/qutlook/addressview.h | 79 | ||||
-rw-r--r-- | examples/activeqt/qutlook/fileopen.xpm | 22 | ||||
-rw-r--r-- | examples/activeqt/qutlook/fileprint.xpm | 24 | ||||
-rw-r--r-- | examples/activeqt/qutlook/filesave.xpm | 22 | ||||
-rw-r--r-- | examples/activeqt/qutlook/main.cpp | 56 | ||||
-rw-r--r-- | examples/activeqt/qutlook/qutlook.pro | 25 |
7 files changed, 517 insertions, 0 deletions
diff --git a/examples/activeqt/qutlook/addressview.cpp b/examples/activeqt/qutlook/addressview.cpp new file mode 100644 index 0000000..281fe6a --- /dev/null +++ b/examples/activeqt/qutlook/addressview.cpp @@ -0,0 +1,289 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#include "addressview.h" +#include "msoutl.h" +#include <QtGui> + +class AddressBookModel : public QAbstractListModel +{ +public: + AddressBookModel(AddressView *parent); + ~AddressBookModel(); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + QVariant data(const QModelIndex &index, int role) const; + + void changeItem(const QModelIndex &index, const QString &firstName, const QString &lastName, const QString &address, const QString &email); + void addItem(const QString &firstName, const QString &lastName, const QString &address, const QString &email); + void update(); + +private: + Outlook::Application outlook; + Outlook::Items * contactItems; + + mutable QHash<QModelIndex, QStringList> cache; +}; +//! [0] //! [1] + +AddressBookModel::AddressBookModel(AddressView *parent) +: QAbstractListModel(parent) +{ + if (!outlook.isNull()) { + Outlook::NameSpace session(outlook.Session()); + session.Logon(); + Outlook::MAPIFolder *folder = session.GetDefaultFolder(Outlook::olFolderContacts); + contactItems = new Outlook::Items(folder->Items()); + connect(contactItems, SIGNAL(ItemAdd(IDispatch*)), parent, SLOT(updateOutlook())); + connect(contactItems, SIGNAL(ItemChange(IDispatch*)), parent, SLOT(updateOutlook())); + connect(contactItems, SIGNAL(ItemRemove()), parent, SLOT(updateOutlook())); + + delete folder; + } +} + +//! [1] //! [2] +AddressBookModel::~AddressBookModel() +{ + delete contactItems; + + if (!outlook.isNull()) + Outlook::NameSpace(outlook.Session()).Logoff(); +} + +//! [2] //! [3] +int AddressBookModel::rowCount(const QModelIndex &) const +{ + return contactItems ? contactItems->Count() : 0; +} + +int AddressBookModel::columnCount(const QModelIndex &parent) const +{ + return 4; +} + +//! [3] //! [4] +QVariant AddressBookModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + switch (section) { + case 0: + return tr("First Name"); + case 1: + return tr("Last Name"); + case 2: + return tr("Address"); + case 3: + return tr("Email"); + default: + break; + } + + return QVariant(); +} + +//! [4] //! [5] +QVariant AddressBookModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid() || role != Qt::DisplayRole) + return QVariant(); + + QStringList data; + if (cache.contains(index)) { + data = cache.value(index); + } else { + Outlook::ContactItem contact(contactItems->Item(index.row() + 1)); + data << contact.FirstName() << contact.LastName() << contact.HomeAddress() << contact.Email1Address(); + cache.insert(index, data); + } + + if (index.column() < data.count()) + return data.at(index.column()); + + return QVariant(); +} + +//! [5] //! [6] +void AddressBookModel::changeItem(const QModelIndex &index, const QString &firstName, const QString &lastName, const QString &address, const QString &email) +{ + Outlook::ContactItem item(contactItems->Item(index.row() + 1)); + + item.SetFirstName(firstName); + item.SetLastName(lastName); + item.SetHomeAddress(address); + item.SetEmail1Address(email); + + item.Save(); + + cache.take(index); +} + +//! [6] //! [7] +void AddressBookModel::addItem(const QString &firstName, const QString &lastName, const QString &address, const QString &email) +{ + Outlook::ContactItem item(outlook.CreateItem(Outlook::olContactItem)); + if (!item.isNull()) { + item.SetFirstName(firstName); + item.SetLastName(lastName); + item.SetHomeAddress(address); + item.SetEmail1Address(email); + + item.Save(); + } +} + +//! [7] //! [8] +void AddressBookModel::update() +{ + cache.clear(); + + emit reset(); +} + + +//! [8] //! [9] +AddressView::AddressView(QWidget *parent) +: QWidget(parent) +{ + QGridLayout *mainGrid = new QGridLayout(this); + + QLabel *liFirstName = new QLabel("First &Name", this); + liFirstName->resize(liFirstName->sizeHint()); + mainGrid->addWidget(liFirstName, 0, 0); + + QLabel *liLastName = new QLabel("&Last Name", this); + liLastName->resize(liLastName->sizeHint()); + mainGrid->addWidget(liLastName, 0, 1); + + QLabel *liAddress = new QLabel("Add&ress", this); + liAddress->resize(liAddress->sizeHint()); + mainGrid->addWidget(liAddress, 0, 2); + + QLabel *liEMail = new QLabel("&E-Mail", this); + liEMail->resize(liEMail->sizeHint()); + mainGrid->addWidget(liEMail, 0, 3); + + add = new QPushButton("A&dd", this); + add->resize(add->sizeHint()); + mainGrid->addWidget(add, 0, 4); + connect(add, SIGNAL(clicked()), this, SLOT(addEntry())); + + iFirstName = new QLineEdit(this); + iFirstName->resize(iFirstName->sizeHint()); + mainGrid->addWidget(iFirstName, 1, 0); + liFirstName->setBuddy(iFirstName); + + iLastName = new QLineEdit(this); + iLastName->resize(iLastName->sizeHint()); + mainGrid->addWidget(iLastName, 1, 1); + liLastName->setBuddy(iLastName); + + iAddress = new QLineEdit(this); + iAddress->resize(iAddress->sizeHint()); + mainGrid->addWidget(iAddress, 1, 2); + liAddress->setBuddy(iAddress); + + iEMail = new QLineEdit(this); + iEMail->resize(iEMail->sizeHint()); + mainGrid->addWidget(iEMail, 1, 3); + liEMail->setBuddy(iEMail); + + change = new QPushButton("&Change", this); + change->resize(change->sizeHint()); + mainGrid->addWidget(change, 1, 4); + connect(change, SIGNAL(clicked()), this, SLOT(changeEntry())); + + treeView = new QTreeView(this); + treeView->setSelectionMode(QTreeView::SingleSelection); + treeView->setRootIsDecorated(false); + + model = new AddressBookModel(this); + treeView->setModel(model); + + connect(treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(itemSelected(QModelIndex))); + + mainGrid->addWidget(treeView, 2, 0, 1, 5); +} + +void AddressView::updateOutlook() +{ + model->update(); +} + +void AddressView::addEntry() +{ + if (!iFirstName->text().isEmpty() || !iLastName->text().isEmpty() || + !iAddress->text().isEmpty() || !iEMail->text().isEmpty()) { + model->addItem(iFirstName->text(), iFirstName->text(), iAddress->text(), iEMail->text()); + } + + iFirstName->setText(""); + iLastName->setText(""); + iAddress->setText(""); + iEMail->setText(""); +} + +void AddressView::changeEntry() +{ + QModelIndex current = treeView->currentIndex(); + + if (current.isValid()) + model->changeItem(current, iFirstName->text(), iLastName->text(), iAddress->text(), iEMail->text()); +} + +//! [9] //! [10] +void AddressView::itemSelected(const QModelIndex &index) +{ + if (!index.isValid()) + return; + + QAbstractItemModel *model = treeView->model(); + iFirstName->setText(model->data(model->index(index.row(), 0)).toString()); + iLastName->setText(model->data(model->index(index.row(), 1)).toString()); + iAddress->setText(model->data(model->index(index.row(), 2)).toString()); + iEMail->setText(model->data(model->index(index.row(), 3)).toString()); +} +//! [10] diff --git a/examples/activeqt/qutlook/addressview.h b/examples/activeqt/qutlook/addressview.h new file mode 100644 index 0000000..5363cc1 --- /dev/null +++ b/examples/activeqt/qutlook/addressview.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ADDRESSVIEW_H +#define ADDRESSVIEW_H + +#include <QWidget> + +class AddressBookModel; +QT_BEGIN_NAMESPACE +class QLineEdit; +class QModelIndex; +class QPushButton; +class QTreeView; +QT_END_NAMESPACE + +//! [0] +class AddressView : public QWidget +{ + Q_OBJECT + +public: + AddressView(QWidget *parent = 0); + +protected slots: + void addEntry(); + void changeEntry(); + void itemSelected(const QModelIndex &index); + + void updateOutlook(); + +protected: + AddressBookModel *model; + + QTreeView *treeView; + QPushButton *add, *change; + QLineEdit *iFirstName, *iLastName, *iAddress, *iEMail; +}; +//! [0] + +#endif // ADDRESSVIEW_H diff --git a/examples/activeqt/qutlook/fileopen.xpm b/examples/activeqt/qutlook/fileopen.xpm new file mode 100644 index 0000000..880417e --- /dev/null +++ b/examples/activeqt/qutlook/fileopen.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *fileopen[] = { +" 16 13 5 1", +". c #040404", +"# c #808304", +"a c None", +"b c #f3f704", +"c c #f3f7f3", +"aaaaaaaaa...aaaa", +"aaaaaaaa.aaa.a.a", +"aaaaaaaaaaaaa..a", +"a...aaaaaaaa...a", +".bcb.......aaaaa", +".cbcbcbcbc.aaaaa", +".bcbcbcbcb.aaaaa", +".cbcb...........", +".bcb.#########.a", +".cb.#########.aa", +".b.#########.aaa", +"..#########.aaaa", +"...........aaaaa" +}; diff --git a/examples/activeqt/qutlook/fileprint.xpm b/examples/activeqt/qutlook/fileprint.xpm new file mode 100644 index 0000000..6ada912 --- /dev/null +++ b/examples/activeqt/qutlook/fileprint.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static const char *fileprint[] = { +" 16 14 6 1", +". c #000000", +"# c #848284", +"a c #c6c3c6", +"b c #ffff00", +"c c #ffffff", +"d c None", +"ddddd.........dd", +"dddd.cccccccc.dd", +"dddd.c.....c.ddd", +"ddd.cccccccc.ddd", +"ddd.c.....c....d", +"dd.cccccccc.a.a.", +"d..........a.a..", +".aaaaaaaaaa.a.a.", +".............aa.", +".aaaaaa###aa.a.d", +".aaaaaabbbaa...d", +".............a.d", +"d.aaaaaaaaa.a.dd", +"dd...........ddd" +}; diff --git a/examples/activeqt/qutlook/filesave.xpm b/examples/activeqt/qutlook/filesave.xpm new file mode 100644 index 0000000..bd6870f --- /dev/null +++ b/examples/activeqt/qutlook/filesave.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *filesave[] = { +" 14 14 4 1", +". c #040404", +"# c #808304", +"a c #bfc2bf", +"b c None", +"..............", +".#.aaaaaaaa.a.", +".#.aaaaaaaa...", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".##........##.", +".############.", +".##.........#.", +".##......aa.#.", +".##......aa.#.", +".##......aa.#.", +"b............." +}; diff --git a/examples/activeqt/qutlook/main.cpp b/examples/activeqt/qutlook/main.cpp new file mode 100644 index 0000000..b015d8a --- /dev/null +++ b/examples/activeqt/qutlook/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +#include "addressview.h" +#include <QApplication> + +int main(int argc, char ** argv) +{ + QApplication a(argc, argv); + + AddressView view; + view.setWindowTitle("Qt Example - Looking at Outlook"); + view.show(); + + return a.exec(); +} +//! [0] diff --git a/examples/activeqt/qutlook/qutlook.pro b/examples/activeqt/qutlook/qutlook.pro new file mode 100644 index 0000000..0387735 --- /dev/null +++ b/examples/activeqt/qutlook/qutlook.pro @@ -0,0 +1,25 @@ +#! [0] #! [1] +TEMPLATE = app +TARGET = qutlook +CONFIG += qaxcontainer + +TYPELIBS = $$system(dumpcpp -getfile {00062FFF-0000-0000-C000-000000000046}) +#! [0] + +isEmpty(TYPELIBS) { + message("Microsoft Outlook type library not found!") + REQUIRES += Outlook +} else { +#! [1] #! [2] + HEADERS = addressview.h + SOURCES = addressview.cpp main.cpp +} +#! [2] + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/qutlook +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS qutlook.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/activeqt/qutlook +INSTALLS += target sources + +include($$QT_SOURCE_TREE/examples/examplebase.pri) |