⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newsblog.js

📁 现在很火的邮件客户端软件thunderbird的源码
💻 JS
📖 第 1 页 / 共 2 页
字号:
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * ***** 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 the News&Blog Feed Downloader * * The Initial Developer of the Original Code is * The Mozilla Foundation. * Portions created by the Initial Developer are Copyright (C) 2004 * the Initial Developer. All Rights Reserved. * * Contributor(s): *  Myk Melez <myk@mozilla.org) (Original Author) *  David Bienvenu <bienvenu@nventure.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 ***** */var gExternalScriptsLoaded = false;var nsNewsBlogFeedDownloader ={  downloadFeed: function(aUrl, aFolder, aQuickMode, aTitle, aUrlListener, aMsgWindow)  {    if (!gExternalScriptsLoaded)      loadScripts();    // we don't yet support the ability to check for new articles while we are in the middle of     // subscribing to a feed. For now, abort the check for new feeds.     if (progressNotifier.mSubscribeMode)    {      debug('Aborting RSS New Mail Check. Feed subscription in progress\n');      return;    }    // if folder seems to have lost its feeds, look in DS for feeds.    if (!aUrl.length)    {      var ds = getSubscriptionsDS(aFolder.server);      var enumerator = ds.GetSources(FZ_DESTFOLDER, aFolder, true);      var concatenatedUris = "";      while (enumerator.hasMoreElements())      {        var containerArc = enumerator.getNext();        var uri = containerArc.QueryInterface(Components.interfaces.nsIRDFResource).Value;        if (concatenatedUris.length > 0)          concatenatedUris += "|";        concatenatedUris += uri;      }      if (concatenatedUris.length > 0)      {        aUrl = concatenatedUris;        try        {          var msgdb = aFolder.getMsgDatabase(null);          var folderInfo = msgdb.dBFolderInfo;          folderInfo.setCharPtrProperty("feedUrl", concatenatedUris);        }        catch (ex) {dump(ex);}      }    }    // aUrl may be a delimited list of feeds for a particular folder. We need to kick off a download    // for each feed.    var feedUrlArray = aUrl.split("|");    // we might just pull all these args out of the aFolder DB, instead of passing them in...    var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]        .getService(Components.interfaces.nsIRDFService);    progressNotifier.init(aMsgWindow, false);    for (url in feedUrlArray)    {      if (feedUrlArray[url])      {                id = rdf.GetResource(feedUrlArray[url]);        feed = new Feed(id, aFolder.server);        feed.folder = aFolder;        gNumPendingFeedDownloads++; // bump our pending feed download count        feed.download(true, progressNotifier);      }    }  },  subscribeToFeed: function(aUrl, aFolder, aMsgWindow)  {    if (!gExternalScriptsLoaded)      loadScripts();    // we don't support the ability to subscribe to several feeds at once yet...    // for now, abort the subscription if we are already in the middle of subscribing to a feed    // via drag and drop.    if (gNumPendingFeedDownloads)    {      debug('Aborting RSS subscription. Feed downloads already in progress\n');      return;    }    // if aFolder is null, then use the root folder for the first RSS account    if (!aFolder)    {      var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"]                           .getService(Components.interfaces.nsIMsgAccountManager);      var allServers = accountManager.allServers;      for (var i=0; i< allServers.Count() && !aFolder; i++)      {        var currentServer = allServers.GetElementAt(i).QueryInterface(Components.interfaces.nsIMsgIncomingServer);        if (currentServer && currentServer.type == 'rss')          aFolder = currentServer.rootFolder;            }    }    // What do we do if the user hasn't created an RSS account yet?     // for now, fall out, would be nice if we could force RSS account creation    if (!aFolder)      return;    // if aUrl is a feed url, then it is of the form: feed:http://somesite/feed.xml or     // feed://http://somesite/feed.xml    // Strip off the feed: part so we can subscribe to the contained URL.    if (/^feed:/i.test(aUrl))    {      aUrl = aUrl.replace(/^feed:/i, '');      // Strip off the optional forward slashes if we were given feed://      aUrl = aUrl.replace(/^\x2f\x2f/, '');    }    // make sure we aren't already subscribed to this feed before we attempt to subscribe to it.    if (feedAlreadyExists(aUrl, aFolder.server))    {      aMsgWindow.statusFeedback.showStatusString(GetNewsBlogStringBundle().GetStringFromName('subscribe-feedAlreadySubscribed'));           return;    }    var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]              .getService(Components.interfaces.nsIRDFService);        var itemResource = rdf.GetResource(aUrl);    var feed = new Feed(itemResource, aFolder.server);    feed.quickMode = feed.server.getBoolAttribute('quickMode');    if (!aFolder.isServer) // if the root server, create a new folder for the feed      feed.folder = aFolder; // user must want us to add this subscription url to an existing RSS folder.    progressNotifier.init(aMsgWindow, true);    gNumPendingFeedDownloads++;    feed.download(true, progressNotifier);  },  updateSubscriptionsDS: function(aFolder, aUnsubscribe)  {    if (!gExternalScriptsLoaded)      loadScripts();    // an rss folder was just renamed...we need to update our feed data source    var msgdb = aFolder.QueryInterface(Components.interfaces.nsIMsgFolder).getMsgDatabase(null);    var folderInfo = msgdb.dBFolderInfo;    var feedurls = folderInfo.getCharPtrProperty("feedUrl");    var feedUrlArray = feedurls.split("|");    var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);    var ds = getSubscriptionsDS(aFolder.server);    for (url in feedUrlArray)    {      if (feedUrlArray[url])      {                id = rdf.GetResource(feedUrlArray[url]);        // get the node for the current folder URI        var node = ds.GetTarget(id, FZ_DESTFOLDER, true);        // we need to check and see if the folder is a child of the trash...if it is, then we can        // treat this as an unsubscribe action        if (aUnsubscribe)        {          var feeds = getSubscriptionsList(aFolder.server);          var index = feeds.IndexOf(id);          if (index != -1)            feeds.RemoveElementAt(index, false);          removeAssertions(ds, id);        }          else          ds.Change(id, FZ_DESTFOLDER, node, rdf.GetResource(aFolder.URI));      }    } // for each feed url in the folder property    ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush(); // flush any changes  },  QueryInterface: function(aIID)  {    if (aIID.equals(Components.interfaces.nsINewsBlogFeedDownloader) ||        aIID.equals(Components.interfaces.nsISupports))      return this;    Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;    return null;  }}var nsNewsBlogAcctMgrExtension = {   name: "newsblog",  chromePackageName: "messenger-newsblog",  showPanel: function (server)  {    return server.type == "rss";  },  QueryInterface: function(aIID)  {    if (aIID.equals(Components.interfaces.nsIMsgAccountManagerExtension) ||        aIID.equals(Components.interfaces.nsISupports))      return this;    Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;    return null;  }  }var nsFeedCommandLineHandler = {  /* nsISupports */  QueryInterface : function(aIID)   {    if (!aIID.equals(Components.interfaces.nsISupports) &&        !aIID.equals(Components.interfaces.nsICommandLineHandler))      throw Components.errors.NS_ERROR_NO_INTERFACE;    return this;  },  /* nsICommandLineHandler */  handle : function(cmdLine)   {    // we only care about "-mail someurl" where someurl is a feed: url    // we also don't want to remove the parameter in case we don't end up handling it...    var mailPos = cmdLine.findFlag("mail", false);    if (mailPos != -1 && cmdLine.length >= mailPos )    {       var uriStr = cmdLine.getArgument(mailPos + 1);      if (/^feed:/i.test(uriStr))      {        var mailWindow = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService()                         .QueryInterface(Components.interfaces.nsIWindowMediator).getMostRecentWindow("mail:3pane");                         // if we don't have a 3 pane window visible already, then we can optimize and do nothing here,        // that will let the default command line handler create a 3pane window for us using the feed        // URL as an argument to that window when it gets constructed...so we only care about the        // case where we want to re-use an existing 3 pane to subscribe to the feed url        if (mailWindow)        {          cmdLine.handleFlagWithParam("mail", false); // eat up the arguments we are now handling          cmdLine.preventDefault = true; // prevent the default cmd line handler from doing anything          var feedHandler = Components.classes["@mozilla.org/newsblog-feed-downloader;1"].getService(Components.interfaces.nsINewsBlogFeedDownloader);          if (feedHandler)            feedHandler.subscribeToFeed(uriStr, null, mailWindow.msgWindow);        }              }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -