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

183 lines
7.9 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<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="tqhttp.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 tquic-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, TQ_SIGNAL(done(bool)), this, TQ_SLOT(searchDone(bool)));
connect(&amp;articleFetcher, TQ_SIGNAL(done(bool)), this, TQ_SLOT(fetchDone(bool)));
connect(myListView, TQ_SIGNAL(selectionChanged(TQListViewItem*)), this, TQ_SLOT(fetch(TQListViewItem*)));
connect(myLineEdit, TQ_SIGNAL(returnPressed()), this, TQ_SLOT(search()));
connect(myListView, TQ_SIGNAL(returnPressed(TQListViewItem*)), this, TQ_SLOT(fetch(TQListViewItem*)));
connect(myPushButton, TQ_SIGNAL(clicked()), this, TQ_SLOT(close()));
}
void ArchiveDialog::fetch( <a href="tqlistviewitem.html">TQListViewItem</a> *it )
{
<a name="x477"></a> <a href="tqurl.html">TQUrl</a> u(it-&gt;<a href="tqlistviewitem.html#text">text</a>(1));
<a name="x485"></a> articleFetcher.setHost(u.<a href="tqurl.html#host">host</a>());
articleFetcher.get(it-&gt;<a href="tqlistviewitem.html#text">text</a>(1));
}
void ArchiveDialog::fetchDone( bool error )
{
if (error) {
<a name="x478"></a> TQMessageBox::<a href="tqmessagebox.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="tqmessagebox.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="tqhttprequestheader.html">TQHttpRequestHeader</a> header("POST", "/qt-interest/search.php");
<a name="x476"></a> header.<a href="tqhttpheader.html#setValue">setValue</a>("Host", "lists.trolltech.com");
<a name="x475"></a> header.<a href="tqhttpheader.html#setContentType">setContentType</a>("application/x-www-form-urlencoded");
<a href="tqstring.html">TQString</a> encodedTopic = myLineEdit-&gt;text();
<a name="x484"></a> TQUrl::<a href="tqurl.html#encode">encode</a>(encodedTopic);
<a href="tqstring.html">TQString</a> searchString = "qt-interest=on&amp;search=" + encodedTopic;
<a name="x483"></a> articleSearcher.request(header, searchString.<a href="tqstring.html#utf8">utf8</a>());
}
}
void ArchiveDialog::searchDone( bool error )
{
if (error) {
TQMessageBox::<a href="tqmessagebox.html#critical">critical</a>(this, "Error searching",
"An error occurred when searching: "
+ articleSearcher.errorString(),
TQMessageBox::Ok, TQMessageBox::NoButton);
} else {
<a href="tqstring.html">TQString</a> result(articleSearcher.readAll());
<a href="tqregexp.html">TQRegExp</a> rx("&lt;a href=\"(http://lists\\.trolltech\\.com/qt-interest/.*)\"&gt;(.*)&lt;/a&gt;");
<a name="x482"></a> rx.<a href="tqregexp.html#setMinimal">setMinimal</a>(TRUE);
int pos = 0;
while (pos &gt;= 0) {
<a name="x481"></a> pos = rx.<a href="tqregexp.html#search">search</a>(result, pos);
if (pos &gt; -1) {
<a name="x480"></a> pos += rx.<a href="tqregexp.html#matchedLength">matchedLength</a>();
<a name="x479"></a> new <a href="tqlistviewitem.html">TQListViewItem</a>(myListView, rx.<a href="tqregexp.html#cap">cap</a>(2), rx.<a href="tqregexp.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="tqobject.html#connect">connect</a>( &amp;a, TQ_SIGNAL(<a href="ntqapplication.html#lastWindowClosed">lastWindowClosed</a>()),
<a name="x488"></a> &amp;a, TQ_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>