1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef __nsMsgAppCore_h 7 #define __nsMsgAppCore_h 8 9 #include "nscore.h" 10 #include "nsIMessenger.h" 11 #include "nsCOMPtr.h" 12 #include "nsITransactionManager.h" 13 #include "nsIFile.h" 14 #include "nsIDocShell.h" 15 #include "nsString.h" 16 #include "nsIStringBundle.h" 17 #include "nsIFile.h" 18 #include "nsIFilePicker.h" 19 #include "nsWeakReference.h" 20 #include "mozIDOMWindow.h" 21 #include "nsTArray.h" 22 #include "nsIFolderListener.h" 23 #include "nsIMsgStatusFeedback.h" 24 25 class nsMessenger : public nsIMessenger, 26 public nsSupportsWeakReference, 27 public nsIFolderListener { 28 using PathString = mozilla::PathString; 29 30 public: 31 nsMessenger(); 32 33 NS_DECL_ISUPPORTS 34 NS_DECL_NSIMESSENGER 35 NS_DECL_NSIFOLDERLISTENER 36 37 nsresult Alert(const char* stringName); 38 39 nsresult SaveAttachment(nsIFile* file, const nsACString& unescapedUrl, 40 const nsACString& messageUri, 41 const nsACString& contentType, void* closure, 42 nsIUrlListener* aListener); 43 nsresult PromptIfFileExists(nsIFile* file); 44 nsresult DetachAttachments(const nsTArray<nsCString>& aContentTypeArray, 45 const nsTArray<nsCString>& aUrlArray, 46 const nsTArray<nsCString>& aDisplayNameArray, 47 const nsTArray<nsCString>& aMessageUriArray, 48 nsTArray<nsCString>* saveFileUris, 49 bool withoutWarning = false); 50 nsresult SaveAllAttachments(const nsTArray<nsCString>& contentTypeArray, 51 const nsTArray<nsCString>& urlArray, 52 const nsTArray<nsCString>& displayNameArray, 53 const nsTArray<nsCString>& messageUriArray, 54 bool detaching); 55 nsresult SaveOneAttachment(const nsACString& aContentType, 56 const nsACString& aURL, 57 const nsACString& aDisplayName, 58 const nsACString& aMessageUri, bool detaching); 59 60 protected: 61 virtual ~nsMessenger(); 62 63 void GetString(const nsString& aStringName, nsString& stringValue); 64 nsresult InitStringBundle(); 65 nsresult PromptIfDeleteAttachments( 66 bool saveFirst, const nsTArray<nsCString>& displayNameArray); 67 68 private: 69 nsresult GetLastSaveDirectory(nsIFile** aLastSaveAsDir); 70 // if aLocalFile is a dir, we use it. otherwise, we use the parent of 71 // aLocalFile. 72 nsresult SetLastSaveDirectory(nsIFile* aLocalFile); 73 74 nsresult AdjustFileIfNameTooLong(nsIFile* aFile); 75 76 nsresult GetSaveAsFile(const nsAString& aMsgFilename, 77 int32_t* aSaveAsFileType, nsIFile** aSaveAsFile); 78 79 nsresult GetSaveToDir(nsIFile** aSaveToDir); 80 nsresult ShowPicker(nsIFilePicker* aPicker, int16_t* aResult); 81 82 // The URL to load in CompleteOpenURL. An empty string to aborts loading. 83 nsCString mURLToLoad; 84 nsresult CompleteOpenURL(); 85 86 class nsFilePickerShownCallback : public nsIFilePickerShownCallback { ~nsFilePickerShownCallback()87 virtual ~nsFilePickerShownCallback() {} 88 89 public: 90 nsFilePickerShownCallback(); 91 NS_DECL_ISUPPORTS 92 93 NS_IMETHOD Done(int16_t aResult) override; 94 95 public: 96 bool mPickerDone; 97 int16_t mResult; 98 }; 99 100 nsString mId; 101 nsCOMPtr<nsITransactionManager> mTxnMgr; 102 103 /* rhp - need this to drive message display */ 104 nsCOMPtr<mozIDOMWindowProxy> mWindow; 105 nsCOMPtr<nsIMsgWindow> mMsgWindow; 106 nsCOMPtr<nsIDocShell> mDocShell; 107 108 // String bundles... 109 nsCOMPtr<nsIStringBundle> mStringBundle; 110 111 nsCString mCurrentDisplayCharset; 112 113 nsCOMPtr<nsISupports> mSearchContext; 114 // this used when the user attempts to force a charset reload of a message... 115 // we need to get the last displayed uri so we can re-display it. 116 nsCString mLastDisplayURI; 117 nsCString mNavigatingToUri; 118 nsTArray<nsCString> mLoadedMsgHistory; 119 int32_t mCurHistoryPos; 120 }; 121 122 #define NS_MESSENGER_CID \ 123 { /* f436a174-e2c0-4955-9afe-e3feb68aee56 */ \ 124 0xf436a174, 0xe2c0, 0x4955, { \ 125 0x9a, 0xfe, 0xe3, 0xfe, 0xb6, 0x8a, 0xee, 0x56 \ 126 } \ 127 } 128 129 #endif 130