1 /*jslint 
  2 browser: true,
  3 nomen: false,
  4 debug: true,
  5 forin: true,
  6 undef: true,
  7 white: false,
  8 onevar: false 
  9  */
 10 var sc;
 11  
 12 /**
 13  * These are system-oriented functions, mostly utilizing AIR apis
 14  * to interact with the OS
 15  * 
 16  * NOTE: to use all these helpers, you must additionally load a platform-specific definition file!
 17  */
 18 
 19 /**
 20  * @constant 
 21  */
 22 var SPAZCORE_PLATFORM_AIR			= 'AIR';
 23 /**
 24  * @constant 
 25  */
 26 var SPAZCORE_PLATFORM_WEBOS		= 'webOS';
 27 /**
 28  * @constant 
 29  */
 30 var SPAZCORE_PLATFORM_TITANIUM	= 'Titanium';
 31 /**
 32  * @constant 
 33  */
 34 var SPAZCORE_PLATFORM_UNKNOWN		= '__UNKNOWN';
 35 
 36 
 37 /**
 38  * @constant 
 39  */
 40 var SPAZCORE_OS_WINDOWS		= 'Windows';
 41 /**
 42  * @constant 
 43  */
 44 var SPAZCORE_OS_LINUX		= 'Linux';
 45 /**
 46  * @constant 
 47  */
 48 var SPAZCORE_OS_MACOS		= 'MacOS';
 49 /**
 50  * @constant 
 51  */
 52 var SPAZCORE_OS_UNKNOWN		= '__OS_UNKNOWN';
 53 
 54 
 55 /**
 56  * error reporting levels 
 57  */
 58 /**
 59  * @constant 
 60  */
 61 var SPAZCORE_DUMPLEVEL_DEBUG   = 4;
 62 /**
 63  * @constant 
 64  */
 65 var SPAZCORE_DUMPLEVEL_NOTICE  = 3;
 66 /**
 67  * @constant 
 68  */
 69 var SPAZCORE_DUMPLEVEL_WARNING = 2;
 70 /**
 71  * @constant 
 72  */
 73 var SPAZCORE_DUMPLEVEL_ERROR   = 1;
 74 /**
 75  * @constant 
 76  */
 77 var SPAZCORE_DUMPLEVEL_NONE    = 0; // this means "never ever dump anything!"
 78 
 79 
 80 
 81 
 82 
 83 /**
 84 * Returns a string identifier for the platform.
 85 * 
 86 * Right now these checks are really, really basic
 87 * 
 88 * @return {String} an identifier for the platform
 89 * @member sc.helpers
 90 */
 91 sc.helpers.getPlatform = function() {
 92 	if (window.runtime) {
 93 		return SPAZCORE_PLATFORM_AIR;
 94 	}
 95 	if (window.Mojo) {
 96 		return SPAZCORE_PLATFORM_WEBOS;
 97 	}
 98 	if (window.Titanium) {
 99 		return SPAZCORE_PLATFORM_TITANIUM;
100 	}
101 	return SPAZCORE_PLATFORM_UNKNOWN;
102 };
103 
104 /**
105 * checks to see if current platform is the one passed in
106 * 
107 * use one of the defined constants, like SPAZCORE_PLATFORM_AIR
108 * 
109 * @param {String} str the platform you're checking for
110 * 
111 * @member sc.helpers
112 */
113 sc.helpers.isPlatform = function(str) {
114 	var pform = sc.helpers.getPlatform();
115 	if ( pform.toLowerCase() === str.toLowerCase() ) {
116 		return true;
117 	} else {
118 		return false;
119 	}
120 };
121 
122 /**
123  * @member sc.helpers 
124  */
125 sc.helpers.isAIR = function() {
126 	return sc.helpers.isPlatform(SPAZCORE_PLATFORM_AIR);
127 };
128 
129 /**
130  * @member sc.helpers 
131  */
132 sc.helpers.iswebOS = function() {
133 	return sc.helpers.isPlatform(SPAZCORE_PLATFORM_WEBOS);
134 };
135 
136 /**
137  * @member sc.helpers 
138  */
139 sc.helpers.isTitanium = function() {
140 	return sc.helpers.isPlatform(SPAZCORE_PLATFORM_TITANIUM);
141 };
142 
143 
144 
145 /**
146  * Helper to send a debug dump 
147  * @member sc.helpers
148 
*/
149 sc.helpers.debug = function(obj) {
150 	sc.helpers.dump(obj, SPAZCORE_DUMPLEVEL_DEBUG);
151 };
152 
153 /**
154  * helper to send a notice dump 
155  * @member sc.helpers
156 
*/
157 sc.helpers.note = function(obj) {
158 	sc.helpers.dump(obj, SPAZCORE_DUMPLEVEL_NOTICE);
159 };
160 
161 /**
162  * helper to send a warn dump 
163  * @member sc.helpers
164 
*/
165 sc.helpers.warn = function(obj) {
166 	sc.helpers.dump(obj, SPAZCORE_DUMPLEVEL_WARNING);
167 };
168 
169 /**
170  * helper to send an error dump 
171  * @member sc.helpers
172 
*/
173 sc.helpers.error = function(obj) {
174 	sc.helpers.dump(obj, SPAZCORE_DUMPLEVEL_ERROR);
175 };
176 
177 
178 /**
179  * A simple logging function
180  * @platformstub
181  * @member sc.helpers
182 
*/
183 sc.helpers.dump = function(obj, level) {
184 	console.log(obj);
185 };
186 
187 /**
188  * Open a URL in the default system web browser
189  * @platformstub
190  * @member sc.helpers
191 
*/
192 sc.helpers.openInBrowser = function(url) {
193 	window.open(url);
194 };
195 
196 
197 /**
198  * Returns the current application version string
199  * @platformstub
200  * @member sc.helpers
201 
*/
202 sc.helpers.getAppVersion = function() {
203 	// stub
204 };
205 
206 
207 /**
208  * Returns the user agent string for the app
209  * @platformstub
210  * @member sc.helpers
211 
*/
212 sc.helpers.getUserAgent = function() {
213 	// stub
214 };
215 
216 /**
217  * Sets the user agent string for the app
218  * @platformstub
219  * @member sc.helpers
220 
*/
221 sc.helpers.setUserAgent = function(uastring) {
222 	// stub
223 };
224 
225 /**
226  * Gets clipboard text
227  * @platformstub
228  * @member sc.helpers
229 
*/
230 sc.helpers.getClipboardText = function() {
231 	// stub
232 };
233 
234 /**
235  * Sets clipboard text
236  * @platformstub
237  * @member sc.helpers
238 
*/
239 sc.helpers.setClipboardText = function(text) {
240 	// stub
241 };
242 
243 
244 /**
245  * Loads a value for a key from EncryptedLocalStore
246  * @platformstub
247  * @member sc.helpers
248 
*/
249 sc.helpers.getEncryptedValue = function(key) {
250 	// stub
251 };
252 
253 /**
254  * Sets a value in the EncryptedLocalStore of AIR
255  * @platformstub
256  * @member sc.helpers
257 
*/
258 sc.helpers.setEncryptedValue = function(key, val) {
259 	// stub
260 };
261 
262 
263 /**
264  * Get the app storage directory
265  * @TODO is there an equivalent for this on all platforms?
266  * @platformstub
267  * @member sc.helpers
268 
*/
269 sc.helpers.getAppStoreDir = function() {
270 	// stub
271 };
272 
273 /**
274  * Get the preferences file
275  * @TODO this should be removed and we rely on the preferences lib 
276  * @member sc.helpers
277 
*/
278 sc.helpers.getPreferencesFile = function(name, create) {
279 	// stub
280 };
281 
282 /**
283  * initializes a file at the given location. set overwrite to true
284  * to clear out an existing file.
285  * returns the air.File object or false
286  * @platformstub
287 */
288 sc.helpers.init_file = function(path, overwrite) {
289 	// stub
290 };
291 
292 
293 /**
294 * Returns a string identifier for the OS.
295 * 
296 * @return {String} an identifier for the OS.  See the SPAZCORE_OS_* variables
297 */
298 sc.helpers.getOS = function() {
299 	// stub
300 	return SPAZCORE_OS_UNKNOWN;
301 };
302 
303 /**
304 * checks to see if current platform is the one passed in. Use one of the defined constants, like SPAZCORE_OS_WINDOWS
305 * 
306 * @param {String} str the platform you're checking for
307 * @member sc.helpers
308 */
309 sc.helpers.isOS = function(str) {
310 	var type = sc.helpers.getOS();
311 	if (type === str) {
312 		return true;
313 	}
314 	return false;
315 };
316 
317 /**
318  * @member sc.helpers 
319  */
320 sc.helpers.isWindows = function() {
321 	return sc.helpers.isOS(SPAZCORE_OS_WINDOWS);
322 };
323 
324 /**
325  * @member sc.helpers 
326  */
327 sc.helpers.isLinux = function() {
328 	return sc.helpers.isOS(SPAZCORE_OS_LINUX);
329 };
330 
331 /**
332  * @member sc.helpers 
333  */
334 sc.helpers.isMacOS = function() {
335 	return sc.helpers.isOS(SPAZCORE_OS_MACOS);
336 };
337