/
SystemImpl.cpp
210 lines (172 loc) · 4.4 KB
/
SystemImpl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include <time.h>
#include "ruby/ext/rho/rhoruby.h"
#include "common/RhoDefs.h"
#include "common/RhoPort.h"
//#include "common/StringConverter.h"
#include "common/RhoFilePath.h"
#include "logging/RhoLog.h"
#undef null
#include <qglobal.h>
#include <QWebPage>
#include "MainWindowImpl.h"
using namespace rho;
using namespace rho::common;
extern "C" {
VALUE phone_number()
{
return rho_ruby_get_NIL();
}
static int has_camera()
{
return 0;
}
static double get_screen_ppi_x()
{
//TODO: get_screen_ppi_x
double ret = 96.;
return ret;
}
static double get_screen_ppi_y()
{
//TODO: get_screen_ppi_y
double ret = 96.;
return ret;
}
VALUE rho_sys_get_locale()
{
//TODO: rho_sys_get_locale
return rho_ruby_create_string("en");
}
int rho_sys_get_screen_width()
{
return CMainWindow::getScreenWidth();
}
int rho_sys_get_screen_height()
{
return CMainWindow::getScreenHeight();
}
int rho_sysimpl_get_property(char* szPropName, VALUE* resValue)
{
if (strcasecmp("webview_framework",szPropName) == 0) {
*resValue = rho_ruby_create_string("WEBKIT/" QTWEBKIT_VERSION_STR);
return 1;
}
if (strcasecmp("main_window_closed",szPropName) == 0) {
*resValue = rho_ruby_create_boolean(CMainWindow::mainWindowClosed);
return 1;
}
if (strcasecmp("has_camera",szPropName) == 0) {
*resValue = rho_ruby_create_boolean(has_camera());
return 1;
}
if (strcasecmp("phone_number",szPropName) == 0) {
*resValue = phone_number();
return 1;
}
if (strcasecmp("ppi_x",szPropName) == 0) {
*resValue = rho_ruby_create_double(get_screen_ppi_x());
return 1;
}
if (strcasecmp("ppi_y",szPropName) == 0) {
*resValue = rho_ruby_create_double(get_screen_ppi_y());
return 1;
}
if (strcasecmp("locale",szPropName) == 0) {
*resValue = rho_sys_get_locale();
return 1;
}
if (strcasecmp("country",szPropName) == 0) {
//TODO: "country"
*resValue = rho_ruby_create_string("US");
return 1;
}
if (strcasecmp("device_name",szPropName) == 0) {
*resValue = rho_ruby_create_string("Qt");
return 1;
}
if (strcasecmp("os_version",szPropName) == 0) {
//TODO: "os_version"
*resValue = rho_ruby_create_string(QT_VERSION_STR);
return 1;
}
if (strcasecmp("is_emulator",szPropName) == 0) {
*resValue = rho_ruby_create_boolean(1);
return 1;
}
if (strcasecmp("has_calendar",szPropName) == 0) {
*resValue = rho_ruby_create_boolean(1);
return 1;
}
if (strcasecmp("has_touchscreen",szPropName) == 0) {
*resValue = rho_ruby_create_boolean(1);
return 1;
}
if (strcasecmp("screen_orientation",szPropName) == 0) {
if (rho_sys_get_screen_width() <= rho_sys_get_screen_height())
{
*resValue = rho_ruby_create_string("portrait");
}
else {
*resValue = rho_ruby_create_string("landscape");
}
return 1;
}
return 0;
}
VALUE rho_sys_makephonecall(const char* callname, int nparams, char** param_names, char** param_values)
{
return rho_ruby_get_NIL();
}
static int g_rho_has_network = 1;
void rho_sysimpl_sethas_network(int nValue)
{
g_rho_has_network = nValue;
}
VALUE rho_sys_has_network()
{
return rho_ruby_create_boolean(g_rho_has_network!=0);
}
void rho_sys_app_exit()
{
CMainWindow::getInstance()->exitCommand();
}
void rho_sys_open_url(const char* url)
{
//TODO: rho_sys_open_url
}
void rho_sys_run_app(const char *appname, VALUE params)
{
//TODO: rho_sys_run_app
}
void rho_sys_bring_to_front()
{
// TODO: rho_sys_bring_to_front
LOG(INFO) + "rho_sys_bring_to_front() has no implementation in RhoSimulator.";
}
void rho_sys_report_app_started()
{
// TODO: rho_sys_report_app_started
LOG(INFO) + "rho_sys_report_app_started() has no implementation in RhoSimulator.";
}
int rho_sys_is_app_installed(const char *appname)
{
int nRet = 0;
//TODO: rho_sys_is_app_installed
return nRet;
}
void rho_sys_app_install(const char *url)
{
rho_sys_open_url(url);
}
void rho_sys_app_uninstall(const char *appname)
{
//TODO: rho_sys_app_uninstall
}
#ifndef OS_WINDOWS
int rho_sys_set_sleeping(int sleeping)
{
//TODO: rho_sys_set_sleeping
return 1;
}
#endif
} //extern "C"