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