diff options
Diffstat (limited to 'examples/network/archivesearch')
-rw-r--r-- | examples/network/archivesearch/archivedialog.ui | 137 | ||||
-rw-r--r-- | examples/network/archivesearch/archivedialog.ui.h | 102 | ||||
-rw-r--r-- | examples/network/archivesearch/archivesearch.doc | 25 | ||||
-rw-r--r-- | examples/network/archivesearch/archivesearch.pro | 9 | ||||
-rw-r--r-- | examples/network/archivesearch/main.cpp | 23 |
5 files changed, 296 insertions, 0 deletions
diff --git a/examples/network/archivesearch/archivedialog.ui b/examples/network/archivesearch/archivedialog.ui new file mode 100644 index 0000000..0aafb7b --- /dev/null +++ b/examples/network/archivesearch/archivedialog.ui @@ -0,0 +1,137 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>ArchiveDialog</class> +<widget class="QDialog"> + <property name="name"> + <cstring>ArchiveDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>673</width> + <height>561</height> + </rect> + </property> + <property name="caption"> + <string>Qt-interest Archive Search Tool</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>myTextLabel</cstring> + </property> + <property name="text"> + <string>Search phrase</string> + </property> + </widget> + <widget class="QLineEdit"> + <property name="name"> + <cstring>myLineEdit</cstring> + </property> + </widget> + </hbox> + </widget> + <widget class="QSplitter"> + <property name="name"> + <cstring>splitter1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <widget class="QListView"> + <column> + <property name="text"> + <string>Matching documents</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>myListView</cstring> + </property> + </widget> + <widget class="QTextBrowser"> + <property name="name"> + <cstring>myTextBrowser</cstring> + </property> + </widget> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>mySpacer</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>281</width> + <height>21</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>myPushButton</cstring> + </property> + <property name="text"> + <string>&Quit</string> + </property> + <property name="autoDefault"> + <bool>false</bool> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<includes> + <include location="global" impldecl="in declaration">qhttp.h</include> + <include location="global" impldecl="in declaration">qurl.h</include> + <include location="global" impldecl="in declaration">qmessagebox.h</include> + <include location="global" impldecl="in declaration">qapplication.h</include> + <include location="global" impldecl="in declaration">qcursor.h</include> + <include location="global" impldecl="in declaration">qregexp.h</include> + <include location="local" impldecl="in implementation">archivedialog.ui.h</include> +</includes> +<variables> + <variable access="private">QHttp articleSearcher;</variable> + <variable access="private">QHttp articleFetcher;</variable> +</variables> +<slots> + <slot specifier="non virtual">fetch( QListViewItem * it )</slot> + <slot specifier="non virtual">fetchDone( bool error )</slot> + <slot specifier="non virtual">search()</slot> + <slot specifier="non virtual">searchDone( bool error )</slot> +</slots> +<functions> + <function access="private" specifier="non virtual">init()</function> +</functions> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/examples/network/archivesearch/archivedialog.ui.h b/examples/network/archivesearch/archivedialog.ui.h new file mode 100644 index 0000000..6608cd6 --- /dev/null +++ b/examples/network/archivesearch/archivedialog.ui.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. 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 +** Qt 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(&articleSearcher, SIGNAL(done(bool)), this, SLOT(searchDone(bool))); + connect(&articleFetcher, SIGNAL(done(bool)), this, SLOT(fetchDone(bool))); + connect(myListView, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(fetch(QListViewItem*))); + connect(myLineEdit, SIGNAL(returnPressed()), this, SLOT(search())); + connect(myListView, SIGNAL(returnPressed(QListViewItem*)), this, SLOT(fetch(QListViewItem*))); + connect(myPushButton, SIGNAL(clicked()), this, SLOT(close())); +} + +void ArchiveDialog::fetch( QListViewItem *it ) +{ + QUrl u(it->text(1)); + articleFetcher.setHost(u.host()); + articleFetcher.get(it->text(1)); +} + +void ArchiveDialog::fetchDone( bool error ) +{ + if (error) { + QMessageBox::critical(this, "Error fetching", + "An error occurred when fetching this document: " + + articleFetcher.errorString(), + QMessageBox::Ok, QMessageBox::NoButton); + } else { + myTextBrowser->setText(articleFetcher.readAll()); + } +} + +void ArchiveDialog::search() +{ + if (articleSearcher.state() == QHttp::HostLookup + || articleSearcher.state() == QHttp::Connecting + || articleSearcher.state() == QHttp::Sending + || articleSearcher.state() == QHttp::Reading) { + articleSearcher.abort(); + } + + if (myLineEdit->text() == "") { + QMessageBox::critical(this, "Empty query", + "Please type a search string.", + QMessageBox::Ok, QMessageBox::NoButton); + } else { + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + + articleSearcher.setHost("lists.trolltech.com"); + + QHttpRequestHeader header("POST", "/qt-interest/search.php"); + header.setValue("Host", "lists.trolltech.com"); + header.setContentType("application/x-www-form-urlencoded"); + + QString encodedTopic = myLineEdit->text(); + QUrl::encode(encodedTopic); + QString searchString = "qt-interest=on&search=" + encodedTopic; + + articleSearcher.request(header, searchString.utf8()); + } + +} + +void ArchiveDialog::searchDone( bool error ) +{ + if (error) { + QMessageBox::critical(this, "Error searching", + "An error occurred when searching: " + + articleSearcher.errorString(), + QMessageBox::Ok, QMessageBox::NoButton); + } else { + QString result(articleSearcher.readAll()); + + QRegExp rx("<a href=\"(http://lists\\.trolltech\\.com/qt-interest/.*)\">(.*)</a>"); + rx.setMinimal(TRUE); + int pos = 0; + while (pos >= 0) { + pos = rx.search(result, pos); + if (pos > -1) { + pos += rx.matchedLength(); + new QListViewItem(myListView, rx.cap(2), rx.cap(1)); + } + } + } + + QApplication::restoreOverrideCursor(); +} diff --git a/examples/network/archivesearch/archivesearch.doc b/examples/network/archivesearch/archivesearch.doc new file mode 100644 index 0000000..e4589cc --- /dev/null +++ b/examples/network/archivesearch/archivesearch.doc @@ -0,0 +1,25 @@ +/* +*/ + +/*! \page archivesearch-example.html + + \ingroup network-examples + + \title A qt-interest mail archive search + + This example does a search on the qt-interest mailinglist archives. It uses + QHttp to issue the search command and to fetch the results. The GUI parts + were done using \link designer-manual.book Qt Designer\endlink. + + <hr> + + The implementation of the HTTP requests (archivedialog.ui.h): + + \include network/archivesearch/archivedialog.ui.h + + <hr> + + Main (main.cpp): + + \include network/archivesearch/main.cpp +*/ diff --git a/examples/network/archivesearch/archivesearch.pro b/examples/network/archivesearch/archivesearch.pro new file mode 100644 index 0000000..1423814 --- /dev/null +++ b/examples/network/archivesearch/archivesearch.pro @@ -0,0 +1,9 @@ +TEMPLATE = app + +CONFIG += qt warn_on release + +REQUIRES = network full-config + +HEADERS += archivedialog.ui.h +INTERFACES += archivedialog.ui +SOURCES += main.cpp diff --git a/examples/network/archivesearch/main.cpp b/examples/network/archivesearch/main.cpp new file mode 100644 index 0000000..1766470 --- /dev/null +++ b/examples/network/archivesearch/main.cpp @@ -0,0 +1,23 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "archivedialog.h" +#include <qapplication.h> + +int main(int argc, char **argv) +{ + QApplication a( argc, argv ); + ArchiveDialog ad; + ad.show(); + + QObject::connect( &a, SIGNAL(lastWindowClosed()), + &a, SLOT(quit()) ); + + return a.exec(); +} |