-rw-r--r-- | noncore/net/ubrowser/httpcomm.cpp | 43 | ||||
-rw-r--r-- | noncore/net/ubrowser/httpcomm.h | 6 | ||||
-rw-r--r-- | noncore/net/ubrowser/httpfactory.cpp | 25 | ||||
-rw-r--r-- | noncore/net/ubrowser/httpfactory.h | 1 |
4 files changed, 59 insertions, 16 deletions
diff --git a/noncore/net/ubrowser/httpcomm.cpp b/noncore/net/ubrowser/httpcomm.cpp index 3c14053..4f189ce 100644 --- a/noncore/net/ubrowser/httpcomm.cpp +++ b/noncore/net/ubrowser/httpcomm.cpp @@ -41,3 +41,3 @@ void HttpComm::setUp(QString *newName) -void HttpComm::setStuff(QString newHost, QString newPortS, QString newFile, QTextDrag *newText) +void HttpComm::setStuff(QString newHost, QString newPortS, QString newFile, QTextDrag *newText, QImageDrag *newImage, bool newIsImage) { @@ -47,2 +47,4 @@ void HttpComm::setStuff(QString newHost, QString newPortS, QString newFile, QTex text = newText; + isImage = newIsImage; + image = newImage; } @@ -72,8 +74,11 @@ void HttpComm::incoming() { - int ba=socket->bytesAvailable(), i=0, j=0, semi=0; + int ba=socket->size(), i=0, j=0, semi=0; char *tempString = new char [ba]; + int br = socket->readBlock(tempString, ba); + socket->flush(); bool nextChunk=false; bool done=false; - socket->readBlock(tempString, ba); printf("HttpComm::incoming: ba: %d\n", ba); + printf("HttpComm::incoming: bytes read from socket: %d\n", br); +// printf("HttpComm::incoming: tempString length: %d\n"); QString sclength; @@ -134,2 +139,3 @@ void HttpComm::incoming() { + int startclength=0; QString tempQString = tempString; @@ -190,3 +196,6 @@ void HttpComm::incoming() status=0; - tempQString = tempQString.remove(0, clength); + tempQString = tempQString.remove(0, newTQstring.length()); + startclength = tempQString.find('\n'); + printf("HttpComm::incoming: startclength: %d\n", startclength); + tempQString = tempQString.remove(0, startclength+1); done=false; @@ -199,2 +208,3 @@ void HttpComm::incoming() { + printf("HttpComm::incoming: not truncating tempQString\n"); body+=tempQString; @@ -204,2 +214,3 @@ void HttpComm::incoming() { + printf("HttpComm::incoming: truncating tempQString\n"); tempQString.truncate(ba); @@ -229,3 +240,6 @@ void HttpComm::incoming() status=0; - tempQString = tempQString.remove(0, clength); + tempQString = tempQString.remove(0, newTQstring.length()); + startclength = tempQString.find('\n'); + printf("HttpComm::incoming: startclength, tempQString length: %d %d\n", startclength, tempQString.length()); + tempQString = tempQString.remove(0, startclength+1); done=false; @@ -238,2 +252,3 @@ void HttpComm::incoming() { + printf("HttpComm::incoming: not truncating tempQString\n"); body+=tempQString; @@ -243,2 +258,3 @@ void HttpComm::incoming() { + printf("HttpComm::incoming: truncating tempQString\n"); tempQString.truncate(ba); @@ -310,8 +326,17 @@ void HttpComm::processBody() end.truncate(lastSlash+1); - QString context("http://"+host+':'+portS+end); + QString context = "http://"+host+':'+portS+end; printf("HttpComm::processBody: context: %s\n", context.latin1() ); - browser->setTextFormat(RichText); - browser->mimeSourceFactory()->setFilePath(context); - browser->setText(body, context); + if(!isImage) + { + browser->setTextFormat(RichText); + browser->mimeSourceFactory()->setFilePath(context); + browser->setText(body, context); + } + else + { + QImage tempImage(body.latin1()); + image->setImage(tempImage); + browser->update(); + } } diff --git a/noncore/net/ubrowser/httpcomm.h b/noncore/net/ubrowser/httpcomm.h index c20fe72..d6f63fc 100644 --- a/noncore/net/ubrowser/httpcomm.h +++ b/noncore/net/ubrowser/httpcomm.h @@ -22,2 +22,4 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include <qtextbrowser.h> +#include <qcstring.h> +#include <qimage.h> @@ -31,3 +33,3 @@ public: void setUp(QString *newName); - void setStuff(QString newHost, QString newPortS, QString newFile, QTextDrag *newText); + void setStuff(QString newHost, QString newPortS, QString newFile, QTextDrag *newText, QImageDrag *newImage, bool newIsImage); void parseHeader(); @@ -51,2 +53,3 @@ private: QTextDrag *text; + QImageDrag *image; QTextBrowser *browser; @@ -56,2 +59,3 @@ private: int status; + bool isImage; }; diff --git a/noncore/net/ubrowser/httpfactory.cpp b/noncore/net/ubrowser/httpfactory.cpp index 92718fb..50a3c9a 100644 --- a/noncore/net/ubrowser/httpfactory.cpp +++ b/noncore/net/ubrowser/httpfactory.cpp @@ -24,2 +24,3 @@ HttpFactory::HttpFactory(QTextBrowser *newBrowser):QMimeSourceFactory() comm = new HttpComm(socket, browser); + image = new QImageDrag; } @@ -32,3 +33,3 @@ const QMimeSource * HttpFactory::data(const QString &abs_name) const QString host, file, portS, name, tempString; - bool done=false; + bool done=false, isImage=false; @@ -48,3 +49,4 @@ const QMimeSource * HttpFactory::data(const QString &abs_name) const { - return 0; + name.prepend(browser->context()); + name = name.remove(0, 7); } @@ -79,4 +81,9 @@ const QMimeSource * HttpFactory::data(const QString &abs_name) const } + + if(file.find(".png", file.length()-4) != -1 || file.find(".gif", file.length()-4) != -1 || file.find(".jpg", file.length()-4) != -1) + { + isImage=true; + } - comm->setStuff(host, portS, file, text); + comm->setStuff(host, portS, file, text, image, isImage); @@ -84,5 +91,11 @@ const QMimeSource * HttpFactory::data(const QString &abs_name) const - text->setText(""); - - return text; + if(!image) + { + text->setText(""); + return text; + } + else + { + return image; + } } diff --git a/noncore/net/ubrowser/httpfactory.h b/noncore/net/ubrowser/httpfactory.h index bb7615b..1802f56 100644 --- a/noncore/net/ubrowser/httpfactory.h +++ b/noncore/net/ubrowser/httpfactory.h @@ -36,2 +36,3 @@ private: QTextDrag *text; + QImageDrag *image; QTextBrowser *browser; |