/* Downloading wikipages and calls the functions to extract content/links */ /** if this fails to compile, add 'QT+=network' to the .pro **/ #ifndef NETWORK_H #define NETWORK_H #include #include #include #include #include #include class SpideyHttp { public: SpideyHttp(); ~SpideyHttp(); void downloadWikiPage(const QString & pageName); QHttp *http; QTemporaryFile *tempFile; }; SpideyHttp::SpideyHttp() { http = new QHttp(); tempFile = new QTemporaryFile(); tempFile->setAutoRemove(true); } /* Instead of this destructor, we could make SpideyHttp a descendent of QObject and connect a closing-everything signal to a clean-up slot. However, trying this gave compile issues out the wazoo, so this destructor method is staying for now. Hey, it's one in the morning; compiler issues are NOT something I want to deal with right now. */ SpideyHttp::~SpideyHttp() { tempFile->remove(); delete tempFile; delete http; } void SpideyHttp::downloadWikiPage(const QString & pageName) { if(!tempFile->open()) { QMessageBox::warning(this, tr("Error!"), tr("Could not open wiki page %1").arg(pageName)); return; } http->setHost("en.wikipedia.org"); //http->get("/wiki/Malacca", tempFile); http->get("/wiki/" + pageName, tempFile); /* //Test QString tempString(tempFile->readAll()); QLabel *tmpL = new QLabel("BLAH" + tempString + "BLAH"); tmpL->show(); */ //QTextEdit *fileEdit = new QTextEdit(); // VERY ANNOYING!!!!!!!!!!!!! //fileEdit->setHtml(tempString); //fileEdit->show(); } #endif // NETWORK_H