home *** CD-ROM | disk | FTP | other *** search
Text File | 2004-10-16 | 48.3 KB | 1,410 lines |
- /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is weatherfox.mozdev.org code.
- *
- * The Initial Developer of the Original Code is
- * Jon Stritar <jstritar@MIT.EDU>.
- * Portions created by the Initial Developer are Copyright (C) 2004
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Jon Stritar <jstritar@MIT.EDU>
- * Richard Klein <richwklein@mchsi.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
- /* Frequency Constants */
- const FREQ_CURRENT = 30;
- const FREQ_FORECAST = 120;
- const FREQ_LINKS = 720;
-
- /* Last Update Prefs */
- const PREF_CURRENT_LAST = "current.last";
- const PREF_FORECAST_LAST = "forecast.last";
- const PREF_LINKS_LAST = "links.last";
-
- /* Cache Prefs */
- const PREF_CURRENT_CACHE = "current.cache";
- const PREF_FORECAST_CACHE = "forecast.cache";
- const PREF_LINKS_CACHE = "links.cache";
-
- /* Notification Prefs */
- const PREF_SLIDER_FREQ = "slider.freq";
- const PREF_SLIDER_COUNT = "slider.count";
-
- /* Profile Location */
- const PROFILE_FILE = "profiles.xml";
-
- /******************************************************************************
- * nsWfUpdateService class constructor
- ******************************************************************************/
- function nsWeatherfoxUpdate()
- {
- //internal variables
- this.mProductCode = "xoap";
- this.mPartnerId = "1005561467";
- this.mLicenseKey = "a388d0d4a8a3f714";
- this.mServer = "http://xoap.weather.com/weather/local/";
- this.mTimer = null;
- this.mTimeOut = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
- this.mHttpRequest = null;
- this.mPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("weatherfox.");
- this.mObsService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
- this.mDOMParser = Components.classes["@mozilla.org/xmlextras/domparser;1"].createInstance(Components.interfaces.nsIDOMParser);
- this.mFileIO = new fileIO();
- this.mLoadingProf = false;
-
- //set internal arrays for storage
- this.mLastError = {};
- this.mLoc = {};
- this.mCurrent = {};
- this.mForecast = new Array();
- this.mPartDay = new Array();
- this.mPartNight = new Array();
- this.mLinks = new Array();
-
-
- //migrate old preferences
- this.migratePrefs();
-
- //add shutdown observer
- this.mObsService.addObserver(this, "xpcom-shutdown", false);
- this.mObsService.addObserver(this, "weatherfox:profile:start", false);
- this.mObsService.addObserver(this, "weatherfox:profile:end", false);
- this.mObsService.addObserver(this, "weatherfox:profile:error", false);
-
- //add prefernce observer
- var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
- pbi.addObserver("", this, false);
-
- //load data
- this.updateData();
- }
-
- nsWeatherfoxUpdate.prototype =
- {
- //readonly attributes fo UI
- get productCode() { return this.mProductCode; },
- get partnerId() { return this.mPartnerId; },
- get licenseKey() { return this.mLicenseKey; },
- get server() { return this.mServer; },
-
- getKeys: function(aName, aCount)
- {
- var asKeys = new Array();
- var sKey = null;
- switch (aName) {
- case "lastError":
- for (sKey in this.mLastError) asKeys.push(sKey);
- aCount.value = asKeys.length;
- break;
- case "location":
- for (sKey in this.mLoc) asKeys.push(sKey);
- aCount.value = asKeys.length;
- break;
- case "current":
- for (sKey in this.mCurrent) asKeys.push(sKey);
- aCount.value = asKeys.length;
- break;
- case "forecast":
- for (sKey in this.mForecast[0]) asKeys.push(sKey);
- aCount.value = asKeys.length;
- break;
- case "day":
- for (sKey in this.mPartDay[0]) asKeys.push(sKey);
- aCount.value = asKeys.length;
- break;
- case "night":
- for (sKey in this.mPartNight[0]) asKeys.push(sKey);
- aCount.value = asKeys.length;
- break;
- case "links":
- for (sKey in this.mLinks[0]) asKeys.push(sKey);
- aCount.value = asKeys.length;
- break;
- }
- asKeys.sort();
- return asKeys;
- },
-
- getLinkCount: function()
- {
- return this.mLinks.length;
- },
-
- getValue: function(aName, aKey, aIndex)
- {
- var val = "";
- switch (aName) {
- case "lastError":
- val = this.mLastError[aKey];
- break;
- case "location":
- val = this.mLoc[aKey];
- break;
- case "current":
- val = this.mCurrent[aKey];
- break;
- case "forecast":
- val = this.mForecast[aIndex][aKey];
- break;
- case "day":
- val = this.mPartDay[aIndex][aKey];
- break;
- case "night":
- val = this.mPartNight[aIndex][aKey];
- break;
- case "links":
- val = this.mLinks[aIndex][aKey];
- break;
- }
- return val;
- },
-
- load: function(aForced)
- {
- //reset last prefs if forced
- if (aForced) {
- this.mPrefs.clearUserPref(PREF_CURRENT_LAST);
- this.mPrefs.clearUserPref(PREF_FORECAST_LAST);
- this.mPrefs.clearUserPref(PREF_LINKS_LAST);
- }
-
- //update the data
- this.updateData();
- },
-
- //main internal function to load data from server
- updateData: function()
- {
-
- // If the locid hasn't been set yet, prompt for it and bail out.
- if (this.mPrefs.getCharPref("locid") == "00000") {
- var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
- var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
- var topWindow = windowManagerInterface.getMostRecentWindow("navigator:browser");
- if (!topWindow)
- topWindow = window.openDialog("chrome://browser/content/browser.xul", "_blank", "chrome,all,dialog=no", "about:blank", null, null);
- topWindow.openDialog("chrome://weatherfox/content/options.xul", "options", "chrome");
- }
- else {
- debug("Updating the data...");
-
- // Notify observers that updating has begun.
- this.mObsService.notifyObservers(null, "weatherfox:update:start", "");
-
- //clear old errors
- this.mLastError = {};
-
- // The array contains true if the data is being refreshed from the server.
- // If false, load the data from the cache.
- var refresh_needed = new Array();
- refresh_needed["CURRENT"] = this.shouldRefresh("CURRENT");
- refresh_needed["FORECAST"] = this.shouldRefresh("FORECAST");
- refresh_needed["LINKS"] = this.shouldRefresh("LINKS");
-
- // Get the cached data and the server data.
- this.getCachedData(refresh_needed);
- this.getServerData(refresh_needed);
-
- if (refresh_needed["CURRENT"] || refresh_needed["FORECAST"] || refresh_needed["LINKS"])
- this.mTimeOut.initWithCallback(this, 10 * 1000, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
-
- }
- },
-
- getCachedData: function(refresh_needed)
- {
- // First find out what files we need to load data from.
- var file_array = new Array();
- var failed = new Array();
- for (var value in refresh_needed) {
- if (!refresh_needed[value]) {
- var file = this.mPrefs.getCharPref(eval("PREF_" + value + "_CACHE"));
- if (!file_array[file])
- file_array[file] = new Array();
- file_array[file][value] = true;
- }
- }
-
- // Then read the files.
- for (file in file_array) {
- var text = this.mFileIO.read(file);
-
- if (!text) {
- for (value in file_array[file])
- if (file_array[file][value])
- failed[value] = true;
- continue;
- }
-
- var doc = this.mDOMParser.parseFromString(text, "text/xml");
- this.parseResponse(doc, file_array[file], false);
-
- debug("Refreshing " + ((file_array[file]["CURRENT"]) ? "current" : "") + " " + ((file_array[file]["FORECAST"]) ? "forecast" : "") + " " + ((file_array[file]["LINKS"]) ? "links" : "") + " from " + file);
- }
-
- if (failed["CURRENT"] || failed["FORECAST"] || failed["LINKS"]) {
- debug("Read failed for " + ((failed["CURRENT"]) ? "current" : "") + " " + ((failed["FORECAST"]) ? "forecast" : "") + " " + ((failed["LINKS"]) ? "links" : "") + " ...");
- this.getServerData(failed);
- } else if (!refresh_needed["CURRENT"] && !refresh_needed["FORECAST"] && !refresh_needed["LINKS"]) {
- debug("Done updating.");
- this.scheduleUpdate();
- }
- },
-
- getServerData: function(refresh_needed)
- {
- var mComponent = this;
-
- // Bail out if nothing needs to be refreshed.
- if (!refresh_needed["CURRENT"] && !refresh_needed["FORECAST"] && !refresh_needed["LINKS"])
- return;
-
- // Construct the query url.
- var query = this.mServer + this.mPrefs.getCharPref("locid") + "?";
-
- // Only query the server for things that we need.
- if (refresh_needed["CURRENT"])
- query += "cc=*&";
- if (refresh_needed["FORECAST"])
- query += "dayf=10&";
- if (refresh_needed["LINKS"])
- query += "link=xoap&";
-
- // Add the unit and the license info.
- query += "unit=" + (this.mPrefs.getBoolPref("celcius") ? "m&" : "s&");
- query += "prod=" + this.mProductCode + "&par=" + this.mPartnerId + "&key=" + this.mLicenseKey;
-
-
- // Replace query with test location:
- //query = "http://web.mit.edu/jstritar/www/test.xml";
-
- debug("Updating " + ((refresh_needed["CURRENT"]) ? "current" : "") + " " + ((refresh_needed["FORECAST"]) ? "forecast" : "") + " " + ((refresh_needed["LINKS"]) ? "links" : "") + " from server.");
-
- this.mHttpRequest = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest);
- this.mHttpRequest.overrideMimeType("text/xml");
- this.mHttpRequest.onload = function () {
- // It didn't timeout, so cancel that timer.
- mComponent.mTimeOut.cancel();
-
- var doc = this.responseXML;
-
- if (mComponent.handleError(doc, this.status))
- return;
-
- // Cache the response, then parse it and update our data.
- mComponent.saveResponse(this.responseText, refresh_needed);
- mComponent.parseResponse(doc, refresh_needed, true);
-
- debug("Done updating");
-
- // Then schedule an update.
- mComponent.scheduleUpdate();
-
- return;
- }
- this.mHttpRequest.open("GET", query, true);
- // Should insert some error handling for when the send timeouts.
- this.mHttpRequest.send(null);
-
- },
-
- handleError: function(doc, status)
- {
- if (status > 200) {
- this.mLastError["type"] = "0";
- this.mLastError["msg"] = "Network Error";
-
- debug ("Error: " + this.mLastError["type"] + this.mLastError["msg"]);
-
- // Then notify the observers of the error.
- this.mObsService.notifyObservers(null, "weatherfox:update:error", "");
- return true;
- }
-
- if (doc.getElementsByTagName("error").length > 0) {
- var error = doc.getElementsByTagName("err")[0];
- debug("Error: " + error.getAttribute("type") + " " + error.firstChild.nodeValue);
-
- // Record error.
- this.mLastError["type"] = error.getAttribute("type");
- this.mLastError["msg"] = error.firstChild.nodeValue;
-
- debug ("Error: " + this.mLastError["type"] + this.mLastError["msg"]);
-
- // Then notify the observers of the error.
- this.mObsService.notifyObservers(null, "weatherfox:update:error", "");
-
- return true;
- }
-
- return false;
- },
-
- saveResponse: function(text, refresh_needed)
- {
- var file;
- var time = (new Date()).valueOf();
- var profile = this.mPrefs.getCharPref("profile");
-
- // Assign file names this way so that the links one gets held longest.
- if (refresh_needed["LINKS"])
- file = "linkscache-" + profile + ".xml";
- else if (refresh_needed["FORECAST"])
- file = "forecastcache-" + profile + ".xml";
- else if (refresh_needed["CURRENT"])
- file = "currentcache-" + profile + ".xml";
-
- // Then save the file...
- this.mFileIO.write(file, text);
-
- // And update the CACHE prefs.
- for (var value in refresh_needed) {
- if (refresh_needed[value]) {
- this.mPrefs.setCharPref(eval("PREF_" + value + "_CACHE"), file);
- this.mPrefs.setCharPref(eval("PREF_" + value + "_LAST"), time);
- }
- }
- },
-
- parseResponse: function(doc, contains, server)
- {
- //XXX should have a better way of parsing this without having to know the structure of the XML
- var w,x,y,z;
- var time = (new Date()).valueOf();
-
- // TODO: clear this.mLoc
- // Parse loc info.
- this.mLoc = {};
- var data_needed = new Array("locale", "ut", "ud", "us", "up", "ur", "dnam", "tm", "lat", "lon", "sunr", "suns", "zone");
-
- for (var value in data_needed)
- this.mLoc[data_needed[value]] = doc.getElementsByTagName(data_needed[value])[0].firstChild.nodeValue;
-
- this.addUnits("loc");
-
- if (contains["CURRENT"]) {
- // Clear old data:
- this.mCurrent = {};
-
- // Then parse in the new data:
- var cc = doc.getElementsByTagName("cc")[0].childNodes;
-
- for (x = 0; x < cc.length; x++) {
- if (cc[x].nodeName == "#text")
- continue;
- if (cc[x].nodeName == "bar" || cc[x].nodeName == "wind" || cc[x].nodeName == "uv") {
- var next_nodes = cc[x].childNodes;
- for (w=0; w < next_nodes.length; w++) {
- if (next_nodes[w].nodeName == "#text")
- continue;
- this.mCurrent[cc[x].nodeName + next_nodes[w].nodeName] = next_nodes[w].firstChild.nodeValue;
- }
- }
- else
- this.mCurrent[cc[x].nodeName] = cc[x].firstChild.nodeValue;
- }
-
- this.addUnits("current");
- this.mObsService.notifyObservers(null, "weatherfox:update:end:current", "");
-
- //do alert notification
- try {
- var sliderfreq = this.mPrefs.getIntPref("slider.freq");
- var slidercount = this.mPrefs.getIntPref("slider.count");
- if (sliderfreq != 0 && server) {
- this.mPrefs.setIntPref("slider.count", (slidercount + 1));
- if (slidercount >= sliderfreq) {
- // Show the slider and reset it's count.
- var alertTitle = this.mCurrent["t"] + ", " + this.mCurrent["tmp"];
- var alertText = this.mLoc["dnam"];
- var alerts = Components.classes["@mozilla.org/alerts-service;1"].getService(Components.interfaces.nsIAlertsService);
- alerts.showAlertNotification("chrome://weatherfox/skin/images/large/" + this.mCurrent["icon"] + ".png", alertTitle, alertText, true, "", this);
- this.mPrefs.setIntPref("slider.count", "1");
- }
- }
- } catch(e) {}
- }
-
- if (contains["FORECAST"]) {
- // Clear old forecast data:
- this.mForecast = new Array();
- this.mPartDay = new Array();
- this.mPartNight = new Array();
-
- //get all the days in the forecast
- var days = doc.getElementsByTagName("day");
- for (x=0; x < days.length; x++) {
- var day_nodes = days[x].childNodes;
- var data = {};
- next_nodes = null;
-
- data["day"] = days[x].getAttribute("t");
- data["date"] = days[x].getAttribute("dt");
-
- //loop through nodes in day
- for (y=0; y < day_nodes.length; y++) {
- if (day_nodes[y].nodeName == "#text")
- continue;
- //get part data
- if (day_nodes[y].nodeName == "part") {
- var part_nodes = day_nodes[y].childNodes;
- var part = {};
- if (day_nodes[y].getAttribute("p") == "d") {
- //loop through nodes in part
- for (z=0; z < part_nodes.length; z++) {
- if (part_nodes[z].nodeName == "#text")
- continue;
- if (part_nodes[z].nodeName == "bar" || part_nodes[z].nodeName == "wind" || part_nodes[z].nodeName == "uv") {
- next_nodes = part_nodes[z].childNodes;
- for (w=0; w < next_nodes.length; w++) {
- if (next_nodes[w].nodeName == "#text")
- continue;
- part[part_nodes[z].nodeName + next_nodes[w].nodeName] = next_nodes[w].firstChild.nodeValue;
- }
- }
- else
- part[part_nodes[z].nodeName] = part_nodes[z].firstChild.nodeValue;
- }
- this.mPartDay[x] = part;
- }
- else {
- //loop through nodes in part
- for (z=0; z < part_nodes.length; z++) {
- if (part_nodes[z].nodeName == "#text")
- continue;
- if (part_nodes[z].nodeName == "bar" || part_nodes[z].nodeName == "wind" || part_nodes[z].nodeName == "uv") {
- next_nodes = part_nodes[z].childNodes;
- for (w=0; w < next_nodes.length; w++) {
- if (next_nodes[w].nodeName == "#text")
- continue;
- part[part_nodes[z].nodeName + next_nodes[w].nodeName] = next_nodes[w].firstChild.nodeValue;
- }
- }
- else
- part[part_nodes[z].nodeName] = part_nodes[z].firstChild.nodeValue;
- }
- this.mPartNight[x] = part;
- }
- }
- else {
- if (day_nodes[y].nodeName == "bar" || day_nodes[y].nodeName == "wind" || day_nodes[y].nodeName == "uv") {
- next_nodes = day_nodes[y].childNodes;
- for (w=0; w < next_nodes.length; w++) {
- if (next_nodes[w].nodeName == "#text")
- continue;
- data[day_nodes[y].nodeName + next_nodes[w].nodeName] = next_nodes[w].firstChild.nodeValue;
- }
- }
- else
- data[day_nodes[y].nodeName] = day_nodes[y].firstChild.nodeValue;
- }
- }
- this.mForecast[x] = data;
- }
-
- this.addUnits("forecast");
- this.mObsService.notifyObservers(null, "weatherfox:update:end:forecast", "");
- }
-
- if (contains["LINKS"]) {
- // Parse links info.
- this.mLinks = new Array();
-
- var links = doc.getElementsByTagName("lnks");
-
- if (links[0].getAttribute("type") == "prmo")
- links = links[0].getElementsByTagName("link");
-
- for (x = 0; x < links.length; x++) {
- // Create the array for this link
- var link_array = {};
- link_array["url"] = links[x].getElementsByTagName("l")[0].firstChild.nodeValue;
- link_array["title"] = links[x].getElementsByTagName("t")[0].firstChild.nodeValue;
-
- // Then insert it into our internal array that holds the links.
- this.mLinks[x] = link_array;
- }
- this.addUnits("links");
- this.mObsService.notifyObservers(null, "weatherfox:update:end:links", "");
- }
- },
-
- addUnits: function(type)
- {
- var deg = String.fromCharCode(176);
-
-
- switch (type) {
- case "loc" :
- this.mLoc["lat"] = addUnit(this.mLoc["lat"], deg);
- this.mLoc["lon"] = addUnit(this.mLoc["lon"], deg);
- break;
- case "current" :
- this.mCurrent["tmp"] = addUnit(this.mCurrent["tmp"], deg + this.mLoc["ut"]);
- this.mCurrent["flik"] = addUnit(this.mCurrent["flik"], deg + this.mLoc["ut"]);
- this.mCurrent["barr"] = addUnit(this.mCurrent["barr"], this.mLoc["ur"]);
- this.mCurrent["winds"] = addUnit(this.mCurrent["winds"], this.mLoc["us"]);
- this.mCurrent["windgust"] = addUnit(this.mCurrent["windgust"], this.mLoc["us"]);
- this.mCurrent["windd"] = addUnit(this.mCurrent["windd"], deg);
- this.mCurrent["hmid"] = addUnit(this.mCurrent["hmid"], "%");
- this.mCurrent["vis"] = addUnit(this.mCurrent["vis"], this.mLoc["ud"]);
- this.mCurrent["dewp"] = addUnit(this.mCurrent["dewp"], deg + this.mLoc["ut"]);
- break;
- case "forecast" :
- for (var x = 0; x < this.mForecast.length; x++) {
- this.mForecast[x]["hi"] = addUnit(this.mForecast[x]["hi"], deg + this.mLoc["ut"]);
- this.mForecast[x]["low"] = addUnit(this.mForecast[x]["low"], deg + this.mLoc["ut"]);
- this.mPartDay[x]["winds"] = addUnit(this.mPartDay[x]["winds"], this.mLoc["us"]);
- this.mPartDay[x]["windgust"] = addUnit(this.mPartDay[x]["windgust"], this.mLoc["us"]);
- this.mPartDay[x]["windd"] = addUnit(this.mPartDay[x]["daywindd"], deg);
- this.mPartDay[x]["ppcp"] = addUnit(this.mPartDay[x]["ppcp"], "%");
- this.mPartDay[x]["hmid"] = addUnit(this.mPartDay[x]["hmid"], "%");
- this.mPartNight[x]["winds"] = addUnit(this.mPartNight[x]["winds"], this.mLoc["us"]);
- this.mPartNight[x]["windgust"] = addUnit(this.mPartNight[x]["windgust"], this.mLoc["us"]);
- this.mPartNight[x]["windd"] = addUnit(this.mPartNight[x]["windd"], deg);
- this.mPartNight[x]["ppcp"] = addUnit(this.mPartNight[x]["ppcp"], "%");
- this.mPartNight[x]["hmid"] = addUnit(this.mPartNight[x]["hmid"], "%");
- }
- break;
- case "links" :
- break;
- }
- },
-
- migratePrefs: function()
- {
- if (this.mPrefs.getBoolPref("migrated"))
- return;
-
- try {
- //only clear last do not migrate
- if (this.mPrefs.prefHasUserValue("lastccr")) {
- this.mPrefs.clearUserPref("lastccr");
- }
- if (this.mPrefs.prefHasUserValue("lastdayfr")) {
- this.mPrefs.clearUserPref("lastdayfr");
- }
- if (this.mPrefs.prefHasUserValue("ccache")) {
- this.mPrefs.setCharPref("current.cache", this.mPrefs.getCharPref("ccache"));
- this.mPrefs.clearUserPref("ccache");
- }
- if (this.mPrefs.prefHasUserValue("cc")) {
- this.mPrefs.setBoolPref("current.display", this.mPrefs.getBoolPref("cc"));
- this.mPrefs.clearUserPref("cc");
- }
- if (this.mPrefs.prefHasUserValue("dayfcache")) {
- this.mPrefs.setCharPref("forecast.cache", this.mPrefs.getCharPref("dayfcache"));
- this.mPrefs.clearUserPref("dayfcache");
- }
- if (this.mPrefs.prefHasUserValue("cccache")) {
- this.mPrefs.setCharPref("current.cache", this.mPrefs.getCharPref("cccache"));
- this.mPrefs.clearUserPref("cccache");
- }
- if (this.mPrefs.prefHasUserValue("days")) {
- this.mPrefs.setIntPref("forecast.days", parseInt(this.mPrefs.getCharPref("days")));
- this.mPrefs.clearUserPref("days");
- }
- if (this.mPrefs.prefHasUserValue("bar")) {
- this.mPrefs.setCharPref("display.bar", this.mPrefs.getCharPref("bar"));
- this.mPrefs.clearUserPref("bar");
- }
- if (this.mPrefs.prefHasUserValue("nextnode")) {
- this.mPrefs.setCharPref("display.nextnode", this.mPrefs.getCharPref("nextnode"));
- this.mPrefs.clearUserPref("nextnode");
- }
- if (this.mPrefs.prefHasUserValue("insertafter")) {
- this.mPrefs.setBoolPref("display.insertafter", this.mPrefs.getBoolPref("insertafter"));
- this.mPrefs.clearUserPref("insertafter");
- }
- if (this.mPrefs.prefHasUserValue("sliderfreq")) {
- this.mPrefs.setIntPref("slider.freq", parseInt(this.mPrefs.getCharPref("sliderfreq")));
- this.mPrefs.clearUserPref("sliderfreq");
- }
- if (this.mPrefs.prefHasUserValue("slidercount")) {
- this.mPrefs.setIntPref("slider.count", parseInt(this.mPrefs.getCharPref("slidercount")));
- this.mPrefs.clearUserPref("slidercount");
- }
-
- this.mPrefs.setBoolPref("migrated",true);
- }
- catch(e) {}
- },
-
- scheduleUpdate: function(force_time)
- {
- var timer_time = null;
-
- if (force_time)
- timer_time = force_time;
- else {
-
- // Schedules the next updateData call.
- var real_time = (new Date()).valueOf();
-
- var next = new Array();
- // Get time till next refresh for each category.
- next[0] = Number(this.mPrefs.getCharPref(PREF_CURRENT_LAST)) + FREQ_CURRENT * 60 * 1000 - real_time;
- next[1] = Number(this.mPrefs.getCharPref(PREF_FORECAST_LAST)) + FREQ_FORECAST * 60 * 1000 - real_time;
- next[2] = Number(this.mPrefs.getCharPref(PREF_LINKS_LAST)) + FREQ_LINKS * 60 * 1000 - real_time;
-
-
- next.sort(function (a, b) { return (a - b) });
-
- // If there will be another refresh within 1 min of the scheduled one, refresh
- // at that point instead --> to clump them together.
-
- if ((next[2] - next[0]) < 15 * 60 * 1000) {
- debug("Timer delayed " + ((next[2] - next[0]) / 60 / 1000).toFixed(1) + " minutes to catch multiple queries.");
- timer_time = next[2];
- }
- else if ((next[1] - next[0]) < 10 * 60 * 1000) {
- debug("Timer delayed " + ((next[1] - next[0]) / 60 / 1000).toFixed(1) + " minutes to catch multiple queries.");
- timer_time = next[1];
- }
- else
- timer_time = next[0];
-
- if (timer_time < 0)
- timer_time = 100;
-
- timer_time += 100;
-
- }
-
- // Create the timer if its not already made
- if (!this.mTimer)
- this.mTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
-
- this.mTimer.cancel();
-
- // Then schedule the timeout.
- this.mTimer.initWithCallback(this, timer_time, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
-
- debug("Next refresh scheduled for " + (timer_time / 1000 / 60).toFixed(1) + " minutes.");
- },
-
- shouldRefresh: function(data)
- {
- var time = (new Date()).valueOf();
-
- // Make sure data is a valid element.
- if ((data != "CURRENT") && (data != "FORECAST") && (data != "LINKS"))
- return false;
-
- // Then get the time for the next refresh.
- var next = Number(this.mPrefs.getCharPref(eval("PREF_" + data + "_LAST"))) + eval("FREQ_" + data) * 60 * 1000;
-
- return ((next - time) <= 0);
- },
-
- ///////////////////////////
- // nsITimerCallback
- notify: function(timer)
- {
- if (timer == this.mTimeOut) {
- debug("Query timed out...");
-
- this.scheduleUpdate(2 * 60 * 1000);
-
- this.mLastError["type"] = "0";
- this.mLastError["msg"] = "Timed out";
-
- // Then notify the observers of the error.
- this.mObsService.notifyObservers(null, "weatherfox:update:error", "");
- }
- else if (timer == this.mTimer) {
- // update the data.
- this.updateData();
- }
- },
-
- ///////////////////////////
- // nsIAlertListener
- onAlertFinished: function() {},
- onAlertClickCallback: function(aCookie)
- {
- var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
- var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
- var topWindow = windowManagerInterface.getMostRecentWindow("navigator:browser");
- if (!topWindow) {
- topWindow = window.openDialog("chrome://browser/content/browser.xul", "_blank", "chrome,all,dialog=no", "about:blank", null, null);
- }
- var browser = topWindow.document.getElementById("content");
- var url = "http://www.weather.com/weather/local/" + this.mPrefs.getCharPref("locid");
- url = url + "?prod=" + this.mProductCode + "&par=" + this.mPartnerId;
- browser.loadURI(url);
- },
-
- /////////////////////////////
- // nsIObserver
- observe: function(aSubject, aTopic, aData)
- {
- switch (aTopic) {
- case "weatherfox:profile:start":
- this.mLoadingProf = true;
- break;
- case "weatherfox:profile:end":
- this.mLoadingProf = false;
- this.scheduleUpdate(100);
- break;
- case "weatherfox:profile:error":
- this.mLoadingProf = false;
- break;
- case "nsPref:changed":
- if (!this.mLoadingProf) {
- if (aData == "locid" || aData == "celcius") {
- if (this.mPrefs.prefHasUserValue(PREF_CURRENT_LAST))
- this.mPrefs.clearUserPref(PREF_CURRENT_LAST);
- if (this.mPrefs.prefHasUserValue(PREF_FORECAST_LAST))
- this.mPrefs.clearUserPref(PREF_FORECAST_LAST);
- if (this.mPrefs.prefHasUserValue(PREF_LINKS_LAST))
- this.mPrefs.clearUserPref(PREF_LINKS_LAST);
- this.scheduleUpdate(250);
- }
- }
- break;
- case "xpcom-shutdown":
-
- // Clean up held observers etc to avoid leaks.
- this.mObsService.removeObserver(this, "xpcom-shutdown");
- this.mObsService.removeObserver(this, "weatherfox:profile:start", false);
- this.mObsService.removeObserver(this, "weatherfox:profile:end", false);
- this.mObsService.removeObserver(this, "weatherfox:profile:error", false);
- var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
- pbi.removeObserver("", this);
-
- // Release strongly held services.
- this.mPrefs = null;
- this.mObsService = null;
- this.mHttpRequest = null;
- this.mDOMParser = null;
-
- this.mFileIO.destroy();
- this.mFileIO = null;
- if (this.mTimer) {
- this.mTimer.cancel();
- this.mTimer = null;
- }
- break;
- }
- },
-
- QueryInterface: function (iid)
- {
- if (!iid.equals(Components.interfaces.nsIWeatherfoxUpdate) &&
- !iid.equals(Components.interfaces.nsIAlertListener)
- && !iid.equals(Components.interfaces.nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- }
- }
-
- function nsWeatherfoxProfile()
- {
- //set up base variables
- this.mPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("weatherfox.");
- this.mObsService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
- this.mDOMParser = Components.classes["@mozilla.org/xmlextras/domparser;1"].createInstance(Components.interfaces.nsIDOMParser);
- this.mSerializer = Components.classes["@mozilla.org/xmlextras/xmlserializer;1"].createInstance(Components.interfaces.nsIDOMSerializer);
- this.mFileIO = new fileIO();
- this.mDirService = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
-
- this.mPrefList = [["locid", "Char"],
- ["celcius", "Bool"],
- ["display.bar", "Char"],
- ["display.nextnode", "Char"],
- ["display.insertafter", "Bool"],
- ["current.display", "Bool"],
- ["current.mode", "Int"],
- ["current.last", "Char"],
- ["current.cache", "Char"],
- ["current.label", "Char"],
- ["current.tooltip", "Char"],
- ["forecast.days", "Int"],
- ["forecast.mode", "Int"],
- ["forecast.parts", "Int"],
- ["forecast.last", "Char"],
- ["forecast.cache", "Char"],
- ["forecast.label", "Char"],
- ["forecast.tooltip", "Char"],
- ["links.last", "Char"],
- ["links.cache", "Char"],
- ["slider.freq", "Int"],
- ["slider.count", "Int"],
- ["current.tipicon", "Bool"],
- ["forecast.tipicon", "Bool"]];
- this.mDoc = this.getProfiles();
- this.mProfile = this.mPrefs.getCharPref("profile");
- //add shutdown observer
- this.mObsService.addObserver(this, "xpcom-shutdown", false);
-
- //add prefernce observer for locid
- var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
- pbi.addObserver("", this, false);
-
- return this;
- }
-
- nsWeatherfoxProfile.prototype =
- {
- saveCurrent: function()
- {
- this.saveProfile(this.mProfile);
- },
-
- saveProfile: function(name)
- {
- name = this.stripName(name);
- debug("Saving profile " + name);
-
- var profile = this.getProfileNode(name);
- var profiles = this.mDoc.getElementsByTagName("profiles")[0];
- var new_profile = false;
- var pref;
-
- if (profile)
- profile.parentNode.removeChild(profile);
- else {
- // set new_profile so we can rename the cache files down there after the profile node has been created
- debug("Creating a NEW profile");
- new_profile = true;
- this.mObsService.notifyObservers(null, "weatherfox:profile:new", name);
- }
-
- profile = this.mDoc.createElement("profile");
- profile.setAttribute("id", name);
-
- for (var x = 0; x < this.mPrefList.length; x++) {
- pref = this.mDoc.createElement("pref");
- pref.setAttribute("name", this.mPrefList[x][0]);
- pref.setAttribute("type", this.mPrefList[x][1]);
- pref.setAttribute("value", eval("this.mPrefs.get" + this.mPrefList[x][1] + "Pref('" + this.mPrefList[x][0] + "')"));
- profile.appendChild(pref);
- }
-
- profiles.appendChild(profile);
-
- if (new_profile)
- this.copyCacheFiles(profile.getAttribute("id"), profile);
-
- this.saveProfiles();
- },
-
- copyCacheFiles: function( p1, p2 )
- {
- //copies p1's cache files to p2 names... and redoes p2's cache prefs
- // p1 = name of profile 1
- // p2 = profile node of one to copy to
-
- var to_copy = new Array();
- var new_file, file, x, pref;
- var current_prof = (this.mProfile == p1);
-
- if (current_prof)
- file = this.mPrefs.getCharPref(PREF_LINKS_CACHE);
- else
- file = this.getProfilePref(p1, PREF_LINKS_CACHE);
-
- if (!to_copy[file])
- to_copy[file] = new Array();
- to_copy[file][PREF_LINKS_CACHE] = true;
-
- if (current_prof)
- file = this.mPrefs.getCharPref(PREF_FORECAST_CACHE);
- else
- file = this.getProfilePref(p1, PREF_FORECAST_CACHE);
-
- if (!to_copy[file])
- to_copy[file] = new Array();
- to_copy[file][PREF_FORECAST_CACHE] = true;
-
- if (current_prof)
- file = this.mPrefs.getCharPref(PREF_CURRENT_CACHE);
- else
- file = this.getProfilePref(p1, PREF_CURRENT_CACHE);
-
- if (!to_copy[file])
- to_copy[file] = new Array();
- to_copy[file][PREF_CURRENT_CACHE] = true;
-
- for (file in to_copy) {
- if (to_copy[file][PREF_LINKS_CACHE])
- new_file = "linkscache-" + p2.getAttribute("id") + ".xml";
- else if (to_copy[file][PREF_FORECAST_CACHE])
- new_file = "forecastcache-" + p2.getAttribute("id") + ".xml";
- else if (to_copy[file][PREF_CURRENT_CACHE])
- new_file = "currentcache-" + p2.getAttribute("id") + ".xml";
-
-
- for (pref in to_copy[file]) {
- if (to_copy[file][pref]) {
- debug("Pref: " + pref + " value: " + new_file);
- if (current_prof)
- this.mPrefs.setCharPref(pref, new_file);
- else
- this.setProfilePref(p2, pref, new_file);
- }
- }
-
- // copy the file
- this.mFileIO.copyFile(file, new_file);
-
- // then change the file in the array so
- to_copy[new_file] = to_copy[file];
- to_copy[file] = null;
- }
-
- // update the prefs
- var prefs = p2.getElementsByTagName("pref");
-
- for (x = 0; x < prefs.length; x++) {
- pref = prefs[x].getAttribute("name");
- if ((pref == PREF_CURRENT_CACHE) || (pref == PREF_FORECAST_CACHE) || (pref == PREF_LINKS_CACHE)) {
- // set the file that this pref is now associated iwth
- for (file in to_copy) {
- if (to_copy[file] && to_copy[file][pref])
- prefs[x].setAttribute("value", file);
- }
- }
- }
- },
-
- getProfilePref: function(profile, pref)
- {
- var profile_node = this.getProfileNode(profile);
- var prefs = profile_node.getElementsByTagName("pref");
- for (var x = 0; x < prefs.length; x++) {
- if (prefs[x].getAttribute("name") == pref) {
- return prefs[x].getAttribute("value");
- }
- }
- return false;
- },
-
- setProfilePref: function(profile, pref, value)
- {
- var prefs = profile.getElementsByTagName("pref");
- var pref_node = null;
-
- for (var x = 0; x < prefs.length; x++) {
- if (prefs[x].getAttribute("name") == pref) {
- prefs[x].setAttribute("value", value);
- return;
- }
- }
- },
-
- getNames: function(aCount)
- {
- var asKeys = new Array();
- var sKey = null;
- var profiles = this.mDoc.getElementsByTagName("profile");
-
- if (profiles.length == 0) {
- this.saveCurrent();
- profiles = this.mDoc.getElementsByTagName("profile");
- }
-
- for (var x = 0; x < profiles.length; x++)
- asKeys.push(profiles[x].getAttribute("id"));
-
- aCount.value = asKeys.length;
- asKeys.sort();
- return asKeys;
- },
-
- getProfileNode: function(name)
- {
- var profiles = this.mDoc.getElementsByTagName("profile");
- var val;
- for (var x = 0; x < profiles.length; x++) {
- if (profiles[x].getAttribute("id") == name) {
- val = profiles[x];
- break;
- }
- }
- return val;
- },
-
- loadProfile: function(name)
- {
- this.saveCurrent();
-
- debug("Loading profile " + name);
-
- this.mObsService.notifyObservers(null, "weatherfox:profile:start", "");
-
- var profile = this.getProfileNode(name);
-
- if (!profile) {
- //profile doesn't exist - error
- this.mObsService.notifyObservers(null, "weatherfox:profile:error", "Profile not found");
- return;
- }
-
- var prefs = profile.getElementsByTagName("pref");
- var pref, type, value;
-
- for (var x = 0; x < prefs.length; x++) {
- pref = prefs[x].getAttribute("name");
- type = prefs[x].getAttribute("type");
- value = prefs[x].getAttribute("value");
- switch (type) {
- case "Bool":
- value = (value == "true") ? true : false;
- break;
- case "Int":
- value = Number(value);
- break;
- case "Char":
- value = "'" + value + "'";
- }
-
- //now set the pref
- eval("this.mPrefs.set" + type + "Pref('" + pref + "', " + value + ")");
- }
-
- this.mProfile = name;
- this.mObsService.notifyObservers(null, "weatherfox:profile:end", name);
- },
-
- renameProfile: function(old_name, new_name)
- {
- new_name = this.stripName(new_name);
- debug("Renaming profile " + old_name + " to " + new_name);
- this.getProfileNode(old_name).setAttribute("id", new_name);
-
- // Change the profile pref if we renamed the current profile.
- if (this.mPrefs.getCharPref("profile") == old_name) {
- this.mProfile = new_name;
- this.mPrefs.setCharPref("profile", new_name);
- }
-
- // copy cache files to new name
- this.copyCacheFiles(new_name, this.getProfileNode(new_name));
-
- // and remove all possibilities
- this.mFileIO.removeFile("currentcache-" + old_name + ".xml");
- this.mFileIO.removeFile("forecastcache-" + old_name + ".xml");
- this.mFileIO.removeFile("linkscache-" + old_name + ".xml");
-
- this.saveProfiles();
- },
-
- stripName: function(name)
- {
- // remove illegal characters
- return name.replace(/[\\\/:*?<>|\'\"]/g, "")
- },
-
- deleteProfile: function(name)
- {
-
- var node = this.getProfileNode(name);
-
- // remove cached files
- this.mFileIO.removeFile("currentcache-" + name + ".xml");
- this.mFileIO.removeFile("forecastcache-" + name + ".xml");
- this.mFileIO.removeFile("linkscache-" + name + ".xml");
-
- //remove the node
- node.parentNode.removeChild(node);
-
- debug("Removed profile " + name);
-
- //save it
- this.saveProfiles();
- },
-
- getProfiles: function()
- {
- debug("Reading profiles from disk");
- var text = this.mFileIO.read(PROFILE_FILE);
-
- if (!text)
- return this.migrateProfiles();
-
- return this.mDOMParser.parseFromString(text, "text/xml");
- },
-
-
- migrateProfiles: function()
- {
- // In this function, we copy the profiles.xml file from the defaults folder to the profile directory
- var file = this.mDirService.get("ProfD", Components.interfaces.nsIFile);
- var target = file.clone();
- target.append("weatherfox");
-
- file.append("extensions");
- file.append("{BA8E053E-2867-4772-B9F0-26A5979AFA09}");
- file.append("defaults");
- file.append(PROFILE_FILE);
- file.copyTo(target, PROFILE_FILE);
-
- target.append(PROFILE_FILE);
- if (!target.isWritable())
- target.permissions = 0644;
-
- return this.getProfiles();
- },
-
- saveProfiles: function()
- {
- debug("Writing profiles to disk...")
-
- //save the doc to file
- this.mFileIO.write(PROFILE_FILE, this.mSerializer.serializeToString(this.mDoc));
- },
-
- /////////////////////////////
- // nsIObserver
- observe: function(aSubject, aTopic, aData)
- {
- switch (aTopic) {
- case "nsPref:changed":
- var new_prof = this.mPrefs.getCharPref("profile");
- if ((aData == "profile") && (new_prof != this.mProfile))
- this.loadProfile(this.mPrefs.getCharPref("profile"));
- break;
- case "xpcom-shutdown":
- //save the current profile
- this.saveCurrent();
-
- this.mObsService.removeObserver(this, "xpcom-shutdown");
- var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
- pbi.removeObserver("", this);
-
- // Release strongly held services.
- this.mPrefs = null;
- this.mObsService = null;
- this.mDOMParser = null;
- this.mSerializer = null;
-
- this.mFileIO.destroy();
- this.mFileIO = null;
- break;
- }
- },
-
- QueryInterface: function (iid)
- {
- if (!iid.equals(Components.interfaces.nsIWeatherfoxProfile) &&
- !iid.equals(Components.interfaces.nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- }
- };
-
- /******************************************************************************
- * XPCOM Functions for construction and registration
- ******************************************************************************/
-
- var gModule =
- {
- mFirstTime: true,
- registerSelf: function (aCompMgr, aFileSpec, aLocation, aType)
- {
- if (this.mFirstTime) {
- this.mFirstTime = false;
- throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
- }
- aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- for (var key in this.mObjects) {
- var obj = this.mObjects[key];
- aCompMgr.registerFactoryLocation(obj.CID, obj.className, obj.contractID,
- aFileSpec, aLocation, aType);
- }
- },
-
- getClassObject: function (aCompMgr, aCID, aIID)
- {
- if (!aIID.equals(Components.interfaces.nsIFactory))
- throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
-
- for (var key in this.mObjects) {
- if (aCID.equals(this.mObjects[key].CID))
- return this.mObjects[key].factory;
- }
-
- throw Components.results.NS_ERROR_NO_INTERFACE;
- },
-
- mObjects: {
- updateService: {
- CID: Components.ID("{6F7A0252-FFF1-49f4-A175-CC7F077AB85C}"),
- contractID: "@mozdev.org/weatherfox/update;1",
- className: "Weatherfox Update Service",
- factory: {
- createInstance: function (aOuter, aIID)
- {
- if (aOuter != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- return (new nsWeatherfoxUpdate()).QueryInterface(aIID);
- }
- }
- },
-
- profileService: {
- CID: Components.ID("{6CF34FFC-830E-4abf-AAA9-6A41CF66F2A0}"),
- contractID: "@mozdev.org/weatherfox/profile;1",
- className: "Weatherfox Profile Service",
- factory: {
- createInstance: function (aOuter, aIID)
- {
- if (aOuter != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- return (new nsWeatherfoxProfile()).QueryInterface(aIID);
- }
- }
- }
- },
-
- canUnload: function(compMgr)
- {
- return true;
- }
- };
-
- function NSGetModule(compMgr, fileSpec) { return gModule; }
-
- /******************************************************************************
- * Utility functions
- ******************************************************************************/
-
- function debug(message) {
- var time = new Date();
- var time_string = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
-
- dump("[WeatherFox " + time_string + "]: " + message + "\n");
- }
-
- function addUnit(base, unit) {
- if ((base == "N/A") || ((!Number(base)) && (base != 0)))
- return base;
- else
- return (base + unit);
- }
-
- function fileIO()
- {
- this.mDirService = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
- this.mFoStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
- this.mFiStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
- this.mSiStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
-
- return this;
- }
-
- fileIO.prototype = {
- destroy: function()
- {
- this.mDirService = null;
- this.mFoStream = null;
- this.mFiStream = null;
- this.mSiStream = null;
- },
-
- write: function(name, contents)
- {
- var file = this.mDirService.get("ProfD", Components.interfaces.nsIFile);
-
- //put in weatherfox subdirectory
- file.append("weatherfox");
- if (!file.exists())
- file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
-
- file.append(name);
-
- var flags = 0x02 | 0x08 | 0x20;
- this.mFoStream.init(file, flags, 0664, 0);
- this.mFoStream.write(contents, contents.length);
- this.mFoStream.close();
-
- return true;
- },
-
- read: function(name)
- {
- var file = this.mDirService.get("ProfD", Components.interfaces.nsIFile)
-
- //get from weatherfox subdirectory
- file.append("weatherfox");
- if (!file.exists())
- return false;
-
- file.append(name);
-
- var contents = new String();
-
- try {
- this.mFiStream.init(file, 1, 0, false);
- this.mSiStream.init(this.mFiStream);
- contents += this.mSiStream.read(-1);
-
- this.mSiStream.close();
- this.mFiStream.close();
- return contents;
- }
- catch(e) {
- return false;
- }
- },
-
- copyFile: function(file, newfile)
- {
- var old_file = this.mDirService.get("ProfD", Components.interfaces.nsIFile);
- old_file.append("weatherfox");
-
- var target = old_file.clone();
-
- old_file.append(file);
-
- // remove the file if it already exists
- var file_check = target.clone();
- file_check.append(newfile);
- if (file_check.exists())
- file_check.remove(false);
-
- // copy the old one to this location
- old_file.copyTo(target, newfile);
-
- },
-
- removeFile: function(file)
- {
- var target = this.mDirService.get("ProfD", Components.interfaces.nsIFile);
- target.append("weatherfox");
- target.append(file);
- debug("Deleting " + file);
- try {
- target.remove(false);
- } catch (e) { }
-
- }
-
- };