[190] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/network/archivesearch/archivesearch.doc:5 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>A qt-interest mail archive search</title>
|
---|
| 7 | <style type="text/css"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { background: #ffffff; color: black; }
|
---|
| 12 | --></style>
|
---|
| 13 | </head>
|
---|
| 14 | <body>
|
---|
| 15 |
|
---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
| 17 | <tr bgcolor="#E5E5E5">
|
---|
| 18 | <td valign=center>
|
---|
| 19 | <a href="index.html">
|
---|
| 20 | <font color="#004faf">Home</font></a>
|
---|
| 21 | | <a href="classes.html">
|
---|
| 22 | <font color="#004faf">All Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main Classes</font></a>
|
---|
| 25 | | <a href="annotated.html">
|
---|
| 26 | <font color="#004faf">Annotated</font></a>
|
---|
| 27 | | <a href="groups.html">
|
---|
| 28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
| 29 | | <a href="functions.html">
|
---|
| 30 | <font color="#004faf">Functions</font></a>
|
---|
| 31 | </td>
|
---|
| 32 | <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>
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | <p>
|
---|
| 36 | <p> This example does a search on the qt-interest mailinglist archives. It uses
|
---|
| 37 | <a href="qhttp.html">QHttp</a> to issue the search command and to fetch the results. The GUI parts
|
---|
| 38 | were done using <a href="designer-manual.html">Qt Designer</a>.
|
---|
| 39 | <p> <hr>
|
---|
| 40 | <p> The implementation of the HTTP requests (archivedialog.ui.h):
|
---|
| 41 | <p> <pre>/****************************************************************************
|
---|
| 42 | ** $Id: archivesearch-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 43 | **
|
---|
| 44 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 45 | **
|
---|
| 46 | ** This file is part of an example program for Qt. This example
|
---|
| 47 | ** program may be used, distributed and modified without limitation.
|
---|
| 48 | **
|
---|
| 49 | *****************************************************************************/
|
---|
| 50 |
|
---|
| 51 | /****************************************************************************
|
---|
| 52 | ** ui.h extension file, included from the uic-generated form implementation.
|
---|
| 53 | **
|
---|
| 54 | ** If you wish to add, delete or rename functions or slots use
|
---|
| 55 | ** Qt Designer which will update this file, preserving your code. Create an
|
---|
| 56 | ** init() function in place of a constructor, and a destroy() function in
|
---|
| 57 | ** place of a destructor.
|
---|
| 58 | *****************************************************************************/
|
---|
| 59 |
|
---|
| 60 | void ArchiveDialog::init()
|
---|
| 61 | {
|
---|
| 62 | connect(&articleSearcher, SIGNAL(done(bool)), this, SLOT(searchDone(bool)));
|
---|
| 63 | connect(&articleFetcher, SIGNAL(done(bool)), this, SLOT(fetchDone(bool)));
|
---|
| 64 | connect(myListView, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(fetch(QListViewItem*)));
|
---|
| 65 | connect(myLineEdit, SIGNAL(returnPressed()), this, SLOT(search()));
|
---|
| 66 | connect(myListView, SIGNAL(returnPressed(QListViewItem*)), this, SLOT(fetch(QListViewItem*)));
|
---|
| 67 | connect(myPushButton, SIGNAL(clicked()), this, SLOT(close()));
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | void ArchiveDialog::fetch( <a href="qlistviewitem.html">QListViewItem</a> *it )
|
---|
| 71 | {
|
---|
| 72 | <a name="x477"></a> <a href="qurl.html">QUrl</a> u(it-><a href="qlistviewitem.html#text">text</a>(1));
|
---|
| 73 | <a name="x485"></a> articleFetcher.setHost(u.<a href="qurl.html#host">host</a>());
|
---|
| 74 | articleFetcher.get(it-><a href="qlistviewitem.html#text">text</a>(1));
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | void ArchiveDialog::fetchDone( bool error )
|
---|
| 78 | {
|
---|
| 79 | if (error) {
|
---|
| 80 | <a name="x478"></a> QMessageBox::<a href="qmessagebox.html#critical">critical</a>(this, "Error fetching",
|
---|
| 81 | "An error occurred when fetching this document: "
|
---|
| 82 | + articleFetcher.errorString(),
|
---|
| 83 | QMessageBox::Ok, QMessageBox::NoButton);
|
---|
| 84 | } else {
|
---|
| 85 | myTextBrowser->setText(articleFetcher.readAll());
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | void ArchiveDialog::search()
|
---|
| 90 | {
|
---|
| 91 | if (articleSearcher.state() == QHttp::HostLookup
|
---|
| 92 | || articleSearcher.state() == QHttp::Connecting
|
---|
| 93 | || articleSearcher.state() == QHttp::Sending
|
---|
| 94 | || articleSearcher.state() == QHttp::Reading) {
|
---|
| 95 | articleSearcher.abort();
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | if (myLineEdit->text() == "") {
|
---|
| 99 | QMessageBox::<a href="qmessagebox.html#critical">critical</a>(this, "Empty query",
|
---|
| 100 | "Please type a search string.",
|
---|
| 101 | QMessageBox::Ok, QMessageBox::NoButton);
|
---|
| 102 | } else {
|
---|
| 103 | <a name="x474"></a> QApplication::<a href="qapplication.html#setOverrideCursor">setOverrideCursor</a>(QCursor(Qt::WaitCursor));
|
---|
| 104 |
|
---|
| 105 | articleSearcher.setHost("lists.trolltech.com");
|
---|
| 106 |
|
---|
| 107 | <a href="qhttprequestheader.html">QHttpRequestHeader</a> header("POST", "/qt-interest/search.php");
|
---|
| 108 | <a name="x476"></a> header.<a href="qhttpheader.html#setValue">setValue</a>("Host", "lists.trolltech.com");
|
---|
| 109 | <a name="x475"></a> header.<a href="qhttpheader.html#setContentType">setContentType</a>("application/x-www-form-urlencoded");
|
---|
| 110 |
|
---|
| 111 | <a href="qstring.html">QString</a> encodedTopic = myLineEdit->text();
|
---|
| 112 | <a name="x484"></a> QUrl::<a href="qurl.html#encode">encode</a>(encodedTopic);
|
---|
| 113 | <a href="qstring.html">QString</a> searchString = "qt-interest=on&search=" + encodedTopic;
|
---|
| 114 |
|
---|
| 115 | <a name="x483"></a> articleSearcher.request(header, searchString.<a href="qstring.html#utf8">utf8</a>());
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | void ArchiveDialog::searchDone( bool error )
|
---|
| 121 | {
|
---|
| 122 | if (error) {
|
---|
| 123 | QMessageBox::<a href="qmessagebox.html#critical">critical</a>(this, "Error searching",
|
---|
| 124 | "An error occurred when searching: "
|
---|
| 125 | + articleSearcher.errorString(),
|
---|
| 126 | QMessageBox::Ok, QMessageBox::NoButton);
|
---|
| 127 | } else {
|
---|
| 128 | <a href="qstring.html">QString</a> result(articleSearcher.readAll());
|
---|
| 129 |
|
---|
| 130 | <a href="qregexp.html">QRegExp</a> rx("<a href=\"(http://lists\\.trolltech\\.com/qt-interest/.*)\">(.*)</a>");
|
---|
| 131 | <a name="x482"></a> rx.<a href="qregexp.html#setMinimal">setMinimal</a>(TRUE);
|
---|
| 132 | int pos = 0;
|
---|
| 133 | while (pos >= 0) {
|
---|
| 134 | <a name="x481"></a> pos = rx.<a href="qregexp.html#search">search</a>(result, pos);
|
---|
| 135 | if (pos > -1) {
|
---|
| 136 | <a name="x480"></a> pos += rx.<a href="qregexp.html#matchedLength">matchedLength</a>();
|
---|
| 137 | <a name="x479"></a> new <a href="qlistviewitem.html">QListViewItem</a>(myListView, rx.<a href="qregexp.html#cap">cap</a>(2), rx.<a href="qregexp.html#cap">cap</a>(1));
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | <a name="x473"></a> QApplication::<a href="qapplication.html#restoreOverrideCursor">restoreOverrideCursor</a>();
|
---|
| 143 | }
|
---|
| 144 | </pre>
|
---|
| 145 |
|
---|
| 146 | <p> <hr>
|
---|
| 147 | <p> Main (main.cpp):
|
---|
| 148 | <p> <pre>/****************************************************************************
|
---|
| 149 | ** $Id: archivesearch-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 150 | **
|
---|
| 151 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 152 | **
|
---|
| 153 | ** This file is part of an example program for Qt. This example
|
---|
| 154 | ** program may be used, distributed and modified without limitation.
|
---|
| 155 | **
|
---|
| 156 | *****************************************************************************/
|
---|
| 157 |
|
---|
| 158 | #include "archivedialog.h"
|
---|
| 159 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
| 160 |
|
---|
| 161 | int main(int argc, char **argv)
|
---|
| 162 | {
|
---|
| 163 | <a href="qapplication.html">QApplication</a> a( argc, argv );
|
---|
| 164 | ArchiveDialog ad;
|
---|
| 165 | ad.show();
|
---|
| 166 |
|
---|
| 167 | <a name="x489"></a><a name="x487"></a> QObject::<a href="qobject.html#connect">connect</a>( &a, SIGNAL(<a href="qapplication.html#lastWindowClosed">lastWindowClosed</a>()),
|
---|
| 168 | <a name="x488"></a> &a, SLOT(<a href="qapplication.html#quit">quit</a>()) );
|
---|
| 169 |
|
---|
| 170 | <a name="x486"></a> return a.<a href="qapplication.html#exec">exec</a>();
|
---|
| 171 | }
|
---|
| 172 | </pre>
|
---|
| 173 |
|
---|
| 174 | <p>See also <a href="network-examples.html">Network Examples</a>.
|
---|
| 175 |
|
---|
| 176 | <!-- eof -->
|
---|
| 177 | <p><address><hr><div align=center>
|
---|
| 178 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 179 | <td>Copyright © 2007
|
---|
| 180 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 181 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 182 | </table></div></address></body>
|
---|
| 183 | </html>
|
---|