PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/useragentprovider.cpp

https://bitbucket.org/yogeshwarp/gnewsreader-nokia
C++ | 120 lines | 72 code | 11 blank | 37 comment | 5 complexity | 913b293306e92f300e6dc1a1c9107e79 MD5 | raw file
  1. #include "useragentprovider.h"
  2. #include <QDebug>
  3. #include <QNetworkConfiguration>
  4. #ifdef Q_OS_SYMBIAN
  5. #include <apgtask.h>
  6. #include <apgcli.h>
  7. #include <EIKENV.H>
  8. #endif
  9. UserAgentProvider::UserAgentProvider(QWidget *parent) :
  10. QWebPage(parent)
  11. {
  12. }
  13. QString UserAgentProvider::getUserAgent()
  14. {
  15. return userAgentForUrl(QUrl(""));
  16. }
  17. Helper::Helper(QObject *parent) :
  18. QObject(parent)
  19. {
  20. //qDebug() << "Helper is getting new lease of life";
  21. configManager = new QNetworkConfigurationManager(this);
  22. //QObject::connect(configManager, SIGNAL(onlineStateChanged(bool)), this, SLOT(updateNwState(bool)));
  23. }
  24. //void Helper::updateNwState(bool isOnline) {
  25. // //qDebug() << "Network state changed to:" << isOnline;
  26. // this->nwStateChanged(isOnline);
  27. //}
  28. //void Helper::openNetConnection() {
  29. // const bool canStartIAP = (configManager->capabilities()
  30. // & QNetworkConfigurationManager::CanStartAndStopInterfaces);
  31. // // Is there default access point, use it
  32. // QNetworkConfiguration cfg = configManager->defaultConfiguration();
  33. // if (!cfg.isValid() || (!canStartIAP && cfg.state() != QNetworkConfiguration::Active)) {
  34. // qDebug() << "No Access Point found.";
  35. // return;
  36. // }
  37. // netSession = new QNetworkSession(cfg, this);
  38. // netSession->open();
  39. // netSession->waitForOpened(-1);
  40. //}
  41. //void Helper::closeNetConnection() {
  42. // if(netSession->isOpen()) netSession->stop();
  43. //}
  44. void Helper::openURLDefault(const QString &url){
  45. #ifdef Q_OS_SYMBIAN
  46. const TInt KWmlBrowserUid = 0x10008D39; //10008d39
  47. TPtrC myUrl (reinterpret_cast<const TText*>(url.constData()),url.length());
  48. //QDesktopServices::openUrl(QUrl(url));
  49. RApaLsSession lsSession;
  50. // create a session with apparc server.
  51. User::LeaveIfError(lsSession.Connect());
  52. CleanupClosePushL(lsSession);
  53. TDataType mimeDatatype(_L8("application/x-web-browse"));
  54. TUid handlerUID;
  55. // get the default application uid for application/x-web-browse
  56. lsSession.AppForDataType(mimeDatatype,handlerUID);
  57. // there may not be a mime-type handler defined, especially on S60 3.x
  58. // in such case we default to the built-in browser
  59. if (handlerUID.iUid == 0 || handlerUID.iUid == -1)
  60. handlerUID.iUid = KWmlBrowserUid;
  61. // Finally launch default browser
  62. LaunchBrowserL(myUrl, handlerUID);
  63. qDebug() << "Launching with UID:" << handlerUID.iUid;
  64. // Cleanup
  65. CleanupStack::PopAndDestroy(&lsSession);
  66. #else
  67. qDebug() << "Trying default Qt function : QDesktopServices::openUrl" << url;
  68. QDesktopServices::openUrl(url);
  69. #endif
  70. }
  71. // ----------------------------------------------------
  72. // CBrowserAppUi::LaunchBrowserL(const TDesC& aUrl)
  73. // Used for launching the default browser with provided url.
  74. // ----------------------------------------------------
  75. //
  76. #ifdef Q_OS_SYMBIAN
  77. void Helper::LaunchBrowserL(const TDesC& aUrl, TUid& aUid)
  78. {
  79. qDebug() << "Inside LaunchBrowserL";
  80. TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
  81. TApaTask task = taskList.FindApp( aUid );
  82. if ( task.Exists() )
  83. {
  84. HBufC8* param = HBufC8::NewLC( aUrl.Length() + 2);
  85. //"4 " is to Start/Continue the browser specifying a URL
  86. param->Des().Append(_L("4 "));
  87. param->Des().Append(aUrl);
  88. task.SendMessage( TUid::Uid( 0 ), *param ); // Uid is not used
  89. CleanupStack::PopAndDestroy(param);
  90. }
  91. else
  92. {
  93. HBufC16* param = HBufC16::NewLC( aUrl.Length() + 2);
  94. //"4 " is to Start/Continue the browser specifying a URL
  95. param->Des().Append(_L("4 "));
  96. param->Des().Append(aUrl);
  97. RApaLsSession appArcSession;
  98. // connect to AppArc server
  99. User::LeaveIfError(appArcSession.Connect());
  100. TThreadId id;
  101. appArcSession.StartDocument( *param, aUid, id );
  102. appArcSession.Close();
  103. CleanupStack::PopAndDestroy(param);
  104. }
  105. }
  106. #endif
  107. void Helper::logToFile(const QString &messageToLog){
  108. qDebug() << messageToLog;
  109. }