From 707b14be95afc4591d2c35c65587d849a17dd1c6 Mon Sep 17 00:00:00 2001 From: under2x Date: Sun, 29 Jul 2007 21:30:42 +0000 Subject: [PATCH] fixed some bugs with the httpTitle stuff... git-svn-id: http://basket.linux62.org/svn/basket/trunk@546 68e0c82f-6715-0410-a4b6-c4571a790354 --- src/notecontent.cpp | 53 +++++++++++++++++++++++++++++++++++++---------------- src/notecontent.h | 3 ++- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/notecontent.cpp b/src/notecontent.cpp index 2165dee..6923ce2 100644 --- a/src/notecontent.cpp +++ b/src/notecontent.cpp @@ -1211,10 +1211,15 @@ QString SoundContent::messageWhenOpenning(OpenMessage where) */ LinkContent::LinkContent(Note *parent, const KURL &url, const QString &title, const QString &icon, bool autoTitle, bool autoIcon) - : NoteContent(parent), m_httpBuff(0), m_previewJob(0) + : NoteContent(parent), m_http(0), m_httpBuff(0), m_previewJob(0) { setLink(url, title, icon, autoTitle, autoIcon); } +LinkContent::~LinkContent() +{ + delete m_http; + delete m_httpBuff; +} int LinkContent::setWidthAndGetHeight(int width) { @@ -1341,13 +1346,13 @@ void LinkContent::removePreview(const KFileItem*) // QHttp slots for getting link title void LinkContent::httpReadyRead(const QHttpResponseHeader& ) { - Q_ULONG bytesAvailable = m_http.bytesAvailable(); + Q_ULONG bytesAvailable = m_http->bytesAvailable(); if(bytesAvailable <= 0) return; char* buf = new char[bytesAvailable+1]; - Q_LONG bytes_read = m_http.readBlock(buf, bytesAvailable); + Q_LONG bytes_read = m_http->readBlock(buf, bytesAvailable); if(bytes_read > 0) { // m_httpBuff will keep data if title is not found in initial read @@ -1357,12 +1362,14 @@ void LinkContent::httpReadyRead(const QHttpResponseHeader& ) else { (*m_httpBuff) += buf; } - - QRegExp reg("([^<>]+)", false); + + // todo: this should probably strip odd html tags like   etc + QRegExp reg("[\\s]*( )?([^<]+)[\\s]*", false); + reg.setMinimal(TRUE); int offset = 0; - + //std::cout << *m_httpBuff << " bytes: " << bytes_read << std::endl; if((offset = reg.search(*m_httpBuff)) >= 0) { - m_title = reg.cap(1); + m_title = reg.cap(2); m_autoTitle = false; setEdited(); @@ -1370,14 +1377,14 @@ void LinkContent::httpReadyRead(const QHttpResponseHeader& ) setLink(url(), title(), icon(), autoTitle(), autoIcon()); // stop the http connection - m_http.abort(); + m_http->abort(); delete m_httpBuff; m_httpBuff = 0; } // Stop at 10k bytes else if(m_httpBuff->length() > 10000) { - m_http.abort(); + m_http->abort(); delete m_httpBuff; m_httpBuff = 0; } @@ -1386,17 +1393,31 @@ void LinkContent::httpReadyRead(const QHttpResponseHeader& ) } void LinkContent::httpDone(bool) { - m_http.closeConnection(); + m_http->closeConnection(); } void LinkContent::startFetchingLinkTitle() { - connect(&m_http, SIGNAL(done(bool)), this, SLOT(httpDone(bool))); - connect(&m_http, SIGNAL(readyRead(const QHttpResponseHeader&)), this, - SLOT(httpReadyRead(const QHttpResponseHeader&))); - m_http.setHost(this->url().host(), this->url().port() == 0 ? 80: this->url().port()); - m_http.get(this->url().path()); - + if(this->url().protocol() == "http") + { + // delete old m_http, for some reason it will not connect a second time... + if(m_http != 0) { + delete m_http; + m_http = 0; + } + if(m_http == 0) { + m_http = new QHttp(this); + connect(m_http, SIGNAL(done(bool)), this, SLOT(httpDone(bool))); + connect(m_http, SIGNAL(readyRead(const QHttpResponseHeader&)), this, + SLOT(httpReadyRead(const QHttpResponseHeader&))); + } + m_http->setHost(this->url().host(), this->url().port() == 0 ? 80: this->url().port()); + QString path = this->url().encodedPathAndQuery(1); + if(path == "") + path = "/"; + //std::cout << "path: " << path << std::endl; + m_http->get(path); + } } // Code dupicated from FileContent::startFetchingUrlPreview() diff --git a/src/notecontent.h b/src/notecontent.h index 356eafd..7fa49ec 100644 --- a/src/notecontent.h +++ b/src/notecontent.h @@ -412,6 +412,7 @@ class LinkContent : public QObject, public NoteContent public: // Constructor and destructor: LinkContent(Note *parent, const KURL &url, const QString &title, const QString &icon, bool autoTitle, bool autoIcon); + ~LinkContent(); // Simple Generic Methods: NoteType::Id type(); QString typeName(); @@ -460,7 +461,7 @@ class LinkContent : public QObject, public NoteContent bool m_autoTitle; bool m_autoIcon; LinkDisplay m_linkDisplay; - QHttp m_http; + QHttp* m_http; QString* m_httpBuff; // File Preview Management: protected slots: -- 2.11.4.GIT