1 | /****************************************************************************
|
---|
2 | ** $Id: archivedialog.ui.h 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
|
---|
5 | **
|
---|
6 | ** This file is part of an example program for Qt. This example
|
---|
7 | ** program may be used, distributed and modified without limitation.
|
---|
8 | **
|
---|
9 | *****************************************************************************/
|
---|
10 |
|
---|
11 | /****************************************************************************
|
---|
12 | ** ui.h extension file, included from the uic-generated form implementation.
|
---|
13 | **
|
---|
14 | ** If you wish to add, delete or rename functions or slots use
|
---|
15 | ** Qt Designer which will update this file, preserving your code. Create an
|
---|
16 | ** init() function in place of a constructor, and a destroy() function in
|
---|
17 | ** place of a destructor.
|
---|
18 | *****************************************************************************/
|
---|
19 |
|
---|
20 | void ArchiveDialog::init()
|
---|
21 | {
|
---|
22 | connect(&articleSearcher, SIGNAL(done(bool)), this, SLOT(searchDone(bool)));
|
---|
23 | connect(&articleFetcher, SIGNAL(done(bool)), this, SLOT(fetchDone(bool)));
|
---|
24 | connect(myListView, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(fetch(QListViewItem*)));
|
---|
25 | connect(myLineEdit, SIGNAL(returnPressed()), this, SLOT(search()));
|
---|
26 | connect(myListView, SIGNAL(returnPressed(QListViewItem*)), this, SLOT(fetch(QListViewItem*)));
|
---|
27 | connect(myPushButton, SIGNAL(clicked()), this, SLOT(close()));
|
---|
28 | }
|
---|
29 |
|
---|
30 | void ArchiveDialog::fetch( QListViewItem *it )
|
---|
31 | {
|
---|
32 | QUrl u(it->text(1));
|
---|
33 | articleFetcher.setHost(u.host());
|
---|
34 | articleFetcher.get(it->text(1));
|
---|
35 | }
|
---|
36 |
|
---|
37 | void ArchiveDialog::fetchDone( bool error )
|
---|
38 | {
|
---|
39 | if (error) {
|
---|
40 | QMessageBox::critical(this, "Error fetching",
|
---|
41 | "An error occurred when fetching this document: "
|
---|
42 | + articleFetcher.errorString(),
|
---|
43 | QMessageBox::Ok, QMessageBox::NoButton);
|
---|
44 | } else {
|
---|
45 | myTextBrowser->setText(articleFetcher.readAll());
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | void ArchiveDialog::search()
|
---|
50 | {
|
---|
51 | if (articleSearcher.state() == QHttp::HostLookup
|
---|
52 | || articleSearcher.state() == QHttp::Connecting
|
---|
53 | || articleSearcher.state() == QHttp::Sending
|
---|
54 | || articleSearcher.state() == QHttp::Reading) {
|
---|
55 | articleSearcher.abort();
|
---|
56 | }
|
---|
57 |
|
---|
58 | if (myLineEdit->text() == "") {
|
---|
59 | QMessageBox::critical(this, "Empty query",
|
---|
60 | "Please type a search string.",
|
---|
61 | QMessageBox::Ok, QMessageBox::NoButton);
|
---|
62 | } else {
|
---|
63 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
---|
64 |
|
---|
65 | articleSearcher.setHost("www.trolltech.com");
|
---|
66 |
|
---|
67 | QHttpRequestHeader header("POST", "/search.html");
|
---|
68 | header.setValue("Host", "www.trolltech.com");
|
---|
69 | header.setContentType("application/x-www-form-urlencoded");
|
---|
70 |
|
---|
71 | QString encodedTopic = myLineEdit->text();
|
---|
72 | QUrl::encode(encodedTopic);
|
---|
73 | QString searchString = "qt-interest=on&search=" + encodedTopic;
|
---|
74 |
|
---|
75 | articleSearcher.request(header, searchString.utf8());
|
---|
76 | }
|
---|
77 |
|
---|
78 | }
|
---|
79 |
|
---|
80 | void ArchiveDialog::searchDone( bool error )
|
---|
81 | {
|
---|
82 | if (error) {
|
---|
83 | QMessageBox::critical(this, "Error searching",
|
---|
84 | "An error occurred when searching: "
|
---|
85 | + articleSearcher.errorString(),
|
---|
86 | QMessageBox::Ok, QMessageBox::NoButton);
|
---|
87 | } else {
|
---|
88 | QString result(articleSearcher.readAll());
|
---|
89 |
|
---|
90 | QRegExp rx("<a href=\"(http://lists\\.trolltech\\.com/qt-interest/.*)\">(.*)</a>");
|
---|
91 | rx.setMinimal(TRUE);
|
---|
92 | int pos = 0;
|
---|
93 | while (pos >= 0) {
|
---|
94 | pos = rx.search(result, pos);
|
---|
95 | if (pos > -1) {
|
---|
96 | pos += rx.matchedLength();
|
---|
97 | new QListViewItem(myListView, rx.cap(2), rx.cap(1));
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | QApplication::restoreOverrideCursor();
|
---|
103 | }
|
---|