PageRenderTime 29ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/commonAPI/coreapi/ext/platform/qt/src/CSystemImpl.cpp

http://github.com/rhomobile/rhodes
C++ | 318 lines | 232 code | 54 blank | 32 comment | 2 complexity | 0204b352e6f866c4ae96979af5ed9ed9 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, MIT, Apache-2.0, LGPL-2.1, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. #include "../../../shared/SystemImplBase.h"
  2. #include "common/RhoConf.h"
  3. #include "logging/RhoLog.h"
  4. #include "../../platform/shared/qt/rhodes/impl/MainWindowImpl.h"
  5. #include "../../platform/shared/qt/rhodes/RhoSimulator.h"
  6. #undef null
  7. // commented for OSX build, but headers seems to unused
  8. //#include <qwebkitglobal.h>
  9. //#if QT_VERSION >= 0x050000
  10. //#include <QtWebKit/qtwebkitversion.h>
  11. //#endif
  12. //#include <qtwebkitversion.h>
  13. //#include <qwebkitglobal.h>
  14. #include <QLocale>
  15. #include <QDesktopServices>
  16. #include <QUrl>
  17. #undef DEFAULT_LOGCATEGORY
  18. #define DEFAULT_LOGCATEGORY "System"
  19. namespace rho {
  20. using namespace apiGenerator;
  21. class CSystemImpl: public CSystemImplBase
  22. {
  23. public:
  24. CSystemImpl(): CSystemImplBase(){}
  25. virtual void getScreenWidth(CMethodResult& oResult);
  26. virtual void getScreenHeight(CMethodResult& oResult);
  27. virtual void getScreenOrientation(CMethodResult& oResult);
  28. virtual void getPpiX(CMethodResult& oResult);
  29. virtual void getPpiY(CMethodResult& oResult);
  30. virtual void getPhoneId(CMethodResult& oResult);
  31. virtual void getDeviceName(CMethodResult& oResult);
  32. virtual void getOsVersion(CMethodResult& oResult);
  33. virtual void getLocale(CMethodResult& oResult);
  34. virtual void getCountry(CMethodResult& oResult);
  35. virtual void getIsEmulator(CMethodResult& oResult);
  36. virtual void getHasCalendar(CMethodResult& oResult);
  37. virtual void getOemInfo(CMethodResult& oResult);
  38. virtual void getUuid(CMethodResult& oResult);
  39. virtual void getHttpProxyURI(CMethodResult& oResult);
  40. virtual void setHttpProxyURI( const rho::String& value, CMethodResult& oResult);
  41. virtual void getLockWindowSize(CMethodResult& oResult);
  42. virtual void setLockWindowSize( bool value, CMethodResult& oResult);
  43. //virtual void getKeyboardState(CMethodResult& oResult);
  44. //virtual void setKeyboardState( const rho::String& value, CMethodResult& oResult);
  45. virtual void getFullScreen(CMethodResult& oResult);
  46. virtual void setFullScreen( bool value, CMethodResult& oResult);
  47. virtual void getScreenAutoRotate(CMethodResult& oResult);
  48. virtual void setScreenAutoRotate( bool value, CMethodResult& oResult);
  49. virtual void getHasTouchscreen(rho::apiGenerator::CMethodResult& oResult);
  50. virtual void getScreenSleeping(rho::apiGenerator::CMethodResult& oResult);
  51. virtual void setScreenSleeping( bool value, rho::apiGenerator::CMethodResult& oResult);
  52. virtual void applicationInstall( const rho::String& applicationUrl, CMethodResult& oResult);
  53. virtual void isApplicationInstalled( const rho::String& applicationName, CMethodResult& oResult);
  54. virtual void applicationUninstall( const rho::String& applicationName, CMethodResult& oResult);
  55. virtual void openUrl( const rho::String& url, CMethodResult& oResult);
  56. //virtual void setRegistrySetting( int hive, int type, const rho::String& subKey, const rho::String& setting, const rho::String& value, rho::apiGenerator::CMethodResult& oResult);
  57. //virtual void getRegistrySetting( int hive, const rho::String& subKey, const rho::String& setting, rho::apiGenerator::CMethodResult& oResult);
  58. virtual void setWindowFrame( int x, int y, int width, int height, CMethodResult& oResult);
  59. virtual void setWindowPosition( int x, int y, CMethodResult& oResult);
  60. virtual void setWindowSize( int width, int height, rho::apiGenerator::CMethodResult& oResult);
  61. virtual void getWebviewFramework(rho::apiGenerator::CMethodResult& oResult);
  62. virtual void bringToFront(rho::apiGenerator::CMethodResult& oResult);
  63. virtual void runApplication( const rho::String& appName, const rho::String& params, bool blockingCall, rho::apiGenerator::CMethodResult& oResult);
  64. virtual void getMain_window_closed(rho::apiGenerator::CMethodResult& oResult);
  65. virtual void set_http_proxy_url( const rho::String& proxyURI, rho::apiGenerator::CMethodResult& oResult);
  66. virtual void unset_http_proxy(rho::apiGenerator::CMethodResult& oResult);
  67. };
  68. void CSystemImpl::getOsVersion(CMethodResult& oResult)
  69. {
  70. #ifndef OS_LINUX
  71. oResult.set(String(RHOSIMULATOR_NAME " v" RHOSIMULATOR_VERSION));
  72. #endif
  73. }
  74. void CSystemImpl::getIsEmulator(CMethodResult& oResult)
  75. {
  76. oResult.set(true);
  77. }
  78. void CSystemImpl::getScreenWidth(CMethodResult& oResult)
  79. {
  80. oResult.set(CMainWindow::getScreenWidth());
  81. }
  82. void CSystemImpl::getScreenHeight(CMethodResult& oResult)
  83. {
  84. oResult.set(CMainWindow::getScreenHeight());
  85. }
  86. void CSystemImpl::getScreenOrientation(CMethodResult& oResult)
  87. {
  88. oResult.set(StringW(CMainWindow::getScreenWidth() <= CMainWindow::getScreenHeight() ? L"portrait" : L"landscape"));
  89. }
  90. void CSystemImpl::getPpiX(CMethodResult& oResult)
  91. {
  92. oResult.set(CMainWindow::getInstance()->getLogicalDpiX());
  93. }
  94. void CSystemImpl::getPpiY(CMethodResult& oResult)
  95. {
  96. oResult.set(CMainWindow::getInstance()->getLogicalDpiY());
  97. }
  98. void CSystemImpl::getPhoneId(CMethodResult& oResult)
  99. {
  100. //oResult.set(...);
  101. getOsVersion(oResult);
  102. }
  103. void CSystemImpl::getDeviceName(CMethodResult& oResult)
  104. {
  105. #ifdef RHODES_EMULATOR
  106. oResult.set(String("RhoSimulator"));
  107. #else
  108. oResult.set(String("Qt"));
  109. #endif
  110. }
  111. void CSystemImpl::getLocale(CMethodResult& oResult)
  112. {
  113. oResult.set(String(QLocale::system().name().left(2).toStdString().c_str()));
  114. }
  115. void CSystemImpl::getCountry(CMethodResult& oResult)
  116. {
  117. oResult.set(String(QLocale::system().name().right(2).toStdString().c_str()));
  118. }
  119. void CSystemImpl::getHasCalendar(CMethodResult& oResult)
  120. {
  121. oResult.set(true);
  122. }
  123. void CSystemImpl::getOemInfo(CMethodResult& oResult)
  124. {
  125. //oResult.set(...);
  126. }
  127. void CSystemImpl::getUuid(CMethodResult& oResult)
  128. {
  129. //oResult.set(...);
  130. }
  131. void CSystemImpl::getLockWindowSize(CMethodResult& oResult){}
  132. void CSystemImpl::setLockWindowSize( bool value, CMethodResult& oResult){}
  133. //void CSystemImpl::getKeyboardState(CMethodResult& oResult){}
  134. //void CSystemImpl::setKeyboardState( const rho::String& value, CMethodResult& oResult){}
  135. void CSystemImpl::getFullScreen(CMethodResult& oResult)
  136. {
  137. //all apps working in full screen mode on WP8
  138. oResult.set(CMainWindow::getInstance()->getFullScreen());
  139. }
  140. void CSystemImpl::setFullScreen(bool value, CMethodResult& oResult)
  141. {
  142. CMainWindow::getInstance()->fullscreenCommand(value);
  143. }
  144. void CSystemImpl::getScreenAutoRotate(CMethodResult& oResult)
  145. {
  146. oResult.set(false);
  147. }
  148. void CSystemImpl::setScreenAutoRotate( bool value, CMethodResult& oResult)
  149. {
  150. // TODO: impolement auto rotate
  151. }
  152. void CSystemImpl::applicationInstall( const rho::String& applicationUrl, CMethodResult& oResult)
  153. {
  154. }
  155. void CSystemImpl::isApplicationInstalled( const rho::String& applicationName, CMethodResult& oResult)
  156. {
  157. oResult.set(false);
  158. }
  159. void CSystemImpl::applicationUninstall( const rho::String& applicationName, CMethodResult& oResult)
  160. {
  161. }
  162. void CSystemImpl::openUrl( const rho::String& url, CMethodResult& oResult)
  163. {
  164. QString sUrl = QString::fromStdString(url);
  165. if (sUrl.startsWith("/"))
  166. sUrl.prepend("file://");
  167. QDesktopServices::openUrl(QUrl(sUrl));
  168. }
  169. void CSystemImpl::getMain_window_closed(rho::apiGenerator::CMethodResult& oResult)
  170. {
  171. oResult.set(CMainWindow::mainWindowClosed);
  172. }
  173. void CSystemImpl::runApplication( const rho::String& appName, const rho::String& params, bool blockingCall, CMethodResult& oResult)
  174. {
  175. //unsupported
  176. }
  177. /* use default implementation from SystemImplBase.cpp
  178. void CSystemImpl::setRegistrySetting( int hive, int type, const rho::String& subKey, const rho::String& setting, const rho::String& value, rho::apiGenerator::CMethodResult& oResult)
  179. {
  180. //unsupported
  181. }
  182. void CSystemImpl::getRegistrySetting( int hive, const rho::String& subKey, const rho::String& setting, rho::apiGenerator::CMethodResult& oResult)
  183. {
  184. //unsupported
  185. }
  186. */
  187. void CSystemImpl::setWindowFrame(int x, int y, int width, int height, CMethodResult& oResult)
  188. {
  189. CMainWindow::getInstance()->setFrame(x, y, width, height);
  190. }
  191. void CSystemImpl::setWindowPosition( int x, int y, CMethodResult& oResult)
  192. {
  193. CMainWindow::getInstance()->setPosition(x, y);
  194. }
  195. extern "C" const char* rho_sys_qt_getWebviewFramework();
  196. void CSystemImpl::getWebviewFramework(rho::apiGenerator::CMethodResult& oResult)
  197. {
  198. oResult.set(String(rho_sys_qt_getWebviewFramework()));
  199. }
  200. void CSystemImpl::bringToFront(rho::apiGenerator::CMethodResult& oResult)
  201. {
  202. CMainWindow::getInstance()->bringToFront();
  203. }
  204. extern "C" const char* rho_sys_get_http_proxy_url();
  205. extern "C" void rho_sys_set_http_proxy_url(const char* url);
  206. extern "C" void rho_sys_unset_http_proxy();
  207. void CSystemImpl::getHttpProxyURI(CMethodResult& oResult)
  208. {
  209. oResult.set(rho_sys_get_http_proxy_url());
  210. }
  211. void CSystemImpl::setHttpProxyURI( const rho::String& value, CMethodResult& oResult)
  212. {
  213. if ( value.length() )
  214. rho_sys_set_http_proxy_url( value.c_str() );
  215. else
  216. rho_sys_unset_http_proxy();
  217. }
  218. void CSystemImpl::getHasTouchscreen(rho::apiGenerator::CMethodResult& oResult)
  219. {
  220. oResult.set(true);
  221. }
  222. void CSystemImpl::getScreenSleeping(rho::apiGenerator::CMethodResult& oResult)
  223. {
  224. oResult.set(false);
  225. }
  226. void CSystemImpl::setScreenSleeping( bool value, rho::apiGenerator::CMethodResult& oResult)
  227. {
  228. //unsupported
  229. }
  230. void CSystemImpl::setWindowSize( int width, int height, rho::apiGenerator::CMethodResult& oResult)
  231. {
  232. CMainWindow::getInstance()->setSize(width, height);
  233. }
  234. void CSystemImpl::set_http_proxy_url( const rho::String& proxyURI, rho::apiGenerator::CMethodResult& oResult)
  235. {
  236. rho_sys_set_http_proxy_url( proxyURI.c_str() );
  237. }
  238. void CSystemImpl::unset_http_proxy(rho::apiGenerator::CMethodResult& oResult)
  239. {
  240. rho_sys_unset_http_proxy();
  241. }
  242. ////////////////////////////////////////////////////////////////////////
  243. class CSystemSingleton: public CModuleSingletonBase<ISystemSingleton>
  244. {
  245. public:
  246. ~CSystemSingleton(){}
  247. rho::StringW getInitialDefaultID(){return L"1";}
  248. rho::StringW getDefaultID(){return L"1";}
  249. void setDefaultID(const rho::StringW& strI){}
  250. };
  251. class CSystemFactory: public CSystemFactoryBase
  252. {
  253. public:
  254. ~CSystemFactory(){}
  255. ISystemSingleton* createModuleSingleton(){ return new CSystemImpl(); }
  256. };
  257. extern "C" void Init_System()
  258. {
  259. CSystemFactory::setInstance( new CSystemFactory() );
  260. Init_System_API();
  261. RHODESAPP().getExtManager().requireRubyFile("RhoSystemApi");
  262. }
  263. }