You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tqt3/doc/html/archivesearch-example.html

184 lines
8.0 KiB

<!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/examples/network/archivesearch/archivesearch.doc:5 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>A qt-interest mail archive search</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>A qt-interest mail archive search</h1>
<p>
<p> This example does a search on the qt-interest mailinglist archives. It uses
<a href="ntqhttp.html">TQHttp</a> to issue the search command and to fetch the results. The GUI parts
were done using <a href="designer-manual.html">TQt Designer</a>.
<p> <hr>
<p> The implementation of the HTTP requests (archivedialog.ui.h):
<p> <pre>/****************************************************************************
** $Id: qt/archivedialog.ui.h 3.3.8 edited Jan 29 15:54 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for TQt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** TQt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
void ArchiveDialog::init()
{
connect(&amp;articleSearcher, SIGNAL(done(bool)), this, SLOT(searchDone(bool)));
connect(&amp;articleFetcher, SIGNAL(done(bool)), this, SLOT(fetchDone(bool)));
connect(myListView, SIGNAL(selectionChanged(TQListViewItem*)), this, SLOT(fetch(TQListViewItem*)));
connect(myLineEdit, SIGNAL(returnPressed()), this, SLOT(search()));
connect(myListView, SIGNAL(returnPressed(TQListViewItem*)), this, SLOT(fetch(TQListViewItem*)));
connect(myPushButton, SIGNAL(clicked()), this, SLOT(close()));
}
void ArchiveDialog::fetch( <a href="qlistviewitem.html">TQListViewItem</a> *it )
{
<a name="x477"></a> <a href="ntqurl.html">TQUrl</a> u(it-&gt;<a href="qlistviewitem.html#text">text</a>(1));
<a name="x485"></a> articleFetcher.setHost(u.<a href="ntqurl.html#host">host</a>());
articleFetcher.get(it-&gt;<a href="qlistviewitem.html#text">text</a>(1));
}
void ArchiveDialog::fetchDone( bool error )
{
if (error) {
<a name="x478"></a> TQMessageBox::<a href="ntqmessagebox.html#critical">critical</a>(this, "Error fetching",
"An error occurred when fetching this document: "
+ articleFetcher.errorString(),
TQMessageBox::Ok, TQMessageBox::NoButton);
} else {
myTextBrowser-&gt;setText(articleFetcher.readAll());
}
}
void ArchiveDialog::search()
{
if (articleSearcher.state() == TQHttp::HostLookup
|| articleSearcher.state() == TQHttp::Connecting
|| articleSearcher.state() == TQHttp::Sending
|| articleSearcher.state() == TQHttp::Reading) {
articleSearcher.abort();
}
if (myLineEdit-&gt;text() == "") {
TQMessageBox::<a href="ntqmessagebox.html#critical">critical</a>(this, "Empty query",
"Please type a search string.",
TQMessageBox::Ok, TQMessageBox::NoButton);
} else {
<a name="x474"></a> TQApplication::<a href="ntqapplication.html#setOverrideCursor">setOverrideCursor</a>(TQCursor(TQt::WaitCursor));
articleSearcher.setHost("lists.trolltech.com");
<a href="qhttprequestheader.html">TQHttpRequestHeader</a> header("POST", "/qt-interest/search.php");
<a name="x476"></a> header.<a href="qhttpheader.html#setValue">setValue</a>("Host", "lists.trolltech.com");
<a name="x475"></a> header.<a href="qhttpheader.html#setContentType">setContentType</a>("application/x-www-form-urlencoded");
<a href="ntqstring.html">TQString</a> encodedTopic = myLineEdit-&gt;text();
<a name="x484"></a> TQUrl::<a href="ntqurl.html#encode">encode</a>(encodedTopic);
<a href="ntqstring.html">TQString</a> searchString = "qt-interest=on&amp;search=" + encodedTopic;
<a name="x483"></a> articleSearcher.request(header, searchString.<a href="ntqstring.html#utf8">utf8</a>());
}
}
void ArchiveDialog::searchDone( bool error )
{
if (error) {
TQMessageBox::<a href="ntqmessagebox.html#critical">critical</a>(this, "Error searching",
"An error occurred when searching: "
+ articleSearcher.errorString(),
TQMessageBox::Ok, TQMessageBox::NoButton);
} else {
<a href="ntqstring.html">TQString</a> result(articleSearcher.readAll());
<a href="ntqregexp.html">TQRegExp</a> rx("&lt;a href=\"(http://lists\\.trolltech\\.com/qt-interest/.*)\"&gt;(.*)&lt;/a&gt;");
<a name="x482"></a> rx.<a href="ntqregexp.html#setMinimal">setMinimal</a>(TRUE);
int pos = 0;
while (pos &gt;= 0) {
<a name="x481"></a> pos = rx.<a href="ntqregexp.html#search">search</a>(result, pos);
if (pos &gt; -1) {
<a name="x480"></a> pos += rx.<a href="ntqregexp.html#matchedLength">matchedLength</a>();
<a name="x479"></a> new <a href="qlistviewitem.html">TQListViewItem</a>(myListView, rx.<a href="ntqregexp.html#cap">cap</a>(2), rx.<a href="ntqregexp.html#cap">cap</a>(1));
}
}
}
<a name="x473"></a> TQApplication::<a href="ntqapplication.html#restoreOverrideCursor">restoreOverrideCursor</a>();
}
</pre>
<p> <hr>
<p> Main (main.cpp):
<p> <pre>/****************************************************************************
** $Id: qt/main.cpp 3.3.8 edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for TQt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include "archivedialog.h"
#include &lt;<a href="qapplication-h.html">ntqapplication.h</a>&gt;
int main(int argc, char **argv)
{
<a href="ntqapplication.html">TQApplication</a> a( argc, argv );
ArchiveDialog ad;
ad.show();
<a name="x489"></a><a name="x487"></a> TQObject::<a href="ntqobject.html#connect">connect</a>( &amp;a, SIGNAL(<a href="ntqapplication.html#lastWindowClosed">lastWindowClosed</a>()),
<a name="x488"></a> &amp;a, SLOT(<a href="ntqapplication.html#quit">quit</a>()) );
<a name="x486"></a> return a.<a href="ntqapplication.html#exec">exec</a>();
}
</pre>
<p>See also <a href="network-examples.html">Network 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>TQt 3.3.8</div>
</table></div></address></body>
</html>