home *** CD-ROM | disk | FTP | other *** search
- /* ***** 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 NewsFox.
- *
- * The Initial Developer of the Original Code is
- * Andy Frank <andy@andyfrank.com>.
- * Portions created by the Initial Developer are Copyright (C) 2005-2007
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Andrey Gromyko <andrey@gromyko.name>
- * Ron Pruitt <wa84it@gmail.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 LGPL or the GPL. 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 ***** */
-
- ////////////////////////////////////////////////////////////////
- // Global
- ////////////////////////////////////////////////////////////////
-
- var gOptions = new AppOptions();
-
- var noObserve = false;
-
- var nFprefObserver =
- {
- observe: function(subject, topic, data)
- {
- if (noObserve) return;
- gOptions.load();
- if (gOptions.addUrl != "") addFeedUrl();
- }
- }
-
- ////////////////////////////////////////////////////////////////
- // Model
- ////////////////////////////////////////////////////////////////
-
- function AppOptions()
- {
- // Control wether we display an article as simple text or
- // if we dislpay the actual webpage link. Can be overrided
- // by individual feed.
- //
- // 1 Text
- // 2 Web page
- // 3 Newspaper
- this.globalStyle = 1;
-
- // Control if feeds should be automatically checked on startup
- this.checkOnStartup = false;
-
- // Auto-refresh flag
- this.autoRefresh = false;
-
- // Auto-refresh interval, minutes
- this.autoRefreshInterval = 30;
-
- this.notifyUponNew = false;
-
- // Confirm deletions?
- this.confirmDelete = true;
-
- ////////////////////////////////////////////////////////////////
- // Methods
- ////////////////////////////////////////////////////////////////
-
- this.startup = function()
- {
- // var nsIPref = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPref);
- // var branch = nsIPref.getBranch("newsfox.global.TMP.");
- // branch.deleteBranch("");
- this.renamePrefs();
- // need to set the directory preference, so the observer doesn't catch
- // the setting later and process the addurl before models loaded
- var file = getProfileDir();
- this.load();
- this.save(true);
- this.addObserver();
- }
-
- this.addObserver = function()
- {
- var nsIPrefBranch2 = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch2);
- nsIPrefBranch2.addObserver("newsfox.", nFprefObserver, false);
- }
-
- this.rmObserver = function()
- {
- var nsIPrefBranch2 = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch2);
- nsIPrefBranch2.removeObserver("newsfox.", nFprefObserver);
- }
-
- this.load = function()
- {
- this.globalStyle = getPref("global.style", "int", 1);
- this.checkOnStartup = getPref("global.checkOnStartup", "bool", false);
- this.autoRefresh = getPref("global.autoRefresh", "bool", false);
- this.autoRefreshInterval = getPref("global.autoRefreshInterval", "int", 30);
- this.notifyUponNew = getPref("global.notifyUponNew", "bool", false);
- this.confirmDelete = getPref("global.confirmDelete", "bool", true);
- this.dateStyle = getPref("global.dateStyle", "int", 2);
- this.addUrl = getPref("internal.addUrl", "str", NEWSFOX_RSS);
- this.favicons = getPref("advanced.favicons", "bool", getPref("browser.chrome.favicons","bool",true,true));
- this.guessHomepage = getPref("advanced.guessHomepage", "bool", true);
- this.refreshTimeout = 1000 * getPref("advanced.refreshTimeoutInSeconds", "int", 60);
- this.horiz = getPref("advanced.horizontalPanes", "bool", false);
- this.newtab = getPref("advanced.buttonOpensNewTab", "bool", false);
- this.copyToClip = getPref("advanced.copyArtBodyToClipboard","bool", false);
- this.selectAddedFeed = getPref("advanced.selectAddedFeed", "bool", true);
- this.changedUnread = getPref("advanced.markChangedArtAsUnread", "bool", false);
- this.dateNoneStrict = getPref("date.noneStrict", "bool", true);
- this.dateInvalidStrict = getPref("date.invalidStrict", "bool", true);
- this.dateFutureStrict = getPref("date.futureStrict", "bool", false);
- }
-
- this.save = function(savenonUI)
- {
- noObserve = true; // can't have observer while saving many options
- setPref("global.style", "int", this.globalStyle);
- setPref("global.checkOnStartup", "bool", this.checkOnStartup);
- setPref("global.autoRefresh", "bool", this.autoRefresh);
- setPref("global.autoRefreshInterval", "int", this.autoRefreshInterval);
- setPref("global.notifyUponNew", "bool", this.notifyUponNew);
- setPref("global.confirmDelete", "bool", this.confirmDelete);
- setPref("global.dateStyle", "int", this.dateStyle);
- setPref("internal.addUrl", "str", this.addUrl);
- if (savenonUI)
- {
- setPref("advanced.favicons", "bool", this.favicons);
- setPref("advanced.guessHomepage", "bool", this.guessHomepage);
- setPref("advanced.refreshTimeoutInSeconds", "int", this.refreshTimeout/1000);
- setPref("advanced.horizontalPanes", "bool", this.horiz);
- setPref("advanced.buttonOpensNewTab", "bool", this.newtab);
- setPref("advanced.copyArtBodyToClipboard", "bool", this.copyToClip);
- setPref("advanced.selectAddedFeed", "bool", this.selectAddedFeed);
- setPref("advanced.markChangedArtAsUnread", "bool", this.changedUnread);
- setPref("date.noneStrict", "bool", this.dateNoneStrict);
- setPref("date.invalidStrict", "bool", this.dateInvalidStrict);
- setPref("date.futureStrict", "bool", this.dateFutureStrict);
- }
- noObserve = false;
- }
-
- this.renamePrefs = function()
- {
- var done = getPref("internal.rename", "bool", false);
- if (!done)
- {
- var prefs = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefService)
- .getBranch("newsfox.");
- setPref("internal.addUrl", "str",
- getPref("global.addUrl", "str", NEWSFOX_RSS));
- if (getPref("global.addUrl","str",null))
- prefs.clearUserPref("global.addUrl");
- setPref("advanced.favicons", "bool",
- getPref("global.favicons", "bool",
- getPref("browser.chrome.favicons","bool",true,true)));
- if (getPref("global.favicons","bool",null))
- prefs.clearUserPref("global.favicons");
- setPref("advanced.guessHomepage", "bool",
- getPref("global.guessHomepage", "bool", true));
- if (getPref("global.guessHomepage","bool",null))
- prefs.clearUserPref("global.guessHomepage");
- setPref("advanced.refreshTimeoutInSeconds", "int",
- getPref("global.refreshTimeoutInSeconds", "int", 60));
- if (getPref("global.refreshTimeoutInSeconds","int",null))
- prefs.clearUserPref("global.refreshTimeoutInSeconds");
- setPref("advanced.horizontalPanes", "bool",
- getPref("global.horizontalPanes", "bool", false));
- if (getPref("global.horizontalPanes","bool",null))
- prefs.clearUserPref("global.horizontalPanes");
- if (!gKMeleon)
- {
- setPref("internal.doneButton", "bool",
- getPref("global.doneButton", "bool", false));
- if (getPref("global.doneButton","bool",null))
- prefs.clearUserPref("global.doneButton");
- setPref("internal.doneAutoSubscribe", "bool",
- getPref("global.doneAutoSubscribe", "bool", false));
- if (getPref("global.doneAutoSubscribe","bool",null))
- prefs.clearUserPref("global.doneAutoSubscribe");
- }
- setPref("internal.rename", "bool", true);
- }
- }
- }
-