/*! @file @id $Id$ */ // 1 2 3 4 5 6 7 8 // 45678901234567890123456789012345678901234567890123456789012345678901234567890 #ifndef WEBPAGE_HXX #define WEBPAGE_HXX #include #include #include #include #include #include #include #include #include #ifndef LOG #include #define LOG(X) std::clog<setOfflineStorageDefaultQuota(1024*1024*1024); settings()->setOfflineStoragePath("/tmp/"); settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); //settings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true); settings()->setAttribute(QWebSettings::LocalStorageEnabled, true); } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wterminate" virtual ~TestWebPage() { if (!_nextFile.isEmpty() && !std::uncaught_exception()) // will not call terminate(), because I check std::uncaught_exception() throw LastFileNotUploaded(_nextFile); } #pragma GCC diagnostic pop void setNextUploadFile(QString nextFile) { if (!_unattended) throw NotUnattended(); if (!_nextFile.isEmpty()) throw LastFileNotUploaded(_nextFile); if (nextFile.isEmpty()) throw EmptyUploadFile(); _nextFile = nextFile; } bool uploadPrepared() { return !_nextFile.isEmpty(); } Q_SIGNALS: void uploadFile(QString filename); protected: virtual QString chooseFile(QWebFrame* frame, const QString&) { if (_unattended) { if (_nextFile.isEmpty()) throw NoUploadFile(); if (!QFile(_nextFile).exists()) throw FileNotFound(_nextFile); QString filename(_nextFile); _nextFile.clear(); return filename; } else { QString filename(QFileDialog::getOpenFileName (frame->page()->view(), tr("File to Upload"))); if (filename.size()) uploadFile(filename); return filename; } } virtual void javaScriptAlert(QWebFrame* frame, const QString& msg) { LOG("javaScriptAlert: "+msg); if (_unattended) { return; } else { return; /// @todo handle javascript alerts //return QWebPage::javaScriptAlert(frame, msg); } } virtual bool javaScriptConfirm(QWebFrame* frame, const QString& msg) { LOG("javaScriptConfirm "+msg); if (_unattended) { return true; } else { return true; /// @todo handle javascript confirmations //return QWebPage::javaScriptConfirm(frame, msg); } } virtual void javaScriptConsoleMessage(const QString& msg, int line, const QString& src) { LOG("javaScriptConsoleMessage: "+msg); if (_unattended) { return; } else { return; /// @todo handle javascript console messages //return QWebPage::javaScriptConsoleMessage(msg, line, src); } } virtual bool javaScriptPrompt(QWebFrame* frame, const QString& msg, const QString& defaultValue, QString* result) { LOG("javaScriptPrompt: "+msg); if (_unattended) { return true; } else { return true; /// @todo handle javascript prompts //return QWebPage::javaScriptPrompt(frame, msg, defaultValue, result); } } private: bool _unattended; QString _nextFile; }; #endif