NS_IMETHODIMP nsWMImport::GetImportInterface(const char *pImportType, nsISupports **ppInterface) { NS_ENSURE_ARG_POINTER(pImportType); NS_ENSURE_ARG_POINTER(ppInterface); *ppInterface = nullptr; nsresult rv; if (!strcmp(pImportType, "settings")) { nsCOMPtr<nsIImportSettings> pSettings; rv = nsWMSettings::Create(getter_AddRefs(pSettings)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsISupports> pInterface(do_QueryInterface(pSettings)); pInterface.forget(ppInterface); } return rv; } return NS_ERROR_NOT_AVAILABLE; }
NS_IMETHODIMP ImportVCardAddressImpl::FindAddressBooks( nsIFile *pLoc, nsISupportsArray **ppArray) { NS_ENSURE_ARG_POINTER(pLoc); NS_ENSURE_ARG_POINTER(ppArray); *ppArray = nullptr; bool exists = false; nsresult rv = pLoc->Exists(&exists); if (NS_FAILED(rv) || !exists) return NS_ERROR_FAILURE; bool isFile = false; rv = pLoc->IsFile(&isFile); if (NS_FAILED(rv) || !isFile) return NS_ERROR_FAILURE; m_fileLoc = do_QueryInterface(pLoc); /* Build an address book descriptor based on the file passed in! */ nsCOMPtr<nsISupportsArray> array; rv = NS_NewISupportsArray(getter_AddRefs(array)); if (NS_FAILED(rv)) { IMPORT_LOG0("FAILED to allocate the nsISupportsArray\n"); return rv; } nsString name; m_fileLoc->GetLeafName(name); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed getting leaf name of file\n"); return rv; } int32_t idx = name.RFindChar('.'); if ((idx != -1) && (idx > 0) && ((name.Length() - idx - 1) < 5)) { name.SetLength(idx); } nsCOMPtr<nsIImportABDescriptor> desc; nsCOMPtr<nsIImportService> impSvc( do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed to obtain the import service\n"); return rv; } rv = impSvc->CreateNewABDescriptor(getter_AddRefs(desc)); if (NS_SUCCEEDED(rv)) { int64_t sz = 0; pLoc->GetFileSize(&sz); desc->SetPreferredName(name); desc->SetSize((uint32_t) sz); desc->SetAbFile(m_fileLoc); nsCOMPtr<nsISupports> pInterface(do_QueryInterface(desc, &rv)); array->AppendElement(pInterface); } if (NS_FAILED(rv)) { IMPORT_LOG0( "*** Error creating address book descriptor for vCard import\n"); } else { array.swap(*ppArray); } return rv; }