Back to index

lightning-sunbird  0.9+nobinonly
nsNewsDownloader.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _nsNewsDownloader_H_
00039 #define _nsNewsDownloader_H_
00040 
00041 
00042 #include "nsIMsgDatabase.h"
00043 #include "nsIUrlListener.h"
00044 #include "nsIMsgFolder.h"
00045 #include "nsIMsgHdr.h"
00046 #include "nsIMsgWindow.h"
00047 #include "nsIMsgSearchNotify.h"
00048 #include "nsIMsgSearchSession.h"
00049 
00050 // base class for downloading articles in a single newsgroup. Keys to download are passed in
00051 // to DownloadArticles method.
00052 class nsNewsDownloader : public nsIUrlListener, public nsIMsgSearchNotify
00053 {
00054 public:
00055   nsNewsDownloader(nsIMsgWindow *window, nsIMsgDatabase *db, nsIUrlListener *listener);
00056   virtual ~nsNewsDownloader();
00057 
00058   NS_DECL_ISUPPORTS
00059   NS_DECL_NSIURLLISTENER
00060   NS_DECL_NSIMSGSEARCHNOTIFY
00061 
00062   virtual nsresult DownloadArticles(nsIMsgWindow *window, nsIMsgFolder *folder, nsMsgKeyArray *pKeyArray);
00063   
00064   PRBool ShouldAbort() const { return m_abort; }
00065        
00066 protected:
00067   virtual PRInt32 Write(const char * /*block*/, PRInt32 length) {return length;}
00068   virtual void Abort();
00069   virtual void Complete();
00070   virtual PRBool GetNextHdrToRetrieve();
00071   virtual nsresult DownloadNext(PRBool firstTimeP);
00072   virtual PRInt32 FinishDownload() {return 0;}
00073   virtual PRInt32    StartDownload() {return 0;}
00074   virtual nsresult ShowProgress(const PRUnichar *progressString, PRInt32 percent);
00075 
00076   nsMsgKeyArray                    m_keysToDownload;
00077   nsCOMPtr <nsIMsgFolder>   m_folder;
00078   nsCOMPtr <nsIMsgDatabase> m_newsDB;
00079   nsCOMPtr <nsIUrlListener> m_listener;
00080   PRPackedBool m_downloadFromKeys;
00081   PRPackedBool m_existedP;
00082   PRPackedBool m_wroteAnyP;
00083   PRPackedBool m_summaryValidP;
00084   PRPackedBool m_abort;
00085   PRInt32     m_numwrote;
00086   nsMsgKey    m_keyToDownload;
00087   nsCOMPtr <nsIMsgWindow> m_window;
00088   nsCOMPtr <nsIMsgStatusFeedback> m_statusFeedback;
00089   nsCOMPtr <nsIMsgSearchSession> m_searchSession;
00090   PRInt32 m_lastPercent;
00091   PRInt64 m_lastProgressTime;                           
00092   nsresult  m_status;
00093 };
00094 
00095 
00096 // class for downloading articles in a single newsgroup to the offline store.
00097 class DownloadNewsArticlesToOfflineStore : public nsNewsDownloader
00098 {
00099 public:
00100   DownloadNewsArticlesToOfflineStore(nsIMsgWindow *window, nsIMsgDatabase *db, nsIUrlListener *listener);
00101   virtual ~DownloadNewsArticlesToOfflineStore();
00102 
00103   NS_IMETHOD OnStartRunningUrl(nsIURI* url);
00104   NS_IMETHOD OnStopRunningUrl(nsIURI* url, nsresult exitCode);
00105 protected:
00106   virtual PRInt32    StartDownload();
00107   virtual PRInt32 FinishDownload();
00108   virtual PRBool GetNextHdrToRetrieve();
00109 
00110   nsCOMPtr <nsISimpleEnumerator>   m_headerEnumerator;
00111   nsCOMPtr <nsIMsgDBHdr>    m_newsHeader;
00112 };
00113 
00114 // class for downloading all the articles that match the passed in search criteria
00115 // for a single newsgroup.
00116 class DownloadMatchingNewsArticlesToNewsDB : public DownloadNewsArticlesToOfflineStore
00117 {
00118 public:
00119   DownloadMatchingNewsArticlesToNewsDB(nsIMsgWindow *window, nsIMsgFolder *folder, nsIMsgDatabase *newsDB,  nsIUrlListener *listener);
00120   virtual ~DownloadMatchingNewsArticlesToNewsDB();
00121   nsresult RunSearch(nsIMsgFolder *folder, nsIMsgDatabase *newsDB, nsIMsgSearchSession *searchSession);
00122 protected:
00123 };
00124 
00125 // this class iterates all the news servers for each group on the server that's configured for
00126 // offline use, downloads the messages that meet the download criteria for that newsgroup/server
00127 class nsMsgDownloadAllNewsgroups : public nsIUrlListener
00128 {
00129 public:
00130   nsMsgDownloadAllNewsgroups(nsIMsgWindow *window, nsIUrlListener *listener);
00131   virtual ~nsMsgDownloadAllNewsgroups();
00132 
00133   NS_DECL_ISUPPORTS
00134   NS_DECL_NSIURLLISTENER
00135 
00136   nsresult ProcessNextGroup();
00137 
00138 protected:
00139   nsresult AdvanceToNextServer(PRBool *done);
00140   nsresult AdvanceToNextGroup(PRBool *done);
00141   nsresult DownloadMsgsForCurrentGroup();
00142 
00143   DownloadMatchingNewsArticlesToNewsDB *m_downloaderForGroup;
00144 
00145   nsCOMPtr <nsIMsgFolder> m_currentFolder;
00146   nsCOMPtr <nsIMsgWindow> m_window;
00147   nsCOMPtr <nsISupportsArray> m_allServers;
00148   nsCOMPtr <nsISupportsArray> m_allFolders;
00149   nsCOMPtr <nsIMsgIncomingServer> m_currentServer;
00150   nsCOMPtr <nsIEnumerator> m_serverEnumerator;
00151   nsCOMPtr <nsIUrlListener> m_listener;
00152   nsCOMPtr <nsISupportsArray> m_termList;
00153 
00154   PRBool m_downloadedHdrsForCurGroup;
00155 };
00156 
00157 #endif