Advertisement
patrickc

Untitled

Aug 12th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     The contents of this file are subject to the Mozilla Public License
  3.     Version 1.1 (the "License"); you may not use this file except in
  4.     compliance with the License. You may obtain a copy of the License at
  5.     http://www.mozilla.org/MPL/
  6.  
  7.     Software distributed under the License is distributed on an "AS IS"
  8.     basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9.     License for the specific language governing rights and limitations
  10.     under the License.
  11.  
  12.     The Original Code is OpenMobl Systems code.
  13.  
  14.     The Initial Developer of the Original Code is OpenMobl Systems.
  15.     Portions created by OpenMobl Systems are Copyright (C) 2010-2011
  16.     OpenMobl Systems. All Rights Reserved.
  17.  
  18.     Contributor(s):
  19.         OpenMobl Systems
  20.         Donald C. Kirker <donald.kirker@openmobl.com>
  21.  
  22.     Alternatively, the contents of this file may be used under the terms
  23.     of the GNU General Public License Version 2 license (the  "GPL"), in
  24.     which case the provisions of GPL License are applicable instead of
  25.     those above. If you wish to allow use of your version of this file only
  26.     under the terms of the GPL License and not to allow others to use
  27.     your version of this file under the MPL, indicate your decision by
  28.     deleting the provisions above and replace them with the notice and
  29.     other provisions required by the GPL License. If you do not delete
  30.     the provisions above, a recipient may use your version of this file
  31.     under either the MPL or the GPL License.
  32.  */
  33.  
  34. Universe = {};
  35.  
  36. function AppAssistant()
  37. {
  38.     Mojo.Log.info("AppAssistant#new");
  39.    
  40.     Universe = this;
  41.    
  42.     this.metrix = new Metrix();
  43.     this.identified = false;
  44.    
  45.     this.mainStageName = "main";
  46.     this.dockStageName = "dock";
  47.     this.downloadsStageName = "downloads";
  48.     this.mainSceneName = "page";
  49.     this.dockSceneName = "topsites"; /* Same as topsites */
  50.     this.bookmarksSceneName = "bookmarks";
  51.     this.historySceneName = "history";
  52.     this.preferencesSceneName = "preferences";
  53.     this.viewOptionsSceneName = "viewoptions";
  54.     this.topSitesSceneName = "topsites";
  55.     this.aboutSceneName = "about";
  56.     this.supportSceneName = "appsupportinfo";
  57.     this.helpSceneName = "help";
  58.     this.downloadsSceneName = "download";
  59.    
  60.     //this.menuAssistant = new MenuAssistant(this);
  61.     this.tabManager = undefined;
  62.     this.historyManager = undefined;
  63.     this.bookmarksManager = undefined;
  64.     this.prefsManager = undefined;
  65.     this.cookie = {};
  66.     this.prefs = {};
  67.     this.needSetup = false;
  68. }
  69.  
  70. AppAssistant.prototype.setup = function()
  71. {
  72.     Mojo.Log.info("AppAssistant#setup");
  73.     /*
  74.     This function is for setup tasks that have to happen when the app is first created.
  75.     This should be used to intialize any application-level data structures.
  76.     */
  77.    
  78.     this.prefsManager = new PrefsManager();
  79.     this.tabManager = new TabManager(this.controller);
  80.     this.historyManager = new HistoryManager();
  81.     this.bookmarksManager = new BookmarksManager(this.controller);
  82. };
  83.  
  84. //AppAssistant.prototype.getMenuAssistant = function() { return this.menuAssistant; };
  85. AppAssistant.prototype.getTabManager = function() { return this.tabManager; };
  86. AppAssistant.prototype.getHistoryManager = function() { return this.historyManager; };
  87. AppAssistant.prototype.getBookmarksManager = function() { return this.bookmarksManager; };
  88. AppAssistant.prototype.getPrefsManager = function() { return this.prefsManager; };
  89. AppAssistant.prototype.needsSetup = function() { return this.needSetup; };
  90. AppAssistant.prototype.wasSetup = function() { this.needSetup = false; };
  91. AppAssistant.prototype.hasIdentified = function() { return this.identified; };
  92. AppAssistant.prototype.identify = function()
  93. {
  94.     if (!this.hasIdentified()) {
  95.         this.metrix.postDeviceData(true);
  96.         this.identified = true;
  97.     }
  98. };
  99. AppAssistant.prototype.identifyPrompt = function(controller)
  100. {
  101.     controller.showAlertDialog({
  102.             allowHTMLMessage: true,
  103.             title: $L("Auto Feedback"),
  104.             message: $L("Universe would like to collect anonymous information about your device's model, OS and locale. Is this OK?<br/><br/>You can change your mind or get more information from the &quot;Preferences &amp; Accounts&quot; scene later."),
  105.             onChoose: (function(choice) {
  106.                     if (choice === "yes") {
  107.                         Universe.getPrefsManager().set("enableMetrix", true);
  108.                         Universe.identify();
  109.                     }
  110.                     Universe.getPrefsManager().set("enableMetrixPrompted", true);
  111.                 }).bind(this),
  112.             choices: [
  113.                 { label: $L("Yes"), type: "affirmative", value: "yes" },
  114.                 { label: $L("No"), type: "negative", value: "no" }
  115.             ]
  116.         });
  117. };
  118. AppAssistant.prototype.getActiveStageController = function()
  119. {
  120.     var stageController = this.controller.getStageController(this.mainStageName);
  121.    
  122.     return stageController;
  123. };
  124.  
  125. AppAssistant.prototype.clearHistory = function()
  126. {
  127.     this.getHistoryManager().clearHistory();
  128.     this.getTabManager().clear(TabManager.clearHistory);
  129. };
  130. AppAssistant.prototype.clearCache = function()
  131. {
  132.     this.getTabManager().clear(TabManager.clearCache);
  133. };
  134. AppAssistant.prototype.clearCookies = function()
  135. {
  136.     this.getTabManager().clear(TabManager.clearCookies);
  137. };
  138.  
  139. AppAssistant.prototype.launchSceneInMainCard = function(stageName, sceneName, params)
  140. {
  141.     var stageController = this.controller.getStageProxy(stageName);
  142.     if (stageController) {
  143.         stageController.pushScene(sceneName, params);
  144.     } else {
  145.         var that = this;
  146.         this.controller.createStageWithCallback({
  147.                     name: stageName,
  148.                     lightweight: true,
  149.                 },
  150.                 function(stageController) {
  151.                     stageController.pushScene(sceneName, params);
  152.                 },
  153.                 Mojo.Controller.StageType.card);
  154.     }
  155. };
  156.  
  157. AppAssistant.prototype.launchSceneInDownloads = function(stageName, sceneName, params)
  158. {
  159.     var stageController = this.controller.getStageProxy(stageName);
  160.     if (stageController) {
  161.         stageController.delegateToSceneAssistant("queueUpDownload", params);
  162.     } else {
  163.         var that = this;
  164.         this.controller.createStageWithCallback({
  165.                     name: stageName,
  166.                     lightweight: true,
  167.                 },
  168.                 function(stageController) {
  169.                     stageController.pushScene(sceneName, params);
  170.                 },
  171.                 Mojo.Controller.StageType.card);
  172.     }
  173. };
  174.  
  175. AppAssistant.prototype.launchTouchstone = function(sceneName, params)
  176. {
  177.     var dockStage = this.controller.getStageController(this.dockStageName);
  178.     if (dockStage) {
  179.         dockStage.window.focus();
  180.     } else {
  181.         var f = function(stageController) {
  182.             var newParams = params;
  183.            
  184.             newParams.dockmode = true;
  185.            
  186.             stageController.pushScene(sceneName, newParams);
  187.         }.bind(this);
  188.         this.controller.createStageWithCallback({name: this.dockStageName, lightweight: true}, f, "dockMode"); 
  189.     }
  190. };
  191.  
  192. AppAssistant.prototype.launchFavorites = function(params)
  193. {
  194.     this.launchSceneInMainCard(this.mainStageName, this.favoritesSceneName, params);
  195. };
  196.  
  197. AppAssistant.prototype.launchHistory = function(params)
  198. {
  199.     this.launchSceneInMainCard(this.mainStageName, this.historySceneName, params);
  200. };
  201.  
  202. AppAssistant.prototype.launchPreferences = function(params)
  203. {
  204.     this.launchSceneInMainCard(this.mainStageName, this.preferencesSceneName, params);
  205. };
  206.  
  207. AppAssistant.prototype.launchViewOptions = function(params)
  208. {
  209.     this.launchSceneInMainCard(this.mainStageName, this.viewOptionsSceneName, params);
  210. };
  211.  
  212. AppAssistant.prototype.launchDownloads = function(params)
  213. {
  214.     this.launchSceneInDownloads(this.downloadsStageName, this.downloadsSceneName, params);
  215. };
  216.  
  217. AppAssistant.prototype.launchFilePicker = function(that)
  218. {
  219.     var params = {
  220.         kinds: ["file"],
  221.         extensions: ["htm", "html", "xhtml"],
  222.         defaultKind: "file",
  223.         onSelect: function(file) {
  224.             var url = "file://" + file.fullPath;
  225.            
  226.             this.controller.serviceRequest("palm://com.palm.applicationManager",
  227.                 {
  228.                     method: "open",
  229.                     parameters: {
  230.                         "id": "com.openmobl.app.universe",
  231.                         "params": {"url": url}
  232.                     }
  233.                 });
  234.         }.bind(that)
  235.     };
  236.     Mojo.FilePicker.pickFile(params, that.controller.stageController);
  237. };
  238.  
  239. AppAssistant.prototype.launchAbout = function(params)
  240. {
  241.     this.launchSceneInMainCard(this.mainStageName, this.aboutSceneName, params);
  242. };
  243.  
  244. AppAssistant.prototype.considerForNotification = function(notificationData)
  245. {
  246.     /*
  247.     This function is called if all other notification commanders do not
  248.     process a particular sendToNotification call. The assistant may perform
  249.     any default processing here if desired.
  250.     */
  251. };
  252.  
  253. AppAssistant.prototype.handleLaunch = function(params)
  254. {
  255.     Mojo.Log.info("AppAssistant#handleLaunch");
  256.     /*
  257.     This function is called after the application has launched by the user or
  258.     the applicationManager service. This may be called while the app is already
  259.     running.
  260.  
  261.     This function should handle any application-defined commands stored in the
  262.     params field and launch the main stage, if necessary.
  263.     */
  264.  
  265.     Mojo.Log.info("Launched with params: " + Object.toJSON(params));
  266.  
  267.     var stageName = this.mainStageName + "-" + Date.now();
  268.    
  269.     if (params.dockMode || params.touchstoneMode) {
  270.         this.launchTouchstone(this.dockSceneName, params);
  271.     } else {
  272.         this.getTabManager().openNewTab(params, stageName, this.mainSceneName);
  273.     }
  274. };
  275.  
  276. AppAssistant.prototype.handleCommand = function(event)
  277. {
  278.     //this.menuAssistant.handleCommand(event);
  279. };
  280.  
  281. AppAssistant.prototype.cleanup = function()
  282. {
  283.     /* this function should do any cleanup needed before the app is destroyed */
  284.     this.getPrefsManager().set("rotateLock", false);
  285. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement