Back to index

lightning-sunbird  0.9+nobinonly
Core.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; 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 Roaming code.
00016  *
00017  * The Initial Developer of the Original Code is 
00018  *   Ben Bucksch <http://www.bucksch.org> of
00019  *   Beonex <http://www.beonex.com>
00020  * Portions created by the Initial Developer are Copyright (C) 2002-2004
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 /* Central object for session roaming. Controls program sequence and provides
00040    common functions. */
00041 
00042 #ifndef _Core_H_
00043 #define _Core_H_
00044 
00045 
00046 #include "nsISessionRoaming.h"
00047 #include "nsCOMPtr.h"
00048 #include "nsISupports.h"
00049 #include "nsIRegistry.h"
00050 #include "nsIURI.h"
00051 #include "nsString.h"
00052 #include "nsVoidArray.h"
00053 
00054 #define NS_SESSIONROAMING_CID                          \
00055   { /* {ab62465c-494c-446e-b671-930bb98a7bc4} */       \
00056     0xab62465c,                                        \
00057     0x494c,                                            \
00058     0x446e,                                            \
00059     { 0xb6, 0x71, 0x93, 0x0b, 0xb9, 0x8a, 0x7b, 0xc4 } \
00060   }
00061 
00062 #define NS_SESSIONROAMING_CONTRACTID      \
00063           "@mozilla.org/profile/session-roaming;1"
00064 
00065 class Protocol;
00066 
00067 class Core: public nsISessionRoaming
00068 {
00069 public:
00070     NS_DECL_ISUPPORTS
00071     NS_DECL_NSISESSIONROAMING
00072 
00073     Core();
00074 
00075     // Is a roaming profile (if not, then nothing to do)
00076     inline PRBool IsRoaming() { return mIsRoaming; };
00077 
00078     // Which profile files should be stored on the server
00079     // @return pointer to the internal nsDeque object. Do not free it.
00080     inline const nsCStringArray* GetFilesToRoam()  { return &mFiles; };
00081 
00082     // Local profile directory
00083     nsresult GetProfileDir(nsIFile** result);
00084 
00085     // Method used to store remote files
00086     // 0=unknown, 1=HTTP, 2=Copy
00087     inline PRInt32 GetMethod() { return mMethod; };
00088 
00089     /* If we'd normally overwrite a newer file. Ask user, which file to keep.
00090      * @param download  direction: true = download, false = upload
00091      * @param files     conflicting files
00092      * @param result    Files for which conflicts should be ignored.
00093      *                  This is a subset of the files param and those should
00094      *                  be uploaded / downloaded. The rest of files in the
00095      *                  files param should *not* be uploaded / downloaded.
00096      *                  Wants an array passed in, items will be added to that.
00097      * @return NS_ERROR_ABORT, if the user clicked Cancel.
00098      */
00099     nsresult ConflictResolveUI(PRBool download, const nsCStringArray& files,
00100                                nsCStringArray* result);
00101 
00102     nsresult GetRegistry(nsCOMPtr<nsIRegistry>& result);
00103     nsresult GetRegistryTree(nsRegistryKey& result);
00104 
00105     /* At the time we attempt to upload, the network lib has already been
00106        shut down. So, temporarily restore it and then close it down again.
00107        Of course, this is a hack, until we (me, ccarlen, darin) have found a
00108        better solution and it has been tested thoroughly for regressions.
00109        This problem currently doesn't appear during download (at startup).
00110 
00111        @param restore  if true, then restore, otherwise close
00112        @param topic  the notification topic.
00113                      either "profile-change-net-restore"
00114                      or "profile-change-net-teardown"
00115     */
00116     inline nsresult RestoreNet() { return RestoreCloseNet(PR_TRUE); };
00117     inline nsresult CloseNet() { return RestoreCloseNet(PR_FALSE); };
00118 
00119 protected:
00120     // Data (see getters above)
00121     PRBool mIsRoaming;
00122     PRInt32 mMethod;
00123     nsCStringArray mFiles;
00124 
00125     // Cache
00126     nsCOMPtr<nsIRegistry> mRegistry;
00127 
00128     // Reads liprefs: is roaming profile?, files, server info etc.
00129     nsresult ReadRoamingPrefs();
00130 
00131     // Factory method for a new method handler that can handle this method
00132     // We'll use a new object for down-/upload respectively
00133     // @return new object. you have to free it with delete.
00134     Protocol* CreateMethodHandler();
00135 
00136     nsresult RestoreCloseNet(PRBool restore);
00137 };
00138 
00139 #endif