main.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #include <cstddef>
  2. #include <QtGui/QApplication>
  3. #include "qmlapplicationviewer.h"
  4. #if defined(Q_WS_SIMULATOR)
  5. #include <QNetworkProxy>
  6. #endif
  7. #include <QUrl>
  8. #include <QtDeclarative>
  9. #include <QSplashScreen>
  10. #include <QPixmap>
  11. #include <QTranslator>
  12. #include <QLocale>
  13. #include "qplatformdefs.h"
  14. #include "networkaccessmanagerfactory.h"
  15. #include "useragentprovider.h"
  16. #include "setting.h"
  17. #include <QtDebug>
  18. #include <QFile>
  19. #include <QTextStream>
  20. void customMessageHandler(QtMsgType type, const char *msg)
  21. {
  22. QString txt;
  23. switch (type) {
  24. case QtDebugMsg:
  25. txt = QString("Debug: %1").arg(msg);
  26. break;
  27. case QtWarningMsg:
  28. txt = QString("Warning: %1").arg(msg);
  29. break;
  30. case QtCriticalMsg:
  31. txt = QString("Critical: %1").arg(msg);
  32. break;
  33. case QtFatalMsg:
  34. txt = QString("Fatal: %1").arg(msg);
  35. abort();
  36. }
  37. #ifdef MEEGO_EDITION_HARMATTAN
  38. QFile outFile("/opt/gNewsReader/qml/gNewsReader/debug.log");
  39. #else
  40. QFile outFile("E://logs//gnewsreader//debug.log");
  41. #endif
  42. outFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
  43. QTextStream ts(&outFile);
  44. ts << txt << endl;
  45. }
  46. Q_DECL_EXPORT int main(int argc, char *argv[])
  47. {
  48. QScopedPointer<QApplication> app(createApplication(argc, argv));
  49. QLocale locale = QLocale::system();
  50. //QLocale locale = QLocale(QLocale::Italian, QLocale::China);
  51. QString localeString = locale.name();
  52. qDebug() << "Application Locale :" <<localeString;
  53. // qDebug() << "Font Path:" << QUrl::fromLocalFile("qml/gNewsReader/fonts/NokiaPureTextReg.ttf").toLocalFile();
  54. // QFontDatabase::addApplicationFont(QUrl::fromLocalFile("qml/gNewsReader/fonts/NokiaPureTextReg.ttf").toLocalFile());
  55. // QApplication::setFont(QFont("Nokia Pure Text"));
  56. app->setApplicationName(QString("gNewsReader")); //For Ovi Store
  57. app->setApplicationVersion(QString(APP_VERSION));
  58. #if defined(Q_WS_SIMULATOR)
  59. QUrl proxyUrl(qgetenv("http_proxy"));
  60. if (proxyUrl.isValid() && !proxyUrl.host().isEmpty()) {
  61. int proxyPort = (proxyUrl.port() > 0) ? proxyUrl.port() : 8080;
  62. QNetworkProxy proxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyPort);
  63. QNetworkProxy::setApplicationProxy(proxy);
  64. }
  65. else {
  66. QNetworkProxyQuery query(QUrl(QLatin1String("https://www.google.com")));
  67. QNetworkProxy proxy = QNetworkProxyFactory::systemProxyForQuery(query).value(0);
  68. if (proxy.type() != QNetworkProxy::NoProxy)
  69. QNetworkProxy::setApplicationProxy(proxy);
  70. }
  71. #endif
  72. QPixmap pixmap("qml/gNewsReader/pics/splash.png");
  73. QSplashScreen splash(pixmap, Qt::WindowStaysOnTopHint);
  74. splash.show();
  75. app->processEvents();
  76. splash.raise();
  77. app->processEvents();
  78. QmlApplicationViewer viewer;
  79. // Set custom NetworkAccessManagerFactory object in QDeclarative context
  80. UserAgentProvider p;
  81. QString userAgent = p.getUserAgent();
  82. //#ifdef Q_OS_SYMBIAN
  83. // QDeclarativeEngine engine;
  84. // qDebug() << "Offline Storage Path: " << engine.offlineStoragePath();
  85. // engine.setOfflineStoragePath("E:\\Private\\20049f95\\QML\\OfflineStorage");
  86. // qDebug() << "Offline Storage Path: " << engine.offlineStoragePath();
  87. //#endif
  88. NetworkAccessManagerFactory factory(userAgent);
  89. viewer.engine()->setNetworkAccessManagerFactory(&factory);
  90. qDebug() << QApplication::applicationDirPath();
  91. #ifdef MEEGO_EDITION_HARMATTAN
  92. QWebSettings::globalSettings()->setUserStyleSheetUrl(QUrl::fromLocalFile("/opt/gNewsReader/qml/gNewsReader/css/addBlock.css"));
  93. #else
  94. QWebSettings::globalSettings()->setUserStyleSheetUrl(QUrl::fromLocalFile("qml/gNewsReader/css/addBlock.css"));
  95. #endif
  96. QWebSettings::globalSettings()->enablePersistentStorage();
  97. QWebSettings::globalSettings()->setAttribute(QWebSettings::TiledBackingStoreEnabled, true);
  98. QWebSettings::globalSettings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, true);
  99. app->processEvents();
  100. //Set platformStype for MeeGo
  101. // #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
  102. // qDebug() << "Symbian UI platform style - Use default";
  103. #ifdef MEEGO_EDITION_HARMATTAN
  104. qDebug() << "MeeGo UI platform style";
  105. QScopedPointer<QDeclarativePropertyMap> platformStyle(new QDeclarativePropertyMap());
  106. platformStyle->insert("borderSizeMedium", QVariant(8));
  107. platformStyle->insert("paddingSmall", QVariant(4));
  108. platformStyle->insert("paddingMedium", QVariant(8));
  109. platformStyle->insert("paddingLarge", QVariant(12));
  110. platformStyle->insert("fontSizeSmall", QVariant(18));
  111. platformStyle->insert("colorNormalLight", QVariant(QColor(255, 255, 255)));
  112. platformStyle->insert("colorNormalDark", QVariant(QColor(0, 0, 0)));
  113. platformStyle->insert("colorNormalMid", QVariant(QColor(153, 153, 153)));
  114. platformStyle->insert("colorNormalLink", QVariant(QColor(0, 0, 200)));
  115. platformStyle->insert("colorNormalLightInverted", QVariant(QColor("#191919")));
  116. platformStyle->insert("colorNormalMidInverted", QVariant(QColor("#a6a8ab")));
  117. platformStyle->insert("fontFamilyRegular", QVariant(QString("Nokia Pure Text")));
  118. platformStyle->insert("fontFamilyLight", QVariant(QString("Nokia Pure Text")));
  119. platformStyle->insert("fontSizeMedium", QVariant(22));
  120. platformStyle->insert("fontSizeLarge", QVariant(26));
  121. platformStyle->insert("graphicSizeLarge", QVariant(48));
  122. platformStyle->insert("graphicSizeMedium", QVariant(32));
  123. platformStyle->insert("graphicSizeSmall", QVariant(24));
  124. platformStyle->insert("graphicSizeTiny", QVariant(20));
  125. viewer.rootContext()->setContextProperty("meegoStyle", platformStyle.data());
  126. //qmlRegisterType<FileIO, 1>("FileIO", 1, 0, "FileIO");
  127. #endif
  128. //qmlRegisterType<MyWebView>("myLib", 1, 0, "MyWebView");
  129. //Lets register our custom handler, before we start
  130. //qInstallMsgHandler(customMessageHandler);
  131. //Register custom URL handler to make pocket Auth scheme happy
  132. //QDesktopServices::setUrlHandler(QLatin1String("gnewsreader"), this, "handleBrowserCallback");
  133. Helper launcher;// = new Helper();
  134. viewer.rootContext()->setContextProperty("appLauncher", &launcher);
  135. viewer.rootContext()->setContextProperty("appVersion", QVariant(QString(APP_VERSION)));
  136. Settings settings("gNewsReader", "mainSettings");
  137. viewer.rootContext()->setContextProperty("settings", &settings);
  138. bool forceEnglish = settings.getValue("main/language/forceenglish", QVariant(QBool(false))).toBool();
  139. // SubItemModel subItemModel;
  140. // SubItemFilter subItemFilter;
  141. // subItemFilter.setSourceModel(&subItemModel);
  142. // viewer.rootContext()->setContextProperty("subListModel2", &subItemModel);
  143. // viewer.rootContext()->setContextProperty("subListModelFilter", &subItemFilter);
  144. //Load translations from qrc file
  145. qDebug() << "Application Country :" <<locale.country();
  146. qDebug() << "Application Country :" <<locale.countryToString(locale.country());
  147. if((locale.country() == QLocale::Taiwan || locale.country() == QLocale::Macau || locale.country() == QLocale::HongKong) && (locale.language() == QLocale::Chinese) )
  148. localeString = "zh_TW";
  149. if(forceEnglish) localeString = "en_US";
  150. qDebug() << "Application Locale :" <<localeString;
  151. QTranslator translator;
  152. if (translator.load("gtrans_" + localeString, ":/"))
  153. app->installTranslator(&translator);
  154. #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
  155. viewer.rootContext()->setContextProperty("applicationPlatform", QVariant(QString("symbian")));
  156. viewer.setMainQmlFile(QLatin1String("qml/gNewsReader/qml/newsreader.qml"));
  157. #else
  158. viewer.rootContext()->setContextProperty("applicationPlatform", QVariant(QString("meego")));
  159. viewer.setMainQmlFile(QLatin1String("qml/gNewsReader/meego/newsreader.qml"));
  160. #endif
  161. viewer.setAttribute(Qt::WA_OpaquePaintEvent);
  162. viewer.setAttribute(Qt::WA_NoSystemBackground);
  163. viewer.viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
  164. viewer.viewport()->setAttribute(Qt::WA_NoSystemBackground);
  165. viewer.showExpanded();
  166. splash.finish(&viewer);
  167. QApplication::setAttribute(Qt::AA_S60DisablePartialScreenInputMode, false);
  168. return app->exec();
  169. #ifdef Q_OS_SYMBIAN
  170. if(&pixmap != NULL) delete &pixmap;
  171. if(&splash != NULL) delete &splash;
  172. #endif
  173. }