author | victorp@symbian.org |
Wed, 05 May 2010 11:52:23 +0100 | |
changeset 43 | a6c61f6ea350 |
parent 42 | 20be4dd42b12 |
child 44 | 48bcd0bbc1ab |
permissions | -rwxr-xr-x |
42 | 1 |
// //////////////////////////////////////////////////////////////////////////// |
2 |
// Symbian Foundation Example Code |
|
3 |
// |
|
4 |
// This software is in the public domain. No copyright is claimed, and you |
|
5 |
// may use it for any purpose without license from the Symbian Foundation. |
|
6 |
// No warranty for any purpose is expressed or implied by the authors or |
|
7 |
// the Symbian Foundation. |
|
8 |
// //////////////////////////////////////////////////////////////////////////// |
|
9 |
||
10 |
||
11 |
/////////////////////////////////////////////////////////////////////////////// |
|
12 |
// A widget for accessing developer.symbian.org |
|
13 |
||
14 |
||
15 |
// Reference to the WRTKit user interface manager and main view. |
|
16 |
var uiManager; |
|
17 |
||
18 |
// Global settings / URLs and such |
|
19 |
||
20 |
// Symbian.org web site base URL |
|
21 |
//var symbianOrgBaseUrl = "http://staging.foundationhost.org"; |
|
22 |
//var symbianOrgBaseUrlSsl = "https://staging.foundationhost.org"; |
|
23 |
var symbianOrgBaseUrl = "http://developer.symbian.org"; |
|
24 |
var symbianOrgBaseUrlSsl = "https://developer.symbian.org"; |
|
25 |
var registrationURL = symbianOrgBaseUrl + "/main/user_profile/register.php"; |
|
26 |
var blogFeedName = "Symbian Blog"; |
|
27 |
var blogFeedUrl = "http://blog.symbian.org/feed/"; |
|
28 |
||
29 |
// FORUM vars and settings |
|
30 |
var symbianOrgNewThreadUrl = symbianOrgBaseUrl+"/forum/newthread.php?"; |
|
31 |
var symbianOrgNewReplyUrl = symbianOrgBaseUrl+"/forum/newreply.php?"; |
|
32 |
var symbianOrgLoginUrl = symbianOrgBaseUrlSsl+"/main/user_profile/login.php"; |
|
33 |
var symbianOrgLoginUsernameField = "username"; |
|
34 |
var symbianOrgLoginPasswordField = "password"; |
|
35 |
var forumUsername = null; |
|
36 |
var forumPassword = null; |
|
37 |
var Packageid=null; |
|
38 |
var myforumid=null; |
|
39 |
var myforumtitle=null; |
|
40 |
||
41 |
// Feed name, URL etc for forums |
|
42 |
var forumFeedName = "Symbian.org Forums"; |
|
43 |
var forumFeedURL = symbianOrgBaseUrl+ "/forum/external2.php?type=rss2"; //&fulldesc=1&lastpost=1 |
|
44 |
var forumsForumSpecQuery = "&forumid="; |
|
45 |
var forumFeedUpdateFrequency = -1; |
|
46 |
||
47 |
var forumGroupsUrl = symbianOrgBaseUrl+ "/rss/forum.php?type=groups"; |
|
48 |
var forumsListUrl = symbianOrgBaseUrl+ "/rss/forum.php?type=forums&group="; |
|
49 |
var forumThreadUrl = symbianOrgBaseUrl+ "/rss/forum.php?type=threadmsgs&threadid="; |
|
50 |
||
51 |
var bugUrl= symbianOrgBaseUrl + "/bugs/show_bug.cgi?id="; |
|
52 |
var buildresultsUrl = symbianOrgBaseUrl + "/main/source/packages/package/builds.php?package="; |
|
53 |
// Wiki url etc |
|
54 |
var wikiFeedName = "New on Symbian.org Wiki"; |
|
55 |
var wikiFeedUrl = symbianOrgBaseUrl+"/wiki/index.php?title=Special:NewPages&feed=rss"; |
|
56 |
var wikiBaseUrl = symbianOrgBaseUrl+"/wiki/index.php"; |
|
57 |
||
58 |
// Update variables |
|
43
a6c61f6ea350
version 0.2a for Mypackage widget, changes to the Open bugs quaery to not include enhancements
victorp@symbian.org
parents:
42
diff
changeset
|
59 |
var myversion = "0.2a"; |
42 | 60 |
var versionWikiPageUrl = wikiBaseUrl + "/My_Package_Widget"; |
61 |
var versionWikiPageString = "Current widget version is ["; |
|
62 |
var downloadUrl = "http://tiny.symbian.org/mypackage"; |
|
63 |
||
64 |
// UI elements |
|
65 |
||
66 |
// blog / forum instances |
|
67 |
// all are SOScreen subclasses |
|
68 |
var home; // home screen |
|
69 |
var blog; // RSSReader showing blog |
|
70 |
var wiki; // RSSReader showing wiki |
|
71 |
var bugzilla; // RSSReader showing bugzilla feeds |
|
72 |
var forumGroups; // RSSReader showing list of forum groups |
|
73 |
var settings; |
|
74 |
var about; |
|
75 |
||
76 |
// currently showing SOScreen |
|
77 |
var currentScreen = null; |
|
78 |
||
79 |
// Controls for the settings view |
|
80 |
var forumUsernameControl; |
|
81 |
var forumPasswordControl; |
|
82 |
var packageControl; |
|
83 |
var ForumControl; |
|
84 |
||
85 |
// Constants for menu item identifiers. |
|
86 |
var MENU_ITEM_HOME = 0; |
|
87 |
var MENU_ITEM_SETTINGS = 1; |
|
88 |
var MENU_ITEM_REFRESH = 2; |
|
89 |
var MENU_ITEM_ABOUT = 3; |
|
90 |
var MENU_ITEM_CHECK_UPDATE = 4; |
|
91 |
var MENU_ITEM_LARGER_FONT = 5; |
|
92 |
var MENU_ITEM_SMALLER_FONT = 6; |
|
93 |
// Flag indicating weather the web site login has been initiated |
|
94 |
var loginInitiated = false; |
|
95 |
var loginInitiatedCallback = null; |
|
96 |
||
97 |
||
98 |
||
99 |
var widgetHomepage = symbianOrgBaseUrl + "/wiki/index.php?title=Symbian.org_WRT_Widget&action=render"; |
|
100 |
var aboutText = "<strong>My Package "+myversion+"</strong><br>" |
|
101 |
+ "MyPackage WRT Widget is a Web Runtime application which allows mobile " |
|
102 |
+ "access to packag dashboard that collect online information from developer.symbian.org. <br>" |
|
103 |
+ "For more information and updates check <div class=FeedItemLink>" |
|
104 |
+ "<a href=\"JavaScript:void(0)\" onclick=\"openURL('" |
|
105 |
+ widgetHomepage |
|
106 |
+ "'); return false;\">" |
|
107 |
+ "The MyPackage Widget Homepage</a></div><p>" |
|
108 |
+ "My Page Author: Victor Palau<br>" |
|
109 |
+" This Widget heavily borrows from Symbian.org Widget" |
|
110 |
+ "Credits: Ivan Litovski, Ryan Grentz, James Mentz"; |
|
111 |
||
112 |
||
113 |
var currentFontSize = 14; |
|
114 |
||
115 |
// Called from the onload event handler to initialize the widget. |
|
116 |
function init() { |
|
117 |
||
118 |
// set tab-navigation mode and show softkeys |
|
119 |
// (only if we are in the WRT environment) |
|
120 |
if (window.widget) { |
|
121 |
widget.setNavigationEnabled(false); |
|
122 |
window.menu.showSoftkeys(); |
|
123 |
// create menu |
|
124 |
var homeMenuItem = new MenuItem("Home", MENU_ITEM_HOME); |
|
125 |
homeMenuItem.onSelect = menuItemSelected; |
|
126 |
menu.append(homeMenuItem); |
|
127 |
var refreshMenuItem = new MenuItem("Refresh", MENU_ITEM_REFRESH); |
|
128 |
refreshMenuItem.onSelect = menuItemSelected; |
|
129 |
menu.append(refreshMenuItem); |
|
130 |
var settingsMenuItem = new MenuItem("Settings", MENU_ITEM_SETTINGS); |
|
131 |
settingsMenuItem.onSelect = menuItemSelected; |
|
132 |
menu.append(settingsMenuItem); |
|
133 |
var updateMenuItem = new MenuItem("Check for updates", MENU_ITEM_CHECK_UPDATE); |
|
134 |
updateMenuItem.onSelect = menuItemSelected; |
|
135 |
menu.append(updateMenuItem); |
|
136 |
var largerFontMenuItem = new MenuItem("Large font", MENU_ITEM_LARGER_FONT); |
|
137 |
largerFontMenuItem.onSelect = menuItemSelected; |
|
138 |
menu.append(largerFontMenuItem); |
|
139 |
var smallerFontMenuItem = new MenuItem("Small font", MENU_ITEM_SMALLER_FONT); |
|
140 |
smallerFontMenuItem.onSelect = menuItemSelected; |
|
141 |
menu.append(smallerFontMenuItem); |
|
142 |
var aboutMenuItem = new MenuItem("About", MENU_ITEM_ABOUT); |
|
143 |
aboutMenuItem.onSelect = menuItemSelected; |
|
144 |
menu.append(aboutMenuItem); |
|
145 |
} |
|
146 |
||
147 |
||
148 |
// load prefs |
|
149 |
if (!forumUsername || !forumPassword || !Packageid) { |
|
150 |
loadPreferences(); |
|
151 |
} |
|
152 |
// create UI manager |
|
153 |
uiManager = new UIManager(); |
|
154 |
||
155 |
bugzilla = new BugzillaSearchPanel(null); |
|
156 |
||
157 |
// Create the home view |
|
158 |
//home = new ListView(null, "<img src=logo.png>"); |
|
159 |
||
160 |
// soft keys |
|
161 |
bugzilla.setupSoftKeys = function() { |
|
162 |
if (window.widget) { |
|
163 |
menu.setRightSoftkeyLabel("Exit", function(){window.close();}); |
|
164 |
} |
|
165 |
} |
|
166 |
||
167 |
||
168 |
||
169 |
||
170 |
// create settings view |
|
171 |
settings = new ListView(null, createCaption("Settings")); |
|
172 |
settings.previousView = home; |
|
173 |
||
174 |
var settingsIntroLabel = new Label(null, null, |
|
175 |
"In order to access all site features, you must login. " |
|
176 |
+ "If you have not registered yet, please click the 'Register' button below."); |
|
177 |
||
178 |
settings.addControl(settingsIntroLabel); |
|
179 |
// forum username control |
|
180 |
forumUsernameControl = new TextField('forumUsername', "Symbian.org username", forumUsername?forumUsername:""); |
|
181 |
settings.addControl(forumUsernameControl); |
|
182 |
||
183 |
// forum password control |
|
184 |
forumPasswordControl = new TextField('forumPassword', "Symbian.org password", forumPassword?forumPassword:"", true); |
|
185 |
settings.addControl(forumPasswordControl); |
|
186 |
||
187 |
//package ID |
|
188 |
packageControl = new TextField('packageControl', "Bugzilla Package name", Packageid?Packageid:""); |
|
189 |
settings.addControl(packageControl); |
|
190 |
||
191 |
//choose a forum |
|
192 |
ForumControl = new NavigationButton(1, "right.gif", myforumtitle ? "Forum: " + myforumtitle : "Choose a forum from main screen"); |
|
193 |
||
194 |
ForumControl.addEventListener("ActionPerformed", function(){ |
|
195 |
var forum_choose = new RssReader(mypackage, forumsListUrl + "18", new ForumsSettingsFeedPresenter(null), settings, forumListResponseParser); |
|
196 |
forum_choose.show(); |
|
197 |
}); |
|
198 |
||
199 |
settings.addControl(ForumControl); |
|
200 |
||
201 |
// save settings button |
|
202 |
settingsSaveButton = new FormButton(null, "Save"); |
|
203 |
settingsSaveButton.addEventListener("ActionPerformed", saveSettingsClicked); |
|
204 |
settings.addControl(settingsSaveButton); |
|
205 |
||
206 |
||
207 |
||
208 |
// cancel settings button |
|
209 |
var settingsRegisterButton = new FormButton(null, "Register"); |
|
210 |
settingsRegisterButton.addEventListener("ActionPerformed", function(){openURL(registrationURL);}); |
|
211 |
settings.addControl(settingsRegisterButton); |
|
212 |
||
213 |
// cancel settings button |
|
214 |
settingsCancelButton = new FormButton(null, "Cancel"); |
|
215 |
settingsCancelButton.addEventListener("ActionPerformed", function(){settings.goBack();}); |
|
216 |
settings.addControl(settingsCancelButton); |
|
217 |
||
218 |
//Create about view |
|
219 |
about = new ListView(null, createCaption("My Package")); |
|
220 |
about.previousView = home; |
|
221 |
// About label control |
|
222 |
aboutLabel = new ContentPanel(null, null, null, true); |
|
223 |
aboutLabel.setCaption("About this Widget"); |
|
224 |
aboutLabel.setContent(aboutText); |
|
225 |
aboutLabel.setExpanded(true); |
|
226 |
about.addControl(aboutLabel); |
|
227 |
||
228 |
||
229 |
bugzilla.show(); |
|
230 |
login(bugzilla.update(true)); |
|
231 |
setDefaultFontSizeForScreenSize(); |
|
232 |
} |
|
233 |
||
234 |
// Callback for when menu items are selected. |
|
235 |
function menuItemSelected(id) { |
|
236 |
var currentView = uiManager.getView(); |
|
237 |
switch (id) { |
|
238 |
case MENU_ITEM_SETTINGS: |
|
239 |
if ( currentView == settings || currentView == about) { |
|
240 |
settings.previousView = home; |
|
241 |
} else { |
|
242 |
settings.previousView = currentView; |
|
243 |
} |
|
244 |
uiManager.hideNotification(); |
|
245 |
settings.show(); |
|
246 |
break; |
|
247 |
case MENU_ITEM_HOME: |
|
248 |
currentView = bugzilla; |
|
249 |
bugzilla.show(); |
|
250 |
break; |
|
251 |
case MENU_ITEM_REFRESH: |
|
252 |
currentView.update(true); |
|
253 |
break; |
|
254 |
case MENU_ITEM_LARGER_FONT: |
|
255 |
setLargeView(); |
|
256 |
// increaseFontSize(); |
|
257 |
break; |
|
258 |
case MENU_ITEM_SMALLER_FONT: |
|
259 |
setSmallView(); |
|
260 |
// decreaseFontSize(); |
|
261 |
break; |
|
262 |
case MENU_ITEM_CHECK_UPDATE: |
|
263 |
checkForUpdates(); |
|
264 |
break; |
|
265 |
case MENU_ITEM_ABOUT: |
|
266 |
if ( currentView == settings || currentView == about) { |
|
267 |
about.previousView = home; |
|
268 |
} else { |
|
269 |
about.previousView = currentView; |
|
270 |
} |
|
271 |
about.show(); |
|
272 |
break; |
|
273 |
} |
|
274 |
} |
|
275 |
||
276 |
// Loads widget preferences. |
|
277 |
function loadPreferences() { |
|
278 |
if (window.widget) { |
|
279 |
// load settings from widget preferences store |
|
280 |
forumUsername = widget.preferenceForKey("forumUsername"); |
|
281 |
forumPassword = widget.preferenceForKey("forumPassword"); |
|
282 |
Packageid=widget.preferenceForKey("Packageid"); |
|
283 |
myforumid=widget.preferenceForKey("myforumid"); |
|
284 |
myforumtitle=widget.preferenceForKey("myforumtitle"); |
|
285 |
} |
|
286 |
} |
|
287 |
||
288 |
// Loads widget preferences. |
|
289 |
function savePreferences() { |
|
290 |
if (window.widget) { |
|
291 |
// save settings in widget preferences store |
|
292 |
widget.setPreferenceForKey(forumUsername, "forumUsername"); |
|
293 |
widget.setPreferenceForKey(forumPassword, "forumPassword"); |
|
294 |
widget.setPreferenceForKey(Packageid, "Packageid"); |
|
295 |
widget.setPreferenceForKey(myforumid, "myforumid"); |
|
296 |
widget.setPreferenceForKey(myforumtitle, "myforumtitle"); |
|
297 |
||
298 |
} |
|
299 |
} |
|
300 |
||
301 |
// Callback for settings view save button. |
|
302 |
function saveSettingsClicked() { |
|
303 |
var firstboot=true; |
|
304 |
if (!Packageid) { fristboot=false;} |
|
305 |
forumUsername = forumUsernameControl.getText(); |
|
306 |
forumPassword = forumPasswordControl.getText(); |
|
307 |
Packageid = packageControl.getText(); |
|
308 |
||
309 |
// save preferences |
|
310 |
savePreferences(); |
|
311 |
||
312 |
settings.goBack(); |
|
313 |
||
314 |
if ( loginInitiated ) { |
|
315 |
login(loginInitiatedCallback); |
|
316 |
} |
|
317 |
bugzilla.update(firstboot); |
|
318 |
} |
|
319 |
||
320 |
// Opens a URL in a separate browser window |
|
321 |
function openURL(url) { |
|
322 |
if (window.widget) { |
|
323 |
// in WRT |
|
324 |
widget.openURL(url); |
|
325 |
} else { |
|
326 |
// outside WRT |
|
327 |
window.open(url, "NewWindow"); |
|
328 |
} |
|
329 |
} |
|
330 |
||
331 |
var updatePageAjax = null; |
|
332 |
||
333 |
function checkForUpdates() { |
|
334 |
uiManager.showNotification(-1, "wait", "Checking for updates...", -1); |
|
335 |
updatePageAjax = new Ajax(); |
|
336 |
updatePageAjax.onreadystatechange = checkForUpdatesStage2; |
|
337 |
updatePageAjax.open('GET', nocache(versionWikiPageUrl), true); |
|
338 |
updatePageAjax.send(null); |
|
339 |
} |
|
340 |
||
341 |
function checkForUpdatesStage2() { |
|
342 |
if (updatePageAjax.readyState == 4) { |
|
343 |
// extract version number |
|
344 |
var content = updatePageAjax.responseText; |
|
345 |
var ind = content.indexOf(versionWikiPageString); |
|
346 |
if ( ind == -1 ) { |
|
347 |
uiManager.showNotification(3000, "warning", "Update failed, check manually."); |
|
348 |
return; |
|
349 |
} |
|
350 |
ind += versionWikiPageString.length; |
|
351 |
var ind2 = content.indexOf("]",ind); |
|
352 |
if ( ind2 == -1 || (ind2-ind) > 10 ) { |
|
353 |
uiManager.showNotification(3000, "warning", "Update failed, check manually."); |
|
354 |
return; |
|
355 |
} |
|
356 |
var version = content.substring(ind,ind2); |
|
357 |
// compare to this version |
|
358 |
if ( version != myversion ) { |
|
359 |
var answer = confirm("Install new version " + version + "?"); |
|
360 |
if (answer) { |
|
361 |
// ok, we have the update |
|
362 |
uiManager.hideNotification(); |
|
363 |
openURL(nocache(downloadUrl)); |
|
364 |
setTimeout(function () {window.close();}, 1000); |
|
365 |
} else { |
|
366 |
uiManager.showNotification(3000, "info", "Update cancelled."); |
|
367 |
} |
|
368 |
} else { |
|
369 |
uiManager.showNotification(3000, "info", "Up to date!"); |
|
370 |
} |
|
371 |
} |
|
372 |
} |
|
373 |
||
374 |
function createCaption(caption) { |
|
375 |
if (caption.length > 30) { |
|
376 |
caption = caption.substring(0, 30) + "..."; |
|
377 |
} |
|
378 |
return "<table border=0><tr><td style=\"{vertical-align:middle}\">" |
|
379 |
+ "<img src=titlebar.png style=\"{vertical-align:middle}\" >" |
|
380 |
+ "</td><td style=\"{vertical-align:middle}\"> " |
|
381 |
+ "<p class=ListViewCaptionText>" + caption +"</p></td></tr></table>"; |
|
382 |
} |
|
383 |
||
384 |
function setDefaultFontSizeForScreenSize(){ |
|
385 |
// no preference available, check screen size |
|
386 |
if (window.innerWidth > 400 || window.innerHeight > 400) { |
|
387 |
// hi res screen, use large font |
|
388 |
setLargeView(); |
|
389 |
} |
|
390 |
else { |
|
391 |
// lo res screen, use small font |
|
392 |
setSmallView(); |
|
393 |
} |
|
394 |
} |
|
395 |
||
396 |
function setLargeView(){ |
|
397 |
document.getElementById('stylesheet').href = 'WRTKit/Resources/UI-large.css'; |
|
398 |
// setCssBodyFontSize(22); |
|
399 |
} |
|
400 |
||
401 |
function setSmallView(){ |
|
402 |
document.getElementById('stylesheet').href = 'WRTKit/Resources/UI.css'; |
|
403 |
// setCssBodyFontSize(14); |
|
404 |
} |
|
405 |
||
406 |
function increaseFontSize(){ |
|
407 |
if (window.widget) { |
|
408 |
setCssBodyFontSize(currentFontSize + 2); |
|
409 |
} |
|
410 |
} |
|
411 |
||
412 |
function decreaseFontSize(){ |
|
413 |
if (window.widget) { |
|
414 |
if (currentFontSize > 4) { |
|
415 |
setCssBodyFontSize(currentFontSize - 2); |
|
416 |
} |
|
417 |
} |
|
418 |
} |
|
419 |
||
420 |
function setCssBodyFontSize(size){ |
|
421 |
if (window.widget) { |
|
422 |
currentFontSize = size; |
|
423 |
var sizestring = "" + size; |
|
424 |
document.body.style.fontSize = sizestring + "px"; |
|
425 |
widget.setPreferenceForKey(sizestring, "fontsize"); |
|
426 |
} |
|
427 |
} |
|
428 |
||
429 |
function nocache(url) { |
|
430 |
if (url.indexOf("?") == -1) { |
|
431 |
url += "?"; |
|
432 |
} else { |
|
433 |
url += "&"; |
|
434 |
} |
|
435 |
url += "xnocache=" + (new Date().getTime()); |
|
436 |
return url; |
|
437 |
} |