summaryrefslogtreecommitdiffstats
path: root/doc/html/qaxcontainer-example-qutlook.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/html/qaxcontainer-example-qutlook.html')
-rw-r--r--doc/html/qaxcontainer-example-qutlook.html243
1 files changed, 243 insertions, 0 deletions
diff --git a/doc/html/qaxcontainer-example-qutlook.html b/doc/html/qaxcontainer-example-qutlook.html
new file mode 100644
index 0000000..fb9241f
--- /dev/null
+++ b/doc/html/qaxcontainer-example-qutlook.html
@@ -0,0 +1,243 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/extensions/activeqt/examples/qutlook/qutlook.doc:1 -->
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>In Sync with Outlook</title>
+<style type="text/css"><!--
+fn { margin-left: 1cm; text-indent: -1cm; }
+a:link { color: #004faf; text-decoration: none }
+a:visited { color: #672967; text-decoration: none }
+body { background: #ffffff; color: black; }
+--></style>
+</head>
+<body>
+
+<table border="0" cellpadding="0" cellspacing="0" width="100%">
+<tr bgcolor="#E5E5E5">
+<td valign=center>
+ <a href="index.html">
+<font color="#004faf">Home</font></a>
+ | <a href="classes.html">
+<font color="#004faf">All&nbsp;Classes</font></a>
+ | <a href="mainclasses.html">
+<font color="#004faf">Main&nbsp;Classes</font></a>
+ | <a href="annotated.html">
+<font color="#004faf">Annotated</font></a>
+ | <a href="groups.html">
+<font color="#004faf">Grouped&nbsp;Classes</font></a>
+ | <a href="functions.html">
+<font color="#004faf">Functions</font></a>
+</td>
+<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>In Sync with Outlook</h1>
+
+
+
+This example is a modified version of the standard
+<a href="addressbook-example.html">Qt addressbook</a> example.
+<p> It demonstrates the use of <a href="qaxobject.html">QAxObject</a> and querySubObject to instantiate and
+navigate the Outlook Object Model, and the use of the Qt property system to
+read and write values of items in the Outlook contact folder.
+<p>
+
+The modifications in the class declaration of the central widget are
+a forward declaration of the QAxObject class and the IDispatch interface,
+and a new <a href="qlistviewitem.html">QListViewItem</a> subclass <tt>ABListViewItem</tt> that implements a
+constructor and a destructor and has a member <tt>contact_item</tt> of type
+<a href="qaxobject.html">QAxObject</a>.
+<pre> class QAxObject;
+ struct IDispatch;
+
+ class ABListViewItem : public <a href="qlistviewitem.html">QListViewItem</a>
+ {
+ public:
+ ABListViewItem( <a href="qlistview.html">QListView</a> *listview, QString firstName, QString lastName, QString address, QString eMail, QAxObject *contact );
+ ~ABListViewItem();
+
+ <a href="qaxobject.html">QAxObject</a> *contactItem() const;
+
+ private:
+ <a href="qaxobject.html">QAxObject</a> *contact_item;
+ };
+</pre>
+<p> The ABCentralWidget gets a destructor, a new protected function <tt>setupOutlook</tt>,
+a new protected slot <tt>updateOutlook</tt>, and also three members of type <a href="qaxobject.html">QAxObject</a>.
+<pre> void findEntries();
+
+ void updateOutlook();
+
+ protected:
+ void setupTabWidget();
+ void setupListView();
+ void setupOutlook();
+
+ <a href="qaxobject.html">QAxObject</a> *outlook, *outlookSession, *contactItems;
+
+ <a href="qgridlayout.html">QGridLayout</a> *mainGrid;
+</pre>
+<p>
+
+The implementation of the ABListViewItem class is trivial:
+<pre> ABListViewItem::ABListViewItem( <a href="qlistview.html">QListView</a> *listview,
+ <a href="qstring.html">QString</a> firstName,
+ <a href="qstring.html">QString</a> lastName,
+ <a href="qstring.html">QString</a> address,
+ <a href="qstring.html">QString</a> eMail,
+ <a href="qaxobject.html">QAxObject</a> *contact )
+ : <a href="qlistviewitem.html">QListViewItem</a>( listview, firstName, lastName, address, eMail ), contact_item( contact )
+ {
+ }
+
+ ABListViewItem::~ABListViewItem()
+ {
+ delete contact_item;
+ }
+
+ QAxObject *ABListViewItem::contactItem() const
+ {
+ return contact_item;
+ }
+</pre>The ABCentralWidget constructor initializes the <a href="qaxobject.html">QAxObject</a> pointers to zero and
+calls the <tt>setupOutlook</tt> function. The ABCentralWidget destructor calls the
+Logoff method of the outlookSession object.
+<pre> ABCentralWidget::ABCentralWidget( <a href="qwidget.html">QWidget</a> *parent, const char *name )
+ : <a href="qwidget.html">QWidget</a>( parent, name ), outlook( 0 ), outlookSession( 0 ), contactItems( 0 )
+ {
+ mainGrid = new <a href="qgridlayout.html">QGridLayout</a>( this, 2, 1, 5, 5 );
+
+ setupTabWidget();
+ setupListView();
+ setupOutlook();
+
+ <a name="x2722"></a> mainGrid-&gt;<a href="qgridlayout.html#setRowStretch">setRowStretch</a>( 0, 0 );
+ mainGrid-&gt;<a href="qgridlayout.html#setRowStretch">setRowStretch</a>( 1, 1 );
+ }
+
+ ABCentralWidget::~ABCentralWidget()
+ {
+ if ( outlookSession )
+ outlookSession-&gt;dynamicCall( "Logoff()" );
+ }
+</pre>The <tt>setupOutlook</tt> implementation creates a QAxObject to wrap the
+Outlook.Application COM object.
+<pre> void ABCentralWidget::setupOutlook()
+ {
+ outlook = new <a href="qaxobject.html">QAxObject</a>( "Outlook.Application", this );
+</pre>The call to <tt>querySubObject</tt> returns a new <a href="qaxobject.html">QAxObject</a> wrapper around the
+"Session" object of the Outlook Object hierarchy. If the call fails for
+some reason setupOutlook returns, otherwise it calls the "Logon" method
+of the Session object.
+<pre> // Get a session object
+ <a name="x2721"></a> outlookSession = outlook-&gt;<a href="qaxbase.html#querySubObject">querySubObject</a>( "Session" );
+ if ( !outlookSession )
+ return;
+ // Login; doesn't hurt if you are already running and logged on...
+ outlookSession-&gt;dynamicCall( "Logon()" );
+</pre>The following call to <tt>querySubObject</tt> returns a new QAxObject wrapper
+around the default folder for "contacts".
+<pre> // Get the default folder for contacts
+ <a href="qaxobject.html">QAxObject</a> *defFolder = outlookSession-&gt;querySubObject( "GetDefaultFolder(OlDefaultFolders)", "olFolderContacts" );
+</pre><tt>querySubObject</tt> is then used again to get the list of all items in the
+folder. The <tt>connect</tt> statement connects the new ABCentralWidget slot
+to the signals provided by the "Items" COM object. Finally, it calls the
+<tt>updateOutlook</tt> function to populate the listview.
+<pre> // Get all items
+ if ( defFolder ) {
+ contactItems = defFolder-&gt;<a href="qaxbase.html#querySubObject">querySubObject</a>( "Items" );
+ <a href="qobject.html#connect">connect</a>( contactItems, SIGNAL(ItemAdd(IDispatch*)), this, SLOT(updateOutlook()) );
+ <a href="qobject.html#connect">connect</a>( contactItems, SIGNAL(ItemChange(IDispatch*)), this, SLOT(updateOutlook()) );
+ <a href="qobject.html#connect">connect</a>( contactItems, SIGNAL(ItemRemove()), this, SLOT(updateOutlook()) );
+ }
+
+ updateOutlook();
+ }
+</pre>
+<p> The implementation of the <tt>updateOutlook</tt> slot clears the listview, and uses
+<tt>querySubObject</tt> to iterate through the list of items. For every item provided a new
+ABListViewItem object is created and filled with the properties of the item
+object. The object returned by <tt>querySubObject</tt> is a child of the callee (ie. "contactItems"),
+but the list view item should take ownership to provide a cleaner relation between
+entries, so the item has to be removed from its parent object.
+<pre> void ABCentralWidget::updateOutlook()
+ {
+ <a name="x2725"></a> listView-&gt;<a href="qlistview.html#clear">clear</a>();
+ if ( !contactItems )
+ return;
+
+ <a href="qaxobject.html">QAxObject</a> *item = contactItems-&gt;querySubObject( "GetFirst()" );
+ while ( item ) {
+ <a name="x2729"></a> <a href="qstring.html">QString</a> firstName = item-&gt;<a href="qobject.html#property">property</a>( "FirstName" ).toString();
+ <a href="qstring.html">QString</a> lastName = item-&gt;<a href="qobject.html#property">property</a>( "LastName" ).toString();
+ <a href="qstring.html">QString</a> address = item-&gt;<a href="qobject.html#property">property</a>( "HomeAddress" ).toString();
+ <a href="qstring.html">QString</a> email = item-&gt;<a href="qobject.html#property">property</a>( "Email1Address" ).toString();
+
+ (void)new ABListViewItem( listView, firstName, lastName, address, email, item );
+ // the listviewitem takes ownership
+ <a name="x2727"></a> item-&gt;<a href="qlistviewitem.html#parent">parent</a>()-&gt;removeChild( item );
+
+ item = contactItems-&gt;querySubObject( "GetNext()" );
+ }
+ }
+</pre>
+<p> The <tt>addEntry</tt> implementation calls the CreateItem method of the Outlook.Application
+object to create a new contact item, and creates a new ABListViewItem if the call
+succeeds.
+<pre> void ABCentralWidget::addEntry()
+ {
+ <a name="x2724"></a> if ( !iFirstName-&gt;<a href="qlineedit.html#text">text</a>().isEmpty() || !iLastName-&gt;<a href="qlineedit.html#text">text</a>().isEmpty() ||
+ !iAddress-&gt;<a href="qlineedit.html#text">text</a>().isEmpty() || !iEMail-&gt;<a href="qlineedit.html#text">text</a>().isEmpty() ) {
+ <a href="qaxobject.html">QAxObject</a> *contactItem = outlook-&gt;<a href="qaxbase.html#querySubObject">querySubObject</a>( "CreateItem(OlItemType)", "olContactItem" );
+ if ( contactItem ) {
+ <a name="x2730"></a> contactItem-&gt;<a href="qobject.html#setProperty">setProperty</a>( "FirstName", iFirstName-&gt;<a href="qlineedit.html#text">text</a>() );
+ contactItem-&gt;<a href="qobject.html#setProperty">setProperty</a>( "LastName", iLastName-&gt;<a href="qlineedit.html#text">text</a>() );
+ contactItem-&gt;<a href="qobject.html#setProperty">setProperty</a>( "HomeAddress", iAddress-&gt;<a href="qlineedit.html#text">text</a>() );
+ contactItem-&gt;<a href="qobject.html#setProperty">setProperty</a>( "Email1Address", iEMail-&gt;<a href="qlineedit.html#text">text</a>() );
+ <a name="x2720"></a> contactItem-&gt;<a href="qaxbase.html#dynamicCall">dynamicCall</a>( "Save()" );
+
+ new ABListViewItem( listView, iFirstName-&gt;<a href="qlineedit.html#text">text</a>(),
+ iLastName-&gt;<a href="qlineedit.html#text">text</a>(), iAddress-&gt;<a href="qlineedit.html#text">text</a>(), iEMail-&gt;<a href="qlineedit.html#text">text</a>(), contactItem );
+ }
+ }
+
+ <a name="x2723"></a> iFirstName-&gt;<a href="qlineedit.html#setText">setText</a>( "" );
+ iLastName-&gt;<a href="qlineedit.html#setText">setText</a>( "" );
+ iAddress-&gt;<a href="qlineedit.html#setText">setText</a>( "" );
+ iEMail-&gt;<a href="qlineedit.html#setText">setText</a>( "" );
+ }
+</pre>
+<p> The <tt>changeEntry</tt> implementation updates the values in the contact item of the current
+listview item as well as the values of the listview item itself.
+<pre> void ABCentralWidget::changeEntry()
+ {
+ <a name="x2726"></a> ABListViewItem *item = (ABListViewItem*)listView-&gt;<a href="qlistview.html#currentItem">currentItem</a>();
+
+ if ( item &amp;&amp;
+ ( !iFirstName-&gt;<a href="qlineedit.html#text">text</a>().isEmpty() || !iLastName-&gt;<a href="qlineedit.html#text">text</a>().isEmpty() ||
+ !iAddress-&gt;<a href="qlineedit.html#text">text</a>().isEmpty() || !iEMail-&gt;<a href="qlineedit.html#text">text</a>().isEmpty() ) ) {
+
+ <a href="qaxobject.html">QAxObject</a> *contactItem = item-&gt;contactItem();
+ contactItem-&gt;<a href="qobject.html#setProperty">setProperty</a>( "FirstName", iFirstName-&gt;<a href="qlineedit.html#text">text</a>() );
+ contactItem-&gt;<a href="qobject.html#setProperty">setProperty</a>( "LastName", iLastName-&gt;<a href="qlineedit.html#text">text</a>() );
+ contactItem-&gt;<a href="qobject.html#setProperty">setProperty</a>( "HomeAddress", iAddress-&gt;<a href="qlineedit.html#text">text</a>() );
+ contactItem-&gt;<a href="qobject.html#setProperty">setProperty</a>( "Email1Address", iEMail-&gt;<a href="qlineedit.html#text">text</a>() );
+ contactItem-&gt;<a href="qaxbase.html#dynamicCall">dynamicCall</a>( "Save()" );
+
+ <a name="x2728"></a> item-&gt;<a href="qlistviewitem.html#setText">setText</a>( 0, iFirstName-&gt;<a href="qlineedit.html#text">text</a>() );
+ item-&gt;<a href="qlistviewitem.html#setText">setText</a>( 1, iLastName-&gt;<a href="qlineedit.html#text">text</a>() );
+ item-&gt;<a href="qlistviewitem.html#setText">setText</a>( 2, iAddress-&gt;<a href="qlineedit.html#text">text</a>() );
+ item-&gt;<a href="qlistviewitem.html#setText">setText</a>( 3, iEMail-&gt;<a href="qlineedit.html#text">text</a>() );
+ }
+ }
+</pre>
+<p> To build the example you must first build the <a href="qaxcontainer.html">QAxContainer</a>
+library. Then run your make tool in <tt>examples/qutlook</tt> and run the resulting <tt>qutlok.exe</tt>.
+<p>See also <a href="qaxcontainer-examples.html">The QAxContainer Examples</a>.
+
+<!-- eof -->
+<p><address><hr><div align=center>
+<table width=100% cellspacing=0 border=0><tr>
+<td>Copyright &copy; 2007
+<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
+<td align=right><div align=right>Qt 3.3.8</div>
+</table></div></address></body>
+</html>