qspnetworkaccessmanager.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "qspnetworkaccessmanager.h"
  2. #include "qspreply.h"
  3. QspNetworkAccessManager::QspNetworkAccessManager(QNetworkAccessManager *oldManager, QObject *parent) : QNetworkAccessManager(parent)
  4. {
  5. //setCache(oldManager->cache());
  6. setCookieJar(oldManager->cookieJar());
  7. //setProxy(oldManager->proxy());
  8. //setProxyFactory(oldManager->proxyFactory());
  9. }
  10. QspNetworkAccessManager::~QspNetworkAccessManager()
  11. {
  12. }
  13. void QspNetworkAccessManager::SetPlainText(const QString &text)
  14. {
  15. m_isUseHtml = false;
  16. m_text= text;
  17. }
  18. void QspNetworkAccessManager::SetHtml(const QString &text)
  19. {
  20. m_isUseHtml = true;
  21. m_text =text;
  22. }
  23. void QspNetworkAccessManager::SetGamePath(const QString &path)
  24. {
  25. m_path = path;
  26. }
  27. void QspNetworkAccessManager::SetLinkColor(const QColor &color)
  28. {
  29. m_linkColor = color;
  30. }
  31. void QspNetworkAccessManager::SetBackgroundColor(const QColor &color)
  32. {
  33. m_backColor = color;
  34. }
  35. void QspNetworkAccessManager::SetForegroundColor(const QColor &color)
  36. {
  37. m_fontColor = color;
  38. }
  39. void QspNetworkAccessManager::SetBackgroundImage(const QString &path)
  40. {
  41. m_bmpBg = path;
  42. }
  43. void QspNetworkAccessManager::SetTextFont(const QFont &new_font)
  44. {
  45. m_font = new_font;
  46. }
  47. QNetworkReply *QspNetworkAccessManager::createRequest(
  48. QNetworkAccessManager::Operation operation, const QNetworkRequest &request,
  49. QIODevice *device)
  50. {
  51. if (request.url().scheme() == "http" || request.url().scheme() == "https")
  52. return QNetworkAccessManager::createRequest(operation, request, device);
  53. if (operation == GetOperation)
  54. // Handle qsp:// URLs separately by creating custom QNetworkReply objects.
  55. return new QspReply(request.url(), m_text, m_isUseHtml, m_path, m_linkColor, m_backColor, m_fontColor, m_bmpBg, m_font);
  56. else
  57. return QNetworkAccessManager::createRequest(operation, request, device);
  58. }