Bug 1341211 - Replace nsIFilePicker::Show() with nsIFilePicker::Open() in the address book manager. rs=bustage-fix

This commit is contained in:
Jorg K 2017-08-13 00:02:45 +02:00
Родитель c7107555e3
Коммит d5c3e917b5
2 изменённых файлов: 50 добавлений и 12 удалений

Просмотреть файл

@ -17,7 +17,6 @@
#include "prmem.h"
#include "nsIServiceManager.h"
#include "mozIDOMWindow.h"
#include "nsIFilePicker.h"
#include "plbase64.h"
#include "nsIWindowWatcher.h"
#include "nsDirectoryServiceUtils.h"
@ -524,6 +523,16 @@ enum ADDRESSBOOK_EXPORT_FILE_TYPE
LDIF_EXPORT_TYPE = 5,
};
NS_IMPL_ISUPPORTS(nsAbManager::nsFilePickerShownCallback,
nsIFilePickerShownCallback)
nsAbManager::nsFilePickerShownCallback::nsFilePickerShownCallback(
nsAbManager* aAbManager, nsIFilePicker* aFilePicker, nsIAbDirectory *aDirectory)
: mFilePicker(aFilePicker)
, mAbManager(aAbManager)
, mDirectory(aDirectory)
{
}
NS_IMETHODIMP nsAbManager::ExportAddressBook(mozIDOMWindowProxy *aParentWin, nsIAbDirectory *aDirectory)
{
NS_ENSURE_ARG_POINTER(aParentWin);
@ -585,17 +594,23 @@ NS_IMETHODIMP nsAbManager::ExportAddressBook(mozIDOMWindowProxy *aParentWin, nsI
rv = filePicker->AppendFilter(filterString, NS_LITERAL_STRING("*.ldi; *.ldif"));
NS_ENSURE_SUCCESS(rv, rv);
int16_t dialogResult;
filePicker->Show(&dialogResult);
nsCOMPtr<nsIFilePickerShownCallback> callback =
new nsAbManager::nsFilePickerShownCallback(this, filePicker, aDirectory);
return filePicker->Open(callback);
}
if (dialogResult == nsIFilePicker::returnCancel)
return rv;
NS_IMETHODIMP
nsAbManager::nsFilePickerShownCallback::Done(int16_t aResult)
{
nsresult rv;
if (aResult == nsIFilePicker::returnCancel)
return NS_OK;
nsCOMPtr<nsIFile> localFile;
rv = filePicker->GetFile(getter_AddRefs(localFile));
rv = mFilePicker->GetFile(getter_AddRefs(localFile));
NS_ENSURE_SUCCESS(rv, rv);
if (dialogResult == nsIFilePicker::returnReplace) {
if (aResult == nsIFilePicker::returnReplace) {
// be extra safe and only delete when the file is really a file
bool isFile;
rv = localFile->IsFile(&isFile);
@ -608,7 +623,7 @@ NS_IMETHODIMP nsAbManager::ExportAddressBook(mozIDOMWindowProxy *aParentWin, nsI
// The type of export is determined by the drop-down in
// the file picker dialog.
int32_t exportType;
rv = filePicker->GetFilterIndex(&exportType);
rv = mFilePicker->GetFilterIndex(&exportType);
NS_ENSURE_SUCCESS(rv,rv);
nsAutoString fileName;
@ -627,7 +642,7 @@ NS_IMETHODIMP nsAbManager::ExportAddressBook(mozIDOMWindowProxy *aParentWin, nsI
fileName.AppendLiteral(LDIF_FILE_EXTENSION2);
localFile->SetLeafName(fileName);
}
rv = ExportDirectoryToLDIF(aDirectory, localFile);
rv = mAbManager->ExportDirectoryToLDIF(mDirectory, localFile);
break;
case CSV_EXPORT_TYPE: // csv
@ -639,7 +654,8 @@ NS_IMETHODIMP nsAbManager::ExportAddressBook(mozIDOMWindowProxy *aParentWin, nsI
fileName.AppendLiteral(CSV_FILE_EXTENSION);
localFile->SetLeafName(fileName);
}
rv = ExportDirectoryToDelimitedText(aDirectory, CSV_DELIM, CSV_DELIM_LEN, localFile,
rv = mAbManager->ExportDirectoryToDelimitedText(
mDirectory, CSV_DELIM, CSV_DELIM_LEN, localFile,
exportType==CSV_EXPORT_TYPE_UTF8);
break;
@ -653,7 +669,8 @@ NS_IMETHODIMP nsAbManager::ExportAddressBook(mozIDOMWindowProxy *aParentWin, nsI
fileName.AppendLiteral(TXT_FILE_EXTENSION);
localFile->SetLeafName(fileName);
}
rv = ExportDirectoryToDelimitedText(aDirectory, TAB_DELIM, TAB_DELIM_LEN, localFile,
rv = mAbManager->ExportDirectoryToDelimitedText(
mDirectory, TAB_DELIM, TAB_DELIM_LEN, localFile,
exportType==TAB_EXPORT_TYPE_UTF8);
break;
@ -665,7 +682,7 @@ NS_IMETHODIMP nsAbManager::ExportAddressBook(mozIDOMWindowProxy *aParentWin, nsI
fileName.AppendLiteral(VCF_FILE_EXTENSION);
localFile->SetLeafName(fileName);
}
rv = ExportDirectoryToVCard(aDirectory, localFile);
rv = mAbManager->ExportDirectoryToVCard(mDirectory, localFile);
break;
};

Просмотреть файл

@ -14,6 +14,7 @@
#include "nsInterfaceHashtable.h"
#include "nsIAbDirFactoryService.h"
#include "nsIAbDirectory.h"
#include "nsIFilePicker.h"
class nsIAbLDAPAttributeMap;
@ -63,6 +64,26 @@ private:
}
};
class nsFilePickerShownCallback
: public nsIFilePickerShownCallback
{
virtual ~nsFilePickerShownCallback()
{ }
public:
nsFilePickerShownCallback(nsAbManager* aInput,
nsIFilePicker* aFilePicker,
nsIAbDirectory *aDirectory);
NS_DECL_ISUPPORTS
NS_IMETHOD Done(int16_t aResult) override;
private:
nsCOMPtr<nsIFilePicker> mFilePicker;
RefPtr<nsAbManager> mAbManager;
RefPtr<nsIAbDirectory> mDirectory;
};
nsTObserverArray<abListener> mListeners;
nsCOMPtr<nsIAbDirectory> mCacheTopLevelAb;
nsInterfaceHashtable<nsCStringHashKey, nsIAbDirectory> mAbStore;