home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 September
/
PCWorld_2008-09_cd.bin
/
komunikace
/
kmeleon
/
K-Meleon1.1.3en-US.exe
/
chrome
/
newsfox.jar
/
content
/
newsfox
/
globalfuncs.js
< prev
next >
Wrap
Text File
|
2007-10-25
|
6KB
|
186 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 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 ***** */
const VERSION = "0.8.1";
const NEWSFOX = "NewsFox";
const NEWSFOX_RSS = "http://newsfox.mozdev.org/rss/rss.xml?startup";
const NEWSFOX_DATE = "April 15, 2003 8:01 PM";
const LONG_DATE_STYLE = 2;
const ERROR_OK = "0";
const ERROR_INVALID_FEED_URL = "1";
const ERROR_UNKNOWN_FEED_FORMAT = "2";
const FEED_VALIDATOR = "http://validator.w3.org/feed/check.cgi?url=";
const NO_LINK = "";
const ICON_OK = "chrome://newsfox/skin/images/feed.png";
var gKMeleon = false;
var gFF3 = false;
var gNewsfoxDirURL = null;
var gMsgDone = false;
/**
* Get the newsfox directory
*/
function getProfileDir()
{
var nsIPH = Components.classes["@mozilla.org/network/protocol;1?name=file"].createInstance(Components.interfaces.nsIFileProtocolHandler);
const NF_SB = document.getElementById("newsfox-string-bundle");
var profURL = getPref("global.directory", "str", "");
if (gNewsfoxDirURL != null) // use it, but warn if preference changed
{
if (gNewsfoxDirURL != profURL && !gMsgDone)
{
alert(NF_SB.getString('inuse'));
gMsgDone = true;
}
return nsIPH.getFileFromURLSpec(gNewsfoxDirURL);
}
if (profURL != "") // use it if exists, otherwise choose new
{
var file = nsIPH.getFileFromURLSpec(profURL);
if (file.exists())
{
gNewsfoxDirURL = profURL;
return nsIPH.getFileFromURLSpec(gNewsfoxDirURL);
}
var msg = NF_SB.getString('confirm.newNewsfoxDir');
if (window.confirm(msg)) // pick new directory, else use default
{
var picker = nfDirPicked(file);
if (picker)
{
gNewsfoxDirURL = nsIPH.getURLSpecFromFile(picker.file);
setPref("global.directory", "str", gNewsfoxDirURL);
return picker.file;
}
}
}
// default to standard location
var file = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("ProfD", Components.interfaces.nsIFile);
file.append("newsfox");
if (!file.exists()) file.create(0x01, 0750);
gNewsfoxDirURL = nsIPH.getURLSpecFromFile(file);
setPref("global.directory", "str", gNewsfoxDirURL);
return file;
}
function nfDirPicked(startFile)
{
var picker = Components.classes["@mozilla.org/filepicker;1"].
createInstance(Components.interfaces.nsIFilePicker);
var file = startFile;
try
{
while (!file.exists() || file.isFile()) file = file.parent;
picker.displayDirectory = file;
}
catch(e){}
picker.init(window, "Choose Newsfox folder", picker.modeGetFolder);
if(picker.show() == picker.returnOK) return picker;
else return null;
}
function getPref(name, type, dfault, notNewsfox)
{
var base = "newsfox.";
if (notNewsfox) base = "";
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch(base);
if (prefs.getPrefType(name) == prefs.PREF_INVALID) return dfault;
switch (type)
{
case "str":
return prefs.getCharPref(name);
break;
case "int":
return prefs.getIntPref(name);
break;
case "bool":
return prefs.getBoolPref(name);
break;
}
return null;
}
function setPref(name, type, value, notNewsfox)
{
var base = "newsfox.";
if (notNewsfox) base = "";
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch(base);
switch (type)
{
case "str":
prefs.setCharPref(name,value);
break;
case "int":
prefs.setIntPref(name,value);
break;
case "bool":
prefs.setBoolPref(name,value);
break;
}
}
String.prototype.trim = function()
{
return this.replace(/^\s+|\s+$/g, '');
}
function setTitle()
{
newTitle(gFdGroup[0].getUnread());
}
function newTitle(undone)
{
var nF = NEWSFOX;
if (undone > 0) nF += " (" + undone + ")";
// prevent flicker, only redo if needed
if (document.title != nF) document.title = nF;
}